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;
63 /***************************************************************************************
65 **************************************************************************************/
66 class FGAirport : public FGPositioned
69 FGAirport(PositionedID aGuid, const std::string& id, const SGGeod& location,
70 const std::string& name, bool has_metar, Type aType);
73 const std::string& getId() const { return ident(); }
74 const std::string& getName() const { return _name; }
75 double getLongitude() const { return longitude(); }
77 double getLatitude() const { return latitude(); }
79 double getElevation() const { return elevation(); }
80 bool getMetar() const { return _has_metar; }
81 bool isAirport() const;
82 bool isSeaport() const;
83 bool isHeliport() const;
85 static bool isAirportType(FGPositioned* pos);
87 virtual const std::string& name() const
91 * reload the ILS data from XML if required.
92 * @result true if the data was refreshed, false if no data was loaded
93 * or previously cached data is still correct.
95 bool validateILSData();
97 SGGeod getTowerLocation() const;
99 void setMetar(bool value) { _has_metar = value; }
101 FGRunway* getActiveRunwayForUsage() const;
103 FGAirportDynamics *getDynamics();
105 unsigned int numRunways() const;
106 unsigned int numHelipads() const;
107 FGRunway* getRunwayByIndex(unsigned int aIndex) const;
108 FGHelipad* getHelipadByIndex(unsigned int aIndex) const;
110 bool hasRunwayWithIdent(const std::string& aIdent) const;
111 bool hasHelipadWithIdent(const std::string& aIdent) const;
112 FGRunway* getRunwayByIdent(const std::string& aIdent) const;
113 FGHelipad* getHelipadByIdent(const std::string& aIdent) const;
114 FGRunway* findBestRunwayForHeading(double aHeading) const;
117 * return the most likely target runway based on a position.
118 * Specifically, return the runway for which the course from aPos
119 * to the runway end, mostly closely matches the runway heading.
120 * This is a good approximation of which runway the position is on or
123 FGRunway* findBestRunwayForPos(const SGGeod& aPos) const;
126 * Useful predicate for FMS/GPS/NAV displays and similar - check if this
127 * aiport has a hard-surfaced runway of at least the specified length.
129 bool hasHardRunwayOfLengthFt(double aLengthFt) const;
131 unsigned int numTaxiways() const;
132 FGTaxiway* getTaxiwayByIndex(unsigned int aIndex) const;
134 unsigned int numPavements() const;
135 FGPavement* getPavementByIndex(unsigned int aIndex) const;
137 class AirportFilter : public Filter
140 virtual bool pass(FGPositioned* aPos) const {
141 return passAirport(static_cast<FGAirport*>(aPos));
144 virtual Type minType() const {
148 virtual Type maxType() const {
152 virtual bool passAirport(FGAirport* aApt) const {
158 * Filter which passes heliports and seaports in addition to airports
160 class PortsFilter : public AirportFilter
163 virtual Type maxType() const {
168 class HardSurfaceFilter : public AirportFilter
171 HardSurfaceFilter(double minLengthFt = -1);
173 virtual bool passAirport(FGAirport* aApt) const;
180 void setProcedures(const std::vector<flightgear::SID*>& aSids,
181 const std::vector<flightgear::STAR*>& aStars,
182 const std::vector<flightgear::Approach*>& aApproaches);
184 void addSID(flightgear::SID* aSid);
185 void addSTAR(flightgear::STAR* aStar);
186 void addApproach(flightgear::Approach* aApp);
188 unsigned int numSIDs() const;
189 flightgear::SID* getSIDByIndex(unsigned int aIndex) const;
190 flightgear::SID* findSIDWithIdent(const std::string& aIdent) const;
192 unsigned int numSTARs() const;
193 flightgear::STAR* getSTARByIndex(unsigned int aIndex) const;
194 flightgear::STAR* findSTARWithIdent(const std::string& aIdent) const;
196 unsigned int numApproaches() const;
197 flightgear::Approach* getApproachByIndex(unsigned int aIndex) const;
198 flightgear::Approach* findApproachWithIdent(const std::string& aIdent) const;
201 * Syntactic wrapper around FGPositioned::findClosest - find the closest
202 * match for filter, and return it cast to FGAirport. The default filter
203 * passes airports, but not seaports or heliports
205 static FGAirport* findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
208 * Helper to look up an FGAirport instance by unique ident. Throws an
209 * exception if the airport could not be found - so callers can assume
210 * the result is non-NULL.
212 static FGAirport* getByIdent(const std::string& aIdent);
215 * Helper to look up an FGAirport instance by unique ident. Returns NULL
216 * if the airport could not be found.
218 static FGAirport* findByIdent(const std::string& aIdent);
221 * Specialised helper to implement the AirportList dialog. Performs a
222 * case-insensitive search on airport names and ICAO codes, and returns
223 * matches in a format suitable for use by a puaList.
225 static char** searchNamesAndIdents(const std::string& aFilter);
227 flightgear::CommStationList commStationsOfType(FGPositioned::Type aTy) const;
229 flightgear::CommStationList commStations() const;
231 static flightgear::AirportCache airportCache;
234 FGAirport operator=(FGAirport &other);
235 FGAirport(const FGAirport&);
238 * helper to read airport data from the scenery XML files.
240 void loadSceneryDefinitions() const;
243 * Helpers to process property data loaded from an ICAO.threshold.xml file
245 void readThresholdData(SGPropertyNode* aRoot);
246 void processThreshold(SGPropertyNode* aThreshold);
248 void readILSData(SGPropertyNode* aRoot);
250 void validateTowerData() const;
253 * Helper to parse property data loaded from an ICAO.twr.xml file
255 void readTowerData(SGPropertyNode* aRoot);
259 FGAirportDynamics *_dynamics;
261 void loadRunways() const;
262 void loadHelipads() const;
263 void loadTaxiways() const;
264 void loadProcedures() const;
266 mutable bool mTowerDataLoaded;
267 mutable bool mRunwaysLoaded;
268 mutable bool mHelipadsLoaded;
269 mutable bool mTaxiwaysLoaded;
270 mutable bool mProceduresLoaded;
273 mutable PositionedIDVec mRunways;
274 mutable PositionedIDVec mHelipads;
275 mutable PositionedIDVec mTaxiways;
276 PositionedIDVec mPavements;
278 typedef SGSharedPtr<flightgear::SID> SIDRef;
279 typedef SGSharedPtr<flightgear::STAR> STARRef;
280 typedef SGSharedPtr<flightgear::Approach> ApproachRef;
282 std::vector<SIDRef> mSIDs;
283 std::vector<STARRef> mSTARs;
284 std::vector<ApproachRef> mApproaches;
287 // find basic airport location info from airport database
288 const FGAirport *fgFindAirportID( const std::string& id);
290 // get airport elevation
291 double fgGetAirportElev( const std::string& id );
293 #endif // _FG_SIMPLE_HXX