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