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>
17 #include <simgear/xml/easyxml.hxx>
18 #include <simgear/misc/strutils.hxx>
20 #include <Main/globals.hxx>
21 #include <Main/fg_props.hxx>
23 #include "xmlloader.hxx"
24 #include "dynamicloader.hxx"
25 #include "runwayprefloader.hxx"
27 #include "dynamics.hxx"
28 #include "runwayprefs.hxx"
32 XMLLoader::XMLLoader() {}
33 XMLLoader::~XMLLoader() {}
35 void XMLLoader::load(FGAirportDynamics* d) {
36 FGAirportDynamicsXMLLoader visitor(d);
37 if (fgGetBool("/sim/paths/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()) {
45 readXML(parkpath.str(), visitor);
48 catch (const sg_exception &) {
52 if(loadAirportXMLDataIntoVisitor(d->getId(), "groundnet", visitor)) {
58 void XMLLoader::load(FGRunwayPreference* p) {
59 FGRunwayPreferenceXMLLoader visitor(p);
60 if (fgGetBool("/sim/paths/use-custom-scenery-data") == false) {
61 SGPath rwyPrefPath( globals->get_fg_root() );
62 rwyPrefPath.append( "AI/Airports/" );
63 rwyPrefPath.append( p->getId() );
64 rwyPrefPath.append( "rwyuse.xml" );
65 if (rwyPrefPath.exists()) {
67 readXML(rwyPrefPath.str(), visitor);
69 catch (const sg_exception &) {
73 loadAirportXMLDataIntoVisitor(p->getId(), "rwyuse", visitor);
77 void XMLLoader::load(FGSidStar* p) {
79 if (findAirportData(p->getId(), "SID", path)) {
84 bool XMLLoader::findAirportData(const std::string& aICAO,
85 const std::string& aFileName, SGPath& aPath)
87 string fileName(aFileName);
88 if (!simgear::strutils::ends_with(aFileName, ".xml")) {
89 fileName.append(".xml");
92 string_list sc = globals->get_fg_scenery();
94 ::snprintf(buffer, 128, "%c/%c/%c/%s.%s",
95 aICAO[0], aICAO[1], aICAO[2],
96 aICAO.c_str(), fileName.c_str());
98 for (string_list_iterator it = sc.begin(); it != sc.end(); ++it) {
100 path.append("Airports");
101 path.append(string(buffer));
106 } // of scenery path iteration
110 bool XMLLoader::loadAirportXMLDataIntoVisitor(const string& aICAO,
111 const string& aFileName, XMLVisitor& aVisitor)
114 if (!findAirportData(aICAO, aFileName, path)) {
115 SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: failed to find data for " << aICAO << "/" << aFileName);
119 SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: loading from " << path.str());
120 readXML(path.str(), aVisitor);