Debian Codegraph @

Aircraft/Instruments-3d/FG1000/Nasal/MFDPages/IntersectionInfo/IntersectionInfoController.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 # IntersectionInfo Controller
18 var IntersectionInfoController =
19 {
20 new : func (page, svg)
21 {
22 var obj = {
23 parents : [ IntersectionInfoController, 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.getIntersection(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 getIntersection : func(id) {
83 var navdata = nil;
84 var vordata = 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 : "fix" } } );
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 # Get the nearest VOR to the intersection
102 var params = { lat: navdata.lat,
103 lon: navdata.lon,
104 type : "vor" };
105
106 notification = notifications.PFDEventNotification.new(
107 "MFD",
108 me.getDeviceID(),
109 notifications.PFDEventNotification.NavData,
110 {Id: "NavDataWithinRange", Value: params });
111
112 response = me._transmitter.NotifyAll(notification);
113 retval = notification.EventParameter.Value;
114
115 if ((!me._transmitter.IsFailed(response)) and (size(retval) > 0)) {
116 var crsAndDst = courseAndDistance(navdata, retval[0]);
117 vordata = {};
118 vordata.id = retval[0].id;
119 vordata.crs = crsAndDst[0];
120 vordata.dst = crsAndDst[1];
121 }
122 }
123
124 # Display the retrieved data.
125 me._page.update(navdata, vordata);
126 },
127
128 handleStringInput : func(value) {
129 me._page.dataEntry.clearElement();
130 me._page.dataEntry.setValue(value);
131 me.getIntersection(value);
132 me._page.dataEntry.unhighlightElement();
133 return emesary.Transmitter.ReceiptStatus_Finished;
134 },
135 handleKeyInput : func (value) {
136 me._page.dataEntry.keyPress(value);
137 return emesary.Transmitter.ReceiptStatus_Finished;
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.getIntersection(me._page.dataEntry.getValue());
143 },
144 offdisplay : func() {
145 me.DeRegisterWithEmesary();
146 },
147
148
149
150 };