art-ix

Flightgear Canvas Airbus ND

Jan 31st, 2015
360
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var nd_display = {};
  2.  
  3. setlistener("sim/signals/fdm-initialized", func() {
  4.  
  5.     var myCockpit_switches = {
  6.         # symbolic alias : relative property (as used in bindings), initial value, type
  7.         'toggle_range':     {path: '/inputs/range-nm', value:40, type:'INT'},
  8.         'toggle_weather':   {path: '/inputs/wxr', value:0, type:'BOOL'},
  9.         'toggle_airports':  {path: '/inputs/arpt', value:0, type:'BOOL'},
  10.         'toggle_ndb':   {path: '/inputs/NDB', value:0, type:'BOOL'},
  11.         'toggle_stations':     {path: '/inputs/sta', value:0, type:'BOOL'},
  12.         'toggle_vor':   {path: '/inputs/VORD', value:0, type:'BOOL'},
  13.         'toggle_dme':   {path: '/inputs/DME', value:0, type:'BOOL'},
  14.         'toggle_cstr':  {path: '/inputs/CSTR', value:0, type:'BOOL'},
  15.         'toggle_waypoints':     {path: '/inputs/wpt', value:0, type:'BOOL'},
  16.         'toggle_position':  {path: '/inputs/pos', value:0, type:'BOOL'},
  17.         'toggle_data':      {path: '/inputs/data',value:0, type:'BOOL'},
  18.         'toggle_terrain':   {path: '/inputs/terr',value:0, type:'BOOL'},
  19.         'toggle_traffic':       {path: '/inputs/tfc',value:0, type:'BOOL'},
  20.         'toggle_centered':      {path: '/inputs/nd-centered',value:0, type:'BOOL'},
  21.         'toggle_lh_vor_adf':    {path: '/input/lh-vor-adf',value:0, type:'INT'},
  22.         'toggle_rh_vor_adf':    {path: '/input/rh-vor-adf',value:0, type:'INT'},
  23.         'toggle_display_mode':  {path: '/nd/canvas-display-mode', value:'NAV', type:'STRING'},
  24.         'toggle_display_type':  {path: '/mfd/display-type', value:'LCD', type:'STRING'},
  25.         'toggle_true_north':    {path: '/mfd/true-north', value:1, type:'BOOL'},
  26.         'toggle_track_heading':     {path: '/trk-selected', value:0, type:'BOOL'},
  27.         'toggle_wpt_idx': {path: '/inputs/plan-wpt-index', value: -1, type: 'INT'},
  28.         'toggle_plan_loop': {path: '/nd/plan-mode-loop', value: 0, type: 'INT'},
  29.         'toggle_weather_live': {path: '/mfd/wxr-live-enabled', value: 0, type: 'BOOL'},
  30.         'toggle_chrono': {path: '/inputs/CHRONO', value: 0, type: 'INT'},
  31.         # add new switches here
  32.     };
  33.  
  34.     # get a handle to the NavDisplay in canvas namespace (for now), see $FG_ROOT/Nasal/canvas/map/navdisplay.mfd
  35.     var ND = canvas.NavDisplay;
  36.     var NDCpt = ND.new("instrumentation/efis", myCockpit_switches, 'Airbus');
  37.  
  38.     nd_display.main = canvas.new({
  39.         "name": "ND",
  40.         "size": [1024, 1024],
  41.         "view": [1024, 1024],
  42.         "mipmapping": 1
  43.     });
  44.  
  45.     # Change ND.screen with the name of the object you are using in your aircraft model for the black screen
  46.     nd_display.main.addPlacement({"node": "ND.screen"});
  47.  
  48.     var group = nd_display.main.createGroup();
  49.     NDCpt.newMFD(group);
  50.     NDCpt.update();
  51.  
  52.     setprop("instrumentation/efis/inputs/plan-wpt-index", -1);
  53.  
  54.     print("ND Canvas Initialized!");
  55. }); # fdm-initialized listener callback
  56.  
  57.  
  58. setlistener("instrumentation/efis/nd/display-mode", func(){
  59.     var canvas_mode = "instrumentation/efis/nd/canvas-display-mode";
  60.     var nd_centered = "instrumentation/efis/inputs/nd-centered";
  61.     var mode = getprop("instrumentation/efis/nd/display-mode");
  62.     var cvs_mode = 'NAV';
  63.     var centered = 1;
  64.     if(mode == 'ILS'){
  65.         cvs_mode = 'APP';
  66.     }
  67.     elsif(mode == 'VOR') {
  68.         cvs_mode = 'VOR';
  69.     }
  70.     elsif(mode == 'NAV'){
  71.         cvs_mode = 'MAP';
  72.     }
  73.     elsif(mode == 'ARC'){
  74.         cvs_mode = 'MAP';
  75.         centered = 0;
  76.     }
  77.     elsif(mode == 'PLAN'){
  78.         cvs_mode = 'PLAN';
  79.     }
  80.     setprop(canvas_mode, cvs_mode);
  81.     setprop(nd_centered, centered);
  82. });
  83.  
  84. # This is optional: you can set the property defined by the 'toggle_wpt_idx' toggle in order to navigate
  85. # the whole flight plan when the ND is in PLAN mode (this is usually linked to the mCDU arrow keys).
  86.  
  87. setlistener("/instrumentation/mcdu/f-pln/disp/first", func{
  88.     var first = getprop("/instrumentation/mcdu/f-pln/disp/first");
  89.     if(typeof(first) == 'nil') first = -1;
  90.     if(getprop('autopilot/route-manager/route/num') == 0) first = -1;
  91.     setprop("instrumentation/efis/inputs/plan-wpt-index", first);
  92.     setprop("instrumentation/efis[1]/inputs/plan-wpt-index", first);
  93. });
  94.  
  95. var showNd = func(nd = nil) {
  96.     if(nd == nil) nd = 'main';
  97.     # The optional second arguments enables creating a window decoration
  98.     var dlg = canvas.Window.new([400, 400], "dialog");
  99.     dlg.setCanvas( nd_display[nd] );
  100. }
RAW Paste Data