]> git.mxchange.org Git - flightgear.git/blob - src/Airports/xmlloader.cxx
Suppress warnings
[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        SG_LOG(SG_GENERAL, SG_DEBUG, "running old loader:" << parkpath.c_str());
52        if (parkpath.exists()) {
53            try {
54                readXML(parkpath.str(), visitor);
55                d->init();
56            } 
57            catch (const sg_exception &) {
58            }
59        }
60     } else {
61         string_list sc = globals->get_fg_scenery();
62         char buffer[32];
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());
73                 try {
74                     readXML(parkpath.str(), visitor);
75                     d->init();
76                 } 
77                 catch (const sg_exception &) {
78                 }
79                 return;
80             }
81         }
82     }
83 }
84
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()) {
93             try {
94                 readXML(rwyPrefPath.str(), visitor);
95             } 
96             catch (const sg_exception &) {
97             }
98          }
99       }  else {
100        string_list sc = globals->get_fg_scenery();
101        char buffer[32];
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()) {
110                try {
111                    readXML(rwypath.str(), visitor);
112                 } 
113                 catch (const sg_exception &) {
114                 }
115                 return;
116             }
117         }
118     }
119 }
120
121 void XMLLoader::load(FGSidStar* p) {
122     //FGRunwayPreferenceXMLLoader visitor(p);
123     if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == true) {
124        string_list sc = globals->get_fg_scenery();
125        char buffer[32];
126        snprintf(buffer, 32, "%s.SID.xml", p->getId().c_str() );
127        string airportDir = expandICAODirs(p->getId());
128        for (string_list_iterator i = sc.begin(); i != sc.end(); i++) {
129            SGPath sidpath( *i );
130            sidpath.append( "Airports" );
131            sidpath.append ( airportDir );
132            sidpath.append( string(buffer) );
133            if (sidpath.exists()) {
134                try {
135                    //readXML(rwypath.str(), visitor);
136                    //cerr << "Reading SID procedure : " << sidpath.str() << endl;
137                    p->load(sidpath);
138                 } 
139                 catch (const sg_exception &) {
140                 }
141                 return;
142             }
143         }
144     }
145 }