]> git.mxchange.org Git - flightgear.git/blob - src/Airports/simple.hxx
Merge branch 'next' of gitorious.org:fg/flightgear into next
[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 /***************************************************************************************
49  *
50  **************************************************************************************/
51 class FGAirport : public FGPositioned
52 {
53 public:
54     FGAirport(const std::string& id, const SGGeod& location, const SGGeod& tower, 
55             const std::string& name, bool has_metar, Type aType);
56     ~FGAirport();
57
58     const std::string& getId() const { return ident(); }
59     const std::string& getName() const { return _name; }
60     double getLongitude() const { return longitude(); }
61     // Returns degrees
62     double getLatitude()  const { return latitude(); }
63     // Returns ft
64     double getElevation() const { return elevation(); }
65     bool   getMetar()     const { return _has_metar; }
66     bool   isAirport()    const;
67     bool   isSeaport()    const;
68     bool   isHeliport()   const;
69
70     virtual const std::string& name() const
71     { return _name; }
72
73     const SGGeod& getTowerLocation() const { return _tower_location; }
74
75     void setMetar(bool value) { _has_metar = value; }
76
77     FGRunway* getActiveRunwayForUsage() const;
78
79     FGAirportDynamics *getDynamics();
80     
81     unsigned int numRunways() const;
82     FGRunway* getRunwayByIndex(unsigned int aIndex) const;
83
84     bool hasRunwayWithIdent(const std::string& aIdent) const;
85     FGRunway* getRunwayByIdent(const std::string& aIdent) const;
86     FGRunway* findBestRunwayForHeading(double aHeading) const;
87     
88      /**
89      * Useful predicate for FMS/GPS/NAV displays and similar - check if this
90      * aiport has a hard-surfaced runway of at least the specified length.
91      */
92     bool hasHardRunwayOfLengthFt(double aLengthFt) const;
93
94     unsigned int numTaxiways() const;
95     FGTaxiway* getTaxiwayByIndex(unsigned int aIndex) const;
96
97     unsigned int numPavements() const;
98     FGPavement* getPavementByIndex(unsigned int aIndex) const;
99
100     void setRunwaysAndTaxiways(std::vector<FGRunwayPtr>& rwys,
101       std::vector<FGTaxiwayPtr>& txwys,
102       std::vector<FGPavementPtr>& pvts);
103     
104     class AirportFilter : public Filter
105      {
106      public:
107        virtual bool pass(FGPositioned* aPos) const { 
108          return passAirport(static_cast<FGAirport*>(aPos));
109        }
110        
111        virtual Type minType() const {
112          return AIRPORT;
113        }
114        
115        virtual Type maxType() const {
116          return AIRPORT;
117        }
118        
119        virtual bool passAirport(FGAirport* aApt) const {
120          return true;
121        }
122      };
123      
124      /**
125       * Filter which passes heliports and seaports in addition to airports
126       */
127      class PortsFilter : public AirportFilter
128      {
129      public:
130        virtual Type maxType() const {
131          return SEAPORT;
132        }
133      };
134      
135      class HardSurfaceFilter : public AirportFilter
136      {
137      public:
138        HardSurfaceFilter(double minLengthFt);
139        
140        virtual bool passAirport(FGAirport* aApt) const;
141        
142      private:
143        double mMinLengthFt;
144      };
145      
146      /**
147       * Syntactic wrapper around FGPositioned::findClosest - find the closest
148       * match for filter, and return it cast to FGAirport. The default filter
149       * passes airports, but not seaports or heliports
150       */
151      static FGAirport* findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
152      
153      /**
154       * Helper to look up an FGAirport instance by unique ident. Throws an 
155       * exception if the airport could not be found - so callers can assume
156       * the result is non-NULL.
157       */
158      static FGAirport* getByIdent(const std::string& aIdent);
159      
160      /**
161       * Helper to look up an FGAirport instance by unique ident. Returns NULL
162       * if the airport could not be found.
163       */
164      static FGAirport* findByIdent(const std::string& aIdent);
165      
166      /**
167       * Specialised helper to implement the AirportList dialog. Performs a
168       * case-insensitive search on airport names and ICAO codes, and returns
169       * matches in a format suitable for use by a puaList. 
170       */
171      static char** searchNamesAndIdents(const std::string& aFilter);
172 private:
173     typedef std::vector<FGRunwayPtr>::const_iterator Runway_iterator;
174     /**
175      * Helper to locate a runway by ident
176      */
177     Runway_iterator getIteratorForRunwayIdent(const std::string& aIdent) const;
178
179     // disable these
180     FGAirport operator=(FGAirport &other);
181     FGAirport(const FGAirport&);
182   
183     /**
184      * helper to read airport data from the scenery XML files.
185      */
186     void loadSceneryDefintions() const;
187     
188     /**
189      * Helpers to process property data loaded from an ICAO.threshold.xml file
190      */
191     void readThresholdData(SGPropertyNode* aRoot);
192     void processThreshold(SGPropertyNode* aThreshold);
193     
194     /**
195      * Helper to parse property data loaded from an ICAO.twr.xml filke
196      */
197     void readTowerData(SGPropertyNode* aRoot);
198     
199     SGGeod _tower_location;
200     std::string _name;
201     bool _has_metar;
202     FGAirportDynamics *_dynamics;
203
204     void loadRunways() const;
205     void loadTaxiways() const;
206     
207     mutable bool mRunwaysLoaded;
208     mutable bool mTaxiwaysLoaded;
209     
210     std::vector<FGRunwayPtr> mRunways;
211     std::vector<FGTaxiwayPtr> mTaxiways;
212     std::vector<FGPavementPtr> mPavements;
213 };
214
215 // find basic airport location info from airport database
216 const FGAirport *fgFindAirportID( const std::string& id);
217
218 // get airport elevation
219 double fgGetAirportElev( const std::string& id );
220
221 #endif // _FG_SIMPLE_HXX
222
223