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>
17 #include <Main/globals.hxx>
19 #include "xmlloader.hxx"
20 #include "dynamicloader.hxx"
21 #include "runwayprefloader.hxx"
23 #include "dynamics.hxx"
24 #include "runwayprefs.hxx"
26 XMLLoader::XMLLoader() {}
27 XMLLoader::~XMLLoader() {}
29 string XMLLoader::expandICAODirs(const string in){
30 cerr << "Expanding " << in << endl;
33 snprintf(buffer, 11, "%c/%c/%c", in[0], in[1], in[2]);
34 cerr << "result: " << buffer << endl;
35 return string(buffer);
42 void XMLLoader::load(FGAirportDynamics* d) {
43 FGAirportDynamicsXMLLoader visitor(d);
44 if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == false) {
45 SGPath parkpath( globals->get_fg_root() );
46 parkpath.append( "/AI/Airports/" );
47 parkpath.append( d->getId() );
48 parkpath.append( "parking.xml" );
49 if (parkpath.exists()) {
51 readXML(parkpath.str(), visitor);
54 catch (const sg_exception &e) {
57 string_list sc = globals->get_fg_scenery();
59 snprintf(buffer, 32, "%s.groundnet.xml", d->getId().c_str() );
60 string airportDir = XMLLoader::expandICAODirs(d->getId());
61 for (string_list_iterator i = sc.begin(); i != sc.end(); i++) {
62 SGPath parkpath( *i );
63 parkpath.append( "Airports" );
64 parkpath.append ( airportDir );
65 parkpath.append( string (buffer) );
66 if (parkpath.exists()) {
68 readXML(parkpath.str(), visitor);
71 catch (const sg_exception &e) {
79 void XMLLoader::load(FGRunwayPreference* p) {
80 FGRunwayPreferenceXMLLoader visitor(p);
81 if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == false) {
82 SGPath rwyPrefPath( globals->get_fg_root() );
83 rwyPrefPath.append( "AI/Airports/" );
84 rwyPrefPath.append( p->getId() );
85 rwyPrefPath.append( "rwyuse.xml" );
86 if (rwyPrefPath.exists()) {
88 readXML(rwyPrefPath.str(), visitor);
90 catch (const sg_exception &e) {
94 string_list sc = globals->get_fg_scenery();
96 snprintf(buffer, 32, "%s.rwyuse.xml", p->getId().c_str() );
97 string airportDir = expandICAODirs(p->getId());
98 for (string_list_iterator i = sc.begin(); i != sc.end(); i++) {
100 rwypath.append( "Airports" );
101 rwypath.append ( airportDir );
102 rwypath.append( string(buffer) );
103 if (rwypath.exists()) {
105 readXML(rwypath.str(), visitor);
107 catch (const sg_exception &e) {