]> git.mxchange.org Git - flightgear.git/blobdiff - src/Autopilot/route_mgr.cxx
AircraftModel hacking for package support.
[flightgear.git] / src / Autopilot / route_mgr.cxx
index 12237717a24ee40c3c387291ade1edf21b9ced6d..0ef6e72c207da6bfe5be57da8c21c95ed3329016 100644 (file)
@@ -51,6 +51,8 @@
 #include "Navaids/positioned.hxx"
 #include <Navaids/waypoint.hxx>
 #include <Navaids/procedure.hxx>
+#include <Navaids/routePath.hxx>
+
 #include "Airports/airport.hxx"
 #include "Airports/runways.hxx"
 #include <GUI/new_gui.hxx>
@@ -215,7 +217,7 @@ FGRouteMgr::FGRouteMgr() :
   input->setStringValue("");
   input->addChangeListener(listener);
   
-  SGCommandMgr* cmdMgr = SGCommandMgr::instance();
+  SGCommandMgr* cmdMgr = globals->get_commands();
   cmdMgr->addCommand("define-user-waypoint", this, &FGRouteMgr::commandDefineUserWaypoint);
   cmdMgr->addCommand("delete-user-waypoint", this, &FGRouteMgr::commandDeleteUserWaypoint);
     
@@ -238,7 +240,7 @@ FGRouteMgr::~FGRouteMgr()
                _plan->removeDelegate(this);
        }
 
-    SGCommandMgr* cmdMgr = SGCommandMgr::instance();
+    SGCommandMgr* cmdMgr = globals->get_commands();
     cmdMgr->removeCommand("define-user-waypoint");
     cmdMgr->removeCommand("delete-user-waypoint");
     cmdMgr->removeCommand("load-flightplan");
@@ -269,7 +271,7 @@ void FGRouteMgr::init() {
   departure->tie("name", SGRawValueMethods<FGRouteMgr, const char*>(*this, 
     &FGRouteMgr::getDepartureName, NULL));
   departure->tie("field-elevation-ft", SGRawValueMethods<FGRouteMgr, double>(*this, 
-                                                                               &FGRouteMgr::getDestinationFieldElevation, NULL));
+                                                                               &FGRouteMgr::getDepartureFieldElevation, NULL));
   departure->getChild("etd", 0, true);
   departure->getChild("takeoff-time", 0, true);
 
@@ -294,6 +296,7 @@ void FGRouteMgr::init() {
                                                                       &FGRouteMgr::getDestinationFieldElevation, NULL));
   
   destination->getChild("eta", 0, true);
+  destination->getChild("eta-seconds", 0, true);
   destination->getChild("touchdown-time", 0, true);
 
   alternate = fgGetNode(RM "alternate", true);
@@ -335,16 +338,19 @@ void FGRouteMgr::init() {
   wp0->getChild("id", 0, true);
   wp0->getChild("dist", 0, true);
   wp0->getChild("eta", 0, true);
+  wp0->getChild("eta-seconds", 0, true);
   wp0->getChild("bearing-deg", 0, true);
   
   wp1 = fgGetNode(RM "wp", 1, true);
   wp1->getChild("id", 0, true);
   wp1->getChild("dist", 0, true);
   wp1->getChild("eta", 0, true);
+  wp1->getChild("eta-seconds", 0, true);
   
   wpn = fgGetNode(RM "wp-last", 0, true);
   wpn->getChild("dist", 0, true);
   wpn->getChild("eta", 0, true);
+  wpn->getChild("eta-seconds", 0, true);
   
   _pathNode = fgGetNode(RM "file-path", 0, true);
 }
@@ -478,16 +484,18 @@ void FGRouteMgr::update( double dt )
     return;
   }
   
-  double courseDeg;
-  double distanceM;
-  boost::tie(courseDeg, distanceM) = leg->waypoint()->courseAndDistanceFrom(currentPos);
-  
-// update wp0 / wp1 / wp-last
+  // use RoutePath to compute location of active WP
+  RoutePath path(_plan);
+  SGGeod wpPos = path.positionForIndex(_plan->currentIndex());
+  double courseDeg, az2, distanceM;
+  SGGeodesy::inverse(currentPos, wpPos, courseDeg, az2, distanceM);
+
+  // update wp0 / wp1 / wp-last
   wp0->setDoubleValue("dist", distanceM * SG_METER_TO_NM);
   wp0->setDoubleValue("true-bearing-deg", courseDeg);
   courseDeg -= magvar->getDoubleValue(); // expose magnetic bearing
   wp0->setDoubleValue("bearing-deg", courseDeg);
-  setETAPropertyFromDistance(wp0->getChild("eta"), distanceM);
+  setETAPropertyFromDistance(wp0, distanceM);
   
   double totalPathDistanceNm = _plan->totalDistanceNm();
   double totalDistanceRemaining = distanceM * SG_METER_TO_NM; // distance to current waypoint
@@ -503,13 +511,14 @@ void FGRouteMgr::update( double dt )
   
   FlightPlan::Leg* nextLeg = _plan->nextLeg();
   if (nextLeg) {
-    boost::tie(courseDeg, distanceM) = nextLeg->waypoint()->courseAndDistanceFrom(currentPos);
-     
+    wpPos = path.positionForIndex(_plan->currentIndex() + 1);
+    SGGeodesy::inverse(currentPos, wpPos, courseDeg, az2, distanceM);
+
     wp1->setDoubleValue("dist", distanceM * SG_METER_TO_NM);
     wp1->setDoubleValue("true-bearing-deg", courseDeg);
     courseDeg -= magvar->getDoubleValue(); // expose magnetic bearing
     wp1->setDoubleValue("bearing-deg", courseDeg);
-    setETAPropertyFromDistance(wp1->getChild("eta"), distanceM);    
+    setETAPropertyFromDistance(wp1, distanceM);    
     wp1->setDoubleValue("distance-along-route-nm", 
                         nextLeg->distanceAlongRoute());
     wp1->setDoubleValue("remaining-distance-nm", 
@@ -519,7 +528,7 @@ void FGRouteMgr::update( double dt )
   distanceToGo->setDoubleValue(totalDistanceRemaining);
   wpn->setDoubleValue("dist", totalDistanceRemaining);
   ete->setDoubleValue(totalDistanceRemaining / gs * 3600.0);
-  setETAPropertyFromDistance(wpn->getChild("eta"), totalDistanceRemaining);
+  setETAPropertyFromDistance(wpn, totalDistanceRemaining);
 }
 
 void FGRouteMgr::clearRoute()
@@ -575,6 +584,7 @@ void FGRouteMgr::setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDi
 
   char eta_str[64];
   double eta = aDistance * SG_METER_TO_NM / speed;
+  aProp->getChild("eta-seconds")->setIntValue( eta * 3600 );
   if ( eta >= 100.0 ) { 
       eta = 99.999; // clamp
   }
@@ -586,7 +596,7 @@ void FGRouteMgr::setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDi
   int major = (int)eta, 
       minor = (int)((eta - (int)eta) * 60.0);
   snprintf( eta_str, 64, "%d:%02d", major, minor );
-  aProp->setStringValue( eta_str );
+  aProp->getChild("eta")->setStringValue( eta_str );
 }
 
 void FGRouteMgr::removeLegAtIndex(int aIndex)
@@ -736,7 +746,7 @@ bool FGRouteMgr::activate()
     return false;
   }
  
-  _plan->setCurrentIndex(0);
+  _plan->activate();
   active->setBoolValue(true);
   SG_LOG(SG_AUTOPILOT, SG_INFO, "route-manager, activate route ok");
   return true;