]> git.mxchange.org Git - flightgear.git/blob - src/Airports/xmlloader.cxx
Development for two new features:
[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 #include <Main/globals.hxx>
18
19 #include "xmlloader.hxx"
20 #include "dynamicloader.hxx"
21 #include "runwayprefloader.hxx"
22
23 #include "dynamics.hxx"
24 #include "runwayprefs.hxx"
25
26 XMLLoader::XMLLoader() {}
27 XMLLoader::~XMLLoader() {}
28
29 string XMLLoader::expandICAODirs(const string in){
30      cerr << "Expanding " << in << endl;
31      if (in.size() == 4) {
32           char buffer[11];
33           snprintf(buffer, 11, "%c/%c/%c", in[0], in[1], in[2]);
34           cerr << "result: " << buffer << endl;
35           return string(buffer);
36      } else {
37            return in;
38      }
39      //exit(1);
40 }
41
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()) {
50            try {
51                readXML(parkpath.str(), visitor);
52                d->init();
53            } 
54            catch (const sg_exception &e) {
55            }
56        } else {
57             string_list sc = globals->get_fg_scenery();
58             char buffer[32];
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()) {
67                     try {
68                         readXML(parkpath.str(), visitor);
69                         d->init();
70                 } 
71                 catch (const sg_exception &e) {
72                 }
73                 return;
74              }
75          }
76     }
77 }
78
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()) {
87             try {
88                 readXML(rwyPrefPath.str(), visitor);
89             } 
90             catch (const sg_exception &e) {
91             }
92          }
93       }  else {
94        string_list sc = globals->get_fg_scenery();
95        char buffer[32];
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++) {
99            SGPath rwypath( *i );
100            rwypath.append( "Airports" );
101            rwypath.append ( airportDir );
102            rwypath.append( string(buffer) );
103            if (rwypath.exists()) {
104                try {
105                    readXML(rwypath.str(), visitor);
106                 } 
107                 catch (const sg_exception &e) {
108                 }
109                 return;
110             }
111         }
112     }
113 }
114