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