]> git.mxchange.org Git - flightgear.git/blob - src/Airports/airport.hxx
Expose heliports to Nasal for future use in maps
[flightgear.git] / src / Airports / airport.hxx
1 // airport.hxx -- a really simplistic class to manage airport ID,
2 //                 lat, lon of the center of one of it's runways, and
3 //                 elevation in feet.
4 //
5 // Written by Curtis Olson, started April 1998.
6 // Updated by Durk Talsma, started December 2004.
7 //
8 // Copyright (C) 1998  Curtis L. Olson  - http://www.flightgear.org/~curt
9 //
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.
14 //
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.
19 //
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.
23 //
24 // $Id$
25
26
27 #ifndef _FG_SIMPLE_HXX
28 #define _FG_SIMPLE_HXX
29
30 #include <simgear/compiler.h>
31
32 #include <string>
33 #include <vector>
34 #include <map>
35
36 #include <Navaids/positioned.hxx>
37
38 // forward decls
39 class FGAirportDynamics;
40 class FGRunway;
41 class FGHelipad;
42 class FGTaxiway;
43 class FGPavement;
44 class SGPropertyNode;
45 class FGAirport;
46
47 namespace flightgear {
48   class SID;
49   class STAR;
50   class Approach;
51   class Waypt;
52   class CommStation;
53
54   typedef SGSharedPtr<Waypt> WayptRef;
55   typedef std::vector<WayptRef> WayptVec;
56   
57   typedef std::vector<CommStation*> CommStationList;
58   typedef std::map<std::string, FGAirport*> AirportCache;
59 }
60
61
62
63 /***************************************************************************************
64  *
65  **************************************************************************************/
66 class FGAirport : public FGPositioned
67 {
68 public:
69     FGAirport(PositionedID aGuid, const std::string& id, const SGGeod& location,
70             const std::string& name, bool has_metar, Type aType);
71     ~FGAirport();
72
73     const std::string& getId() const { return ident(); }
74     const std::string& getName() const { return _name; }
75     double getLongitude() const { return longitude(); }
76     // Returns degrees
77     double getLatitude()  const { return latitude(); }
78     // Returns ft
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;
84
85     static bool isAirportType(FGPositioned* pos);
86     
87     virtual const std::string& name() const
88     { return _name; }
89
90     /**
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.
94      */
95     bool validateILSData();
96
97     SGGeod getTowerLocation() const;
98
99     void setMetar(bool value) { _has_metar = value; }
100
101     FGRunway* getActiveRunwayForUsage() const;
102
103     FGAirportDynamics *getDynamics();
104     
105     unsigned int numRunways() const;
106     unsigned int numHelipads() const;
107     FGRunway* getRunwayByIndex(unsigned int aIndex) const;
108     FGHelipad* getHelipadByIndex(unsigned int aIndex) const;
109
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;
115     
116     /**
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
121      * aiming towards.
122      */
123     FGRunway* findBestRunwayForPos(const SGGeod& aPos) const;
124     
125      /**
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.
128      */
129     bool hasHardRunwayOfLengthFt(double aLengthFt) const;
130
131     unsigned int numTaxiways() const;
132     FGTaxiway* getTaxiwayByIndex(unsigned int aIndex) const;
133
134     unsigned int numPavements() const;
135     FGPavement* getPavementByIndex(unsigned int aIndex) const;
136     
137     class AirportFilter : public Filter
138      {
139      public:
140        virtual bool pass(FGPositioned* aPos) const { 
141          return passAirport(static_cast<FGAirport*>(aPos));
142        }
143        
144        virtual Type minType() const {
145          return AIRPORT;
146        }
147        
148        virtual Type maxType() const {
149          return AIRPORT;
150        }
151        
152        virtual bool passAirport(FGAirport* aApt) const {
153          return true;
154        }
155      };
156      
157      /**
158       * Filter which passes heliports and seaports in addition to airports
159       */
160      class PortsFilter : public AirportFilter
161      {
162      public:
163        virtual Type maxType() const {
164          return SEAPORT;
165        }
166      };
167      
168      class HardSurfaceFilter : public AirportFilter
169      {
170      public:
171        HardSurfaceFilter(double minLengthFt = -1);
172        
173        virtual bool passAirport(FGAirport* aApt) const;
174        
175      private:
176        double mMinLengthFt;
177      };
178      
179      
180      void setProcedures(const std::vector<flightgear::SID*>& aSids,
181       const std::vector<flightgear::STAR*>& aStars,
182       const std::vector<flightgear::Approach*>& aApproaches);
183      
184      void addSID(flightgear::SID* aSid);
185       void addSTAR(flightgear::STAR* aStar);
186       void addApproach(flightgear::Approach* aApp);
187
188       unsigned int numSIDs() const;
189       flightgear::SID* getSIDByIndex(unsigned int aIndex) const;
190       flightgear::SID* findSIDWithIdent(const std::string& aIdent) const;
191       
192       unsigned int numSTARs() const;
193       flightgear::STAR* getSTARByIndex(unsigned int aIndex) const;
194       flightgear::STAR* findSTARWithIdent(const std::string& aIdent) const;
195       
196       unsigned int numApproaches() const;
197       flightgear::Approach* getApproachByIndex(unsigned int aIndex) const;
198       flightgear::Approach* findApproachWithIdent(const std::string& aIdent) const;
199   
200      /**
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
204       */
205      static FGAirport* findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
206      
207      /**
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.
211       */
212      static FGAirport* getByIdent(const std::string& aIdent);
213      
214      /**
215       * Helper to look up an FGAirport instance by unique ident. Returns NULL
216       * if the airport could not be found.
217       */
218      static FGAirport* findByIdent(const std::string& aIdent);
219      
220      /**
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. 
224       */
225      static char** searchNamesAndIdents(const std::string& aFilter);
226          
227     flightgear::CommStationList commStationsOfType(FGPositioned::Type aTy) const;
228     
229     flightgear::CommStationList commStations() const;
230 private:
231     static flightgear::AirportCache airportCache;
232
233     // disable these
234     FGAirport operator=(FGAirport &other);
235     FGAirport(const FGAirport&);
236   
237     /**
238      * helper to read airport data from the scenery XML files.
239      */
240     void loadSceneryDefinitions() const;
241     
242     /**
243      * Helpers to process property data loaded from an ICAO.threshold.xml file
244      */
245     void readThresholdData(SGPropertyNode* aRoot);
246     void processThreshold(SGPropertyNode* aThreshold);
247       
248     void readILSData(SGPropertyNode* aRoot);
249   
250     void validateTowerData() const;
251     
252     /**
253      * Helper to parse property data loaded from an ICAO.twr.xml file
254      */
255     void readTowerData(SGPropertyNode* aRoot);
256     
257     std::string _name;
258     bool _has_metar;
259     FGAirportDynamics *_dynamics;
260
261     void loadRunways() const;
262     void loadHelipads() const;
263     void loadTaxiways() const;
264     void loadProcedures() const;
265     
266     mutable bool mTowerDataLoaded;
267     mutable bool mRunwaysLoaded;
268     mutable bool mHelipadsLoaded;
269     mutable bool mTaxiwaysLoaded;
270     mutable bool mProceduresLoaded;
271     bool mILSDataLoaded;
272   
273     mutable PositionedIDVec mRunways;
274     mutable PositionedIDVec mHelipads;
275     mutable PositionedIDVec mTaxiways;
276     PositionedIDVec mPavements;
277     
278     typedef SGSharedPtr<flightgear::SID> SIDRef;
279     typedef SGSharedPtr<flightgear::STAR> STARRef;
280     typedef SGSharedPtr<flightgear::Approach> ApproachRef;
281     
282     std::vector<SIDRef> mSIDs;
283     std::vector<STARRef> mSTARs;
284     std::vector<ApproachRef> mApproaches;
285   };
286
287 // find basic airport location info from airport database
288 const FGAirport *fgFindAirportID( const std::string& id);
289
290 // get airport elevation
291 double fgGetAirportElev( const std::string& id );
292
293 #endif // _FG_SIMPLE_HXX
294
295