1 // airport.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>
36 #include <Navaids/positioned.hxx>
37 #include <Airports/runways.hxx>
40 class FGAirportDynamics;
48 namespace flightgear {
55 typedef SGSharedPtr<Waypt> WayptRef;
56 typedef std::vector<WayptRef> WayptVec;
58 typedef std::vector<CommStation*> CommStationList;
59 typedef std::map<std::string, FGAirport*> AirportCache;
62 typedef std::vector<FGRunway*> FGRunwayList;
65 /***************************************************************************************
67 **************************************************************************************/
68 class FGAirport : public FGPositioned
71 FGAirport(PositionedID aGuid, const std::string& id, const SGGeod& location,
72 const std::string& name, bool has_metar, Type aType);
75 const std::string& getId() const { return ident(); }
76 const std::string& getName() const { return _name; }
77 double getLongitude() const { return longitude(); }
79 double getLatitude() const { return latitude(); }
81 double getElevation() const { return elevation(); }
82 bool getMetar() const { return _has_metar; }
83 bool isAirport() const;
84 bool isSeaport() const;
85 bool isHeliport() const;
87 static bool isAirportType(FGPositioned* pos);
89 virtual const std::string& name() const
93 * reload the ILS data from XML if required.
94 * @result true if the data was refreshed, false if no data was loaded
95 * or previously cached data is still correct.
97 bool validateILSData();
99 SGGeod getTowerLocation() const;
101 void setMetar(bool value) { _has_metar = value; }
103 FGRunway* getActiveRunwayForUsage() const;
105 FGAirportDynamics *getDynamics();
107 unsigned int numRunways() const;
108 unsigned int numHelipads() const;
109 FGRunway* getRunwayByIndex(unsigned int aIndex) const;
110 FGHelipad* getHelipadByIndex(unsigned int aIndex) const;
112 bool hasRunwayWithIdent(const std::string& aIdent) const;
113 bool hasHelipadWithIdent(const std::string& aIdent) const;
114 FGRunway* getRunwayByIdent(const std::string& aIdent) const;
115 FGHelipad* getHelipadByIdent(const std::string& aIdent) const;
116 FGRunway* findBestRunwayForHeading(double aHeading) const;
119 * return the most likely target runway based on a position.
120 * Specifically, return the runway for which the course from aPos
121 * to the runway end, mostly closely matches the runway heading.
122 * This is a good approximation of which runway the position is on or
125 FGRunway* findBestRunwayForPos(const SGGeod& aPos) const;
128 * Retrieve all runways at the airport, but excluding the reciprocal
129 * runways. For example at KSFO this might return 1L, 1R, 28L and 28R,
130 * but would not then include 19L/R or 10L/R.
132 * Exactly which runways you get, is undefined (i.e, dont assumes it's
133 * runways with heading < 180 degrees) - it depends on order in apt.dat.
135 * This is useful for code that wants to process each piece of tarmac at
136 * an airport *once*, not *twice* - eg mapping and nav-display code.
138 FGRunwayList getRunwaysWithoutReciprocals() const;
141 * Useful predicate for FMS/GPS/NAV displays and similar - check if this
142 * aiport has a hard-surfaced runway of at least the specified length.
144 bool hasHardRunwayOfLengthFt(double aLengthFt) const;
146 unsigned int numTaxiways() const;
147 FGTaxiway* getTaxiwayByIndex(unsigned int aIndex) const;
149 unsigned int numPavements() const;
150 FGPavement* getPavementByIndex(unsigned int aIndex) const;
152 class AirportFilter : public Filter
155 virtual bool pass(FGPositioned* aPos) const {
156 return passAirport(static_cast<FGAirport*>(aPos));
159 virtual Type minType() const {
163 virtual Type maxType() const {
167 virtual bool passAirport(FGAirport* aApt) const {
173 * Filter which passes heliports and seaports in addition to airports
175 class PortsFilter : public AirportFilter
178 virtual Type maxType() const {
183 class HardSurfaceFilter : public AirportFilter
186 HardSurfaceFilter(double minLengthFt = -1);
188 virtual bool passAirport(FGAirport* aApt) const;
195 void setProcedures(const std::vector<flightgear::SID*>& aSids,
196 const std::vector<flightgear::STAR*>& aStars,
197 const std::vector<flightgear::Approach*>& aApproaches);
199 void addSID(flightgear::SID* aSid);
200 void addSTAR(flightgear::STAR* aStar);
201 void addApproach(flightgear::Approach* aApp);
203 unsigned int numSIDs() const;
204 flightgear::SID* getSIDByIndex(unsigned int aIndex) const;
205 flightgear::SID* findSIDWithIdent(const std::string& aIdent) const;
207 unsigned int numSTARs() const;
208 flightgear::STAR* getSTARByIndex(unsigned int aIndex) const;
209 flightgear::STAR* findSTARWithIdent(const std::string& aIdent) const;
211 unsigned int numApproaches() const;
212 flightgear::Approach* getApproachByIndex(unsigned int aIndex) const;
213 flightgear::Approach* findApproachWithIdent(const std::string& aIdent) const;
216 * Syntactic wrapper around FGPositioned::findClosest - find the closest
217 * match for filter, and return it cast to FGAirport. The default filter
218 * passes airports, but not seaports or heliports
220 static FGAirport* findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
223 * Helper to look up an FGAirport instance by unique ident. Throws an
224 * exception if the airport could not be found - so callers can assume
225 * the result is non-NULL.
227 static FGAirport* getByIdent(const std::string& aIdent);
230 * Helper to look up an FGAirport instance by unique ident. Returns NULL
231 * if the airport could not be found.
233 static FGAirport* findByIdent(const std::string& aIdent);
236 * Specialised helper to implement the AirportList dialog. Performs a
237 * case-insensitive search on airport names and ICAO codes, and returns
238 * matches in a format suitable for use by a puaList.
240 static char** searchNamesAndIdents(const std::string& aFilter);
242 flightgear::CommStationList commStationsOfType(FGPositioned::Type aTy) const;
244 flightgear::CommStationList commStations() const;
246 static flightgear::AirportCache airportCache;
249 FGAirport operator=(FGAirport &other);
250 FGAirport(const FGAirport&);
253 * helper to read airport data from the scenery XML files.
255 void loadSceneryDefinitions() const;
258 * Helpers to process property data loaded from an ICAO.threshold.xml file
260 void readThresholdData(SGPropertyNode* aRoot);
261 void processThreshold(SGPropertyNode* aThreshold);
263 void readILSData(SGPropertyNode* aRoot);
265 void validateTowerData() const;
268 * Helper to parse property data loaded from an ICAO.twr.xml file
270 void readTowerData(SGPropertyNode* aRoot);
274 FGAirportDynamics *_dynamics;
276 void loadRunways() const;
277 void loadHelipads() const;
278 void loadTaxiways() const;
279 void loadProcedures() const;
281 mutable bool mTowerDataLoaded;
282 mutable bool mRunwaysLoaded;
283 mutable bool mHelipadsLoaded;
284 mutable bool mTaxiwaysLoaded;
285 mutable bool mProceduresLoaded;
288 mutable PositionedIDVec mRunways;
289 mutable PositionedIDVec mHelipads;
290 mutable PositionedIDVec mTaxiways;
291 PositionedIDVec mPavements;
293 typedef SGSharedPtr<flightgear::SID> SIDRef;
294 typedef SGSharedPtr<flightgear::STAR> STARRef;
295 typedef SGSharedPtr<flightgear::Approach> ApproachRef;
297 std::vector<SIDRef> mSIDs;
298 std::vector<STARRef> mSTARs;
299 std::vector<ApproachRef> mApproaches;
302 // find basic airport location info from airport database
303 const FGAirport *fgFindAirportID( const std::string& id);
305 // get airport elevation
306 double fgGetAirportElev( const std::string& id );
308 #endif // _FG_SIMPLE_HXX