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;
46 if (name == string("Parking"))
48 for (int i = 0; i < atts.size(); i++)
50 //cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl;
51 attname = atts.getName(i);
52 if (attname == string("index"))
53 park.setIndex(atoi(atts.getValue(i)));
54 else if (attname == string("type"))
55 park.setType(atts.getValue(i));
56 else if (attname == string("name"))
57 gateName = atts.getValue(i);
58 else if (attname == string("number"))
59 gateNumber = atts.getValue(i);
60 else if (attname == string("lat"))
61 park.setLatitude(atts.getValue(i));
62 else if (attname == string("lon"))
63 park.setLongitude(atts.getValue(i));
64 else if (attname == string("heading"))
65 park.setHeading(atof(atts.getValue(i)));
66 else if (attname == string("radius")) {
67 string radius = atts.getValue(i);
68 if (radius.find("M") != string::npos)
69 radius = radius.substr(0, radius.find("M",0));
70 //cerr << "Radius " << radius <<endl;
71 park.setRadius(atof(radius.c_str()));
73 else if (attname == string("airlineCodes"))
74 park.setCodes(atts.getValue(i));
76 park.setName((gateName+gateNumber));
77 _dynamics->addParking(park);
79 if (name == string("node"))
81 for (int i = 0; i < atts.size() ; i++)
83 attname = atts.getName(i);
84 if (attname == string("index"))
85 taxiNode.setIndex(atoi(atts.getValue(i)));
86 if (attname == string("lat"))
87 taxiNode.setLatitude(atts.getValue(i));
88 if (attname == string("lon"))
89 taxiNode.setLongitude(atts.getValue(i));
90 if (attname == string("isOnRunway"))
91 taxiNode.setOnRunway((bool) atoi(atts.getValue(i)));
92 if (attname == string("holdPointType")) {
93 attval = atts.getValue(i);
94 if (attval==string("none")) {
96 } else if (attval==string("normal")) {
98 } else if (attval==string("CAT II/III")) {
100 } else if (attval==string("PushBack")) {
103 //cerr << "Setting Holding point to " << holdPointType << endl;
104 taxiNode.setHoldPointType(holdPointType);
107 _dynamics->getGroundNetwork()->addNode(taxiNode);
109 if (name == string("arc"))
111 taxiSegment.setIndex(++index);
112 for (int i = 0; i < atts.size() ; i++)
114 attname = atts.getName(i);
115 if (attname == string("begin"))
116 taxiSegment.setStartNodeRef(atoi(atts.getValue(i)));
117 if (attname == string("end"))
118 taxiSegment.setEndNodeRef(atoi(atts.getValue(i)));
119 if (attname == string("isPushBackRoute"))
120 taxiSegment.setPushBackType((bool) atoi(atts.getValue(i)));
122 _dynamics->getGroundNetwork()->addSegment(taxiSegment);
124 // sort by radius, in asending order, so that smaller gates are first in the list
127 void FGAirportDynamicsXMLLoader::endElement (const char * name) {
128 //cout << "End element " << name << endl;
132 void FGAirportDynamicsXMLLoader::data (const char * s, int len) {
133 string token = string(s,len);
134 //cout << "Character data " << string(s,len) << endl;
135 //if ((token.find(" ") == string::npos && (token.find('\n')) == string::npos))
138 //value = string("");
141 void FGAirportDynamicsXMLLoader::pi (const char * target, const char * data) {
142 //cout << "Processing instruction " << target << ' ' << data << endl;
145 void FGAirportDynamicsXMLLoader::warning (const char * message, int line, int column) {
146 SG_LOG(SG_IO, SG_WARN, "Warning: " << message << " (" << line << ',' << column << ')');
149 void FGAirportDynamicsXMLLoader::error (const char * message, int line, int column) {
150 SG_LOG(SG_IO, SG_ALERT, "Error: " << message << " (" << line << ',' << column << ')');