]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/dynamicloader.cxx
Document that property write-protection is not a security measure
[flightgear.git] / src / Airports / dynamicloader.cxx
index c7b74a58f91d751cafdd758feffd0b9540295ba8..b2b435d73df28bd14ecc59e008ee33025f3375c3 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>
+
+using std::string;
+
 /*****************************************************************************
  * Helper function for parsing position string
  ****************************************************************************/
@@ -53,14 +60,31 @@ void  FGAirportDynamicsXMLLoader::startXML () {
   //cout << "FGAirportDynamicsLoader::Start XML" << endl;
 }
 
-void  FGAirportDynamicsXMLLoader::endXML () {
-  //cout << "End XML" << endl;
+void  FGAirportDynamicsXMLLoader::endXML ()
+{
+  std::map<PositionedID, int>::iterator it;
+  flightgear::NavDataCache* cache = flightgear::NavDataCache::instance();
+  
+  for (it = _parkingPushbacks.begin(); it != _parkingPushbacks.end(); ++it) {
+    std::map<int, PositionedID>::iterator j = _idMap.find(it->second);
+    if (j == _idMap.end()) {
+      SG_LOG(SG_NAVAID, SG_WARN, "bad groundnet, no node for index:" << it->first);
+      continue;
+    }
+    
+    cache->setParkingPushBackRoute(it->first, j->second);
+  }
+  
+  BOOST_FOREACH(PositionedID id, _unreferencedNodes) {
+    SG_LOG(SG_NAVAID, SG_WARN, "unreferenced groundnet node:" << id);
+  }
+  
 }
 
 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 +124,22 @@ 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);
+  PositionedID guid = flightgear::NavDataCache::instance()->insertParking(gateName + gateNumber, pos,
+                                                      _dynamics->parent()->guid(),
+                                                      heading, radius, type, airlineCodes);
+  if (pushBackRoute > 0) {
+    _parkingPushbacks[guid] = pushBackRoute;
+  }
+  
+  _idMap[index] = guid;
 }
 
 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 +151,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 +168,20 @@ void FGAirportDynamicsXMLLoader::startNode(const XMLAttributes &atts)
     }
        }
   
+  if (_idMap.find(index) != _idMap.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);
+  PositionedID guid = flightgear::NavDataCache::instance()->insertTaxiNode(pos,
+    _dynamics->parent()->guid(), holdPointType, onRunway);
+  _idMap[index] = guid;
+  _unreferencedNodes.insert(guid);
 }
 
 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 +192,25 @@ 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;
+  }
+  
+  _arcSet.insert(e);
+  flightgear::NavDataCache::instance()->insertGroundnetEdge(_dynamics->parent()->guid(),
+                                                            _idMap[begin], _idMap[end]);
+  
+  _unreferencedNodes.erase(_idMap[begin]);
+  _unreferencedNodes.erase(_idMap[end]);
+  
+  if (isPushBackRoute) {
+    flightgear::NavDataCache::instance()->markGroundnetAsPushback(_idMap[end]);
+  }
 }
 
 void FGAirportDynamicsXMLLoader::startElement (const char * name, const XMLAttributes &atts)