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