]> git.mxchange.org Git - flightgear.git/blob - src/Airports/simple.hxx
Stefan C. Müller :
[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/math/point3d.hxx>
31
32 #include <simgear/compiler.h>
33
34 #include <string>
35 #include <map>
36 #include <set>
37 #include <vector>
38
39 #include "Airports/runways.hxx"
40
41 // forward decls
42 class FGAirportDynamics;
43
44 /***************************************************************************************
45  *
46  **************************************************************************************/
47 class FGAirport {
48 private:
49     std::string _id;
50     SGGeod _location;
51     SGGeod _tower_location;
52     std::string _name;
53     bool _has_metar;
54     bool _is_airport;
55     bool _is_seaport;
56     bool _is_heliport;
57     FGAirportDynamics *_dynamics;
58
59 public:
60     FGAirport();
61     // FGAirport(const FGAirport &other);
62     FGAirport(const std::string& id, const SGGeod& location, const SGGeod& tower, 
63             const std::string& name,
64             bool has_metar, bool is_airport, bool is_seaport, bool is_heliport);
65     ~FGAirport();
66
67     const std::string& getId() const { return _id; }
68     const std::string& getName() const { return _name; }
69     double getLongitude() const { return _location.getLongitudeDeg(); }
70     // Returns degrees
71     double getLatitude()  const { return _location.getLatitudeDeg(); }
72     // Returns ft
73     double getElevation() const { return _location.getElevationFt(); }
74     bool   getMetar()     const { return _has_metar; }
75     bool   isAirport()    const { return _is_airport; }
76     bool   isSeaport()    const { return _is_seaport; }
77     bool   isHeliport()   const { return _is_heliport; }
78
79     const SGGeod& getTowerLocation() const { return _tower_location; }
80
81     void setId(const std::string& id) { _id = id; }
82     void setMetar(bool value) { _has_metar = value; }
83
84     FGRunway getActiveRunwayForUsage() const;
85
86     FGAirportDynamics *getDynamics();
87     
88     unsigned int numRunways() const;
89     FGRunway getRunwayByIndex(unsigned int aIndex) const;
90
91     bool hasRunwayWithIdent(const std::string& aIdent) const;
92     FGRunway getRunwayByIdent(const std::string& aIdent) const;
93     FGRunway findBestRunwayForHeading(double aHeading) const;
94     
95     unsigned int numTaxiways() const;
96     FGRunway getTaxiwayByIndex(unsigned int aIndex) const;
97     
98     void addRunway(const FGRunway& aRunway);
99 private:
100     /**
101      * Helper to locate a runway by ident
102      */
103     FGRunwayVector::const_iterator getIteratorForRunwayIdent(const std::string& aIdent, bool& aReversed) const;
104
105     FGAirport operator=(FGAirport &other);
106     FGAirport(const FGAirport&);
107     
108     std::vector<FGRunway> mRunways;
109     std::vector<FGRunway> mTaxiways;
110 };
111
112
113 class FGAirportSearchFilter {
114 public:
115     virtual ~FGAirportSearchFilter() {}
116     // all airports pass the filter by default
117     virtual bool pass(FGAirport*) { return true; }
118 };
119
120 class FGIdentOrdering {
121 public:
122   virtual ~FGIdentOrdering()
123   { ; }
124   
125   virtual bool compare(const std::string& aA, const std::string& aB) const
126   { return aA < aB; }
127 };
128
129 typedef std::map < std::string, FGAirport* > airport_map;
130 typedef airport_map::iterator airport_map_iterator;
131 typedef airport_map::const_iterator const_airport_map_iterator;
132
133 typedef std::vector < FGAirport * > airport_list;
134 typedef airport_list::iterator airport_list_iterator;
135 typedef airport_list::const_iterator const_airport_list_iterator;
136
137
138
139 class FGAirportList {
140 private:
141
142     airport_map airports_by_id;
143     airport_list airports_array;
144
145 public:
146     // Constructor (new)
147     FGAirportList();
148
149     // Destructor
150     ~FGAirportList();
151
152     // add an entry to the list
153     FGAirport* add( const std::string& id, const SGGeod& location, const SGGeod& tower,
154               const std::string& name, bool has_metar, bool is_airport,
155               bool is_seaport, bool is_heliport );
156
157     // search for the specified id.
158     // Returns NULL if unsucessfull.
159     FGAirport* search( const std::string& id );
160
161     // Search for the next airport in ASCII sequence to the supplied id.
162     // eg. id = "KDC" or "KDCA" would both return "KDCA".
163     // NOTE: Numbers come prior to A-Z in ASCII sequence so id = "LD" would return "LD57", not "LDDP"
164     // optional ordering can make letters come before numbers
165     // Implementation assumes airport codes are unique.
166     // Returns NULL if unsucessfull.
167     const FGAirport* findFirstById(const std::string& aIdent, FGIdentOrdering* aOrder = NULL);
168
169     // search for the airport closest to the specified position
170     // (currently a linear inefficient search so it's probably not
171     // best to use this at runtime.)  An FGAirportSearchFilter class
172     // can be used to restrict the possible choices to a subtype.
173     // max_range limits search - specified as an arc distance, in degrees
174     FGAirport* search( double lon_deg, double lat_deg, double max_range );
175     FGAirport* search( double lon_deg, double lat_deg, double max_range, FGAirportSearchFilter& );
176
177     /**
178      * Return the number of airports in the list.
179      */
180     int size() const;
181
182     /**
183      * Return a specific airport, by position.
184      */
185     const FGAirport *getAirport( unsigned int index ) const;
186
187     /**
188      * Return a pointer to the raw airport list
189      */
190     inline const airport_list* getAirportList() { return (&airports_array); }
191
192     /**
193      * Mark the specified airport record as not having metar
194      */
195     void no_metar( const std::string &id );
196
197     /**
198      * Mark the specified airport record as (yes) having metar
199      */
200     void has_metar( const std::string &id );
201
202 };
203
204 // find basic airport location info from airport database
205 const FGAirport *fgFindAirportID( const std::string& id);
206
207 // get airport elevation
208 double fgGetAirportElev( const std::string& id );
209
210 // get airport position
211 Point3D fgGetAirportPos( const std::string& id );
212
213 #endif // _FG_SIMPLE_HXX
214
215