]> git.mxchange.org Git - flightgear.git/blob - src/Airports/simple.hxx
toggle fullscreen: also adapt GUI plane when resizing
[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 namespace flightgear {
45   class SID;
46   class STAR;
47   class Approach;
48   class Waypt;
49   class CommStation;
50
51   typedef SGSharedPtr<Waypt> WayptRef;
52   typedef std::vector<WayptRef> WayptVec;
53   
54   typedef std::vector<CommStation*> CommStationList;
55 }
56
57
58
59 /***************************************************************************************
60  *
61  **************************************************************************************/
62 class FGAirport : public FGPositioned
63 {
64 public:
65     FGAirport(PositionedID aGuid, const std::string& id, const SGGeod& location,
66             const std::string& name, bool has_metar, Type aType);
67     ~FGAirport();
68
69     const std::string& getId() const { return ident(); }
70     const std::string& getName() const { return _name; }
71     double getLongitude() const { return longitude(); }
72     // Returns degrees
73     double getLatitude()  const { return latitude(); }
74     // Returns ft
75     double getElevation() const { return elevation(); }
76     bool   getMetar()     const { return _has_metar; }
77     bool   isAirport()    const;
78     bool   isSeaport()    const;
79     bool   isHeliport()   const;
80
81     static bool isAirportType(FGPositioned* pos);
82     
83     virtual const std::string& name() const
84     { return _name; }
85
86     /**
87      * reload the ILS data from XML if required.
88      * @result true if the data was refreshed, false if no data was loaded
89      * or previously cached data is still correct.
90      */
91     bool validateILSData();
92
93     SGGeod getTowerLocation() const;
94
95     void setMetar(bool value) { _has_metar = value; }
96
97     FGRunway* getActiveRunwayForUsage() const;
98
99     FGAirportDynamics *getDynamics();
100     
101     unsigned int numRunways() const;
102     FGRunway* getRunwayByIndex(unsigned int aIndex) const;
103
104     bool hasRunwayWithIdent(const std::string& aIdent) const;
105     FGRunway* getRunwayByIdent(const std::string& aIdent) const;
106     FGRunway* findBestRunwayForHeading(double aHeading) const;
107     
108     /**
109      * return the most likely target runway based on a position.
110      * Specifically, return the runway for which the course from aPos
111      * to the runway end, mostly closely matches the runway heading.
112      * This is a good approximation of which runway the position is on or
113      * aiming towards.
114      */
115     FGRunway* findBestRunwayForPos(const SGGeod& aPos) const;
116     
117      /**
118      * Useful predicate for FMS/GPS/NAV displays and similar - check if this
119      * aiport has a hard-surfaced runway of at least the specified length.
120      */
121     bool hasHardRunwayOfLengthFt(double aLengthFt) const;
122
123     unsigned int numTaxiways() const;
124     FGTaxiway* getTaxiwayByIndex(unsigned int aIndex) const;
125
126     unsigned int numPavements() const;
127     FGPavement* getPavementByIndex(unsigned int aIndex) const;
128     
129     class AirportFilter : public Filter
130      {
131      public:
132        virtual bool pass(FGPositioned* aPos) const { 
133          return passAirport(static_cast<FGAirport*>(aPos));
134        }
135        
136        virtual Type minType() const {
137          return AIRPORT;
138        }
139        
140        virtual Type maxType() const {
141          return AIRPORT;
142        }
143        
144        virtual bool passAirport(FGAirport* aApt) const {
145          return true;
146        }
147      };
148      
149      /**
150       * Filter which passes heliports and seaports in addition to airports
151       */
152      class PortsFilter : public AirportFilter
153      {
154      public:
155        virtual Type maxType() const {
156          return SEAPORT;
157        }
158      };
159      
160      class HardSurfaceFilter : public AirportFilter
161      {
162      public:
163        HardSurfaceFilter(double minLengthFt = -1);
164        
165        virtual bool passAirport(FGAirport* aApt) const;
166        
167      private:
168        double mMinLengthFt;
169      };
170      
171      
172      void setProcedures(const std::vector<flightgear::SID*>& aSids,
173       const std::vector<flightgear::STAR*>& aStars,
174       const std::vector<flightgear::Approach*>& aApproaches);
175      
176      void addSID(flightgear::SID* aSid);
177       void addSTAR(flightgear::STAR* aStar);
178       void addApproach(flightgear::Approach* aApp);
179
180       unsigned int numSIDs() const;
181       flightgear::SID* getSIDByIndex(unsigned int aIndex) const;
182       flightgear::SID* findSIDWithIdent(const std::string& aIdent) const;
183       
184       unsigned int numSTARs() const;
185       flightgear::STAR* getSTARByIndex(unsigned int aIndex) const;
186       flightgear::STAR* findSTARWithIdent(const std::string& aIdent) const;
187       
188       unsigned int numApproaches() const;
189       flightgear::Approach* getApproachByIndex(unsigned int aIndex) const;
190       flightgear::Approach* findApproachWithIdent(const std::string& aIdent) const;
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     flightgear::CommStationList commStationsOfType(FGPositioned::Type aTy) const;
220     
221     flightgear::CommStationList commStations() const;
222 private:
223     // disable these
224     FGAirport operator=(FGAirport &other);
225     FGAirport(const FGAirport&);
226   
227     /**
228      * helper to read airport data from the scenery XML files.
229      */
230     void loadSceneryDefinitions() const;
231     
232     /**
233      * Helpers to process property data loaded from an ICAO.threshold.xml file
234      */
235     void readThresholdData(SGPropertyNode* aRoot);
236     void processThreshold(SGPropertyNode* aThreshold);
237       
238     void readILSData(SGPropertyNode* aRoot);
239   
240     void validateTowerData() const;
241     
242     /**
243      * Helper to parse property data loaded from an ICAO.twr.xml filke
244      */
245     void readTowerData(SGPropertyNode* aRoot);
246     
247     std::string _name;
248     bool _has_metar;
249     FGAirportDynamics *_dynamics;
250
251     void loadRunways() const;
252     void loadTaxiways() const;
253     void loadProcedures() const;
254     
255     mutable bool mTowerDataLoaded;
256     mutable bool mRunwaysLoaded;
257     mutable bool mTaxiwaysLoaded;
258     mutable bool mProceduresLoaded;
259     bool mILSDataLoaded;
260   
261     mutable PositionedIDVec mRunways;
262     mutable PositionedIDVec mTaxiways;
263     PositionedIDVec mPavements;
264     
265     typedef SGSharedPtr<flightgear::SID> SIDRef;
266     typedef SGSharedPtr<flightgear::STAR> STARRef;
267     typedef SGSharedPtr<flightgear::Approach> ApproachRef;
268     
269     std::vector<SIDRef> mSIDs;
270     std::vector<STARRef> mSTARs;
271     std::vector<ApproachRef> mApproaches;
272   };
273
274 // find basic airport location info from airport database
275 const FGAirport *fgFindAirportID( const std::string& id);
276
277 // get airport elevation
278 double fgGetAirportElev( const std::string& id );
279
280 #endif // _FG_SIMPLE_HXX
281
282