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