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.
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.
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.
16 #include <simgear/debug/logstream.hxx>
18 #include "runwayprefloader.hxx"
20 FGRunwayPreferenceXMLLoader::FGRunwayPreferenceXMLLoader(FGRunwayPreference* p):XMLVisitor(), _pref(p) {}
22 void FGRunwayPreferenceXMLLoader::startXML () {
23 // cout << "Start XML" << endl;
26 void FGRunwayPreferenceXMLLoader::endXML () {
27 //cout << "End XML" << endl;
30 void FGRunwayPreferenceXMLLoader::startElement (const char * name, const XMLAttributes &atts) {
31 //cout << "StartElement " << name << endl;
33 if (!(strcmp(name, "wind"))) {
34 //cerr << "Will be processing Wind" << endl;
35 for (int i = 0; i < atts.size(); i++)
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)));
43 if (atts.getName(i) == string("cross")) {
44 //cerr << "Cross Wind = " << atts.getValue(i) << endl;
45 currTimes.setCrossWind(atof(atts.getValue(i)));
49 if (!(strcmp(name, "time"))) {
50 //cerr << "Will be processing time" << endl;
51 for (int i = 0; i < atts.size(); i++)
53 if (atts.getName(i) == string("start")) {
54 //cerr << "Start Time = " << atts.getValue(i) << endl;
55 currTimes.addStartTime(processTime(atts.getValue(i)));
57 if (atts.getName(i) == string("end")) {
58 //cerr << "End time = " << atts.getValue(i) << endl;
59 currTimes.addEndTime(processTime(atts.getValue(i)));
61 if (atts.getName(i) == string("schedule")) {
62 //cerr << "Schedule Name = " << atts.getValue(i) << endl;
63 currTimes.addScheduleName(atts.getValue(i));
67 if (!(strcmp(name, "takeoff"))) {
70 if (!(strcmp(name, "landing")))
74 if (!(strcmp(name, "schedule"))) {
75 for (int i = 0; i < atts.size(); i++)
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);
87 //based on a string containing hour and minute, return nr seconds since day start.
88 time_t FGRunwayPreferenceXMLLoader::processTime(const string &tme)
90 string hour = tme.substr(0, tme.find(":",0));
91 string minute = tme.substr(tme.find(":",0)+1, tme.length());
93 //cerr << "hour = " << hour << " Minute = " << minute << endl;
94 return (atoi(hour.c_str()) * 3600 + atoi(minute.c_str()) * 60);
97 void FGRunwayPreferenceXMLLoader::endElement (const char * name) {
98 //cout << "End element " << name << endl;
99 if (!(strcmp(name, "rwyuse"))) {
100 _pref->setInitialized(true);
102 if (!(strcmp(name, "com"))) { // Commercial Traffic
103 //cerr << "Setting time table for commerical traffic" << endl;
104 _pref->setComTimes(currTimes);
107 if (!(strcmp(name, "gen"))) { // General Aviation
108 //cerr << "Setting time table for general aviation" << endl;
109 _pref->setGenTimes(currTimes);
112 if (!(strcmp(name, "mil"))) { // Military Traffic
113 //cerr << "Setting time table for military traffic" << endl;
114 _pref->setMilTimes(currTimes);
118 if (!(strcmp(name, "takeoff"))) {
119 //cerr << "Adding takeoff: " << value << endl;
120 rwyList.set(name, value);
121 rwyGroup.add(rwyList);
123 if (!(strcmp(name, "landing"))) {
124 //cerr << "Adding landing: " << value << endl;
125 rwyList.set(name, value);
126 rwyGroup.add(rwyList);
128 if (!(strcmp(name, "schedule"))) {
129 //cerr << "Adding schedule" << scheduleName << endl;
130 rwyGroup.setName(scheduleName);
131 //rwyGroup.addRunways(rwyList);
132 _pref->addRunwayGroup(rwyGroup);
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))
144 // value = string("");
148 void FGRunwayPreferenceXMLLoader::pi (const char * target, const char * data) {
149 //cout << "Processing instruction " << target << ' ' << data << endl;
152 void FGRunwayPreferenceXMLLoader::warning (const char * message, int line, int column) {
153 SG_LOG(SG_IO, SG_WARN, "Warning: " << message << " (" << line << ',' << column << ')');
156 void FGRunwayPreferenceXMLLoader::error (const char * message, int line, int column) {
157 SG_LOG(SG_IO, SG_ALERT, "Error: " << message << " (" << line << ',' << column << ')');