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