Debian Codegraph @

Aircraft/Instruments-3d/FG1000/Nasal/MFDPages/NearestVOR/NearestVOR.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 # NearestVOR
18 var NearestVOR =
19 {
20 new : func (mfd, myCanvas, device, svg)
21 {
22 var obj = {
23 parents : [
24 NearestVOR,
25 MFDPage.new(mfd, myCanvas, device, svg, "NearestVOR", "NRST - NEAREST VOR")
26 ],
27 };
28
29 obj.setController(fg1000.NearestVORController.new(obj, svg));
30
31 # Dynamic elements. There is a single dynamic element containing the list of
32 # the 25 nearest intersections.
33 obj.select = PFD.GroupElement.new(
34 obj.pageName,
35 svg,
36 [ "Arrow", "ID", "CRS", "DST"],
37 11,
38 "Arrow",
39 1,
40 "ScrollTrough",
41 "ScrollThumb",
42 250 - 116
43 );
44
45 # Other dynamic text elements
46 obj.addTextElements(["Lat", "Lon", "Name", "Freq"]);
47
48 obj.topMenu(device, obj, nil);
49
50 return obj;
51 },
52
53 # Indicate which group is selected by colour of the softkeys
54 display_toggle : func(device, svg, mi, group) {
55 var bg_name = sprintf("SoftKey%d-bg",mi.menu_id);
56 if (me.getController().getSelectedGroup() == group) {
57 device.svg.getElementById(bg_name).setColorFill(0.5,0.5,0.5);
58 svg.setColor(0.0,0.0,0.0);
59 } else {
60 device.svg.getElementById(bg_name).setColorFill(0.0,0.0,0.0);
61 svg.setColor(1.0,1.0,1.0);
62 }
63 svg.setText(mi.title);
64 svg.setVisible(1); # display function
65 },
66
67 # Function to highlight the VOR softkey - used when CRSR is pressed to indicate
68 # that we're editing the VOR selection.
69 selectVOR : func() {
70 me.resetMenuColors();
71 var bg_name = sprintf("SoftKey%d-bg",4);
72 var tname = sprintf("SoftKey%d",4);
73 me.device.svg.getElementById(bg_name).setColorFill(0.5,0.5,0.5);
74 me.device.svg.getElementById(tname).setColor(0.0,0.0,0.0);
75 },
76
77 hideCRSR : func() {
78 me.select.hideCRSR();
79 me.unhighlightTextElement("Freq");
80 me.resetMenuColors();
81 },
82
83 offdisplay : func() {
84 # The Nearest... pages use the underlying navigation map.
85 me.mfd.NavigationMap.offdisplayPartial();
86
87 # Reset the menu colours. Shouldn't have to do this here, but
88 # there's not currently an obvious other location to do so.
89 me.resetMenuColors();
90
91 me.getController().offdisplay();
92 },
93 ondisplay : func() {
94 me.getController().ondisplay();
95
96 # The Nearest... pages use the underlying navigation map.
97 me.mfd.NavigationMap.ondisplayPartial();
98
99 me.mfd.setPageTitle(me.title);
100 },
101 updateNavData : func(navdata) {
102
103 if ((navdata == nil) or (size(navdata) == 0)) return;
104
105 var navDataList = [];
106 for (var i = 0; i < size(navdata); i = i + 1) {
107 var nav = navdata[i];
108 var crsAndDst = courseAndDistance(nav);
109
110 # Display the course and distance in NM .
111 # 248 is the extended ASCII code for the degree symbol
112 var crs = sprintf("%i°", crsAndDst[0]);
113 var dst = sprintf("%.1fnm", crsAndDst[1]);
114
115 # Convert into something we can pass straight to the UIGroup.
116 append(navDataList, {
117 Arrow : nav.id,
118 ID: nav.id,
119 CRS: crs,
120 DST: dst,
121 });
122 }
123
124 me.select.setValues(navDataList);
125
126 if (size(navDataList) > 0) {
127 me.updateNavDataItem(navdata[0]);
128 } else {
129 me.setTextElement("Name", "NONE WITHIN 200NM");
130 me.setTextElement("Lon", "");
131 me.setTextElement("Lat", "");
132 me.setTextElement("Frequency", "");
133 }
134 },
135 updateNavDataItem : func(nav) {
136
137 if (nav == nil) return;
138
139 me.setTextElementLat("Lat", nav.lat);
140 me.setTextElementLon("Lon", nav.lon);
141 me.setTextElement("Freq", sprintf("%.2f", nav.frequency / 100.0));
142 me.setTextElement("Name", nav.name);
143
144 # Display the DTO line to the airport
145 me.mfd.NavigationMap.getController().setDTOLineTarget(nav.lat, nav.lon);
146 },
147
148 topMenu : func(device, pg, menuitem) {
149 pg.clearMenu();
150 pg.resetMenuColors();
151 pg.addMenuItem(0, "ENGINE", pg, pg.mfd.EIS.engineMenu);
152 pg.addMenuItem(2, "MAP", pg, pg.mfd.NavigationMap.mapMenu);
153 pg.addMenuItem(4, "VOR", pg,
154 func(dev, pg, mi) { pg.getController().selectVOR(); device.updateMenus(); }, # callback
155 func(svg, mi) { pg.display_toggle(device, svg, mi, NearestVORController.UIGROUP.VOR); }
156 );
157
158 pg.addMenuItem(5, "FREQ", pg,
159 func(dev, pg, mi) { pg.getController().selectFrequencies(); device.updateMenus(); }, # callback
160 func(svg, mi) { pg.display_toggle(device, svg, mi, NearestVORController.UIGROUP.FREQ); }
161 );
162 },
163 };