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