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 <Main/globals.hxx>
19 #include <Main/fg_props.hxx>
21 #include "xmlloader.hxx"
22 #include "dynamicloader.hxx"
23 #include "runwayprefloader.hxx"
25 #include "dynamics.hxx"
26 #include "runwayprefs.hxx"
28 XMLLoader::XMLLoader() {}
29 XMLLoader::~XMLLoader() {}
31 string XMLLoader::expandICAODirs(const string in){
32 //cerr << "Expanding " << in << endl;
35 snprintf(buffer, 11, "%c/%c/%c", in[0], in[1], in[2]);
36 //cerr << "result: " << buffer << endl;
37 return string(buffer);
44 void XMLLoader::load(FGAirportDynamics* d) {
45 FGAirportDynamicsXMLLoader visitor(d);
46 if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == false) {
47 SGPath parkpath( globals->get_fg_root() );
48 parkpath.append( "/AI/Airports/" );
49 parkpath.append( d->getId() );
50 parkpath.append( "parking.xml" );
51 SG_LOG(SG_GENERAL, SG_DEBUG, "running old loader:" << parkpath.c_str());
52 if (parkpath.exists()) {
54 readXML(parkpath.str(), visitor);
57 catch (const sg_exception &e) {
61 string_list sc = globals->get_fg_scenery();
63 snprintf(buffer, 32, "%s.groundnet.xml", d->getId().c_str() );
64 string airportDir = XMLLoader::expandICAODirs(d->getId());
65 for (string_list_iterator i = sc.begin(); i != sc.end(); i++) {
66 SGPath parkpath( *i );
67 parkpath.append( "Airports" );
68 parkpath.append ( airportDir );
69 parkpath.append( string (buffer) );
70 SG_LOG(SG_GENERAL, SG_DEBUG, "Trying to read ground net:" << parkpath.c_str());
71 if (parkpath.exists()) {
72 SG_LOG(SG_GENERAL, SG_DEBUG, "reading ground net:" << parkpath.c_str());
74 readXML(parkpath.str(), visitor);
77 catch (const sg_exception &e) {
85 void XMLLoader::load(FGRunwayPreference* p) {
86 FGRunwayPreferenceXMLLoader visitor(p);
87 if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == false) {
88 SGPath rwyPrefPath( globals->get_fg_root() );
89 rwyPrefPath.append( "AI/Airports/" );
90 rwyPrefPath.append( p->getId() );
91 rwyPrefPath.append( "rwyuse.xml" );
92 if (rwyPrefPath.exists()) {
94 readXML(rwyPrefPath.str(), visitor);
96 catch (const sg_exception &e) {
100 string_list sc = globals->get_fg_scenery();
102 snprintf(buffer, 32, "%s.rwyuse.xml", p->getId().c_str() );
103 string airportDir = expandICAODirs(p->getId());
104 for (string_list_iterator i = sc.begin(); i != sc.end(); i++) {
105 SGPath rwypath( *i );
106 rwypath.append( "Airports" );
107 rwypath.append ( airportDir );
108 rwypath.append( string(buffer) );
109 if (rwypath.exists()) {
111 readXML(rwypath.str(), visitor);
113 catch (const sg_exception &e) {