2014-04-29 02:26:32 +00:00
|
|
|
# See: http://wiki.flightgear.org/MapStructure
|
2013-12-01 12:29:22 +00:00
|
|
|
# Class things:
|
2014-04-29 02:26:32 +00:00
|
|
|
var name ='VOR';
|
2013-12-01 12:29:22 +00:00
|
|
|
var parents = [SymbolLayer.Controller];
|
|
|
|
var __self__ = caller(0)[0];
|
2014-04-29 02:26:32 +00:00
|
|
|
SymbolLayer.Controller.add(name, __self__);
|
|
|
|
SymbolLayer.add(name, {
|
2013-12-01 12:29:22 +00:00
|
|
|
parents: [SymbolLayer],
|
2014-04-29 02:26:32 +00:00
|
|
|
type: name, # Symbol type
|
2013-12-01 12:29:22 +00:00
|
|
|
df_controller: __self__, # controller to use by default -- this one
|
|
|
|
});
|
|
|
|
var new = func(layer) {
|
2014-04-29 02:26:32 +00:00
|
|
|
|
|
|
|
if(0) {
|
|
|
|
# TODO: generalize and move to MapStructure.nas
|
|
|
|
var required_controllers = [ {name: 'query_range',type:'func'}, ];
|
|
|
|
foreach(var c; required_controllers) {
|
|
|
|
if (!contains(layer.map.controller, c.name) or typeof(layer.map.controller[c.name]) !=c.type)
|
|
|
|
die("Required controller is missing/invalid:"~ c.name ~ ' ['~c.type~']' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-01 12:29:22 +00:00
|
|
|
var m = {
|
|
|
|
parents: [__self__],
|
|
|
|
layer: layer,
|
2014-04-29 02:26:32 +00:00
|
|
|
map: layer.map,
|
2013-12-01 12:29:22 +00:00
|
|
|
active_vors: [],
|
|
|
|
navNs: props.globals.getNode("instrumentation").getChildren("nav"),
|
|
|
|
listeners: [],
|
2014-01-10 03:04:36 +00:00
|
|
|
query_type:'vor',
|
2013-12-01 12:29:22 +00:00
|
|
|
};
|
|
|
|
setsize(m.active_vors, size(m.navNs));
|
|
|
|
foreach (var navN; m.navNs) {
|
|
|
|
append(m.listeners, setlistener(
|
|
|
|
navN.getNode("frequencies/selected-mhz"),
|
|
|
|
func m.changed_freq()
|
|
|
|
));
|
|
|
|
}
|
|
|
|
#call(debug.dump, keys(layer));
|
|
|
|
m.changed_freq(update:0);
|
|
|
|
return m;
|
|
|
|
};
|
|
|
|
var del = func() {
|
2014-04-29 02:26:32 +00:00
|
|
|
printlog(_MP_dbg_lvl, name,".lcontroller.del()");
|
2013-12-01 12:29:22 +00:00
|
|
|
foreach (var l; me.listeners)
|
|
|
|
removelistener(l);
|
|
|
|
};
|
|
|
|
|
|
|
|
# Controller methods
|
|
|
|
var isActive = func(model) {
|
|
|
|
var my_freq = model.frequency/100;
|
|
|
|
foreach (var freq; me.active_vors)
|
|
|
|
if (freq == my_freq) return 1;
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
var changed_freq = func(update=1) {
|
|
|
|
#debug.dump(me.active_vors);
|
|
|
|
foreach (var navN; me.navNs)
|
|
|
|
me.active_vors[ navN.getIndex() ] = navN.getValue("frequencies/selected-mhz");
|
|
|
|
if (update) me.layer.update();
|
|
|
|
};
|
|
|
|
var searchCmd = func {
|
2014-01-24 03:13:54 +00:00
|
|
|
printlog(_MP_dbg_lvl, "Running query:", me.query_type);
|
2014-04-29 02:26:32 +00:00
|
|
|
var range = me.map.getRange();
|
|
|
|
if (range == nil) return;
|
|
|
|
return positioned.findWithinRange(me.map.getPosCoord(), range, me.query_type);
|
2013-12-01 12:29:22 +00:00
|
|
|
};
|
|
|
|
|