]> git.mxchange.org Git - flightgear.git/blob - src/Airports/runwayprefloader.cxx
Change tower location to an SGGeod. Include taxiways too.
[flightgear.git] / src / Airports / runwayprefloader.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 <simgear/debug/logstream.hxx>
17
18 #include "runwayprefloader.hxx"
19
20 FGRunwayPreferenceXMLLoader::FGRunwayPreferenceXMLLoader(FGRunwayPreference* p):XMLVisitor(), _pref(p) {}
21
22 void  FGRunwayPreferenceXMLLoader::startXML () {
23   //  cout << "Start XML" << endl;
24 }
25
26 void  FGRunwayPreferenceXMLLoader::endXML () {
27   //cout << "End XML" << endl;
28 }
29
30 void  FGRunwayPreferenceXMLLoader::startElement (const char * name, const XMLAttributes &atts) {
31   //cout << "StartElement " << name << endl;
32   value = string("");
33   if (!(strcmp(name, "wind"))) {
34     //cerr << "Will be processing Wind" << endl;
35     for (int i = 0; i < atts.size(); i++)
36       {
37         //cout << "  " << atts.getName(i) << '=' << atts.getValue(i) << endl; 
38         //attname = atts.getName(i);
39         if (atts.getName(i) == string("tail")) {
40           //cerr << "Tail Wind = " << atts.getValue(i) << endl;
41           currTimes.setTailWind(atof(atts.getValue(i)));
42         }       
43         if (atts.getName(i) == string("cross")) {
44           //cerr << "Cross Wind = " << atts.getValue(i) << endl;
45           currTimes.setCrossWind(atof(atts.getValue(i)));
46         }
47      }
48   }
49     if (!(strcmp(name, "time"))) {
50       //cerr << "Will be processing time" << endl;      
51     for (int i = 0; i < atts.size(); i++)
52       {
53         if (atts.getName(i) == string("start")) {
54           //cerr << "Start Time = " << atts.getValue(i) << endl;
55           currTimes.addStartTime(processTime(atts.getValue(i)));
56         }
57         if (atts.getName(i) == string("end")) {
58           //cerr << "End time = " << atts.getValue(i) << endl;
59           currTimes.addEndTime(processTime(atts.getValue(i)));
60         }
61         if (atts.getName(i) == string("schedule")) {
62           //cerr << "Schedule Name  = " << atts.getValue(i) << endl;
63           currTimes.addScheduleName(atts.getValue(i));
64         }       
65     }
66   }
67   if (!(strcmp(name, "takeoff"))) {
68     rwyList.clear();
69   }
70   if  (!(strcmp(name, "landing")))
71     {
72       rwyList.clear();
73     }
74   if (!(strcmp(name, "schedule"))) {
75     for (int i = 0; i < atts.size(); i++)
76       {
77         //cout << "  " << atts.getName(i) << '=' << atts.getValue(i) << endl; 
78         //attname = atts.getName(i);
79         if (atts.getName(i) == string("name")) {
80           //cerr << "Schedule name = " << atts.getValue(i) << endl;
81           scheduleName = atts.getValue(i);
82         }
83       }
84   }
85 }
86
87 //based on a string containing hour and minute, return nr seconds since day start.
88 time_t FGRunwayPreferenceXMLLoader::processTime(const string &tme)
89 {
90   string hour   = tme.substr(0, tme.find(":",0));
91   string minute = tme.substr(tme.find(":",0)+1, tme.length());
92
93   //cerr << "hour = " << hour << " Minute = " << minute << endl;
94   return (atoi(hour.c_str()) * 3600 + atoi(minute.c_str()) * 60);
95 }
96
97 void  FGRunwayPreferenceXMLLoader::endElement (const char * name) {
98   //cout << "End element " << name << endl;
99   if (!(strcmp(name, "rwyuse"))) {
100     _pref->setInitialized(true);
101   }
102   if (!(strcmp(name, "com"))) { // Commercial Traffic
103     //cerr << "Setting time table for commerical traffic" << endl;
104     _pref->setComTimes(currTimes);
105     currTimes.clear();
106   }
107   if (!(strcmp(name, "gen"))) { // General Aviation
108     //cerr << "Setting time table for general aviation" << endl;
109     _pref->setGenTimes(currTimes);
110     currTimes.clear();
111   }  
112   if (!(strcmp(name, "mil"))) { // Military Traffic
113     //cerr << "Setting time table for military traffic" << endl;
114     _pref->setMilTimes(currTimes);
115     currTimes.clear();
116   }
117   if (!(strcmp(name, "ul"))) { // Military Traffic
118     //cerr << "Setting time table for military traffic" << endl;
119     _pref->setULTimes(currTimes);
120     currTimes.clear();
121   }
122
123
124   if (!(strcmp(name, "takeoff"))) {
125     //cerr << "Adding takeoff: " << value << endl;
126     rwyList.set(name, value);
127     rwyGroup.add(rwyList);
128   }
129   if (!(strcmp(name, "landing"))) {
130     //cerr << "Adding landing: " << value << endl;
131     rwyList.set(name, value);
132     rwyGroup.add(rwyList);
133   }
134   if (!(strcmp(name, "schedule"))) {
135     //cerr << "Adding schedule" << scheduleName << endl;
136     rwyGroup.setName(scheduleName);
137     //rwyGroup.addRunways(rwyList);
138     _pref->addRunwayGroup(rwyGroup);
139     rwyGroup.clear();
140     //exit(1);
141   }
142 }
143
144 void  FGRunwayPreferenceXMLLoader::data (const char * s, int len) {
145   string token = string(s,len);
146   //cout << "Character data " << string(s,len) << endl;
147   //if ((token.find(" ") == string::npos && (token.find('\n')) == string::npos))
148   //  value += token;
149   //else
150   //  value = string("");
151   value += token;
152 }
153
154 void  FGRunwayPreferenceXMLLoader::pi (const char * target, const char * data) {
155   //cout << "Processing instruction " << target << ' ' << data << endl;
156 }
157
158 void  FGRunwayPreferenceXMLLoader::warning (const char * message, int line, int column) {
159   SG_LOG(SG_IO, SG_WARN, "Warning: " << message << " (" << line << ',' << column << ')');
160 }
161
162 void  FGRunwayPreferenceXMLLoader::error (const char * message, int line, int column) {
163   SG_LOG(SG_IO, SG_ALERT, "Error: " << message << " (" << line << ',' << column << ')');
164 }