]> git.mxchange.org Git - flightgear.git/commitdiff
Route-file saving.
authorjmt <jmt>
Mon, 12 Apr 2010 23:27:48 +0000 (23:27 +0000)
committerTim Moore <timoore33@gmail.com>
Mon, 19 Apr 2010 07:52:32 +0000 (09:52 +0200)
src/Autopilot/route_mgr.cxx

index c9fbe0bfd4e91da22af7c16773c1778e3e8eb911..967ca992a240e2f8d60550a2383f303f6d4f85a2 100644 (file)
@@ -658,10 +658,44 @@ void FGRouteMgr::saveRoute()
   SGPath path(_pathNode->getStringValue());
   SG_LOG(SG_IO, SG_INFO, "Saving route to " << path.str());
   try {
-    writeProperties(path.str(), mirror, false, SGPropertyNode::ARCHIVE);
+    SGPropertyNode_ptr d(new SGPropertyNode);
+    SGPath path(_pathNode->getStringValue());
+    d->setIntValue("version", 1);
+    
+    if (_departure) {
+      d->setStringValue("departure/airport", _departure->ident());
+      d->setStringValue("departure/sid", departure->getStringValue("sid"));
+      d->setStringValue("departure/runway", departure->getStringValue("runway"));
+    }
+    
+    if (_destination) {
+      d->setStringValue("destination/airport", _destination->ident());
+      d->setStringValue("destination/star", destination->getStringValue("star"));
+      d->setStringValue("destination/transition", destination->getStringValue("transition"));
+      d->setStringValue("destination/runway", destination->getStringValue("runway"));
+    }
+  
+    // route nodes
+    SGPropertyNode* routeNode = d->getChild("route", 0, true);
+    for (int i=0; i<_route->size(); ++i) {
+      SGPropertyNode* wpNode = routeNode->getChild("wp",i, true);
+      SGWayPoint wp(_route->get_waypoint(i));
+      
+      wpNode->setStringValue("ident", wp.get_id());
+      wpNode->setStringValue("name", wp.get_name());
+      SGGeod geod(wp.get_target());
+      
+      wpNode->setDoubleValue("longitude-deg", geod.getLongitudeDeg());
+      wpNode->setDoubleValue("latitude-deg", geod.getLatitudeDeg());
+      
+      if (geod.getElevationFt() > -9990.0) {
+        wpNode->setDoubleValue("altitude-ft", geod.getElevationFt());
+      }
+    } // of waypoint iteration
+    
+    writeProperties(path.str(), d, true /* write-all */);
   } catch (const sg_exception &e) {
     SG_LOG(SG_IO, SG_WARN, "Error saving route:" << e.getMessage());
-    //guiErrorMessage("Error writing autosave.xml: ", e);
   }
 }