//
// simple.cxx -- a really simplistic class to manage airport ID,
-// lat, lon of the center of one of it's runways, and
+// lat, lon of the center of one of it's runways, and
// elevation in feet.
//
// Written by Curtis Olson, started April 1998.
#include <Main/fg_props.hxx>
#include <Airports/runways.hxx>
-#include STL_STRING
+#include <string>
#include "simple.hxx"
+#include "xmlloader.hxx"
SG_USING_STD(sort);
SG_USING_STD(random_shuffle);
-
-
/***************************************************************************
* FGAirport
***************************************************************************/
-FGAirport::FGAirport() : _longitude(0), _latitude(0), _elevation(0)
+FGAirport::FGAirport() : _dynamics(0)
{
- dynamics = 0;
}
-
-FGAirport::FGAirport(const string &id, double lon, double lat, double elev, const string &name, bool has_metar)
+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),
+ _tower_location(tower_location),
+ _name(name),
+ _has_metar(has_metar),
+ _is_airport(is_airport),
+ _is_seaport(is_seaport),
+ _is_heliport(is_heliport),
+ _dynamics(0)
{
- _id = id;
- _longitude = lon;
- _latitude = lat;
- _elevation = elev;
- _name = name;
- _has_metar = has_metar;
- dynamics = 0;
}
+
FGAirport::~FGAirport()
{
- delete dynamics;
+ delete _dynamics;
}
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( "/Airports/AI/" );
- parkpath.append(_id);
- parkpath.append("parking.xml");
-
- SGPath rwyPrefPath( globals->get_fg_root() );
- rwyPrefPath.append( "/Airports/AI/" );
- 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);
- dynamics->init();
- }
- catch (const sg_exception &e) {
- //cerr << "unable to read " << parkpath.str() << endl;
- }
- }
- //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);
- }
- return dynamics;
+ if (_dynamics != 0) {
+ return _dynamics;
+ } else {
+ //cerr << "Trying to load dynamics for " << _id << endl;
+ _dynamics = new FGAirportDynamics(this);
+ XMLLoader::load(_dynamics);
+
+ FGRunwayPreference rwyPrefs(this);
+ XMLLoader::load(&rwyPrefs);
+ _dynamics->setRwyUse(rwyPrefs);
+ }
+ return _dynamics;
}
// in the base package.
//
// Note: 2005/12/23: This is probably not necessary anymore, because I'm
-// Switching to runtime airport dynamics loading (DT).
+// Switching to runtime airport dynamics loading (DT).
FGAirportList::FGAirportList()
{
// ulDir* d;
}
-FGAirportList::~FGAirportList( void ) {
- for(unsigned int i = 0; i < airports_array.size(); ++i) {
+FGAirportList::~FGAirportList( void )
+{
+ for (unsigned int i = 0; i < airports_array.size(); ++i) {
delete airports_array[i];
}
}
// add an entry to the list
-void FGAirportList::add( const string &id, const double longitude,
- const double latitude, const double elevation,
- const string &name, const bool has_metar )
+void 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)
{
- FGRunwayPreference rwyPrefs;
- FGAirport* a = new FGAirport(id, longitude, latitude, elevation, name, has_metar);
+ FGAirport* a = new FGAirport(id, location, tower_location, name, has_metar,
+ is_airport, is_seaport, is_heliport);
-
airports_by_id[a->getId()] = a;
// try and read in an auxilary file
-
+
airports_array.push_back( a );
- SG_LOG( SG_GENERAL, SG_BULK, "Adding " << id << " pos = " << longitude
- << ", " << latitude << " elev = " << elevation );
+ SG_LOG( SG_GENERAL, SG_BULK, "Adding " << id << " pos = " << location.getLongitudeDeg()
+ << ", " << location.getLatitudeDeg() << " elev = " << location.getElevationFt() );
}
// search for the specified id
-FGAirport* FGAirportList::search( const string& id) {
- airport_map_iterator itr = airports_by_id.find(id);
- return(itr == airports_by_id.end() ? NULL : itr->second);
+FGAirport* FGAirportList::search( const string& id)
+{
+ airport_map_iterator itr = airports_by_id.find(id);
+ return (itr == airports_by_id.end() ? NULL : itr->second);
}
// search for first subsequent alphabetically to supplied id
-const FGAirport* FGAirportList::findFirstById( const string& id, bool exact ) {
+const FGAirport* FGAirportList::findFirstById( const string& id, bool exact )
+{
airport_map_iterator itr;
- if(exact) {
+ if (exact) {
itr = airports_by_id.find(id);
} else {
itr = airports_by_id.lower_bound(id);
}
- if(itr == airports_by_id.end()) {
- return(NULL);
+ if (itr == airports_by_id.end()) {
+ return (NULL);
} else {
- return(itr->second);
+ return (itr->second);
}
}
// search for the airport nearest the specified position
-FGAirport* FGAirportList::search( double lon_deg, double lat_deg,
- bool with_metar ) {
- int closest = -1;
+FGAirport* FGAirportList::search(double lon_deg, double lat_deg)
+{
+ static FGAirportSearchFilter accept_any;
+ return search(lon_deg, lat_deg, accept_any);
+}
+
+
+// search for the airport nearest the specified position and
+// passing the filter
+FGAirport* FGAirportList::search(double lon_deg, double lat_deg,
+ FGAirportSearchFilter& filter)
+{
double min_dist = 360.0;
- unsigned int i;
- for ( i = 0; i < airports_array.size(); ++i ) {
+ airport_list_iterator it = airports_array.begin();
+ airport_list_iterator end = airports_array.end();
+ airport_list_iterator closest = end;
+ for (; it != end; ++it) {
+ if (!filter.pass(*it))
+ continue;
+
// crude manhatten distance based on lat/lon difference
- double d = fabs(lon_deg - airports_array[i]->getLongitude())
- + fabs(lat_deg - airports_array[i]->getLatitude());
- if ( d < min_dist ) {
- if ( !with_metar || (with_metar&&airports_array[i]->getMetar()) ) {
- closest = i;
- min_dist = d;
- }
+ double d = fabs(lon_deg - (*it)->getLongitude())
+ + fabs(lat_deg - (*it)->getLatitude());
+ if (d < min_dist) {
+ closest = it;
+ min_dist = d;
}
}
-
- return ( closest > -1 ? airports_array[closest] : NULL );
+ return closest != end ? *closest : 0;
}
return airports_array.size();
}
+
const FGAirport *FGAirportList::getAirport( unsigned int index ) const
{
- if(index < airports_array.size()) {
+ if (index < airports_array.size()) {
return(airports_array[index]);
} else {
return(NULL);
/**
* Mark the specified airport record as not having metar
*/
-void FGAirportList::no_metar( const string &id ) {
- if(airports_by_id.find(id) != airports_by_id.end()) {
+void FGAirportList::no_metar( const string &id )
+{
+ if(airports_by_id.find(id) != airports_by_id.end()) {
airports_by_id[id]->setMetar(false);
}
}
/**
* Mark the specified airport record as (yes) having metar
*/
-void FGAirportList::has_metar( const string &id ) {
- if(airports_by_id.find(id) != airports_by_id.end()) {
+void FGAirportList::has_metar( const string &id )
+{
+ if(airports_by_id.find(id) != airports_by_id.end()) {
airports_by_id[id]->setMetar(true);
}
}
+
// find basic airport location info from airport database
-const FGAirport *fgFindAirportID( const string& id) {
+const FGAirport *fgFindAirportID( const string& id)
+{
const FGAirport* result = NULL;
if ( id.length() ) {
SG_LOG( SG_GENERAL, SG_BULK, "Searching for airport code = " << id );
// get airport elevation
-double fgGetAirportElev( const string& id ) {
-
- // double lon, lat;
-
+double fgGetAirportElev( const string& id )
+{
SG_LOG( SG_GENERAL, SG_BULK,
"Finding elevation for airport: " << id );
}
}
-// get airport position
-Point3D fgGetAirportPos( const string& id ) {
- // double lon, lat;
+// get airport position
+Point3D fgGetAirportPos( const string& id )
+{
SG_LOG( SG_ATC, SG_BULK,
"Finding position for airport: " << id );
const FGAirport *a = fgFindAirportID( id);
-
+
if (a) {
return Point3D(a->getLongitude(), a->getLatitude(), a->getElevation());
} else {