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.
22 #include "dynamicloader.hxx"
24 /*****************************************************************************
25 * Helper function for parsing position string
26 ****************************************************************************/
27 static double processPosition(const string &pos)
36 prefix= subs.substr(0,1);
37 if (prefix == string("S") || (prefix == string("W")))
39 subs = subs.substr(1, subs.length());
40 degree = subs.substr(0, subs.find(" ",0));
41 decimal = subs.substr(subs.find(" ",0), subs.length());
43 value = sign * (atof(degree.c_str()) + atof(decimal.c_str())/60.0);
47 FGAirportDynamicsXMLLoader::FGAirportDynamicsXMLLoader(FGAirportDynamics* dyn):
48 XMLVisitor(), _dynamics(dyn)
51 void FGAirportDynamicsXMLLoader::startXML () {
52 //cout << "FGAirportDynamicsLoader::Start XML" << endl;
55 void FGAirportDynamicsXMLLoader::endXML () {
56 //cout << "End XML" << endl;
59 void FGAirportDynamicsXMLLoader::startParking(const XMLAttributes &atts)
63 string gateName, gateNumber;
68 int pushBackRoute = 0;
70 for (int i = 0; i < atts.size(); i++)
72 string attname(atts.getName(i));
73 if (attname == "index") {
74 index = std::atoi(atts.getValue(i));
75 } else if (attname == "type")
76 type = atts.getValue(i);
77 else if (attname == "name")
78 gateName = atts.getValue(i);
79 else if (attname == "number")
80 gateNumber = atts.getValue(i);
81 else if (attname == "lat")
82 lat = atts.getValue(i);
83 else if (attname == "lon")
84 lon = atts.getValue(i);
85 else if (attname == "heading")
86 heading = std::atof(atts.getValue(i));
87 else if (attname == "radius") {
88 string radiusStr = atts.getValue(i);
89 if (radiusStr.find("M") != string::npos)
90 radiusStr = radiusStr.substr(0, radiusStr.find("M",0));
91 radius = std::atof(radiusStr.c_str());
93 else if (attname == "airlineCodes")
94 airlineCodes = atts.getValue(i);
95 else if (attname == "pushBackRoute") {
96 pushBackRoute = std::atoi(atts.getValue(i));
100 SGGeod pos(SGGeod::fromDeg(processPosition(lon), processPosition(lat)));
102 FGParking* pk = new FGParking(0, index, pos, heading, radius,
103 gateName + gateNumber, type, airlineCodes);
104 pk->setPushBackPoint(pushBackRoute);
105 _dynamics->addParking(pk);
108 void FGAirportDynamicsXMLLoader::startNode(const XMLAttributes &atts)
115 for (int i = 0; i < atts.size() ; i++)
117 string attname(atts.getName(i));
118 if (attname == "index")
119 index = std::atoi(atts.getValue(i));
120 else if (attname == "lat")
121 lat = atts.getValue(i);
122 else if (attname == "lon")
123 lon = atts.getValue(i);
124 else if (attname == "isOnRunway")
125 onRunway = (bool) std::atoi(atts.getValue(i));
126 else if (attname == "holdPointType") {
127 string attval = atts.getValue(i);
128 if (attval=="none") {
130 } else if (attval=="normal") {
132 } else if (attval=="CAT II/III") {
134 } else if (attval=="PushBack") {
142 SGGeod pos(SGGeod::fromDeg(processPosition(lon), processPosition(lat)));
143 FGTaxiNode* taxiNode = new FGTaxiNode(0, index, pos, onRunway, holdPointType);
144 _dynamics->getGroundNetwork()->addNode(taxiNode);
147 void FGAirportDynamicsXMLLoader::startArc(const XMLAttributes &atts)
150 bool isPushBackRoute = false;
152 for (int i = 0; i < atts.size() ; i++)
154 string attname = atts.getName(i);
155 if (attname == "begin")
156 begin = std::atoi(atts.getValue(i));
157 else if (attname == "end")
158 end = std::atoi(atts.getValue(i));
159 else if (attname == "isPushBackRoute")
160 isPushBackRoute = (bool) std::atoi(atts.getValue(i));
163 _dynamics->getGroundNetwork()->addSegment(new FGTaxiSegment(begin, end, isPushBackRoute));
166 void FGAirportDynamicsXMLLoader::startElement (const char * name, const XMLAttributes &atts)
168 if (!strcmp("Parking", name)) {
170 } else if (!strcmp("node", name)) {
172 } else if (!strcmp("arc", name)) {
177 void FGAirportDynamicsXMLLoader::endElement (const char * name)
179 int valueAsInt = atoi(value.c_str());
180 if (!strcmp("version", name)) {
181 _dynamics->getGroundNetwork()->addVersion(valueAsInt);
182 } else if (!strcmp("AWOS", name)) {
183 _dynamics->addAwosFreq(valueAsInt);
184 } else if (!strcmp("UNICOM", name)) {
185 _dynamics->addUnicomFreq(valueAsInt);
186 } else if (!strcmp("CLEARANCE", name)) {
187 _dynamics->addClearanceFreq(valueAsInt);
188 } else if (!strcmp("GROUND", name)) {
189 _dynamics->addGroundFreq(valueAsInt);
190 } else if (!strcmp("TOWER", name)) {
191 _dynamics->addTowerFreq(valueAsInt);
192 } else if (!strcmp("APPROACH", name)) {
193 _dynamics->addApproachFreq(valueAsInt);
197 void FGAirportDynamicsXMLLoader::data (const char * s, int len) {
198 string token = string(s,len);
199 //cout << "Character data " << string(s,len) << endl;
200 if ((token.find(" ") == string::npos && (token.find('\n')) == string::npos))
206 void FGAirportDynamicsXMLLoader::pi (const char * target, const char * data) {
207 //cout << "Processing instruction " << target << ' ' << data << endl;
210 void FGAirportDynamicsXMLLoader::warning (const char * message, int line, int column) {
211 SG_LOG(SG_IO, SG_WARN, "Warning: " << message << " (" << line << ',' << column << ')');
214 void FGAirportDynamicsXMLLoader::error (const char * message, int line, int column) {
215 SG_LOG(SG_IO, SG_ALERT, "Error: " << message << " (" << line << ',' << column << ')');