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.
19 #include <simgear/debug/logstream.hxx>
21 #include "runwayprefloader.hxx"
25 FGRunwayPreferenceXMLLoader::FGRunwayPreferenceXMLLoader(FGRunwayPreference* p):XMLVisitor(), _pref(p) {}
27 void FGRunwayPreferenceXMLLoader::startXML () {
28 // cout << "Start XML" << endl;
31 void FGRunwayPreferenceXMLLoader::endXML () {
32 //cout << "End XML" << endl;
35 void FGRunwayPreferenceXMLLoader::startElement (const char * name, const XMLAttributes &atts) {
36 //cout << "StartElement " << name << endl;
38 if (!(strcmp(name, "wind"))) {
39 //cerr << "Will be processing Wind" << endl;
40 for (int i = 0; i < atts.size(); i++)
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)));
48 if (atts.getName(i) == string("cross")) {
49 //cerr << "Cross Wind = " << atts.getValue(i) << endl;
50 currTimes.setCrossWind(atof(atts.getValue(i)));
54 if (!(strcmp(name, "time"))) {
55 //cerr << "Will be processing time" << endl;
56 for (int i = 0; i < atts.size(); i++)
58 if (atts.getName(i) == string("start")) {
59 //cerr << "Start Time = " << atts.getValue(i) << endl;
60 currTimes.addStartTime(processTime(atts.getValue(i)));
62 if (atts.getName(i) == string("end")) {
63 //cerr << "End time = " << atts.getValue(i) << endl;
64 currTimes.addEndTime(processTime(atts.getValue(i)));
66 if (atts.getName(i) == string("schedule")) {
67 //cerr << "Schedule Name = " << atts.getValue(i) << endl;
68 currTimes.addScheduleName(atts.getValue(i));
72 if (!(strcmp(name, "takeoff"))) {
75 if (!(strcmp(name, "landing")))
79 if (!(strcmp(name, "schedule"))) {
80 for (int i = 0; i < atts.size(); i++)
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);
92 //based on a string containing hour and minute, return nr seconds since day start.
93 time_t FGRunwayPreferenceXMLLoader::processTime(const string &tme)
95 string hour = tme.substr(0, tme.find(":",0));
96 string minute = tme.substr(tme.find(":",0)+1, tme.length());
98 //cerr << "hour = " << hour << " Minute = " << minute << endl;
99 return (atoi(hour.c_str()) * 3600 + atoi(minute.c_str()) * 60);
102 void FGRunwayPreferenceXMLLoader::endElement (const char * name) {
103 //cout << "End element " << name << endl;
104 if (!(strcmp(name, "rwyuse"))) {
105 _pref->setInitialized(true);
107 if (!(strcmp(name, "com"))) { // Commercial Traffic
108 //cerr << "Setting time table for commerical traffic" << endl;
109 _pref->setComTimes(currTimes);
112 if (!(strcmp(name, "gen"))) { // General Aviation
113 //cerr << "Setting time table for general aviation" << endl;
114 _pref->setGenTimes(currTimes);
117 if (!(strcmp(name, "mil"))) { // Military Traffic
118 //cerr << "Setting time table for military traffic" << endl;
119 _pref->setMilTimes(currTimes);
122 if (!(strcmp(name, "ul"))) { // Military Traffic
123 //cerr << "Setting time table for military traffic" << endl;
124 _pref->setULTimes(currTimes);
129 if (!(strcmp(name, "takeoff"))) {
130 //cerr << "Adding takeoff: " << value << endl;
131 rwyList.set(name, value);
132 rwyGroup.add(rwyList);
134 if (!(strcmp(name, "landing"))) {
135 //cerr << "Adding landing: " << value << endl;
136 rwyList.set(name, value);
137 rwyGroup.add(rwyList);
139 if (!(strcmp(name, "schedule"))) {
140 //cerr << "Adding schedule" << scheduleName << endl;
141 rwyGroup.setName(scheduleName);
142 //rwyGroup.addRunways(rwyList);
143 _pref->addRunwayGroup(rwyGroup);
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))
155 // value = string("");
159 void FGRunwayPreferenceXMLLoader::pi (const char * target, const char * data) {
160 //cout << "Processing instruction " << target << ' ' << data << endl;
163 void FGRunwayPreferenceXMLLoader::warning (const char * message, int line, int column) {
164 SG_LOG(SG_IO, SG_WARN, "Warning: " << message << " (" << line << ',' << column << ')');
167 void FGRunwayPreferenceXMLLoader::error (const char * message, int line, int column) {
168 SG_LOG(SG_IO, SG_ALERT, "Error: " << message << " (" << line << ',' << column << ')');