Debian Codegraph @

Aircraft/Instruments-3d/FG1000/Nasal/MFDPages/NDBInfo/NDBInfoController.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 # NDBInfo Controller
18 var NDBInfoController =
19 {
20 new : func (page, svg)
21 {
22 var obj = {
23 parents : [ NDBInfoController, 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 handleFMSInner : func(value) {
43 if (me._crsrToggle == 1) {
44 me._page.dataEntry.incrSmall(value);
45 return emesary.Transmitter.ReceiptStatus_Finished;
46 } else {
47 return me._page.mfd.SurroundController.handleFMSInner(value);
48 }
49 },
50 handleFMSOuter : func(value) {
51 if (me._crsrToggle == 1) {
52 me._page.dataEntry.incrLarge(value);
53 return emesary.Transmitter.ReceiptStatus_Finished;
54 } else {
55 return me._page.mfd.SurroundController.handleFMSOuter(value);
56 }
57 },
58 handleEnter : func(value) {
59 if (me._crsrToggle == 1) {
60 var id = me._page.dataEntry.enterElement();
61 me.getNDB(id);
62 return emesary.Transmitter.ReceiptStatus_Finished;
63 } else {
64 return emesary.Transmitter.ReceiptStatus_NotProcessed;
65 }
66 },
67 handleClear : func(value) {
68 if (me._crsrToggle == 1) {
69 me._page.dataEntry.clearElement();
70 return emesary.Transmitter.ReceiptStatus_Finished;
71 } else {
72 return emesary.Transmitter.ReceiptStatus_NotProcessed;
73 }
74 },
75 handleRange : func(val)
76 {
77 # Pass any range entries to the NavMapController
78 me._page.Map.handleRange(val);
79 },
80
81 # Retrieve intersection information for the provided id and display it.
82 getNDB : func(id) {
83 var navdata = nil;
84 var aptdata = nil;
85
86 # Use Emesary to get the intersection
87 var notification = notifications.PFDEventNotification.new(
88 "MFD",
89 me.getDeviceID(),
90 notifications.PFDEventNotification.NavData,
91 {Id: "NavAidByID", Value: { id: id, type : "ndb" } } );
92
93 var response = me._transmitter.NotifyAll(notification);
94 var retval = notification.EventParameter.Value;
95
96 if ((!me._transmitter.IsFailed(response)) and (size(retval) > 0)) {
97
98 # Simply take the first value. Should handle duplicates.
99 navdata = retval[0];
100
101 debug.dump(navdata);
102
103 # Get the nearest Airport to the intersection
104 var params = { lat: navdata.lat,
105 lon: navdata.lon,
106 type : "airport" };
107
108 notification = notifications.PFDEventNotification.new(
109 "MFD",
110 me.getDeviceID(),
111 notifications.PFDEventNotification.NavData,
112 {Id: "NavDataWithinRange", Value: params });
113
114 response = me._transmitter.NotifyAll(notification);
115 retval = notification.EventParameter.Value;
116
117 if ((!me._transmitter.IsFailed(response)) and (size(retval) > 0)) {
118 var crsAndDst = courseAndDistance(navdata, retval[0]);
119 aptdata = {};
120 aptdata.id = retval[0].id;
121 aptdata.crs = crsAndDst[0];
122 aptdata.dst = crsAndDst[1];
123 }
124 }
125
126 # Display the retrieved data.
127 me._page.update(navdata, aptdata);
128 },
129
130 handleStringInput : func(value) {
131 me._page.dataEntry.clearElement();
132 me._page.dataEntry.setValue(value);
133 me.getNDB(value);
134 me._page.dataEntry.unhighlightElement();
135 return emesary.Transmitter.ReceiptStatus_Finished;
136 },
137 handleKeyInput : func (value) {
138 me._page.dataEntry.keyPress(value);
139 return emesary.Transmitter.ReceiptStatus_Finished;
140 },
141
142 # Reset controller if required when the page is displayed or hidden
143 ondisplay : func() {
144 me.RegisterWithEmesary();
145 if (me._page.dataEntry.getValue() != "") me.getNDB(me._page.dataEntry.getValue());
146 },
147 offdisplay : func() {
148 me.DeRegisterWithEmesary();
149 },
150
151 };