]> git.mxchange.org Git - flightgear.git/blob - src/Airports/xmlloader.cxx
Remove /sim/paths/use-custom-scenery-data.
[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 #ifdef HAVE_CONFIG_H
17 #  include "config.h"
18 #endif
19
20 #include <simgear/misc/sg_path.hxx>
21 #include <simgear/xml/easyxml.hxx>
22 #include <simgear/misc/strutils.hxx>
23
24 #include <Main/globals.hxx>
25 #include <Main/fg_props.hxx>
26
27 #include "xmlloader.hxx"
28 #include "dynamicloader.hxx"
29 #include "runwayprefloader.hxx"
30
31 #include "dynamics.hxx"
32 #include "runwayprefs.hxx"
33
34 using std::string;
35
36 XMLLoader::XMLLoader() {}
37 XMLLoader::~XMLLoader() {}
38
39 void XMLLoader::load(FGAirportDynamics* d) {
40   FGAirportDynamicsXMLLoader visitor(d);
41   if(loadAirportXMLDataIntoVisitor(d->getId(), "groundnet", visitor)) {
42     d->init();
43   }
44 }
45
46 void XMLLoader::load(FGRunwayPreference* p) {
47   FGRunwayPreferenceXMLLoader visitor(p);
48   loadAirportXMLDataIntoVisitor(p->getId(), "rwyuse", visitor);
49 }
50
51 void XMLLoader::load(FGSidStar* p) {
52   SGPath path;
53   if (findAirportData(p->getId(), "SID", path)) {
54     p->load(path);
55   }
56 }
57
58 bool XMLLoader::findAirportData(const std::string& aICAO, 
59     const std::string& aFileName, SGPath& aPath)
60 {
61   string fileName(aFileName);
62   if (!simgear::strutils::ends_with(aFileName, ".xml")) {
63     fileName.append(".xml");
64   }
65   
66   string_list sc = globals->get_fg_scenery();
67   char buffer[128];
68   ::snprintf(buffer, 128, "%c/%c/%c/%s.%s", 
69     aICAO[0], aICAO[1], aICAO[2], 
70     aICAO.c_str(), fileName.c_str());
71
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)
74     if (!it->empty()) {
75         SGPath path(*it);
76         path.append("Airports");
77         path.append(string(buffer));
78         if (path.exists()) {
79           aPath = path;
80           return true;
81         } // of path exists
82     }
83   } // of scenery path iteration
84   return false;
85 }
86
87 bool XMLLoader::loadAirportXMLDataIntoVisitor(const string& aICAO, 
88     const string& aFileName, XMLVisitor& aVisitor)
89 {
90   SGPath path;
91   if (!findAirportData(aICAO, aFileName, path)) {
92     SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: failed to find data for " << aICAO << "/" << aFileName);
93     return false;
94   }
95
96   SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: loading from " << path.str());
97   readXML(path.str(), aVisitor);
98   return true;
99 }
100