FlightGear next
airport.hxx
Go to the documentation of this file.
1/*
2 * SPDX-FileName: airport.hxx
3 * SPDX-FileComment: a really simplistic class to manage airport ID, lat, lon of the center of one of it's runways, and elevation in feet.
4 * SPDX-FileCopyrightText: Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
5 * SPDX-FileContributor: Updated by Durk Talsma, started December 2004.
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#pragma once
10
11#include <map>
12#include <memory>
13#include <string>
14#include <vector>
15
16#include <simgear/compiler.h>
17#include <simgear/misc/sg_path.hxx>
18
20#include <Navaids/procedure.hxx>
21
22#include "airports_fwd.hxx"
23#include "runways.hxx"
24
25class FGGroundNetwork;
26
27
28/***************************************************************************************
29 *
30 **************************************************************************************/
31class FGAirport : public FGPositioned
32{
33public:
34 // 'sceneryPath' is the scenery path that provided the apt.dat file for
35 // the airport (except for the “default dat file” under $FG_ROOT and the
36 // null SGPath special case, 'sceneryPath' should be an element of
37 // globals->get_fg_scenery()). Knowing this allows one to stop looking for
38 // files such as ils.xml or threshold.xml in scenery paths that come later
39 // in globals->get_fg_scenery() order (cf. XMLLoader::findAirportData()).
40 FGAirport(PositionedID aGuid, const std::string& id, const SGGeod& location,
41 const std::string& name, bool has_metar, Type aType,
42 SGPath sceneryPath = SGPath());
43 ~FGAirport();
44
45 static bool isType(FGPositioned::Type ty)
46 {
47 return (ty >= FGPositioned::AIRPORT) && (ty <= FGPositioned::SEAPORT);
48 }
49
50 // Return the realpath() of the scenery folder under which we found the
51 // apt.dat file for this airport.
52 SGPath sceneryPath() const;
53 const std::string& getId() const { return ident(); }
54 const std::string& getName() const { return _name; }
55 std::string toString() const { return "an airport " + ident(); }
56
57 double getLongitude() const { return longitude(); }
58 // Returns degrees
59 double getLatitude() const { return latitude(); }
60 // Returns ft
61 double getElevation() const { return elevation(); }
62 bool getMetar() const { return _has_metar; }
63 bool isAirport() const;
64 bool isSeaport() const;
65 bool isHeliport() const;
66
70 bool isClosed() const
71 {
72 return mIsClosed;
73 }
74
75 virtual const std::string& name() const
76 {
77 return _name;
78 }
79
83 void validateILSData();
84
85 bool hasTower() const;
86
87 SGGeod getTowerLocation() const;
88
89 void setMetar(bool value) { _has_metar = value; }
90
92
94
96
97 unsigned int numRunways() const;
98 unsigned int numHelipads() const;
99 FGRunwayRef getRunwayByIndex(unsigned int aIndex) const;
100 FGHelipadRef getHelipadByIndex(unsigned int aIndex) const;
103
104 bool hasRunwayWithIdent(const std::string& aIdent) const;
105 bool hasHelipadWithIdent(const std::string& aIdent) const;
106 FGRunwayRef getRunwayByIdent(const std::string& aIdent) const;
107 FGHelipadRef getHelipadByIdent(const std::string& aIdent) const;
108
124 FGRunwayRef findBestRunwayForHeading(double aHeading, struct FindBestRunwayForHeadingParams* parms = NULL) const;
125
133 FGRunwayRef findBestRunwayForPos(const SGGeod& aPos) const;
134
147
151 FGRunwayList getRunways() const;
152
153 std::string findAPTRunwayForNewName(const std::string& newIdent) const;
154
159 bool hasHardRunwayOfLengthFt(double aLengthFt) const;
160
162
163 unsigned int numTaxiways() const;
164 FGTaxiwayRef getTaxiwayByIndex(unsigned int aIndex) const;
166
167 unsigned int numPavements() const;
168 FGPavementRef getPavementByIndex(unsigned int aIndex) const;
170 void addPavement(FGPavementRef pavement);
171
172 unsigned int numBoundary() const;
173 FGPavementRef getBoundaryIndex(unsigned int aIndex) const;
175 void addBoundary(FGPavementRef boundary);
176
177 unsigned int numLineFeatures() const;
179 void addLineFeature(FGPavementRef linefeature);
180
181 class AirportFilter : public Filter
182 {
183 public:
184 virtual bool pass(FGPositioned* aPos) const
185 {
186 return passAirport(static_cast<FGAirport*>(aPos));
187 }
188
189 virtual Type minType() const
190 {
191 return AIRPORT;
192 }
193
194 virtual Type maxType() const
195 {
196 return AIRPORT;
197 }
198
199 virtual bool passAirport(FGAirport* aApt) const
200 {
201 return true;
202 }
203 };
204
209 {
210 public:
211 virtual Type maxType() const override
212 {
213 return SEAPORT;
214 }
215 };
216
218 {
219 public:
220 explicit HardSurfaceFilter(double minLengthFt = -1);
221
222 virtual bool passAirport(FGAirport* aApt) const override;
223
224 private:
225 double mMinLengthFt;
226 };
227
233 {
234 public:
236
240 bool fromTypeString(const std::string& type);
241
242 virtual FGPositioned::Type minType() const override { return _type; }
243 virtual FGPositioned::Type maxType() const override { return _type; }
244 virtual bool pass(FGPositioned* pos) const override;
245
246 protected:
249 };
250
251
252 void setProcedures(const std::vector<flightgear::SID*>& aSids,
253 const std::vector<flightgear::STAR*>& aStars,
254 const std::vector<flightgear::Approach*>& aApproaches);
255
256 void addSID(flightgear::SID* aSid);
257 void addSTAR(flightgear::STAR* aStar);
259
260 unsigned int numSIDs() const;
261 flightgear::SID* getSIDByIndex(unsigned int aIndex) const;
262 flightgear::SID* findSIDWithIdent(const std::string& aIdent) const;
264
266 flightgear::Transition* selectSIDByTransition(const FGRunway* runway, const std::string& aIdent) const;
267
268 unsigned int numSTARs() const;
269 flightgear::STAR* getSTARByIndex(unsigned int aIndex) const;
270 flightgear::STAR* findSTARWithIdent(const std::string& aIdent) const;
272
274 flightgear::Transition* selectSTARByTransition(const FGRunway* runway, const std::string& aIdent) const;
275
276 unsigned int numApproaches() const;
277 flightgear::Approach* getApproachByIndex(unsigned int aIndex) const;
278 flightgear::Approach* findApproachWithIdent(const std::string& aIdent) const;
281
287 static FGAirportRef findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
288
294 static FGAirportRef getByIdent(const std::string& aIdent);
295
300 static FGAirportRef findByIdent(const std::string& aIdent);
301
307 static char** searchNamesAndIdents(const std::string& aFilter);
308
309
314 static void sortBySize(FGPositionedList&);
315
317
319
320 static void clearAirportsCache();
321
322 // helper to allow testing without needing a full Airports hierarchy
323 // only for use by the test-suite, not available outside of it.
324 void testSuiteInjectGroundnetXML(const SGPath& path);
325
326 void testSuiteInjectProceduresXML(const SGPath& path);
327
328private:
329 static flightgear::AirportCache airportCache;
330
331 // disable these
332 FGAirport operator=(FGAirport& other);
333 FGAirport(const FGAirport&);
334
338 void loadSceneryDefinitions() const;
339
343 void readThresholdData(SGPropertyNode* aRoot);
344 void processThreshold(SGPropertyNode* aThreshold);
345
346 void readILSData(SGPropertyNode* aRoot);
347
348 void validateTowerData() const;
349
353 void readTowerData(SGPropertyNode* aRoot);
354
358 void parseRunwayRenameData(SGPropertyNode* aRoot);
359
360 PositionedIDVec itemsOfType(FGPositioned::Type ty) const;
361
362 std::string _name;
363 bool _has_metar = false;
364 const SGPath _sceneryPath;
365
366 void loadRunways() const;
367 void loadHelipads() const;
368 void loadTaxiways() const;
369 void loadProcedures() const;
370 void loadRunwayRenames() const;
371
372 mutable bool mTowerDataLoaded;
373 mutable bool mHasTower;
374 mutable SGGeod mTowerPosition;
375
376 mutable bool mRunwaysLoaded;
377 mutable bool mHelipadsLoaded;
378 mutable bool mTaxiwaysLoaded;
379 mutable bool mProceduresLoaded;
380 mutable bool mRunwayRenamesLoaded = false;
381 bool mIsClosed;
382 mutable bool mThresholdDataLoaded;
383 bool mILSDataLoaded;
384
385 mutable std::vector<FGRunwayRef> mRunways;
386
387 mutable PositionedIDVec mHelipads;
388 mutable PositionedIDVec mTaxiways;
389 std::vector<FGPavementRef> mPavements;
390 std::vector<FGPavementRef> mBoundary;
391 std::vector<FGPavementRef> mLineFeatures;
392
393 typedef SGSharedPtr<flightgear::SID> SIDRef;
394 typedef SGSharedPtr<flightgear::STAR> STARRef;
395 typedef SGSharedPtr<flightgear::Approach> ApproachRef;
396
397 std::vector<SIDRef> mSIDs;
398 std::vector<STARRef> mSTARs;
399 std::vector<ApproachRef> mApproaches;
400
401 mutable std::unique_ptr<FGGroundNetwork> _groundNetwork;
402
403 using RunwayRenameMap = std::map<std::string, std::string>;
404 // map from new name (eg in Navigraph) to old name (in apt.dat)
405 RunwayRenameMap _renamedRunways;
406};
407
408// find basic airport location info from airport database
409const FGAirport* fgFindAirportID(const std::string& id);
410
411// get airport elevation
412double fgGetAirportElev(const std::string& id);
const FGAirport * fgFindAirportID(const std::string &id)
Definition airport.cxx:523
double fgGetAirportElev(const std::string &id)
Definition airport.cxx:1119
std::map< std::string, FGRunwayRef > FGRunwayMap
SGSharedPtr< FGTaxiway > FGTaxiwayRef
SGSharedPtr< FGAirportDynamics > FGAirportDynamicsRef
std::vector< FGRunwayRef > FGRunwayList
SGSharedPtr< FGHelipad > FGHelipadRef
SGSharedPtr< FGPavement > FGPavementRef
std::vector< FGPavementRef > FGPavementList
std::map< std::string, FGHelipadRef > FGHelipadMap
SGSharedPtr< FGAirport > FGAirportRef
SGSharedPtr< FGRunway > FGRunwayRef
std::vector< FGTaxiwayRef > FGTaxiwayList
virtual bool pass(FGPositioned *aPos) const
Over-rideable filter method.
Definition airport.hxx:184
virtual Type maxType() const
Definition airport.hxx:194
virtual bool passAirport(FGAirport *aApt) const
Definition airport.hxx:199
virtual Type minType() const
Definition airport.hxx:189
HardSurfaceFilter(double minLengthFt=-1)
Definition airport.cxx:439
virtual bool passAirport(FGAirport *aApt) const override
Definition airport.cxx:447
Filter which passes heliports and seaports in addition to airports.
Definition airport.hxx:209
virtual Type maxType() const override
Definition airport.hxx:211
FGPositioned::Type _type
Definition airport.hxx:247
virtual FGPositioned::Type maxType() const override
Definition airport.hxx:243
bool fromTypeString(const std::string &type)
Construct from string containing type (airport, seaport or heliport)
Definition airport.cxx:461
virtual FGPositioned::Type minType() const override
Definition airport.hxx:242
virtual bool pass(FGPositioned *pos) const override
Over-rideable filter method.
Definition airport.cxx:472
FGAirportDynamicsRef getDynamics() const
Definition airport.cxx:1048
SGPath sceneryPath() const
Definition airport.cxx:96
bool getMetar() const
Definition airport.hxx:62
unsigned int numRunways() const
Definition airport.cxx:102
FGPavementRef getPavementByIndex(unsigned int aIndex) const
void testSuiteInjectProceduresXML(const SGPath &path)
std::string findAPTRunwayForNewName(const std::string &newIdent) const
Definition airport.cxx:783
flightgear::STAR * getSTARByIndex(unsigned int aIndex) const
Definition airport.cxx:914
FGRunwayRef findBestRunwayForHeading(double aHeading, struct FindBestRunwayForHeadingParams *parms=NULL) const
Definition airport.cxx:211
FGPavementList getLineFeatures() const
Definition airport.cxx:391
bool isClosed() const
is the airport closed (disused)?
Definition airport.hxx:70
void setProcedures(const std::vector< flightgear::SID * > &aSids, const std::vector< flightgear::STAR * > &aStars, const std::vector< flightgear::Approach * > &aApproaches)
FGHelipadRef getHelipadByIndex(unsigned int aIndex) const
Definition airport.cxx:123
FGRunwayRef findBestRunwayForPos(const SGGeod &aPos) const
return the most likely target runway based on a position.
Definition airport.cxx:248
void validateILSData()
reload the ILS data from XML if required.
Definition airport.cxx:795
unsigned int numApproaches() const
Definition airport.cxx:940
unsigned int numSIDs() const
Definition airport.cxx:873
unsigned int numTaxiways() const
Definition airport.cxx:330
FGRunwayRef getRunwayByIndex(unsigned int aIndex) const
Definition airport.cxx:116
bool isAirport() const
Definition airport.cxx:81
FGRunwayList getRunwaysWithoutReciprocals() const
Retrieve all runways at the airport, but excluding the reciprocal runways.
Definition airport.cxx:308
double getElevation() const
Definition airport.hxx:61
double getLatitude() const
Definition airport.hxx:59
double getLongitude() const
Definition airport.hxx:57
FGRunwayRef getRunwayByIdent(const std::string &aIdent) const
Definition airport.cxx:182
void addLineFeature(FGPavementRef linefeature)
Definition airport.cxx:396
static void sortBySize(FGPositionedList &)
Sort an FGPositionedList of airports by size (number of runways + length) this is meant to prioritise...
Definition airport.cxx:1035
flightgear::Transition * selectSIDByEnrouteTransition(FGPositioned *enroute) const
Definition airport.cxx:1064
flightgear::CommStationList commStationsOfType(FGPositioned::Type aTy) const
Definition airport.cxx:997
std::string toString() const
Definition airport.hxx:55
bool isSeaport() const
Definition airport.cxx:86
bool hasHardRunwayOfLengthFt(double aLengthFt) const
Useful predicate for FMS/GPS/NAV displays and similar - check if this airport has a hard-surfaced run...
Definition airport.cxx:272
FGPavementList getPavements() const
Definition airport.cxx:357
static FGAirportRef findClosest(const SGGeod &aPos, double aCuttofNm, Filter *filter=NULL)
Syntactic wrapper around FGPositioned::findClosest - find the closest match for filter,...
Definition airport.cxx:425
unsigned int numLineFeatures() const
Definition airport.cxx:385
flightgear::Approach * getApproachByIndex(unsigned int aIndex) const
Definition airport.cxx:947
static void clearAirportsCache()
Definition airport.cxx:483
unsigned int numHelipads() const
Definition airport.cxx:109
void setMetar(bool value)
Definition airport.hxx:89
flightgear::Transition * selectSTARByTransition(const FGRunway *runway, const std::string &aIdent) const
Definition airport.cxx:1103
static FGAirportRef findByIdent(const std::string &aIdent)
Helper to look up an FGAirport instance by unique ident.
Definition airport.cxx:489
flightgear::STAR * findSTARWithIdent(const std::string &aIdent) const
Definition airport.cxx:921
bool hasHelipadWithIdent(const std::string &aIdent) const
Definition airport.cxx:175
void addSID(flightgear::SID *aSid)
Definition airport.cxx:857
void addPavement(FGPavementRef pavement)
Definition airport.cxx:362
static char ** searchNamesAndIdents(const std::string &aFilter)
Specialised helper to implement the AirportList dialog.
Definition airport.cxx:517
virtual const std::string & name() const
Return the name of this positioned.
Definition airport.hxx:75
FGPavementRef getBoundaryIndex(unsigned int aIndex) const
FGTaxiwayList getTaxiways() const
Definition airport.cxx:344
bool hasRunwayWithIdent(const std::string &aIdent) const
Definition airport.cxx:162
void testSuiteInjectGroundnetXML(const SGPath &path)
flightgear::ApproachList getApproaches(flightgear::ProcedureType type=flightgear::PROCEDURE_INVALID) const
Definition airport.cxx:967
flightgear::Transition * selectSTARByEnrouteTransition(FGPositioned *enroute) const
Definition airport.cxx:1091
FGPavementList getBoundary() const
Definition airport.cxx:374
unsigned int numPavements() const
Definition airport.cxx:351
FGRunwayRef longestRunway() const
Definition airport.cxx:285
void addSTAR(flightgear::STAR *aStar)
Definition airport.cxx:862
FGTaxiwayRef getTaxiwayByIndex(unsigned int aIndex) const
Definition airport.cxx:337
FGRunwayList getRunways() const
Retrieve all runways at the airport.
Definition airport.cxx:300
flightgear::CommStationList commStations() const
Definition airport.cxx:983
const std::string & getName() const
Definition airport.hxx:54
bool isHeliport() const
Definition airport.cxx:91
flightgear::STARList getSTARs() const
Definition airport.cxx:934
void addApproach(flightgear::Approach *aApp)
Definition airport.cxx:867
const std::string & getId() const
Definition airport.hxx:53
SGGeod getTowerLocation() const
Definition airport.cxx:696
FGAirport(PositionedID aGuid, const std::string &id, const SGGeod &location, const std::string &name, bool has_metar, Type aType, SGPath sceneryPath=SGPath())
Definition airport.cxx:53
flightgear::Approach * findApproachWithIdent(const std::string &aIdent) const
Definition airport.cxx:954
static bool isType(FGPositioned::Type ty)
Definition airport.hxx:45
void addBoundary(FGPavementRef boundary)
Definition airport.cxx:379
FGRunwayMap getRunwayMap() const
Definition airport.cxx:130
unsigned int numBoundary() const
Definition airport.cxx:368
flightgear::SID * findSIDWithIdent(const std::string &aIdent) const
Definition airport.cxx:887
FGHelipadRef getHelipadByIdent(const std::string &aIdent) const
Definition airport.cxx:199
unsigned int numSTARs() const
Definition airport.cxx:907
flightgear::SID * getSIDByIndex(unsigned int aIndex) const
Definition airport.cxx:880
bool hasTower() const
Definition airport.cxx:819
FGRunwayRef getActiveRunwayForUsage() const
Definition airport.cxx:402
FGHelipadMap getHelipadMap() const
Definition airport.cxx:148
flightgear::Transition * selectSIDByTransition(const FGRunway *runway, const std::string &aIdent) const
Definition airport.cxx:1076
FGGroundNetwork * groundNetwork() const
Definition airport.cxx:1053
flightgear::SIDList getSIDs() const
Definition airport.cxx:900
static FGAirportRef getByIdent(const std::string &aIdent)
Helper to look up an FGAirport instance by unique ident.
Definition airport.cxx:509
Predicate class to support custom filtering of FGPositioned queries Default implementation of this pa...
FGPositioned(PositionedID aGuid, Type ty, const std::string &aIdent, const SGGeod &aPos)
double longitude() const
double latitude() const
double elevation() const
Type type() const
const std::string & ident() const
Describe an approach procedure, including the missed approach segment.
Encapsulate a transition segment.
Definition procedure.hxx:70
std::vector< Approach * > ApproachList
std::vector< CommStationRef > CommStationList
std::vector< STAR * > STARList
std::vector< flightgear::SID * > SIDList
std::map< std::string, FGAirport * > AirportCache
@ PROCEDURE_INVALID
Definition procedure.hxx:37
std::vector< PositionedID > PositionedIDVec
std::vector< FGPositionedRef > FGPositionedList
int64_t PositionedID