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