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.
20 #include <simgear/misc/sg_path.hxx>
21 #include <simgear/xml/easyxml.hxx>
22 #include <simgear/misc/strutils.hxx>
24 #include <Main/globals.hxx>
25 #include <Main/fg_props.hxx>
27 #include "xmlloader.hxx"
28 #include "dynamicloader.hxx"
29 #include "runwayprefloader.hxx"
31 #include "dynamics.hxx"
33 #include "runwayprefs.hxx"
37 XMLLoader::XMLLoader() {}
38 XMLLoader::~XMLLoader() {}
40 void XMLLoader::load(FGAirportDynamics* d)
42 FGAirportDynamicsXMLLoader visitor(d);
43 if(loadAirportXMLDataIntoVisitor(d->parent()->ident(), "groundnet", visitor)) {
48 void XMLLoader::load(FGRunwayPreference* p) {
49 FGRunwayPreferenceXMLLoader visitor(p);
50 loadAirportXMLDataIntoVisitor(p->getId(), "rwyuse", visitor);
53 bool XMLLoader::findAirportData(const std::string& aICAO,
54 const std::string& aFileName, SGPath& aPath)
56 string fileName(aFileName);
57 if (!simgear::strutils::ends_with(aFileName, ".xml")) {
58 fileName.append(".xml");
61 string_list sc = globals->get_fg_scenery();
63 ::snprintf(buffer, 128, "%c/%c/%c/%s.%s",
64 aICAO[0], aICAO[1], aICAO[2],
65 aICAO.c_str(), fileName.c_str());
67 for (string_list_iterator it = sc.begin(); it != sc.end(); ++it) {
68 // fg_senery contains empty strings as "markers" (see FGGlobals::set_fg_scenery)
71 path.append("Airports");
72 path.append(string(buffer));
78 } // of scenery path iteration
82 bool XMLLoader::loadAirportXMLDataIntoVisitor(const string& aICAO,
83 const string& aFileName, XMLVisitor& aVisitor)
86 if (!findAirportData(aICAO, aFileName, path)) {
87 SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: failed to find data for " << aICAO << "/" << aFileName);
91 SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: loading from " << path.str());
92 readXML(path.str(), aVisitor);