]> git.mxchange.org Git - flightgear.git/blob - src/Airports/simple.hxx
Remove the FGIdentOrdering cruft from FGAirport; now handled by FGPositioned.
[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 <map>
34 #include <set>
35 #include <vector>
36
37 #include <simgear/math/point3d.hxx>
38 #include "Navaids/positioned.hxx"
39
40 // forward decls
41 class FGAirportDynamics;
42 class FGRunway;
43
44 typedef SGSharedPtr<FGRunway> FGRunwayPtr;
45
46 /***************************************************************************************
47  *
48  **************************************************************************************/
49 class FGAirport : public FGPositioned
50 {
51 private:
52     SGGeod _tower_location;
53     std::string _name;
54     bool _has_metar;
55     FGAirportDynamics *_dynamics;
56
57 public:
58     FGAirport(const std::string& id, const SGGeod& location, const SGGeod& tower, 
59             const std::string& name, bool has_metar, Type aType);
60     ~FGAirport();
61
62     const std::string& getId() const { return ident(); }
63     const std::string& getName() const { return _name; }
64     double getLongitude() const { return longitude(); }
65     // Returns degrees
66     double getLatitude()  const { return latitude(); }
67     // Returns ft
68     double getElevation() const { return elevation(); }
69     bool   getMetar()     const { return _has_metar; }
70     bool   isAirport()    const;
71     bool   isSeaport()    const;
72     bool   isHeliport()   const;
73
74     const SGGeod& getTowerLocation() const { return _tower_location; }
75
76     void setMetar(bool value) { _has_metar = value; }
77
78     FGRunway* getActiveRunwayForUsage() const;
79
80     FGAirportDynamics *getDynamics();
81     
82     unsigned int numRunways() const;
83     FGRunway* getRunwayByIndex(unsigned int aIndex) const;
84
85     bool hasRunwayWithIdent(const std::string& aIdent) const;
86     FGRunway* getRunwayByIdent(const std::string& aIdent) const;
87     FGRunway* findBestRunwayForHeading(double aHeading) const;
88     
89      /**
90      * Useful predicate for FMS/GPS/NAV displays and similar - check if this
91      * aiport has a hard-surfaced runway of at least the specified length.
92      * For the moment, hard means asphalt or concrete, not gravel or a
93      * lake bed.
94      */
95     bool hasHardRunwayOfLengthFt(double aLengthFt) const;
96     
97     unsigned int numTaxiways() const;
98     FGRunway* getTaxiwayByIndex(unsigned int aIndex) const;
99     
100     void addRunway(FGRunway* aRunway);
101     
102     class AirportFilter : public Filter
103      {
104      public:
105        virtual bool pass(FGPositioned* aPos) const { 
106          Type ty(aPos->type());
107          return (ty >= AIRPORT) && (ty <= SEAPORT);
108        }
109      };
110      
111      class HardSurfaceFilter : public Filter
112      {
113      public:
114        HardSurfaceFilter(double minLengthFt);
115        
116        virtual bool pass(FGPositioned* aPos) const;
117      private:
118        double mMinLengthFt;
119      };
120      
121      /**
122       * Syntactic wrapper around FGPositioned::findClosest - find the closest
123       * match for filter, and return it cast to FGAirport. The default filter
124       * passes all airports, including seaports and heliports.
125       */
126      static FGAirport* findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
127 private:
128     typedef std::vector<FGRunwayPtr>::const_iterator Runway_iterator;
129     /**
130      * Helper to locate a runway by ident
131      */
132     Runway_iterator getIteratorForRunwayIdent(const std::string& aIdent) const;
133
134     FGAirport operator=(FGAirport &other);
135     FGAirport(const FGAirport&);
136     
137     std::vector<FGRunwayPtr> mRunways;
138     std::vector<FGRunwayPtr> mTaxiways;
139 };
140
141
142 class FGAirportSearchFilter {
143 public:
144     virtual ~FGAirportSearchFilter() {}
145     // all airports pass the filter by default
146     virtual bool pass(FGAirport*) { return true; }
147 };
148
149 typedef std::map < std::string, FGAirport* > airport_map;
150 typedef airport_map::iterator airport_map_iterator;
151 typedef airport_map::const_iterator const_airport_map_iterator;
152
153 typedef std::vector < FGAirport * > airport_list;
154 typedef airport_list::iterator airport_list_iterator;
155 typedef airport_list::const_iterator const_airport_list_iterator;
156
157
158
159 class FGAirportList {
160 private:
161
162     airport_map airports_by_id;
163     airport_list airports_array;
164
165 public:
166     // Constructor (new)
167     FGAirportList();
168
169     // Destructor
170     ~FGAirportList();
171
172     // add an entry to the list
173     FGAirport* add( const std::string& id, const SGGeod& location, const SGGeod& tower,
174               const std::string& name, bool has_metar, FGPositioned::Type aType);
175
176     // search for the specified id.
177     // Returns NULL if unsucessfull.
178     FGAirport* search( const std::string& id );
179
180     // search for the airport closest to the specified position
181     // (currently a linear inefficient search so it's probably not
182     // best to use this at runtime.)  An FGAirportSearchFilter class
183     // can be used to restrict the possible choices to a subtype.
184     // max_range limits search - specified as an arc distance, in degrees
185     FGAirport* search( double lon_deg, double lat_deg, double max_range );
186     FGAirport* search( double lon_deg, double lat_deg, double max_range, FGAirportSearchFilter& );
187
188     /**
189      * Return the number of airports in the list.
190      */
191     int size() const;
192
193     /**
194      * Return a specific airport, by position.
195      */
196     const FGAirport *getAirport( unsigned int index ) const;
197
198     /**
199      * Mark the specified airport record as not having metar
200      */
201     void no_metar( const std::string &id );
202
203     /**
204      * Mark the specified airport record as (yes) having metar
205      */
206     void has_metar( const std::string &id );
207
208 };
209
210 // find basic airport location info from airport database
211 const FGAirport *fgFindAirportID( const std::string& id);
212
213 // get airport elevation
214 double fgGetAirportElev( const std::string& id );
215
216 // get airport position
217 Point3D fgGetAirportPos( const std::string& id );
218
219 #endif // _FG_SIMPLE_HXX
220
221