]> git.mxchange.org Git - flightgear.git/blob - src/Airports/xmlloader.cxx
Update FGRunway to process information from threshold.xml files.
[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 <simgear/xml/easyxml.hxx>
19
20 #include <Main/globals.hxx>
21 #include <Main/fg_props.hxx>
22
23 #include "xmlloader.hxx"
24 #include "dynamicloader.hxx"
25 #include "runwayprefloader.hxx"
26
27 #include "dynamics.hxx"
28 #include "runwayprefs.hxx"
29
30 using std::string;
31
32 XMLLoader::XMLLoader() {}
33 XMLLoader::~XMLLoader() {}
34
35 void XMLLoader::load(FGAirportDynamics* d) {
36   FGAirportDynamicsXMLLoader visitor(d);
37   if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == false) {
38    SGPath parkpath( globals->get_fg_root() );
39    parkpath.append( "/AI/Airports/" );
40    parkpath.append( d->getId() );
41    parkpath.append( "parking.xml" );
42    SG_LOG(SG_GENERAL, SG_DEBUG, "running old loader:" << parkpath.c_str());
43    if (parkpath.exists()) {
44        try {
45            readXML(parkpath.str(), visitor);
46            d->init();
47        } 
48        catch (const sg_exception &) {
49        }
50    }
51   } else {
52     loadAirportXMLDataIntoVisitor(d->getId(), "groundnet", visitor);
53   }
54 }
55
56 void XMLLoader::load(FGRunwayPreference* p) {
57   FGRunwayPreferenceXMLLoader visitor(p);
58   if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == false) {
59     SGPath rwyPrefPath( globals->get_fg_root() );
60     rwyPrefPath.append( "AI/Airports/" );
61     rwyPrefPath.append( p->getId() );
62     rwyPrefPath.append( "rwyuse.xml" );
63     if (rwyPrefPath.exists()) {
64         try {
65             readXML(rwyPrefPath.str(), visitor);
66         } 
67         catch (const sg_exception &) {
68         }
69      }
70   } else {
71     loadAirportXMLDataIntoVisitor(p->getId(), "rwyuse", visitor);
72   }
73 }
74
75 void XMLLoader::load(FGSidStar* p) {
76   SGPath path;
77   if (findAirportData(p->getId(), "SID", path)) {
78     p->load(path);
79   }
80 }
81
82 bool XMLLoader::findAirportData(const std::string& aICAO, 
83     const std::string& aFileName, SGPath& aPath)
84 {
85   string_list sc = globals->get_fg_scenery();
86   char buffer[128];
87   ::snprintf(buffer, 128, "%c/%c/%c/%s.%s.xml", 
88     aICAO[0], aICAO[1], aICAO[2], 
89     aICAO.c_str(), aFileName.c_str());
90
91   for (string_list_iterator it = sc.begin(); it != sc.end(); ++it) {
92     SGPath path(*it);
93     path.append("Airports");
94     path.append(string(buffer));
95     if (path.exists()) {
96       aPath = path;
97       return true;
98     } // of path exists
99   } // of scenery path iteration
100   return false;
101 }
102
103 bool XMLLoader::loadAirportXMLDataIntoVisitor(const string& aICAO, 
104     const string& aFileName, XMLVisitor& aVisitor)
105 {
106   SGPath path;
107   if (!findAirportData(aICAO, aFileName, path)) {
108     SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: failed to find data for " << aICAO << "/" << aFileName);
109     return false;
110   }
111
112   SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: loading from " << path.str());
113   readXML(path.str(), aVisitor);
114   return true;
115 }
116