]> git.mxchange.org Git - flightgear.git/blob - src/Airports/simple.hxx
fix warnings in Multiplayer, Scripting, and Time
[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 class FGTaxiway;
41 class FGPavement;
42
43 typedef SGSharedPtr<FGRunway> FGRunwayPtr;
44 typedef SGSharedPtr<FGTaxiway> FGTaxiwayPtr;
45 typedef SGSharedPtr<FGPavement> FGPavementPtr;
46
47 /***************************************************************************************
48  *
49  **************************************************************************************/
50 class FGAirport : public FGPositioned
51 {
52 private:
53     SGGeod _tower_location;
54     std::string _name;
55     bool _has_metar;
56     FGAirportDynamics *_dynamics;
57
58 public:
59     FGAirport(const std::string& id, const SGGeod& location, const SGGeod& tower, 
60             const std::string& name, bool has_metar, Type aType);
61     ~FGAirport();
62
63     const std::string& getId() const { return ident(); }
64     const std::string& getName() const { return _name; }
65     double getLongitude() const { return longitude(); }
66     // Returns degrees
67     double getLatitude()  const { return latitude(); }
68     // Returns ft
69     double getElevation() const { return elevation(); }
70     bool   getMetar()     const { return _has_metar; }
71     bool   isAirport()    const;
72     bool   isSeaport()    const;
73     bool   isHeliport()   const;
74
75     virtual const std::string& name() const
76     { return _name; }
77
78     const SGGeod& getTowerLocation() const { return _tower_location; }
79
80     void setMetar(bool value) { _has_metar = value; }
81
82     FGRunway* getActiveRunwayForUsage() const;
83
84     FGAirportDynamics *getDynamics();
85     
86     unsigned int numRunways() const;
87     FGRunway* getRunwayByIndex(unsigned int aIndex) const;
88
89     bool hasRunwayWithIdent(const std::string& aIdent) const;
90     FGRunway* getRunwayByIdent(const std::string& aIdent) const;
91     FGRunway* findBestRunwayForHeading(double aHeading) const;
92     
93      /**
94      * Useful predicate for FMS/GPS/NAV displays and similar - check if this
95      * aiport has a hard-surfaced runway of at least the specified length.
96      */
97     bool hasHardRunwayOfLengthFt(double aLengthFt) const;
98
99     unsigned int numTaxiways() const;
100     FGTaxiway* getTaxiwayByIndex(unsigned int aIndex) const;
101
102     unsigned int numPavements() const;
103     FGPavement* getPavementByIndex(unsigned int aIndex) const;
104
105     void setRunwaysAndTaxiways(std::vector<FGRunwayPtr>& rwys,
106       std::vector<FGTaxiwayPtr>& txwys,
107       std::vector<FGPavementPtr>& pvts);
108     
109     class AirportFilter : public Filter
110      {
111      public:
112        virtual bool pass(FGPositioned* aPos) const { 
113          return passAirport(static_cast<FGAirport*>(aPos));
114        }
115        
116        virtual Type minType() const {
117          return AIRPORT;
118        }
119        
120        virtual Type maxType() const {
121          return SEAPORT;
122        }
123        
124        virtual bool passAirport(FGAirport* aApt) const {
125          return true;
126        }
127      };
128      
129      class HardSurfaceFilter : public AirportFilter
130      {
131      public:
132        HardSurfaceFilter(double minLengthFt);
133        
134        virtual bool passAirport(FGAirport* aApt) const;
135        
136        virtual Type maxType() const {
137          return AIRPORT;
138        }
139      private:
140        double mMinLengthFt;
141      };
142      
143      /**
144       * Syntactic wrapper around FGPositioned::findClosest - find the closest
145       * match for filter, and return it cast to FGAirport. The default filter
146       * passes all airports, including seaports and heliports.
147       */
148      static FGAirport* findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter = NULL);
149      
150      /**
151       * Helper to look up an FGAirport instance by unique ident. Throws an 
152       * exception if the airport could not be found - so callers can assume
153       * the result is non-NULL.
154       */
155      static FGAirport* getByIdent(const std::string& aIdent);
156      
157      /**
158       * Helper to look up an FGAirport instance by unique ident. Returns NULL
159       * if the airport could not be found.
160       */
161      static FGAirport* findByIdent(const std::string& aIdent);
162      
163      /**
164       * Specialised helper to implement the AirportList dialog. Performs a
165       * case-insensitive search on airport names and ICAO codes, and returns
166       * matches in a format suitable for use by a puaList. 
167       */
168      static char** searchNamesAndIdents(const std::string& aFilter);
169 private:
170     typedef std::vector<FGRunwayPtr>::const_iterator Runway_iterator;
171     /**
172      * Helper to locate a runway by ident
173      */
174     Runway_iterator getIteratorForRunwayIdent(const std::string& aIdent) const;
175
176     FGAirport operator=(FGAirport &other);
177     FGAirport(const FGAirport&);
178     
179     std::vector<FGRunwayPtr> mRunways;
180     std::vector<FGTaxiwayPtr> mTaxiways;
181     std::vector<FGPavementPtr> mPavements;
182 };
183
184 // find basic airport location info from airport database
185 const FGAirport *fgFindAirportID( const std::string& id);
186
187 // get airport elevation
188 double fgGetAirportElev( const std::string& id );
189
190 #endif // _FG_SIMPLE_HXX
191
192