]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/positioned.hxx
MapWidget: make use of the new POI system and display cities on the map.
[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     VILLAGE,
89       
90     LAST_TYPE
91   } Type;
92
93   typedef std::vector<FGPositionedRef> List;
94   
95   virtual ~FGPositioned();
96   
97   Type type() const
98   { return mType; }
99
100   const std::string& ident() const
101   { return mIdent; }
102
103   /**
104    * Return the name of this positioned. By default this is the same as the
105    * ident, but for many derived classes it's more meaningful - the aiport or
106    * navaid name, for example.
107    */
108   virtual const std::string& name() const
109   { return mIdent; }
110
111   const SGGeod& geod() const
112   { return mPosition; }
113   
114   PositionedID guid() const
115   { return mGuid; }
116
117   /**
118    *  The cartesian position associated with this object
119    */
120   const SGVec3d& cart() const;
121
122   double latitude() const
123   { return mPosition.getLatitudeDeg(); }
124   
125   double longitude() const
126   { return mPosition.getLongitudeDeg(); }
127   
128   double elevation() const
129   { return mPosition.getElevationFt(); }
130   
131   /**
132    * Predicate class to support custom filtering of FGPositioned queries
133    * Default implementation of this passes any FGPositioned instance.
134    */
135   class Filter
136   {
137   public:
138     virtual ~Filter() { ; }
139     
140     /**
141      * Over-rideable filter method. Default implementation returns true.
142      */
143     virtual bool pass(FGPositioned* aPos) const
144     { return true; }
145     
146     virtual Type minType() const
147     { return INVALID; }
148     
149     virtual Type maxType() const
150     { return INVALID; }
151     
152     
153     bool operator()(FGPositioned* aPos) const
154     { return pass(aPos); }
155   };
156   
157   class TypeFilter : public Filter
158   {
159   public:
160     TypeFilter(Type aTy);
161     virtual bool pass(FGPositioned* aPos) const;
162     
163     virtual Type minType() const
164     { return mMinType; }
165     
166     virtual Type maxType() const
167     { return mMaxType; }
168     
169     void addType(Type aTy);
170   private:
171     std::vector<Type> types;
172     Type mMinType, mMaxType;
173   };
174   
175   static List findWithinRange(const SGGeod& aPos, double aRangeNm, Filter* aFilter = NULL);
176   
177   static List findWithinRangePartial(const SGGeod& aPos, double aRangeNm, Filter* aFilter, bool& aPartial);
178         
179   static FGPositionedRef findClosestWithIdent(const std::string& aIdent, const SGGeod& aPos, Filter* aFilter = NULL);
180
181   static FGPositionedRef findFirstWithIdent(const std::string& aIdent, Filter* aFilter = NULL);
182
183   /**
184    * Find all items with the specified ident
185    * @param aFilter - optional filter on items
186    */
187   static List findAllWithIdent(const std::string& aIdent, Filter* aFilter = NULL, bool aExact = true);
188   
189   /**
190    * As above, but searches names instead of idents
191    */
192   static List findAllWithName(const std::string& aName, Filter* aFilter = NULL, bool aExact = true);
193   
194   /**
195    * Sort an FGPositionedList by distance from a position
196    */
197   static void sortByRange(List&, const SGGeod& aPos);
198   
199   /**
200    * Find the closest item to a position, which pass the specified filter
201    * A cutoff range in NM must be specified, to constrain the search acceptably.
202    * Very large cutoff values will make this slow.
203    * 
204    * @result The closest item passing the filter, or NULL
205    * @param aCutoffNm - maximum distance to search within, in nautical miles
206    */
207   static FGPositionedRef findClosest(const SGGeod& aPos, double aCutoffNm, Filter* aFilter = NULL);
208   
209   /**
210    * Find the closest N items to a position, which pass the specified filter
211    * A cutoff range in NM must be specified, to constrain the search acceptably.
212    * Very large cutoff values will make this slow.
213    * 
214    * @result The matches (possibly less than N, depending on the filter and cutoff),
215    *    sorted by distance from the search pos
216    * @param aN - number of matches to find
217    * @param aCutoffNm - maximum distance to search within, in nautical miles
218    */
219   static List findClosestN(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter = NULL);
220     
221   /**
222    * Same as above, but with a time-bound in msec too.
223    */
224   static List findClosestNPartial(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter,
225                            bool& aPartial);
226     
227   /**
228    * Map a candidate type string to a real type. Returns INVALID if the string
229    * does not correspond to a defined type.
230    */
231   static Type typeFromName(const std::string& aName);
232   
233   /**
234    * Map a type to a human-readable string
235    */
236   static const char* nameForType(Type aTy);
237   
238   static FGPositioned* createUserWaypoint(const std::string& aIdent, const SGGeod& aPos);
239   static void deleteUserWaypoint(const std::string& aIdent);
240 protected:
241   friend class flightgear::NavDataCache;
242   
243   FGPositioned(PositionedID aGuid, Type ty, const std::string& aIdent, const SGGeod& aPos);
244     
245   void modifyPosition(const SGGeod& newPos);
246   
247   const PositionedID mGuid;
248   const SGGeod mPosition;
249   const SGVec3d mCart;
250   const Type mType;
251   const std::string mIdent;
252   
253 private:
254   SG_DISABLE_COPY(FGPositioned);
255 };
256
257 #endif // of FG_POSITIONED_HXX