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>
35 #include <Navaids/positioned.hxx>
38 class FGAirportDynamics;
44 namespace flightgear {
51 typedef SGSharedPtr<Waypt> WayptRef;
52 typedef std::vector<WayptRef> WayptVec;
54 typedef std::vector<CommStation*> CommStationList;
59 /***************************************************************************************
61 **************************************************************************************/
62 class FGAirport : public FGPositioned
65 FGAirport(PositionedID aGuid, const std::string& id, const SGGeod& location,
66 const std::string& name, bool has_metar, Type aType);
69 const std::string& getId() const { return ident(); }
70 const std::string& getName() const { return _name; }
71 double getLongitude() const { return longitude(); }
73 double getLatitude() const { return latitude(); }
75 double getElevation() const { return elevation(); }
76 bool getMetar() const { return _has_metar; }
77 bool isAirport() const;
78 bool isSeaport() const;
79 bool isHeliport() const;
81 static bool isAirportType(FGPositioned* pos);
83 virtual const std::string& name() const
87 * reload the ILS data from XML if required.
88 * @result true if the data was refreshed, false if no data was loaded
89 * or previously cached data is still correct.
91 bool validateILSData();
93 SGGeod getTowerLocation() const;
95 void setMetar(bool value) { _has_metar = value; }
97 FGRunway* getActiveRunwayForUsage() const;
99 FGAirportDynamics *getDynamics();
101 unsigned int numRunways() const;
102 FGRunway* getRunwayByIndex(unsigned int aIndex) const;
104 bool hasRunwayWithIdent(const std::string& aIdent) const;
105 FGRunway* getRunwayByIdent(const std::string& aIdent) const;
106 FGRunway* findBestRunwayForHeading(double aHeading) const;
109 * return the most likely target runway based on a position.
110 * Specifically, return the runway for which the course from aPos
111 * to the runway end, mostly closely matches the runway heading.
112 * This is a good approximation of which runway the position is on or
115 FGRunway* findBestRunwayForPos(const SGGeod& aPos) const;
118 * Useful predicate for FMS/GPS/NAV displays and similar - check if this
119 * aiport has a hard-surfaced runway of at least the specified length.
121 bool hasHardRunwayOfLengthFt(double aLengthFt) const;
123 unsigned int numTaxiways() const;
124 FGTaxiway* getTaxiwayByIndex(unsigned int aIndex) const;
126 unsigned int numPavements() const;
127 FGPavement* getPavementByIndex(unsigned int aIndex) const;
129 class AirportFilter : public Filter
132 virtual bool pass(FGPositioned* aPos) const {
133 return passAirport(static_cast<FGAirport*>(aPos));
136 virtual Type minType() const {
140 virtual Type maxType() const {
144 virtual bool passAirport(FGAirport* aApt) const {
150 * Filter which passes heliports and seaports in addition to airports
152 class PortsFilter : public AirportFilter
155 virtual Type maxType() const {
160 class HardSurfaceFilter : public AirportFilter
163 HardSurfaceFilter(double minLengthFt = -1);
165 virtual bool passAirport(FGAirport* aApt) const;
172 void setProcedures(const std::vector<flightgear::SID*>& aSids,
173 const std::vector<flightgear::STAR*>& aStars,
174 const std::vector<flightgear::Approach*>& aApproaches);
176 void addSID(flightgear::SID* aSid);
177 void addSTAR(flightgear::STAR* aStar);
178 void addApproach(flightgear::Approach* aApp);
180 unsigned int numSIDs() const;
181 flightgear::SID* getSIDByIndex(unsigned int aIndex) const;
182 flightgear::SID* findSIDWithIdent(const std::string& aIdent) const;
184 unsigned int numSTARs() const;
185 flightgear::STAR* getSTARByIndex(unsigned int aIndex) const;
186 flightgear::STAR* findSTARWithIdent(const std::string& aIdent) const;
188 unsigned int numApproaches() const;
189 flightgear::Approach* getApproachByIndex(unsigned int aIndex) const;
190 flightgear::Approach* findApproachWithIdent(const std::string& aIdent) const;
193 * Syntactic wrapper around FGPositioned::findClosest - find the closest
194 * match for filter, and return it cast to FGAirport. The default filter
195 * passes airports, but not seaports or heliports
197 static FGAirport* findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
200 * Helper to look up an FGAirport instance by unique ident. Throws an
201 * exception if the airport could not be found - so callers can assume
202 * the result is non-NULL.
204 static FGAirport* getByIdent(const std::string& aIdent);
207 * Helper to look up an FGAirport instance by unique ident. Returns NULL
208 * if the airport could not be found.
210 static FGAirport* findByIdent(const std::string& aIdent);
213 * Specialised helper to implement the AirportList dialog. Performs a
214 * case-insensitive search on airport names and ICAO codes, and returns
215 * matches in a format suitable for use by a puaList.
217 static char** searchNamesAndIdents(const std::string& aFilter);
219 flightgear::CommStationList commStationsOfType(FGPositioned::Type aTy) const;
221 flightgear::CommStationList commStations() const;
224 FGAirport operator=(FGAirport &other);
225 FGAirport(const FGAirport&);
228 * helper to read airport data from the scenery XML files.
230 void loadSceneryDefinitions() const;
233 * Helpers to process property data loaded from an ICAO.threshold.xml file
235 void readThresholdData(SGPropertyNode* aRoot);
236 void processThreshold(SGPropertyNode* aThreshold);
238 void readILSData(SGPropertyNode* aRoot);
240 void validateTowerData() const;
243 * Helper to parse property data loaded from an ICAO.twr.xml filke
245 void readTowerData(SGPropertyNode* aRoot);
249 FGAirportDynamics *_dynamics;
251 void loadRunways() const;
252 void loadTaxiways() const;
253 void loadProcedures() const;
255 mutable bool mTowerDataLoaded;
256 mutable bool mRunwaysLoaded;
257 mutable bool mTaxiwaysLoaded;
258 mutable bool mProceduresLoaded;
261 mutable PositionedIDVec mRunways;
262 mutable PositionedIDVec mTaxiways;
263 PositionedIDVec mPavements;
265 std::vector<flightgear::SID*> mSIDs;
266 std::vector<flightgear::STAR*> mSTARs;
267 std::vector<flightgear::Approach*> mApproaches;
270 // find basic airport location info from airport database
271 const FGAirport *fgFindAirportID( const std::string& id);
273 // get airport elevation
274 double fgGetAirportElev( const std::string& id );
276 #endif // _FG_SIMPLE_HXX