2018-02-09 18:55:53 +00:00
|
|
|
# Copyright 2018 Stuart Buchanan
|
|
|
|
# This file is part of FlightGear.
|
|
|
|
#
|
|
|
|
# Foobar is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# FlightGear is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with FlightGear. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
2017-11-24 23:04:46 +00:00
|
|
|
# Traffic Map Controller
|
|
|
|
var TrafficMapController =
|
|
|
|
{
|
|
|
|
# Altitude levels levels.
|
|
|
|
ALTS : { ABOVE : { label: "ABOVE", ceiling_ft: 9000, floor_ft: 2700 },
|
|
|
|
NORMAL : { label: "NORMAL", ceiling_ft: 2700, floor_ft: 2700 },
|
|
|
|
BELOW : { label: "BELOW", ceiling_ft: 2700, floor_ft: 9000 },
|
|
|
|
UNREST : { label: "UNRESTRICTED", ceiling_ft: 9000, floor_ft: 9000 }},
|
|
|
|
|
|
|
|
|
|
|
|
# Three ranges available
|
|
|
|
# 2nm
|
|
|
|
# 2nm / 6nm
|
|
|
|
# 6nm / 12nm
|
|
|
|
#
|
|
|
|
# TODO: Currently we simply use the outer range, and display the inner
|
|
|
|
# range as 1/3 of the outer. Doing this properly, we should display
|
|
|
|
# different inner rings.
|
|
|
|
RANGES : [ {range: 2, inner_label: nil, outer_label: "2nm"},
|
|
|
|
{range: 6, inner_label: "2nm", outer_label: "6nm"},
|
|
|
|
{range: 12, inner_label: "4nm", outer_label: "12nm"} ],
|
|
|
|
|
|
|
|
|
2017-12-10 22:15:21 +00:00
|
|
|
new : func (page, svg)
|
2017-11-24 23:04:46 +00:00
|
|
|
{
|
2018-01-08 21:39:39 +00:00
|
|
|
var obj = { parents : [ TrafficMapController, MFDPageController.new(page) ] };
|
2017-11-24 23:04:46 +00:00
|
|
|
obj.range = 1;
|
|
|
|
obj.alt = "NORMAL";
|
|
|
|
obj.operating = 0;
|
|
|
|
obj.flight_id = 0;
|
2017-12-10 22:15:21 +00:00
|
|
|
obj.page = page;
|
|
|
|
obj.page.setScreenRange(689/2.0);
|
2017-11-24 23:04:46 +00:00
|
|
|
|
2017-12-10 22:15:21 +00:00
|
|
|
# Emesary
|
|
|
|
obj._recipient = nil;
|
2017-12-27 19:51:54 +00:00
|
|
|
|
2017-11-24 23:04:46 +00:00
|
|
|
obj.setZoom(obj.range);
|
2018-01-08 21:39:39 +00:00
|
|
|
obj.setAlt(obj.alt);
|
|
|
|
obj.setOperate(obj.operating);
|
2017-11-24 23:04:46 +00:00
|
|
|
return obj;
|
|
|
|
},
|
|
|
|
zoomIn : func() {
|
|
|
|
me.setZoom(me.current_zoom -1);
|
|
|
|
},
|
|
|
|
zoomOut : func() {
|
|
|
|
me.setZoom(me.current_zoom +1);
|
|
|
|
},
|
|
|
|
setZoom : func(zoom) {
|
|
|
|
if ((zoom < 0) or (zoom > (size(me.RANGES) - 1))) return;
|
|
|
|
me.current_zoom = zoom;
|
2017-12-10 22:15:21 +00:00
|
|
|
me.page.setRange(
|
2017-11-24 23:04:46 +00:00
|
|
|
me.RANGES[zoom].range,
|
|
|
|
me.RANGES[zoom].inner_label,
|
|
|
|
me.RANGES[zoom].outer_label);
|
|
|
|
},
|
|
|
|
setAlt : func(alt) {
|
|
|
|
if (me.ALTS[alt] == nil) return;
|
2018-01-08 21:39:39 +00:00
|
|
|
me.page.setAlt(me.ALTS[alt].floor_ft, me.ALTS[alt].ceiling_ft, me.ALTS[alt].label);
|
2017-11-24 23:04:46 +00:00
|
|
|
me.alt = alt;
|
|
|
|
},
|
|
|
|
setOperate : func(enabled) {
|
2018-01-08 21:39:39 +00:00
|
|
|
me.page.setOperate(enabled);
|
|
|
|
me.operating = enabled;
|
2017-11-24 23:04:46 +00:00
|
|
|
},
|
|
|
|
setFlightID : func(enabled) {
|
|
|
|
me.flight_id = enabled;
|
2017-12-10 22:15:21 +00:00
|
|
|
me.page.Options.setOption("TFC", "display_id", enabled);
|
2017-11-24 23:04:46 +00:00
|
|
|
},
|
|
|
|
toggleFlightID : func() {
|
|
|
|
me.setFlightID(! me.flight_id);
|
|
|
|
},
|
|
|
|
isEnabled : func(label) {
|
|
|
|
# Cheeky little function that returns whether the alt or operation mode
|
|
|
|
# matches the label. Used to highlight current settings in softkeys
|
|
|
|
if (label == me.alt) return 1;
|
|
|
|
if (me.operating and label == "OPERATE") return 1;
|
|
|
|
if (me.operating == 0 and label == "STANDBY") return 1;
|
|
|
|
if (me.flight_id == 1 and label == "FLT ID") return 1;
|
|
|
|
return 0;
|
|
|
|
},
|
2018-01-08 21:39:39 +00:00
|
|
|
handleRange : func(val)
|
|
|
|
{
|
|
|
|
var incr_or_decr = (val > 0) ? 1 : -1;
|
|
|
|
me.setZoom(me.current_zoom + incr_or_decr);
|
2017-12-10 22:15:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
# Reset controller if required when the page is displayed or hidden
|
|
|
|
ondisplay : func() {
|
|
|
|
me.RegisterWithEmesary();
|
|
|
|
},
|
|
|
|
offdisplay : func() {
|
|
|
|
me.DeRegisterWithEmesary();
|
|
|
|
},
|
2017-11-24 23:04:46 +00:00
|
|
|
};
|