Debian Codegraph @

Aircraft/Instruments-3d/FG1000/Nasal/MFD.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 # FG1000 MFD
18
19 var MFDPages = [
20 "NavigationMap",
21 "TrafficMap",
22 "Stormscope",
23 "WeatherDataLink",
24 "TAWSB",
25 "AirportInfo",
26 "AirportDirectory",
27 "AirportDeparture",
28 "AirportArrival",
29 "AirportApproach",
30 "AirportWeather",
31 "IntersectionInfo",
32 "NDBInfo",
33 "VORInfo",
34 "UserWPTInfo",
35 "TripPlanning",
36 "Utility",
37 "GPSStatus",
38 "XMRadio",
39 "XMInfo",
40 "SystemStatus",
41 "ActiveFlightPlanNarrow",
42 "ActiveFlightPlanWide",
43 "FlightPlanCatalog",
44 "StoredFlightPlan",
45 "Checklist",
46 "NearestAirports",
47 "NearestIntersections",
48 "NearestNDB",
49 "NearestVOR",
50 "NearestUserWPT",
51 "NearestFrequencies",
52 "NearestAirspaces",
53 "WaypointEntry",
54 "DirectTo",
55 "Surround",
56 ];
57
58 var nasal_dir = getprop("/sim/fg-root") ~ "/Aircraft/Instruments-3d/FG1000/Nasal/";
59
60 foreach (var page; MFDPages) {
61 io.load_nasal(nasal_dir ~ "MFDPages/" ~ page ~ '/' ~ page ~ '.nas', "fg1000");
62 io.load_nasal(nasal_dir ~ "MFDPages/" ~ page ~ '/' ~ page ~ 'Styles.nas', "fg1000");
63 io.load_nasal(nasal_dir ~ "MFDPages/" ~ page ~ '/' ~ page ~ 'Options.nas', "fg1000");
64 io.load_nasal(nasal_dir ~ "MFDPages/" ~ page ~ '/' ~ page ~ 'Controller.nas', "fg1000");
65 }
66
67 var MFDDisplay =
68 {
69 new : func (fg1000instance, EIS_Class, EIS_SVG, SVG_Path, myCanvas, device_id=1)
70 {
71 var obj = {
72 parents : [ MFDDisplay ],
73 EIS : nil,
74 NavigationMap: nil,
75 Surround : nil,
76 _pageList : {},
77 _fg1000 : fg1000instance,
78 _canvas : myCanvas,
79 };
80
81 obj.ConfigStore = obj._fg1000.getConfigStore();
82
83 obj._svg = myCanvas.createGroup("softkeys");
84 obj._svg.set("clip-frame", canvas.Element.LOCAL);
85 obj._svg.set("clip", "rect(0px, 1024px, 768px, 0px)");
86
87 var fontmapper = func (family, weight) {
88 #if( family == "Liberation Sans" and weight == "narrow" ) {
89 return "LiberationFonts/LiberationSansNarrow-Regular.ttf";
90 #}
91 # If we don't return anything the default font is used
92 };
93
94
95 foreach (var page; MFDPages) {
96 var svg_file = SVG_Path ~ page ~ '.svg';
97 # Load an SVG file if available.
98 if (resolvepath(svg_file) != "") {
99 canvas.parsesvg(obj._svg,
100 svg_file,
101 {'font-mapper': fontmapper});
102 }
103 }
104
105 canvas.parsesvg(obj._svg,
106 EIS_SVG,
107 {'font-mapper': fontmapper});
108
109 obj._MFDDevice = canvas.PFD_Device.new(obj._svg, 12, "SoftKey", myCanvas, "MFD");
110 obj._MFDDevice.device_id = device_id;
111
112 # DirectTo "Page" loaded first so that it receives any Emesary notifications
113 # _before_ the actual page.
114 obj._DTO = fg1000.DirectTo.new(obj, myCanvas, obj._MFDDevice, obj._svg);
115 obj._DTO.getController().RegisterWithEmesary();
116
117 # Next, the WaypointEntry "Page" so that it too receives any Emesary notifications
118 # _before_ the actual page.
119 obj._WaypointEntry = fg1000.WaypointEntry.new(obj, myCanvas, obj._MFDDevice, obj._svg);
120 obj._WaypointEntry.getController().RegisterWithEmesary();
121
122 obj._MFDDevice.RegisterWithEmesary();
123
124 # Surround dynamic elements
125 obj._pageTitle = obj._svg.getElementById("PageTitle");
126
127 # Controller for the header and display on the bottom left which allows selection
128 # of page groups and individual pages using the FMS controller.
129 obj.Surround = fg1000.Surround.new(obj, myCanvas, obj._MFDDevice, obj._svg);
130 obj.SurroundController = obj.Surround.getController();
131
132 # Engine Information System. A special case as it's always displayed on the MFD.
133 # Note that it is passed in on the constructor
134 obj.EIS = EIS_Class.new(obj, myCanvas, obj._MFDDevice, obj._svg);
135 obj.addPage("EIS", obj.EIS);
136
137 # The NavigationMap page is a special case, as it is displayed with the Nearest... pages as an overlay
138 obj.NavigationMap = fg1000.NavigationMap.new(obj, myCanvas, obj._MFDDevice, obj._svg);
139 obj.addPage("NavigationMap", obj.NavigationMap);
140 obj.NavigationMap.topMenu(obj._MFDDevice, obj.NavigationMap, nil);
141
142 # Now load the other pages normally;
143 foreach (var page; MFDPages) {
144 if ((page != "NavigationMap") and (page != "EIS") and (page != "DirectTo") and (page != "WaypointEntry")) {
145 #var code = "obj.Surround.addPage(\"" ~ page ~ "\", fg1000." ~ page ~ ".new(obj, myCanvas, obj._MFDDevice, obj._svg));";
146 var code = "obj.addPage(\"" ~ page ~ "\", fg1000." ~ page ~ ".new(obj, myCanvas, obj._MFDDevice, obj._svg));";
147 var addPageFn = compile(code);
148 addPageFn();
149 }
150 }
151
152 # Display the Surround, EIS and NavMap and the appropriate top level on startup.
153 obj.Surround.setVisible(1);
154 obj.EIS.setVisible(1);
155 obj._MFDDevice.selectPage(obj.NavigationMap);
156
157 return obj;
158 },
159 getDevice : func () {
160 return me._MFDDevice;
161 },
162 del: func()
163 {
164 me._MFDDevice.current_page.offdisplay();
165 me._MFDDevice.DeRegisterWithEmesary();
166 me.SurroundController.del();
167
168 },
169 setPageTitle: func(title)
170 {
171 me._pageTitle.setText(title);
172 },
173 addPage : func(name, page)
174 {
175 me._pageList[name] = page;
176 },
177
178 getPage : func(name)
179 {
180 return me._pageList[name];
181 },
182
183 getDeviceID : func() {
184 return me._MFDDevice.device_id;
185 },
186
187 getCanvas : func() {
188 return me._canvas;
189 }
190 };