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.
16 #include "dynamicloader.hxx"
18 FGAirportDynamicsXMLLoader::FGAirportDynamicsXMLLoader(FGAirportDynamics* dyn):
19 XMLVisitor(), _dynamics(dyn) {}
21 void FGAirportDynamicsXMLLoader::startXML () {
22 //cout << "Start XML" << endl;
25 void FGAirportDynamicsXMLLoader::endXML () {
26 //cout << "End XML" << endl;
29 void FGAirportDynamicsXMLLoader::startElement (const char * name, const XMLAttributes &atts) {
30 // const char *attval;
33 FGTaxiSegment taxiSegment;
35 taxiSegment.setIndex(index);
36 //cout << "Start element " << name << endl;
43 if (name == string("Parking"))
45 for (int i = 0; i < atts.size(); i++)
47 //cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl;
48 attname = atts.getName(i);
49 if (attname == string("index"))
50 park.setIndex(atoi(atts.getValue(i)));
51 else if (attname == string("type"))
52 park.setType(atts.getValue(i));
53 else if (attname == string("name"))
54 gateName = atts.getValue(i);
55 else if (attname == string("number"))
56 gateNumber = atts.getValue(i);
57 else if (attname == string("lat"))
58 park.setLatitude(atts.getValue(i));
59 else if (attname == string("lon"))
60 park.setLongitude(atts.getValue(i));
61 else if (attname == string("heading"))
62 park.setHeading(atof(atts.getValue(i)));
63 else if (attname == string("radius")) {
64 string radius = atts.getValue(i);
65 if (radius.find("M") != string::npos)
66 radius = radius.substr(0, radius.find("M",0));
67 //cerr << "Radius " << radius <<endl;
68 park.setRadius(atof(radius.c_str()));
70 else if (attname == string("airlineCodes"))
71 park.setCodes(atts.getValue(i));
73 park.setName((gateName+gateNumber));
74 _dynamics->addParking(park);
76 if (name == string("node"))
78 for (int i = 0; i < atts.size() ; i++)
80 attname = atts.getName(i);
81 if (attname == string("index"))
82 taxiNode.setIndex(atoi(atts.getValue(i)));
83 if (attname == string("lat"))
84 taxiNode.setLatitude(atts.getValue(i));
85 if (attname == string("lon"))
86 taxiNode.setLongitude(atts.getValue(i));
88 _dynamics->getGroundNetwork()->addNode(taxiNode);
90 if (name == string("arc"))
92 taxiSegment.setIndex(++index);
93 for (int i = 0; i < atts.size() ; i++)
95 attname = atts.getName(i);
96 if (attname == string("begin"))
97 taxiSegment.setStartNodeRef(atoi(atts.getValue(i)));
98 if (attname == string("end"))
99 taxiSegment.setEndNodeRef(atoi(atts.getValue(i)));
101 _dynamics->getGroundNetwork()->addSegment(taxiSegment);
103 // sort by radius, in asending order, so that smaller gates are first in the list
106 void FGAirportDynamicsXMLLoader::endElement (const char * name) {
107 //cout << "End element " << name << endl;
111 void FGAirportDynamicsXMLLoader::data (const char * s, int len) {
112 string token = string(s,len);
113 //cout << "Character data " << string(s,len) << endl;
114 //if ((token.find(" ") == string::npos && (token.find('\n')) == string::npos))
117 //value = string("");
120 void FGAirportDynamicsXMLLoader::pi (const char * target, const char * data) {
121 //cout << "Processing instruction " << target << ' ' << data << endl;
124 void FGAirportDynamicsXMLLoader::warning (const char * message, int line, int column) {
125 SG_LOG(SG_IO, SG_WARN, "Warning: " << message << " (" << line << ',' << column << ')');
128 void FGAirportDynamicsXMLLoader::error (const char * message, int line, int column) {
129 SG_LOG(SG_IO, SG_ALERT, "Error: " << message << " (" << line << ',' << column << ')');