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