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