1 // simple.hxx -- a really simplistic class to manage airport ID,
2 // lat, lon of the center of one of it's runways, and
5 // Written by Curtis Olson, started April 1998.
6 // Updated by Durk Talsma, started December 2004.
8 // Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License as
12 // published by the Free Software Foundation; either version 2 of the
13 // License, or (at your option) any later version.
15 // This program is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #ifndef _FG_SIMPLE_HXX
28 #define _FG_SIMPLE_HXX
30 #include <simgear/compiler.h>
37 #include <simgear/math/point3d.hxx>
38 #include "Navaids/positioned.hxx"
41 class FGAirportDynamics;
44 typedef SGSharedPtr<FGRunway> FGRunwayPtr;
46 /***************************************************************************************
48 **************************************************************************************/
49 class FGAirport : public FGPositioned
52 SGGeod _tower_location;
55 FGAirportDynamics *_dynamics;
58 FGAirport(const std::string& id, const SGGeod& location, const SGGeod& tower,
59 const std::string& name, bool has_metar, Type aType);
62 const std::string& getId() const { return ident(); }
63 const std::string& getName() const { return _name; }
64 double getLongitude() const { return longitude(); }
66 double getLatitude() const { return latitude(); }
68 double getElevation() const { return elevation(); }
69 bool getMetar() const { return _has_metar; }
70 bool isAirport() const;
71 bool isSeaport() const;
72 bool isHeliport() const;
74 const SGGeod& getTowerLocation() const { return _tower_location; }
76 void setMetar(bool value) { _has_metar = value; }
78 FGRunway* getActiveRunwayForUsage() const;
80 FGAirportDynamics *getDynamics();
82 unsigned int numRunways() const;
83 FGRunway* getRunwayByIndex(unsigned int aIndex) const;
85 bool hasRunwayWithIdent(const std::string& aIdent) const;
86 FGRunway* getRunwayByIdent(const std::string& aIdent) const;
87 FGRunway* findBestRunwayForHeading(double aHeading) const;
89 unsigned int numTaxiways() const;
90 FGRunway* getTaxiwayByIndex(unsigned int aIndex) const;
92 void addRunway(FGRunway* aRunway);
94 typedef std::vector<FGRunwayPtr>::const_iterator Runway_iterator;
96 * Helper to locate a runway by ident
98 Runway_iterator getIteratorForRunwayIdent(const std::string& aIdent) const;
100 FGAirport operator=(FGAirport &other);
101 FGAirport(const FGAirport&);
103 std::vector<FGRunwayPtr> mRunways;
104 std::vector<FGRunwayPtr> mTaxiways;
108 class FGAirportSearchFilter {
110 virtual ~FGAirportSearchFilter() {}
111 // all airports pass the filter by default
112 virtual bool pass(FGAirport*) { return true; }
115 class FGIdentOrdering {
117 virtual ~FGIdentOrdering()
120 virtual bool compare(const std::string& aA, const std::string& aB) const
124 typedef std::map < std::string, FGAirport* > airport_map;
125 typedef airport_map::iterator airport_map_iterator;
126 typedef airport_map::const_iterator const_airport_map_iterator;
128 typedef std::vector < FGAirport * > airport_list;
129 typedef airport_list::iterator airport_list_iterator;
130 typedef airport_list::const_iterator const_airport_list_iterator;
134 class FGAirportList {
137 airport_map airports_by_id;
138 airport_list airports_array;
147 // add an entry to the list
148 FGAirport* add( const std::string& id, const SGGeod& location, const SGGeod& tower,
149 const std::string& name, bool has_metar, FGPositioned::Type aType);
151 // search for the specified id.
152 // Returns NULL if unsucessfull.
153 FGAirport* search( const std::string& id );
155 // Search for the next airport in ASCII sequence to the supplied id.
156 // eg. id = "KDC" or "KDCA" would both return "KDCA".
157 // NOTE: Numbers come prior to A-Z in ASCII sequence so id = "LD" would return "LD57", not "LDDP"
158 // optional ordering can make letters come before numbers
159 // Implementation assumes airport codes are unique.
160 // Returns NULL if unsucessfull.
161 const FGAirport* findFirstById(const std::string& aIdent, FGIdentOrdering* aOrder = NULL);
163 // search for the airport closest to the specified position
164 // (currently a linear inefficient search so it's probably not
165 // best to use this at runtime.) An FGAirportSearchFilter class
166 // can be used to restrict the possible choices to a subtype.
167 // max_range limits search - specified as an arc distance, in degrees
168 FGAirport* search( double lon_deg, double lat_deg, double max_range );
169 FGAirport* search( double lon_deg, double lat_deg, double max_range, FGAirportSearchFilter& );
172 * Return the number of airports in the list.
177 * Return a specific airport, by position.
179 const FGAirport *getAirport( unsigned int index ) const;
182 * Return a pointer to the raw airport list
184 inline const airport_list* getAirportList() { return (&airports_array); }
187 * Mark the specified airport record as not having metar
189 void no_metar( const std::string &id );
192 * Mark the specified airport record as (yes) having metar
194 void has_metar( const std::string &id );
198 // find basic airport location info from airport database
199 const FGAirport *fgFindAirportID( const std::string& id);
201 // get airport elevation
202 double fgGetAirportElev( const std::string& id );
204 // get airport position
205 Point3D fgGetAirportPos( const std::string& id );
207 #endif // _FG_SIMPLE_HXX