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"
32 #include "runwayprefs.hxx"
36 XMLLoader::XMLLoader() {}
37 XMLLoader::~XMLLoader() {}
39 void XMLLoader::load(FGAirportDynamics* d) {
40 FGAirportDynamicsXMLLoader visitor(d);
41 if(loadAirportXMLDataIntoVisitor(d->getId(), "groundnet", visitor)) {
46 void XMLLoader::load(FGRunwayPreference* p) {
47 FGRunwayPreferenceXMLLoader visitor(p);
48 loadAirportXMLDataIntoVisitor(p->getId(), "rwyuse", visitor);
51 void XMLLoader::load(FGSidStar* p) {
53 if (findAirportData(p->getId(), "SID", path)) {
58 bool XMLLoader::findAirportData(const std::string& aICAO,
59 const std::string& aFileName, SGPath& aPath)
61 string fileName(aFileName);
62 if (!simgear::strutils::ends_with(aFileName, ".xml")) {
63 fileName.append(".xml");
66 string_list sc = globals->get_fg_scenery();
68 ::snprintf(buffer, 128, "%c/%c/%c/%s.%s",
69 aICAO[0], aICAO[1], aICAO[2],
70 aICAO.c_str(), fileName.c_str());
72 for (string_list_iterator it = sc.begin(); it != sc.end(); ++it) {
73 // fg_senery contains empty strings as "markers" (see FGGlobals::set_fg_scenery)
76 path.append("Airports");
77 path.append(string(buffer));
83 } // of scenery path iteration
87 bool XMLLoader::loadAirportXMLDataIntoVisitor(const string& aICAO,
88 const string& aFileName, XMLVisitor& aVisitor)
91 if (!findAirportData(aICAO, aFileName, path)) {
92 SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: failed to find data for " << aICAO << "/" << aFileName);
96 SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: loading from " << path.str());
97 readXML(path.str(), aVisitor);