X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FAirports%2Fxmlloader.cxx;h=9487144c99817ed42361776b9d4c495d19c368c7;hb=d35b8db13f7aceee46d63b061cd20e6d3968f92a;hp=198f81c9e7b6fda4d00bdadf33bd0126202fc986;hpb=43c47f3823faa0829aada79d64a26c2960d2a1d2;p=flightgear.git diff --git a/src/Airports/xmlloader.cxx b/src/Airports/xmlloader.cxx index 198f81c9e..9487144c9 100644 --- a/src/Airports/xmlloader.cxx +++ b/src/Airports/xmlloader.cxx @@ -15,6 +15,8 @@ #include +#include + #include
#include
@@ -25,93 +27,92 @@ #include "dynamics.hxx" #include "runwayprefs.hxx" +using std::string; + XMLLoader::XMLLoader() {} XMLLoader::~XMLLoader() {} -string XMLLoader::expandICAODirs(const string in){ - //cerr << "Expanding " << in << endl; - if (in.size() == 4) { - char buffer[11]; - snprintf(buffer, 11, "%c/%c/%c", in[0], in[1], in[2]); - //cerr << "result: " << buffer << endl; - return string(buffer); - } else { - return in; - } - //exit(1); -} - void XMLLoader::load(FGAirportDynamics* d) { - FGAirportDynamicsXMLLoader visitor(d); - if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == false) { - SGPath parkpath( globals->get_fg_root() ); - parkpath.append( "/AI/Airports/" ); - parkpath.append( d->getId() ); - parkpath.append( "parking.xml" ); - if (parkpath.exists()) { - try { - readXML(parkpath.str(), visitor); - d->init(); - } - catch (const sg_exception &e) { - } - } else { - string_list sc = globals->get_fg_scenery(); - char buffer[32]; - snprintf(buffer, 32, "%s.groundnet.xml", d->getId().c_str() ); - string airportDir = XMLLoader::expandICAODirs(d->getId()); - for (string_list_iterator i = sc.begin(); i != sc.end(); i++) { - SGPath parkpath( *i ); - parkpath.append( "Airports" ); - parkpath.append ( airportDir ); - parkpath.append( string (buffer) ); - if (parkpath.exists()) { - try { - readXML(parkpath.str(), visitor); - d->init(); - } - catch (const sg_exception &e) { - } - return; - } - } - } + FGAirportDynamicsXMLLoader visitor(d); + if (fgGetBool("/sim/paths/use-custom-scenery-data") == false) { + SGPath parkpath( globals->get_fg_root() ); + parkpath.append( "/AI/Airports/" ); + parkpath.append( d->getId() ); + parkpath.append( "parking.xml" ); + SG_LOG(SG_GENERAL, SG_DEBUG, "running old loader:" << parkpath.c_str()); + if (parkpath.exists()) { + try { + readXML(parkpath.str(), visitor); + d->init(); + } + catch (const sg_exception &) { + } + } + } else { + if(loadAirportXMLDataIntoVisitor(d->getId(), "groundnet", visitor)) { + d->init(); } + } } void XMLLoader::load(FGRunwayPreference* p) { - FGRunwayPreferenceXMLLoader visitor(p); - if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == false) { - SGPath rwyPrefPath( globals->get_fg_root() ); - rwyPrefPath.append( "AI/Airports/" ); - rwyPrefPath.append( p->getId() ); - rwyPrefPath.append( "rwyuse.xml" ); - if (rwyPrefPath.exists()) { - try { - readXML(rwyPrefPath.str(), visitor); - } - catch (const sg_exception &e) { - } - } - } else { - string_list sc = globals->get_fg_scenery(); - char buffer[32]; - snprintf(buffer, 32, "%s.rwyuse.xml", p->getId().c_str() ); - string airportDir = expandICAODirs(p->getId()); - for (string_list_iterator i = sc.begin(); i != sc.end(); i++) { - SGPath rwypath( *i ); - rwypath.append( "Airports" ); - rwypath.append ( airportDir ); - rwypath.append( string(buffer) ); - if (rwypath.exists()) { - try { - readXML(rwypath.str(), visitor); - } - catch (const sg_exception &e) { - } - return; - } + FGRunwayPreferenceXMLLoader visitor(p); + if (fgGetBool("/sim/paths/use-custom-scenery-data") == false) { + SGPath rwyPrefPath( globals->get_fg_root() ); + rwyPrefPath.append( "AI/Airports/" ); + rwyPrefPath.append( p->getId() ); + rwyPrefPath.append( "rwyuse.xml" ); + if (rwyPrefPath.exists()) { + try { + readXML(rwyPrefPath.str(), visitor); + } + catch (const sg_exception &) { } - } + } + } else { + loadAirportXMLDataIntoVisitor(p->getId(), "rwyuse", visitor); + } +} + +void XMLLoader::load(FGSidStar* p) { + SGPath path; + if (findAirportData(p->getId(), "SID", path)) { + p->load(path); + } +} + +bool XMLLoader::findAirportData(const std::string& aICAO, + const std::string& aFileName, SGPath& aPath) +{ + string_list sc = globals->get_fg_scenery(); + char buffer[128]; + ::snprintf(buffer, 128, "%c/%c/%c/%s.%s.xml", + aICAO[0], aICAO[1], aICAO[2], + aICAO.c_str(), aFileName.c_str()); + + for (string_list_iterator it = sc.begin(); it != sc.end(); ++it) { + SGPath path(*it); + path.append("Airports"); + path.append(string(buffer)); + if (path.exists()) { + aPath = path; + return true; + } // of path exists + } // of scenery path iteration + return false; +} + +bool XMLLoader::loadAirportXMLDataIntoVisitor(const string& aICAO, + const string& aFileName, XMLVisitor& aVisitor) +{ + SGPath path; + if (!findAirportData(aICAO, aFileName, path)) { + SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: failed to find data for " << aICAO << "/" << aFileName); + return false; + } + + SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: loading from " << path.str()); + readXML(path.str(), aVisitor); + return true; }