]> git.mxchange.org Git - flightgear.git/blob - src/Airports/airport.hxx
Give the FGAirport class a sane filename.
[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     FGRunway* getRunwayByIdent(const std::string& aIdent) const;
112     FGRunway* findBestRunwayForHeading(double aHeading) const;
113     
114     /**
115      * return the most likely target runway based on a position.
116      * Specifically, return the runway for which the course from aPos
117      * to the runway end, mostly closely matches the runway heading.
118      * This is a good approximation of which runway the position is on or
119      * aiming towards.
120      */
121     FGRunway* findBestRunwayForPos(const SGGeod& aPos) const;
122     
123      /**
124      * Useful predicate for FMS/GPS/NAV displays and similar - check if this
125      * aiport has a hard-surfaced runway of at least the specified length.
126      */
127     bool hasHardRunwayOfLengthFt(double aLengthFt) const;
128
129     unsigned int numTaxiways() const;
130     FGTaxiway* getTaxiwayByIndex(unsigned int aIndex) const;
131
132     unsigned int numPavements() const;
133     FGPavement* getPavementByIndex(unsigned int aIndex) const;
134     
135     class AirportFilter : public Filter
136      {
137      public:
138        virtual bool pass(FGPositioned* aPos) const { 
139          return passAirport(static_cast<FGAirport*>(aPos));
140        }
141        
142        virtual Type minType() const {
143          return AIRPORT;
144        }
145        
146        virtual Type maxType() const {
147          return AIRPORT;
148        }
149        
150        virtual bool passAirport(FGAirport* aApt) const {
151          return true;
152        }
153      };
154      
155      /**
156       * Filter which passes heliports and seaports in addition to airports
157       */
158      class PortsFilter : public AirportFilter
159      {
160      public:
161        virtual Type maxType() const {
162          return SEAPORT;
163        }
164      };
165      
166      class HardSurfaceFilter : public AirportFilter
167      {
168      public:
169        HardSurfaceFilter(double minLengthFt = -1);
170        
171        virtual bool passAirport(FGAirport* aApt) const;
172        
173      private:
174        double mMinLengthFt;
175      };
176      
177      
178      void setProcedures(const std::vector<flightgear::SID*>& aSids,
179       const std::vector<flightgear::STAR*>& aStars,
180       const std::vector<flightgear::Approach*>& aApproaches);
181      
182      void addSID(flightgear::SID* aSid);
183       void addSTAR(flightgear::STAR* aStar);
184       void addApproach(flightgear::Approach* aApp);
185
186       unsigned int numSIDs() const;
187       flightgear::SID* getSIDByIndex(unsigned int aIndex) const;
188       flightgear::SID* findSIDWithIdent(const std::string& aIdent) const;
189       
190       unsigned int numSTARs() const;
191       flightgear::STAR* getSTARByIndex(unsigned int aIndex) const;
192       flightgear::STAR* findSTARWithIdent(const std::string& aIdent) 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   
198      /**
199       * Syntactic wrapper around FGPositioned::findClosest - find the closest
200       * match for filter, and return it cast to FGAirport. The default filter
201       * passes airports, but not seaports or heliports
202       */
203      static FGAirport* findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
204      
205      /**
206       * Helper to look up an FGAirport instance by unique ident. Throws an 
207       * exception if the airport could not be found - so callers can assume
208       * the result is non-NULL.
209       */
210      static FGAirport* getByIdent(const std::string& aIdent);
211      
212      /**
213       * Helper to look up an FGAirport instance by unique ident. Returns NULL
214       * if the airport could not be found.
215       */
216      static FGAirport* findByIdent(const std::string& aIdent);
217      
218      /**
219       * Specialised helper to implement the AirportList dialog. Performs a
220       * case-insensitive search on airport names and ICAO codes, and returns
221       * matches in a format suitable for use by a puaList. 
222       */
223      static char** searchNamesAndIdents(const std::string& aFilter);
224          
225     flightgear::CommStationList commStationsOfType(FGPositioned::Type aTy) const;
226     
227     flightgear::CommStationList commStations() const;
228 private:
229     static flightgear::AirportCache airportCache;
230
231     // disable these
232     FGAirport operator=(FGAirport &other);
233     FGAirport(const FGAirport&);
234   
235     /**
236      * helper to read airport data from the scenery XML files.
237      */
238     void loadSceneryDefinitions() const;
239     
240     /**
241      * Helpers to process property data loaded from an ICAO.threshold.xml file
242      */
243     void readThresholdData(SGPropertyNode* aRoot);
244     void processThreshold(SGPropertyNode* aThreshold);
245       
246     void readILSData(SGPropertyNode* aRoot);
247   
248     void validateTowerData() const;
249     
250     /**
251      * Helper to parse property data loaded from an ICAO.twr.xml file
252      */
253     void readTowerData(SGPropertyNode* aRoot);
254     
255     std::string _name;
256     bool _has_metar;
257     FGAirportDynamics *_dynamics;
258
259     void loadRunways() const;
260     void loadHelipads() const;
261     void loadTaxiways() const;
262     void loadProcedures() const;
263     
264     mutable bool mTowerDataLoaded;
265     mutable bool mRunwaysLoaded;
266     mutable bool mHelipadsLoaded;
267     mutable bool mTaxiwaysLoaded;
268     mutable bool mProceduresLoaded;
269     bool mILSDataLoaded;
270   
271     mutable PositionedIDVec mRunways;
272     mutable PositionedIDVec mHelipads;
273     mutable PositionedIDVec mTaxiways;
274     PositionedIDVec mPavements;
275     
276     typedef SGSharedPtr<flightgear::SID> SIDRef;
277     typedef SGSharedPtr<flightgear::STAR> STARRef;
278     typedef SGSharedPtr<flightgear::Approach> ApproachRef;
279     
280     std::vector<SIDRef> mSIDs;
281     std::vector<STARRef> mSTARs;
282     std::vector<ApproachRef> mApproaches;
283   };
284
285 // find basic airport location info from airport database
286 const FGAirport *fgFindAirportID( const std::string& id);
287
288 // get airport elevation
289 double fgGetAirportElev( const std::string& id );
290
291 #endif // _FG_SIMPLE_HXX
292
293