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 double getLongitude() const { return longitude(); }
56 double getLatitude() const { return latitude(); }
58 double getElevation() const { return elevation(); }
59 bool getMetar() const { return _has_metar; }
60 bool isAirport() const;
61 bool isSeaport() const;
62 bool isHeliport() const;
64 static bool isAirportType(FGPositioned* pos);
66 virtual const std::string& name() const
70 * reload the ILS data from XML if required.
71 * @result true if the data was refreshed, false if no data was loaded
72 * or previously cached data is still correct.
74 bool validateILSData();
76 SGGeod getTowerLocation() const;
78 void setMetar(bool value) { _has_metar = value; }
80 FGRunway* getActiveRunwayForUsage() const;
82 FGAirportDynamics *getDynamics();
84 unsigned int numRunways() const;
85 unsigned int numHelipads() const;
86 FGRunway* getRunwayByIndex(unsigned int aIndex) const;
87 FGHelipad* 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 FGRunway* getRunwayByIdent(const std::string& aIdent) const;
94 FGHelipad* getHelipadByIdent(const std::string& aIdent) const;
95 FGRunway* findBestRunwayForHeading(double aHeading) const;
98 * return the most likely target runway based on a position.
99 * Specifically, return the runway for which the course from aPos
100 * to the runway end, mostly closely matches the runway heading.
101 * This is a good approximation of which runway the position is on or
104 FGRunway* findBestRunwayForPos(const SGGeod& aPos) const;
107 * Retrieve all runways at the airport, but excluding the reciprocal
108 * runways. For example at KSFO this might return 1L, 1R, 28L and 28R,
109 * but would not then include 19L/R or 10L/R.
111 * Exactly which runways you get, is undefined (i.e, dont assumes it's
112 * runways with heading < 180 degrees) - it depends on order in apt.dat.
114 * This is useful for code that wants to process each piece of tarmac at
115 * an airport *once*, not *twice* - eg mapping and nav-display code.
117 FGRunwayList getRunwaysWithoutReciprocals() const;
120 * Useful predicate for FMS/GPS/NAV displays and similar - check if this
121 * aiport has a hard-surfaced runway of at least the specified length.
123 bool hasHardRunwayOfLengthFt(double aLengthFt) const;
125 unsigned int numTaxiways() const;
126 FGTaxiway* getTaxiwayByIndex(unsigned int aIndex) const;
127 FGTaxiwayList getTaxiways() const;
129 unsigned int numPavements() const;
130 FGPavement* getPavementByIndex(unsigned int aIndex) const;
131 FGPavementList getPavements() const;
133 class AirportFilter : public Filter
136 virtual bool pass(FGPositioned* aPos) const {
137 return passAirport(static_cast<FGAirport*>(aPos));
140 virtual Type minType() const {
144 virtual Type maxType() const {
148 virtual bool passAirport(FGAirport* aApt) const {
154 * Filter which passes heliports and seaports in addition to airports
156 class PortsFilter : public AirportFilter
159 virtual Type maxType() const {
164 class HardSurfaceFilter : public AirportFilter
167 HardSurfaceFilter(double minLengthFt = -1);
169 virtual bool passAirport(FGAirport* aApt) const;
176 void setProcedures(const std::vector<flightgear::SID*>& aSids,
177 const std::vector<flightgear::STAR*>& aStars,
178 const std::vector<flightgear::Approach*>& aApproaches);
180 void addSID(flightgear::SID* aSid);
181 void addSTAR(flightgear::STAR* aStar);
182 void addApproach(flightgear::Approach* aApp);
184 unsigned int numSIDs() const;
185 flightgear::SID* getSIDByIndex(unsigned int aIndex) const;
186 flightgear::SID* findSIDWithIdent(const std::string& aIdent) const;
187 flightgear::SIDList getSIDs() const;
189 unsigned int numSTARs() const;
190 flightgear::STAR* getSTARByIndex(unsigned int aIndex) const;
191 flightgear::STAR* findSTARWithIdent(const std::string& aIdent) const;
192 flightgear::STARList getSTARs() const;
194 unsigned int numApproaches() const;
195 flightgear::Approach* getApproachByIndex(unsigned int aIndex) const;
196 flightgear::Approach* findApproachWithIdent(const std::string& aIdent) const;
197 flightgear::ApproachList getApproaches
199 flightgear::ProcedureType type = flightgear::PROCEDURE_INVALID
203 * Syntactic wrapper around FGPositioned::findClosest - find the closest
204 * match for filter, and return it cast to FGAirport. The default filter
205 * passes airports, but not seaports or heliports
207 static FGAirport* findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
210 * Helper to look up an FGAirport instance by unique ident. Throws an
211 * exception if the airport could not be found - so callers can assume
212 * the result is non-NULL.
214 static FGAirport* getByIdent(const std::string& aIdent);
217 * Helper to look up an FGAirport instance by unique ident. Returns NULL
218 * if the airport could not be found.
220 static FGAirport* findByIdent(const std::string& aIdent);
223 * Specialised helper to implement the AirportList dialog. Performs a
224 * case-insensitive search on airport names and ICAO codes, and returns
225 * matches in a format suitable for use by a puaList.
227 static char** searchNamesAndIdents(const std::string& aFilter);
229 flightgear::CommStationList commStationsOfType(FGPositioned::Type aTy) const;
231 flightgear::CommStationList commStations() const;
233 static flightgear::AirportCache airportCache;
236 FGAirport operator=(FGAirport &other);
237 FGAirport(const FGAirport&);
240 * helper to read airport data from the scenery XML files.
242 void loadSceneryDefinitions() const;
245 * Helpers to process property data loaded from an ICAO.threshold.xml file
247 void readThresholdData(SGPropertyNode* aRoot);
248 void processThreshold(SGPropertyNode* aThreshold);
250 void readILSData(SGPropertyNode* aRoot);
252 void validateTowerData() const;
255 * Helper to parse property data loaded from an ICAO.twr.xml file
257 void readTowerData(SGPropertyNode* aRoot);
261 FGAirportDynamics *_dynamics;
263 void loadRunways() const;
264 void loadHelipads() const;
265 void loadTaxiways() const;
266 void loadProcedures() const;
268 mutable bool mTowerDataLoaded;
269 mutable bool mRunwaysLoaded;
270 mutable bool mHelipadsLoaded;
271 mutable bool mTaxiwaysLoaded;
272 mutable bool mProceduresLoaded;
275 mutable PositionedIDVec mRunways;
276 mutable PositionedIDVec mHelipads;
277 mutable PositionedIDVec mTaxiways;
278 PositionedIDVec mPavements;
280 typedef SGSharedPtr<flightgear::SID> SIDRef;
281 typedef SGSharedPtr<flightgear::STAR> STARRef;
282 typedef SGSharedPtr<flightgear::Approach> ApproachRef;
284 std::vector<SIDRef> mSIDs;
285 std::vector<STARRef> mSTARs;
286 std::vector<ApproachRef> mApproaches;
289 // find basic airport location info from airport database
290 const FGAirport *fgFindAirportID( const std::string& id);
292 // get airport elevation
293 double fgGetAirportElev( const std::string& id );
295 #endif // _FG_SIMPLE_HXX