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 if (parkpath.exists()) {
53 readXML(parkpath.str(), visitor);
56 catch (const sg_exception &e) {
59 string_list sc = globals->get_fg_scenery();
61 snprintf(buffer, 32, "%s.groundnet.xml", d->getId().c_str() );
62 string airportDir = XMLLoader::expandICAODirs(d->getId());
63 for (string_list_iterator i = sc.begin(); i != sc.end(); i++) {
64 SGPath parkpath( *i );
65 parkpath.append( "Airports" );
66 parkpath.append ( airportDir );
67 parkpath.append( string (buffer) );
68 if (parkpath.exists()) {
70 readXML(parkpath.str(), visitor);
73 catch (const sg_exception &e) {
82 void XMLLoader::load(FGRunwayPreference* p) {
83 FGRunwayPreferenceXMLLoader visitor(p);
84 if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == false) {
85 SGPath rwyPrefPath( globals->get_fg_root() );
86 rwyPrefPath.append( "AI/Airports/" );
87 rwyPrefPath.append( p->getId() );
88 rwyPrefPath.append( "rwyuse.xml" );
89 if (rwyPrefPath.exists()) {
91 readXML(rwyPrefPath.str(), visitor);
93 catch (const sg_exception &e) {
97 string_list sc = globals->get_fg_scenery();
99 snprintf(buffer, 32, "%s.rwyuse.xml", p->getId().c_str() );
100 string airportDir = expandICAODirs(p->getId());
101 for (string_list_iterator i = sc.begin(); i != sc.end(); i++) {
102 SGPath rwypath( *i );
103 rwypath.append( "Airports" );
104 rwypath.append ( airportDir );
105 rwypath.append( string(buffer) );
106 if (rwypath.exists()) {
108 readXML(rwypath.str(), visitor);
110 catch (const sg_exception &e) {