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.
22 #include <simgear/misc/sg_path.hxx>
23 #include <simgear/xml/easyxml.hxx>
24 #include <simgear/misc/strutils.hxx>
25 #include <simgear/timing/timestamp.hxx>
27 #include <Main/globals.hxx>
28 #include <Main/fg_props.hxx>
30 #include "xmlloader.hxx"
31 #include "dynamicloader.hxx"
32 #include "runwayprefloader.hxx"
34 #include "dynamics.hxx"
35 #include "airport.hxx"
36 #include "runwayprefs.hxx"
38 #include <Navaids/NavDataCache.hxx>
42 XMLLoader::XMLLoader() {}
43 XMLLoader::~XMLLoader() {}
45 void XMLLoader::load(FGAirportDynamics* d)
48 if (!findAirportData(d->parent()->ident(), "groundnet", path)) {
52 SG_LOG(SG_NAVAID, SG_INFO, "reading groundnet data from " << path);
56 FGAirportDynamicsXMLLoader visitor(d);
57 readXML(path.str(), visitor);
58 } catch (sg_exception& e) {
59 SG_LOG(SG_NAVAID, SG_INFO, "parsing groundnet XML failed:" << e.getFormattedMessage());
62 SG_LOG(SG_NAVAID, SG_INFO, "parsing groundnet XML took " << t.elapsedMSec());
65 void XMLLoader::load(FGRunwayPreference* p) {
66 FGRunwayPreferenceXMLLoader visitor(p);
67 loadAirportXMLDataIntoVisitor(p->getId(), "rwyuse", visitor);
70 bool XMLLoader::findAirportData(const std::string& aICAO,
71 const std::string& aFileName, SGPath& aPath)
73 string fileName(aFileName);
74 if (!simgear::strutils::ends_with(aFileName, ".xml")) {
75 fileName.append(".xml");
78 string_list sc = globals->get_fg_scenery();
80 ::snprintf(buffer, 128, "%c/%c/%c/%s.%s",
81 aICAO[0], aICAO[1], aICAO[2],
82 aICAO.c_str(), fileName.c_str());
84 for (string_list_iterator it = sc.begin(); it != sc.end(); ++it) {
85 // fg_senery contains empty strings as "markers" (see FGGlobals::set_fg_scenery)
88 path.append("Airports");
89 path.append(string(buffer));
95 } // of scenery path iteration
99 bool XMLLoader::loadAirportXMLDataIntoVisitor(const string& aICAO,
100 const string& aFileName, XMLVisitor& aVisitor)
103 if (!findAirportData(aICAO, aFileName, path)) {
104 SG_LOG(SG_NAVAID, SG_DEBUG, "loadAirportXMLDataIntoVisitor: failed to find data for " << aICAO << "/" << aFileName);
108 SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: loading from " << path.str());
109 readXML(path.str(), aVisitor);