| 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 |
# Traffic Map Controller |
| 18 |
var TrafficMapController = |
| 19 |
{ |
| 20 |
# Altitude levels levels. |
| 21 |
ALTS : { ABOVE : { label: "ABOVE", ceiling_ft: 9000, floor_ft: 2700 }, |
| 22 |
NORMAL : { label: "NORMAL", ceiling_ft: 2700, floor_ft: 2700 }, |
| 23 |
BELOW : { label: "BELOW", ceiling_ft: 2700, floor_ft: 9000 }, |
| 24 |
UNREST : { label: "UNRESTRICTED", ceiling_ft: 9000, floor_ft: 9000 }}, |
| 25 |
|
| 26 |
|
| 27 |
# Three ranges available |
| 28 |
# 2nm |
| 29 |
# 2nm / 6nm |
| 30 |
# 6nm / 12nm |
| 31 |
# |
| 32 |
# TODO: Currently we simply use the outer range, and display the inner |
| 33 |
# range as 1/3 of the outer. Doing this properly, we should display |
| 34 |
# different inner rings. |
| 35 |
RANGES : [ {range: 2, inner_label: nil, outer_label: "2nm"}, |
| 36 |
{range: 6, inner_label: "2nm", outer_label: "6nm"}, |
| 37 |
{range: 12, inner_label: "4nm", outer_label: "12nm"} ], |
| 38 |
|
| 39 |
|
| 40 |
new : func (page, svg) |
| 41 |
{ |
| 42 |
var obj = { parents : [ TrafficMapController, MFDPageController.new(page) ] }; |
| 43 |
obj.range = 1; |
| 44 |
obj.alt = "NORMAL"; |
| 45 |
obj.operating = 0; |
| 46 |
obj.flight_id = 0; |
| 47 |
obj.page = page; |
| 48 |
obj.page.setScreenRange(689/2.0); |
| 49 |
|
| 50 |
# Emesary |
| 51 |
obj._recipient = nil; |
| 52 |
|
| 53 |
obj.setZoom(obj.range); |
| 54 |
obj.setAlt(obj.alt); |
| 55 |
obj.setOperate(obj.operating); |
| 56 |
return obj; |
| 57 |
}, |
| 58 |
zoomIn : func() { |
| 59 |
me.setZoom(me.current_zoom -1); |
| 60 |
}, |
| 61 |
zoomOut : func() { |
| 62 |
me.setZoom(me.current_zoom +1); |
| 63 |
}, |
| 64 |
setZoom : func(zoom) { |
| 65 |
if ((zoom < 0) or (zoom > (size(me.RANGES) - 1))) return; |
| 66 |
me.current_zoom = zoom; |
| 67 |
me.page.setRange( |
| 68 |
me.RANGES[zoom].range, |
| 69 |
me.RANGES[zoom].inner_label, |
| 70 |
me.RANGES[zoom].outer_label); |
| 71 |
}, |
| 72 |
setAlt : func(alt) { |
| 73 |
if (me.ALTS[alt] == nil) return; |
| 74 |
me.page.setAlt(me.ALTS[alt].floor_ft, me.ALTS[alt].ceiling_ft, me.ALTS[alt].label); |
| 75 |
me.alt = alt; |
| 76 |
}, |
| 77 |
setOperate : func(enabled) { |
| 78 |
me.page.setOperate(enabled); |
| 79 |
me.operating = enabled; |
| 80 |
}, |
| 81 |
setFlightID : func(enabled) { |
| 82 |
me.flight_id = enabled; |
| 83 |
me.page.Options.setOption("TFC", "display_id", enabled); |
| 84 |
}, |
| 85 |
toggleFlightID : func() { |
| 86 |
me.setFlightID(! me.flight_id); |
| 87 |
}, |
| 88 |
isEnabled : func(label) { |
| 89 |
# Cheeky little function that returns whether the alt or operation mode |
| 90 |
# matches the label. Used to highlight current settings in softkeys |
| 91 |
if (label == me.alt) return 1; |
| 92 |
if (me.operating and label == "OPERATE") return 1; |
| 93 |
if (me.operating == 0 and label == "STANDBY") return 1; |
| 94 |
if (me.flight_id == 1 and label == "FLT ID") return 1; |
| 95 |
return 0; |
| 96 |
}, |
| 97 |
handleRange : func(val) |
| 98 |
{ |
| 99 |
var incr_or_decr = (val > 0) ? 1 : -1; |
| 100 |
me.setZoom(me.current_zoom + incr_or_decr); |
| 101 |
}, |
| 102 |
|
| 103 |
# Reset controller if required when the page is displayed or hidden |
| 104 |
ondisplay : func() { |
| 105 |
me.RegisterWithEmesary(); |
| 106 |
}, |
| 107 |
offdisplay : func() { |
| 108 |
me.DeRegisterWithEmesary(); |
| 109 |
}, |
| 110 |
}; |