X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FAirports%2Fxmlloader.cxx;h=8ff3eb1fdae00f22fbb268c7922702f384091175;hb=2013f7149d239ad6dccd2fc53fb77c4a0c85e484;hp=e808eaf5c01b5fe1871d899d04086c57b28ec65d;hpb=f9de92f53db91c45e4bd885ba606749e9597fdbb;p=flightgear.git diff --git a/src/Airports/xmlloader.cxx b/src/Airports/xmlloader.cxx index e808eaf5c..8ff3eb1fd 100644 --- a/src/Airports/xmlloader.cxx +++ b/src/Airports/xmlloader.cxx @@ -13,7 +13,16 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + #include +#include +#include +#include #include
#include
@@ -23,98 +32,94 @@ #include "runwayprefloader.hxx" #include "dynamics.hxx" +#include "simple.hxx" #include "runwayprefs.hxx" +#include + +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) +{ + SGPath path; + if (!findAirportData(d->parent()->ident(), "groundnet", path)) { + return; + } -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" ); - 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 &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) ); - SG_LOG(SG_GENERAL, SG_DEBUG, "Trying to read ground net:" << parkpath.c_str()); - if (parkpath.exists()) { - SG_LOG(SG_GENERAL, SG_DEBUG, "reading ground net:" << parkpath.c_str()); - try { - readXML(parkpath.str(), visitor); - d->init(); - } - catch (const sg_exception &e) { - } - return; - } - } - } + flightgear::NavDataCache* cache = flightgear::NavDataCache::instance(); + if (!cache->isCachedFileModified(path)) { + return; + } + + SG_LOG(SG_NAVAID, SG_INFO, "reading groundnet data from " << path); + SGTimeStamp t; + try { + flightgear::NavDataCache::Transaction txn(cache); + t.stamp(); + { + // drop all current data + cache->dropGroundnetFor(d->parent()->guid()); + + FGAirportDynamicsXMLLoader visitor(d); + readXML(path.str(), visitor); + } // ensure visitor is destroyed so its destructor runs + cache->stampCacheFile(path); + txn.commit(); + } catch (sg_exception& e) { + SG_LOG(SG_NAVAID, SG_INFO, "parsing groundnet XML failed:" << e.getFormattedMessage()); + } + + SG_LOG(SG_NAVAID, SG_INFO, "parsing groundnet XML took " << t.elapsedMSec()); } 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); + loadAirportXMLDataIntoVisitor(p->getId(), "rwyuse", visitor); +} + +bool XMLLoader::findAirportData(const std::string& aICAO, + const std::string& aFileName, SGPath& aPath) +{ + string fileName(aFileName); + if (!simgear::strutils::ends_with(aFileName, ".xml")) { + fileName.append(".xml"); + } + + string_list sc = globals->get_fg_scenery(); + char buffer[128]; + ::snprintf(buffer, 128, "%c/%c/%c/%s.%s", + aICAO[0], aICAO[1], aICAO[2], + aICAO.c_str(), fileName.c_str()); + + for (string_list_iterator it = sc.begin(); it != sc.end(); ++it) { + // fg_senery contains empty strings as "markers" (see FGGlobals::set_fg_scenery) + if (!it->empty()) { + 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_NAVAID, 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; }