]> git.mxchange.org Git - flightgear.git/blob - src/Airports/dynamicloader.cxx
- Added ultra-light traffic is now a separate traffic class that can have its
[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 "dynamicloader.hxx"
17
18 FGAirportDynamicsXMLLoader::FGAirportDynamicsXMLLoader(FGAirportDynamics* dyn):
19     XMLVisitor(), _dynamics(dyn) {}
20
21 void  FGAirportDynamicsXMLLoader::startXML () {
22   //cout << "Start XML" << endl;
23 }
24
25 void  FGAirportDynamicsXMLLoader::endXML () {
26   //cout << "End XML" << endl;
27 }
28
29 void  FGAirportDynamicsXMLLoader::startElement (const char * name, const XMLAttributes &atts) {
30   // const char *attval;
31   FGParking park;
32   FGTaxiNode taxiNode;
33   FGTaxiSegment taxiSegment;
34   int index = 0;
35   taxiSegment.setIndex(index);
36   //cout << "Start element " << name << endl;
37   string attname;
38   string value;
39   string gateName;
40   string gateNumber;
41   string lat;
42   string lon;
43   if (name == string("Parking"))
44     {
45       for (int i = 0; i < atts.size(); i++)
46         {
47           //cout << "  " << atts.getName(i) << '=' << atts.getValue(i) << endl; 
48           attname = atts.getName(i);
49           if (attname == string("index"))
50             park.setIndex(atoi(atts.getValue(i)));
51           else if (attname == string("type"))
52             park.setType(atts.getValue(i));
53          else if (attname == string("name"))
54            gateName = atts.getValue(i);
55           else if (attname == string("number"))
56             gateNumber = atts.getValue(i);
57           else if (attname == string("lat"))
58            park.setLatitude(atts.getValue(i));
59           else if (attname == string("lon"))
60             park.setLongitude(atts.getValue(i)); 
61           else if (attname == string("heading"))
62             park.setHeading(atof(atts.getValue(i)));
63           else if (attname == string("radius")) {
64             string radius = atts.getValue(i);
65             if (radius.find("M") != string::npos)
66               radius = radius.substr(0, radius.find("M",0));
67             //cerr << "Radius " << radius <<endl;
68             park.setRadius(atof(radius.c_str()));
69           }
70            else if (attname == string("airlineCodes"))
71              park.setCodes(atts.getValue(i));
72         }
73       park.setName((gateName+gateNumber));
74       _dynamics->addParking(park);
75     }
76   if (name == string("node")) 
77     {
78       for (int i = 0; i < atts.size() ; i++)
79         {
80           attname = atts.getName(i);
81           if (attname == string("index"))
82             taxiNode.setIndex(atoi(atts.getValue(i)));
83           if (attname == string("lat"))
84             taxiNode.setLatitude(atts.getValue(i));
85           if (attname == string("lon"))
86             taxiNode.setLongitude(atts.getValue(i));
87         }
88       _dynamics->getGroundNetwork()->addNode(taxiNode);
89     }
90   if (name == string("arc")) 
91     {
92       taxiSegment.setIndex(++index);
93       for (int i = 0; i < atts.size() ; i++)
94         {
95           attname = atts.getName(i);
96           if (attname == string("begin"))
97             taxiSegment.setStartNodeRef(atoi(atts.getValue(i)));
98           if (attname == string("end"))
99             taxiSegment.setEndNodeRef(atoi(atts.getValue(i)));
100         }
101       _dynamics->getGroundNetwork()->addSegment(taxiSegment);
102     }
103   // sort by radius, in asending order, so that smaller gates are first in the list
104 }
105
106 void  FGAirportDynamicsXMLLoader::endElement (const char * name) {
107   //cout << "End element " << name << endl;
108
109 }
110
111 void  FGAirportDynamicsXMLLoader::data (const char * s, int len) {
112   string token = string(s,len);
113   //cout << "Character data " << string(s,len) << endl;
114   //if ((token.find(" ") == string::npos && (token.find('\n')) == string::npos))
115     //value += token;
116   //else
117     //value = string("");
118 }
119
120 void  FGAirportDynamicsXMLLoader::pi (const char * target, const char * data) {
121   //cout << "Processing instruction " << target << ' ' << data << endl;
122 }
123
124 void  FGAirportDynamicsXMLLoader::warning (const char * message, int line, int column) {
125   SG_LOG(SG_IO, SG_WARN, "Warning: " << message << " (" << line << ',' << column << ')');
126 }
127
128 void  FGAirportDynamicsXMLLoader::error (const char * message, int line, int column) {
129   SG_LOG(SG_IO, SG_ALERT, "Error: " << message << " (" << line << ',' << column << ')');
130 }