Debian Codegraph @

Aircraft/Instruments-3d/FG1000/Nasal/MFDPages/WaypointEntry/WaypointEntry.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 # WaypointEntry page. This is an overlay, sitting on whatever page the user
18 # is on already. Hence it is not called in the normal way, but instead
19 # explicitly called by Flightplan pages to insert a waypoint.
20
21 var WaypointEntry =
22 {
23 SHORTCUTS : [ "FPL", "NRST", "RECENT", "USER", "AIRWAY" ],
24
25 new : func (mfd, myCanvas, device, svg)
26 {
27 var obj = {
28 parents : [
29 WaypointEntry,
30 MFDPage.new(mfd, myCanvas, device, svg, "WaypointEntry", "")
31 ],
32 symbols : {},
33 };
34
35 obj.crsrIdx = 0;
36
37 # Dynamic text elements in the SVG file. In the SVG these have an "WaypointEntry" prefix.
38 textelements = [
39 "Name",
40 "City",
41 "Region",
42 "LocationBRG",
43 "LocationDIS",
44 "LocationLat",
45 "LocationLon",
46 ];
47
48 obj.addTextElements(textelements);
49
50 obj._SVGGroup.setInt("z-index", 9);
51
52 # Data Entry information. Keyed from the name of the element, which must
53 # be one of the textelements above. Each data element maps to a set of
54 # text elements in the SVG of the form [PageName][TextElement]{0...n}, each
55 # representing a single character for data entry.
56 #
57 # .size is the number of characters of data entry
58 # .chars is the set of characters, used to scroll through using the small
59 # FMS knob.
60 obj.IDEntry = PFD.DataEntryElement.new(obj.pageName, svg, "ID", "", 4, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
61
62 # The Shortcut window. This allows the user to scroll through a set of lists
63 # of waypoints.
64 obj.WaypointSubmenuGroup = obj._SVGGroup.getElementById("WaypointEntryWaypointSubmenuGroup");
65 assert(obj.WaypointSubmenuGroup != nil, "Unable to find WaypointEntryWaypointSubmenuGroup");
66 obj.WaypointSubmenuGroup.setVisible(0);
67 obj.WaypointSubmenuSelect = PFD.ScrollElement.new(obj.pageName, svg, "WaypointSubmenuSelect", WaypointEntry.SHORTCUTS);
68 obj.WaypointSubmenuScroll = PFD.GroupElement.new(obj.pageName, svg, [ "WaypointSubmenuScroll" ] , 4, "WaypointSubmenuScroll", 0, "WaypointSubmenuScrollTrough" , "WaypointSubmenuScrollThumb", 60);
69
70 # The Airport Chart - only displayed on the MFD variant (where thre's if there's a Map SVG element present)
71 if (obj.elementExists("Map")) {
72 obj.WaypointEntryChart = fg1000.NavMap.new(obj, obj.getElement("Map"), [860,440], "rect(-160px, 160px, 160px, -160px)", 0, 2, 1);
73 } else {
74 obj.WaypointEntryChart = nil;
75 }
76
77 obj.setController(fg1000.WaypointEntryController.new(obj, svg));
78 return obj;
79 },
80
81 displayDestination : func(destination) {
82 if (destination != nil) {
83 # Display a given location
84 if (me.WaypointEntryChart != nil) {
85 me.WaypointEntryChart.setVisible(1);
86 me.WaypointEntryChart.getController().setPosition(destination.lat,destination.lon);
87 }
88 me.setTextElement("Name", string.uc(destination.name));
89 me.setTextElement("City", "");
90 me.setTextElement("Region", "");
91 me.setTextElement("LocationBRG", "" ~ sprintf("%03d°", destination.course));
92 me.setTextElement("LocationDIS", sprintf("%d", destination.range_nm) ~ "nm");
93 me.setTextElementLat("LocationLat", destination.lat);
94 me.setTextElementLon("LocationLon", destination.lon);
95 me.IDEntry.setValue(destination.id);
96 } else {
97 if (me.WaypointEntryChart != nil) me.WaypointEntryChart.setVisible(0);
98 me.setTextElement("Name", "___");
99 me.setTextElement("City", "____________");
100 me.setTextElement("Region", "____________");
101 me.setTextElement("LocationBRG", "___°");
102 me.setTextElement("LocationDIS", "__._nm");
103 me.setTextElement("LocationLat", "_ __°__.__'");
104 me.setTextElement("LocationLon", "____°__.__'");
105 me.IDEntry.setValue("####");
106 }
107 },
108
109 offdisplay : func() {
110 me._group.setVisible(0);
111 if (me.WaypointEntryChart != nil) me.WaypointEntryChart.setVisible(0);
112 me.getElement("Group").setVisible(0);
113 me.getController().offdisplay();
114 },
115 ondisplay : func() {
116 me._group.setVisible(1);
117 me.getElement("Group").setVisible(1);
118 me.getController().ondisplay();
119 },
120 };