2014-04-29 02:26:32 +00:00
|
|
|
# See: http://wiki.flightgear.org/MapStructure
|
2014-01-10 03:04:36 +00:00
|
|
|
# Class things:
|
|
|
|
var name = 'WPT'; # for waypoints
|
|
|
|
var parents = [SymbolLayer.Controller];
|
|
|
|
var __self__ = caller(0)[0];
|
|
|
|
SymbolLayer.Controller.add(name, __self__);
|
|
|
|
SymbolLayer.add(name, {
|
2014-05-25 18:11:13 +00:00
|
|
|
parents: [MultiSymbolLayer],
|
2014-01-10 03:04:36 +00:00
|
|
|
type: name, # Symbol type
|
|
|
|
df_controller: __self__, # controller to use by default -- this one
|
2014-05-25 18:11:13 +00:00
|
|
|
df_options: { # default configuration options
|
|
|
|
active_node: "/autopilot/route-manager/active",
|
|
|
|
current_wp_node: "/autopilot/route-manager/current-wp",
|
2014-07-08 10:28:26 +00:00
|
|
|
wp_num: "/autopilot/route-manager/route/num",
|
2014-05-25 18:11:13 +00:00
|
|
|
}
|
2014-01-10 03:04:36 +00:00
|
|
|
});
|
|
|
|
var new = func(layer) {
|
|
|
|
var m = {
|
|
|
|
parents: [__self__],
|
|
|
|
layer: layer,
|
2014-06-07 02:12:39 +00:00
|
|
|
options: layer.options,
|
2014-04-29 02:26:32 +00:00
|
|
|
map: layer.map,
|
2014-01-10 03:04:36 +00:00
|
|
|
listeners: [],
|
|
|
|
};
|
2014-05-25 18:11:13 +00:00
|
|
|
layer.searcher._equals = func(l,r) l.equals(r);
|
2014-07-08 10:28:26 +00:00
|
|
|
append(m.listeners, setlistener(layer.options.active_node, func m.layer.update() ), setlistener(layer.options.wp_num, func m.layer.update() ));
|
2015-05-30 18:20:59 +00:00
|
|
|
var driver = opt_member(m.layer.options, 'route_driver');
|
|
|
|
if(driver == nil){
|
|
|
|
driver = RouteDriver.new();
|
|
|
|
}
|
|
|
|
var driver_listeners = driver.getListeners();
|
|
|
|
foreach(var listener; driver_listeners){
|
|
|
|
append(m.listeners, setlistener(listener, func m.layer.update()));
|
|
|
|
}
|
|
|
|
m.route_driver = driver;
|
2014-05-25 18:11:13 +00:00
|
|
|
m.addVisibilityListener();
|
|
|
|
|
2014-01-10 03:04:36 +00:00
|
|
|
return m;
|
|
|
|
};
|
|
|
|
var del = func() {
|
2014-01-27 02:18:30 +00:00
|
|
|
#print(name~"VOR.lcontroller.del()");
|
2014-01-10 03:04:36 +00:00
|
|
|
foreach (var l; me.listeners)
|
|
|
|
removelistener(l);
|
|
|
|
};
|
|
|
|
|
2014-05-25 18:11:13 +00:00
|
|
|
var WPT_model = {
|
2014-06-07 02:12:39 +00:00
|
|
|
new: func(fp, idx, offset=0) {
|
|
|
|
var m = { parents:[WPT_model], idx:(idx+offset) };
|
2014-05-25 18:11:13 +00:00
|
|
|
var wp = fp.getWP(idx);
|
|
|
|
m.name = wp.wp_name;
|
2019-06-24 15:39:51 +00:00
|
|
|
|
2014-05-25 18:11:13 +00:00
|
|
|
var alt = wp.alt_cstr;
|
|
|
|
if (alt != 0)
|
|
|
|
m.name ~= "\n"~alt;
|
|
|
|
|
2019-06-24 15:39:51 +00:00
|
|
|
if (idx > 0) {
|
|
|
|
var path = wp.path();
|
|
|
|
# check for empty path
|
|
|
|
if (size(path) == 0)
|
|
|
|
return nil;
|
|
|
|
var n = wp.path()[-1];
|
|
|
|
} else {
|
|
|
|
var wp2idx = 1; # next waypoint
|
|
|
|
if (fp.getPlanSize() == 1) # if only have one wpt then it must be at element 0.
|
2018-09-29 11:40:33 +00:00
|
|
|
wp2idx = 0;
|
2019-06-24 15:39:51 +00:00
|
|
|
var path = fp.getWP(wp2idx).path();
|
|
|
|
if (size(path) == 0)
|
|
|
|
return nil;
|
|
|
|
var n = fp.getWP(wp2idx).path()[0];
|
|
|
|
}
|
2018-09-29 11:40:33 +00:00
|
|
|
|
2014-05-25 18:11:13 +00:00
|
|
|
(m.lat,m.lon) = (n.lat,n.lon);
|
|
|
|
return m;
|
|
|
|
},
|
|
|
|
equals: func(other) {
|
|
|
|
# this is set on symbol init, so use this for equality...
|
|
|
|
me.name == other.name
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2014-01-10 03:04:36 +00:00
|
|
|
var searchCmd = func {
|
2014-04-29 02:26:32 +00:00
|
|
|
printlog(_MP_dbg_lvl, "Running query: "~name);
|
2014-05-25 18:11:13 +00:00
|
|
|
|
2014-06-07 02:12:39 +00:00
|
|
|
if (!getprop(me.options.active_node)) return [];
|
2015-05-30 18:20:59 +00:00
|
|
|
var driver = me.route_driver;
|
|
|
|
driver.update();
|
2014-01-27 02:18:30 +00:00
|
|
|
var result = [];
|
2015-05-30 18:20:59 +00:00
|
|
|
var planCount = driver.getNumberOfFlightPlans();
|
|
|
|
for(var idx = 0; idx < planCount; idx += 1){
|
|
|
|
var fp = driver.getFlightPlan(idx);
|
|
|
|
var fpSize = fp.getPlanSize(idx);
|
2019-06-24 15:39:51 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < fpSize; i+=1) {
|
|
|
|
var wm = WPT_model.new(fp, i);
|
|
|
|
if (wm != nil)
|
|
|
|
append(result, wm);
|
|
|
|
}
|
2015-05-30 18:20:59 +00:00
|
|
|
}
|
2014-04-29 02:26:32 +00:00
|
|
|
return result;
|
2014-01-10 03:04:36 +00:00
|
|
|
};
|
|
|
|
|