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;
38 taxiSegment.setIndex(index);
39 //cout << "Start element " << name << endl;
50 if (name == string("Parking"))
53 for (int i = 0; i < atts.size(); i++)
55 //cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl;
56 attname = atts.getName(i);
57 if (attname == string("index")) {
58 park.setIndex(std::atoi(atts.getValue(i)));
59 idxStr = atts.getValue(i);
61 else if (attname == string("type"))
62 park.setType(atts.getValue(i));
63 else if (attname == string("name"))
64 gateName = atts.getValue(i);
65 else if (attname == string("number"))
66 gateNumber = atts.getValue(i);
67 else if (attname == string("lat"))
68 park.setLatitude(atts.getValue(i));
69 else if (attname == string("lon"))
70 park.setLongitude(atts.getValue(i));
71 else if (attname == string("heading"))
72 park.setHeading(std::atof(atts.getValue(i)));
73 else if (attname == string("radius")) {
74 string radius = atts.getValue(i);
75 if (radius.find("M") != string::npos)
76 radius = radius.substr(0, radius.find("M",0));
77 //cerr << "Radius " << radius <<endl;
78 park.setRadius(std::atof(radius.c_str()));
80 else if (attname == string("airlineCodes"))
81 park.setCodes(atts.getValue(i));
82 else if (attname == string("pushBackRoute")) {
83 pushBackPoint = std::atoi(atts.getValue(i));
84 //park.setPushBackPoint(std::atoi(atts.getValue(i)));
88 park.setPushBackPoint(pushBackPoint);
89 park.setName((gateName+gateNumber));
90 //cerr << "Parking " << idxStr << "( " << gateName << gateNumber << ") has pushBackPoint " << pushBackPoint << endl;
91 _dynamics->addParking(park);
93 if (name == string("node"))
95 for (int i = 0; i < atts.size() ; i++)
97 attname = atts.getName(i);
98 if (attname == string("index"))
99 taxiNode.setIndex(std::atoi(atts.getValue(i)));
100 if (attname == string("lat"))
101 taxiNode.setLatitude(atts.getValue(i));
102 if (attname == string("lon"))
103 taxiNode.setLongitude(atts.getValue(i));
104 if (attname == string("isOnRunway"))
105 taxiNode.setOnRunway((bool) std::atoi(atts.getValue(i)));
106 if (attname == string("holdPointType")) {
107 attval = atts.getValue(i);
108 if (attval==string("none")) {
110 } else if (attval==string("normal")) {
112 } else if (attval==string("CAT II/III")) {
114 } else if (attval==string("PushBack")) {
117 //cerr << "Setting Holding point to " << holdPointType << endl;
118 taxiNode.setHoldPointType(holdPointType);
121 _dynamics->getGroundNetwork()->addNode(taxiNode);
123 if (name == string("arc"))
125 taxiSegment.setIndex(++index);
126 for (int i = 0; i < atts.size() ; i++)
128 attname = atts.getName(i);
129 if (attname == string("begin"))
130 taxiSegment.setStartNodeRef(std::atoi(atts.getValue(i)));
131 if (attname == string("end"))
132 taxiSegment.setEndNodeRef(std::atoi(atts.getValue(i)));
133 if (attname == string("isPushBackRoute"))
134 taxiSegment.setPushBackType((bool) std::atoi(atts.getValue(i)));
136 _dynamics->getGroundNetwork()->addSegment(taxiSegment);
138 // sort by radius, in asending order, so that smaller gates are first in the list
141 void FGAirportDynamicsXMLLoader::endElement (const char * name) {
142 //cout << "End element " << name << endl;
143 if (name == string("AWOS")) {
144 _dynamics->addAwosFreq(atoi(value.c_str()));
145 //cerr << "Adding AWOS" << value<< endl;
147 if (name == string("UNICOM")) {
148 _dynamics->addUnicomFreq(atoi(value.c_str()));
149 //cerr << "UNICOM" << value<< endl;
151 if (name == string("CLEARANCE")) {
152 _dynamics->addClearanceFreq(atoi(value.c_str()));
153 //cerr << "Adding CLEARANCE" << value<< endl;
155 if (name == string("GROUND")) {
156 _dynamics->addGroundFreq(atoi(value.c_str()));
157 //cerr << "Adding GROUND" << value<< endl;
160 if (name == string("TOWER")) {
161 _dynamics->addTowerFreq(atoi(value.c_str()));
162 //cerr << "Adding TOWER" << value<< endl;
164 if (name == string("APPROACH")) {
165 _dynamics->addApproachFreq(atoi(value.c_str()));
166 //cerr << "Adding approach" << value<< endl;
171 void FGAirportDynamicsXMLLoader::data (const char * s, int len) {
172 string token = string(s,len);
173 //cout << "Character data " << string(s,len) << endl;
174 if ((token.find(" ") == string::npos && (token.find('\n')) == string::npos))
180 void FGAirportDynamicsXMLLoader::pi (const char * target, const char * data) {
181 //cout << "Processing instruction " << target << ' ' << data << endl;
184 void FGAirportDynamicsXMLLoader::warning (const char * message, int line, int column) {
185 SG_LOG(SG_IO, SG_WARN, "Warning: " << message << " (" << line << ',' << column << ')');
188 void FGAirportDynamicsXMLLoader::error (const char * message, int line, int column) {
189 SG_LOG(SG_IO, SG_ALERT, "Error: " << message << " (" << line << ',' << column << ')');