]> git.mxchange.org Git - flightgear.git/blob - src/Airports/runwayprefloader.cxx
Thomas Foerster: Made FGParking a subclass of FGTaxiNode
[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
118   if (!(strcmp(name, "takeoff"))) {
119     //cerr << "Adding takeoff: " << value << endl;
120     rwyList.set(name, value);
121     rwyGroup.add(rwyList);
122   }
123   if (!(strcmp(name, "landing"))) {
124     //cerr << "Adding landing: " << value << endl;
125     rwyList.set(name, value);
126     rwyGroup.add(rwyList);
127   }
128   if (!(strcmp(name, "schedule"))) {
129     //cerr << "Adding schedule" << scheduleName << endl;
130     rwyGroup.setName(scheduleName);
131     //rwyGroup.addRunways(rwyList);
132     _pref->addRunwayGroup(rwyGroup);
133     rwyGroup.clear();
134     //exit(1);
135   }
136 }
137
138 void  FGRunwayPreferenceXMLLoader::data (const char * s, int len) {
139   string token = string(s,len);
140   //cout << "Character data " << string(s,len) << endl;
141   //if ((token.find(" ") == string::npos && (token.find('\n')) == string::npos))
142   //  value += token;
143   //else
144   //  value = string("");
145   value += token;
146 }
147
148 void  FGRunwayPreferenceXMLLoader::pi (const char * target, const char * data) {
149   //cout << "Processing instruction " << target << ' ' << data << endl;
150 }
151
152 void  FGRunwayPreferenceXMLLoader::warning (const char * message, int line, int column) {
153   SG_LOG(SG_IO, SG_WARN, "Warning: " << message << " (" << line << ',' << column << ')');
154 }
155
156 void  FGRunwayPreferenceXMLLoader::error (const char * message, int line, int column) {
157   SG_LOG(SG_IO, SG_ALERT, "Error: " << message << " (" << line << ',' << column << ')');
158 }