]> git.mxchange.org Git - flightgear.git/blobdiff - src/Autopilot/route_mgr.cxx
Clean-up: move autosave.xml loading code to proper method
[flightgear.git] / src / Autopilot / route_mgr.cxx
index 94ec9980e7a8122d5b68f432f560262c9ac4b660..f236884f93a123241680348f60ac71b94187a24d 100644 (file)
@@ -539,9 +539,22 @@ flightgear::WayptRef FGRouteMgr::removeWayptAtIndex(int aIndex)
   return w;
 }
   
+struct NotGeneratedWayptPredicate : public std::unary_function<const Waypt*, bool>
+{
+  bool operator() (const Waypt* w) const
+  {
+    return (w->flag(WPT_GENERATED) == false);
+  }
+};
+
+
 void FGRouteMgr::clearRoute()
 {
-  _route.clear();
+// erase all non-generated waypoints
+  WayptVec::iterator r =  
+    std::remove_if(_route.begin(), _route.end(), NotGeneratedWayptPredicate());
+  _route.erase(r, _route.end());
+  
   _currentIndex = -1;
   
   update_mirror();
@@ -978,7 +991,6 @@ void FGRouteMgr::update_mirror()
 
     const SGGeod& pos(wp->position());
     prop->setStringValue("id", wp->ident().c_str());
-    //prop->setStringValue("name", wp.get_name().c_str());
     prop->setDoubleValue("longitude-deg", pos.getLongitudeDeg());
     prop->setDoubleValue("latitude-deg",pos.getLatitudeDeg());
    
@@ -995,6 +1007,7 @@ void FGRouteMgr::update_mirror()
       double ft = wp->altitudeFt();
       prop->setDoubleValue("altitude-m", ft * SG_FEET_TO_METER);
       prop->setDoubleValue("altitude-ft", ft);
+      prop->setIntValue("flight-level", static_cast<int>(ft / 1000) * 10);
     } else {
       prop->setDoubleValue("altitude-m", -9999.9);
       prop->setDoubleValue("altitude-ft", -9999.9);
@@ -1135,15 +1148,7 @@ void FGRouteMgr::initAtPosition()
 
 bool FGRouteMgr::haveUserWaypoints() const
 {
-  for (int i = 0; i < numWaypts(); i++) {
-    if (!_route[i]->flag(WPT_GENERATED)) {
-      // have a non-generated waypoint, we're done
-      return true;
-    }
-  }
-  
-  // all waypoints are generated
-  return false;
+  return std::find_if(_route.begin(), _route.end(), NotGeneratedWayptPredicate()) != _route.end();
 }
 
 bool FGRouteMgr::activate()
@@ -1273,6 +1278,15 @@ Waypt* FGRouteMgr::wayptAtIndex(int index) const
   return _route[index];
 }
 
+SGPropertyNode_ptr FGRouteMgr::wayptNodeAtIndex(int index) const
+{
+    if ((index < 0) || (index >= numWaypts())) {
+        throw sg_range_exception("waypt index out of range", "FGRouteMgr::wayptAtIndex");
+    }
+    
+    return mirror->getChild("wp", index);
+}
+
 bool FGRouteMgr::saveRoute(const SGPath& path)
 {
   SG_LOG(SG_IO, SG_INFO, "Saving route to " << path.str());
@@ -1556,3 +1570,42 @@ void FGRouteMgr::setDestinationICAO(const char* aIdent)
   
   arrivalChanged();
 }
+
+FGAirportRef FGRouteMgr::departureAirport() const
+{
+    return _departure;
+}
+
+FGAirportRef FGRouteMgr::destinationAirport() const
+{
+    return _destination;
+}
+
+FGRunway* FGRouteMgr::departureRunway() const
+{
+    if (!_departure) {
+        return NULL;
+    }
+    
+    string runwayId(departure->getStringValue("runway"));
+    if (!_departure->hasRunwayWithIdent(runwayId)) {
+        return NULL;
+    }
+    
+    return _departure->getRunwayByIdent(runwayId);
+}
+
+FGRunway* FGRouteMgr::destinationRunway() const
+{
+    if (!_destination) {
+        return NULL;
+    }
+    
+    string runwayId(destination->getStringValue("runway"));
+    if (!_destination->hasRunwayWithIdent(runwayId)) {
+        return NULL;
+    }
+    
+    return _destination->getRunwayByIdent(runwayId);
+}
+