]> git.mxchange.org Git - flightgear.git/commitdiff
Bug #927 - flightplan XML loading.
authorJames Turner <zakalawe@mac.com>
Tue, 27 Nov 2012 22:42:46 +0000 (22:42 +0000)
committerJames Turner <zakalawe@mac.com>
Tue, 27 Nov 2012 22:42:46 +0000 (22:42 +0000)
This bug was caused by the code not tolerating missing navaids / waypoints. Update logic so missing navaids degenerate to basic waypoints without problem. Also tolerate present, but empty, runway properties - don't throw an exception by looking up empty identifiers.

src/Navaids/FlightPlan.cxx
src/Navaids/route.cxx

index 3f3eff4f6dc7e11836349cabd0ccfbd8dd700b2b..cb7e41c0dfe1590084ac2b3cb28012e9b06d031b 100644 (file)
@@ -612,8 +612,9 @@ void FlightPlan::loadXMLRouteHeader(SGPropertyNode_ptr routeData)
     string depIdent = dep->getStringValue("airport");
     setDeparture((FGAirport*) fgFindAirportID(depIdent));
     if (_departure) {
-      if (dep->hasChild("runway")) {
-        setDeparture(_departure->getRunwayByIdent(dep->getStringValue("runway")));
+      string rwy(dep->getStringValue("runway"));
+      if (_departure->hasRunwayWithIdent(rwy)) {
+        setDeparture(_departure->getRunwayByIdent(rwy));
       }
     
       if (dep->hasChild("sid")) {
@@ -628,8 +629,9 @@ void FlightPlan::loadXMLRouteHeader(SGPropertyNode_ptr routeData)
   if (dst) {
     setDestination((FGAirport*) fgFindAirportID(dst->getStringValue("airport")));
     if (_destination) {
-      if (dst->hasChild("runway")) {
-        setDestination(_destination->getRunwayByIdent(dst->getStringValue("runway")));
+      string rwy(dst->getStringValue("runway"));
+      if (_destination->hasRunwayWithIdent(rwy)) {
+        setDestination(_destination->getRunwayByIdent(rwy));
       }
       
       if (dst->hasChild("star")) {
@@ -709,18 +711,23 @@ WayptRef FlightPlan::parseVersion1XMLWaypt(SGPropertyNode* aWP)
   } else {
     string nid = aWP->getStringValue("navid", ident.c_str());
     FGPositionedRef p = FGPositioned::findClosestWithIdent(nid, lastPos);
-    if (!p) {
-      throw sg_io_exception("bad route file, unknown navid:" + nid);
+    SGGeod pos;
+    
+    if (p) {
+      pos = p->geod();
+    } else {
+      SG_LOG(SG_GENERAL, SG_WARN, "unknown navaid in flightplan:" << nid);
+      pos = SGGeod::fromDeg(aWP->getDoubleValue("longitude-deg"),
+                            aWP->getDoubleValue("latitude-deg"));
     }
     
-    SGGeod pos(p->geod());
     if (aWP->hasChild("offset-nm") && aWP->hasChild("offset-radial")) {
       double radialDeg = aWP->getDoubleValue("offset-radial");
       // convert magnetic radial to a true radial!
       radialDeg += magvarDegAt(pos);
       double offsetNm = aWP->getDoubleValue("offset-nm");
       double az2;
-      SGGeodesy::direct(p->geod(), radialDeg, offsetNm * SG_NM_TO_METER, pos, az2);
+      SGGeodesy::direct(pos, radialDeg, offsetNm * SG_NM_TO_METER, pos, az2);
     }
     
     w = new BasicWaypt(pos, ident, NULL);
index 952860c4d653e490690a5112ca4e40cf6a3fb416..9123d24c3059b0cc3cb6698b0d928fead8b7219f 100644 (file)
@@ -237,7 +237,17 @@ WayptRef Waypt::createFromProperties(RouteBase* aOwner, SGPropertyNode_ptr aProp
       "Waypt::createFromProperties");
   }
   
-  WayptRef nd(createInstance(aOwner, aProp->getStringValue("type")));
+  try {
+    WayptRef nd(createInstance(aOwner, aProp->getStringValue("type")));
+    nd->initFromProperties(aProp);
+    return nd;
+  } catch (sg_exception& e) {
+    SG_LOG(SG_GENERAL, SG_WARN, "failed to create waypoint, trying basic:" << e.getMessage());
+  }
+  
+// if we failed to make the waypoint, try again making a basic waypoint.
+// this handles the case where a navaid waypoint is missing, for example
+  WayptRef nd(new BasicWaypt(aOwner));
   nd->initFromProperties(aProp);
   return nd;
 }