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
87 typedef std::vector<FGPositionedRef> List;
89 virtual ~FGPositioned();
94 const std::string& ident() const
98 * Return the name of this positioned. By default this is the same as the
99 * ident, but for many derived classes it's more meaningful - the aiport or
100 * navaid name, for example.
102 virtual const std::string& name() const
105 const SGGeod& geod() const
106 { return mPosition; }
108 PositionedID guid() const
112 * The cartesian position associated with this object
114 const SGVec3d& cart() const;
116 double latitude() const
117 { return mPosition.getLatitudeDeg(); }
119 double longitude() const
120 { return mPosition.getLongitudeDeg(); }
122 double elevation() const
123 { return mPosition.getElevationFt(); }
126 * Predicate class to support custom filtering of FGPositioned queries
127 * Default implementation of this passes any FGPositioned instance.
132 virtual ~Filter() { ; }
135 * Over-rideable filter method. Default implementation returns true.
137 virtual bool pass(FGPositioned* aPos) const
140 virtual Type minType() const
143 virtual Type maxType() const
147 bool operator()(FGPositioned* aPos) const
148 { return pass(aPos); }
151 class TypeFilter : public Filter
154 TypeFilter(Type aTy);
155 virtual bool pass(FGPositioned* aPos) const;
157 virtual Type minType() const
160 virtual Type maxType() const
163 void addType(Type aTy);
165 std::vector<Type> types;
166 Type mMinType, mMaxType;
169 static List findWithinRange(const SGGeod& aPos, double aRangeNm, Filter* aFilter = NULL);
171 static List findWithinRangePartial(const SGGeod& aPos, double aRangeNm, Filter* aFilter, bool& aPartial);
173 static FGPositionedRef findClosestWithIdent(const std::string& aIdent, const SGGeod& aPos, Filter* aFilter = NULL);
175 static FGPositionedRef findFirstWithIdent(const std::string& aIdent, Filter* aFilter = NULL);
178 * Find all items with the specified ident
179 * @param aFilter - optional filter on items
181 static List findAllWithIdent(const std::string& aIdent, Filter* aFilter = NULL, bool aExact = true);
184 * As above, but searches names instead of idents
186 static List findAllWithName(const std::string& aName, Filter* aFilter = NULL, bool aExact = true);
189 * Sort an FGPositionedList by distance from a position
191 static void sortByRange(List&, const SGGeod& aPos);
194 * Find the closest item to a position, which pass the specified filter
195 * A cutoff range in NM must be specified, to constrain the search acceptably.
196 * Very large cutoff values will make this slow.
198 * @result The closest item passing the filter, or NULL
199 * @param aCutoffNm - maximum distance to search within, in nautical miles
201 static FGPositionedRef findClosest(const SGGeod& aPos, double aCutoffNm, Filter* aFilter = NULL);
204 * Find the closest N items to a position, which pass the specified filter
205 * A cutoff range in NM must be specified, to constrain the search acceptably.
206 * Very large cutoff values will make this slow.
208 * @result The matches (possibly less than N, depending on the filter and cutoff),
209 * sorted by distance from the search pos
210 * @param aN - number of matches to find
211 * @param aCutoffNm - maximum distance to search within, in nautical miles
213 static List findClosestN(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter = NULL);
216 * Same as above, but with a time-bound in msec too.
218 static List findClosestNPartial(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter,
222 * Map a candidate type string to a real type. Returns INVALID if the string
223 * does not correspond to a defined type.
225 static Type typeFromName(const std::string& aName);
228 * Map a type to a human-readable string
230 static const char* nameForType(Type aTy);
232 static FGPositioned* createUserWaypoint(const std::string& aIdent, const SGGeod& aPos);
234 friend class flightgear::NavDataCache;
236 FGPositioned(PositionedID aGuid, Type ty, const std::string& aIdent, const SGGeod& aPos);
238 void modifyPosition(const SGGeod& newPos);
240 const PositionedID mGuid;
241 const SGGeod mPosition;
244 const std::string mIdent;
247 SG_DISABLE_COPY(FGPositioned);
250 #endif // of FG_POSITIONED_HXX