Debian Codegraph @

Aircraft/Instruments-3d/FG1000/Nasal/MFDPages/VORInfo/VORInfo.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
18 var VORInfo =
19 {
20 new : func (mfd, myCanvas, device, svg)
21 {
22 var obj = {
23 parents : [
24 VORInfo,
25 MFDPage.new(mfd, myCanvas, device, svg, "VORInfo", "WPT - VOR INFORMATION")
26 ],
27 };
28
29 # Dynamic text elements in the SVG file. In the SVG these have an "NDBInfo" prefix.
30 textelements = [
31 "ID",
32 "Type",
33 "Facility",
34 "NearestCity",
35 "Class", # Low Altitude / High Altitude / Terminal
36 "MagVar",
37 "Region",
38 "Lat",
39 "Lon",
40 "Freq",
41 "AirportID",
42 "AirportCRS",
43 "AirportDST"
44 ];
45
46 obj.addTextElements(textelements);
47
48 # Data Entry information. Keyed from the name of the element, which must
49 # be one of the textelements above. Each data element maps to a set of
50 # text elements in the SVG of the form [PageName][TextElement]{0...n}, each
51 # representing a single character for data entry.
52 #
53 # .size is the number of characters of data entry
54 # .chars is the set of characters, used to scroll through using the small
55 # FMS knob.
56 obj.dataEntry = PFD.DataEntryElement.new(obj.pageName, svg, "ID", "", 3, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
57
58 obj.Map = fg1000.NavMap.new(
59 obj,
60 obj.getElement("NavMap"),
61 [860,400],
62 "",
63 -50,
64 0,
65 1);
66
67
68 obj.topMenu(device, obj, nil);
69 obj.update(nil, nil);
70
71 obj.setController(fg1000.VORInfoController.new(obj, svg));
72
73 return obj;
74 },
75
76 update : func(navdata, aptdata) {
77 if (navdata != nil) {
78 me.setTextElement("ID", navdata.id);
79
80 var type = "VOR";
81 if (navdata.vortac) type = "VORTAC";
82 if (navdata.dme) type = "VOR-DME";
83
84 me.setTextElement("Type", type);
85 me.setTextElement("Facility", "");
86 me.setTextElement("NearestCity", "");
87 me.setTextElement("Class", "");
88 me.setTextElementMagVar("MagVar", navdata.magvar);
89 me.setTextElement("Region", "");
90
91 me.setTextElementLat("Lat", navdata.lat);
92 me.setTextElementLon("Lon", navdata.lon);
93 me.setTextElementNavFreq("Freq", navdata.frequency / 100.0);
94
95 me.Map.getController().setPosition(navdata.lat, navdata.lon);
96 me.Map.show();
97 } else {
98 me.setTextElement("ID", "###");
99 me.setTextElement("Type", "_______");
100 me.setTextElement("Facility", "_______");
101 me.setTextElement("NearestCity", "_______");
102 me.setTextElement("Class", "_______");
103 me.setTextElement("MagVar", "");
104 me.setTextElement("Region", "_______");
105
106 me.setTextElementLat("Lat", nil);
107 me.setTextElementLon("Lon", nil);
108 me.setTextElementNavFreq("Freq", "");
109 me.Map.hide();
110 }
111
112 if (aptdata != nil) {
113 var crsAndDst = courseAndDistance(navdata, aptdata);
114 me.setTextElement("AirportID", aptdata.id);
115 me.setTextElementBearing("AirportCRS", aptdata.crs);
116 me.setTextElementDistance("AirportDST", aptdata.dst);
117 } else {
118 me.setTextElement("AirportID", "____");
119 me.setTextElementBearing("AirportCRS", "");
120 me.setTextElementDistance("AirportDST", "");
121 }
122 },
123
124 offdisplay : func() {
125 me._group.setVisible(0);
126
127 # Reset the menu colours. Shouldn't have to do this here, but
128 # there's not currently an obvious other location to do so.
129 for(var i = 0; i < 12; i +=1) {
130 var name = sprintf("SoftKey%d",i);
131 me.device.svg.getElementById(name ~ "-bg").setColorFill(0.0,0.0,0.0);
132 me.device.svg.getElementById(name).setColor(1.0,1.0,1.0);
133 }
134 me.getElement("NavMap").setVisible(0);
135 me.Map.setVisible(0);
136 me.getController().offdisplay();
137 },
138 ondisplay : func() {
139 me._group.setVisible(1);
140 me.mfd.setPageTitle(me.title);
141 me.getElement("NavMap").setVisible(1);
142 me.Map.setVisible(1);
143 me.getController().ondisplay();
144 },
145 topMenu : func(device, pg, menuitem) {
146 pg.clearMenu();
147 pg.resetMenuColors();
148 pg.addMenuItem(0, "ENGINE", pg.mfd.EIS, pg.mfd.EIS.engineMenu);
149 pg.addMenuItem(2, "MAP", pg.mfd.NavigationMap, pg.mfd.NavigationMap.mapMenu);
150 device.updateMenus();
151 },
152
153
154 };