2007-07-05 19:00:59 +00:00
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
//
|
|
|
|
|
2011-11-14 08:38:58 +01:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-02-07 19:00:54 +01:00
|
|
|
#include <cstdio>
|
|
|
|
|
2007-07-04 17:39:03 +00:00
|
|
|
#include <simgear/misc/sg_path.hxx>
|
2009-08-29 10:21:21 +00:00
|
|
|
#include <simgear/xml/easyxml.hxx>
|
2011-05-26 20:18:27 +01:00
|
|
|
#include <simgear/misc/strutils.hxx>
|
2012-10-01 17:18:36 +01:00
|
|
|
#include <simgear/timing/timestamp.hxx>
|
2009-08-29 10:21:21 +00:00
|
|
|
|
2007-07-04 17:39:03 +00:00
|
|
|
#include <Main/globals.hxx>
|
2009-01-30 19:05:27 +00:00
|
|
|
#include <Main/fg_props.hxx>
|
2007-07-04 17:39:03 +00:00
|
|
|
|
|
|
|
#include "xmlloader.hxx"
|
|
|
|
#include "dynamicloader.hxx"
|
|
|
|
#include "runwayprefloader.hxx"
|
|
|
|
|
|
|
|
#include "dynamics.hxx"
|
2013-02-21 11:32:02 +00:00
|
|
|
#include "airport.hxx"
|
2007-07-04 17:39:03 +00:00
|
|
|
#include "runwayprefs.hxx"
|
|
|
|
|
2012-10-01 17:18:36 +01:00
|
|
|
#include <Navaids/NavDataCache.hxx>
|
|
|
|
|
2009-08-29 10:21:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
2007-07-04 17:39:03 +00:00
|
|
|
XMLLoader::XMLLoader() {}
|
|
|
|
XMLLoader::~XMLLoader() {}
|
|
|
|
|
2016-01-10 16:38:01 -06:00
|
|
|
void XMLLoader::load(FGGroundNetwork* net)
|
2012-09-23 21:42:40 +01:00
|
|
|
{
|
2012-10-01 17:18:36 +01:00
|
|
|
SGPath path;
|
2016-01-10 16:38:01 -06:00
|
|
|
if (!findAirportData(net->airport()->ident(), "groundnet", path)) {
|
2012-10-01 17:18:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-24 12:14:56 +00:00
|
|
|
SG_LOG(SG_NAVAID, SG_INFO, "reading groundnet data from " << path);
|
2012-10-01 17:18:36 +01:00
|
|
|
SGTimeStamp t;
|
2015-12-05 00:25:29 +00:00
|
|
|
t.stamp();
|
2012-10-01 17:18:36 +01:00
|
|
|
try {
|
2016-01-10 16:38:01 -06:00
|
|
|
FGGroundNetXMLLoader visitor(net);
|
2016-07-03 23:43:39 +01:00
|
|
|
readXML(path, visitor);
|
2012-10-01 17:18:36 +01:00
|
|
|
} catch (sg_exception& e) {
|
2012-12-23 23:32:53 +00:00
|
|
|
SG_LOG(SG_NAVAID, SG_INFO, "parsing groundnet XML failed:" << e.getFormattedMessage());
|
2012-10-01 17:18:36 +01:00
|
|
|
}
|
|
|
|
|
2012-11-24 12:14:56 +00:00
|
|
|
SG_LOG(SG_NAVAID, SG_INFO, "parsing groundnet XML took " << t.elapsedMSec());
|
2007-07-04 17:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void XMLLoader::load(FGRunwayPreference* p) {
|
2009-08-29 10:21:51 +00:00
|
|
|
FGRunwayPreferenceXMLLoader visitor(p);
|
2012-03-15 18:48:57 +01:00
|
|
|
loadAirportXMLDataIntoVisitor(p->getId(), "rwyuse", visitor);
|
2007-07-04 17:39:03 +00:00
|
|
|
}
|
2009-01-30 18:48:44 +00:00
|
|
|
|
2009-08-29 10:21:21 +00:00
|
|
|
bool XMLLoader::findAirportData(const std::string& aICAO,
|
|
|
|
const std::string& aFileName, SGPath& aPath)
|
|
|
|
{
|
2011-05-25 00:03:51 +01:00
|
|
|
string fileName(aFileName);
|
2011-05-26 20:18:27 +01:00
|
|
|
if (!simgear::strutils::ends_with(aFileName, ".xml")) {
|
2011-05-25 00:03:51 +01:00
|
|
|
fileName.append(".xml");
|
|
|
|
}
|
|
|
|
|
2016-06-21 12:29:04 +01:00
|
|
|
PathList sc = globals->get_fg_scenery();
|
2009-08-29 10:21:21 +00:00
|
|
|
char buffer[128];
|
2011-05-25 00:03:51 +01:00
|
|
|
::snprintf(buffer, 128, "%c/%c/%c/%s.%s",
|
2009-08-29 10:21:21 +00:00
|
|
|
aICAO[0], aICAO[1], aICAO[2],
|
2011-05-25 00:03:51 +01:00
|
|
|
aICAO.c_str(), fileName.c_str());
|
2009-08-29 10:21:21 +00:00
|
|
|
|
2016-06-21 12:29:04 +01:00
|
|
|
for (PathList::const_iterator it = sc.begin(); it != sc.end(); ++it) {
|
2011-08-20 23:02:26 +02:00
|
|
|
// fg_senery contains empty strings as "markers" (see FGGlobals::set_fg_scenery)
|
2016-06-21 12:29:04 +01:00
|
|
|
if (!it->isNull()) {
|
2011-08-20 23:02:26 +02:00
|
|
|
SGPath path(*it);
|
|
|
|
path.append("Airports");
|
|
|
|
path.append(string(buffer));
|
|
|
|
if (path.exists()) {
|
|
|
|
aPath = path;
|
|
|
|
return true;
|
|
|
|
} // of path exists
|
|
|
|
}
|
2009-08-29 10:21:21 +00:00
|
|
|
} // of scenery path iteration
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool XMLLoader::loadAirportXMLDataIntoVisitor(const string& aICAO,
|
|
|
|
const string& aFileName, XMLVisitor& aVisitor)
|
|
|
|
{
|
|
|
|
SGPath path;
|
|
|
|
if (!findAirportData(aICAO, aFileName, path)) {
|
2012-11-24 12:14:56 +00:00
|
|
|
SG_LOG(SG_NAVAID, SG_DEBUG, "loadAirportXMLDataIntoVisitor: failed to find data for " << aICAO << "/" << aFileName);
|
2009-08-29 10:21:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-21 12:28:35 +01:00
|
|
|
SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: loading from " << path);
|
2016-07-03 23:43:39 +01:00
|
|
|
readXML(path, aVisitor);
|
2009-08-29 10:21:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|