diff --git a/src/Airports/apt_loader.cxx b/src/Airports/apt_loader.cxx index 1f92be4d5..85f803191 100644 --- a/src/Airports/apt_loader.cxx +++ b/src/Airports/apt_loader.cxx @@ -36,6 +36,7 @@ #include #include #include +#include #include @@ -44,6 +45,18 @@ #include "apt_loader.hxx" +static FGPositioned::Type fptypeFromRobinType(int aType) +{ + switch (aType) { + case 1: return FGPositioned::AIRPORT; + case 16: return FGPositioned::SEAPORT; + case 17: return FGPositioned::HELIPORT; + default: + SG_LOG(SG_GENERAL, SG_ALERT, "unsupported type:" << aType); + throw sg_range_exception("Unsupported airport type", "fptypeFromRobinType"); + } +} + FGAirport* addAirport(FGAirportList *airports, const string& apt_id, const string& apt_name, int rwy_count, double rwy_lat_accum, double rwy_lon_accum, double last_rwy_heading, double apt_elev, SGGeod& tower, bool got_tower, int type) @@ -69,8 +82,10 @@ FGAirport* addAirport(FGAirportList *airports, const string& apt_id, const strin tower = SGGeod::fromDegFt(lon + fudge_lon, lat + fudge_lat, apt_elev + tower_height); } + + return airports->add(apt_id, SGGeod::fromDegFt(lon, lat, apt_elev), tower, apt_name, false, - type == 1/*airport*/, type == 16/*seaport*/, type == 17/*heliport*/); + fptypeFromRobinType(type)); } // Load the airport data base from the specified aptdb file. The @@ -213,14 +228,14 @@ bool fgAirportDBLoad( FGAirportList *airports, int surface_code = atoi( token[10].c_str() ); FGRunway* rwy = new FGRunway(NULL, rwy_no, lon, lat, heading, length, - width, displ_thresh1, stopway1, surface_code, false); + width, displ_thresh1, stopway1, surface_code, false); FGRunway* reciprocal = new FGRunway(NULL, FGRunway::reverseIdent(rwy_no), lon, lat, heading + 180.0, length, width, displ_thresh2, stopway2, surface_code, true); - runways.push_back(rwy); runways.push_back(reciprocal); + } else if ( line_id == 18 ) { // beacon entry (ignore) } else if ( line_id == 14 ) { @@ -252,7 +267,7 @@ bool fgAirportDBLoad( FGAirportList *airports, // add the last airport being processed if any addAirport(airports, last_apt_id, last_apt_name, rwy_count, rwy_lat_accum, rwy_lon_accum, - last_rwy_heading, last_apt_elev, last_tower, got_tower, 0); + last_rwy_heading, last_apt_elev, last_tower, got_tower, last_apt_type); // diff --git a/src/Airports/simple.cxx b/src/Airports/simple.cxx index 9a0a4dab4..8f8c87529 100644 --- a/src/Airports/simple.cxx +++ b/src/Airports/simple.cxx @@ -33,21 +33,16 @@ #include -#include -#include - #include #include #include #include #include -//#include #include #include
#include
#include #include -#include #include @@ -63,21 +58,13 @@ using std::random_shuffle; /*************************************************************************** * FGAirport ***************************************************************************/ -FGAirport::FGAirport() : _dynamics(0) -{ -} FGAirport::FGAirport(const string &id, const SGGeod& location, const SGGeod& tower_location, - const string &name, bool has_metar, bool is_airport, bool is_seaport, - bool is_heliport) : - _id(id), - _location(location), + const string &name, bool has_metar, Type aType) : + FGPositioned(aType, id, location), _tower_location(tower_location), _name(name), _has_metar(has_metar), - _is_airport(is_airport), - _is_seaport(is_seaport), - _is_heliport(is_heliport), _dynamics(0) { } @@ -88,6 +75,20 @@ FGAirport::~FGAirport() delete _dynamics; } +bool FGAirport::isAirport() const +{ + return type() == AIRPORT; +} + +bool FGAirport::isSeaport() const +{ + return type() == SEAPORT; +} + +bool FGAirport::isHeliport() const +{ + return type() == HELIPORT; +} FGAirportDynamics * FGAirport::getDynamics() { @@ -125,8 +126,8 @@ FGRunway* FGAirport::getRunwayByIdent(const string& aIdent) const { Runway_iterator it = getIteratorForRunwayIdent(aIdent); if (it == mRunways.end()) { - SG_LOG(SG_GENERAL, SG_ALERT, "no such runway '" << aIdent << "' at airport " << _id); - throw sg_range_exception("unknown runway " + aIdent + " at airport:" + _id, "FGAirport::getRunwayByIdent"); + SG_LOG(SG_GENERAL, SG_ALERT, "no such runway '" << aIdent << "' at airport " << ident()); + throw sg_range_exception("unknown runway " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent"); } return *it; @@ -220,7 +221,7 @@ FGRunway* FGAirport::getActiveRunwayForUsage() const envMgr = (FGEnvironmentMgr *) globals->get_subsystem("environment"); } - FGEnvironment stationWeather(envMgr->getEnvironment(_location)); + FGEnvironment stationWeather(envMgr->getEnvironment(mPosition)); double windSpeed = stationWeather.get_wind_speed_kt(); double hdg = stationWeather.get_wind_from_heading_deg(); @@ -271,12 +272,9 @@ FGAirportList::~FGAirportList( void ) // add an entry to the list FGAirport* FGAirportList::add( const string &id, const SGGeod& location, const SGGeod& tower_location, - const string &name, bool has_metar, bool is_airport, bool is_seaport, - bool is_heliport) + const string &name, bool has_metar, FGPositioned::Type aType) { - FGAirport* a = new FGAirport(id, location, tower_location, name, has_metar, - is_airport, is_seaport, is_heliport); - + FGAirport* a = new FGAirport(id, location, tower_location, name, has_metar, aType); airports_by_id[a->getId()] = a; // try and read in an auxilary file diff --git a/src/Airports/simple.hxx b/src/Airports/simple.hxx index 2236b7660..2ec8a9173 100644 --- a/src/Airports/simple.hxx +++ b/src/Airports/simple.hxx @@ -35,7 +35,6 @@ #include #include - #include "Navaids/positioned.hxx" // forward decls @@ -47,41 +46,33 @@ typedef SGSharedPtr FGRunwayPtr; /*************************************************************************************** * **************************************************************************************/ -class FGAirport { +class FGAirport : public FGPositioned +{ private: - std::string _id; - SGGeod _location; SGGeod _tower_location; std::string _name; bool _has_metar; - bool _is_airport; - bool _is_seaport; - bool _is_heliport; FGAirportDynamics *_dynamics; public: - FGAirport(); - // FGAirport(const FGAirport &other); FGAirport(const std::string& id, const SGGeod& location, const SGGeod& tower, - const std::string& name, - bool has_metar, bool is_airport, bool is_seaport, bool is_heliport); + const std::string& name, bool has_metar, Type aType); ~FGAirport(); - const std::string& getId() const { return _id; } + const std::string& getId() const { return ident(); } const std::string& getName() const { return _name; } - double getLongitude() const { return _location.getLongitudeDeg(); } + double getLongitude() const { return longitude(); } // Returns degrees - double getLatitude() const { return _location.getLatitudeDeg(); } + double getLatitude() const { return latitude(); } // Returns ft - double getElevation() const { return _location.getElevationFt(); } + double getElevation() const { return elevation(); } bool getMetar() const { return _has_metar; } - bool isAirport() const { return _is_airport; } - bool isSeaport() const { return _is_seaport; } - bool isHeliport() const { return _is_heliport; } + bool isAirport() const; + bool isSeaport() const; + bool isHeliport() const; const SGGeod& getTowerLocation() const { return _tower_location; } - void setId(const std::string& id) { _id = id; } void setMetar(bool value) { _has_metar = value; } FGRunway* getActiveRunwayForUsage() const; @@ -101,7 +92,6 @@ public: void addRunway(FGRunway* aRunway); private: typedef std::vector::const_iterator Runway_iterator; - /** * Helper to locate a runway by ident */ @@ -156,8 +146,7 @@ public: // add an entry to the list FGAirport* add( const std::string& id, const SGGeod& location, const SGGeod& tower, - const std::string& name, bool has_metar, bool is_airport, - bool is_seaport, bool is_heliport ); + const std::string& name, bool has_metar, FGPositioned::Type aType); // search for the specified id. // Returns NULL if unsucessfull.