]> git.mxchange.org Git - flightgear.git/blob - src/Airports/simple.hxx
Merge branch 'next' into durk-atc
[flightgear.git] / src / Airports / simple.hxx
1 // simple.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
35 #include <Navaids/positioned.hxx>
36
37 // forward decls
38 class FGAirportDynamics;
39 class FGRunway;
40 class FGTaxiway;
41 class FGPavement;
42 class SGPropertyNode;
43
44 typedef SGSharedPtr<FGRunway> FGRunwayPtr;
45 typedef SGSharedPtr<FGTaxiway> FGTaxiwayPtr;
46 typedef SGSharedPtr<FGPavement> FGPavementPtr;
47
48 namespace flightgear {
49   class SID;
50   class STAR;
51   class Approach;
52   class Waypt;
53
54
55   typedef SGSharedPtr<Waypt> WayptRef;
56   typedef std::vector<WayptRef> WayptVec;
57 }
58
59
60
61 /***************************************************************************************
62  *
63  **************************************************************************************/
64 class FGAirport : public FGPositioned
65 {
66 public:
67     FGAirport(const std::string& id, const SGGeod& location, const SGGeod& tower, 
68             const std::string& name, bool has_metar, Type aType);
69     ~FGAirport();
70
71     const std::string& getId() const { return ident(); }
72     const std::string& getName() const { return _name; }
73     double getLongitude() const { return longitude(); }
74     // Returns degrees
75     double getLatitude()  const { return latitude(); }
76     // Returns ft
77     double getElevation() const { return elevation(); }
78     bool   getMetar()     const { return _has_metar; }
79     bool   isAirport()    const;
80     bool   isSeaport()    const;
81     bool   isHeliport()   const;
82
83     virtual const std::string& name() const
84     { return _name; }
85
86     const SGGeod& getTowerLocation() const { return _tower_location; }
87
88     void setMetar(bool value) { _has_metar = value; }
89
90     FGRunway* getActiveRunwayForUsage() const;
91
92     FGAirportDynamics *getDynamics();
93     
94     unsigned int numRunways() const;
95     FGRunway* getRunwayByIndex(unsigned int aIndex) const;
96
97     bool hasRunwayWithIdent(const std::string& aIdent) const;
98     FGRunway* getRunwayByIdent(const std::string& aIdent) const;
99     FGRunway* findBestRunwayForHeading(double aHeading) const;
100     
101     /**
102      * return the most likely target runway based on a position.
103      * Specifically, return the runway for which the course from aPos
104      * to the runway end, mostly closely matches the runway heading.
105      * This is a good approximation of which runway the position is on or
106      * aiming towards.
107      */
108     FGRunway* findBestRunwayForPos(const SGGeod& aPos) const;
109     
110      /**
111      * Useful predicate for FMS/GPS/NAV displays and similar - check if this
112      * aiport has a hard-surfaced runway of at least the specified length.
113      */
114     bool hasHardRunwayOfLengthFt(double aLengthFt) const;
115
116     unsigned int numTaxiways() const;
117     FGTaxiway* getTaxiwayByIndex(unsigned int aIndex) const;
118
119     unsigned int numPavements() const;
120     FGPavement* getPavementByIndex(unsigned int aIndex) const;
121
122     void setRunwaysAndTaxiways(std::vector<FGRunwayPtr>& rwys,
123       std::vector<FGTaxiwayPtr>& txwys,
124       std::vector<FGPavementPtr>& pvts);
125     
126     class AirportFilter : public Filter
127      {
128      public:
129        virtual bool pass(FGPositioned* aPos) const { 
130          return passAirport(static_cast<FGAirport*>(aPos));
131        }
132        
133        virtual Type minType() const {
134          return AIRPORT;
135        }
136        
137        virtual Type maxType() const {
138          return AIRPORT;
139        }
140        
141        virtual bool passAirport(FGAirport* aApt) const {
142          return true;
143        }
144      };
145      
146      /**
147       * Filter which passes heliports and seaports in addition to airports
148       */
149      class PortsFilter : public AirportFilter
150      {
151      public:
152        virtual Type maxType() const {
153          return SEAPORT;
154        }
155      };
156      
157      class HardSurfaceFilter : public AirportFilter
158      {
159      public:
160        HardSurfaceFilter(double minLengthFt);
161        
162        virtual bool passAirport(FGAirport* aApt) const;
163        
164      private:
165        double mMinLengthFt;
166      };
167      
168      
169      void setProcedures(const std::vector<flightgear::SID*>& aSids,
170       const std::vector<flightgear::STAR*>& aStars,
171       const std::vector<flightgear::Approach*>& aApproaches);
172      
173      void addSID(flightgear::SID* aSid);
174       void addSTAR(flightgear::STAR* aStar);
175       void addApproach(flightgear::Approach* aApp);
176
177       unsigned int numSIDs() const;
178       flightgear::SID* getSIDByIndex(unsigned int aIndex) const;
179       flightgear::SID* findSIDWithIdent(const std::string& aIdent) const;
180       
181       unsigned int numSTARs() const;
182       flightgear::STAR* getSTARByIndex(unsigned int aIndex) const;
183       flightgear::STAR* findSTARWithIdent(const std::string& aIdent) const;
184       
185       unsigned int numApproaches() const;
186       flightgear::Approach* getApproachByIndex(unsigned int aIndex) const;
187
188      /**
189       * Syntactic wrapper around FGPositioned::findClosest - find the closest
190       * match for filter, and return it cast to FGAirport. The default filter
191       * passes airports, but not seaports or heliports
192       */
193      static FGAirport* findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
194      
195      /**
196       * Helper to look up an FGAirport instance by unique ident. Throws an 
197       * exception if the airport could not be found - so callers can assume
198       * the result is non-NULL.
199       */
200      static FGAirport* getByIdent(const std::string& aIdent);
201      
202      /**
203       * Helper to look up an FGAirport instance by unique ident. Returns NULL
204       * if the airport could not be found.
205       */
206      static FGAirport* findByIdent(const std::string& aIdent);
207      
208      /**
209       * Specialised helper to implement the AirportList dialog. Performs a
210       * case-insensitive search on airport names and ICAO codes, and returns
211       * matches in a format suitable for use by a puaList. 
212       */
213      static char** searchNamesAndIdents(const std::string& aFilter);
214      
215      bool buildApproach(flightgear::Waypt* aEnroute, flightgear::STAR* aSTAR, 
216       FGRunway* aRwy, flightgear::WayptVec& aRoute);
217     
218     /**
219      * Given a destiation point, select the best SID and transition waypt from 
220      * this airport. Returns (NULL,NULL) is no SIDs are defined, otherwise the
221      * best SID/transition is that which is closest to the destination point.
222      */
223     std::pair<flightgear::SID*, flightgear::WayptRef> selectSID(const SGGeod& aDest, FGRunway* aRwy);
224     
225     /**
226      * Select a STAR and enroute transition waypt, given an origin (departure) position.
227      * returns (NULL, NULL) is no suitable STAR is exists
228      */
229     std::pair<flightgear::STAR*, flightgear::WayptRef> selectSTAR(const SGGeod& aOrigin, FGRunway* aRwy);
230     
231 private:
232     typedef std::vector<FGRunwayPtr>::const_iterator Runway_iterator;
233     /**
234      * Helper to locate a runway by ident
235      */
236     Runway_iterator getIteratorForRunwayIdent(const std::string& aIdent) const;
237
238     // disable these
239     FGAirport operator=(FGAirport &other);
240     FGAirport(const FGAirport&);
241   
242     /**
243      * helper to read airport data from the scenery XML files.
244      */
245     void loadSceneryDefinitions() const;
246     
247     /**
248      * Helpers to process property data loaded from an ICAO.threshold.xml file
249      */
250     void readThresholdData(SGPropertyNode* aRoot);
251     void processThreshold(SGPropertyNode* aThreshold);
252     
253     /**
254      * Helper to parse property data loaded from an ICAO.twr.xml filke
255      */
256     void readTowerData(SGPropertyNode* aRoot);
257     
258     SGGeod _tower_location;
259     std::string _name;
260     bool _has_metar;
261     FGAirportDynamics *_dynamics;
262
263     void loadRunways() const;
264     void loadTaxiways() const;
265     void loadProcedures() const;
266     
267     mutable bool mRunwaysLoaded;
268     mutable bool mTaxiwaysLoaded;
269     mutable bool mProceduresLoaded;
270     
271     std::vector<FGRunwayPtr> mRunways;
272     std::vector<FGTaxiwayPtr> mTaxiways;
273     std::vector<FGPavementPtr> mPavements;
274     
275     std::vector<flightgear::SID*> mSIDs;
276     std::vector<flightgear::STAR*> mSTARs;
277     std::vector<flightgear::Approach*> mApproaches;
278 };
279
280 // find basic airport location info from airport database
281 const FGAirport *fgFindAirportID( const std::string& id);
282
283 // get airport elevation
284 double fgGetAirportElev( const std::string& id );
285
286 #endif // _FG_SIMPLE_HXX
287
288