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