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>
39 class FGAirportDynamics;
47 namespace flightgear {
54 typedef SGSharedPtr<Waypt> WayptRef;
55 typedef std::vector<WayptRef> WayptVec;
57 typedef std::vector<CommStation*> CommStationList;
58 typedef std::map<std::string, FGAirport*> AirportCache;
61 typedef std::vector<FGRunway*> FGRunwayList;
64 /***************************************************************************************
66 **************************************************************************************/
67 class FGAirport : public FGPositioned
70 FGAirport(PositionedID aGuid, const std::string& id, const SGGeod& location,
71 const std::string& name, bool has_metar, Type aType);
74 const std::string& getId() const { return ident(); }
75 const std::string& getName() const { return _name; }
76 double getLongitude() const { return longitude(); }
78 double getLatitude() const { return latitude(); }
80 double getElevation() const { return elevation(); }
81 bool getMetar() const { return _has_metar; }
82 bool isAirport() const;
83 bool isSeaport() const;
84 bool isHeliport() const;
86 static bool isAirportType(FGPositioned* pos);
88 virtual const std::string& name() const
92 * reload the ILS data from XML if required.
93 * @result true if the data was refreshed, false if no data was loaded
94 * or previously cached data is still correct.
96 bool validateILSData();
98 SGGeod getTowerLocation() const;
100 void setMetar(bool value) { _has_metar = value; }
102 FGRunway* getActiveRunwayForUsage() const;
104 FGAirportDynamics *getDynamics();
106 unsigned int numRunways() const;
107 unsigned int numHelipads() const;
108 FGRunway* getRunwayByIndex(unsigned int aIndex) const;
109 FGHelipad* getHelipadByIndex(unsigned int aIndex) const;
111 bool hasRunwayWithIdent(const std::string& aIdent) const;
112 bool hasHelipadWithIdent(const std::string& aIdent) const;
113 FGRunway* getRunwayByIdent(const std::string& aIdent) const;
114 FGHelipad* getHelipadByIdent(const std::string& aIdent) const;
115 FGRunway* findBestRunwayForHeading(double aHeading) const;
118 * return the most likely target runway based on a position.
119 * Specifically, return the runway for which the course from aPos
120 * to the runway end, mostly closely matches the runway heading.
121 * This is a good approximation of which runway the position is on or
124 FGRunway* findBestRunwayForPos(const SGGeod& aPos) const;
127 * Retrieve all runways at the airport, but excluding the reciprocal
128 * runways. For example at KSFO this might return 1L, 1R, 28L and 28R,
129 * but would not then include 19L/R or 10L/R.
131 * Exactly which runways you get, is undefined (i.e, dont assumes it's
132 * runways with heading < 180 degrees) - it depends on order in apt.dat.
134 * This is useful for code that wants to process each piece of tarmac at
135 * an airport *once*, not *twice* - eg mapping and nav-display code.
137 FGRunwayList getRunwaysWithoutReciprocals() 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 FGTaxiway* getTaxiwayByIndex(unsigned int aIndex) const;
148 unsigned int numPavements() const;
149 FGPavement* getPavementByIndex(unsigned int aIndex) const;
151 class AirportFilter : public Filter
154 virtual bool pass(FGPositioned* aPos) const {
155 return passAirport(static_cast<FGAirport*>(aPos));
158 virtual Type minType() const {
162 virtual Type maxType() const {
166 virtual bool passAirport(FGAirport* aApt) const {
172 * Filter which passes heliports and seaports in addition to airports
174 class PortsFilter : public AirportFilter
177 virtual Type maxType() const {
182 class HardSurfaceFilter : public AirportFilter
185 HardSurfaceFilter(double minLengthFt = -1);
187 virtual bool passAirport(FGAirport* aApt) const;
194 void setProcedures(const std::vector<flightgear::SID*>& aSids,
195 const std::vector<flightgear::STAR*>& aStars,
196 const std::vector<flightgear::Approach*>& aApproaches);
198 void addSID(flightgear::SID* aSid);
199 void addSTAR(flightgear::STAR* aStar);
200 void addApproach(flightgear::Approach* aApp);
202 unsigned int numSIDs() const;
203 flightgear::SID* getSIDByIndex(unsigned int aIndex) const;
204 flightgear::SID* findSIDWithIdent(const std::string& aIdent) const;
206 unsigned int numSTARs() const;
207 flightgear::STAR* getSTARByIndex(unsigned int aIndex) const;
208 flightgear::STAR* findSTARWithIdent(const std::string& aIdent) const;
210 unsigned int numApproaches() const;
211 flightgear::Approach* getApproachByIndex(unsigned int aIndex) const;
212 flightgear::Approach* findApproachWithIdent(const std::string& aIdent) const;
215 * Syntactic wrapper around FGPositioned::findClosest - find the closest
216 * match for filter, and return it cast to FGAirport. The default filter
217 * passes airports, but not seaports or heliports
219 static FGAirport* findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
222 * Helper to look up an FGAirport instance by unique ident. Throws an
223 * exception if the airport could not be found - so callers can assume
224 * the result is non-NULL.
226 static FGAirport* getByIdent(const std::string& aIdent);
229 * Helper to look up an FGAirport instance by unique ident. Returns NULL
230 * if the airport could not be found.
232 static FGAirport* findByIdent(const std::string& aIdent);
235 * Specialised helper to implement the AirportList dialog. Performs a
236 * case-insensitive search on airport names and ICAO codes, and returns
237 * matches in a format suitable for use by a puaList.
239 static char** searchNamesAndIdents(const std::string& aFilter);
241 flightgear::CommStationList commStationsOfType(FGPositioned::Type aTy) const;
243 flightgear::CommStationList commStations() const;
245 static flightgear::AirportCache airportCache;
248 FGAirport operator=(FGAirport &other);
249 FGAirport(const FGAirport&);
252 * helper to read airport data from the scenery XML files.
254 void loadSceneryDefinitions() const;
257 * Helpers to process property data loaded from an ICAO.threshold.xml file
259 void readThresholdData(SGPropertyNode* aRoot);
260 void processThreshold(SGPropertyNode* aThreshold);
262 void readILSData(SGPropertyNode* aRoot);
264 void validateTowerData() const;
267 * Helper to parse property data loaded from an ICAO.twr.xml file
269 void readTowerData(SGPropertyNode* aRoot);
273 FGAirportDynamics *_dynamics;
275 void loadRunways() const;
276 void loadHelipads() const;
277 void loadTaxiways() const;
278 void loadProcedures() const;
280 mutable bool mTowerDataLoaded;
281 mutable bool mRunwaysLoaded;
282 mutable bool mHelipadsLoaded;
283 mutable bool mTaxiwaysLoaded;
284 mutable bool mProceduresLoaded;
287 mutable PositionedIDVec mRunways;
288 mutable PositionedIDVec mHelipads;
289 mutable PositionedIDVec mTaxiways;
290 PositionedIDVec mPavements;
292 typedef SGSharedPtr<flightgear::SID> SIDRef;
293 typedef SGSharedPtr<flightgear::STAR> STARRef;
294 typedef SGSharedPtr<flightgear::Approach> ApproachRef;
296 std::vector<SIDRef> mSIDs;
297 std::vector<STARRef> mSTARs;
298 std::vector<ApproachRef> mApproaches;
301 // find basic airport location info from airport database
302 const FGAirport *fgFindAirportID( const std::string& id);
304 // get airport elevation
305 double fgGetAirportElev( const std::string& id );
307 #endif // _FG_SIMPLE_HXX