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.
16 #include <simgear/misc/sg_path.hxx>
18 #include <simgear/xml/easyxml.hxx>
20 #include <Main/globals.hxx>
21 #include <Main/fg_props.hxx>
23 #include "xmlloader.hxx"
24 #include "dynamicloader.hxx"
25 #include "runwayprefloader.hxx"
27 #include "dynamics.hxx"
28 #include "runwayprefs.hxx"
32 XMLLoader::XMLLoader() {}
33 XMLLoader::~XMLLoader() {}
35 void XMLLoader::load(FGAirportDynamics* d) {
36 FGAirportDynamicsXMLLoader visitor(d);
37 if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == false) {
38 SGPath parkpath( globals->get_fg_root() );
39 parkpath.append( "/AI/Airports/" );
40 parkpath.append( d->getId() );
41 parkpath.append( "parking.xml" );
42 SG_LOG(SG_GENERAL, SG_DEBUG, "running old loader:" << parkpath.c_str());
43 if (parkpath.exists()) {
45 readXML(parkpath.str(), visitor);
48 catch (const sg_exception &) {
52 loadAirportXMLDataIntoVisitor(d->getId(), "groundnet", visitor);
56 void XMLLoader::load(FGRunwayPreference* p) {
57 FGRunwayPreferenceXMLLoader visitor(p);
58 if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == false) {
59 SGPath rwyPrefPath( globals->get_fg_root() );
60 rwyPrefPath.append( "AI/Airports/" );
61 rwyPrefPath.append( p->getId() );
62 rwyPrefPath.append( "rwyuse.xml" );
63 if (rwyPrefPath.exists()) {
65 readXML(rwyPrefPath.str(), visitor);
67 catch (const sg_exception &) {
71 loadAirportXMLDataIntoVisitor(p->getId(), "rwyuse", visitor);
75 void XMLLoader::load(FGSidStar* p) {
77 if (findAirportData(p->getId(), "SID", path)) {
82 bool XMLLoader::findAirportData(const std::string& aICAO,
83 const std::string& aFileName, SGPath& aPath)
85 string_list sc = globals->get_fg_scenery();
87 ::snprintf(buffer, 128, "%c/%c/%c/%s.%s.xml",
88 aICAO[0], aICAO[1], aICAO[2],
89 aICAO.c_str(), aFileName.c_str());
91 for (string_list_iterator it = sc.begin(); it != sc.end(); ++it) {
93 path.append("Airports");
94 path.append(string(buffer));
99 } // of scenery path iteration
104 bool XMLLoader::loadAirportXMLDataIntoVisitor(const string& aICAO,
105 const string& aFileName, XMLVisitor& aVisitor)
108 if (!findAirportData(aICAO, aFileName, path)) {
109 SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: failed to find data for " << aICAO << "/" << aFileName);
113 SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: loading from " << path.str());
114 readXML(path.str(), aVisitor);