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