20,741
edits
No edit summary |
|||
Line 72: | Line 72: | ||
== Base Package changes == | == Base Package changes == | ||
{{Note|The following patch contains changes that | {{Note|The following patch contains changes that move the definition of aircraft specific switches back into the navdisplay.styles file, adding GUI related fields to the hash, so that these can be used to procedurally create a UI without requiring an actual cockpit (including an optional values vector). In addition, this makes deletion of the Canvas by the ND optional, so that PUI based CanvasWidgets can reuse the ND without having to reallocate a new Canvas. Also, changes references to properly resolve to canvas.Path. | ||
}} | }} | ||
<syntaxhighlight lang="diff">diff --git a/Nasal/canvas/api.nas b/Nasal/canvas/api.nas | <syntaxhighlight lang="diff">diff --git a/Nasal/canvas/api.nas b/Nasal/canvas/api.nas | ||
Line 91: | Line 88: | ||
foreach (var k; keys(me.layers)) { | foreach (var k; keys(me.layers)) { | ||
diff --git a/Nasal/canvas/map/navdisplay.mfd b/Nasal/canvas/map/navdisplay.mfd | diff --git a/Nasal/canvas/map/navdisplay.mfd b/Nasal/canvas/map/navdisplay.mfd | ||
index | index 89996f4..7f8f4f8 100644 | ||
--- a/Nasal/canvas/map/navdisplay.mfd | --- a/Nasal/canvas/map/navdisplay.mfd | ||
+++ b/Nasal/canvas/map/navdisplay.mfd | +++ b/Nasal/canvas/map/navdisplay.mfd | ||
@@ - | @@ -60,33 +60,6 @@ NDSourceDriver.new = func { | ||
removelistener(l); | # 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 = { | |||
- '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'}, | |||
- 'toggle_traffic': {path: '/inputs/tfc',value:0, type:'BOOL'}, | |||
- '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'}, | |||
- 'toggle_rangearc': {path: '/mfd/rangearc', value:0, type:'BOOL'}, | |||
- 'toggle_track_heading':{path: '/trk-selected', value:0, type:'BOOL'}, | |||
- 'toggle_weather_live': {path: '/mfd/wxr-live-enabled', value: 0, type: 'BOOL'}, | |||
- 'toggle_chrono': {path: '/inputs/CHRONO', value: 0, type: 'INT'}, | |||
- 'toggle_xtrk_error': {path: '/mfd/xtrk-error', value: 0, type: 'BOOL'}, | |||
- 'toggle_trk_line': {path: '/mfd/trk-line', value: 0, type: 'BOOL'}, | |||
- 'toggle_hdg_bug_only': {path: '/mfd/hdg-bug-only', value: 0, type: 'BOOL'}, | |||
-}; | |||
- | |||
## | |||
# TODO: | |||
# - introduce a MFD class (use it also for PFD/EICAS) | |||
@@ -96,20 +69,26 @@ var NavDisplay = { | |||
# static | |||
id:0, | |||
- del: func { | |||
+ del: func(destroy_canvas=1) { | |||
print("Cleaning up NavDisplay"); | |||
# shut down all timers and other loops here | |||
me.update_timer.stop(); | |||
foreach(var t; me.timers) | |||
t.stop(); | |||
foreach(var l; me.listeners) | |||
- removelistener(l); | |||
+ # removelistener(l); | |||
+ call(removelistener, [l]); | |||
# clean up MapStructure | # clean up MapStructure | ||
me.map.del(); | me.map.del(); | ||
# call(canvas.Map.del, [], me.map); | |||
- # destroy the canvas | |||
- if (me.canvas_handle != nil) | |||
+ | |||
+ me.nd.del(); # delete symbols (compass rose etc, needed in case we keep the underlying canvas) | |||
+ | |||
+ # destroy the canvas (now optional, we may not always want to delete the whole canvas) | |||
+ if (destroy_canvas and me.canvas_handle != nil) { | |||
+ print("ND: destroying Canvas!"); | |||
me.canvas_handle.del(); | me.canvas_handle.del(); | ||
@@ - | + } | ||
me.df_options = nil; | me.inited = 0; | ||
NavDisplay.id -= 1; | |||
}, | |||
@@ -127,7 +106,7 @@ var NavDisplay = { | |||
listen_switch: func(s,c) { | |||
# print("event setup for: ", id(c)); | |||
if (!contains(me.efis_switches, s)) { | |||
- print('EFIS Switch not defined: '~ s); | |||
+ print('cannot set up listener, EFIS Switch not defined in style/switches: '~ s); | |||
return; | |||
} | |||
me.listen( me.get_full_switch_path(s), func { | |||
@@ -178,14 +157,26 @@ var NavDisplay = { | |||
# TODO: the ctor should allow customization, for different aircraft | |||
# especially properties and SVG files/handles (747, 757, 777 etc) | |||
- new : func(prop1, switches=default_switches, style='Boeing') { | |||
+ new : func(prop1, switches, style='Boeing') { | |||
+ | |||
+ # if no custom switches specified, use default switches | |||
+ if (switches==nil) { | |||
+ print("ND: Using ND specific default switches"); | |||
+ switches = NDStyles[styles].default_switches; | |||
+ } | |||
+ | |||
NavDisplay.id +=1; | |||
var m = { parents : [NavDisplay]}; | |||
- var df_toggles = keys(default_switches); | |||
+ m.nd_style = NDStyles[style]; # look up ND specific stuff (file names etc) | |||
+ | |||
+ var df_toggles = keys(m.nd_style.default_switches); | |||
+ print("ND specific default switches:", size(df_toggles)); | |||
foreach(var toggle_name; df_toggles){ | |||
- if(!contains(switches, toggle_name)) | |||
- switches[toggle_name] = default_switches[toggle_name]; | |||
+ if(!contains(switches, toggle_name)) { | |||
+ print("Undefined ND switch, using default mapping for:", toggle_name); | |||
+ switches[toggle_name] = m.nd_style.default_switches[toggle_name]; | |||
+ } | |||
} | |||
m.inited = 0; | |||
@@ -194,11 +185,11 @@ var NavDisplay = { | |||
m.listeners=[]; # for cleanup handling | |||
m.aircraft_source = NDSourceDriver.new(); # uses the main aircraft as the driver/source (speeds, position, heading) | |||
- m.nd_style = NDStyles[style]; # look up ND specific stuff (file names etc) | |||
m.style_name = style; | |||
m.radio_list=["instrumentation/comm/frequencies","instrumentation/comm[1]/frequencies", | |||
"instrumentation/nav/frequencies", "instrumentation/nav[1]/frequencies"]; | |||
+ # FIXME: this is redundant, must be moved to the style/Switches list | |||
m.mfd_mode_list=["APP","VOR","MAP","PLAN"]; | |||
m.efis_path = prop1; | |||
@@ -251,7 +242,7 @@ var NavDisplay = { | |||
me.update_timer = maketimer(update_time, func me.update() ); | |||
me.nd = canvas_group; | |||
me.canvas_handle = parent; | |||
- me.df_options = nil; | |||
+ me.df_options = { map:{width:1024, height:1024} }; | |||
if (contains(me.nd_style, 'options')) | if (contains(me.nd_style, 'options')) | ||
me.df_options = me.nd_style.options; | me.df_options = me.nd_style.options; | ||
nd_options = canvas.default_hash(nd_options, me.df_options); | |||
@@ -278,7 +269,8 @@ var NavDisplay = { | |||
@@ - | |||
me.nd_style.initialize_elements(me); | |||
- | - | ||
+ | + | ||
+ # var map_rect = [124, me.options.map.width, me.options.map.height, 0]; | |||
var map_rect = [124, 1024, 1024, 0]; | var map_rect = [124, 1024, 1024, 0]; | ||
var map_opts = me.options['map']; | var map_opts = me.options['map']; | ||
if (map_opts == nil) map_opts = {}; | if (map_opts == nil) map_opts = {}; | ||
@@ - | @@ -582,7 +574,7 @@ var NavDisplay = { | ||
me.map.setTranslation(trsl.x, trsl.y); | |||
} else { | |||
if(me.in_mode('toggle_display_mode', ['PLAN'])) | |||
- me.map.setTranslation(512,512); | |||
+ me.map.setTranslation(512,512); # FIXME use options hash to look up actual texture dimensions here | |||
elsif(me.get_switch('toggle_centered')) | |||
me.map.setTranslation(512,565); | |||
else | |||
+ | |||
diff --git a/Nasal/canvas/map/navdisplay.styles b/Nasal/canvas/map/navdisplay.styles | diff --git a/Nasal/canvas/map/navdisplay.styles b/Nasal/canvas/map/navdisplay.styles | ||
index | index c2196c8..6539d63 100644 | ||
--- a/Nasal/canvas/map/navdisplay.styles | --- a/Nasal/canvas/map/navdisplay.styles | ||
+++ b/Nasal/canvas/map/navdisplay.styles | +++ b/Nasal/canvas/map/navdisplay.styles | ||
@@ - | @@ -29,6 +29,37 @@ var NDStyles = { | ||
# | return "LiberationFonts/LiberationSans-Regular.ttf"; | ||
}, | |||
+ # to be used for validating new/modified styles, this can be used to encode a list of switches that | |||
+ # should be configured by the aircraft developer, lest the ND may not work completely | |||
+ | |||
+# switches are ND specific, TODO: use UI version with legends/labels | |||
+ | + | ||
+ | +default_switches: { | ||
+ # symbolic alias : GUI legend/tooltip, relative property (as used in bindings), initial value, valid values (vector), property type | |||
+ # TODO: should support a vector of valid_values() (ranges) | |||
+ 'toggle_range': {legend:'rng', path: '/inputs/range-nm', value:40, values:[10,20,40,80,160,320], type:'INT'}, | |||
+ 'toggle_weather': {legend:'wxr', path: '/inputs/wxr', value:0, type:'BOOL'}, | |||
+ 'toggle_airports': {legend:'apt', path: '/inputs/arpt', value:0, type:'BOOL'}, | |||
+ 'toggle_stations': {legend:'sta', path: '/inputs/sta', value:0, type:'BOOL'}, | |||
+ 'toggle_waypoints': {legend:'wpt', path: '/inputs/wpt', value:0, type:'BOOL'}, | |||
+ 'toggle_position': {legend:'pos', path: '/inputs/pos', value:0, type:'BOOL'}, | |||
+ 'toggle_data': {legend:'dat', path: '/inputs/data',value:0, type:'BOOL'}, | |||
+ 'toggle_terrain': {legend:'terr', path: '/inputs/terr',value:0, type:'BOOL'}, | |||
+ 'toggle_traffic': {legend:'tfc', path: '/inputs/tfc',value:0, type:'BOOL'}, | |||
+ 'toggle_centered': {legend:'ctr', path: '/inputs/nd-centered',value:0, type:'BOOL'}, | |||
+ 'toggle_lh_vor_adf': {legend:'vor/adf (l)', path: '/inputs/lh-vor-adf',value:0, values:{'VOR':1, 'OFF':0, 'ADF':-1 }, type:'INT'}, | |||
+ 'toggle_rh_vor_adf': {legend:'vor/adf (r)', path: '/inputs/rh-vor-adf',value:0, values:{'VOR':1, 'OFF':0, 'ADF':-1 }, type:'INT'}, | |||
+ 'toggle_display_mode': {legend:'map',path: '/mfd/display-mode', value:'MAP', values:['APP', 'MAP', 'PLAN', 'VOR' ], type:'STRING'}, | |||
+ 'toggle_display_type': {legend:'lcd',path: '/mfd/display-type', value:'LCD', values:['CRT', 'LCD' ], type:'STRING'}, | |||
+ 'toggle_true_north': {legend:'tru',path: '/mfd/true-north', value:0, type:'BOOL'}, | |||
+ 'toggle_rangearc': {legend:'rng',path: '/mfd/rangearc', value:0, type:'BOOL'}, | |||
+ 'toggle_track_heading': {legend:'trk',path: '/hdg-trk-selected', value:0, type:'BOOL'}, | |||
+ 'toggle_hdg_bug_only': {legend:'hdg',path: '/hdg-bug-only', value:0, type:'BOOL'}, | |||
+ # add any new switches here (and update navdisplay.styles as needed) | |||
+ | |||
+}, # end of aircraft-specific default switches | |||
+ | + | ||
+ | + | ||
# where all the symbols are stored | |||
# TODO: SVG elements should be renamed to use boeing/airbus prefix | |||
# aircraft developers should all be editing the same ND.svg image | |||
@@ -52,7 +83,7 @@ var NDStyles = { | |||
+ | "HdgBugCRT2","TrkBugLCD2","HdgBugLCD2","hdgBug2","selHdgLine","selHdgLine2","curHdgPtr2", | ||
"staArrowL","staArrowR","staToL","staFromL","staToR","staFromR"] ) | |||
me.symbols[element] = me.nd.getElementById(element).updateCenter(); | |||
- | |||
+ | + | ||
}, # initialize_elements | |||
## | ## | ||
@@ - | @@ -1147,6 +1178,43 @@ var NDStyles = { | ||
if( family == "Liberation Sans" and weight == "normal" ) | |||
# | return "LiberationFonts/LiberationSans-Regular.ttf"; | ||
}, | |||
+# switches are ND specific, TODO: see actual Airbus ND.nas (artix/omega95) | |||
+ | + | ||
+ | +# switches are ND specific, TODO: use UI version with legends/labels | ||
+# https://github.com/artix75/A320neo/blob/master/Models/Instruments/ND/canvas/ND.nas#L16 | |||
+ | + | ||
+ # | +default_switches: { | ||
+ | + # symbolic alias : relative property (as used in bindings), initial value, type | ||
+ | + 'toggle_range': {legend: "range", path: '/inputs/range-nm', value:40, values:[10,20,40,80,160,320],type:'INT'}, | ||
+ | + 'toggle_weather': {legend: "wxr", path: '/inputs/wxr', value:0, type:'BOOL'}, | ||
+ | + 'toggle_airports': {legend: "apt", path: '/inputs/arpt', value:0, type:'BOOL'}, | ||
+ | + 'toggle_ndb': {legend: "ndb", path: '/inputs/NDB', value:0, type:'BOOL'}, | ||
+ 'toggle_stations': {legend: "sta", path: '/inputs/sta', value:0, type:'BOOL'}, | |||
+ 'toggle_vor': {legend:"vor", path: '/inputs/VORD', value:0, type:'BOOL'}, | |||
+ 'toggle_dme': {legend: "dme", path: '/inputs/DME', value:0, type:'BOOL'}, | |||
+ 'toggle_cstr': {legend: "cstr", path: '/inputs/CSTR', value:0, type:'BOOL'}, | |||
+ 'toggle_waypoints': {legend:"wpt", path: '/inputs/wpt', value:0, type:'BOOL'}, | |||
+ 'toggle_position': {legend:"pos", path: '/inputs/pos', value:0, type:'BOOL'}, | |||
+ 'toggle_data': {legend:"dat", path: '/inputs/data',value:0, type:'BOOL'}, | |||
+ 'toggle_terrain': {legend:"terr", path: '/inputs/terr',value:0, type:'BOOL'}, | |||
+ 'toggle_traffic': {legend:"tfc",path: '/inputs/tfc',value:0, type:'BOOL'}, | |||
+ 'toggle_centered': {legend:"ctr",path: '/inputs/nd-centered',value:0, type:'BOOL'}, | |||
+ 'toggle_lh_vor_adf': {legend:"vor/adf(l)",path: '/input/lh-vor-adf',value:0, values:{'VOR':1, 'OFF':0, 'ADF':-1 }, type:'INT'}, | |||
+ 'toggle_rh_vor_adf': {legend:"vor/adf(r)", path: '/input/rh-vor-adf',value:0,values:{'VOR':1, 'OFF':0, 'ADF':-1 }, type:'INT'}, | |||
+ # FIXME: this should be reviewed by one of the airbus developers, not sure if these values make sense for the Airbus style (will only affect the GUI dialog though) | |||
+ 'toggle_display_mode': {legend: "mode", path: '/nd/canvas-display-mode', value:'NAV', values:['NAV','APP','MAP','VOR','PLAN'],type:'STRING'}, | |||
+ 'toggle_display_type': {legend: "LCD/CRT", path: '/mfd/display-type', value:'LCD', values:['LCD','CRT'],type:'STRING'}, | |||
+ 'toggle_true_north': {legend: "tru", path: '/mfd/true-north', value:1, type:'BOOL'}, | |||
+ 'toggle_track_heading': {legend:"trk", path: '/trk-selected', value:0, type:'BOOL'}, | |||
+ 'toggle_wpt_idx': {legend:"wpt idx", path: '/inputs/plan-wpt-index', value: -1,type: 'INT'}, | |||
+ 'toggle_plan_loop': {legend:"plan loop", path: '/nd/plan-mode-loop', value: 0,type: 'INT'}, | |||
+ 'toggle_weather_live': {legend: "live wxr", path: '/mfd/wxr-live-enabled', value: 0, type: 'BOOL'}, | |||
+ 'toggle_chrono': {legend:"chrono", path: '/inputs/CHRONO', value: 0, values:[],type: 'INT'}, | |||
+ 'toggle_xtrk_error': {legend: "xte", path: '/mfd/xtrk-error', value: 0,type: 'BOOL'}, | |||
+ 'toggle_trk_line': {legend:"trk line", path: '/mfd/trk-line', value: 0, type: 'BOOL'}, | |||
+ # add new switches here | |||
+}, # end of aircraft-specific default switches | |||
+ | + | ||
# where all the symbols are stored | |||
# TODO: SVG elements should be renamed to use boeing/airbus prefix | |||
@@ -1171,7 +1239,7 @@ var NDStyles = { | |||
+ | "HdgBugCRT2","TrkBugLCD2","HdgBugLCD2","hdgBug2","selHdgLine","selHdgLine2","curHdgPtr2", | ||
"staArrowL","staArrowR","staToL","staFromL","staToR","staFromR"] ) | |||
me.symbols[element] = me.nd.getElementById(element).updateCenter(); | |||
- | |||
+ | + | ||
}, # initialize_elements | |||
+ | |||
+ | @@ -1530,9 +1598,9 @@ var NDStyles = { | ||
var adf1_frq = getprop(me.options.adf1_frq); | |||
var adf2_frq = getprop(me.options.adf2_frq); | |||
if(adf1_frq == frq or adf2_frq == frq){ | |||
- me.element.setColor(tuned_color, [Path]); | |||
+ me.element.setColor(tuned_color, [canvas.Path]); | |||
} else { | |||
- me.element.setColor(dfcolor, [Path]); | |||
+ me.element.setColor(dfcolor, [canvas.Path]); | |||
} | |||
} | |||
}, | |||
</syntaxhighlight> | </syntaxhighlight> | ||