]> git.mxchange.org Git - flightgear.git/blob - src/Airports/airport.hxx
Fix missing includes
[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 #include <Airports/runways.hxx>
38
39 // forward decls
40 class FGAirportDynamics;
41 class FGRunway;
42 class FGHelipad;
43 class FGTaxiway;
44 class FGPavement;
45 class SGPropertyNode;
46 class FGAirport;
47
48 namespace flightgear {
49   class SID;
50   class STAR;
51   class Approach;
52   class Waypt;
53   class CommStation;
54
55   typedef SGSharedPtr<Waypt> WayptRef;
56   typedef std::vector<WayptRef> WayptVec;
57   
58   typedef std::vector<CommStation*> CommStationList;
59   typedef std::map<std::string, FGAirport*> AirportCache;
60 }
61
62 typedef std::vector<FGRunway*> FGRunwayList;
63
64
65 /***************************************************************************************
66  *
67  **************************************************************************************/
68 class FGAirport : public FGPositioned
69 {
70 public:
71     FGAirport(PositionedID aGuid, const std::string& id, const SGGeod& location,
72             const std::string& name, bool has_metar, Type aType);
73     ~FGAirport();
74
75     const std::string& getId() const { return ident(); }
76     const std::string& getName() const { return _name; }
77     double getLongitude() const { return longitude(); }
78     // Returns degrees
79     double getLatitude()  const { return latitude(); }
80     // Returns ft
81     double getElevation() const { return elevation(); }
82     bool   getMetar()     const { return _has_metar; }
83     bool   isAirport()    const;
84     bool   isSeaport()    const;
85     bool   isHeliport()   const;
86
87     static bool isAirportType(FGPositioned* pos);
88     
89     virtual const std::string& name() const
90     { return _name; }
91
92     /**
93      * reload the ILS data from XML if required.
94      * @result true if the data was refreshed, false if no data was loaded
95      * or previously cached data is still correct.
96      */
97     bool validateILSData();
98
99     SGGeod getTowerLocation() const;
100
101     void setMetar(bool value) { _has_metar = value; }
102
103     FGRunway* getActiveRunwayForUsage() const;
104
105     FGAirportDynamics *getDynamics();
106     
107     unsigned int numRunways() const;
108     unsigned int numHelipads() const;
109     FGRunway* getRunwayByIndex(unsigned int aIndex) const;
110     FGHelipad* getHelipadByIndex(unsigned int aIndex) const;
111
112     bool hasRunwayWithIdent(const std::string& aIdent) const;
113     bool hasHelipadWithIdent(const std::string& aIdent) const;
114     FGRunway* getRunwayByIdent(const std::string& aIdent) const;
115     FGHelipad* getHelipadByIdent(const std::string& aIdent) const;
116     FGRunway* findBestRunwayForHeading(double aHeading) const;
117     
118     /**
119      * return the most likely target runway based on a position.
120      * Specifically, return the runway for which the course from aPos
121      * to the runway end, mostly closely matches the runway heading.
122      * This is a good approximation of which runway the position is on or
123      * aiming towards.
124      */
125     FGRunway* findBestRunwayForPos(const SGGeod& aPos) const;
126     
127     /**
128      * Retrieve all runways at the airport, but excluding the reciprocal
129      * runways. For example at KSFO this might return 1L, 1R, 28L and 28R,
130      * but would not then include 19L/R or 10L/R.
131      *
132      * Exactly which runways you get, is undefined (i.e, dont assumes it's
133      * runways with heading < 180 degrees) - it depends on order in apt.dat.
134      *
135      * This is useful for code that wants to process each piece of tarmac at
136      * an airport *once*, not *twice* - eg mapping and nav-display code.
137      */
138     FGRunwayList getRunwaysWithoutReciprocals() const;
139     
140      /**
141      * Useful predicate for FMS/GPS/NAV displays and similar - check if this
142      * aiport has a hard-surfaced runway of at least the specified length.
143      */
144     bool hasHardRunwayOfLengthFt(double aLengthFt) const;
145
146     unsigned int numTaxiways() const;
147     FGTaxiway* getTaxiwayByIndex(unsigned int aIndex) const;
148
149     unsigned int numPavements() const;
150     FGPavement* getPavementByIndex(unsigned int aIndex) const;
151     
152     class AirportFilter : public Filter
153      {
154      public:
155        virtual bool pass(FGPositioned* aPos) const { 
156          return passAirport(static_cast<FGAirport*>(aPos));
157        }
158        
159        virtual Type minType() const {
160          return AIRPORT;
161        }
162        
163        virtual Type maxType() const {
164          return AIRPORT;
165        }
166        
167        virtual bool passAirport(FGAirport* aApt) const {
168          return true;
169        }
170      };
171      
172      /**
173       * Filter which passes heliports and seaports in addition to airports
174       */
175      class PortsFilter : public AirportFilter
176      {
177      public:
178        virtual Type maxType() const {
179          return SEAPORT;
180        }
181      };
182      
183      class HardSurfaceFilter : public AirportFilter
184      {
185      public:
186        HardSurfaceFilter(double minLengthFt = -1);
187        
188        virtual bool passAirport(FGAirport* aApt) const;
189        
190      private:
191        double mMinLengthFt;
192      };
193      
194      
195      void setProcedures(const std::vector<flightgear::SID*>& aSids,
196       const std::vector<flightgear::STAR*>& aStars,
197       const std::vector<flightgear::Approach*>& aApproaches);
198      
199      void addSID(flightgear::SID* aSid);
200       void addSTAR(flightgear::STAR* aStar);
201       void addApproach(flightgear::Approach* aApp);
202
203       unsigned int numSIDs() const;
204       flightgear::SID* getSIDByIndex(unsigned int aIndex) const;
205       flightgear::SID* findSIDWithIdent(const std::string& aIdent) const;
206       
207       unsigned int numSTARs() const;
208       flightgear::STAR* getSTARByIndex(unsigned int aIndex) const;
209       flightgear::STAR* findSTARWithIdent(const std::string& aIdent) const;
210       
211       unsigned int numApproaches() const;
212       flightgear::Approach* getApproachByIndex(unsigned int aIndex) const;
213       flightgear::Approach* findApproachWithIdent(const std::string& aIdent) const;
214   
215      /**
216       * Syntactic wrapper around FGPositioned::findClosest - find the closest
217       * match for filter, and return it cast to FGAirport. The default filter
218       * passes airports, but not seaports or heliports
219       */
220      static FGAirport* findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
221      
222      /**
223       * Helper to look up an FGAirport instance by unique ident. Throws an 
224       * exception if the airport could not be found - so callers can assume
225       * the result is non-NULL.
226       */
227      static FGAirport* getByIdent(const std::string& aIdent);
228      
229      /**
230       * Helper to look up an FGAirport instance by unique ident. Returns NULL
231       * if the airport could not be found.
232       */
233      static FGAirport* findByIdent(const std::string& aIdent);
234      
235      /**
236       * Specialised helper to implement the AirportList dialog. Performs a
237       * case-insensitive search on airport names and ICAO codes, and returns
238       * matches in a format suitable for use by a puaList. 
239       */
240      static char** searchNamesAndIdents(const std::string& aFilter);
241          
242     flightgear::CommStationList commStationsOfType(FGPositioned::Type aTy) const;
243     
244     flightgear::CommStationList commStations() const;
245 private:
246     static flightgear::AirportCache airportCache;
247
248     // disable these
249     FGAirport operator=(FGAirport &other);
250     FGAirport(const FGAirport&);
251   
252     /**
253      * helper to read airport data from the scenery XML files.
254      */
255     void loadSceneryDefinitions() const;
256     
257     /**
258      * Helpers to process property data loaded from an ICAO.threshold.xml file
259      */
260     void readThresholdData(SGPropertyNode* aRoot);
261     void processThreshold(SGPropertyNode* aThreshold);
262       
263     void readILSData(SGPropertyNode* aRoot);
264   
265     void validateTowerData() const;
266     
267     /**
268      * Helper to parse property data loaded from an ICAO.twr.xml file
269      */
270     void readTowerData(SGPropertyNode* aRoot);
271     
272     std::string _name;
273     bool _has_metar;
274     FGAirportDynamics *_dynamics;
275
276     void loadRunways() const;
277     void loadHelipads() const;
278     void loadTaxiways() const;
279     void loadProcedures() const;
280     
281     mutable bool mTowerDataLoaded;
282     mutable bool mRunwaysLoaded;
283     mutable bool mHelipadsLoaded;
284     mutable bool mTaxiwaysLoaded;
285     mutable bool mProceduresLoaded;
286     bool mILSDataLoaded;
287   
288     mutable PositionedIDVec mRunways;
289     mutable PositionedIDVec mHelipads;
290     mutable PositionedIDVec mTaxiways;
291     PositionedIDVec mPavements;
292     
293     typedef SGSharedPtr<flightgear::SID> SIDRef;
294     typedef SGSharedPtr<flightgear::STAR> STARRef;
295     typedef SGSharedPtr<flightgear::Approach> ApproachRef;
296     
297     std::vector<SIDRef> mSIDs;
298     std::vector<STARRef> mSTARs;
299     std::vector<ApproachRef> mApproaches;
300   };
301
302 // find basic airport location info from airport database
303 const FGAirport *fgFindAirportID( const std::string& id);
304
305 // get airport elevation
306 double fgGetAirportElev( const std::string& id );
307
308 #endif // _FG_SIMPLE_HXX
309
310