2013-12-01 12:29:22 +00:00
|
|
|
# ==============================================================================
|
2013-12-28 15:18:35 +00:00
|
|
|
# Boeing Navigation Display by Gijs de Rooy
|
2014-04-29 02:26:32 +00:00
|
|
|
# See: http://wiki.flightgear.org/Canvas_ND_Framework
|
2013-12-01 12:29:22 +00:00
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##
|
2014-05-25 18:11:13 +00:00
|
|
|
# this file contains a hash that declares features in a generic fashion
|
|
|
|
# we want to get rid of the bloated update() method sooner than later
|
|
|
|
# PLEASE DO NOT ADD any code to update() !!
|
|
|
|
# Instead, help clean up the file and move things over to the navdisplay.styles file
|
|
|
|
#
|
|
|
|
# This is the only sane way to keep on generalizing the framework, so that we can
|
|
|
|
# also support different makes/models of NDs in the future
|
2013-12-01 12:29:22 +00:00
|
|
|
#
|
2014-05-25 18:11:13 +00:00
|
|
|
# a huge bloated update() method is going to make that basically IMPOSSIBLE
|
2013-12-01 12:29:22 +00:00
|
|
|
#
|
2014-05-25 18:11:13 +00:00
|
|
|
io.include("Nasal/canvas/map/navdisplay.styles");
|
2013-12-01 12:29:22 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# encapsulate hdg/lat/lon source, so that the ND may also display AI/MP aircraft in a pilot-view at some point (aka stress-testing)
|
2014-05-25 18:11:13 +00:00
|
|
|
# TODO: this predates aircraftpos.controller (MapStructure) should probably be unified to some degree ...
|
2013-12-01 12:29:22 +00:00
|
|
|
|
|
|
|
var NDSourceDriver = {};
|
2014-01-10 03:04:36 +00:00
|
|
|
NDSourceDriver.new = func {
|
2014-01-08 20:45:48 +00:00
|
|
|
var m = {parents:[NDSourceDriver]};
|
|
|
|
m.get_hdg_mag= func getprop("/orientation/heading-magnetic-deg");
|
|
|
|
m.get_hdg_tru= func getprop("/orientation/heading-deg");
|
|
|
|
m.get_hgg = func getprop("instrumentation/afds/settings/heading");
|
|
|
|
m.get_trk_mag= func
|
|
|
|
{
|
|
|
|
if(getprop("/velocities/groundspeed-kt") > 80)
|
2014-01-10 03:04:36 +00:00
|
|
|
getprop("/orientation/track-magnetic-deg");
|
2014-01-08 20:45:48 +00:00
|
|
|
else
|
|
|
|
getprop("/orientation/heading-magnetic-deg");
|
|
|
|
};
|
|
|
|
m.get_trk_tru = func
|
|
|
|
{
|
|
|
|
if(getprop("/velocities/groundspeed-kt") > 80)
|
|
|
|
getprop("/orientation/track-deg");
|
|
|
|
else
|
|
|
|
getprop("/orientation/heading-deg");
|
|
|
|
};
|
|
|
|
m.get_lat= func getprop("/position/latitude-deg");
|
|
|
|
m.get_lon= func getprop("/position/longitude-deg");
|
2014-06-20 19:52:35 +00:00
|
|
|
m.get_spd= func getprop("/instrumentation/airspeed-indicator/true-speed-kt");
|
2014-01-31 22:36:41 +00:00
|
|
|
m.get_gnd_spd= func getprop("/velocities/groundspeed-kt");
|
2014-01-08 20:45:48 +00:00
|
|
|
m.get_vspd= func getprop("/velocities/vertical-speed-fps");
|
|
|
|
return m;
|
2013-12-01 12:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
##
|
|
|
|
# configure aircraft specific cockpit switches here
|
2014-01-10 03:04:36 +00:00
|
|
|
# these are some defaults, can be overridden when calling NavDisplay.new() -
|
|
|
|
# see the 744 ND.nas file the backend code should never deal directly with
|
2013-12-01 12:29:22 +00:00
|
|
|
# aircraft specific properties using getprop.
|
|
|
|
# To get started implementing your own ND, just copy the switches hash to your
|
|
|
|
# ND.nas file and map the keys to your cockpit properties - and things will just work.
|
|
|
|
|
|
|
|
# TODO: switches are ND specific, so move to the NDStyle hash!
|
|
|
|
|
|
|
|
var default_switches = {
|
2014-01-10 03:04:36 +00:00
|
|
|
'toggle_range': {path: '/inputs/range-nm', value:40, type:'INT'},
|
|
|
|
'toggle_weather': {path: '/inputs/wxr', value:0, type:'BOOL'},
|
|
|
|
'toggle_airports': {path: '/inputs/arpt', value:0, type:'BOOL'},
|
|
|
|
'toggle_stations': {path: '/inputs/sta', value:0, type:'BOOL'},
|
|
|
|
'toggle_waypoints': {path: '/inputs/wpt', value:0, type:'BOOL'},
|
|
|
|
'toggle_position': {path: '/inputs/pos', value:0, type:'BOOL'},
|
|
|
|
'toggle_data': {path: '/inputs/data',value:0, type:'BOOL'},
|
|
|
|
'toggle_terrain': {path: '/inputs/terr',value:0, type:'BOOL'},
|
2014-01-26 01:19:12 +00:00
|
|
|
'toggle_traffic': {path: '/inputs/tfc',value:0, type:'BOOL'},
|
2014-01-10 03:04:36 +00:00
|
|
|
'toggle_centered': {path: '/inputs/nd-centered',value:0, type:'BOOL'},
|
|
|
|
'toggle_lh_vor_adf': {path: '/inputs/lh-vor-adf',value:0, type:'INT'},
|
|
|
|
'toggle_rh_vor_adf': {path: '/inputs/rh-vor-adf',value:0, type:'INT'},
|
|
|
|
'toggle_display_mode': {path: '/mfd/display-mode', value:'MAP', type:'STRING'}, # valid values are: APP, MAP, PLAN or VOR
|
|
|
|
'toggle_display_type': {path: '/mfd/display-type', value:'CRT', type:'STRING'}, # valid values are: CRT or LCD
|
|
|
|
'toggle_true_north': {path: '/mfd/true-north', value:0, type:'BOOL'},
|
2014-05-25 18:11:13 +00:00
|
|
|
'toggle_rangearc': {path: '/mfd/rangearc', value:0, type:'BOOL'},
|
|
|
|
'toggle_track_heading':{path: '/trk-selected', value:0, type:'BOOL'},
|
2013-12-01 12:29:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
##
|
2014-01-10 03:04:36 +00:00
|
|
|
# TODO:
|
2013-12-01 12:29:22 +00:00
|
|
|
# - introduce a MFD class (use it also for PFD/EICAS)
|
|
|
|
# - introduce a SGSubsystem class and use it here
|
|
|
|
# - introduce a Boeing NavDisplay class
|
2014-01-10 03:04:36 +00:00
|
|
|
var NavDisplay = {
|
2014-04-29 02:26:32 +00:00
|
|
|
# static
|
|
|
|
id:0,
|
2014-01-10 03:04:36 +00:00
|
|
|
|
2014-01-26 03:13:49 +00:00
|
|
|
del: func {
|
2014-01-24 03:13:54 +00:00
|
|
|
print("Cleaning up NavDisplay");
|
2014-01-08 20:45:48 +00:00
|
|
|
# shut down all timers and other loops here
|
2014-01-10 03:04:36 +00:00
|
|
|
me.update_timer.stop();
|
2014-05-25 18:11:13 +00:00
|
|
|
foreach(var t; me.timers)
|
|
|
|
t.stop();
|
2014-01-08 20:45:48 +00:00
|
|
|
foreach(var l; me.listeners)
|
|
|
|
removelistener(l);
|
2014-01-24 03:13:54 +00:00
|
|
|
# clean up MapStructure
|
|
|
|
me.map.del();
|
|
|
|
# destroy the canvas
|
|
|
|
if (me.canvas_handle != nil)
|
|
|
|
me.canvas_handle.del();
|
|
|
|
me.inited = 0;
|
2014-04-29 02:26:32 +00:00
|
|
|
NavDisplay.id -= 1;
|
2014-01-10 03:04:36 +00:00
|
|
|
},
|
|
|
|
|
2014-05-25 18:11:13 +00:00
|
|
|
addtimer: func(interval, cb) {
|
|
|
|
append(me.timers, var job=maketimer(interval, cb));
|
|
|
|
return job; # so that we can directly work with the timer (start/stop)
|
|
|
|
},
|
|
|
|
|
2014-01-10 03:04:36 +00:00
|
|
|
listen: func(p,c) {
|
|
|
|
append(me.listeners, setlistener(p,c));
|
|
|
|
},
|
|
|
|
|
|
|
|
# listeners for cockpit switches
|
|
|
|
listen_switch: func(s,c) {
|
|
|
|
# print("event setup for: ", id(c));
|
|
|
|
me.listen( me.get_full_switch_path(s), func {
|
|
|
|
# print("listen_switch triggered:", s, " callback id:", id(c) );
|
2014-01-08 20:45:48 +00:00
|
|
|
c();
|
2014-01-10 03:04:36 +00:00
|
|
|
});
|
2014-01-08 20:45:48 +00:00
|
|
|
},
|
2013-12-01 12:29:22 +00:00
|
|
|
|
2014-01-10 03:04:36 +00:00
|
|
|
# get the full property path for a given switch
|
|
|
|
get_full_switch_path: func (s) {
|
|
|
|
# debug.dump( me.efis_switches[s] );
|
|
|
|
return me.efis_path ~ me.efis_switches[s].path; # FIXME: should be using props.nas instead of ~
|
|
|
|
},
|
2013-12-01 12:29:22 +00:00
|
|
|
|
2014-01-10 03:04:36 +00:00
|
|
|
# helper method for getting configurable cockpit switches (which are usually different in each aircraft)
|
|
|
|
get_switch: func(s) {
|
2014-01-08 20:45:48 +00:00
|
|
|
var switch = me.efis_switches[s];
|
|
|
|
var path = me.efis_path ~ switch.path ;
|
2014-01-10 03:04:36 +00:00
|
|
|
#print(s,":Getting switch prop:", path);
|
|
|
|
|
2014-01-08 20:45:48 +00:00
|
|
|
return getprop( path );
|
|
|
|
},
|
2013-12-01 12:29:22 +00:00
|
|
|
|
2014-01-10 03:04:36 +00:00
|
|
|
# for creating NDs that are driven by AI traffic instead of the main aircraft (generalization rocks!)
|
|
|
|
connectAI: func(source=nil) {
|
|
|
|
me.aircraft_source = {
|
2013-12-28 15:18:35 +00:00
|
|
|
get_hdg_mag: func source.getNode('orientation/heading-magnetic-deg').getValue(),
|
|
|
|
get_trk_mag: func source.getNode('orientation/track-magnetic-deg').getValue(),
|
|
|
|
get_lat: func source.getNode('position/latitude-deg').getValue(),
|
|
|
|
get_lon: func source.getNode('position/longitude-deg').getValue(),
|
|
|
|
get_spd: func source.getNode('velocities/true-airspeed-kt').getValue(),
|
2014-01-31 22:36:41 +00:00
|
|
|
get_gnd_spd: func source.getNode('velocities/groundspeed-kt').getValue(),
|
2013-12-28 15:18:35 +00:00
|
|
|
};
|
2014-01-10 03:04:36 +00:00
|
|
|
}, # of connectAI
|
2013-12-01 12:29:22 +00:00
|
|
|
|
2014-05-25 18:11:13 +00:00
|
|
|
setTimerInterval: func(update_time=0.05) me.update_timer.restart(update_time),
|
|
|
|
|
2014-01-08 20:45:48 +00:00
|
|
|
# TODO: the ctor should allow customization, for different aircraft
|
2014-01-10 03:04:36 +00:00
|
|
|
# especially properties and SVG files/handles (747, 757, 777 etc)
|
|
|
|
new : func(prop1, switches=default_switches, style='Boeing') {
|
2014-04-29 02:26:32 +00:00
|
|
|
NavDisplay.id +=1;
|
2014-01-08 20:45:48 +00:00
|
|
|
var m = { parents : [NavDisplay]};
|
2013-12-01 12:29:22 +00:00
|
|
|
|
2014-01-24 03:13:54 +00:00
|
|
|
m.inited = 0;
|
|
|
|
|
2014-05-25 18:11:13 +00:00
|
|
|
m.timers=[];
|
2014-01-08 20:45:48 +00:00
|
|
|
m.listeners=[]; # for cleanup handling
|
|
|
|
m.aircraft_source = NDSourceDriver.new(); # uses the main aircraft as the driver/source (speeds, position, heading)
|
2013-12-01 12:29:22 +00:00
|
|
|
|
2014-01-08 20:45:48 +00:00
|
|
|
m.nd_style = NDStyles[style]; # look up ND specific stuff (file names etc)
|
2014-01-10 03:04:36 +00:00
|
|
|
|
|
|
|
m.radio_list=["instrumentation/comm/frequencies","instrumentation/comm[1]/frequencies",
|
|
|
|
"instrumentation/nav/frequencies", "instrumentation/nav[1]/frequencies"];
|
|
|
|
m.mfd_mode_list=["APP","VOR","MAP","PLAN"];
|
|
|
|
|
2014-01-08 20:45:48 +00:00
|
|
|
m.efis_path = prop1;
|
|
|
|
m.efis_switches = switches;
|
2014-01-10 03:04:36 +00:00
|
|
|
|
|
|
|
# just an alias, to avoid having to rewrite the old code for now
|
2014-01-08 20:45:48 +00:00
|
|
|
m.rangeNm = func m.get_switch('toggle_range');
|
2014-01-10 03:04:36 +00:00
|
|
|
|
|
|
|
m.efis = props.globals.initNode(prop1);
|
|
|
|
m.mfd = m.efis.initNode("mfd");
|
|
|
|
|
|
|
|
# TODO: unify this with switch handling
|
|
|
|
m.mfd_mode_num = m.mfd .initNode("mode-num",2,"INT");
|
|
|
|
m.std_mode = m.efis.initNode("inputs/setting-std",0,"BOOL");
|
|
|
|
m.previous_set = m.efis.initNode("inhg-previous",29.92);
|
|
|
|
m.kpa_mode = m.efis.initNode("inputs/kpa-mode",0,"BOOL");
|
|
|
|
m.kpa_output = m.efis.initNode("inhg-kpa",29.92);
|
|
|
|
m.kpa_prevoutput = m.efis.initNode("inhg-kpa-previous",29.92);
|
|
|
|
m.temp = m.efis.initNode("fixed-temp",0);
|
|
|
|
m.alt_meters = m.efis.initNode("inputs/alt-meters",0,"BOOL");
|
|
|
|
m.fpv = m.efis.initNode("inputs/fpv",0,"BOOL");
|
|
|
|
|
|
|
|
m.mins_mode = m.efis.initNode("inputs/minimums-mode",0,"BOOL");
|
|
|
|
m.mins_mode_txt = m.efis.initNode("minimums-mode-text","RADIO","STRING");
|
|
|
|
m.minimums = m.efis.initNode("minimums",250,"INT");
|
|
|
|
m.mk_minimums = props.globals.getNode("instrumentation/mk-viii/inputs/arinc429/decision-height");
|
|
|
|
|
|
|
|
# TODO: these are switches, can be unified with switch handling hash above (eventually):
|
|
|
|
m.nd_plan_wpt = m.efis.initNode("inputs/plan-wpt-index", 0, "INT"); # not yet in switches hash
|
|
|
|
|
|
|
|
###
|
|
|
|
# initialize all switches based on the defaults specified in the switch hash
|
|
|
|
#
|
|
|
|
foreach(var switch; keys( m.efis_switches ) )
|
|
|
|
props.globals.initNode
|
|
|
|
( m.get_full_switch_path (switch),
|
|
|
|
m.efis_switches[switch].value,
|
|
|
|
m.efis_switches[switch].type
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return m;
|
2014-01-08 20:45:48 +00:00
|
|
|
},
|
2014-05-25 18:11:13 +00:00
|
|
|
newMFD: func(canvas_group, parent=nil, options=nil, update_time=0.05)
|
2013-12-01 12:29:22 +00:00
|
|
|
{
|
2014-01-24 03:13:54 +00:00
|
|
|
if (me.inited) die("MFD already was added to scene");
|
|
|
|
me.inited = 1;
|
2014-05-25 18:11:13 +00:00
|
|
|
me.update_timer = maketimer(update_time, func me.update() );
|
2013-12-01 12:29:22 +00:00
|
|
|
me.nd = canvas_group;
|
2014-01-24 03:13:54 +00:00
|
|
|
me.canvas_handle = parent;
|
2014-01-10 03:04:36 +00:00
|
|
|
|
2013-12-01 12:29:22 +00:00
|
|
|
# load the specified SVG file into the me.nd group and populate all sub groups
|
2014-01-10 03:04:36 +00:00
|
|
|
|
2013-12-01 12:29:22 +00:00
|
|
|
canvas.parsesvg(me.nd, me.nd_style.svg_filename, {'font-mapper': me.nd_style.font_mapper});
|
|
|
|
me.symbols = {}; # storage for SVG elements, to avoid namespace pollution (all SVG elements end up here)
|
|
|
|
|
|
|
|
foreach(var feature; me.nd_style.features ) {
|
2014-01-31 22:36:41 +00:00
|
|
|
me.symbols[feature.id] = me.nd.getElementById(feature.id).updateCenter();
|
2014-01-10 03:04:36 +00:00
|
|
|
if(contains(feature.impl,'init')) feature.impl.init(me.nd, feature); # call The element's init code (i.e. updateCenter)
|
2013-12-01 12:29:22 +00:00
|
|
|
}
|
2014-01-10 03:04:36 +00:00
|
|
|
|
2013-12-01 12:29:22 +00:00
|
|
|
### this is the "old" method that's less flexible, we want to use the style hash instead (see above)
|
|
|
|
# because things are much better configurable that way
|
|
|
|
# now look up all required SVG elements and initialize member fields using the same name to have a convenient handle
|
2014-02-04 21:07:35 +00:00
|
|
|
foreach(var element; ["dmeLDist","dmeRDist","dmeL","dmeR","vorL","vorR","vorLId","vorRId",
|
2014-07-06 21:17:47 +00:00
|
|
|
"status.wxr","status.wpt","status.sta","status.arpt"])
|
2014-01-10 03:04:36 +00:00
|
|
|
me.symbols[element] = me.nd.getElementById(element);
|
2013-12-01 12:29:22 +00:00
|
|
|
|
|
|
|
# load elements from vector image, and create instance variables using identical names, and call updateCenter() on each
|
|
|
|
# anything that needs updatecenter called, should be added to the vector here
|
2014-01-10 03:04:36 +00:00
|
|
|
#
|
2014-07-06 21:17:47 +00:00
|
|
|
foreach(var element; ["staArrowL2","staArrowR2","staFromL2","staToL2","staFromR2","staToR2",
|
|
|
|
"hdgTrk","trkInd","hdgBug","HdgBugCRT","TrkBugLCD","HdgBugLCD","curHdgPtr",
|
2014-02-11 18:45:39 +00:00
|
|
|
"HdgBugCRT2","TrkBugLCD2","HdgBugLCD2","hdgBug2","selHdgLine","selHdgLine2","curHdgPtr2",
|
|
|
|
"staArrowL","staArrowR","staToL","staFromL","staToR","staFromR"] )
|
2014-01-10 03:04:36 +00:00
|
|
|
me.symbols[element] = me.nd.getElementById(element).updateCenter();
|
2014-01-08 20:45:48 +00:00
|
|
|
|
2013-12-01 12:29:22 +00:00
|
|
|
me.map = me.nd.createChild("map","map")
|
2014-01-18 14:22:42 +00:00
|
|
|
.set("clip", "rect(124, 1024, 1024, 0)")
|
2014-05-25 18:11:13 +00:00
|
|
|
.set("screen-range", 700);
|
2014-01-10 03:04:36 +00:00
|
|
|
|
2014-05-25 18:11:13 +00:00
|
|
|
me.update_sub(); # init some map properties based on switches
|
2014-01-10 03:04:36 +00:00
|
|
|
|
2013-12-01 12:29:22 +00:00
|
|
|
# predicate for the draw controller
|
2014-01-10 03:04:36 +00:00
|
|
|
var is_tuned = func(freq) {
|
2014-01-08 20:45:48 +00:00
|
|
|
var nav1=getprop("instrumentation/nav[0]/frequencies/selected-mhz");
|
|
|
|
var nav2=getprop("instrumentation/nav[1]/frequencies/selected-mhz");
|
2014-01-10 03:04:36 +00:00
|
|
|
if (freq == nav1 or freq == nav2) return 1;
|
|
|
|
return 0;
|
2013-12-01 12:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# another predicate for the draw controller
|
2014-01-10 03:04:36 +00:00
|
|
|
var get_course_by_freq = func(freq) {
|
|
|
|
if (freq == getprop("instrumentation/nav[0]/frequencies/selected-mhz"))
|
2014-01-08 20:45:48 +00:00
|
|
|
return getprop("instrumentation/nav[0]/radials/selected-deg");
|
2014-01-10 03:04:36 +00:00
|
|
|
else
|
2014-01-08 20:45:48 +00:00
|
|
|
return getprop("instrumentation/nav[1]/radials/selected-deg");
|
2013-12-01 12:29:22 +00:00
|
|
|
}
|
|
|
|
|
2014-01-10 03:04:36 +00:00
|
|
|
var get_current_position = func {
|
2014-01-27 02:18:30 +00:00
|
|
|
delete(caller(0)[0], "me"); # remove local me, inherit outer one
|
2014-01-10 03:04:36 +00:00
|
|
|
return [
|
|
|
|
me.aircraft_source.get_lat(), me.aircraft_source.get_lon()
|
|
|
|
];
|
2013-12-01 12:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# a hash with controller callbacks, will be passed onto draw routines to customize behavior/appearance
|
|
|
|
# the point being that draw routines don't know anything about their frontends (instrument or GUI dialog)
|
|
|
|
# so we need some simple way to communicate between frontend<->backend until we have real controllers
|
|
|
|
# for now, a single controller hash is shared by most layers - unsupported callbacks are simply ignored by the draw files
|
2014-01-10 03:04:36 +00:00
|
|
|
#
|
2014-04-29 02:26:32 +00:00
|
|
|
|
2014-01-10 03:04:36 +00:00
|
|
|
var controller = {
|
2014-04-29 02:26:32 +00:00
|
|
|
parents: [canvas.Map.Controller],
|
|
|
|
_pos: nil, _time: nil,
|
2014-01-10 03:04:36 +00:00
|
|
|
is_tuned:is_tuned,
|
2014-01-08 20:45:48 +00:00
|
|
|
get_tuned_course:get_course_by_freq,
|
|
|
|
get_position: get_current_position,
|
2014-04-29 02:26:32 +00:00
|
|
|
new: func(map) return { parents:[controller], map:map },
|
|
|
|
should_update_all: func {
|
|
|
|
# TODO: this is just copied from aircraftpos.controller,
|
|
|
|
# it really should be moved to somewhere common and reused
|
|
|
|
# and extended to fully differentiate between "static"
|
|
|
|
# and "volatile" layers.
|
|
|
|
var pos = me.map.getPosCoord();
|
|
|
|
if (pos == nil) return 0;
|
|
|
|
var time = systime();
|
|
|
|
if (me._pos == nil)
|
|
|
|
me._pos = geo.Coord.new(pos);
|
|
|
|
else {
|
|
|
|
var dist_m = me._pos.direct_distance_to(pos);
|
|
|
|
# 2 NM until we update again
|
|
|
|
if (dist_m < 2 * NM2M) return 0;
|
|
|
|
# Update at most every 4 seconds to avoid excessive stutter:
|
|
|
|
elsif (time - me._time < 4) return 0;
|
|
|
|
}
|
|
|
|
#print("update aircraft position");
|
|
|
|
var (x,y,z) = pos.xyz();
|
|
|
|
me._pos.set_xyz(x,y,z);
|
|
|
|
me._time = time;
|
|
|
|
return 1;
|
|
|
|
},
|
2014-01-10 03:04:36 +00:00
|
|
|
};
|
2014-04-29 02:26:32 +00:00
|
|
|
me.map.setController(controller);
|
2014-01-10 03:04:36 +00:00
|
|
|
|
2013-12-01 12:29:22 +00:00
|
|
|
###
|
|
|
|
# set up various layers, controlled via callbacks in the controller hash
|
|
|
|
# revisit this code once Philosopher's "Smart MVC Symbols/Layers" work is committed and integrated
|
|
|
|
|
|
|
|
# helper / closure generator
|
|
|
|
var make_event_handler = func(predicate, layer) func predicate(me, layer);
|
2014-01-10 03:04:36 +00:00
|
|
|
|
2013-12-01 12:29:22 +00:00
|
|
|
me.layers={}; # storage container for all ND specific layers
|
|
|
|
# look up all required layers as specified per the NDStyle hash and do the initial setup for event handling
|
2014-01-10 03:04:36 +00:00
|
|
|
foreach(var layer; me.nd_style.layers) {
|
|
|
|
if(layer['disabled']) continue; # skip this layer
|
|
|
|
#print("newMFD(): Setting up ND layer:", layer.name);
|
|
|
|
|
|
|
|
var the_layer = nil;
|
2014-05-25 18:11:13 +00:00
|
|
|
if(!layer['isMapStructure']) # set up an old INEFFICIENT and SLOW layer
|
|
|
|
the_layer = me.layers[layer.name] = canvas.MAP_LAYERS[layer.name].new( me.map, layer.name, controller );
|
2014-01-10 03:04:36 +00:00
|
|
|
else {
|
2014-01-24 03:13:54 +00:00
|
|
|
printlog(_MP_dbg_lvl, "Setting up MapStructure-based layer for ND, name:", layer.name);
|
2014-04-29 02:26:32 +00:00
|
|
|
var opt = options != nil and options[layer.name] != nil ? options[layer.name] :nil;
|
|
|
|
# print("Options is: ", opt!=nil?"enabled":"disabled");
|
2014-05-25 18:11:13 +00:00
|
|
|
me.map.addLayer(
|
|
|
|
factory: canvas.SymbolLayer,
|
|
|
|
type_arg: layer.name,
|
|
|
|
options:opt,
|
|
|
|
visible:0,
|
|
|
|
priority: layer['z-index']
|
|
|
|
);
|
|
|
|
the_layer = me.layers[layer.name] = me.map.getLayer(layer.name);
|
|
|
|
if (1) (func {
|
|
|
|
var l = layer;
|
|
|
|
var _predicate = l.predicate;
|
|
|
|
l.predicate = func {
|
|
|
|
var t = systime();
|
|
|
|
call(_predicate, arg, me);
|
|
|
|
printlog(_MP_dbg_lvl, "Took "~((systime()-t)*1000)~"ms to update layer "~l.name);
|
|
|
|
}
|
|
|
|
})();
|
2014-01-10 03:04:36 +00:00
|
|
|
}
|
2014-01-08 20:45:48 +00:00
|
|
|
|
|
|
|
# now register all layer specific notification listeners and their corresponding update predicate/callback
|
|
|
|
# pass the ND instance and the layer handle to the predicate when it is called
|
|
|
|
# so that it can directly access the ND instance and its own layer (without having to know the layer's name)
|
2014-01-10 03:04:36 +00:00
|
|
|
var event_handler = make_event_handler(layer.predicate, the_layer);
|
|
|
|
foreach(var event; layer.update_on) {
|
2014-05-25 18:11:13 +00:00
|
|
|
# this handles timers
|
|
|
|
if (typeof(event)=='hash' and contains(event, 'rate_hz')) {
|
|
|
|
#print("FIXME: navdisplay.mfd timer handling is broken ATM");
|
|
|
|
var job=me.addtimer(1/event.rate_hz, event_handler);
|
|
|
|
job.start();
|
|
|
|
}
|
|
|
|
# and this listeners
|
|
|
|
else
|
2014-01-10 03:04:36 +00:00
|
|
|
# print("Setting up subscription:", event, " for ", layer.name, " handler id:", id(event_handler) );
|
|
|
|
me.listen_switch(event, event_handler);
|
2014-01-08 20:45:48 +00:00
|
|
|
} # foreach event subscription
|
|
|
|
# and now update/init each layer once by calling its update predicate for initialization
|
|
|
|
event_handler();
|
|
|
|
} # foreach layer
|
2013-12-01 12:29:22 +00:00
|
|
|
|
2014-01-10 03:04:36 +00:00
|
|
|
#print("navdisplay.mfd:ND layer setup completed");
|
|
|
|
|
|
|
|
# start the update timer, which makes sure that the update() will be called
|
2013-12-01 12:29:22 +00:00
|
|
|
me.update_timer.start();
|
2014-01-10 03:04:36 +00:00
|
|
|
|
2014-05-25 18:11:13 +00:00
|
|
|
# TODO: move this to RTE.lcontroller ?
|
2014-01-10 03:04:36 +00:00
|
|
|
me.listen("/autopilot/route-manager/current-wp", func(activeWp) {
|
2014-01-08 20:45:48 +00:00
|
|
|
canvas.updatewp( activeWp.getValue() );
|
|
|
|
});
|
2014-01-10 03:04:36 +00:00
|
|
|
|
2013-12-01 12:29:22 +00:00
|
|
|
},
|
2014-01-10 03:04:36 +00:00
|
|
|
|
2014-01-08 20:45:48 +00:00
|
|
|
in_mode:func(switch, modes)
|
|
|
|
{
|
|
|
|
foreach(var m; modes) if(me.get_switch(switch)==m) return 1;
|
2013-12-01 12:29:22 +00:00
|
|
|
return 0;
|
|
|
|
},
|
2014-05-25 18:11:13 +00:00
|
|
|
# Helper function for below (update()) and above (newMFD())
|
|
|
|
# to ensure position etc. are correct.
|
|
|
|
update_sub: func()
|
2013-12-01 12:29:22 +00:00
|
|
|
{
|
2014-04-29 02:26:32 +00:00
|
|
|
# Variables:
|
|
|
|
var userLat = me.aircraft_source.get_lat();
|
|
|
|
var userLon = me.aircraft_source.get_lon();
|
|
|
|
var userGndSpd = me.aircraft_source.get_gnd_spd();
|
|
|
|
var userVSpd = me.aircraft_source.get_vspd();
|
|
|
|
var dispLCD = me.get_switch('toggle_display_type') == "LCD";
|
2013-12-28 15:18:35 +00:00
|
|
|
# Heading update
|
2014-01-10 03:04:36 +00:00
|
|
|
var userHdgMag = me.aircraft_source.get_hdg_mag();
|
|
|
|
var userHdgTru = me.aircraft_source.get_hdg_tru();
|
|
|
|
var userTrkMag = me.aircraft_source.get_trk_mag();
|
|
|
|
var userTrkTru = me.aircraft_source.get_trk_tru();
|
2014-02-04 21:07:35 +00:00
|
|
|
|
2014-01-08 20:45:48 +00:00
|
|
|
if(me.get_switch('toggle_true_north')) {
|
2013-12-28 15:18:35 +00:00
|
|
|
var userHdg=userHdgTru;
|
2014-07-06 21:17:47 +00:00
|
|
|
me.userHdg=userHdgTru;
|
2013-12-28 15:18:35 +00:00
|
|
|
var userTrk=userTrkTru;
|
2014-07-06 21:17:47 +00:00
|
|
|
me.userTrk=userTrkTru;
|
2013-12-28 15:18:35 +00:00
|
|
|
} else {
|
|
|
|
var userHdg=userHdgMag;
|
2014-07-06 21:17:47 +00:00
|
|
|
me.userHdg=userHdgMag;
|
2013-12-28 15:18:35 +00:00
|
|
|
var userTrk=userTrkMag;
|
2014-07-06 21:17:47 +00:00
|
|
|
me.userTrk=userTrkMag;
|
2013-12-28 15:18:35 +00:00
|
|
|
}
|
2014-04-29 02:26:32 +00:00
|
|
|
# this should only ever happen when testing the experimental AI/MP ND driver hash (not critical)
|
|
|
|
# or when an error occurs (critical)
|
|
|
|
if (!userHdg or !userTrk or !userLat or !userLon) {
|
|
|
|
print("aircraft source invalid, returning !");
|
|
|
|
return;
|
|
|
|
}
|
2014-07-06 21:17:47 +00:00
|
|
|
if (me.aircraft_source.get_gnd_spd() < 80) {
|
2014-01-10 03:04:36 +00:00
|
|
|
userTrk = userHdg;
|
2014-07-06 21:17:47 +00:00
|
|
|
me.userTrk=userHdg;
|
|
|
|
}
|
2014-02-04 21:07:35 +00:00
|
|
|
|
2014-05-25 18:11:13 +00:00
|
|
|
if((me.in_mode('toggle_display_mode', ['MAP']) and me.get_switch('toggle_display_type') == "CRT")
|
|
|
|
or (me.get_switch('toggle_track_heading') and me.get_switch('toggle_display_type') == "LCD"))
|
|
|
|
{
|
2014-02-04 21:07:35 +00:00
|
|
|
userHdgTrk = userTrk;
|
2014-07-06 21:17:47 +00:00
|
|
|
me.userHdgTrk = userTrk;
|
2014-02-23 18:43:54 +00:00
|
|
|
userHdgTrkTru = userTrkTru;
|
2014-02-04 21:07:35 +00:00
|
|
|
me.symbols.hdgTrk.setText("TRK");
|
|
|
|
} else {
|
|
|
|
userHdgTrk = userHdg;
|
2014-07-06 21:17:47 +00:00
|
|
|
me.userHdgTrk = userHdg;
|
2014-02-23 18:43:54 +00:00
|
|
|
userHdgTrkTru = userHdgTru;
|
2014-02-04 21:07:35 +00:00
|
|
|
me.symbols.hdgTrk.setText("HDG");
|
|
|
|
}
|
2013-12-01 12:29:22 +00:00
|
|
|
|
2014-04-29 02:26:32 +00:00
|
|
|
# First, update the display position of the map
|
|
|
|
var pos = {
|
|
|
|
lat: nil, lon: nil,
|
|
|
|
alt: nil, hdg: nil,
|
|
|
|
range: nil,
|
|
|
|
};
|
|
|
|
pos.range = me.rangeNm(); # avoid this here, use a listener instead
|
|
|
|
# reposition the map, change heading & range:
|
|
|
|
if(me.in_mode('toggle_display_mode', ['PLAN'])) {
|
|
|
|
pos.hdg = 0;
|
|
|
|
if (getprop(me.efis_path ~ "/inputs/plan-wpt-index") >= 0) {
|
|
|
|
pos.lat = getprop("/autopilot/route-manager/route/wp["~getprop(me.efis_path ~ "/inputs/plan-wpt-index")~"]/latitude-deg");
|
|
|
|
pos.lon = getprop("/autopilot/route-manager/route/wp["~getprop(me.efis_path ~ "/inputs/plan-wpt-index")~"]/longitude-deg");
|
|
|
|
} else {
|
|
|
|
pos.lat = me.map.getLat();
|
|
|
|
pos.lon = me.map.getLon();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pos.hdg = userHdgTrkTru;
|
|
|
|
pos.lat = userLat;
|
|
|
|
pos.lon = userLon;
|
|
|
|
}
|
|
|
|
call(me.map.setPos, [pos.lat, pos.lon], me.map, pos);
|
2014-05-25 18:11:13 +00:00
|
|
|
},
|
|
|
|
# each model should keep track of when it last got updated, using current lat/lon
|
|
|
|
# in update(), we can then check if the aircraft has traveled more than 0.5-1 nm (depending on selected range)
|
|
|
|
# and update each model accordingly
|
|
|
|
# TODO: Hooray is still waiting for a really rainy weekend to clean up all the mess here... so plz don't add to it!
|
|
|
|
update: func() # FIXME: This stuff is still too aircraft specific, cannot easily be reused by other aircraft
|
|
|
|
{
|
|
|
|
var _time = systime();
|
|
|
|
|
|
|
|
call(me.update_sub, nil, nil, caller(0)[0]); # call this in the same namespace to "steal" its variables
|
2014-04-29 02:26:32 +00:00
|
|
|
|
|
|
|
# MapStructure update!
|
|
|
|
if (me.map.controller.should_update_all()) {
|
|
|
|
me.map.update();
|
|
|
|
} else {
|
|
|
|
# TODO: ugly list here
|
2014-05-25 18:11:13 +00:00
|
|
|
# FIXME: use a VOLATILE layer helper here that handles TFC, APS, WXR etc ?
|
2014-04-29 02:26:32 +00:00
|
|
|
me.map.update(func(layer) (var n=layer.type) == "TFC" or n == "APS");
|
2013-12-01 12:29:22 +00:00
|
|
|
}
|
2014-01-10 03:04:36 +00:00
|
|
|
|
2014-04-29 02:26:32 +00:00
|
|
|
# Other symbol update
|
|
|
|
# TODO: should be refactored!
|
2014-01-08 20:45:48 +00:00
|
|
|
if(me.in_mode('toggle_display_mode', ['PLAN']))
|
2013-12-28 15:18:35 +00:00
|
|
|
me.map.setTranslation(512,512);
|
2014-01-08 20:45:48 +00:00
|
|
|
elsif(me.get_switch('toggle_centered'))
|
|
|
|
me.map.setTranslation(512,565);
|
2013-12-28 15:18:35 +00:00
|
|
|
else
|
|
|
|
me.map.setTranslation(512,824);
|
2014-01-10 03:04:36 +00:00
|
|
|
|
2014-01-08 20:45:48 +00:00
|
|
|
if(me.get_switch('toggle_lh_vor_adf') == 1)
|
|
|
|
{
|
|
|
|
me.symbols.vorL.setText("VOR L");
|
|
|
|
me.symbols.vorL.setColor(0.195,0.96,0.097);
|
|
|
|
me.symbols.dmeL.setText("DME");
|
|
|
|
me.symbols.dmeL.setColor(0.195,0.96,0.097);
|
|
|
|
if(getprop("instrumentation/nav/in-range"))
|
|
|
|
me.symbols.vorLId.setText(getprop("instrumentation/nav/nav-id"));
|
|
|
|
else
|
|
|
|
me.symbols.vorLId.setText(getprop("instrumentation/nav/frequencies/selected-mhz-fmt"));
|
|
|
|
me.symbols.vorLId.setColor(0.195,0.96,0.097);
|
2014-02-11 18:45:39 +00:00
|
|
|
if(getprop("instrumentation/dme/in-range"))
|
2014-03-25 21:55:06 +00:00
|
|
|
me.symbols.dmeLDist.setText(sprintf("%3.1f",getprop("instrumentation/dme/indicated-distance-nm")));
|
2014-01-08 20:45:48 +00:00
|
|
|
else me.symbols.dmeLDist.setText(" ---");
|
|
|
|
me.symbols.dmeLDist.setColor(0.195,0.96,0.097);
|
|
|
|
} elsif(me.get_switch('toggle_lh_vor_adf') == -1) {
|
|
|
|
me.symbols.vorL.setText("ADF L");
|
|
|
|
me.symbols.vorL.setColor(0,0.6,0.85);
|
|
|
|
me.symbols.dmeL.setText("");
|
|
|
|
me.symbols.dmeL.setColor(0,0.6,0.85);
|
|
|
|
if((var navident=getprop("instrumentation/adf/ident")) != "")
|
|
|
|
me.symbols.vorLId.setText(navident);
|
|
|
|
else me.symbols.vorLId.setText(sprintf("%3d",getprop("instrumentation/adf/frequencies/selected-khz")));
|
|
|
|
me.symbols.vorLId.setColor(0,0.6,0.85);
|
|
|
|
me.symbols.dmeLDist.setText("");
|
|
|
|
me.symbols.dmeLDist.setColor(0,0.6,0.85);
|
|
|
|
} else {
|
|
|
|
me.symbols.vorL.setText("");
|
|
|
|
me.symbols.dmeL.setText("");
|
|
|
|
me.symbols.vorLId.setText("");
|
|
|
|
me.symbols.dmeLDist.setText("");
|
|
|
|
}
|
|
|
|
if(me.get_switch('toggle_rh_vor_adf') == 1) {
|
|
|
|
me.symbols.vorR.setText("VOR R");
|
|
|
|
me.symbols.vorR.setColor(0.195,0.96,0.097);
|
|
|
|
me.symbols.dmeR.setText("DME");
|
|
|
|
me.symbols.dmeR.setColor(0.195,0.96,0.097);
|
|
|
|
if(getprop("instrumentation/nav[1]/in-range"))
|
|
|
|
me.symbols.vorRId.setText(getprop("instrumentation/nav[1]/nav-id"));
|
|
|
|
else
|
|
|
|
me.symbols.vorRId.setText(getprop("instrumentation/nav[1]/frequencies/selected-mhz-fmt"));
|
|
|
|
me.symbols.vorRId.setColor(0.195,0.96,0.097);
|
2014-02-11 18:45:39 +00:00
|
|
|
if(getprop("instrumentation/dme[1]/in-range"))
|
2014-03-25 21:55:06 +00:00
|
|
|
me.symbols.dmeRDist.setText(sprintf("%3.1f",getprop("instrumentation/dme[1]/indicated-distance-nm")));
|
2014-01-08 20:45:48 +00:00
|
|
|
else me.symbols.dmeRDist.setText(" ---");
|
|
|
|
me.symbols.dmeRDist.setColor(0.195,0.96,0.097);
|
|
|
|
} elsif(me.get_switch('toggle_rh_vor_adf') == -1) {
|
|
|
|
me.symbols.vorR.setText("ADF R");
|
|
|
|
me.symbols.vorR.setColor(0,0.6,0.85);
|
|
|
|
me.symbols.dmeR.setText("");
|
|
|
|
me.symbols.dmeR.setColor(0,0.6,0.85);
|
|
|
|
if((var navident=getprop("instrumentation/adf[1]/ident")) != "")
|
|
|
|
me.symbols.vorRId.setText(navident);
|
|
|
|
else me.symbols.vorRId.setText(sprintf("%3d",getprop("instrumentation/adf[1]/frequencies/selected-khz")));
|
|
|
|
me.symbols.vorRId.setColor(0,0.6,0.85);
|
|
|
|
me.symbols.dmeRDist.setText("");
|
|
|
|
me.symbols.dmeRDist.setColor(0,0.6,0.85);
|
|
|
|
} else {
|
|
|
|
me.symbols.vorR.setText("");
|
|
|
|
me.symbols.dmeR.setText("");
|
|
|
|
me.symbols.vorRId.setText("");
|
|
|
|
me.symbols.dmeRDist.setText("");
|
|
|
|
}
|
2014-01-10 03:04:36 +00:00
|
|
|
|
2014-01-18 14:22:42 +00:00
|
|
|
# Hide heading bug 10 secs after change
|
2014-04-29 02:26:32 +00:00
|
|
|
var vhdg_bug = getprop("autopilot/settings/heading-bug-deg") or 0;
|
2014-01-18 14:22:42 +00:00
|
|
|
var hdg_bug_active = getprop("autopilot/settings/heading-bug-active");
|
|
|
|
if (hdg_bug_active == nil)
|
|
|
|
hdg_bug_active = 1;
|
|
|
|
|
2014-05-25 18:11:13 +00:00
|
|
|
if((me.in_mode('toggle_display_mode', ['MAP']) and me.get_switch('toggle_display_type') == "CRT")
|
|
|
|
or (me.get_switch('toggle_track_heading') and me.get_switch('toggle_display_type') == "LCD"))
|
|
|
|
{
|
2013-12-04 22:19:22 +00:00
|
|
|
me.symbols.trkInd.setRotation(0);
|
2014-01-08 20:45:48 +00:00
|
|
|
me.symbols.curHdgPtr.setRotation((userHdg-userTrk)*D2R);
|
|
|
|
me.symbols.curHdgPtr2.setRotation((userHdg-userTrk)*D2R);
|
2013-12-04 22:19:22 +00:00
|
|
|
}
|
2014-04-29 02:26:32 +00:00
|
|
|
else
|
|
|
|
{
|
2014-02-23 18:43:54 +00:00
|
|
|
me.symbols.trkInd.setRotation((userTrk-userHdg)*D2R);
|
|
|
|
me.symbols.curHdgPtr.setRotation(0);
|
|
|
|
me.symbols.curHdgPtr2.setRotation(0);
|
|
|
|
}
|
|
|
|
if(!me.in_mode('toggle_display_mode', ['PLAN']))
|
|
|
|
{
|
2014-02-04 21:07:35 +00:00
|
|
|
var hdgBugRot = (vhdg_bug-userHdgTrk)*D2R;
|
|
|
|
me.symbols.selHdgLine.setRotation(hdgBugRot);
|
|
|
|
me.symbols.hdgBug.setRotation(hdgBugRot);
|
|
|
|
me.symbols.hdgBug2.setRotation(hdgBugRot);
|
|
|
|
me.symbols.selHdgLine2.setRotation(hdgBugRot);
|
2013-12-04 22:19:22 +00:00
|
|
|
}
|
2014-01-10 03:04:36 +00:00
|
|
|
|
2014-05-25 18:11:13 +00:00
|
|
|
var staPtrVis = !me.in_mode('toggle_display_mode', ['PLAN']);
|
|
|
|
if((me.in_mode('toggle_display_mode', ['MAP']) and me.get_switch('toggle_display_type') == "CRT")
|
|
|
|
or (me.get_switch('toggle_track_heading') and me.get_switch('toggle_display_type') == "LCD"))
|
|
|
|
{
|
|
|
|
var vorheading = userTrkTru;
|
|
|
|
var adfheading = userTrkMag;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var vorheading = userHdgTru;
|
|
|
|
var adfheading = userHdgMag;
|
|
|
|
}
|
2014-07-06 21:17:47 +00:00
|
|
|
if(getprop("instrumentation/nav/heading-deg") != nil)
|
|
|
|
var nav0hdg=getprop("instrumentation/nav/heading-deg") - vorheading;
|
|
|
|
if(getprop("instrumentation/nav[1]/heading-deg") != nil)
|
|
|
|
var nav1hdg=getprop("instrumentation/nav[1]/heading-deg") - vorheading;
|
|
|
|
var adf0hdg=getprop("instrumentation/adf/indicated-bearing-deg");
|
|
|
|
var adf1hdg=getprop("instrumentation/adf[1]/indicated-bearing-deg");
|
|
|
|
if(!me.get_switch('toggle_centered'))
|
2014-01-08 20:45:48 +00:00
|
|
|
{
|
2014-07-06 21:17:47 +00:00
|
|
|
if(me.in_mode('toggle_display_mode', ['PLAN']))
|
2014-01-08 20:45:48 +00:00
|
|
|
me.symbols.trkInd.hide();
|
2014-07-06 21:17:47 +00:00
|
|
|
else
|
|
|
|
me.symbols.trkInd.show();
|
|
|
|
if((getprop("instrumentation/nav/in-range") and me.get_switch('toggle_lh_vor_adf') == 1)) {
|
|
|
|
me.symbols.staArrowL.setVisible(staPtrVis);
|
|
|
|
me.symbols.staToL.setColor(0.195,0.96,0.097);
|
|
|
|
me.symbols.staFromL.setColor(0.195,0.96,0.097);
|
|
|
|
me.symbols.staArrowL.setRotation(nav0hdg*D2R);
|
|
|
|
}
|
|
|
|
elsif(getprop("instrumentation/adf/in-range") and (me.get_switch('toggle_lh_vor_adf') == -1)) {
|
|
|
|
me.symbols.staArrowL.setVisible(staPtrVis);
|
|
|
|
me.symbols.staToL.setColor(0,0.6,0.85);
|
|
|
|
me.symbols.staFromL.setColor(0,0.6,0.85);
|
|
|
|
me.symbols.staArrowL.setRotation(adf0hdg*D2R);
|
|
|
|
} else {
|
2014-02-11 18:45:39 +00:00
|
|
|
me.symbols.staArrowL.hide();
|
2014-07-06 21:17:47 +00:00
|
|
|
}
|
|
|
|
if((getprop("instrumentation/nav[1]/in-range") and me.get_switch('toggle_rh_vor_adf') == 1)) {
|
|
|
|
me.symbols.staArrowR.setVisible(staPtrVis);
|
|
|
|
me.symbols.staToR.setColor(0.195,0.96,0.097);
|
|
|
|
me.symbols.staFromR.setColor(0.195,0.96,0.097);
|
|
|
|
me.symbols.staArrowR.setRotation(nav1hdg*D2R);
|
|
|
|
} elsif(getprop("instrumentation/adf[1]/in-range") and (me.get_switch('toggle_rh_vor_adf') == -1)) {
|
|
|
|
me.symbols.staArrowR.setVisible(staPtrVis);
|
|
|
|
me.symbols.staToR.setColor(0,0.6,0.85);
|
|
|
|
me.symbols.staFromR.setColor(0,0.6,0.85);
|
|
|
|
me.symbols.staArrowR.setRotation(adf1hdg*D2R);
|
|
|
|
} else {
|
2014-02-11 18:45:39 +00:00
|
|
|
me.symbols.staArrowR.hide();
|
2014-07-06 21:17:47 +00:00
|
|
|
}
|
|
|
|
me.symbols.staArrowL2.hide();
|
|
|
|
me.symbols.staArrowR2.hide();
|
|
|
|
me.symbols.curHdgPtr2.hide();
|
|
|
|
me.symbols.HdgBugCRT2.hide();
|
|
|
|
me.symbols.TrkBugLCD2.hide();
|
|
|
|
me.symbols.HdgBugLCD2.hide();
|
|
|
|
me.symbols.selHdgLine2.hide();
|
|
|
|
me.symbols.curHdgPtr.setVisible(staPtrVis);
|
|
|
|
me.symbols.HdgBugCRT.setVisible(staPtrVis and !dispLCD);
|
|
|
|
if(me.get_switch('toggle_track_heading'))
|
|
|
|
{
|
2014-01-08 20:45:48 +00:00
|
|
|
me.symbols.HdgBugLCD.hide();
|
2014-07-06 21:17:47 +00:00
|
|
|
me.symbols.TrkBugLCD.setVisible(staPtrVis and dispLCD);
|
2014-01-08 20:45:48 +00:00
|
|
|
}
|
2014-07-06 21:17:47 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
me.symbols.TrkBugLCD.hide();
|
|
|
|
me.symbols.HdgBugLCD.setVisible(staPtrVis and dispLCD);
|
|
|
|
}
|
|
|
|
me.symbols.selHdgLine.setVisible(staPtrVis and hdg_bug_active);
|
2013-12-04 22:19:22 +00:00
|
|
|
} else {
|
2014-07-06 21:17:47 +00:00
|
|
|
me.symbols.trkInd.hide();
|
|
|
|
if((getprop("instrumentation/nav/in-range") and me.get_switch('toggle_lh_vor_adf') == 1)) {
|
|
|
|
me.symbols.staArrowL2.setVisible(staPtrVis);
|
|
|
|
me.symbols.staFromL2.setColor(0.195,0.96,0.097);
|
|
|
|
me.symbols.staToL2.setColor(0.195,0.96,0.097);
|
|
|
|
me.symbols.staArrowL2.setRotation(nav0hdg*D2R);
|
|
|
|
} elsif(getprop("instrumentation/adf/in-range") and (me.get_switch('toggle_lh_vor_adf') == -1)) {
|
|
|
|
me.symbols.staArrowL2.setVisible(staPtrVis);
|
|
|
|
me.symbols.staFromL2.setColor(0,0.6,0.85);
|
|
|
|
me.symbols.staToL2.setColor(0,0.6,0.85);
|
|
|
|
me.symbols.staArrowL2.setRotation(adf0hdg*D2R);
|
|
|
|
} else {
|
|
|
|
me.symbols.staArrowL2.hide();
|
|
|
|
}
|
|
|
|
if((getprop("instrumentation/nav[1]/in-range") and me.get_switch('toggle_rh_vor_adf') == 1)) {
|
|
|
|
me.symbols.staArrowR2.setVisible(staPtrVis);
|
|
|
|
me.symbols.staFromR2.setColor(0.195,0.96,0.097);
|
|
|
|
me.symbols.staToR2.setColor(0.195,0.96,0.097);
|
|
|
|
me.symbols.staArrowR2.setRotation(nav1hdg*D2R);
|
|
|
|
} elsif(getprop("instrumentation/adf[1]/in-range") and (me.get_switch('toggle_rh_vor_adf') == -1)) {
|
|
|
|
me.symbols.staArrowR2.setVisible(staPtrVis);
|
|
|
|
me.symbols.staFromR2.setColor(0,0.6,0.85);
|
|
|
|
me.symbols.staToR2.setColor(0,0.6,0.85);
|
|
|
|
me.symbols.staArrowR2.setRotation(adf1hdg*D2R);
|
|
|
|
} else {
|
|
|
|
me.symbols.staArrowR2.hide();
|
|
|
|
}
|
|
|
|
me.symbols.staArrowL.hide();
|
|
|
|
me.symbols.staArrowR.hide();
|
|
|
|
me.symbols.curHdgPtr.hide();
|
|
|
|
me.symbols.HdgBugCRT.hide();
|
|
|
|
me.symbols.TrkBugLCD.hide();
|
|
|
|
me.symbols.HdgBugLCD.hide();
|
|
|
|
me.symbols.selHdgLine.hide();
|
|
|
|
me.symbols.curHdgPtr2.setVisible(staPtrVis);
|
|
|
|
me.symbols.HdgBugCRT2.setVisible(staPtrVis and !dispLCD);
|
|
|
|
if(me.get_switch('toggle_track_heading'))
|
|
|
|
{
|
|
|
|
me.symbols.HdgBugLCD2.hide();
|
|
|
|
me.symbols.TrkBugLCD2.setVisible(staPtrVis and dispLCD);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
me.symbols.TrkBugLCD2.hide();
|
|
|
|
me.symbols.HdgBugLCD2.setVisible(staPtrVis and dispLCD);
|
|
|
|
}
|
|
|
|
me.symbols.selHdgLine2.setVisible(staPtrVis and hdg_bug_active);
|
2013-12-28 15:18:35 +00:00
|
|
|
}
|
2014-01-10 03:04:36 +00:00
|
|
|
|
2013-12-01 12:29:22 +00:00
|
|
|
## run all predicates in the NDStyle hash and evaluate their true/false behavior callbacks
|
|
|
|
## this is in line with the original design, but normally we don't need to getprop/poll here,
|
|
|
|
## using listeners or timers would be more canvas-friendly whenever possible
|
|
|
|
## because running setprop() on any group/canvas element at framerate means that the canvas
|
|
|
|
## will be updated at frame rate too - wasteful ... (check the performance monitor!)
|
|
|
|
|
|
|
|
foreach(var feature; me.nd_style.features ) {
|
2014-01-08 20:45:48 +00:00
|
|
|
# for stuff that always needs to be updated
|
|
|
|
if (contains(feature.impl, 'common')) feature.impl.common(me);
|
|
|
|
# conditional stuff
|
|
|
|
if(!contains(feature.impl, 'predicate')) continue; # no conditional stuff
|
|
|
|
if ( var result=feature.impl.predicate(me) )
|
|
|
|
feature.impl.is_true(me, result); # pass the result to the predicate
|
|
|
|
else
|
|
|
|
feature.impl.is_false( me, result ); # pass the result to the predicate
|
2013-12-01 12:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
## update the status flags shown on the ND (wxr, wpt, arpt, sta)
|
|
|
|
# this could/should be using listeners instead ...
|
2013-12-28 15:18:35 +00:00
|
|
|
me.symbols['status.wxr'].setVisible( me.get_switch('toggle_weather') and me.in_mode('toggle_display_mode', ['MAP']));
|
|
|
|
me.symbols['status.wpt'].setVisible( me.get_switch('toggle_waypoints') and me.in_mode('toggle_display_mode', ['MAP']));
|
|
|
|
me.symbols['status.arpt'].setVisible( me.get_switch('toggle_airports') and me.in_mode('toggle_display_mode', ['MAP']));
|
|
|
|
me.symbols['status.sta'].setVisible( me.get_switch('toggle_stations') and me.in_mode('toggle_display_mode', ['MAP']));
|
2014-04-29 02:26:32 +00:00
|
|
|
# Okay, _how_ do we hook this up with FGPlot?
|
2014-05-25 18:11:13 +00:00
|
|
|
printlog(_MP_dbg_lvl, "Total ND update took "~((systime()-_time)*100)~"ms");
|
2014-04-29 02:26:32 +00:00
|
|
|
setprop("/instrumentation/navdisplay["~ NavDisplay.id ~"]/update-ms", systime() - _time);
|
2014-05-25 18:11:13 +00:00
|
|
|
} # of update() method (50% of our file ...seriously?)
|
2014-01-10 03:04:36 +00:00
|
|
|
};
|