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