]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/positioned.hxx
James Turner : this patch
[flightgear.git] / src / Navaids / positioned.hxx
1 // positioned.hxx - base class for objects which are positioned 
2 //
3 // Copyright (C) 2008 James Turner
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 //
19 // $Id$
20
21 #ifndef FG_POSITIONED_HXX
22 #define FG_POSITIONED_HXX
23
24 #include <vector>
25
26 #include <simgear/structure/SGSharedPtr.hxx>
27 #include <simgear/bucket/newbucket.hxx>
28
29 class FGPositioned;
30
31 typedef SGSharedPtr<FGPositioned> FGPositionedRef;
32
33 class FGPositioned : public SGReferenced
34 {
35 public:
36
37   typedef enum {
38     INVALID = 0,
39     AIRPORT,
40     HELIPORT,
41     SEAPORT,
42     RUNWAY,
43     TAXIWAY,
44     PARK_STAND,
45     FIX,
46     VOR,
47     NDB,
48     ILS,
49     LOC,
50     GS,
51     OM,
52     MM,
53     IM,
54     DME,
55     TACAN,
56     OBSTACLE,
57     WAYPOINT, // user-defined waypoint
58     FREQ_GND,
59     FREQ_TWR,
60     FREQ_ATIS,
61     LAST_TYPE
62   } Type;
63
64   typedef std::vector<FGPositionedRef> List;
65   
66   virtual ~FGPositioned();
67   
68   Type type() const
69   { return mType; }
70
71   const std::string& ident() const
72   { return mIdent; }
73
74   /**
75    * Return the name of this positioned. By default this is the same as the
76    * ident, but for many derived classes it's more meaningful - the aiport or
77    * navaid name, for example.
78    */
79   virtual const std::string& name() const
80   { return mIdent; }
81
82   const SGGeod& geod() const
83   { return mPosition; }
84
85   SGBucket bucket() const;
86   
87   double latitude() const
88   { return mPosition.getLatitudeDeg(); }
89   
90   double longitude() const
91   { return mPosition.getLongitudeDeg(); }
92   
93   double elevation() const
94   { return mPosition.getElevationFt(); }
95   
96   /**
97    * Predicate class to support custom filtering of FGPositioned queries
98    * Default implementation of this passes any FGPositioned instance.
99    */
100   class Filter
101   {
102   public:
103     virtual ~Filter() { ; }
104     
105     /**
106      * Over-rideable filter method. Default implementation returns true.
107      */
108     virtual bool pass(FGPositioned* aPos) const
109     { return true; }
110     
111     bool operator()(FGPositioned* aPos) const
112     { return pass(aPos); }
113   };
114   
115   class TypeFilter : public Filter
116   {
117   public:
118     TypeFilter(Type aTy) : mType(aTy) { ; }
119     virtual bool pass(FGPositioned* aPos) const
120     { return (mType == aPos->type()); }
121   private:
122     const Type mType;
123   };
124   
125   static List findWithinRange(const SGGeod& aPos, double aRangeNm, Filter* aFilter = NULL);
126         
127   static FGPositionedRef findClosestWithIdent(const std::string& aIdent, const SGGeod& aPos, Filter* aFilter = NULL);
128   
129   /**
130    * Find the next item with the specified partial ID, after the 'current' item
131    * Note this function is not hyper-efficient, particular where the partial id
132    * spans a large number of candidates.
133    *
134    * @param aCur - Current item, or NULL to retrieve the first item with partial id
135    * @param aId - the (partial) id to lookup
136    */
137   static FGPositionedRef findNextWithPartialId(FGPositionedRef aCur, const std::string& aId, Filter* aFilter = NULL);
138   
139   /**
140    * Find all items with the specified ident, and return then sorted by
141    * distance from a position
142    *
143    * @param aFilter - optional filter on items
144    */
145   static List findAllWithIdentSortedByRange(const std::string& aIdent, const SGGeod& aPos, Filter* aFilter = NULL);
146   
147   /**
148    * Find the closest item to a position, which pass the specified filter
149    * A cutoff range in NM must be specified, to constrain the search acceptably.
150    * Very large cutoff values will make this slow.
151    * 
152    * @result The closest item passing the filter, or NULL
153    * @param aCutoffNm - maximum distance to search within, in nautical miles
154    */
155   static FGPositionedRef findClosest(const SGGeod& aPos, double aCutoffNm, Filter* aFilter = NULL);
156   
157   /**
158    * Find the closest N items to a position, which pass the specified filter
159    * A cutoff range in NM must be specified, to constrain the search acceptably.
160    * Very large cutoff values will make this slow.
161    * 
162    * @result The matches (possibly less than N, depending on the filter and cutoff),
163   *    sorted by distance from the search pos
164    * @param aN - number of matches to find
165    * @param aCutoffNm - maximum distance to search within, in nautical miles
166    */
167   static List findClosestN(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter = NULL);
168   
169   
170   
171   /**
172    * Debug helper, map a type to a human-readable string
173    */
174   static const char* nameForType(Type aTy);
175 protected:
176   FGPositioned(Type ty, const std::string& aIdent, double aLat, double aLon, double aElev);
177   
178   FGPositioned(Type ty, const std::string& aIdent, const SGGeod& aPos);
179   
180   SGGeod mPosition; // can't be const right now
181   
182   Type mType;
183   std::string mIdent;
184 };
185
186 #endif // of FG_POSITIONED_HXX