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