1 // simple.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 FGRunway* getRunwayByIdent(const std::string& aIdent) const;
112 FGRunway* findBestRunwayForHeading(double aHeading) 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 FGRunway* findBestRunwayForPos(const SGGeod& aPos) const;
124 * Useful predicate for FMS/GPS/NAV displays and similar - check if this
125 * aiport has a hard-surfaced runway of at least the specified length.
127 bool hasHardRunwayOfLengthFt(double aLengthFt) const;
129 unsigned int numTaxiways() const;
130 FGTaxiway* getTaxiwayByIndex(unsigned int aIndex) const;
132 unsigned int numPavements() const;
133 FGPavement* getPavementByIndex(unsigned int aIndex) const;
135 class AirportFilter : public Filter
138 virtual bool pass(FGPositioned* aPos) const {
139 return passAirport(static_cast<FGAirport*>(aPos));
142 virtual Type minType() const {
146 virtual Type maxType() const {
150 virtual bool passAirport(FGAirport* aApt) const {
156 * Filter which passes heliports and seaports in addition to airports
158 class PortsFilter : public AirportFilter
161 virtual Type maxType() const {
166 class HardSurfaceFilter : public AirportFilter
169 HardSurfaceFilter(double minLengthFt = -1);
171 virtual bool passAirport(FGAirport* aApt) const;
178 void setProcedures(const std::vector<flightgear::SID*>& aSids,
179 const std::vector<flightgear::STAR*>& aStars,
180 const std::vector<flightgear::Approach*>& aApproaches);
182 void addSID(flightgear::SID* aSid);
183 void addSTAR(flightgear::STAR* aStar);
184 void addApproach(flightgear::Approach* aApp);
186 unsigned int numSIDs() const;
187 flightgear::SID* getSIDByIndex(unsigned int aIndex) const;
188 flightgear::SID* findSIDWithIdent(const std::string& aIdent) const;
190 unsigned int numSTARs() const;
191 flightgear::STAR* getSTARByIndex(unsigned int aIndex) const;
192 flightgear::STAR* findSTARWithIdent(const std::string& aIdent) const;
194 unsigned int numApproaches() const;
195 flightgear::Approach* getApproachByIndex(unsigned int aIndex) const;
196 flightgear::Approach* findApproachWithIdent(const std::string& aIdent) const;
199 * Syntactic wrapper around FGPositioned::findClosest - find the closest
200 * match for filter, and return it cast to FGAirport. The default filter
201 * passes airports, but not seaports or heliports
203 static FGAirport* findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
206 * Helper to look up an FGAirport instance by unique ident. Throws an
207 * exception if the airport could not be found - so callers can assume
208 * the result is non-NULL.
210 static FGAirport* getByIdent(const std::string& aIdent);
213 * Helper to look up an FGAirport instance by unique ident. Returns NULL
214 * if the airport could not be found.
216 static FGAirport* findByIdent(const std::string& aIdent);
219 * Specialised helper to implement the AirportList dialog. Performs a
220 * case-insensitive search on airport names and ICAO codes, and returns
221 * matches in a format suitable for use by a puaList.
223 static char** searchNamesAndIdents(const std::string& aFilter);
225 flightgear::CommStationList commStationsOfType(FGPositioned::Type aTy) const;
227 flightgear::CommStationList commStations() const;
229 static flightgear::AirportCache airportCache;
232 FGAirport operator=(FGAirport &other);
233 FGAirport(const FGAirport&);
236 * helper to read airport data from the scenery XML files.
238 void loadSceneryDefinitions() const;
241 * Helpers to process property data loaded from an ICAO.threshold.xml file
243 void readThresholdData(SGPropertyNode* aRoot);
244 void processThreshold(SGPropertyNode* aThreshold);
246 void readILSData(SGPropertyNode* aRoot);
248 void validateTowerData() const;
251 * Helper to parse property data loaded from an ICAO.twr.xml file
253 void readTowerData(SGPropertyNode* aRoot);
257 FGAirportDynamics *_dynamics;
259 void loadRunways() const;
260 void loadHelipads() const;
261 void loadTaxiways() const;
262 void loadProcedures() const;
264 mutable bool mTowerDataLoaded;
265 mutable bool mRunwaysLoaded;
266 mutable bool mHelipadsLoaded;
267 mutable bool mTaxiwaysLoaded;
268 mutable bool mProceduresLoaded;
271 mutable PositionedIDVec mRunways;
272 mutable PositionedIDVec mHelipads;
273 mutable PositionedIDVec mTaxiways;
274 PositionedIDVec mPavements;
276 typedef SGSharedPtr<flightgear::SID> SIDRef;
277 typedef SGSharedPtr<flightgear::STAR> STARRef;
278 typedef SGSharedPtr<flightgear::Approach> ApproachRef;
280 std::vector<SIDRef> mSIDs;
281 std::vector<STARRef> mSTARs;
282 std::vector<ApproachRef> mApproaches;
285 // find basic airport location info from airport database
286 const FGAirport *fgFindAirportID( const std::string& id);
288 // get airport elevation
289 double fgGetAirportElev( const std::string& id );
291 #endif // _FG_SIMPLE_HXX