]> git.mxchange.org Git - flightgear.git/blob - src/Airports/xmlloader.cxx
Merge branch 'topic/tape' into next
[flightgear.git] / src / Airports / xmlloader.cxx
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.
5 //
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.
10 //
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.
14 //
15
16 #include <simgear/misc/sg_path.hxx>
17
18 #include <Main/globals.hxx>
19 #include <Main/fg_props.hxx>
20
21 #include "xmlloader.hxx"
22 #include "dynamicloader.hxx"
23 #include "runwayprefloader.hxx"
24
25 #include "dynamics.hxx"
26 #include "runwayprefs.hxx"
27
28 XMLLoader::XMLLoader() {}
29 XMLLoader::~XMLLoader() {}
30
31 string XMLLoader::expandICAODirs(const string in){
32      //cerr << "Expanding " << in << endl;
33      if (in.size() == 4) {
34           char buffer[11];
35           snprintf(buffer, 11, "%c/%c/%c", in[0], in[1], in[2]);
36           //cerr << "result: " << buffer << endl;
37           return string(buffer);
38      } else {
39            return in;
40      }
41      //exit(1);
42 }
43
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()) {
52            try {
53                readXML(parkpath.str(), visitor);
54                d->init();
55            } 
56            catch (const sg_exception &e) {
57            }
58        } else {
59             string_list sc = globals->get_fg_scenery();
60             char buffer[32];
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()) {
69                     try {
70                         readXML(parkpath.str(), visitor);
71                         d->init();
72                     } 
73                     catch (const sg_exception &e) {
74                     }
75                     return;
76                 }
77             }
78         }
79     }
80 }
81
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()) {
90             try {
91                 readXML(rwyPrefPath.str(), visitor);
92             } 
93             catch (const sg_exception &e) {
94             }
95          }
96       }  else {
97        string_list sc = globals->get_fg_scenery();
98        char buffer[32];
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()) {
107                try {
108                    readXML(rwypath.str(), visitor);
109                 } 
110                 catch (const sg_exception &e) {
111                 }
112                 return;
113             }
114         }
115     }
116 }
117