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.
18 #include "dynamicloader.hxx"
20 FGAirportDynamicsXMLLoader::FGAirportDynamicsXMLLoader(FGAirportDynamics* dyn):
21 XMLVisitor(), _dynamics(dyn) {}
23 void FGAirportDynamicsXMLLoader::startXML () {
24 //cout << "Start XML" << endl;
27 void FGAirportDynamicsXMLLoader::endXML () {
28 //cout << "End XML" << endl;
31 void FGAirportDynamicsXMLLoader::startElement (const char * name, const XMLAttributes &atts) {
32 // const char *attval;
35 FGTaxiSegment taxiSegment;
37 taxiSegment.setIndex(index);
38 //cout << "Start element " << name << endl;
48 if (name == string("Parking"))
50 for (int i = 0; i < atts.size(); i++)
52 //cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl;
53 attname = atts.getName(i);
54 if (attname == string("index"))
55 park.setIndex(std::atoi(atts.getValue(i)));
56 else if (attname == string("type"))
57 park.setType(atts.getValue(i));
58 else if (attname == string("name"))
59 gateName = atts.getValue(i);
60 else if (attname == string("number"))
61 gateNumber = atts.getValue(i);
62 else if (attname == string("lat"))
63 park.setLatitude(atts.getValue(i));
64 else if (attname == string("lon"))
65 park.setLongitude(atts.getValue(i));
66 else if (attname == string("heading"))
67 park.setHeading(std::atof(atts.getValue(i)));
68 else if (attname == string("radius")) {
69 string radius = atts.getValue(i);
70 if (radius.find("M") != string::npos)
71 radius = radius.substr(0, radius.find("M",0));
72 //cerr << "Radius " << radius <<endl;
73 park.setRadius(std::atof(radius.c_str()));
75 else if (attname == string("airlineCodes"))
76 park.setCodes(atts.getValue(i));
78 park.setName((gateName+gateNumber));
79 _dynamics->addParking(park);
81 if (name == string("node"))
83 for (int i = 0; i < atts.size() ; i++)
85 attname = atts.getName(i);
86 if (attname == string("index"))
87 taxiNode.setIndex(std::atoi(atts.getValue(i)));
88 if (attname == string("lat"))
89 taxiNode.setLatitude(atts.getValue(i));
90 if (attname == string("lon"))
91 taxiNode.setLongitude(atts.getValue(i));
92 if (attname == string("isOnRunway"))
93 taxiNode.setOnRunway((bool) std::atoi(atts.getValue(i)));
94 if (attname == string("holdPointType")) {
95 attval = atts.getValue(i);
96 if (attval==string("none")) {
98 } else if (attval==string("normal")) {
100 } else if (attval==string("CAT II/III")) {
102 } else if (attval==string("PushBack")) {
105 //cerr << "Setting Holding point to " << holdPointType << endl;
106 taxiNode.setHoldPointType(holdPointType);
109 _dynamics->getGroundNetwork()->addNode(taxiNode);
111 if (name == string("arc"))
113 taxiSegment.setIndex(++index);
114 for (int i = 0; i < atts.size() ; i++)
116 attname = atts.getName(i);
117 if (attname == string("begin"))
118 taxiSegment.setStartNodeRef(std::atoi(atts.getValue(i)));
119 if (attname == string("end"))
120 taxiSegment.setEndNodeRef(std::atoi(atts.getValue(i)));
121 if (attname == string("isPushBackRoute"))
122 taxiSegment.setPushBackType((bool) std::atoi(atts.getValue(i)));
124 _dynamics->getGroundNetwork()->addSegment(taxiSegment);
126 // sort by radius, in asending order, so that smaller gates are first in the list
129 void FGAirportDynamicsXMLLoader::endElement (const char * name) {
130 //cout << "End element " << name << endl;
134 void FGAirportDynamicsXMLLoader::data (const char * s, int len) {
135 string token = string(s,len);
136 //cout << "Character data " << string(s,len) << endl;
137 //if ((token.find(" ") == string::npos && (token.find('\n')) == string::npos))
140 //value = string("");
143 void FGAirportDynamicsXMLLoader::pi (const char * target, const char * data) {
144 //cout << "Processing instruction " << target << ' ' << data << endl;
147 void FGAirportDynamicsXMLLoader::warning (const char * message, int line, int column) {
148 SG_LOG(SG_IO, SG_WARN, "Warning: " << message << " (" << line << ',' << column << ')');
151 void FGAirportDynamicsXMLLoader::error (const char * message, int line, int column) {
152 SG_LOG(SG_IO, SG_ALERT, "Error: " << message << " (" << line << ',' << column << ')');