]> git.mxchange.org Git - flightgear.git/blob - src/Airports/dynamicloader.cxx
Update to the latest version of JSBSim which supports Lighter Than Air craft
[flightgear.git] / src / Airports / dynamicloader.cxx
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.
5 //
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.
10 //
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.
14 //
15
16 #include <cstdlib>
17
18 #include "dynamicloader.hxx"
19
20 FGAirportDynamicsXMLLoader::FGAirportDynamicsXMLLoader(FGAirportDynamics* dyn):
21     XMLVisitor(), _dynamics(dyn) {}
22
23 void  FGAirportDynamicsXMLLoader::startXML () {
24   //cout << "Start XML" << endl;
25 }
26
27 void  FGAirportDynamicsXMLLoader::endXML () {
28   //cout << "End XML" << endl;
29 }
30
31 void  FGAirportDynamicsXMLLoader::startElement (const char * name, const XMLAttributes &atts) {
32   // const char *attval;
33   FGParking park;
34   FGTaxiNode taxiNode;
35   FGTaxiSegment taxiSegment;
36   int index = 0;
37   taxiSegment.setIndex(index);
38   //cout << "Start element " << name << endl;
39   string attname;
40   string value;
41   string gateName;
42   string gateNumber;
43   string attval;
44   string lat;
45   string lon;
46   int holdPointType;
47   
48   if (name == string("Parking"))
49     {
50       for (int i = 0; i < atts.size(); i++)
51         {
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()));
74           }
75            else if (attname == string("airlineCodes"))
76              park.setCodes(atts.getValue(i));
77         }
78       park.setName((gateName+gateNumber));
79       _dynamics->addParking(park);
80     }
81   if (name == string("node")) 
82     {
83       for (int i = 0; i < atts.size() ; i++)
84         {
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")) {
97                 holdPointType=0;
98             } else if (attval==string("normal")) {
99                  holdPointType=1;
100             } else if (attval==string("CAT II/III")) {
101                  holdPointType=3;
102             } else if (attval==string("PushBack")) {
103                  holdPointType=3;
104             }
105             //cerr << "Setting Holding point to " << holdPointType << endl;
106             taxiNode.setHoldPointType(holdPointType);
107           }
108         }
109       _dynamics->getGroundNetwork()->addNode(taxiNode);
110     }
111   if (name == string("arc")) 
112     {
113       taxiSegment.setIndex(++index);
114       for (int i = 0; i < atts.size() ; i++)
115         {
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)));
123         }
124       _dynamics->getGroundNetwork()->addSegment(taxiSegment);
125     }
126   // sort by radius, in asending order, so that smaller gates are first in the list
127 }
128
129 void  FGAirportDynamicsXMLLoader::endElement (const char * name) {
130   //cout << "End element " << name << endl;
131
132 }
133
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))
138     //value += token;
139   //else
140     //value = string("");
141 }
142
143 void  FGAirportDynamicsXMLLoader::pi (const char * target, const char * data) {
144   //cout << "Processing instruction " << target << ' ' << data << endl;
145 }
146
147 void  FGAirportDynamicsXMLLoader::warning (const char * message, int line, int column) {
148   SG_LOG(SG_IO, SG_WARN, "Warning: " << message << " (" << line << ',' << column << ')');
149 }
150
151 void  FGAirportDynamicsXMLLoader::error (const char * message, int line, int column) {
152   SG_LOG(SG_IO, SG_ALERT, "Error: " << message << " (" << line << ',' << column << ')');
153 }