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