From 3cf771548577ac9018cc70edee72215dfdb9e7af Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 19 Sep 2012 18:40:34 +0100 Subject: [PATCH] Expose the route-path of leg to Nasal. In advance of converting the Map and NavDisplay to use the canvas, expose the full route-path vector for each flight plan leg, as a vector on the leg. Use leg.path() to get this. E.g.: var fp = flightplan(); for (var i=0; i #include #include +#include #include #include @@ -2095,6 +2096,28 @@ static naRef f_leg_setAltitude(naContext c, naRef me, int argc, naRef* args) return naNil(); } +static naRef f_leg_path(naContext c, naRef me, int argc, naRef* args) +{ + FlightPlan::Leg* leg = fpLegGhost(me); + if (!leg) { + naRuntimeError(c, "leg.setAltitude called on non-flightplan-leg object"); + } + + RoutePath path(leg->owner()); + SGGeodVec gv(path.pathForIndex(leg->index())); + + naRef result = naNewVector(c); + BOOST_FOREACH(SGGeod p, gv) { + // construct a geo.Coord! + naRef coord = naNewHash(c); + hashset(c, coord, "lat", naNum(p.getLatitudeDeg())); + hashset(c, coord, "lon", naNum(p.getLongitudeDeg())); + naVec_append(result, coord); + } + + return result; +} + static naRef f_waypoint_navaid(naContext c, naRef me, int argc, naRef* args) { flightgear::Waypt* w = wayptGhost(me); @@ -2297,6 +2320,7 @@ naRef initNasalPositioned(naRef globals, naContext c, naRef gcSave) hashset(c, gcSave, "fpLegProto", fpLegPrototype); hashset(c, fpLegPrototype, "setSpeed", naNewFunc(c, naNewCCode(c, f_leg_setSpeed))); hashset(c, fpLegPrototype, "setAltitude", naNewFunc(c, naNewCCode(c, f_leg_setAltitude))); + hashset(c, fpLegPrototype, "path", naNewFunc(c, naNewCCode(c, f_leg_path))); for(int i=0; funcs[i].name; i++) { hashset(c, globals, funcs[i].name, -- 2.39.5