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 <Navaids/procedure.hxx>
39 #include "airports_fwd.hxx"
40 #include "runways.hxx"
42 /***************************************************************************************
44 **************************************************************************************/
45 class FGAirport : public FGPositioned
48 FGAirport(PositionedID aGuid, const std::string& id, const SGGeod& location,
49 const std::string& name, bool has_metar, Type aType);
52 const std::string& getId() const { return ident(); }
53 const std::string& getName() const { return _name; }
54 std::string toString() const { return "an airport " + ident(); }
56 double getLongitude() const { return longitude(); }
58 double getLatitude() const { return latitude(); }
60 double getElevation() const { return elevation(); }
61 bool getMetar() const { return _has_metar; }
62 bool isAirport() const;
63 bool isSeaport() const;
64 bool isHeliport() const;
66 static bool isAirportType(FGPositioned* pos);
68 virtual const std::string& name() const
72 * reload the ILS data from XML if required.
74 void validateILSData();
76 SGGeod getTowerLocation() const;
78 void setMetar(bool value) { _has_metar = value; }
80 FGRunwayRef getActiveRunwayForUsage() const;
82 FGAirportDynamics *getDynamics();
84 unsigned int numRunways() const;
85 unsigned int numHelipads() const;
86 FGRunwayRef getRunwayByIndex(unsigned int aIndex) const;
87 FGHelipadRef getHelipadByIndex(unsigned int aIndex) const;
88 FGRunwayMap getRunwayMap() const;
89 FGHelipadMap getHelipadMap() const;
91 bool hasRunwayWithIdent(const std::string& aIdent) const;
92 bool hasHelipadWithIdent(const std::string& aIdent) const;
93 FGRunwayRef getRunwayByIdent(const std::string& aIdent) const;
94 FGHelipadRef getHelipadByIdent(const std::string& aIdent) const;
96 struct FindBestRunwayForHeadingParams {
97 FindBestRunwayForHeadingParams() {
106 double surfaceWeight;
107 double deviationWeight;
110 FGRunwayRef findBestRunwayForHeading(double aHeading, struct FindBestRunwayForHeadingParams * parms = NULL ) const;
113 * return the most likely target runway based on a position.
114 * Specifically, return the runway for which the course from aPos
115 * to the runway end, mostly closely matches the runway heading.
116 * This is a good approximation of which runway the position is on or
119 FGRunwayRef findBestRunwayForPos(const SGGeod& aPos) const;
122 * Retrieve all runways at the airport, but excluding the reciprocal
123 * runways. For example at KSFO this might return 1L, 1R, 28L and 28R,
124 * but would not then include 19L/R or 10L/R.
126 * Exactly which runways you get, is undefined (i.e, dont assumes it's
127 * runways with heading < 180 degrees) - it depends on order in apt.dat.
129 * This is useful for code that wants to process each piece of tarmac at
130 * an airport *once*, not *twice* - eg mapping and nav-display code.
132 FGRunwayList getRunwaysWithoutReciprocals() const;
135 * Retrieve all runways at the airport
137 FGRunwayList getRunways() const;
140 * Useful predicate for FMS/GPS/NAV displays and similar - check if this
141 * aiport has a hard-surfaced runway of at least the specified length.
143 bool hasHardRunwayOfLengthFt(double aLengthFt) const;
145 unsigned int numTaxiways() const;
146 FGTaxiwayRef getTaxiwayByIndex(unsigned int aIndex) const;
147 FGTaxiwayList getTaxiways() const;
149 unsigned int numPavements() const;
150 FGPavementRef getPavementByIndex(unsigned int aIndex) const;
151 FGPavementList getPavements() const;
153 class AirportFilter : public Filter
156 virtual bool pass(FGPositioned* aPos) const {
157 return passAirport(static_cast<FGAirport*>(aPos));
160 virtual Type minType() const {
164 virtual Type maxType() const {
168 virtual bool passAirport(FGAirport* aApt) const {
174 * Filter which passes heliports and seaports in addition to airports
176 class PortsFilter : public AirportFilter
179 virtual Type maxType() const {
184 class HardSurfaceFilter : public AirportFilter
187 HardSurfaceFilter(double minLengthFt = -1);
189 virtual bool passAirport(FGAirport* aApt) const;
196 * Filter which passes specified port type and in case of airport checks
197 * if a runway larger the /sim/navdb/min-runway-lenght-ft exists.
199 class TypeRunwayFilter:
206 * Construct from string containing type (airport, seaport or heliport)
208 bool fromTypeString(const std::string& type);
210 virtual FGPositioned::Type minType() const { return _type; }
211 virtual FGPositioned::Type maxType() const { return _type; }
212 virtual bool pass(FGPositioned* pos) const;
215 FGPositioned::Type _type;
216 double _min_runway_length_ft;
220 void setProcedures(const std::vector<flightgear::SID*>& aSids,
221 const std::vector<flightgear::STAR*>& aStars,
222 const std::vector<flightgear::Approach*>& aApproaches);
224 void addSID(flightgear::SID* aSid);
225 void addSTAR(flightgear::STAR* aStar);
226 void addApproach(flightgear::Approach* aApp);
228 unsigned int numSIDs() const;
229 flightgear::SID* getSIDByIndex(unsigned int aIndex) const;
230 flightgear::SID* findSIDWithIdent(const std::string& aIdent) const;
231 flightgear::SIDList getSIDs() const;
233 unsigned int numSTARs() const;
234 flightgear::STAR* getSTARByIndex(unsigned int aIndex) const;
235 flightgear::STAR* findSTARWithIdent(const std::string& aIdent) const;
236 flightgear::STARList getSTARs() const;
238 unsigned int numApproaches() const;
239 flightgear::Approach* getApproachByIndex(unsigned int aIndex) const;
240 flightgear::Approach* findApproachWithIdent(const std::string& aIdent) const;
241 flightgear::ApproachList getApproaches
243 flightgear::ProcedureType type = flightgear::PROCEDURE_INVALID
247 * Syntactic wrapper around FGPositioned::findClosest - find the closest
248 * match for filter, and return it cast to FGAirport. The default filter
249 * passes airports, but not seaports or heliports
251 static FGAirportRef findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
254 * Helper to look up an FGAirport instance by unique ident. Throws an
255 * exception if the airport could not be found - so callers can assume
256 * the result is non-NULL.
258 static FGAirportRef getByIdent(const std::string& aIdent);
261 * Helper to look up an FGAirport instance by unique ident. Returns NULL
262 * if the airport could not be found.
264 static FGAirportRef findByIdent(const std::string& aIdent);
267 * Specialised helper to implement the AirportList dialog. Performs a
268 * case-insensitive search on airport names and ICAO codes, and returns
269 * matches in a format suitable for use by a puaList.
271 static char** searchNamesAndIdents(const std::string& aFilter);
275 * Sort an FGPositionedList of airports by size (number of runways + length)
276 * this is meant to prioritise more important airports.
278 static void sortBySize(FGPositionedList&);
280 flightgear::CommStationList commStationsOfType(FGPositioned::Type aTy) const;
282 flightgear::CommStationList commStations() const;
284 static flightgear::AirportCache airportCache;
287 FGAirport operator=(FGAirport &other);
288 FGAirport(const FGAirport&);
291 * helper to read airport data from the scenery XML files.
293 void loadSceneryDefinitions() const;
296 * Helpers to process property data loaded from an ICAO.threshold.xml file
298 void readThresholdData(SGPropertyNode* aRoot);
299 void processThreshold(SGPropertyNode* aThreshold);
301 void readILSData(SGPropertyNode* aRoot);
303 void validateTowerData() const;
306 * Helper to parse property data loaded from an ICAO.twr.xml file
308 void readTowerData(SGPropertyNode* aRoot);
310 PositionedIDVec itemsOfType(FGPositioned::Type ty) const;
314 FGAirportDynamics *_dynamics;
316 void loadRunways() const;
317 void loadHelipads() const;
318 void loadTaxiways() const;
319 void loadProcedures() const;
321 mutable bool mTowerDataLoaded;
322 mutable SGGeod mTowerPosition;
324 mutable bool mRunwaysLoaded;
325 mutable bool mHelipadsLoaded;
326 mutable bool mTaxiwaysLoaded;
327 mutable bool mProceduresLoaded;
329 mutable bool mThresholdDataLoaded;
332 mutable std::vector<FGRunwayRef> mRunways;
334 mutable PositionedIDVec mHelipads;
335 mutable PositionedIDVec mTaxiways;
336 PositionedIDVec mPavements;
338 typedef SGSharedPtr<flightgear::SID> SIDRef;
339 typedef SGSharedPtr<flightgear::STAR> STARRef;
340 typedef SGSharedPtr<flightgear::Approach> ApproachRef;
342 std::vector<SIDRef> mSIDs;
343 std::vector<STARRef> mSTARs;
344 std::vector<ApproachRef> mApproaches;
347 // find basic airport location info from airport database
348 const FGAirport *fgFindAirportID( const std::string& id);
350 // get airport elevation
351 double fgGetAirportElev( const std::string& id );
353 #endif // _FG_SIMPLE_HXX