]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/positioned.hxx
7b7771b3f0b53ea444f386730901136566047f1e
[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 <string>
25 #include <vector>
26 #include <stdint.h>
27
28 #include <simgear/structure/SGSharedPtr.hxx>
29 #include <simgear/math/SGMath.hxx>
30
31 class FGPositioned;
32 typedef SGSharedPtr<FGPositioned> FGPositionedRef;
33
34 typedef int64_t PositionedID;
35 typedef std::vector<PositionedID> PositionedIDVec;
36
37 namespace flightgear { class NavDataCache; }
38
39 class FGPositioned : public SGReferenced
40 {
41 public:
42
43   typedef enum {
44     INVALID = 0,
45     AIRPORT,
46     HELIPORT,
47     SEAPORT,
48     RUNWAY,
49     TAXIWAY,
50     PAVEMENT,
51     PARK_STAND,
52     WAYPOINT,
53     FIX,
54     NDB,
55     VOR,
56     ILS,
57     LOC,
58     GS,
59     OM,
60     MM,
61     IM,
62 /// important that DME & TACAN are adjacent to keep the TacanFilter
63 /// efficient - DMEs are proxies for TACAN/VORTAC stations
64     DME,
65     TACAN,
66     MOBILE_TACAN,
67     OBSTACLE,
68 /// an actual airport tower - not a radio comms facility!
69 /// some airports have multiple towers, eg EHAM, although our data source
70 /// doesn't necessarily include them     
71     TOWER,
72     FREQ_GROUND,
73     FREQ_TOWER,
74     FREQ_ATIS,
75     FREQ_AWOS,
76     FREQ_APP_DEP,
77     FREQ_ENROUTE,
78     FREQ_CLEARANCE,
79     FREQ_UNICOM,
80     LAST_TYPE
81   } Type;
82
83   typedef std::vector<FGPositionedRef> List;
84   
85   virtual ~FGPositioned();
86   
87   Type type() const
88   { return mType; }
89
90   const std::string& ident() const
91   { return mIdent; }
92
93   /**
94    * Return the name of this positioned. By default this is the same as the
95    * ident, but for many derived classes it's more meaningful - the aiport or
96    * navaid name, for example.
97    */
98   virtual const std::string& name() const
99   { return mIdent; }
100
101   const SGGeod& geod() const
102   { return mPosition; }
103   
104   PositionedID guid() const
105   { return mGuid; }
106
107   /**
108    *  The cartesian position associated with this object
109    */
110   const SGVec3d& cart() const;
111
112   double latitude() const
113   { return mPosition.getLatitudeDeg(); }
114   
115   double longitude() const
116   { return mPosition.getLongitudeDeg(); }
117   
118   double elevation() const
119   { return mPosition.getElevationFt(); }
120   
121   /**
122    * Predicate class to support custom filtering of FGPositioned queries
123    * Default implementation of this passes any FGPositioned instance.
124    */
125   class Filter
126   {
127   public:
128     virtual ~Filter() { ; }
129     
130     /**
131      * Over-rideable filter method. Default implementation returns true.
132      */
133     virtual bool pass(FGPositioned* aPos) const
134     { return true; }
135     
136     virtual Type minType() const
137     { return INVALID; }
138     
139     virtual Type maxType() const
140     { return INVALID; }
141     
142     
143     bool operator()(FGPositioned* aPos) const
144     { return pass(aPos); }
145   };
146   
147   class TypeFilter : public Filter
148   {
149   public:
150     TypeFilter(Type aTy);
151     virtual bool pass(FGPositioned* aPos) const;
152     
153     virtual Type minType() const
154     { return mMinType; }
155     
156     virtual Type maxType() const
157     { return mMaxType; }
158     
159     void addType(Type aTy);
160   private:
161     std::vector<Type> types;
162     Type mMinType, mMaxType;
163   };
164     
165   static List findWithinRange(const SGGeod& aPos, double aRangeNm, Filter* aFilter = NULL);
166         
167   static FGPositionedRef findClosestWithIdent(const std::string& aIdent, const SGGeod& aPos, Filter* aFilter = NULL);
168
169   static FGPositionedRef findFirstWithIdent(const std::string& aIdent, Filter* aFilter = NULL);
170
171   /**
172    * Find all items with the specified ident
173    * @param aFilter - optional filter on items
174    */
175   static List findAllWithIdent(const std::string& aIdent, Filter* aFilter = NULL, bool aExact = true);
176   
177   /**
178    * As above, but searches names instead of idents
179    */
180   static List findAllWithName(const std::string& aName, Filter* aFilter = NULL, bool aExact = true);
181   
182   /**
183    * Sort an FGPositionedList by distance from a position
184    */
185   static void sortByRange(List&, const SGGeod& aPos);
186   
187   /**
188    * Find the closest item to a position, which pass the specified filter
189    * A cutoff range in NM must be specified, to constrain the search acceptably.
190    * Very large cutoff values will make this slow.
191    * 
192    * @result The closest item passing the filter, or NULL
193    * @param aCutoffNm - maximum distance to search within, in nautical miles
194    */
195   static FGPositionedRef findClosest(const SGGeod& aPos, double aCutoffNm, Filter* aFilter = NULL);
196   
197   /**
198    * Find the closest N items to a position, which pass the specified filter
199    * A cutoff range in NM must be specified, to constrain the search acceptably.
200    * Very large cutoff values will make this slow.
201    * 
202    * @result The matches (possibly less than N, depending on the filter and cutoff),
203    *    sorted by distance from the search pos
204    * @param aN - number of matches to find
205    * @param aCutoffNm - maximum distance to search within, in nautical miles
206    */
207   static List findClosestN(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter = NULL);
208   
209   /**
210    * Map a candidate type string to a real type. Returns INVALID if the string
211    * does not correspond to a defined type.
212    */
213   static Type typeFromName(const std::string& aName);
214   
215   /**
216    * Map a type to a human-readable string
217    */
218   static const char* nameForType(Type aTy);
219   
220   static FGPositioned* createUserWaypoint(const std::string& aIdent, const SGGeod& aPos);
221 protected:
222   friend class flightgear::NavDataCache;
223   
224   FGPositioned(PositionedID aGuid, Type ty, const std::string& aIdent, const SGGeod& aPos);
225     
226   void modifyPosition(const SGGeod& newPos);
227   
228   const PositionedID mGuid;
229   const SGGeod mPosition;
230   const SGVec3d mCart;
231   const Type mType;
232   const std::string mIdent;
233 };
234
235 #endif // of FG_POSITIONED_HXX