1 // This program is free software; you can redistribute it and/or
2 // modify it under the terms of the GNU General Public License as
3 // published by the Free Software Foundation; either version 2 of the
4 // License, or (at your option) any later version.
6 // This program is distributed in the hope that it will be useful, but
7 // WITHOUT ANY WARRANTY; without even the implied warranty of
8 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 // General Public License for more details.
11 // You should have received a copy of the GNU General Public License
12 // along with this program; if not, write to the Free Software
13 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include <simgear/misc/sg_path.hxx>
21 #include <simgear/xml/easyxml.hxx>
22 #include <simgear/misc/strutils.hxx>
24 #include <Main/globals.hxx>
25 #include <Main/fg_props.hxx>
27 #include "xmlloader.hxx"
28 #include "dynamicloader.hxx"
29 #include "runwayprefloader.hxx"
31 #include "dynamics.hxx"
32 #include "runwayprefs.hxx"
36 XMLLoader::XMLLoader() {}
37 XMLLoader::~XMLLoader() {}
39 void XMLLoader::load(FGAirportDynamics* d) {
40 FGAirportDynamicsXMLLoader visitor(d);
41 if (fgGetBool("/sim/paths/use-custom-scenery-data") == false) {
42 SGPath parkpath( globals->get_fg_root() );
43 parkpath.append( "/AI/Airports/" );
44 parkpath.append( d->getId() );
45 parkpath.append( "parking.xml" );
46 SG_LOG(SG_GENERAL, SG_DEBUG, "running old loader:" << parkpath.c_str());
47 if (parkpath.exists()) {
49 readXML(parkpath.str(), visitor);
52 catch (const sg_exception &) {
56 if(loadAirportXMLDataIntoVisitor(d->getId(), "groundnet", visitor)) {
62 void XMLLoader::load(FGRunwayPreference* p) {
63 FGRunwayPreferenceXMLLoader visitor(p);
64 if (fgGetBool("/sim/paths/use-custom-scenery-data") == false) {
65 SGPath rwyPrefPath( globals->get_fg_root() );
66 rwyPrefPath.append( "AI/Airports/" );
67 rwyPrefPath.append( p->getId() );
68 rwyPrefPath.append( "rwyuse.xml" );
69 if (rwyPrefPath.exists()) {
71 readXML(rwyPrefPath.str(), visitor);
73 catch (const sg_exception &) {
77 loadAirportXMLDataIntoVisitor(p->getId(), "rwyuse", visitor);
81 void XMLLoader::load(FGSidStar* p) {
83 if (findAirportData(p->getId(), "SID", path)) {
88 bool XMLLoader::findAirportData(const std::string& aICAO,
89 const std::string& aFileName, SGPath& aPath)
91 string fileName(aFileName);
92 if (!simgear::strutils::ends_with(aFileName, ".xml")) {
93 fileName.append(".xml");
96 string_list sc = globals->get_fg_scenery();
98 ::snprintf(buffer, 128, "%c/%c/%c/%s.%s",
99 aICAO[0], aICAO[1], aICAO[2],
100 aICAO.c_str(), fileName.c_str());
102 for (string_list_iterator it = sc.begin(); it != sc.end(); ++it) {
103 // fg_senery contains empty strings as "markers" (see FGGlobals::set_fg_scenery)
106 path.append("Airports");
107 path.append(string(buffer));
113 } // of scenery path iteration
117 bool XMLLoader::loadAirportXMLDataIntoVisitor(const string& aICAO,
118 const string& aFileName, XMLVisitor& aVisitor)
121 if (!findAirportData(aICAO, aFileName, path)) {
122 SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: failed to find data for " << aICAO << "/" << aFileName);
126 SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: loading from " << path.str());
127 readXML(path.str(), aVisitor);