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