]> git.mxchange.org Git - flightgear.git/blobdiff - src/Autopilot/route_mgr.cxx
Fix shared library build for metar executable
[flightgear.git] / src / Autopilot / route_mgr.cxx
index 044c624c8e7919bfb79d920586da760b54b1d01e..178b7cfa2bc01ac333b19524fe7511c4a566b337 100644 (file)
@@ -379,8 +379,8 @@ void FGRouteMgr::init() {
 void FGRouteMgr::postinit()
 {
   SGPath path(_pathNode->getStringValue());
-  if (path.exists()) {
-    SG_LOG(SG_AUTOPILOT, SG_INFO, "loading flight-plan from:" << path.str());
+  if (!path.isNull()) {
+    SG_LOG(SG_AUTOPILOT, SG_INFO, "loading flight-plan from: " << path.str());
     loadRoute(path);
   }
   
@@ -978,7 +978,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 +994,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);
@@ -1273,6 +1273,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());
@@ -1303,13 +1312,20 @@ bool FGRouteMgr::saveRoute(const SGPath& path)
     writeProperties(path.str(), d, true /* write-all */);
     return true;
   } catch (sg_exception& e) {
-    SG_LOG(SG_IO, SG_WARN, "failed to save flight-plan:" << e.getMessage());
+    SG_LOG(SG_IO, SG_ALERT, "Failed to save flight-plan '" << path.str() << "'. " << e.getMessage());
     return false;
   }
 }
 
 bool FGRouteMgr::loadRoute(const SGPath& path)
 {
+  if (!path.exists())
+  {
+      SG_LOG(SG_IO, SG_ALERT, "Failed to load flight-plan '" << path.str()
+              << "'. The file does not exist.");
+      return false;
+  }
+    
   // deactivate route first
   active->setBoolValue(false);
   
@@ -1335,8 +1351,8 @@ bool FGRouteMgr::loadRoute(const SGPath& path)
     }
     return true;
   } catch (sg_exception& e) {
-    SG_LOG(SG_IO, SG_WARN, "failed to load flight-plan (from '" << e.getOrigin()
-      << "'):" << e.getMessage());
+    SG_LOG(SG_IO, SG_ALERT, "Failed to load flight-plan '" << e.getOrigin()
+      << "'" << e.getMessage());
     return false;
   }
 }
@@ -1456,12 +1472,12 @@ WayptRef FGRouteMgr::parseVersion1XMLWaypt(SGPropertyNode* aWP)
 
 bool FGRouteMgr::loadPlainTextRoute(const SGPath& path)
 {
-  sg_gzifstream in(path.str().c_str());
-  if (!in.is_open()) {
-    return false;
-  }
-  
   try {
+    sg_gzifstream in(path.str().c_str());
+    if (!in.is_open()) {
+        throw sg_io_exception("Cannot open file for reading.");
+    }
+  
     WayptVec wpts;
     while (!in.eof()) {
       string line;
@@ -1478,7 +1494,7 @@ bool FGRouteMgr::loadPlainTextRoute(const SGPath& path)
       
       WayptRef w = waypointFromString(line);
       if (!w) {
-        throw sg_io_exception("failed to create waypoint from line:" + line);
+        throw sg_io_exception("Failed to create waypoint from line '" + line + "'.");
       }
       
       wpts.push_back(w);
@@ -1487,7 +1503,7 @@ bool FGRouteMgr::loadPlainTextRoute(const SGPath& path)
     _route = wpts;
     return true;
   } catch (sg_exception& e) {
-    SG_LOG(SG_IO, SG_WARN, "failed to load route from:" << path.str() << ":" << e.getMessage());
+    SG_LOG(SG_IO, SG_ALERT, "Failed to load route from: '" << path.str() << "'. " << e.getMessage());
     return false;
   }
 }
@@ -1549,3 +1565,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);
+}
+