1 #include <simgear/debug/logstream.hxx>
3 #include "runwayprefloader.hxx"
5 FGRunwayPreferenceXMLLoader::FGRunwayPreferenceXMLLoader(FGRunwayPreference* p):XMLVisitor(), _pref(p) {}
7 void FGRunwayPreferenceXMLLoader::startXML () {
8 // cout << "Start XML" << endl;
11 void FGRunwayPreferenceXMLLoader::endXML () {
12 //cout << "End XML" << endl;
15 void FGRunwayPreferenceXMLLoader::startElement (const char * name, const XMLAttributes &atts) {
16 //cout << "StartElement " << name << endl;
18 if (!(strcmp(name, "wind"))) {
19 //cerr << "Will be processing Wind" << endl;
20 for (int i = 0; i < atts.size(); i++)
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)));
28 if (atts.getName(i) == string("cross")) {
29 //cerr << "Cross Wind = " << atts.getValue(i) << endl;
30 currTimes.setCrossWind(atof(atts.getValue(i)));
34 if (!(strcmp(name, "time"))) {
35 //cerr << "Will be processing time" << endl;
36 for (int i = 0; i < atts.size(); i++)
38 if (atts.getName(i) == string("start")) {
39 //cerr << "Start Time = " << atts.getValue(i) << endl;
40 currTimes.addStartTime(processTime(atts.getValue(i)));
42 if (atts.getName(i) == string("end")) {
43 //cerr << "End time = " << atts.getValue(i) << endl;
44 currTimes.addEndTime(processTime(atts.getValue(i)));
46 if (atts.getName(i) == string("schedule")) {
47 //cerr << "Schedule Name = " << atts.getValue(i) << endl;
48 currTimes.addScheduleName(atts.getValue(i));
52 if (!(strcmp(name, "takeoff"))) {
55 if (!(strcmp(name, "landing")))
59 if (!(strcmp(name, "schedule"))) {
60 for (int i = 0; i < atts.size(); i++)
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);
72 //based on a string containing hour and minute, return nr seconds since day start.
73 time_t FGRunwayPreferenceXMLLoader::processTime(const string &tme)
75 string hour = tme.substr(0, tme.find(":",0));
76 string minute = tme.substr(tme.find(":",0)+1, tme.length());
78 //cerr << "hour = " << hour << " Minute = " << minute << endl;
79 return (atoi(hour.c_str()) * 3600 + atoi(minute.c_str()) * 60);
82 void FGRunwayPreferenceXMLLoader::endElement (const char * name) {
83 //cout << "End element " << name << endl;
84 if (!(strcmp(name, "rwyuse"))) {
85 _pref->setInitialized(true);
87 if (!(strcmp(name, "com"))) { // Commercial Traffic
88 //cerr << "Setting time table for commerical traffic" << endl;
89 _pref->setComTimes(currTimes);
92 if (!(strcmp(name, "gen"))) { // General Aviation
93 //cerr << "Setting time table for general aviation" << endl;
94 _pref->setGenTimes(currTimes);
97 if (!(strcmp(name, "mil"))) { // Military Traffic
98 //cerr << "Setting time table for military traffic" << endl;
99 _pref->setMilTimes(currTimes);
103 if (!(strcmp(name, "takeoff"))) {
104 //cerr << "Adding takeoff: " << value << endl;
105 rwyList.set(name, value);
106 rwyGroup.add(rwyList);
108 if (!(strcmp(name, "landing"))) {
109 //cerr << "Adding landing: " << value << endl;
110 rwyList.set(name, value);
111 rwyGroup.add(rwyList);
113 if (!(strcmp(name, "schedule"))) {
114 //cerr << "Adding schedule" << scheduleName << endl;
115 rwyGroup.setName(scheduleName);
116 //rwyGroup.addRunways(rwyList);
117 _pref->addRunwayGroup(rwyGroup);
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))
129 // value = string("");
133 void FGRunwayPreferenceXMLLoader::pi (const char * target, const char * data) {
134 //cout << "Processing instruction " << target << ' ' << data << endl;
137 void FGRunwayPreferenceXMLLoader::warning (const char * message, int line, int column) {
138 SG_LOG(SG_IO, SG_WARN, "Warning: " << message << " (" << line << ',' << column << ')');
141 void FGRunwayPreferenceXMLLoader::error (const char * message, int line, int column) {
142 SG_LOG(SG_IO, SG_ALERT, "Error: " << message << " (" << line << ',' << column << ')');