From 7dfae1562bdb68d0c67e728f3f922c6373b83c9c Mon Sep 17 00:00:00 2001 From: durk Date: Wed, 4 Jul 2007 17:39:03 +0000 Subject: [PATCH] Thomas Foerster: I refactored the XML loading code out of FGAirportDynamics and FGRunwayPreference. I also added a new class XMLLoader, which serves as a facade to the loader functions. Further I changed FGRunwayPreference to just keep a FGAirport ref, which is more concise and closer to the right(tm) solution than storing the airport data a second time ;-) --- src/Airports/Makefile.am | 6 +- src/Airports/dynamicloader.cxx | 115 +++++++++++++++++++ src/Airports/dynamics.cxx | 183 +++++++----------------------- src/Airports/dynamics.hxx | 29 ++--- src/Airports/runwayprefloader.cxx | 143 +++++++++++++++++++++++ src/Airports/runwayprefs.cxx | 154 +------------------------ src/Airports/runwayprefs.hxx | 41 +++---- src/Airports/simple.cxx | 46 ++------ src/Airports/xmlloader.cxx | 50 ++++++++ src/Airports/xmlloader.hxx | 20 ++++ 10 files changed, 422 insertions(+), 365 deletions(-) create mode 100644 src/Airports/dynamicloader.cxx create mode 100644 src/Airports/runwayprefloader.cxx create mode 100644 src/Airports/xmlloader.cxx create mode 100644 src/Airports/xmlloader.hxx diff --git a/src/Airports/Makefile.am b/src/Airports/Makefile.am index 1c6748146..7449c24cb 100644 --- a/src/Airports/Makefile.am +++ b/src/Airports/Makefile.am @@ -10,7 +10,11 @@ libAirports_a_SOURCES = \ parking.cxx parking.hxx \ groundnetwork.cxx groundnetwork.hxx \ dynamics.cxx dynamics.hxx \ - trafficcontrol.hxx trafficcontrol.cxx + trafficcontrol.hxx trafficcontrol.cxx \ + dynamicloader.hxx dynamicloader.cxx \ + runwayprefloader.hxx runwayprefloader.cxx \ + xmlloader.hxx xmlloader.cxx + calc_loc_SOURCES = calc_loc.cxx calc_loc_LDADD = -lsgmath -lsgdebug -lsgmisc -lz $(base_LIBS) diff --git a/src/Airports/dynamicloader.cxx b/src/Airports/dynamicloader.cxx new file mode 100644 index 000000000..456acc835 --- /dev/null +++ b/src/Airports/dynamicloader.cxx @@ -0,0 +1,115 @@ +#include "dynamicloader.hxx" + +FGAirportDynamicsXMLLoader::FGAirportDynamicsXMLLoader(FGAirportDynamics* dyn): + XMLVisitor(), _dynamics(dyn) {} + +void FGAirportDynamicsXMLLoader::startXML () { + //cout << "Start XML" << endl; +} + +void FGAirportDynamicsXMLLoader::endXML () { + //cout << "End XML" << endl; +} + +void FGAirportDynamicsXMLLoader::startElement (const char * name, const XMLAttributes &atts) { + // const char *attval; + FGParking park; + FGTaxiNode taxiNode; + FGTaxiSegment taxiSegment; + int index = 0; + taxiSegment.setIndex(index); + //cout << "Start element " << name << endl; + string attname; + string value; + string gateName; + string gateNumber; + string lat; + string lon; + if (name == string("Parking")) + { + for (int i = 0; i < atts.size(); i++) + { + //cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl; + attname = atts.getName(i); + if (attname == string("index")) + park.setIndex(atoi(atts.getValue(i))); + else if (attname == string("type")) + park.setType(atts.getValue(i)); + else if (attname == string("name")) + gateName = atts.getValue(i); + else if (attname == string("number")) + gateNumber = atts.getValue(i); + else if (attname == string("lat")) + park.setLatitude(atts.getValue(i)); + else if (attname == string("lon")) + park.setLongitude(atts.getValue(i)); + else if (attname == string("heading")) + park.setHeading(atof(atts.getValue(i))); + else if (attname == string("radius")) { + string radius = atts.getValue(i); + if (radius.find("M") != string::npos) + radius = radius.substr(0, radius.find("M",0)); + //cerr << "Radius " << radius <addParking(park); + } + if (name == string("node")) + { + for (int i = 0; i < atts.size() ; i++) + { + attname = atts.getName(i); + if (attname == string("index")) + taxiNode.setIndex(atoi(atts.getValue(i))); + if (attname == string("lat")) + taxiNode.setLatitude(atts.getValue(i)); + if (attname == string("lon")) + taxiNode.setLongitude(atts.getValue(i)); + } + _dynamics->getGroundNetwork()->addNode(taxiNode); + } + if (name == string("arc")) + { + taxiSegment.setIndex(++index); + for (int i = 0; i < atts.size() ; i++) + { + attname = atts.getName(i); + if (attname == string("begin")) + taxiSegment.setStartNodeRef(atoi(atts.getValue(i))); + if (attname == string("end")) + taxiSegment.setEndNodeRef(atoi(atts.getValue(i))); + } + _dynamics->getGroundNetwork()->addSegment(taxiSegment); + } + // sort by radius, in asending order, so that smaller gates are first in the list +} + +void FGAirportDynamicsXMLLoader::endElement (const char * name) { + //cout << "End element " << name << endl; + +} + +void FGAirportDynamicsXMLLoader::data (const char * s, int len) { + string token = string(s,len); + //cout << "Character data " << string(s,len) << endl; + //if ((token.find(" ") == string::npos && (token.find('\n')) == string::npos)) + //value += token; + //else + //value = string(""); +} + +void FGAirportDynamicsXMLLoader::pi (const char * target, const char * data) { + //cout << "Processing instruction " << target << ' ' << data << endl; +} + +void FGAirportDynamicsXMLLoader::warning (const char * message, int line, int column) { + SG_LOG(SG_IO, SG_WARN, "Warning: " << message << " (" << line << ',' << column << ')'); +} + +void FGAirportDynamicsXMLLoader::error (const char * message, int line, int column) { + SG_LOG(SG_IO, SG_ALERT, "Error: " << message << " (" << line << ',' << column << ')'); +} diff --git a/src/Airports/dynamics.cxx b/src/Airports/dynamics.cxx index 3f6185df2..c1958fe2d 100644 --- a/src/Airports/dynamics.cxx +++ b/src/Airports/dynamics.cxx @@ -48,31 +48,26 @@ SG_USING_STD(vector); SG_USING_STD(sort); SG_USING_STD(random_shuffle); +#include "simple.hxx" #include "dynamics.hxx" -/********** FGAirport Dynamics *********************************************/ - -FGAirportDynamics::FGAirportDynamics(double lat, double lon, double elev, string id) : - _longitude(lon), - _latitude(lat), - _elevation(elev), - _id(id) -{ +FGAirportDynamics::FGAirportDynamics(FGAirport* ap) : + _ap(ap), rwyPrefs(ap) { lastUpdate = 0; for (int i = 0; i < 10; i++) - { - avWindHeading [i] = 0; - avWindSpeed [i] = 0; - } + { + avWindHeading [i] = 0; + avWindSpeed [i] = 0; + } } - // Note that the ground network should also be copied -FGAirportDynamics::FGAirportDynamics(const FGAirportDynamics& other) +FGAirportDynamics::FGAirportDynamics(const FGAirportDynamics& other) : + rwyPrefs(other.rwyPrefs) { for (FGParkingVecConstIterator ip= other.parkings.begin(); ip != other.parkings.end(); ip++) parkings.push_back(*(ip)); - rwyPrefs = other.rwyPrefs; + // rwyPrefs = other.rwyPrefs; lastUpdate = other.lastUpdate; stringVecConstIterator il; @@ -108,7 +103,8 @@ void FGAirportDynamics::init() // add the gate positions to the ground network. groundNetwork.addNodes(&parkings); groundNetwork.init(); - groundNetwork .setTowerController(&towerController); + groundNetwork.setTowerController(&towerController); + groundNetwork.setParent(_ap); } bool FGAirportDynamics::getAvailableParking(double *lat, double *lon, double *heading, int *gateId, double rad, const string &flType, const string &acType, const string &airline) @@ -130,9 +126,9 @@ bool FGAirportDynamics::getAvailableParking(double *lat, double *lon, double *he if (parkings.begin() == parkings.end()) { - //cerr << "Could not find parking spot at " << _id << endl; - *lat = _latitude; - *lon = _longitude; + //cerr << "Could not find parking spot at " << _ap->getId() << endl; + *lat = _ap->getLatitude(); + *lon = _ap->getLongitude(); *heading = 0; found = true; } @@ -270,13 +266,13 @@ bool FGAirportDynamics::getAvailableParking(double *lat, double *lon, double *he } if (!found) { - //cerr << "Traffic overflow at" << _id + //cerr << "Traffic overflow at" << _ap->getId() // << ". flType = " << flType // << ". airline = " << airline // << " Radius = " <getLatitude(); + *lon = _ap->getLongitude(); *heading = 0; *gateId = -1; //exit(1); @@ -288,8 +284,8 @@ void FGAirportDynamics::getParking (int id, double *lat, double* lon, double *he { if (id < 0) { - *lat = _latitude; - *lon = _longitude; + *lat = _ap->getLatitude(); + *lon = _ap->getLongitude(); *heading = 0; } else @@ -337,117 +333,6 @@ void FGAirportDynamics::releaseParking(int id) } } -void FGAirportDynamics::startXML () { - //cout << "Start XML" << endl; -} - -void FGAirportDynamics::endXML () { - //cout << "End XML" << endl; -} - -void FGAirportDynamics::startElement (const char * name, const XMLAttributes &atts) { - // const char *attval; - FGParking park; - FGTaxiNode taxiNode; - FGTaxiSegment taxiSegment; - int index = 0; - taxiSegment.setIndex(index); - //cout << "Start element " << name << endl; - string attname; - string value; - string gateName; - string gateNumber; - string lat; - string lon; - if (name == string("Parking")) - { - for (int i = 0; i < atts.size(); i++) - { - //cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl; - attname = atts.getName(i); - if (attname == string("index")) - park.setIndex(atoi(atts.getValue(i))); - else if (attname == string("type")) - park.setType(atts.getValue(i)); - else if (attname == string("name")) - gateName = atts.getValue(i); - else if (attname == string("number")) - gateNumber = atts.getValue(i); - else if (attname == string("lat")) - park.setLatitude(atts.getValue(i)); - else if (attname == string("lon")) - park.setLongitude(atts.getValue(i)); - else if (attname == string("heading")) - park.setHeading(atof(atts.getValue(i))); - else if (attname == string("radius")) { - string radius = atts.getValue(i); - if (radius.find("M") != string::npos) - radius = radius.substr(0, radius.find("M",0)); - //cerr << "Radius " << radius <get_runways()->search(apt->getId(), int(wind_heading)); string scheduleName; - //cerr << "finding active Runway for" << _id << endl; + //cerr << "finding active Runway for" << _ap->getId() << endl; //cerr << "Nr of seconds since day start << " << dayStart << endl; ScheduleTime *currSched; @@ -564,7 +449,7 @@ void FGAirportDynamics::getActiveRunway(const string &trafficType, int action, s //cerr << "Nr of Active Runways = " << nrActiveRunways << endl; // - currRunwayGroup->setActive(_id, + currRunwayGroup->setActive(_ap->getId(), windSpeed, windHeading, maxTail, @@ -622,7 +507,7 @@ void FGAirportDynamics::getActiveRunway(const string &trafficType, int action, s } } - //runway = globals->get_runways()->search(_id, int(windHeading)); + //runway = globals->get_runways()->search(_ap->getId(), int(windHeading)); //cerr << "Seleceted runway: " << runway << endl; } } @@ -642,5 +527,25 @@ string FGAirportDynamics::chooseRunwayFallback() //which is consistent with Flightgear's initial setup. } - return globals->get_runways()->search(_id, int(windHeading)); + return globals->get_runways()->search(_ap->getId(), int(windHeading)); +} + +void FGAirportDynamics::addParking(FGParking& park) { + parkings.push_back(park); +} + +double FGAirportDynamics::getLatitude() const { + return _ap->getLatitude(); +} + +double FGAirportDynamics::getLongitude() const { + return _ap->getLongitude(); +} + +double FGAirportDynamics::getElevation() const { + return _ap->getElevation(); +} + +const string& FGAirportDynamics::getId() const { + return _ap->getId(); } diff --git a/src/Airports/dynamics.hxx b/src/Airports/dynamics.hxx index cbd9953bc..6e9ae1ab4 100644 --- a/src/Airports/dynamics.hxx +++ b/src/Airports/dynamics.hxx @@ -34,14 +34,12 @@ #include "runwayprefs.hxx" #include "trafficcontrol.hxx" +class FGAirport; -class FGAirportDynamics : public XMLVisitor { +class FGAirportDynamics { private: - double _longitude; // degrees - double _latitude; // degrees - double _elevation; // ft - string _id; + FGAirport* _ap; FGParkingVec parkings; FGRunwayPreference rwyPrefs; @@ -64,19 +62,22 @@ private: string chooseRunwayFallback(); public: - FGAirportDynamics(double, double, double, string); + FGAirportDynamics(FGAirport* ap); FGAirportDynamics(const FGAirportDynamics &other); ~FGAirportDynamics(); void init(); - double getLongitude() const { return _longitude;}; + double getLongitude() const; // Returns degrees - double getLatitude() const { return _latitude; }; + double getLatitude() const; // Returns ft - double getElevation() const { return _elevation;}; + double getElevation() const; + const string& getId() const; void getActiveRunway(const string& trafficType, int action, string& runway); + + void addParking(FGParking& park); bool getAvailableParking(double *lat, double *lon, double *heading, int *gate, double rad, const string& fltype, const string& acType, const string& airline); @@ -93,16 +94,6 @@ public: void setRwyUse(const FGRunwayPreference& ref); - - // Some overloaded virtual XMLVisitor members - virtual void startXML (); - virtual void endXML (); - virtual void startElement (const char * name, const XMLAttributes &atts); - virtual void endElement (const char * name); - virtual void data (const char * s, int len); - virtual void pi (const char * target, const char * data); - virtual void warning (const char * message, int line, int column); - virtual void error (const char * message, int line, int column); }; diff --git a/src/Airports/runwayprefloader.cxx b/src/Airports/runwayprefloader.cxx new file mode 100644 index 000000000..b31bc6061 --- /dev/null +++ b/src/Airports/runwayprefloader.cxx @@ -0,0 +1,143 @@ +#include + +#include "runwayprefloader.hxx" + +FGRunwayPreferenceXMLLoader::FGRunwayPreferenceXMLLoader(FGRunwayPreference* p):XMLVisitor(), _pref(p) {} + +void FGRunwayPreferenceXMLLoader::startXML () { + // cout << "Start XML" << endl; +} + +void FGRunwayPreferenceXMLLoader::endXML () { + //cout << "End XML" << endl; +} + +void FGRunwayPreferenceXMLLoader::startElement (const char * name, const XMLAttributes &atts) { + //cout << "StartElement " << name << endl; + value = string(""); + if (!(strcmp(name, "wind"))) { + //cerr << "Will be processing Wind" << endl; + for (int i = 0; i < atts.size(); i++) + { + //cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl; + //attname = atts.getName(i); + if (atts.getName(i) == string("tail")) { + //cerr << "Tail Wind = " << atts.getValue(i) << endl; + currTimes.setTailWind(atof(atts.getValue(i))); + } + if (atts.getName(i) == string("cross")) { + //cerr << "Cross Wind = " << atts.getValue(i) << endl; + currTimes.setCrossWind(atof(atts.getValue(i))); + } + } + } + if (!(strcmp(name, "time"))) { + //cerr << "Will be processing time" << endl; + for (int i = 0; i < atts.size(); i++) + { + if (atts.getName(i) == string("start")) { + //cerr << "Start Time = " << atts.getValue(i) << endl; + currTimes.addStartTime(processTime(atts.getValue(i))); + } + if (atts.getName(i) == string("end")) { + //cerr << "End time = " << atts.getValue(i) << endl; + currTimes.addEndTime(processTime(atts.getValue(i))); + } + if (atts.getName(i) == string("schedule")) { + //cerr << "Schedule Name = " << atts.getValue(i) << endl; + currTimes.addScheduleName(atts.getValue(i)); + } + } + } + if (!(strcmp(name, "takeoff"))) { + rwyList.clear(); + } + if (!(strcmp(name, "landing"))) + { + rwyList.clear(); + } + if (!(strcmp(name, "schedule"))) { + for (int i = 0; i < atts.size(); i++) + { + //cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl; + //attname = atts.getName(i); + if (atts.getName(i) == string("name")) { + //cerr << "Schedule name = " << atts.getValue(i) << endl; + scheduleName = atts.getValue(i); + } + } + } +} + +//based on a string containing hour and minute, return nr seconds since day start. +time_t FGRunwayPreferenceXMLLoader::processTime(const string &tme) +{ + string hour = tme.substr(0, tme.find(":",0)); + string minute = tme.substr(tme.find(":",0)+1, tme.length()); + + //cerr << "hour = " << hour << " Minute = " << minute << endl; + return (atoi(hour.c_str()) * 3600 + atoi(minute.c_str()) * 60); +} + +void FGRunwayPreferenceXMLLoader::endElement (const char * name) { + //cout << "End element " << name << endl; + if (!(strcmp(name, "rwyuse"))) { + _pref->setInitialized(true); + } + if (!(strcmp(name, "com"))) { // Commercial Traffic + //cerr << "Setting time table for commerical traffic" << endl; + _pref->setComTimes(currTimes); + currTimes.clear(); + } + if (!(strcmp(name, "gen"))) { // General Aviation + //cerr << "Setting time table for general aviation" << endl; + _pref->setGenTimes(currTimes); + currTimes.clear(); + } + if (!(strcmp(name, "mil"))) { // Military Traffic + //cerr << "Setting time table for military traffic" << endl; + _pref->setMilTimes(currTimes); + currTimes.clear(); + } + + if (!(strcmp(name, "takeoff"))) { + //cerr << "Adding takeoff: " << value << endl; + rwyList.set(name, value); + rwyGroup.add(rwyList); + } + if (!(strcmp(name, "landing"))) { + //cerr << "Adding landing: " << value << endl; + rwyList.set(name, value); + rwyGroup.add(rwyList); + } + if (!(strcmp(name, "schedule"))) { + //cerr << "Adding schedule" << scheduleName << endl; + rwyGroup.setName(scheduleName); + //rwyGroup.addRunways(rwyList); + _pref->addRunwayGroup(rwyGroup); + rwyGroup.clear(); + //exit(1); + } +} + +void FGRunwayPreferenceXMLLoader::data (const char * s, int len) { + string token = string(s,len); + //cout << "Character data " << string(s,len) << endl; + //if ((token.find(" ") == string::npos && (token.find('\n')) == string::npos)) + // value += token; + //else + // value = string(""); + value += token; +} + +void FGRunwayPreferenceXMLLoader::pi (const char * target, const char * data) { + //cout << "Processing instruction " << target << ' ' << data << endl; +} + +void FGRunwayPreferenceXMLLoader::warning (const char * message, int line, int column) { + SG_LOG(SG_IO, SG_WARN, "Warning: " << message << " (" << line << ',' << column << ')'); +} + +void FGRunwayPreferenceXMLLoader::error (const char * message, int line, int column) { + SG_LOG(SG_IO, SG_ALERT, "Error: " << message << " (" << line << ',' << column << ')'); +} diff --git a/src/Airports/runwayprefs.cxx b/src/Airports/runwayprefs.cxx index 6815e1a04..9be9644f6 100644 --- a/src/Airports/runwayprefs.cxx +++ b/src/Airports/runwayprefs.cxx @@ -44,6 +44,7 @@ #include #include "runwayprefs.hxx" +#include "simple.hxx" /****************************************************************************** * ScheduleTime @@ -364,7 +365,8 @@ void RunwayGroup::getActive(int i, string &name, string &type) /***************************************************************************** * FGRunway preference ****************************************************************************/ -FGRunwayPreference::FGRunwayPreference() +FGRunwayPreference::FGRunwayPreference(FGAirport* ap) : + _ap(ap) { //cerr << "Running default Constructor" << endl; initialized = false; @@ -373,16 +375,11 @@ FGRunwayPreference::FGRunwayPreference() FGRunwayPreference::FGRunwayPreference(const FGRunwayPreference &other) { initialized = other.initialized; - value = other.value; - scheduleName = other.scheduleName; comTimes = other.comTimes; // Commercial Traffic; genTimes = other.genTimes; // General Aviation; milTimes = other.milTimes; // Military Traffic; - currTimes= other.currTimes; // Needed for parsing; - rwyList = other.rwyList; - rwyGroup = other.rwyGroup; PreferenceListConstIterator i; for (i = other.preferences.begin(); i != other.preferences.end(); i++) preferences.push_back(*i); @@ -391,16 +388,11 @@ FGRunwayPreference::FGRunwayPreference(const FGRunwayPreference &other) FGRunwayPreference & FGRunwayPreference::operator= (const FGRunwayPreference &other) { initialized = other.initialized; - value = other.value; - scheduleName = other.scheduleName; comTimes = other.comTimes; // Commercial Traffic; genTimes = other.genTimes; // General Aviation; milTimes = other.milTimes; // Military Traffic; - currTimes= other.currTimes; // Needed for parsing; - rwyList = other.rwyList; - rwyGroup = other.rwyGroup; PreferenceListConstIterator i; preferences.clear(); for (i = other.preferences.begin(); i != other.preferences.end(); i++) @@ -435,140 +427,6 @@ RunwayGroup *FGRunwayPreference::getGroup(const string &groupName) return 0; } -void FGRunwayPreference::startXML () { - // cout << "Start XML" << endl; -} - -void FGRunwayPreference::endXML () { - // cout << "End XML" << endl; -} - -void FGRunwayPreference::startElement (const char * name, const XMLAttributes &atts) { - //cout << "StartElement " << name << endl; - value = string(""); - if (!(strcmp(name, "wind"))) { - //cerr << "Will be processing Wind" << endl; - for (int i = 0; i < atts.size(); i++) - { - //cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl; - //attname = atts.getName(i); - if (atts.getName(i) == string("tail")) { - //cerr << "Tail Wind = " << atts.getValue(i) << endl; - currTimes.setTailWind(atof(atts.getValue(i))); - } - if (atts.getName(i) == string("cross")) { - //cerr << "Cross Wind = " << atts.getValue(i) << endl; - currTimes.setCrossWind(atof(atts.getValue(i))); - } - } - } - if (!(strcmp(name, "time"))) { - //cerr << "Will be processing time" << endl; - for (int i = 0; i < atts.size(); i++) - { - if (atts.getName(i) == string("start")) { - //cerr << "Start Time = " << atts.getValue(i) << endl; - currTimes.addStartTime(processTime(atts.getValue(i))); - } - if (atts.getName(i) == string("end")) { - //cerr << "End time = " << atts.getValue(i) << endl; - currTimes.addEndTime(processTime(atts.getValue(i))); - } - if (atts.getName(i) == string("schedule")) { - //cerr << "Schedule Name = " << atts.getValue(i) << endl; - currTimes.addScheduleName(atts.getValue(i)); - } - } - } - if (!(strcmp(name, "takeoff"))) { - rwyList.clear(); - } - if (!(strcmp(name, "landing"))) - { - rwyList.clear(); - } - if (!(strcmp(name, "schedule"))) { - for (int i = 0; i < atts.size(); i++) - { - //cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl; - //attname = atts.getName(i); - if (atts.getName(i) == string("name")) { - //cerr << "Schedule name = " << atts.getValue(i) << endl; - scheduleName = atts.getValue(i); - } - } - } -} - -//based on a string containing hour and minute, return nr seconds since day start. -time_t FGRunwayPreference::processTime(const string &tme) -{ - string hour = tme.substr(0, tme.find(":",0)); - string minute = tme.substr(tme.find(":",0)+1, tme.length()); - - //cerr << "hour = " << hour << " Minute = " << minute << endl; - return (atoi(hour.c_str()) * 3600 + atoi(minute.c_str()) * 60); -} - -void FGRunwayPreference::endElement (const char * name) { - //cout << "End element " << name << endl; - if (!(strcmp(name, "rwyuse"))) { - initialized = true; - } - if (!(strcmp(name, "com"))) { // Commercial Traffic - //cerr << "Setting time table for commerical traffic" << endl; - comTimes = currTimes; - currTimes.clear(); - } - if (!(strcmp(name, "gen"))) { // General Aviation - //cerr << "Setting time table for general aviation" << endl; - genTimes = currTimes; - currTimes.clear(); - } - if (!(strcmp(name, "mil"))) { // Military Traffic - //cerr << "Setting time table for military traffic" << endl; - genTimes = currTimes; - currTimes.clear(); - } - - if (!(strcmp(name, "takeoff"))) { - //cerr << "Adding takeoff: " << value << endl; - rwyList.set(name, value); - rwyGroup.add(rwyList); - } - if (!(strcmp(name, "landing"))) { - //cerr << "Adding landing: " << value << endl; - rwyList.set(name, value); - rwyGroup.add(rwyList); - } - if (!(strcmp(name, "schedule"))) { - //cerr << "Adding schedule" << scheduleName << endl; - rwyGroup.setName(scheduleName); - //rwyGroup.addRunways(rwyList); - preferences.push_back(rwyGroup); - rwyGroup.clear(); - //exit(1); - } -} - -void FGRunwayPreference::data (const char * s, int len) { - string token = string(s,len); - //cout << "Character data " << string(s,len) << endl; - //if ((token.find(" ") == string::npos && (token.find('\n')) == string::npos)) - // value += token; - //else - // value = string(""); - value += token; -} - -void FGRunwayPreference::pi (const char * target, const char * data) { - //cout << "Processing instruction " << target << ' ' << data << endl; -} - -void FGRunwayPreference::warning (const char * message, int line, int column) { - SG_LOG(SG_IO, SG_WARN, "Warning: " << message << " (" << line << ',' << column << ')'); -} - -void FGRunwayPreference::error (const char * message, int line, int column) { - SG_LOG(SG_IO, SG_ALERT, "Error: " << message << " (" << line << ',' << column << ')'); -} + string FGRunwayPreference::getId() { + return _ap->getId(); + }; diff --git a/src/Airports/runwayprefs.hxx b/src/Airports/runwayprefs.hxx index c52312c89..83e35cdac 100644 --- a/src/Airports/runwayprefs.hxx +++ b/src/Airports/runwayprefs.hxx @@ -24,7 +24,14 @@ #ifndef _RUNWAYPREFS_HXX_ #define _RUNWAYPREFS_HXX_ -#include +#include +#include +#include + +#include + +SG_USING_STD(vector); +SG_USING_STD(string); typedef vector timeVec; typedef vector::const_iterator timeVecConstIterator; @@ -33,6 +40,7 @@ typedef vector stringVec; typedef vector::iterator stringVecIterator; typedef vector::const_iterator stringVecConstIterator; +class FGAirport; /***************************************************************************/ class ScheduleTime { @@ -120,42 +128,37 @@ typedef vector::const_iterator PreferenceListConstIterator; /******************************************************************************/ -class FGRunwayPreference : public XMLVisitor { +class FGRunwayPreference { private: - string value; - string scheduleName; + FGAirport* _ap; ScheduleTime comTimes; // Commercial Traffic; ScheduleTime genTimes; // General Aviation; ScheduleTime milTimes; // Military Traffic; - ScheduleTime currTimes; // Needed for parsing; - RunwayList rwyList; - RunwayGroup rwyGroup; PreferenceList preferences; - - time_t processTime(const string&); bool initialized; public: - FGRunwayPreference(); + FGRunwayPreference(FGAirport* ap); FGRunwayPreference(const FGRunwayPreference &other); FGRunwayPreference & operator= (const FGRunwayPreference &other); + ScheduleTime *getSchedule(const char *trafficType); RunwayGroup *getGroup(const string& groupName); + + string getId(); + bool available() { return initialized; }; + void setInitialized(bool state) { initialized = state; }; + + void setMilTimes(ScheduleTime& t) { milTimes = t; }; + void setGenTimes(ScheduleTime& t) { genTimes = t; }; + void setComTimes(ScheduleTime& t) { comTimes = t; }; - // Some overloaded virtual XMLVisitor members - virtual void startXML (); - virtual void endXML (); - virtual void startElement (const char * name, const XMLAttributes &atts); - virtual void endElement (const char * name); - virtual void data (const char * s, int len); - virtual void pi (const char * target, const char * data); - virtual void warning (const char * message, int line, int column); - virtual void error (const char * message, int line, int column); + void addRunwayGroup(RunwayGroup& g) { preferences.push_back(g); }; }; #endif diff --git a/src/Airports/simple.cxx b/src/Airports/simple.cxx index ed80d43af..64c2109b1 100644 --- a/src/Airports/simple.cxx +++ b/src/Airports/simple.cxx @@ -50,6 +50,7 @@ #include STL_STRING #include "simple.hxx" +#include "xmlloader.hxx" SG_USING_STD(sort); SG_USING_STD(random_shuffle); @@ -89,46 +90,14 @@ FGAirportDynamics * FGAirport::getDynamics() if (dynamics != 0) { return dynamics; } else { - FGRunwayPreference rwyPrefs; //cerr << "Trying to load dynamics for " << _id << endl; - dynamics = new FGAirportDynamics(_latitude, _longitude, _elevation, _id); - - SGPath parkpath( globals->get_fg_root() ); - parkpath.append( "/AI/Airports/" ); - parkpath.append(_id); - parkpath.append("parking.xml"); - - SGPath rwyPrefPath( globals->get_fg_root() ); - rwyPrefPath.append( "AI/Airports/" ); - rwyPrefPath.append(_id); - rwyPrefPath.append("rwyuse.xml"); - - //if (ai_dirs.find(id.c_str()) != ai_dirs.end() - // && parkpath.exists()) - if (parkpath.exists()) { - try { - readXML(parkpath.str(),*dynamics); - //cerr << "Initializing " << getId() << endl; - dynamics->init(); - dynamics->getGroundNetwork()->setParent(this); - } catch (const sg_exception &e) { - //cerr << "unable to read " << parkpath.str() << endl; - } - } + dynamics = new FGAirportDynamics(this); + XMLLoader::load(dynamics); - //if (ai_dirs.find(id.c_str()) != ai_dirs.end() - // && rwyPrefPath.exists()) - if (rwyPrefPath.exists()) { - try { - readXML(rwyPrefPath.str(), rwyPrefs); - dynamics->setRwyUse(rwyPrefs); - } catch (const sg_exception &e) { - //cerr << "unable to read " << rwyPrefPath.str() << endl; - //exit(1); - } - } - //exit(1); - } + FGRunwayPreference rwyPrefs(this); + XMLLoader::load(&rwyPrefs); + dynamics->setRwyUse(rwyPrefs); + } return dynamics; } @@ -178,7 +147,6 @@ void FGAirportList::add( const string &id, const double longitude, const double latitude, const double elevation, const string &name, const bool has_metar ) { - FGRunwayPreference rwyPrefs; FGAirport* a = new FGAirport(id, longitude, latitude, elevation, name, has_metar); airports_by_id[a->getId()] = a; diff --git a/src/Airports/xmlloader.cxx b/src/Airports/xmlloader.cxx new file mode 100644 index 000000000..1448c84f9 --- /dev/null +++ b/src/Airports/xmlloader.cxx @@ -0,0 +1,50 @@ +#include +#include
+ +#include "xmlloader.hxx" +#include "dynamicloader.hxx" +#include "runwayprefloader.hxx" + +#include "dynamics.hxx" +#include "runwayprefs.hxx" + +XMLLoader::XMLLoader() {} +XMLLoader::~XMLLoader() {} + +void XMLLoader::load(FGAirportDynamics* d) { + FGAirportDynamicsXMLLoader visitor(d); + + SGPath parkpath( globals->get_fg_root() ); + parkpath.append( "/AI/Airports/" ); + parkpath.append( d->getId() ); + parkpath.append( "parking.xml" ); + + if (parkpath.exists()) { + try { + readXML(parkpath.str(), visitor); + d->init(); + } catch (const sg_exception &e) { + //cerr << "unable to read " << parkpath.str() << endl; + } + } + +} + +void XMLLoader::load(FGRunwayPreference* p) { + FGRunwayPreferenceXMLLoader visitor(p); + + SGPath rwyPrefPath( globals->get_fg_root() ); + rwyPrefPath.append( "AI/Airports/" ); + rwyPrefPath.append( p->getId() ); + rwyPrefPath.append( "rwyuse.xml" ); + + //if (ai_dirs.find(id.c_str()) != ai_dirs.end() + // && rwyPrefPath.exists()) + if (rwyPrefPath.exists()) { + try { + readXML(rwyPrefPath.str(), visitor); + } catch (const sg_exception &e) { + //cerr << "unable to read " << rwyPrefPath.str() << endl; + } + } +} diff --git a/src/Airports/xmlloader.hxx b/src/Airports/xmlloader.hxx new file mode 100644 index 000000000..a423eac2f --- /dev/null +++ b/src/Airports/xmlloader.hxx @@ -0,0 +1,20 @@ +#ifndef _XML_LOADER_HXX_ +#define _XML_LOADER_HXX_ + +#include + +class FGAirportDynamics; +class FGRunwayPreference; + + +class XMLLoader { +public: + XMLLoader(); + ~XMLLoader(); + + static void load(FGRunwayPreference* p); + static void load(FGAirportDynamics* d); + +}; + +#endif -- 2.39.5