Debian Codegraph @

Aircraft/Instruments-3d/FG1000/Nasal/MFDPages/NearestIntersections/NearestIntersections.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 # NearestIntersections
18 var NearestIntersections =
19 {
20 new : func (mfd, myCanvas, device, svg)
21 {
22 var obj = {
23 parents : [
24 NearestIntersections,
25 MFDPage.new(mfd, myCanvas, device, svg, "NearestIntersections", "NRST - NEAREST INTERSECTIONS")
26 ],
27 };
28
29 obj.setController(fg1000.NearestIntersectionsController.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", "VORID", "VORFreq", "VORCRS", "VORDST"]);
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 var crs = sprintf("%i°", crsAndDst[0]);
104 var dst = sprintf("%.1fnm", crsAndDst[1]);
105
106 # Convert into something we can pass straight to the UIGroup.
107 append(navDataList, {
108 Arrow : nav.id,
109 ID: nav.id,
110 CRS: crs,
111 DST: dst,
112 });
113 }
114
115 me.select.setValues(navDataList);
116
117 if (size(navDataList) > 0) {
118 me.updateNavDataItem(navdata[0]);
119 } else {
120 me.setTextElement("Lat", "NONE WITHIN 200NM");
121 me.setTextElement("VORID", "");
122 me.setTextElement("VORFreq", "");
123 me.setTextElement("VORCRS", "");
124 me.setTextElement("VORDST", "");
125 }
126 },
127 updateNavDataItem : func(nav) {
128 if (nav == nil) return;
129
130 me.setTextElementLat("Lat", nav.lat);
131 me.setTextElementLon("Lon", nav.lon);
132
133 # Determine the nearest VOR, and the bearing and distance TO the VOR,
134 var vordata = me.getController().getNearestNavData("vor");
135
136 if ((vordata != nil ) and (size(vordata) > 0)) {
137 var crsAndDst = courseAndDistance(nav, vordata[0]);
138 var crs = sprintf("%i°", crsAndDst[0]);
139 var dst = sprintf("%.1fnm", crsAndDst[1]);
140 me.setTextElement("VORID", vordata[0].id);
141 me.setTextElement("VORFreq", sprintf("%.2f", vordata[0].frequency / 100.0));
142 me.setTextElement("VORCRS", crs);
143 me.setTextElement("VORDST", dst);
144 } else {
145 me.setTextElement("VORID", "");
146 me.setTextElement("VORFreq", "");
147 me.setTextElement("VORCRS", "");
148 me.setTextElement("VORDST", "");
149 }
150
151 # Display the DTO line to the airport
152 me.mfd.NavigationMap.getController().setDTOLineTarget(nav.lat, nav.lon);
153 },
154
155 topMenu : func(device, pg, menuitem) {
156 pg.clearMenu();
157 pg.resetMenuColors();
158 pg.addMenuItem(0, "ENGINE", pg.mfd.EIS, pg.mfd.EIS.engineMenu);
159 pg.addMenuItem(2, "MAP", pg.mfd.NavigationMap, pg.mfd.NavigationMap.mapMenu);
160
161 device.updateMenus();
162 },
163 };