Howto:Prototyping a new NavDisplay Style: Difference between revisions

Jump to navigation Jump to search
m
→‎Code: considering this sufficiently complete for now, awaiting bug reports ...
m (→‎Code: considering this sufficiently complete for now, awaiting bug reports ...)
Line 370: Line 370:


<syntaxhighlight lang="xml"><?xml version="1.0"?><?xml version="1.0"?>
<syntaxhighlight lang="xml"><?xml version="1.0"?><?xml version="1.0"?>
<!--
GNU GPL v2.0 (c) FlightGear.org 2016
For details, see: http://wiki.flightgear.org/Howto:Prototyping_a_new_NavDisplay_Style
-->
<PropertyList>
<PropertyList>
   <name>canvas-nd</name>
   <name>canvas-nd</name>
Line 375: Line 381:
   <layout>vbox</layout>
   <layout>vbox</layout>
   <text>
   <text>
     <label>Canvas ND</label>
     <label>Canvas NavDisplay</label>
   </text>
   </text>


Line 386: Line 392:


<checkbox>
<checkbox>
<pref-width>30</pref-width>
<pref-width>40</pref-width>
<pref-height>22</pref-height>
<pref-height>22</pref-height>


Line 429: Line 435:
       <frame>
       <frame>
       <layout>vbox</layout>
       <layout>vbox</layout>
       <padding>30</padding>
       <padding>15</padding>
       <stretch>true</stretch>
       <stretch>true</stretch>


Line 448: Line 454:
         <script>
         <script>
           fgcommand("dialog-close", props.Node.new({"dialog-name": "canvas-nd"}));
           fgcommand("dialog-close", props.Node.new({"dialog-name": "canvas-nd"}));
  fgcommand("reinit", props.Node.new({subsystem:'gui'}));
           settimer(func fgcommand("dialog-show", props.Node.new({"dialog-name": "canvas-nd"})), 0);
           settimer(func fgcommand("dialog-show", props.Node.new({"dialog-name": "canvas-nd"})), 0);
         </script>
         </script>
Line 458: Line 465:
       <group>
       <group>
       <layout>hbox</layout>
       <layout>hbox</layout>
      <padding>5</padding>
       <name>mfd-controls</name>
       <name>mfd-controls</name>
       </group>
       </group>
Line 469: Line 477:
    -->
    -->
    <!-- reducing the dimensions even more will look weird due to layouting issues, given the number of hbox aligned checkbox widgets -->
    <!-- reducing the dimensions even more will look weird due to layouting issues, given the number of hbox aligned checkbox widgets -->
                     <pref-width>400</pref-width>
                     <pref-width>256</pref-width>
                     <pref-height>400</pref-height>
                     <pref-height>256</pref-height>
    <view>1024</view>
    <view>1024</view>
    <view>1024</view>
    <view>1024</view>
Line 534: Line 542:
var target = globals.gui.findElementByName(root,  identifier );
var target = globals.gui.findElementByName(root,  identifier );
if(target == nil) die("Target node not found for identifier:"~identifier);
if(target == nil) die("Target node not found for identifier:"~identifier);
return target;
return target;
}
}
Line 578: Line 585:


var initialize_nd = func(index) {
var initialize_nd = func(index) {
  # print("running init nd");
  var my_canvas = canvas.get( cmdarg() );
  my_canvas = canvas.get( cmdarg() );


  # FIXME: use the proper root here
  # FIXME: use the proper root here
  var myND = setupND(mfd_root: "/instrumentation/efis["~index~"]", my_canvas: my_canvas, index:index);
  var myND = setupND(mfd_root: "/instrumentation/efis["~index~"]", my_canvas: my_canvas, index:index);
};
};


Line 590: Line 594:
var errors = [];
var errors = [];


