]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/dynamicloader.cxx
Interim windows build fix
[flightgear.git] / src / Airports / dynamicloader.cxx
index c7b74a58f91d751cafdd758feffd0b9540295ba8..97cab7f105e5ebddef3e7591014e7200cb4a92cd 100644 (file)
 
 #include <cstdlib>
 #include <cstring> // for strcmp
+#include <boost/foreach.hpp>
 
 #include "dynamicloader.hxx"
 
+#include <Navaids/NavDataCache.hxx>
+#include <Airports/dynamics.hxx>
+#include <Airports/airport.hxx>
+#include <Airports/groundnetwork.hxx>
+
+using std::string;
+
 /*****************************************************************************
  * Helper function for parsing position string
  ****************************************************************************/
@@ -53,14 +61,31 @@ void  FGAirportDynamicsXMLLoader::startXML () {
   //cout << "FGAirportDynamicsLoader::Start XML" << endl;
 }
 
-void  FGAirportDynamicsXMLLoader::endXML () {
-  //cout << "End XML" << endl;
+void  FGAirportDynamicsXMLLoader::endXML ()
+{
+  ParkingPushbackIndex::const_iterator it;
+  
+  for (it = _parkingPushbacks.begin(); it != _parkingPushbacks.end(); ++it) {
+    NodeIndexMap::const_iterator j = _indexMap.find(it->second);
+    if (j == _indexMap.end()) {
+      SG_LOG(SG_NAVAID, SG_WARN, "bad groundnet, no node for index:" << it->first);
+      continue;
+    }
+
+    it->first->setPushBackPoint(j->second);
+    
+  }
+  
+  BOOST_FOREACH(FGTaxiNodeRef node, _unreferencedNodes) {
+    SG_LOG(SG_NAVAID, SG_WARN, "unreferenced groundnet node:" << node->ident());
+  }
+  
 }
 
 void FGAirportDynamicsXMLLoader::startParking(const XMLAttributes &atts)
 {
   string type;
-  int index;
+  int index = 0;
   string gateName, gateNumber;
   string lat, lon;
   double heading = 0.0;
@@ -100,18 +125,24 @@ void FGAirportDynamicsXMLLoader::startParking(const XMLAttributes &atts)
  
   SGGeod pos(SGGeod::fromDeg(processPosition(lon), processPosition(lat)));
   
-  FGParking* pk = new FGParking(0, index, pos, heading, radius,
-                                gateName + gateNumber, type, airlineCodes);
-  pk->setPushBackPoint(pushBackRoute);
-  _dynamics->addParking(pk);
+  FGParkingRef parking(new FGParking(index,
+                                     pos, heading, radius,
+                                     gateName + gateNumber,
+                                     type, airlineCodes));
+  if (pushBackRoute > 0) {
+    _parkingPushbacks[parking] = pushBackRoute;
+  }
+  
+  _indexMap[index] = parking;
+  _dynamics->getGroundNetwork()->addParking(parking);
 }
 
 void FGAirportDynamicsXMLLoader::startNode(const XMLAttributes &atts)
 {
-  int index;
+  int index = 0;
   string lat, lon;
-  bool onRunway;
-  int holdPointType;
+  bool onRunway = false;
+  int holdPointType = 0;
   
   for (int i = 0; i < atts.size() ; i++)
        {
@@ -123,7 +154,7 @@ void FGAirportDynamicsXMLLoader::startNode(const XMLAttributes &atts)
          else if (attname == "lon")
            lon = atts.getValue(i);
     else if (attname == "isOnRunway")
-      onRunway = (bool) std::atoi(atts.getValue(i));
+      onRunway = std::atoi(atts.getValue(i)) != 0;
          else if (attname == "holdPointType") {
       string attval = atts.getValue(i);
       if (attval=="none") {
@@ -140,14 +171,19 @@ void FGAirportDynamicsXMLLoader::startNode(const XMLAttributes &atts)
     }
        }
   
+  if (_indexMap.find(index) != _indexMap.end()) {
+    SG_LOG(SG_NAVAID, SG_WARN, "duplicate ground-net index:" << index);
+  }
+  
   SGGeod pos(SGGeod::fromDeg(processPosition(lon), processPosition(lat)));
-  FGTaxiNode* taxiNode = new FGTaxiNode(0, index, pos, onRunway, holdPointType);
-  _dynamics->getGroundNetwork()->addNode(taxiNode);
+  FGTaxiNodeRef node(new FGTaxiNode(index, pos, onRunway, holdPointType));
+  _indexMap[index] = node;
+  _unreferencedNodes.insert(node);
 }
 
 void FGAirportDynamicsXMLLoader::startArc(const XMLAttributes &atts)
 {  
-  int begin, end;
+  int begin = 0, end = 0;
   bool isPushBackRoute = false;
   
   for (int i = 0; i < atts.size() ; i++)
@@ -158,10 +194,40 @@ void FGAirportDynamicsXMLLoader::startArc(const XMLAttributes &atts)
          else if (attname == "end")
            end = std::atoi(atts.getValue(i));
     else if (attname == "isPushBackRoute")
-           isPushBackRoute = (bool) std::atoi(atts.getValue(i));
+           isPushBackRoute = std::atoi(atts.getValue(i)) != 0;
        }
   
-  _dynamics->getGroundNetwork()->addSegment(new FGTaxiSegment(begin, end, isPushBackRoute));
+  IntPair e(begin, end);
+  if (_arcSet.find(e) != _arcSet.end()) {
+    SG_LOG(SG_NAVAID, SG_WARN, _dynamics->parent()->ident() << " ground-net: skipping duplicate edge:" << begin << "->" << end);
+    return;
+  }
+  
+  NodeIndexMap::const_iterator it;
+  FGTaxiNodeRef fromNode, toNode;
+  it = _indexMap.find(begin);
+  if (it == _indexMap.end()) {
+      SG_LOG(SG_NAVAID, SG_WARN, "ground-net: bad edge:" << begin << "->" << end << ", begin index unknown");
+      return;
+  } else {
+      _unreferencedNodes.erase(it->second);
+      fromNode = it->second;
+  }
+
+  it = _indexMap.find(end);
+  if (it == _indexMap.end()) {
+      SG_LOG(SG_NAVAID, SG_WARN, "ground-net: bad edge:" << begin << "->" << end << ", end index unknown");
+      return;
+  } else {
+      _unreferencedNodes.erase(it->second);
+      toNode = it->second;
+  }
+
+  _arcSet.insert(e);  
+  _dynamics->getGroundNetwork()->addSegment(fromNode, toNode);
+  if (isPushBackRoute) {
+      toNode->setIsPushback();
+  }
 }
 
 void FGAirportDynamicsXMLLoader::startElement (const char * name, const XMLAttributes &atts)