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.
73 * @result true if the data was refreshed, false if no data was loaded
74 * or previously cached data is still correct.
76 bool validateILSData();
78 SGGeod getTowerLocation() const;
80 void setMetar(bool value) { _has_metar = value; }
82 FGRunwayRef getActiveRunwayForUsage() const;
84 FGAirportDynamics *getDynamics();
86 unsigned int numRunways() const;
87 unsigned int numHelipads() const;
88 FGRunwayRef getRunwayByIndex(unsigned int aIndex) const;
89 FGHelipadRef getHelipadByIndex(unsigned int aIndex) const;
90 FGRunwayMap getRunwayMap() const;
91 FGHelipadMap getHelipadMap() const;
93 bool hasRunwayWithIdent(const std::string& aIdent) const;
94 bool hasHelipadWithIdent(const std::string& aIdent) const;
95 FGRunwayRef getRunwayByIdent(const std::string& aIdent) const;
96 FGHelipadRef getHelipadByIdent(const std::string& aIdent) const;
98 struct FindBestRunwayForHeadingParams {
99 FindBestRunwayForHeadingParams() {
108 double surfaceWeight;
109 double deviationWeight;
112 FGRunwayRef findBestRunwayForHeading(double aHeading, struct FindBestRunwayForHeadingParams * parms = NULL ) const;
115 * return the most likely target runway based on a position.
116 * Specifically, return the runway for which the course from aPos
117 * to the runway end, mostly closely matches the runway heading.
118 * This is a good approximation of which runway the position is on or
121 FGRunwayRef findBestRunwayForPos(const SGGeod& aPos) const;
124 * Retrieve all runways at the airport, but excluding the reciprocal
125 * runways. For example at KSFO this might return 1L, 1R, 28L and 28R,
126 * but would not then include 19L/R or 10L/R.
128 * Exactly which runways you get, is undefined (i.e, dont assumes it's
129 * runways with heading < 180 degrees) - it depends on order in apt.dat.
131 * This is useful for code that wants to process each piece of tarmac at
132 * an airport *once*, not *twice* - eg mapping and nav-display code.
134 FGRunwayList getRunwaysWithoutReciprocals() const;
137 * Useful predicate for FMS/GPS/NAV displays and similar - check if this
138 * aiport has a hard-surfaced runway of at least the specified length.
140 bool hasHardRunwayOfLengthFt(double aLengthFt) const;
142 unsigned int numTaxiways() const;
143 FGTaxiwayRef getTaxiwayByIndex(unsigned int aIndex) const;
144 FGTaxiwayList getTaxiways() const;
146 unsigned int numPavements() const;
147 FGPavementRef getPavementByIndex(unsigned int aIndex) const;
148 FGPavementList getPavements() const;
150 class AirportFilter : public Filter
153 virtual bool pass(FGPositioned* aPos) const {
154 return passAirport(static_cast<FGAirport*>(aPos));
157 virtual Type minType() const {
161 virtual Type maxType() const {
165 virtual bool passAirport(FGAirport* aApt) const {
171 * Filter which passes heliports and seaports in addition to airports
173 class PortsFilter : public AirportFilter
176 virtual Type maxType() const {
181 class HardSurfaceFilter : public AirportFilter
184 HardSurfaceFilter(double minLengthFt = -1);
186 virtual bool passAirport(FGAirport* aApt) const;
193 * Filter which passes specified port type and in case of airport checks
194 * if a runway larger the /sim/navdb/min-runway-lenght-ft exists.
196 class TypeRunwayFilter:
203 * Construct from string containing type (airport, seaport or heliport)
205 bool fromTypeString(const std::string& type);
207 virtual FGPositioned::Type minType() const { return _type; }
208 virtual FGPositioned::Type maxType() const { return _type; }
209 virtual bool pass(FGPositioned* pos) const;
212 FGPositioned::Type _type;
213 double _min_runway_length_ft;
217 void setProcedures(const std::vector<flightgear::SID*>& aSids,
218 const std::vector<flightgear::STAR*>& aStars,
219 const std::vector<flightgear::Approach*>& aApproaches);
221 void addSID(flightgear::SID* aSid);
222 void addSTAR(flightgear::STAR* aStar);
223 void addApproach(flightgear::Approach* aApp);
225 unsigned int numSIDs() const;
226 flightgear::SID* getSIDByIndex(unsigned int aIndex) const;
227 flightgear::SID* findSIDWithIdent(const std::string& aIdent) const;
228 flightgear::SIDList getSIDs() const;
230 unsigned int numSTARs() const;
231 flightgear::STAR* getSTARByIndex(unsigned int aIndex) const;
232 flightgear::STAR* findSTARWithIdent(const std::string& aIdent) const;
233 flightgear::STARList getSTARs() const;
235 unsigned int numApproaches() const;
236 flightgear::Approach* getApproachByIndex(unsigned int aIndex) const;
237 flightgear::Approach* findApproachWithIdent(const std::string& aIdent) const;
238 flightgear::ApproachList getApproaches
240 flightgear::ProcedureType type = flightgear::PROCEDURE_INVALID
244 * Syntactic wrapper around FGPositioned::findClosest - find the closest
245 * match for filter, and return it cast to FGAirport. The default filter
246 * passes airports, but not seaports or heliports
248 static FGAirportRef findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
251 * Helper to look up an FGAirport instance by unique ident. Throws an
252 * exception if the airport could not be found - so callers can assume
253 * the result is non-NULL.
255 static FGAirportRef getByIdent(const std::string& aIdent);
258 * Helper to look up an FGAirport instance by unique ident. Returns NULL
259 * if the airport could not be found.
261 static FGAirportRef findByIdent(const std::string& aIdent);
264 * Specialised helper to implement the AirportList dialog. Performs a
265 * case-insensitive search on airport names and ICAO codes, and returns
266 * matches in a format suitable for use by a puaList.
268 static char** searchNamesAndIdents(const std::string& aFilter);
272 * Sort an FGPositionedList of airports by size (number of runways + length)
273 * this is meant to prioritise more important airports.
275 static void sortBySize(FGPositionedList&);
277 flightgear::CommStationList commStationsOfType(FGPositioned::Type aTy) const;
279 flightgear::CommStationList commStations() const;
281 static flightgear::AirportCache airportCache;
284 FGAirport operator=(FGAirport &other);
285 FGAirport(const FGAirport&);
288 * helper to read airport data from the scenery XML files.
290 void loadSceneryDefinitions() const;
293 * Helpers to process property data loaded from an ICAO.threshold.xml file
295 void readThresholdData(SGPropertyNode* aRoot);
296 void processThreshold(SGPropertyNode* aThreshold);
298 void readILSData(SGPropertyNode* aRoot);
300 void validateTowerData() const;
303 * Helper to parse property data loaded from an ICAO.twr.xml file
305 void readTowerData(SGPropertyNode* aRoot);
309 FGAirportDynamics *_dynamics;
311 void loadRunways() const;
312 void loadHelipads() const;
313 void loadTaxiways() const;
314 void loadProcedures() const;
316 mutable bool mTowerDataLoaded;
317 mutable bool mRunwaysLoaded;
318 mutable bool mHelipadsLoaded;
319 mutable bool mTaxiwaysLoaded;
320 mutable bool mProceduresLoaded;
323 mutable PositionedIDVec mRunways;
324 mutable PositionedIDVec mHelipads;
325 mutable PositionedIDVec mTaxiways;
326 PositionedIDVec mPavements;
328 typedef SGSharedPtr<flightgear::SID> SIDRef;
329 typedef SGSharedPtr<flightgear::STAR> STARRef;
330 typedef SGSharedPtr<flightgear::Approach> ApproachRef;
332 std::vector<SIDRef> mSIDs;
333 std::vector<STARRef> mSTARs;
334 std::vector<ApproachRef> mApproaches;
337 // find basic airport location info from airport database
338 const FGAirport *fgFindAirportID( const std::string& id);
340 // get airport elevation
341 double fgGetAirportElev( const std::string& id );
343 #endif // _FG_SIMPLE_HXX