CVS: source/src/Autopilot route_mgr.cxx, 1.41, 1.42 route_mgr.hxx, 1.22, 1.23

James Turner <[email protected]> Mon, 12 Apr 2010 18:27:33 -0500
Newsgroups gmane.games.flightgear.cvc
Message-ID <[email protected]>
Update of /var/cvs/FlightGear-0.9/source/src/Autopilot
In directory baron.flightgear.org:/tmp/cvs-serv11371/src/Autopilot

Modified Files:
	route_mgr.cxx route_mgr.hxx 
Log Message:
Support loading plain-text routes, and stop aggressively using the cruise altitude when loading waypoints.


Index: route_mgr.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Autopilot/route_mgr.cxx,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- route_mgr.cxx	27 Mar 2010 17:51:20 -0000	1.41
+++ route_mgr.cxx	12 Apr 2010 23:27:29 -0000	1.42
@@ -39,6 +39,7 @@
 
 #include <simgear/misc/strutils.hxx>
 #include <simgear/structure/exception.hxx>
+#include <simgear/misc/sgstream.hxx>
 
 #include <simgear/props/props_io.hxx>
 #include <simgear/misc/sg_path.hxx>
@@ -666,16 +667,23 @@
 
 void FGRouteMgr::loadRoute()
 {
-  try {
-    // deactivate route first
-    active->setBoolValue(false);
-    
-    SGPropertyNode_ptr routeData(new SGPropertyNode);
-    SGPath path(_pathNode->getStringValue());
+  // deactivate route first
+  active->setBoolValue(false);
+  
+  SGPropertyNode_ptr routeData(new SGPropertyNode);
+  SGPath path(_pathNode->getStringValue());
+  
+  SG_LOG(SG_IO, SG_INFO, "going to read flight-plan from:" << path.str());
     
-    SG_LOG(SG_IO, SG_INFO, "going to read flight-plan from:" << path.str());
+  try {
     readProperties(path.str(), routeData);
-    
+  } catch (sg_exception& e) {
+    // if XML parsing fails, the file might be simple textual list of waypoints
+    loadPlainTextRoute(path);
+    return;
+  }
+  
+  try {
   // departure nodes
     SGPropertyNode* dep = routeData->getChild("departure");
     if (!dep) {
@@ -704,7 +712,9 @@
   // cruise
     SGPropertyNode* crs = routeData->getChild("cruise");
     if (crs) {
-      cruise->setDoubleValue(crs->getDoubleValue("speed"));
+      cruise->setDoubleValue("speed-kts", crs->getDoubleValue("speed-kts"));
+      cruise->setDoubleValue("mach", crs->getDoubleValue("mach"));
+      cruise->setDoubleValue("altitude-ft", crs->getDoubleValue("altitude-ft"));
     } // of cruise data loading
 
   // route nodes
@@ -735,7 +745,7 @@
   }
 
   SGPropertyNode_ptr altProp = aWP->getChild("altitude-ft");
-  double altM = cruise->getDoubleValue("altitude-ft") * SG_FEET_TO_METER;
+  double altM = -9999.0;
   if (altProp) {
     altM = altProp->getDoubleValue() * SG_FEET_TO_METER;
   }
@@ -781,6 +791,26 @@
   }
 }
 
+void FGRouteMgr::loadPlainTextRoute(const SGPath& path)
+{
+  sg_gzifstream in(path.str().c_str());
+  if (!in.is_open()) {
+    return;
+  }
+  
+  _route->clear();
+  while (!in.eof()) {
+    string line;
+    getline(in, line, '\n');
+  // trim CR from end of line, if found
+    if (line[line.size() - 1] == '\r') {
+      line.erase(line.size() - 1, 1);
+    }
+    
+    new_waypoint(line, -1);
+  } // of line iteration
+}
+
 const char* FGRouteMgr::getDepartureICAO() const
 {
   if (!_departure) {

Index: route_mgr.hxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Autopilot/route_mgr.hxx,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- route_mgr.hxx	21 Feb 2010 20:45:08 -0000	1.22
+++ route_mgr.hxx	12 Apr 2010 23:27:29 -0000	1.23
@@ -135,6 +135,9 @@
      */
     bool checkFinished();
     
+    
+    void loadPlainTextRoute(const SGPath& path);
+    
 // tied getters and setters
     const char* getDepartureICAO() const;
     const char* getDepartureName() const;


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev