| 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 |
# ActiveFlightPlanNarrow |
| 18 |
var ActiveFlightPlanNarrow = |
| 19 |
{ |
| 20 |
SHORTCUTS : [ "FPL", "NRST", "RECENT", "USER", "AIRWAY" ], |
| 21 |
|
| 22 |
new : func (mfd, myCanvas, device, svg) |
| 23 |
{ |
| 24 |
var obj = { |
| 25 |
parents : [ |
| 26 |
ActiveFlightPlanNarrow, |
| 27 |
MFDPage.new(mfd, myCanvas, device, svg, "ActiveFlightPlanNarrow", "FPL - ACTIVE FLIGHT PLAN") |
| 28 |
], |
| 29 |
current_flightplan : nil, |
| 30 |
}; |
| 31 |
|
| 32 |
# Scrolling list of waypoints. We have _two_ lists here as we use one |
| 33 |
# Arrow highlight element to show the current leg, and another to allow |
| 34 |
# the FMS knob to highlight a waypoint for insertion/deletion or to make |
| 35 |
# active. |
| 36 |
obj.flightplanList = PFD.GroupElement.new( |
| 37 |
obj.pageName, |
| 38 |
svg, |
| 39 |
[ "Header", "Leg", "DTK", "DIS", "ALT"], |
| 40 |
11, |
| 41 |
"Leg", |
| 42 |
0, |
| 43 |
"ScrollTrough", |
| 44 |
"ScrollThumb", |
| 45 |
180 |
| 46 |
); |
| 47 |
|
| 48 |
obj.currentLegIndicator = PFD.GroupElement.new( |
| 49 |
obj.pageName, |
| 50 |
svg, |
| 51 |
[ "Arrow"], |
| 52 |
11, |
| 53 |
"Arrow", |
| 54 |
1, |
| 55 |
); |
| 56 |
|
| 57 |
obj.Map = fg1000.NavMap.new( |
| 58 |
obj, |
| 59 |
obj.getElement("NavMap"), |
| 60 |
#[360, 275], |
| 61 |
#[fg1000.MAP_PARTIAL.CENTER.X, fg1000.MAP_PARTIAL.CENTER.Y], |
| 62 |
[860,400], |
| 63 |
#"rect(345, 233, -345, -233)", |
| 64 |
"", |
| 65 |
-50, |
| 66 |
2); |
| 67 |
|
| 68 |
obj.topMenu(device, obj, nil); |
| 69 |
|
| 70 |
obj.setController(fg1000.ActiveFlightPlanNarrowController.new(obj, svg)); |
| 71 |
|
| 72 |
return obj; |
| 73 |
}, |
| 74 |
offdisplay : func() { |
| 75 |
me._group.setVisible(0); |
| 76 |
|
| 77 |
# Reset the menu colours. Shouldn't have to do this here, but |
| 78 |
# there's not currently an obvious other location to do so. |
| 79 |
for(var i = 0; i < 12; i +=1) { |
| 80 |
var name = sprintf("SoftKey%d",i); |
| 81 |
me.device.svg.getElementById(name ~ "-bg").setColorFill(0.0,0.0,0.0); |
| 82 |
me.device.svg.getElementById(name).setColor(1.0,1.0,1.0); |
| 83 |
} |
| 84 |
me.getElement("NavMap").setVisible(0); |
| 85 |
me.Map.setVisible(0); |
| 86 |
me.getController().offdisplay(); |
| 87 |
}, |
| 88 |
ondisplay : func() { |
| 89 |
me._group.setVisible(1); |
| 90 |
me.mfd.setPageTitle(me.title); |
| 91 |
me.getElement("NavMap").setVisible(1); |
| 92 |
me.Map.setVisible(1); |
| 93 |
me.getController().ondisplay(); |
| 94 |
}, |
| 95 |
topMenu : func(device, pg, menuitem) { |
| 96 |
pg.clearMenu(); |
| 97 |
pg.resetMenuColors(); |
| 98 |
pg.addMenuItem(0, "ENGINE", pg, pg.mfd.EIS.engineMenu); |
| 99 |
pg.addMenuItem(2, "MAP", pg, pg.mfd.NavigationMap.mapMenu); |
| 100 |
|
| 101 |
device.updateMenus(); |
| 102 |
}, |
| 103 |
|
| 104 |
# Update the FlightPlan display with an updated flightplan. |
| 105 |
setFlightPlan : func(fp, current_wp) { |
| 106 |
var elements = []; |
| 107 |
var arrowElements = []; |
| 108 |
|
| 109 |
if (fp == nil) { |
| 110 |
me.flightplanList.setValues([]); |
| 111 |
me.flightplanList.setCRSR(0); |
| 112 |
me.flightplanList.displayGroup(); |
| 113 |
me.currentLegIndicator.setValues([]); |
| 114 |
me.currentLegIndicator.setCRSR(0); |
| 115 |
me.currentLegIndicator.displayGroup(); |
| 116 |
return; |
| 117 |
} |
| 118 |
|
| 119 |
for (var i = 0; i < fp.getPlanSize(); i = i + 1) { |
| 120 |
var wp = fp.getWP(i); |
| 121 |
|
| 122 |
var element = { |
| 123 |
Header : "", |
| 124 |
Leg : "", |
| 125 |
DTK : "", |
| 126 |
DIS : "", |
| 127 |
ALT : "_____ft", |
| 128 |
}; |
| 129 |
|
| 130 |
if (wp.wp_name != nil) { |
| 131 |
element.Leg = substr(wp.wp_name, 0, 7); |
| 132 |
} else { |
| 133 |
element.Leg = "____"; |
| 134 |
} |
| 135 |
|
| 136 |
if (i == 0) { |
| 137 |
element.DIS = ""; |
| 138 |
element.DTK = ""; |
| 139 |
element.ALT = "_____ft"; |
| 140 |
} else if (i < current_wp) { |
| 141 |
# Passed waypoints are blanked out on the display |
| 142 |
element.DIS = "___nm"; |
| 143 |
element.DTK = "___°"; |
| 144 |
element.ALT = "_____ft"; |
| 145 |
} else { |
| 146 |
if (wp.leg_distance != nil) element.DIS = sprintf("%.1fnm", wp.leg_distance); |
| 147 |
if (wp.leg_bearing != nil) element.DTK = sprintf("%03d°", wp.leg_bearing); |
| 148 |
if (wp.alt_cstr_type != nil) element.ALT = sprintf("%dft", wp.alt_cstr); |
| 149 |
} |
| 150 |
|
| 151 |
append(elements, element); |
| 152 |
append(arrowElements, { Arrow : i}); |
| 153 |
} |
| 154 |
|
| 155 |
me.flightplanList.setValues(elements); |
| 156 |
me.currentLegIndicator.setValues(arrowElements); |
| 157 |
|
| 158 |
if (current_wp == -1) { |
| 159 |
me.flightplanList.setCRSR(0); |
| 160 |
me.currentLegIndicator.setCRSR(0); |
| 161 |
} else { |
| 162 |
me.flightplanList.setCRSR(current_wp); |
| 163 |
me.currentLegIndicator.setCRSR(current_wp); |
| 164 |
} |
| 165 |
|
| 166 |
me.flightplanList.displayGroup(); |
| 167 |
me.currentLegIndicator.displayGroup(); |
| 168 |
|
| 169 |
# Determine a suitable name to display, using the flightplan name if there is one, |
| 170 |
# but falling back to the flightplan departure / destination airports, or failing |
| 171 |
# that the IDs of the first and last waypoints. |
| 172 |
if ((fp.id == nil) or (fp.id == "default-flightplan")) { |
| 173 |
var from = "????"; |
| 174 |
var dest = "????"; |
| 175 |
|
| 176 |
if ((fp.getWP(0) != nil) and (fp.getWP(0).wp_name != nil)) { |
| 177 |
from = fp.getWP(0).wp_name; |
| 178 |
} |
| 179 |
|
| 180 |
if ((fp.getWP(fp.getPlanSize() -1) != nil) and (fp.getWP(fp.getPlanSize() -1).wp_name != nil)) { |
| 181 |
dest = fp.getWP(fp.getPlanSize() -1).wp_name; |
| 182 |
} |
| 183 |
|
| 184 |
if (fp.departure != nil) from = fp.departure.id; |
| 185 |
if (fp.destination != nil) dest = fp.destination.id; |
| 186 |
me.getElement("Name").setText(from ~ " / " ~ dest); |
| 187 |
} else { |
| 188 |
me.getElement("Name").setText(fp.id); |
| 189 |
} |
| 190 |
}, |
| 191 |
}; |