1 // positioned.hxx - base class for objects which are positioned
3 // Copyright (C) 2008 James Turner
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.
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.
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.
21 #ifndef FG_POSITIONED_HXX
22 #define FG_POSITIONED_HXX
28 #include <simgear/sg_inlines.h>
29 #include <simgear/structure/SGSharedPtr.hxx>
30 #include <simgear/math/SGMath.hxx>
33 typedef SGSharedPtr<FGPositioned> FGPositionedRef;
35 typedef int64_t PositionedID;
36 typedef std::vector<PositionedID> PositionedIDVec;
38 namespace flightgear { class NavDataCache; }
40 class FGPositioned : public SGReferenced
63 /// important that DME & TACAN are adjacent to keep the TacanFilter
64 /// efficient - DMEs are proxies for TACAN/VORTAC stations
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
82 PARKING, ///< parking position - might be a gate, or stand
93 typedef std::vector<FGPositionedRef> List;
95 virtual ~FGPositioned();
100 const std::string& ident() const
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.
108 virtual const std::string& name() const
111 const SGGeod& geod() const
112 { return mPosition; }
114 PositionedID guid() const
118 * The cartesian position associated with this object
120 const SGVec3d& cart() const;
122 double latitude() const
123 { return mPosition.getLatitudeDeg(); }
125 double longitude() const
126 { return mPosition.getLongitudeDeg(); }
128 double elevation() const
129 { return mPosition.getElevationFt(); }
132 * Predicate class to support custom filtering of FGPositioned queries
133 * Default implementation of this passes any FGPositioned instance.
138 virtual ~Filter() { ; }
141 * Over-rideable filter method. Default implementation returns true.
143 virtual bool pass(FGPositioned* aPos) const
146 virtual Type minType() const
149 virtual Type maxType() const
153 bool operator()(FGPositioned* aPos) const
154 { return pass(aPos); }
157 class TypeFilter : public Filter
160 TypeFilter(Type aTy);
161 virtual bool pass(FGPositioned* aPos) const;
163 virtual Type minType() const
166 virtual Type maxType() const
169 void addType(Type aTy);
171 std::vector<Type> types;
172 Type mMinType, mMaxType;
175 static List findWithinRange(const SGGeod& aPos, double aRangeNm, Filter* aFilter = NULL);
177 static List findWithinRangePartial(const SGGeod& aPos, double aRangeNm, Filter* aFilter, bool& aPartial);
179 static FGPositionedRef findClosestWithIdent(const std::string& aIdent, const SGGeod& aPos, Filter* aFilter = NULL);
181 static FGPositionedRef findFirstWithIdent(const std::string& aIdent, Filter* aFilter = NULL);
184 * Find all items with the specified ident
185 * @param aFilter - optional filter on items
187 static List findAllWithIdent(const std::string& aIdent, Filter* aFilter = NULL, bool aExact = true);
190 * As above, but searches names instead of idents
192 static List findAllWithName(const std::string& aName, Filter* aFilter = NULL, bool aExact = true);
195 * Sort an FGPositionedList by distance from a position
197 static void sortByRange(List&, const SGGeod& aPos);
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.
204 * @result The closest item passing the filter, or NULL
205 * @param aCutoffNm - maximum distance to search within, in nautical miles
207 static FGPositionedRef findClosest(const SGGeod& aPos, double aCutoffNm, Filter* aFilter = NULL);
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.
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
219 static List findClosestN(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter = NULL);
222 * Same as above, but with a time-bound in msec too.
224 static List findClosestNPartial(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter,
228 * Map a candidate type string to a real type. Returns INVALID if the string
229 * does not correspond to a defined type.
231 static Type typeFromName(const std::string& aName);
234 * Map a type to a human-readable string
236 static const char* nameForType(Type aTy);
238 static FGPositioned* createUserWaypoint(const std::string& aIdent, const SGGeod& aPos);
239 static void deleteUserWaypoint(const std::string& aIdent);
241 friend class flightgear::NavDataCache;
243 FGPositioned(PositionedID aGuid, Type ty, const std::string& aIdent, const SGGeod& aPos);
245 void modifyPosition(const SGGeod& newPos);
247 const PositionedID mGuid;
248 const SGGeod mPosition;
251 const std::string mIdent;
254 SG_DISABLE_COPY(FGPositioned);
257 #endif // of FG_POSITIONED_HXX