# NOTE: this requires changes to navdisplay.mfd
# NOTE: this requires changes to navdisplay.mfd (see the wiki article for details)
# call(func[, args[, me[, locals[, error]]]);
# call(func[, args[, me[, locals[, error]]]);
# call(
# call(
Line 624: Line 628:
var getSwitchesForND = func(index) {
var getSwitchesForND = func(index) {
    
    
   var style_property = "/gui/dialogs/canvas-nd/nd["~index~"]/selected-style";
   var style_property = "/fgcanvas/nd["~index~"]/selected-style";
   var style = getprop(style_property);
   var style = getprop(style_property);


   # make sure that the style  is exposed via the property tree
   # make sure that the style  is exposed via the property tree
   if (style == nil) {
   if (style == nil) {
print("Ooops, style was undefined, using default");
style = 'Boeing'; # our default style
style = 'Boeing'; # our default style
setprop(style_property, style);
setprop(style_property, style);
Line 634: Line 639:


   var switches = NDStyles[style].default_switches;
   var switches = NDStyles[style].default_switches;
   print("Using ND style/switches:", style);
   # print("Using ND style/switches:", style);


   if (switches == nil) print("Unknown ND style: ", style);
   if (switches == nil) print("Unknown ND style: ", style);
Line 643: Line 648:
var setupND = func(mfd_root, my_canvas, index) {
var setupND = func(mfd_root, my_canvas, index) {


   var style = getprop("/gui/dialogs/canvas-nd/nd["~index~"]/selected-style") or 'Boeing';
   var style = getprop("/fgcanvas/nd["~index~"]/selected-style") or 'Boeing';


     ##
     ##
Line 656: Line 661:
     var handle = "ND["~index~"]";
     var handle = "ND["~index~"]";
     MFDInstances[handle] = myND;  
     MFDInstances[handle] = myND;  
     # print("ND setup completed");
     # return {nd: myND, property_root: mfd_root};
    return {nd: myND, property_root: mfd_root};
} # setupND()
} # setupND()


# this determines how many NDs will be added to the dialog, and where their controls live in the property tree
# this determines how many NDs will be added to the dialog, and where their controls live in the property tree
# TODO: support default style per ND, different dimensions ?
# TODO: support default style per ND, different dimensions ?
# persistent config/profiles
var canvas_areas = [
var canvas_areas = [
{name: 'captain.ND', property_root:'/instrumentation/efis[0]',},
{name: 'captain.ND', property_root:'/instrumentation/efis[0]',},
{name: 'copilot.ND', property_root:'/instrumentation/efis[1]',},
#{name: 'copilot.ND', property_root:'/instrumentation/efis[1]',},
# you can add more entries below, for example:  
# you can add more entries below, for example:  
# {name: 'engineer.ND', property_root:'/instrumentation/efis[2]',},
        #{name: 'engineer.ND', property_root:'/instrumentation/efis[2]',},
];
];


# procedurally add one canvas for each ND to be shown (requires less code/maintenance, aka DRY)
# procedurally add one canvas for each ND to be shown (requires less code/maintenance, aka DRY)


var index=0;
var totalNDs = getprop("/fgcanvas/total-nd-instances") or 1;
foreach(var c; canvas_areas) {
 
# var index=0;
for(var index=0;index<totalNDs;index+=1) {
var c = {name: 'ND #'~index, property_root:'/instrumentation/efis['~index~']'};
print("Setting up ND:", c.name);
# foreach(var c; canvas_areas) {
var switches = getSwitchesForND(index);
var switches = getSwitchesForND(index);


Line 683: Line 693:
canvasWidget.getNode("text/label",1).setValue(c.name);
canvasWidget.getNode("text/label",1).setValue(c.name);
canvasWidget.getNode("canvas/name").setValue(c.name);
canvasWidget.getNode("canvas/name").setValue(c.name);
var r = getprop("/fgcanvas/nd-resolution") or 420;
canvasWidget.getNode("canvas/pref-width").setValue(r);
canvasWidget.getNode("canvas/pref-height").setValue(r);


# instantiate and populate combo widgets
# instantiate and populate combo widgets
var selectWidgets= [
var selectWidgets= [
{node: 'combo', label:'Style', attribute: 'Style', property:'/gui/dialogs/canvas-nd/nd['~index~']/selected-style', values:keys(NDStyles) },
{node: 'combo', label:'Style', attribute: 'Style', property:'/fgcanvas/nd['~index~']/selected-style', values:keys(NDStyles) },
{node: 'group[1]/combo[2]', label:'nm', attribute: 'RangeNm', property:c.property_root~switches['toggle_range'].path, values:switches['toggle_range'].values },
{node: 'group[1]/combo[2]', label:'nm', attribute: 'RangeNm', property:c.property_root~switches['toggle_range'].path, values:switches['toggle_range'].values },
{node: 'group[1]/combo', label:'', attribute: 'ndMode', property:c.property_root~switches['toggle_display_mode'].path, values:switches['toggle_display_mode'].values },
{node: 'group[1]/combo', label:'', attribute: 'ndMode', property:c.property_root~switches['toggle_display_mode'].path, values:switches['toggle_display_mode'].values },
Line 703: Line 718:


# FIXME: shouldn't hard-code this here ...
# FIXME: shouldn't hard-code this here ...
var keyValueMap = [1,0,-1]; # switches['toggle_lh_vor_adf'].values; # myCockpit_switches['toggle_lh_vor_adf'].values;
var keyValueMap = [1,0,-1]; # switches['toggle_lh_vor_adf'].values;  


# FIXME look up the proper lh/rh values here
# FIXME look up the proper lh/rh values here
# and use the proper root
populateSelectWidget(leftVORADFSelector, "", "VOR/ADF(l)", index, "/instrumentation/efis["~index~"]/inputs/lh-vor-adf", keyValueMap);   
populateSelectWidget(leftVORADFSelector, "", "VOR/ADF(l)", index, "/instrumentation/efis["~index~"]/inputs/lh-vor-adf", keyValueMap);   
var rightVORADFSelector = canvasWidget.getNode("group[1]/combo[3]");
var rightVORADFSelector = canvasWidget.getNode("group[1]/combo[3]");
Line 714: Line 730:
var cb_index = 0;
var cb_index = 0;
# add checkboxes for each boolean switch
# add checkboxes for each boolean switch
#  TODO: customize this for style-specific switches !


# HACK: get rid of this, it's just an alias for now
# HACK: get rid of this, it's just an alias for now
Line 734: Line 749:
} # add checkboxes for each boolean ND switch
} # add checkboxes for each boolean ND switch


index += 1;
# index += 1;
} # foreach ND instance
} # foreach ND instance


Line 768: Line 783:
       </binding>
       </binding>
     </button>
     </button>
<combo>
  <label>Instances</label>
  <name>TotalNDInstances</name>
  <property>/fgcanvas/total-nd-instances</property>
  <value>1</value>
  <value>2</value>
  <value>3</value>
  <value>4</value>
  <value>5</value>
  <binding>
      <command>dialog-apply</command>
      <object-name>TotalNDInstances</object-name>
  </binding> 
  <binding>
        <command>nasal</command>
        <script>
          fgcommand("dialog-close", props.Node.new({"dialog-name": "canvas-nd"}));
  fgcommand("reinit", props.Node.new({subsystem:'gui'}));
          settimer(func fgcommand("dialog-show", props.Node.new({"dialog-name": "canvas-nd"})), 0);
        </script>
      </binding>
  </combo>
  <combo>
  <label>Size</label>
  <name>NDResolution</name>
  <property>/fgcanvas/nd-resolution</property>
  <value>256</value>
  <value>384</value>
  <value>512</value>
  <value>768</value>
  <binding>
      <command>dialog-apply</command>
      <object-name>NDResolution</object-name>
  </binding> 
    <binding>
        <command>nasal</command>
        <script>
          fgcommand("dialog-close", props.Node.new({"dialog-name": "canvas-nd"}));
  fgcommand("reinit", props.Node.new({subsystem:'gui'}));
          settimer(func fgcommand("dialog-show", props.Node.new({"dialog-name": "canvas-nd"})), 0);
        </script>
      </binding>
  </combo>
</group>
</group>


Navigation menu