Debian Codegraph @

Aircraft/Instruments-3d/FG1000/Nasal/MFDPages/AirportInfo/AirportInfo.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 # AirportInfo
18 var AirportInfo =
19 {
20 new : func (mfd, myCanvas, device, svg)
21 {
22 var obj = {
23 parents : [
24 AirportInfo,
25 MFDPage.new(mfd, myCanvas, device, svg, "AirportInfo", "WPT - AIRPORT INFORMATION")
26 ],
27 symbols : {},
28 };
29
30 obj.crsrIdx = 0;
31
32 # Dynamic text elements in the SVG file. In the SVG these have an "AirportInfo" prefix.
33 textelements = [
34 "Usage",
35 "Name",
36 "City",
37 "Region",
38 "Alt",
39 "Lat",
40 "Lon",
41 "Fuel",
42 "TZ",
43 "RwyDimensions",
44 "RwySurface",
45 "RwyLighting",
46 "Zoom"
47 ];
48
49 obj.addTextElements(textelements);
50
51 # Data Entry information. Keyed from the name of the element, which must
52 # be one of the textelements above. Each data element maps to a set of
53 # text elements in the SVG of the form [PageName][TextElement]{0...n}, each
54 # representing a single character for data entry.
55 #
56 # .size is the number of characters of data entry
57 # .chars is the set of characters, used to scroll through using the small
58 # FMS knob.
59 obj.airportEntry = PFD.DataEntryElement.new(obj.pageName, svg, "ID", "", 4, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
60
61 # TODO: Implement search by name - not currently supported.
62 # obj.airportNameEntry = PFD.DataEntryElement.new(obj.pageName, svg, "Name", ???, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ");
63
64 obj.runwaySelect = PFD.ScrollElement.new(obj.pageName, svg, "Runway", ["36","18"]); # Dummy values
65
66 obj.freqSelect = PFD.GroupElement.new(
67 obj.pageName,
68 svg,
69 ["FreqLabel", "Freq"],
70 7,
71 "Freq",
72 0,
73 "FreqScrollBar",
74 "FreqScroll",
75 150
76 );
77
78 # The Airport Chart
79 obj.AirportChart = obj._group.createChild("map");
80 obj.AirportChart.setController("Static position", "main");
81
82 # Initialize a range and screen resolution. Setting a range
83 # to 4nm means we pick up a good set of surrounding fixes
84 # We will use the screen range for zooming. If we use range
85 # then as we zoom in the airport center goes out of range
86 # and all the runways disappear.
87 obj.AirportChart.setRange(4.0);
88 obj.AirportChart.setScreenRange(fg1000.MAP_PARTIAL.HEIGHT);
89 obj.AirportChart.setTranslation(
90 fg1000.MAP_PARTIAL.CENTER.X,
91 fg1000.MAP_PARTIAL.CENTER.Y
92 );
93
94 var r = func(name,vis=1,zindex=nil) return caller(0)[0];
95 foreach(var type; [r('TAXI'),r('RWY'),r('APT')] ) {
96 obj.AirportChart.addLayer(canvas.SymbolLayer,
97 type.name,
98 4,
99 obj.Styles.getStyle(type.name),
100 obj.Options.getOption(type.name),
101 type.vis );
102 }
103
104 obj.setController(fg1000.AirportInfoController.new(obj, svg));
105
106 obj.topMenu(device, obj, nil);
107
108 return obj;
109 },
110 displayAirport : func(apt_info) {
111 # Display a given airport
112 me.AirportChart.getController().setPosition(apt_info.lat, apt_info.lon);
113 me.AirportChart.update();
114 me.airportEntry.setValue(apt_info.id);
115 me.setTextElement("Usage", "PUBLIC");
116 me.setTextElement("Name", string.uc(apt_info.name));
117 me.setTextElement("City", "CITY");
118 me.setTextElement("Region", "REGION");
119 me.setTextElement("Alt", sprintf("%ift", M2FT * apt_info.elevation));
120 me.setTextElementLat("Lat", apt_info.lat);
121 me.setTextElementLon("Lon", apt_info.lon);
122 me.setTextElement("Fuel", "AVGAS, AVTUR");
123 me.setTextElement("TZ", "UTC-6");
124
125 # Set up the runways list, but ignoring reciprocals so we don't get
126 # runways displayed twice.
127 var rwys = [];
128 var recips = {};
129 foreach(var rwy; sort(keys(apt_info.runways), string.icmp)) {
130 var rwy_info = apt_info.runways[rwy];
131 if (recips[rwy_info.id] == nil) {
132 var lbl = rwy_info.id ~ "-" ~ rwy_info.reciprocal.id;
133 append(rwys, lbl);
134 recips[rwy_info.reciprocal.id] = 1;
135 }
136 }
137
138 me.runwaySelect.setValues(rwys);
139 if (size(rwys) > 0) {
140 me.displayRunway(apt_info.runways[keys(apt_info.runways)[0]]);
141 } else {
142 me.displayRunway(nil);
143 }
144
145 # Display the comms frequencies for this airport
146 var freqarray = [];
147
148 if (size(apt_info.comms()) > 0) {
149 # Airport has one or more frequencies assigned to it.
150 var freqs = {};
151 var comms = apt_info.comms();
152
153 foreach (var c; comms) {
154 freqs[c.ident] = sprintf("%.3f", c.frequency);;
155 }
156
157 foreach (var c; sort(keys(freqs), string.icmp)) {
158 append(freqarray, {FreqLabel: c, Freq: freqs[c]});
159 }
160 }
161
162 # Add any ILS frequencies as well
163 foreach(var rwy; sort(keys(apt_info.runways), string.icmp)) {
164 var rwy_info = apt_info.runways[rwy];
165 if (rwy_info.ils_frequency_mhz != nil) {
166 var label = "ILS " ~ rwy_info.id;
167 var freq = sprintf("%.3f", rwy_info.ils_frequency_mhz);
168 append(freqarray, {FreqLabel: label, Freq: freq});
169 }
170 }
171
172 me.freqSelect.setValues(freqarray);
173
174 },
175 displayRunway : func(rwy_info) {
176 if (rwy_info == nil) {
177 me.setTextElement("RwyDimensions", "");
178 me.setTextElement("RwySurface", "");
179 } else {
180 var dim = sprintf("%ift x %ift", 3.28 * rwy_info.length, 3.28 * rwy_info.width);
181 me.setTextElement("RwyDimensions", dim);
182
183 me.setTextElement("RwySurface", get_SURFACE_TYPES(rwy_info.surface));
184 #me.setTextElement("RwyLighting", rwy_info.surface);
185 }
186 },
187 setZoom : func(zoom, label) {
188 # Set the zoom level for the airport chart display
189 me.AirportChart.setScreenRange(zoom);
190 me.AirportChart.update();
191 me.setTextElement("Zoom", label);
192 },
193
194 # Clear any cursor, highlights. Used when exiting from CRSR mode
195 resetCRSR : func() {
196 me.airportEntry.unhighlightElement();
197 me.runwaySelect.unhighlightElement();
198 me.freqSelect.hideCRSR();
199 },
200
201 offdisplay : func() {
202 me._group.setVisible(0);
203
204 # Reset the menu colours. Shouldn't have to do this here, but
205 # there's not currently an obvious other location to do so.
206 for(var i = 0; i < 12; i +=1) {
207 var name = sprintf("SoftKey%d",i);
208 me.device.svg.getElementById(name ~ "-bg").setColorFill(0.0,0.0,0.0);
209 me.device.svg.getElementById(name).setColor(1.0,1.0,1.0);
210 }
211 me.getController().offdisplay();
212 },
213 ondisplay : func() {
214 me._group.setVisible(1);
215 me.mfd.setPageTitle(me.title);
216 me.getController().ondisplay();
217 },
218 # Softkey menus
219 topMenu : func(device, pg, menuitem) {
220 pg.clearMenu();
221 pg.resetMenuColors();
222 device.updateMenus();
223 },
224 };