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