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 typedef SGSharedPtr<FGRunway> FGRunwayPtr;
45 typedef SGSharedPtr<FGTaxiway> FGTaxiwayPtr;
46 typedef SGSharedPtr<FGPavement> FGPavementPtr;
48 namespace flightgear {
55 typedef SGSharedPtr<Waypt> WayptRef;
56 typedef std::vector<WayptRef> WayptVec;
58 typedef std::vector<CommStation*> CommStationList;
63 /***************************************************************************************
65 **************************************************************************************/
66 class FGAirport : public FGPositioned
69 FGAirport(const std::string& id, const SGGeod& location, const SGGeod& tower,
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
90 const SGGeod& getTowerLocation() const { return _tower_location; }
92 void setMetar(bool value) { _has_metar = value; }
94 FGRunway* getActiveRunwayForUsage() const;
96 FGAirportDynamics *getDynamics();
98 unsigned int numRunways() const;
99 FGRunway* getRunwayByIndex(unsigned int aIndex) const;
101 bool hasRunwayWithIdent(const std::string& aIdent) const;
102 FGRunway* getRunwayByIdent(const std::string& aIdent) const;
103 FGRunway* findBestRunwayForHeading(double aHeading) const;
106 * return the most likely target runway based on a position.
107 * Specifically, return the runway for which the course from aPos
108 * to the runway end, mostly closely matches the runway heading.
109 * This is a good approximation of which runway the position is on or
112 FGRunway* findBestRunwayForPos(const SGGeod& aPos) const;
115 * Useful predicate for FMS/GPS/NAV displays and similar - check if this
116 * aiport has a hard-surfaced runway of at least the specified length.
118 bool hasHardRunwayOfLengthFt(double aLengthFt) const;
120 unsigned int numTaxiways() const;
121 FGTaxiway* getTaxiwayByIndex(unsigned int aIndex) const;
123 unsigned int numPavements() const;
124 FGPavement* getPavementByIndex(unsigned int aIndex) const;
126 void setRunwaysAndTaxiways(std::vector<FGRunwayPtr>& rwys,
127 std::vector<FGTaxiwayPtr>& txwys,
128 std::vector<FGPavementPtr>& pvts);
130 class AirportFilter : public Filter
133 virtual bool pass(FGPositioned* aPos) const {
134 return passAirport(static_cast<FGAirport*>(aPos));
137 virtual Type minType() const {
141 virtual Type maxType() const {
145 virtual bool passAirport(FGAirport* aApt) const {
151 * Filter which passes heliports and seaports in addition to airports
153 class PortsFilter : public AirportFilter
156 virtual Type maxType() const {
161 class HardSurfaceFilter : public AirportFilter
164 HardSurfaceFilter(double minLengthFt);
166 virtual bool passAirport(FGAirport* aApt) const;
173 void setProcedures(const std::vector<flightgear::SID*>& aSids,
174 const std::vector<flightgear::STAR*>& aStars,
175 const std::vector<flightgear::Approach*>& aApproaches);
177 void addSID(flightgear::SID* aSid);
178 void addSTAR(flightgear::STAR* aStar);
179 void addApproach(flightgear::Approach* aApp);
181 unsigned int numSIDs() const;
182 flightgear::SID* getSIDByIndex(unsigned int aIndex) const;
183 flightgear::SID* findSIDWithIdent(const std::string& aIdent) const;
185 unsigned int numSTARs() const;
186 flightgear::STAR* getSTARByIndex(unsigned int aIndex) const;
187 flightgear::STAR* findSTARWithIdent(const std::string& aIdent) const;
189 unsigned int numApproaches() const;
190 flightgear::Approach* getApproachByIndex(unsigned int aIndex) const;
192 static void installPropertyListener();
195 * Syntactic wrapper around FGPositioned::findClosest - find the closest
196 * match for filter, and return it cast to FGAirport. The default filter
197 * passes airports, but not seaports or heliports
199 static FGAirport* findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
202 * Helper to look up an FGAirport instance by unique ident. Throws an
203 * exception if the airport could not be found - so callers can assume
204 * the result is non-NULL.
206 static FGAirport* getByIdent(const std::string& aIdent);
209 * Helper to look up an FGAirport instance by unique ident. Returns NULL
210 * if the airport could not be found.
212 static FGAirport* findByIdent(const std::string& aIdent);
215 * Specialised helper to implement the AirportList dialog. Performs a
216 * case-insensitive search on airport names and ICAO codes, and returns
217 * matches in a format suitable for use by a puaList.
219 static char** searchNamesAndIdents(const std::string& aFilter);
221 bool buildApproach(flightgear::Waypt* aEnroute, flightgear::STAR* aSTAR,
222 FGRunway* aRwy, flightgear::WayptVec& aRoute);
225 * Given a destiation point, select the best SID and transition waypt from
226 * this airport. Returns (NULL,NULL) is no SIDs are defined, otherwise the
227 * best SID/transition is that which is closest to the destination point.
229 std::pair<flightgear::SID*, flightgear::WayptRef> selectSID(const SGGeod& aDest, FGRunway* aRwy);
232 * Select a STAR and enroute transition waypt, given an origin (departure) position.
233 * returns (NULL, NULL) is no suitable STAR is exists
235 std::pair<flightgear::STAR*, flightgear::WayptRef> selectSTAR(const SGGeod& aOrigin, FGRunway* aRwy);
237 virtual flightgear::PositionedBinding* createBinding(SGPropertyNode* nd) const;
239 void setCommStations(flightgear::CommStationList& comms);
241 flightgear::CommStationList commStationsOfType(FGPositioned::Type aTy) const;
243 const flightgear::CommStationList& commStations() const
244 { return mCommStations; }
246 typedef std::vector<FGRunwayPtr>::const_iterator Runway_iterator;
248 * Helper to locate a runway by ident
250 Runway_iterator getIteratorForRunwayIdent(const std::string& aIdent) const;
253 FGAirport operator=(FGAirport &other);
254 FGAirport(const FGAirport&);
257 * helper to read airport data from the scenery XML files.
259 void loadSceneryDefinitions() const;
262 * Helpers to process property data loaded from an ICAO.threshold.xml file
264 void readThresholdData(SGPropertyNode* aRoot);
265 void processThreshold(SGPropertyNode* aThreshold);
268 * Helper to parse property data loaded from an ICAO.twr.xml filke
270 void readTowerData(SGPropertyNode* aRoot);
272 SGGeod _tower_location;
275 FGAirportDynamics *_dynamics;
277 void loadRunways() const;
278 void loadTaxiways() const;
279 void loadProcedures() const;
281 mutable bool mRunwaysLoaded;
282 mutable bool mTaxiwaysLoaded;
283 mutable bool mProceduresLoaded;
285 std::vector<FGRunwayPtr> mRunways;
286 std::vector<FGTaxiwayPtr> mTaxiways;
287 std::vector<FGPavementPtr> mPavements;
289 std::vector<flightgear::SID*> mSIDs;
290 std::vector<flightgear::STAR*> mSTARs;
291 std::vector<flightgear::Approach*> mApproaches;
293 flightgear::CommStationList mCommStations;
296 // find basic airport location info from airport database
297 const FGAirport *fgFindAirportID( const std::string& id);
299 // get airport elevation
300 double fgGetAirportElev( const std::string& id );
302 #endif // _FG_SIMPLE_HXX