]> git.mxchange.org Git - flightgear.git/blob - src/Airports/airport.hxx
MapWidget: silence compiler warning
[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      * @result true if the data was refreshed, false if no data was loaded
74      * or previously cached data is still correct.
75      */
76     bool validateILSData();
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     FGRunwayRef findBestRunwayForHeading(double aHeading) const;
98     
99     /**
100      * return the most likely target runway based on a position.
101      * Specifically, return the runway for which the course from aPos
102      * to the runway end, mostly closely matches the runway heading.
103      * This is a good approximation of which runway the position is on or
104      * aiming towards.
105      */
106     FGRunwayRef findBestRunwayForPos(const SGGeod& aPos) const;
107     
108     /**
109      * Retrieve all runways at the airport, but excluding the reciprocal
110      * runways. For example at KSFO this might return 1L, 1R, 28L and 28R,
111      * but would not then include 19L/R or 10L/R.
112      *
113      * Exactly which runways you get, is undefined (i.e, dont assumes it's
114      * runways with heading < 180 degrees) - it depends on order in apt.dat.
115      *
116      * This is useful for code that wants to process each piece of tarmac at
117      * an airport *once*, not *twice* - eg mapping and nav-display code.
118      */
119     FGRunwayList getRunwaysWithoutReciprocals() const;
120     
121      /**
122      * Useful predicate for FMS/GPS/NAV displays and similar - check if this
123      * aiport has a hard-surfaced runway of at least the specified length.
124      */
125     bool hasHardRunwayOfLengthFt(double aLengthFt) const;
126
127     unsigned int numTaxiways() const;
128     FGTaxiwayRef getTaxiwayByIndex(unsigned int aIndex) const;
129     FGTaxiwayList getTaxiways() const;
130
131     unsigned int numPavements() const;
132     FGPavementRef getPavementByIndex(unsigned int aIndex) const;
133     FGPavementList getPavements() 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       * Filter which passes specified port type and in case of airport checks
179       * if a runway larger the /sim/navdb/min-runway-lenght-ft exists.
180       */
181      class TypeRunwayFilter:
182        public AirportFilter
183      {
184        public:
185          TypeRunwayFilter();
186
187          /**
188           * Construct from string containing type (airport, seaport or heliport)
189           */
190          bool fromTypeString(const std::string& type);
191
192          virtual FGPositioned::Type minType() const { return _type; }
193          virtual FGPositioned::Type maxType() const { return _type; }
194          virtual bool pass(FGPositioned* pos) const;
195
196        protected:
197          FGPositioned::Type _type;
198          double _min_runway_length_ft;
199      };
200
201      
202      void setProcedures(const std::vector<flightgear::SID*>& aSids,
203       const std::vector<flightgear::STAR*>& aStars,
204       const std::vector<flightgear::Approach*>& aApproaches);
205      
206      void addSID(flightgear::SID* aSid);
207       void addSTAR(flightgear::STAR* aStar);
208       void addApproach(flightgear::Approach* aApp);
209
210       unsigned int numSIDs() const;
211       flightgear::SID* getSIDByIndex(unsigned int aIndex) const;
212       flightgear::SID* findSIDWithIdent(const std::string& aIdent) const;
213       flightgear::SIDList getSIDs() const;
214       
215       unsigned int numSTARs() const;
216       flightgear::STAR* getSTARByIndex(unsigned int aIndex) const;
217       flightgear::STAR* findSTARWithIdent(const std::string& aIdent) const;
218       flightgear::STARList getSTARs() const;
219       
220       unsigned int numApproaches() const;
221       flightgear::Approach* getApproachByIndex(unsigned int aIndex) const;
222       flightgear::Approach* findApproachWithIdent(const std::string& aIdent) const;
223       flightgear::ApproachList getApproaches
224       (
225         flightgear::ProcedureType type = flightgear::PROCEDURE_INVALID
226       ) const;
227   
228      /**
229       * Syntactic wrapper around FGPositioned::findClosest - find the closest
230       * match for filter, and return it cast to FGAirport. The default filter
231       * passes airports, but not seaports or heliports
232       */
233      static FGAirportRef findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
234      
235      /**
236       * Helper to look up an FGAirport instance by unique ident. Throws an 
237       * exception if the airport could not be found - so callers can assume
238       * the result is non-NULL.
239       */
240      static FGAirportRef getByIdent(const std::string& aIdent);
241      
242      /**
243       * Helper to look up an FGAirport instance by unique ident. Returns NULL
244       * if the airport could not be found.
245       */
246      static FGAirportRef findByIdent(const std::string& aIdent);
247      
248      /**
249       * Specialised helper to implement the AirportList dialog. Performs a
250       * case-insensitive search on airport names and ICAO codes, and returns
251       * matches in a format suitable for use by a puaList. 
252       */
253      static char** searchNamesAndIdents(const std::string& aFilter);
254     
255     
256     /**
257      * Sort an FGPositionedList of airports by size (number of runways + length)
258      * this is meant to prioritise more important airports.
259      */
260     static void sortBySize(FGPositionedList&);
261     
262     flightgear::CommStationList commStationsOfType(FGPositioned::Type aTy) const;
263     
264     flightgear::CommStationList commStations() const;
265 private:
266     static flightgear::AirportCache airportCache;
267
268     // disable these
269     FGAirport operator=(FGAirport &other);
270     FGAirport(const FGAirport&);
271   
272     /**
273      * helper to read airport data from the scenery XML files.
274      */
275     void loadSceneryDefinitions() const;
276     
277     /**
278      * Helpers to process property data loaded from an ICAO.threshold.xml file
279      */
280     void readThresholdData(SGPropertyNode* aRoot);
281     void processThreshold(SGPropertyNode* aThreshold);
282       
283     void readILSData(SGPropertyNode* aRoot);
284   
285     void validateTowerData() const;
286     
287     /**
288      * Helper to parse property data loaded from an ICAO.twr.xml file
289      */
290     void readTowerData(SGPropertyNode* aRoot);
291     
292     std::string _name;
293     bool _has_metar;
294     FGAirportDynamics *_dynamics;
295
296     void loadRunways() const;
297     void loadHelipads() const;
298     void loadTaxiways() const;
299     void loadProcedures() const;
300     
301     mutable bool mTowerDataLoaded;
302     mutable bool mRunwaysLoaded;
303     mutable bool mHelipadsLoaded;
304     mutable bool mTaxiwaysLoaded;
305     mutable bool mProceduresLoaded;
306     bool mILSDataLoaded;
307   
308     mutable PositionedIDVec mRunways;
309     mutable PositionedIDVec mHelipads;
310     mutable PositionedIDVec mTaxiways;
311     PositionedIDVec mPavements;
312     
313     typedef SGSharedPtr<flightgear::SID> SIDRef;
314     typedef SGSharedPtr<flightgear::STAR> STARRef;
315     typedef SGSharedPtr<flightgear::Approach> ApproachRef;
316     
317     std::vector<SIDRef> mSIDs;
318     std::vector<STARRef> mSTARs;
319     std::vector<ApproachRef> mApproaches;
320   };
321
322 // find basic airport location info from airport database
323 const FGAirport *fgFindAirportID( const std::string& id);
324
325 // get airport elevation
326 double fgGetAirportElev( const std::string& id );
327
328 #endif // _FG_SIMPLE_HXX
329
330