| 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 |
# AirportInfo Controller |
| 18 |
var AirportInfoController = |
| 19 |
{ |
| 20 |
# Vertical ranges, and labels. |
| 21 |
# Unlike some other map displays, we keep the range constant at 4nm an change |
| 22 |
# the ScreenRange to zoom in. Otherwise as we zoom in, the center of the |
| 23 |
# runways moves out of the range of the display and they are not drawn. |
| 24 |
# Ranges are scaled to the display height with range 1 displaying 4nm vertically. |
| 25 |
# 2000nm = 12,152,000ft. |
| 26 |
RANGES : [{range: 4/500/6076.12, label: "500ft"}, |
| 27 |
{range: 4/750/6076.12, label: "750ft"}, |
| 28 |
{range: 4/1000/6076.12, label: "1000ft"}, |
| 29 |
{range: 4/1500/6076.12, label: "1500ft"}, |
| 30 |
{range: 4/2000/6076.12, label: "2000ft"}, |
| 31 |
{range: 8, label: "0.5nm"}, |
| 32 |
{range: 5.33, label: "0.75nm"}, |
| 33 |
{range: 4, label: "1nm"}, |
| 34 |
{range: 2, label: "2nm"}, |
| 35 |
{range: 1.33, label: "3nm"}, |
| 36 |
{range: 1, label: "4nm"}, |
| 37 |
{range: 0.66, label: "6nm"}, |
| 38 |
{range: 0.5, label: "8nm"}, |
| 39 |
{range: 0.4, label: "10nm"} ], |
| 40 |
|
| 41 |
UIGROUP : { |
| 42 |
APT : 0, |
| 43 |
RNWY : 1, |
| 44 |
FREQ : 2, |
| 45 |
}, |
| 46 |
|
| 47 |
new : func (page, svg) |
| 48 |
{ |
| 49 |
var obj = { parents : [ AirportInfoController, MFDPageController.new(page)] }; |
| 50 |
obj.airport = ""; |
| 51 |
obj.runway = ""; |
| 52 |
obj.runwayIdx = -1; |
| 53 |
obj.info = nil; |
| 54 |
obj.page = page; |
| 55 |
obj.crsrToggle = 0; |
| 56 |
obj._currentGroup = AirportInfoController.UIGROUP.APT; |
| 57 |
obj.current_zoom = 7; |
| 58 |
|
| 59 |
obj.setZoom(obj.current_zoom); |
| 60 |
|
| 61 |
return obj; |
| 62 |
}, |
| 63 |
|
| 64 |
selectAirport : func() { |
| 65 |
me.selectGroup(AirportInfoController.UIGROUP.APT) |
| 66 |
}, |
| 67 |
selectRunways : func() { |
| 68 |
me.selectGroup(AirportInfoController.UIGROUP.RNWY); |
| 69 |
}, |
| 70 |
selectFrequencies : func() { |
| 71 |
me.selectGroup(AirportInfoController.UIGROUP.FREQ); |
| 72 |
}, |
| 73 |
getSelectedGroup : func() { |
| 74 |
return me._currentGroup; |
| 75 |
}, |
| 76 |
selectGroup : func(grp) { |
| 77 |
me._currentGroup = grp; |
| 78 |
if (grp == AirportInfoController.UIGROUP.APT) me.page.airportEntry.highlightElement() else me.page.airportEntry.unhighlightElement(); |
| 79 |
if (grp == AirportInfoController.UIGROUP.RNWY) me.page.runwaySelect.highlightElement() else me.page.runwaySelect.unhighlightElement(); |
| 80 |
if (grp == AirportInfoController.UIGROUP.FREQ) me.page.freqSelect.showCRSR() else me.page.freqSelect.hideCRSR(); |
| 81 |
me._crsrToggle = 1; |
| 82 |
}, |
| 83 |
|
| 84 |
setAirport : func(id) |
| 85 |
{ |
| 86 |
if (id == me.airport) return; |
| 87 |
var apt = me.getAirport(id); |
| 88 |
|
| 89 |
if (apt != nil) { |
| 90 |
me.airport = id; |
| 91 |
|
| 92 |
# Set up the default ID if the user presses DTO. |
| 93 |
me.setDefaultDTOWayPoint(id); |
| 94 |
me.info = apt; |
| 95 |
} |
| 96 |
|
| 97 |
# Reset airport display. We do this irrespective of whether the id |
| 98 |
# is valid, as it allows us to clear any bad user input from the ID field |
| 99 |
me.page.displayAirport(me.info); |
| 100 |
}, |
| 101 |
setRunway : func(runwayID) |
| 102 |
{ |
| 103 |
me.page.displayRunway(me.info.runways[runwayID]); |
| 104 |
}, |
| 105 |
|
| 106 |
# Control functions for Input |
| 107 |
zoomIn : func() { |
| 108 |
me.setZoom(me.current_zoom -1); |
| 109 |
}, |
| 110 |
zoomOut : func() { |
| 111 |
me.setZoom(me.current_zoom +1); |
| 112 |
}, |
| 113 |
handleRange : func(val) |
| 114 |
{ |
| 115 |
var incr_or_decr = (val > 0) ? 1 : -1; |
| 116 |
me.setZoom(me.current_zoom + incr_or_decr); |
| 117 |
}, |
| 118 |
setZoom : func(zoom) { |
| 119 |
if ((zoom < 0) or (zoom > (size(me.RANGES) - 1))) return; |
| 120 |
me.current_zoom = zoom; |
| 121 |
me.page.setZoom(me.RANGES[zoom].range * fg1000.MAP_PARTIAL.HEIGHT, me.RANGES[zoom].label); |
| 122 |
}, |
| 123 |
handleCRSR : func() { |
| 124 |
me.crsrToggle = (! me.crsrToggle); |
| 125 |
if (me.crsrToggle) { |
| 126 |
me.selectAirport(); |
| 127 |
} else { |
| 128 |
me.page.resetCRSR(); |
| 129 |
} |
| 130 |
return emesary.Transmitter.ReceiptStatus_Finished; |
| 131 |
}, |
| 132 |
handleKeyInput : func (value) { |
| 133 |
if (me._currentGroup == AirportInfoController.UIGROUP.APT) { |
| 134 |
me.page.airportEntry.keyPress(value); |
| 135 |
return emesary.Transmitter.ReceiptStatus_Finished; |
| 136 |
} |
| 137 |
return emesary.Transmitter.ReceiptStatus_NotProcessed; |
| 138 |
}, |
| 139 |
handleFMSInner : func(value) { |
| 140 |
if (me.crsrToggle == 1) { |
| 141 |
if (me._currentGroup == AirportInfoController.UIGROUP.APT) { |
| 142 |
me.page.airportEntry.incrSmall(value); |
| 143 |
} |
| 144 |
|
| 145 |
if (me._currentGroup == AirportInfoController.UIGROUP.RNWY) { |
| 146 |
me.page.runwaySelect.incrSmall(value); |
| 147 |
var val = me.page.runwaySelect.getValue(); |
| 148 |
if (val != nil) { |
| 149 |
# Selection values are of the form "06L-12R". We need to set the |
| 150 |
# runway to the left half. |
| 151 |
var idx = find("-", val); |
| 152 |
if (idx != -1) { |
| 153 |
var rwy = substr(val, 0, idx); |
| 154 |
me.setRunway(rwy); |
| 155 |
} |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
if (me._currentGroup == AirportInfoController.UIGROUP.FREQ) { |
| 160 |
me.page.freqSelect.incrSmall(value); |
| 161 |
} |
| 162 |
|
| 163 |
return emesary.Transmitter.ReceiptStatus_Finished; |
| 164 |
} else { |
| 165 |
return me.page.mfd.SurroundController.handleFMSInner(value); |
| 166 |
} |
| 167 |
}, |
| 168 |
handleFMSOuter : func(value) { |
| 169 |
if (me.crsrToggle == 1) { |
| 170 |
if ((me._currentGroup == AirportInfoController.UIGROUP.APT) and me.page.airportEntry.isInEdit()) { |
| 171 |
me.page.airportEntry.incrLarge(value); |
| 172 |
} else { |
| 173 |
var incr_or_decr = (value > 0) ? 1 : -1; |
| 174 |
var idx = math.mod(me._currentGroup + incr_or_decr, size(AirportInfoController.UIGROUP)); |
| 175 |
me.selectGroup(idx); |
| 176 |
} |
| 177 |
|
| 178 |
return emesary.Transmitter.ReceiptStatus_Finished; |
| 179 |
} else { |
| 180 |
return me.page.mfd.SurroundController.handleFMSOuter(value); |
| 181 |
} |
| 182 |
}, |
| 183 |
handleEnter : func(value) { |
| 184 |
if (me.crsrToggle == 1) { |
| 185 |
if ((me._currentGroup == AirportInfoController.UIGROUP.APT) and me.page.airportEntry.isInEdit()) { |
| 186 |
var aptname = me.page.airportEntry.enterElement(); |
| 187 |
me.setAirport(aptname); |
| 188 |
} |
| 189 |
|
| 190 |
if (me._currentGroup == AirportInfoController.UIGROUP.FREQ) { |
| 191 |
me.page.mfd.SurroundController.setStandbyNavComFreq(me.page.freqSelect.getValue()); |
| 192 |
} |
| 193 |
|
| 194 |
return emesary.Transmitter.ReceiptStatus_Finished; |
| 195 |
} else { |
| 196 |
return emesary.Transmitter.ReceiptStatus_NotProcessed; |
| 197 |
} |
| 198 |
}, |
| 199 |
handleClear : func(value) { |
| 200 |
if ((me.crsrToggle == 1) and |
| 201 |
(me._currentGroup == AirportInfoController.UIGROUP.APT) and |
| 202 |
me.page.airportEntry.isInEdit()) { |
| 203 |
me.page.airportEntry.clearElement(); |
| 204 |
return emesary.Transmitter.ReceiptStatus_Finished; |
| 205 |
} else { |
| 206 |
return emesary.Transmitter.ReceiptStatus_NotProcessed; |
| 207 |
} |
| 208 |
}, |
| 209 |
|
| 210 |
handleStringInput : func(value) { |
| 211 |
me.selectAirport(); |
| 212 |
me.page.airportEntry.clearElement(); |
| 213 |
me.page.airportEntry.setValue(value); |
| 214 |
me.setAirport(value); |
| 215 |
me.page.resetCRSR(); |
| 216 |
return emesary.Transmitter.ReceiptStatus_Finished; |
| 217 |
}, |
| 218 |
|
| 219 |
# Reset controller if required when the page is displayed or hidden |
| 220 |
ondisplay : func() { |
| 221 |
me.RegisterWithEmesary(); |
| 222 |
|
| 223 |
if (me.airport == "") { |
| 224 |
# Initial airport is our current location. |
| 225 |
# Needs to be done here as the data provider may not be set up when |
| 226 |
# we are created. |
| 227 |
|
| 228 |
# Use Emesary to get the airport |
| 229 |
var notification = notifications.PFDEventNotification.new( |
| 230 |
"MFD", |
| 231 |
me.getDeviceID(), |
| 232 |
notifications.PFDEventNotification.NavData, |
| 233 |
{Id: "NearestAirports", Value: nil}); |
| 234 |
|
| 235 |
var response = me._transmitter.NotifyAll(notification); |
| 236 |
var retval = notification.EventParameter.Value; |
| 237 |
|
| 238 |
if ((! me._transmitter.IsFailed(response)) and (size(retval) > 0)) { |
| 239 |
var current_apt = retval[0]; |
| 240 |
me.setAirport(current_apt.id); |
| 241 |
} |
| 242 |
} |
| 243 |
}, |
| 244 |
offdisplay : func() { |
| 245 |
me.DeRegisterWithEmesary(); |
| 246 |
}, |
| 247 |
|
| 248 |
getAirport : func(id) { |
| 249 |
# Use Emesary to get the airport |
| 250 |
var notification = notifications.PFDEventNotification.new( |
| 251 |
"MFD", |
| 252 |
me.getDeviceID(), |
| 253 |
notifications.PFDEventNotification.NavData, |
| 254 |
{Id: "AirportByID", Value: id}); |
| 255 |
|
| 256 |
var response = me._transmitter.NotifyAll(notification); |
| 257 |
var retval = notification.EventParameter.Value; |
| 258 |
|
| 259 |
if ((! me._transmitter.IsFailed(response)) and (size(retval) > 0)) { |
| 260 |
return retval[0]; |
| 261 |
} else { |
| 262 |
return nil; |
| 263 |
} |
| 264 |
}, |
| 265 |
}; |