#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
****************************************************************************/
//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)
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)
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") {
}
}
+ 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)
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)