Howto:Implementing a simple GCA system: Difference between revisions

Jump to navigation Jump to search
Line 258: Line 258:
Once the underlying script is working well enough, we can look into providing a GUI on top of the script using the Canvas GUI library:  
Once the underlying script is working well enough, we can look into providing a GUI on top of the script using the Canvas GUI library:  
<syntaxhighlight lang="nasal">
<syntaxhighlight lang="nasal">
var (width,height) = (320,250);
var (width,height) = (320,350);
var title = 'GCA Dialog ';
var title = 'GCA Dialog ';


# create a new window, dimensions are WIDTH x HEIGHT, using the dialog decoration (i.e. titlebar)
# create a new window, dimensions are WIDTH x HEIGHT, using the dialog decoration (i.e. titlebar)
var window = canvas.Window.new([width,height],"dialog").set('title',title);
var window = canvas.Window.new([width,height],"dialog").set('title',title);


##
##
Line 296: Line 295:
layout.addItem(input);
layout.addItem(input);
input.setText(default_value);
input.setText(default_value);
## TODO: add widget to hash


if (focus)
if (focus)
Line 302: Line 303:


var validateAircraftRoot = func(input) {
var validateAircraftRoot = func(input) {
var root = props.getNode(input);
if (root == nil) return 1; # error
var required_props = ['altitude-ft', 'longitude-deg', 'latitude-deg'];
foreach(var rp; required_props) {
if (root.getNode(rp) == nil) return 1;
}
}


var validateAirport = func(input) {
return 0; # valid root node
}
}


var validateRunway = func(input) {
var validationHelpers = {
}
 
'AircraftRoot': func(input) {
return 0;
},
 
'Airport': func(input) {
return 0;
},
 
'Runway': func(input) {
return 0;
},
 
'FinalApproach': func(input) {
return 0;
},
 
'Glidepath': func(input) {
return 0;
},
 
'SafetySlope': func(input) {
return 0;
},
 
'DecisionHeight': func(input) {
return 0;
},
 
'TouchdownOffset': func(input) {
return 0;
},


var validateGlidepath = func(input) {
}


var validateTouchdownOffset = func(input) {
}; # validationHelpers;
}




var inputs = [
var inputs = [
{text: 'Aircraft root property:', default_value:'/position', focus:1, callback:nil, tooltip:nil, validate: func return 0, convert:nil},
{text: 'Aircraft root property:', default_value:'/position', focus:1, callback:nil, tooltip:nil, validate: 'AircraftRoot', convert:nil},
{text: 'Airport:', default_value:'KSFO', focus:0, callback:nil, tooltip:nil, validate: func return 0, convert:nil},
{text: 'Airport:', default_value:'KSFO', focus:0, callback:nil, tooltip:nil, validate: 'Airport', convert:nil},
{text: 'Runway:', default_value:'28R', focus:0, callback:nil, tooltip:nil, validate: func return 0, convert:nil},
{text: 'Runway:', default_value:'28R', focus:0, callback:nil, tooltip:nil, validate: 'Runway', convert:nil},
{text: 'Glidepath:', default_value:'3.00', focus:0, callback:nil, tooltip:nil, validate: func return 0, convert:nil},
{text: 'Final Approach (nm):', default_value:'10.00', focus:0, callback:nil, tooltip:nil, validate: 'FinalApproach', convert:nil},
{text: 'Touchdown Offset (m):', default_value:'0.00', focus:0, callback:nil, tooltip:nil, validate: func return 0, convert:nil},
 
{text: 'Glidepath:', default_value:'3.00', focus:0, callback:nil, tooltip:nil, validate: 'Glidepath', convert:nil},
{text: 'Safety Slope:', default_value:'2.00', focus:0, callback:nil, tooltip:nil, validate: 'SafetySlope', convert:nil},
 
{text: 'Decision Height (ft):', default_value:'200.00', focus:0, callback:nil, tooltip:nil, validate: 'DecisionHeight', convert:nil},
{text: 'Touchdown Offset (m):', default_value:'0.00', focus:0, callback:nil, tooltip:nil, validate: 'TouchdownOffset', convert:nil},


];
]; # input fields


foreach(var input; inputs) {
foreach(var input; inputs) {
# TODO: pass input hash
  setupLabeledInput(root, myLayout, input.text, input.default_value, input.focus);
  setupLabeledInput(root, myLayout, input.text, input.default_value, input.focus);
}
}
Line 332: Line 374:
var validateFields = func() {
var validateFields = func() {
foreach(var f; inputs) {
foreach(var f; inputs) {
  var result = f.validate();
var widget = nil; # TODO
  var result = validationHelpers[f.validate] ("/position");
  if (result == 1) {
  if (result == 1) {


Line 340: Line 384:
   cb = nil,
   cb = nil,
   buttons = canvas.MessageBox.Ok
   buttons = canvas.MessageBox.Ok
);
); # MessageBox




Navigation menu