Debian Codegraph @

Aircraft/Instruments-3d/FG1000/Nasal/MFDPages/NearestNDB/NearestNDB.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 # NearestNDB
18 var NearestNDB =
19 {
20 new : func (mfd, myCanvas, device, svg)
21 {
22 var obj = {
23 parents : [
24 NearestNDB,
25 MFDPage.new(mfd, myCanvas, device, svg, "NearestNDB", "NRST - NEAREST NDB")
26 ],
27 };
28
29 obj.setController(fg1000.NearestNDBController.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 showCRSR : func() {
68 me.select.showCRSR();
69 },
70
71 hideCRSR : func() {
72 me.select.hideCRSR();
73 },
74
75 offdisplay : func() {
76 # The Nearest... pages use the underlying navigation map.
77 me.mfd.NavigationMap.offdisplayPartial();
78
79 # Reset the menu colours. Shouldn't have to do this here, but
80 # there's not currently an obvious other location to do so.
81 me.resetMenuColors();
82
83 me.getController().offdisplay();
84 },
85 ondisplay : func() {
86 me.getController().ondisplay();
87
88 # The Nearest... pages use the underlying navigation map.
89 me.mfd.NavigationMap.ondisplayPartial();
90
91 me.mfd.setPageTitle(me.title);
92 },
93 updateNavData : func(navdata) {
94
95 if ((navdata == nil) or (size(navdata) == 0)) return;
96
97 var navDataList = [];
98 for (var i = 0; i < size(navdata); i = i + 1) {
99 var nav = navdata[i];
100 var crsAndDst = courseAndDistance(nav);
101
102 # Display the course and distance in NM .
103 # 248 is the extended ASCII code for the degree symbol
104 var crs = sprintf("%i°", crsAndDst[0]);
105 var dst = sprintf("%.1fnm", crsAndDst[1]);
106
107 # Convert into something we can pass straight to the UIGroup.
108 append(navDataList, {
109 Arrow : nav.id,
110 ID: nav.id,
111 CRS: crs,
112 DST: dst,
113 });
114 }
115
116 me.select.setValues(navDataList);
117
118 if (size(navDataList) > 0) {
119 me.updateNavDataItem(navdata[0]);
120 } else {
121 me.setTextElement("Name", "NONE WITHIN 200NM");
122 me.setTextElementLon("Lon", "");
123 me.setTextElementLat("Lat", "");
124 me.setTextElementNavFreq("Freq", "");
125 }
126 },
127 updateNavDataItem : func(nav) {
128
129 if (nav == nil) return;
130
131
132 me.setTextElementLat("Lat", nav.lat);
133 me.setTextElementLon("Lon", nav.lon);
134 me.setTextElementNavFreq("Freq", nav.frequency / 100.0);
135 me.setTextElement("Name", nav.name);
136
137 # Display the DTO line to the airport
138 me.mfd.NavigationMap.getController().setDTOLineTarget(nav.lat, nav.lon);
139 },
140
141 topMenu : func(device, pg, menuitem) {
142 pg.clearMenu();
143 pg.resetMenuColors();
144 pg.addMenuItem(0, "ENGINE", pg.mfd.EIS, pg.mfd.EIS.engineMenu);
145 pg.addMenuItem(2, "MAP", pg.mfd.NavigationMap, pg.mfd.NavigationMap.mapMenu);
146
147 device.updateMenus();
148 },
149 };