]> git.mxchange.org Git - flightgear.git/commitdiff
Expose the route-path of leg to Nasal.
authorJames Turner <zakalawe@mac.com>
Wed, 19 Sep 2012 17:40:34 +0000 (18:40 +0100)
committerJames Turner <zakalawe@mac.com>
Wed, 19 Sep 2012 17:40:34 +0000 (18:40 +0100)
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<fp.getPlanSize(); i += 1)
{
  var leg = fp.getWP(i);
  debug.dump(leg.path());
}

src/Scripting/NasalPositioned.cxx

index 5b5918af50299199ac4ac830a43613e91268611f..4af3d4fe1fa86436e0d23867a0c7ec561e084111 100644 (file)
@@ -50,6 +50,7 @@
 #include <Navaids/waypoint.hxx>
 #include <Navaids/fix.hxx>
 #include <Autopilot/route_mgr.hxx>
+#include <Navaids/routePath.hxx>
 #include <Navaids/procedure.hxx>
 #include <Navaids/airways.hxx>
 
@@ -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,