]> git.mxchange.org Git - flightgear.git/blob - src/Airports/simple.hxx
Another clean-up iteration: FGAirportList::search is gone, replaced by two
[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
41 typedef SGSharedPtr<FGRunway> FGRunwayPtr;
42
43 /***************************************************************************************
44  *
45  **************************************************************************************/
46 class FGAirport : public FGPositioned
47 {
48 private:
49     SGGeod _tower_location;
50     std::string _name;
51     bool _has_metar;
52     FGAirportDynamics *_dynamics;
53
54 public:
55     FGAirport(const std::string& id, const SGGeod& location, const SGGeod& tower, 
56             const std::string& name, bool has_metar, Type aType);
57     ~FGAirport();
58
59     const std::string& getId() const { return ident(); }
60     const std::string& getName() const { return _name; }
61     double getLongitude() const { return longitude(); }
62     // Returns degrees
63     double getLatitude()  const { return latitude(); }
64     // Returns ft
65     double getElevation() const { return elevation(); }
66     bool   getMetar()     const { return _has_metar; }
67     bool   isAirport()    const;
68     bool   isSeaport()    const;
69     bool   isHeliport()   const;
70
71     virtual const std::string& name() const
72     { return _name; }
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      */
93     bool hasHardRunwayOfLengthFt(double aLengthFt) const;
94     
95     unsigned int numTaxiways() const;
96     FGRunway* getTaxiwayByIndex(unsigned int aIndex) const;
97     
98     void addRunway(FGRunway* aRunway);
99     
100     class AirportFilter : public Filter
101      {
102      public:
103        virtual bool pass(FGPositioned* aPos) const { 
104          Type ty(aPos->type());
105          return (ty >= AIRPORT) && (ty <= SEAPORT);
106        }
107      };
108      
109      class HardSurfaceFilter : public Filter
110      {
111      public:
112        HardSurfaceFilter(double minLengthFt);
113        
114        virtual bool pass(FGPositioned* aPos) const;
115      private:
116        double mMinLengthFt;
117      };
118      
119      /**
120       * Syntactic wrapper around FGPositioned::findClosest - find the closest
121       * match for filter, and return it cast to FGAirport. The default filter
122       * passes all airports, including seaports and heliports.
123       */
124      static FGAirport* findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
125      
126      /**
127       * Helper to look up an FGAirport instance by unique ident. Throws an 
128       * exception if the airport could not be found - so callers can assume
129       * the result is non-NULL.
130       */
131      static FGAirport* getByIdent(const std::string& aIdent);
132      
133      /**
134       * Helper to look up an FGAirport instance by unique ident. Returns NULL
135       * if the airport could not be found.
136       */
137      static FGAirport* findByIdent(const std::string& aIdent);
138      
139      /**
140       * Specialised helper to implement the AirportList dialog. Performs a
141       * case-insensitive search on airport names and ICAO codes, and returns
142       * matches in a format suitable for use by a puaList. 
143       */
144      static char** searchNamesAndIdents(const std::string& aFilter);
145 private:
146     typedef std::vector<FGRunwayPtr>::const_iterator Runway_iterator;
147     /**
148      * Helper to locate a runway by ident
149      */
150     Runway_iterator getIteratorForRunwayIdent(const std::string& aIdent) const;
151
152     FGAirport operator=(FGAirport &other);
153     FGAirport(const FGAirport&);
154     
155     std::vector<FGRunwayPtr> mRunways;
156     std::vector<FGRunwayPtr> mTaxiways;
157 };
158
159 typedef std::vector < FGAirport * > airport_list;
160 typedef airport_list::iterator airport_list_iterator;
161 typedef airport_list::const_iterator const_airport_list_iterator;
162
163
164
165 class FGAirportList {
166 private:
167
168     airport_list airports_array;
169
170 public:
171     // Constructor (new)
172     FGAirportList();
173
174     // Destructor
175     ~FGAirportList();
176
177     // add an entry to the list
178     FGAirport* add( const std::string& id, const SGGeod& location, const SGGeod& tower,
179               const std::string& name, bool has_metar, FGPositioned::Type aType);
180
181     /**
182      * Return the number of airports in the list.
183      */
184     int size() const;
185
186     /**
187      * Return a specific airport, by position.
188      */
189     const FGAirport *getAirport( unsigned int index ) const;
190
191 };
192
193 // find basic airport location info from airport database
194 const FGAirport *fgFindAirportID( const std::string& id);
195
196 // get airport elevation
197 double fgGetAirportElev( const std::string& id );
198
199 #endif // _FG_SIMPLE_HXX
200
201