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