]> git.mxchange.org Git - flightgear.git/blobdiff - src/Autopilot/route_mgr.cxx
Merge branch 'jmt/units-fix' into maint
[flightgear.git] / src / Autopilot / route_mgr.cxx
index 313cd33ed6564d6901776a82e71c403f33a99df4..d6d65cc208331f6e59f1cb940ffeae4dc518ada9 100644 (file)
@@ -340,9 +340,9 @@ void FGRouteMgr::new_waypoint( const string& target, int n ) {
 SGWayPoint* FGRouteMgr::make_waypoint(const string& tgt ) {
     string target(boost::to_upper_copy(tgt));
     
-    // extract altitude
-    double alt = cruise->getDoubleValue("altitude-ft") * SG_FEET_TO_METER;
     
+    double alt = -9999.0;
+    // extract altitude
     size_t pos = target.find( '@' );
     if ( pos != string::npos ) {
         alt = atof( target.c_str() + pos + 1 );
@@ -455,6 +455,10 @@ void FGRouteMgr::update_mirror() {
 void FGRouteMgr::InputListener::valueChanged(SGPropertyNode *prop)
 {
     const char *s = prop->getStringValue();
+    if (strlen(s) == 0) {
+      return;
+    }
+    
     if (!strcmp(s, "@CLEAR"))
         mgr->init();
     else if (!strcmp(s, "@ACTIVATE"))
@@ -486,7 +490,14 @@ void FGRouteMgr::InputListener::valueChanged(SGPropertyNode *prop)
 
 bool FGRouteMgr::activate()
 {
-  if (_departure) {
+  if (isRouteActive()) {
+    SG_LOG(SG_AUTOPILOT, SG_WARN, "duplicate route-activation, no-op");
+    return false;
+  }
+
+  // only add departure waypoint if we're not airborne, so that
+  // in-air route activation doesn't confuse matters.
+  if (weightOnWheels->getBoolValue() && _departure) {
     string runwayId(departure->getStringValue("runway"));
     FGRunway* runway = NULL;
     if (_departure->hasRunwayWithIdent(runwayId)) {
@@ -709,16 +720,16 @@ void FGRouteMgr::parseRouteWaypoint(SGPropertyNode* aWP)
   }
 
   SGPropertyNode_ptr altProp = aWP->getChild("altitude-ft");
-  double alt = cruise->getDoubleValue("altitude-ft") * SG_FEET_TO_METER;
+  double altM = cruise->getDoubleValue("altitude-ft") * SG_FEET_TO_METER;
   if (altProp) {
-    alt = altProp->getDoubleValue();
+    altM = altProp->getDoubleValue() * SG_FEET_TO_METER;
   }
       
   string ident(aWP->getStringValue("ident"));
   if (aWP->hasChild("longitude-deg")) {
     // explicit longitude/latitude
     SGWayPoint swp(aWP->getDoubleValue("longitude-deg"),
-      aWP->getDoubleValue("latitude-deg"), alt, 
+      aWP->getDoubleValue("latitude-deg"), altM
       SGWayPoint::WGS84, ident, aWP->getStringValue("name"));
     add_waypoint(swp);
   } else if (aWP->hasChild("navid")) {
@@ -739,7 +750,7 @@ void FGRouteMgr::parseRouteWaypoint(SGPropertyNode* aWP)
       SGGeodesy::direct(p->geod(), radialDeg, offsetNm * SG_NM_TO_METER, pos, az2);
     }
     
-    SGWayPoint swp(pos.getLongitudeDeg(), pos.getLatitudeDeg(), alt, 
+    SGWayPoint swp(pos.getLongitudeDeg(), pos.getLatitudeDeg(), altM
       SGWayPoint::WGS84, ident, "");
     add_waypoint(swp);
   } else {
@@ -749,7 +760,7 @@ void FGRouteMgr::parseRouteWaypoint(SGPropertyNode* aWP)
       throw sg_io_exception("bad route file, unknown waypoint:" + ident);
     }
     
-    SGWayPoint swp(p->longitude(), p->latitude(), alt, 
+    SGWayPoint swp(p->longitude(), p->latitude(), altM
       SGWayPoint::WGS84, p->ident(), p->name());
     add_waypoint(swp);
   }
@@ -775,7 +786,11 @@ const char* FGRouteMgr::getDepartureName() const
 
 void FGRouteMgr::setDepartureICAO(const char* aIdent)
 {
-  _departure = FGAirport::findByIdent(aIdent);
+  if ((aIdent == NULL) || (strlen(aIdent) < 4)) {
+    _departure = NULL;
+  } else {
+    _departure = FGAirport::findByIdent(aIdent);
+  }
 }
 
 const char* FGRouteMgr::getDestinationICAO() const
@@ -798,6 +813,10 @@ const char* FGRouteMgr::getDestinationName() const
 
 void FGRouteMgr::setDestinationICAO(const char* aIdent)
 {
-  _destination = FGAirport::findByIdent(aIdent);
+  if ((aIdent == NULL) || (strlen(aIdent) < 4)) {
+    _destination = NULL;
+  } else {
+    _destination = FGAirport::findByIdent(aIdent);
+  }
 }