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 string XMLLoader::expandICAODirs(const string& in){
36 //cerr << "Expanding " << in << endl;
39 snprintf(buffer, 11, "%c/%c/%c", in[0], in[1], in[2]);
40 //cerr << "result: " << buffer << endl;
41 return string(buffer);
48 void XMLLoader::load(FGAirportDynamics* d) {
49 FGAirportDynamicsXMLLoader visitor(d);
50 if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == false) {
51 SGPath parkpath( globals->get_fg_root() );
52 parkpath.append( "/AI/Airports/" );
53 parkpath.append( d->getId() );
54 parkpath.append( "parking.xml" );
55 SG_LOG(SG_GENERAL, SG_DEBUG, "running old loader:" << parkpath.c_str());
56 if (parkpath.exists()) {
58 readXML(parkpath.str(), visitor);
61 catch (const sg_exception &) {
65 string_list sc = globals->get_fg_scenery();
67 snprintf(buffer, 32, "%s.groundnet.xml", d->getId().c_str() );
68 string airportDir = XMLLoader::expandICAODirs(d->getId());
69 for (string_list_iterator i = sc.begin(); i != sc.end(); i++) {
70 SGPath parkpath( *i );
71 parkpath.append( "Airports" );
72 parkpath.append ( airportDir );
73 parkpath.append( string (buffer) );
74 SG_LOG(SG_GENERAL, SG_DEBUG, "Trying to read ground net:" << parkpath.c_str());
75 if (parkpath.exists()) {
76 SG_LOG(SG_GENERAL, SG_DEBUG, "reading ground net:" << parkpath.c_str());
78 readXML(parkpath.str(), visitor);
81 catch (const sg_exception &) {
89 void XMLLoader::load(FGRunwayPreference* p) {
90 FGRunwayPreferenceXMLLoader visitor(p);
91 if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == false) {
92 SGPath rwyPrefPath( globals->get_fg_root() );
93 rwyPrefPath.append( "AI/Airports/" );
94 rwyPrefPath.append( p->getId() );
95 rwyPrefPath.append( "rwyuse.xml" );
96 if (rwyPrefPath.exists()) {
98 readXML(rwyPrefPath.str(), visitor);
100 catch (const sg_exception &) {
104 string_list sc = globals->get_fg_scenery();
106 snprintf(buffer, 32, "%s.rwyuse.xml", p->getId().c_str() );
107 string airportDir = expandICAODirs(p->getId());
108 for (string_list_iterator i = sc.begin(); i != sc.end(); i++) {
109 SGPath rwypath( *i );
110 rwypath.append( "Airports" );
111 rwypath.append ( airportDir );
112 rwypath.append( string(buffer) );
113 if (rwypath.exists()) {
115 readXML(rwypath.str(), visitor);
117 catch (const sg_exception &) {
125 void XMLLoader::load(FGSidStar* p) {
126 //FGRunwayPreferenceXMLLoader visitor(p);
127 if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == true) {
128 string_list sc = globals->get_fg_scenery();
130 snprintf(buffer, 32, "%s.SID.xml", p->getId().c_str() );
131 string airportDir = expandICAODirs(p->getId());
132 for (string_list_iterator i = sc.begin(); i != sc.end(); i++) {
133 SGPath sidpath( *i );
134 sidpath.append( "Airports" );
135 sidpath.append ( airportDir );
136 sidpath.append( string(buffer) );
137 if (sidpath.exists()) {
139 //readXML(rwypath.str(), visitor);
140 //cerr << "Reading SID procedure : " << sidpath.str() << endl;
143 catch (const sg_exception &) {
151 bool XMLLoader::findAirportData(const std::string& aICAO,
152 const std::string& aFileName, SGPath& aPath)
154 string_list sc = globals->get_fg_scenery();
156 ::snprintf(buffer, 128, "%c/%c/%c/%s.%s.xml",
157 aICAO[0], aICAO[1], aICAO[2],
158 aICAO.c_str(), aFileName.c_str());
160 for (string_list_iterator it = sc.begin(); it != sc.end(); ++it) {
162 path.append("Airports");
163 path.append(string(buffer));
168 } // of scenery path iteration
174 bool XMLLoader::loadAirportXMLDataIntoVisitor(const string& aICAO,
175 const string& aFileName, XMLVisitor& aVisitor)
178 if (!findAirportData(aICAO, aFileName, path)) {
182 readXML(path.str(), aVisitor);