Debian Codegraph @

Aircraft/Instruments-3d/FG1000/Nasal/MFDPages/VORInfo/VORInfoController.nas

raw
1 # Copyright 2018 Stuart Buchanan
2 # This file is part of FlightGear.
3 #
4 # FlightGear is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # FlightGear is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with FlightGear. If not, see <http://www.gnu.org/licenses/>.
16 #
17 # VORInfo Controller
18 var VORInfoController =
19 {
20 new : func (page, svg)
21 {
22 var obj = {
23 parents : [ VORInfoController, MFDPageController.new(page) ],
24 _crsrToggle : 0,
25 _recipient : nil,
26 _page : page,
27 };
28
29 return obj;
30 },
31
32 # Input Handling
33 handleCRSR : func() {
34 me._crsrToggle = (! me._crsrToggle);
35 if (me._crsrToggle) {
36 me._page.dataEntry.highlightElement();
37 } else {
38 me._page.dataEntry.unhighlightElement();
39 }
40 return emesary.Transmitter.ReceiptStatus_Finished;
41 },
42 handleKeyInput : func (value) {
43 me._page.dataEntry.keyPress(value);
44 return emesary.Transmitter.ReceiptStatus_Finished;
45 },
46 handleFMSInner : func(value) {
47 if (me._crsrToggle == 1) {
48 me._page.dataEntry.incrSmall(value);
49 return emesary.Transmitter.ReceiptStatus_Finished;
50 } else {
51 return me._page.mfd.SurroundController.handleFMSInner(value);
52 }
53 },
54 handleFMSOuter : func(value) {
55 if (me._crsrToggle == 1) {
56 me._page.dataEntry.incrLarge(value);
57 return emesary.Transmitter.ReceiptStatus_Finished;
58 } else {
59 return me._page.mfd.SurroundController.handleFMSOuter(value);
60 }
61 },
62 handleEnter : func(value) {
63 if (me._crsrToggle == 1) {
64 var id = me._page.dataEntry.enterElement();
65 me.getVOR(id);
66 return emesary.Transmitter.ReceiptStatus_Finished;
67 } else {
68 return emesary.Transmitter.ReceiptStatus_NotProcessed;
69 }
70 },
71 handleClear : func(value) {
72 if (me._crsrToggle == 1) {
73 me._page.dataEntry.clearElement();
74 return emesary.Transmitter.ReceiptStatus_Finished;
75 } else {
76 return emesary.Transmitter.ReceiptStatus_NotProcessed;
77 }
78 },
79 handleRange : func(val)
80 {
81 # Pass any range entries to the NavMapController
82 me._page.Map.handleRange(val);
83 },
84
85 # Retrieve intersection information for the provided id and display it.
86 getVOR : func(id) {
87 var navdata = nil;
88 var aptdata = nil;
89
90 # Use Emesary to get the intersection
91 var notification = notifications.PFDEventNotification.new(
92 "MFD",
93 me.getDeviceID(),
94 notifications.PFDEventNotification.NavData,
95 {Id: "NavAidByID", Value: { id: id, type : "vor" } } );
96
97 var response = me._transmitter.NotifyAll(notification);
98 var retval = notification.EventParameter.Value;
99
100 if ((!me._transmitter.IsFailed(response)) and (size(retval) > 0)) {
101 # Simply take the first value, which will be the closest.
102 navdata = retval[0];
103
104 # Get the nearest Airport to the intersection
105 var params = { lat: navdata.lat,
106 lon: navdata.lon,
107 type : "airport" };
108
109 notification = notifications.PFDEventNotification.new(
110 "MFD",
111 me.getDeviceID(),
112 notifications.PFDEventNotification.NavData,
113 {Id: "NavDataWithinRange", Value: params });
114
115 response = me._transmitter.NotifyAll(notification);
116 retval = notification.EventParameter.Value;
117
118 if ((!me._transmitter.IsFailed(response)) and (size(retval) > 0)) {
119 var crsAndDst = courseAndDistance(navdata, retval[0]);
120 aptdata = {};
121 aptdata.id = retval[0].id;
122 aptdata.crs = crsAndDst[0];
123 aptdata.dst = crsAndDst[1];
124 }
125 }
126
127 # Display the retrieved data.
128 me._page.update(navdata, aptdata);
129 },
130
131 handleStringInput : func(value) {
132 me._page.dataEntry.clearElement();
133 me._page.dataEntry.setValue(value);
134 me.getVOR(value);
135 me._page.dataEntry.unhighlightElement();
136 return emesary.Transmitter.ReceiptStatus_Finished;
137 },
138
139 # Reset controller if required when the page is displayed or hidden
140 ondisplay : func() {
141 me.RegisterWithEmesary();
142 if (me._page.dataEntry.getValue() != "") me.getVOR(me._page.dataEntry.getValue());
143 },
144 offdisplay : func() {
145 me.DeRegisterWithEmesary();
146 },
147
148 };