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