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
26 #include <simgear/structure/SGSharedPtr.hxx>
27 #include <simgear/bucket/newbucket.hxx>
31 typedef SGSharedPtr<FGPositioned> FGPositionedRef;
33 class FGPositioned : public SGReferenced
58 WAYPOINT, // user-defined waypoint
65 typedef std::vector<FGPositionedRef> List;
67 virtual ~FGPositioned();
72 const std::string& ident() const
76 * Return the name of this positioned. By default this is the same as the
77 * ident, but for many derived classes it's more meaningful - the aiport or
78 * navaid name, for example.
80 virtual const std::string& name() const
83 const SGGeod& geod() const
87 * Compute the cartesian position associated with this object
91 SGBucket bucket() const;
93 double latitude() const
94 { return mPosition.getLatitudeDeg(); }
96 double longitude() const
97 { return mPosition.getLongitudeDeg(); }
99 double elevation() const
100 { return mPosition.getElevationFt(); }
103 * Predicate class to support custom filtering of FGPositioned queries
104 * Default implementation of this passes any FGPositioned instance.
109 virtual ~Filter() { ; }
112 * Over-rideable filter method. Default implementation returns true.
114 virtual bool pass(FGPositioned* aPos) const
117 virtual Type minType() const
120 virtual Type maxType() const
124 * Test if this filter has a non-empty type range
126 bool hasTypeRange() const;
129 * Assuming hasTypeRange is true, test if a given type passes the range
131 bool passType(Type aTy) const;
133 bool operator()(FGPositioned* aPos) const
134 { return pass(aPos); }
137 class TypeFilter : public Filter
140 TypeFilter(Type aTy) : mType(aTy) { ; }
141 virtual bool pass(FGPositioned* aPos) const
142 { return (mType == aPos->type()); }
147 static List findWithinRange(const SGGeod& aPos, double aRangeNm, Filter* aFilter = NULL);
149 static FGPositionedRef findClosestWithIdent(const std::string& aIdent, const SGGeod& aPos, Filter* aFilter = NULL);
152 * Find the next item with the specified partial ID, after the 'current' item
153 * Note this function is not hyper-efficient, particular where the partial id
154 * spans a large number of candidates.
156 * @param aCur - Current item, or NULL to retrieve the first item with partial id
157 * @param aId - the (partial) id to lookup
159 static FGPositionedRef findNextWithPartialId(FGPositionedRef aCur, const std::string& aId, Filter* aFilter = NULL);
162 * Find all items with the specified ident, and return then sorted by
163 * distance from a position
165 * @param aFilter - optional filter on items
167 static List findAllWithIdentSortedByRange(const std::string& aIdent, const SGGeod& aPos, Filter* aFilter = NULL);
170 * Find the closest item to a position, which pass the specified filter
171 * A cutoff range in NM must be specified, to constrain the search acceptably.
172 * Very large cutoff values will make this slow.
174 * @result The closest item passing the filter, or NULL
175 * @param aCutoffNm - maximum distance to search within, in nautical miles
177 static FGPositionedRef findClosest(const SGGeod& aPos, double aCutoffNm, Filter* aFilter = NULL);
180 * Find the closest N items to a position, which pass the specified filter
181 * A cutoff range in NM must be specified, to constrain the search acceptably.
182 * Very large cutoff values will make this slow.
184 * @result The matches (possibly less than N, depending on the filter and cutoff),
185 * sorted by distance from the search pos
186 * @param aN - number of matches to find
187 * @param aCutoffNm - maximum distance to search within, in nautical miles
189 static List findClosestN(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter = NULL);
194 * Debug helper, map a type to a human-readable string
196 static const char* nameForType(Type aTy);
199 FGPositioned(Type ty, const std::string& aIdent, const SGGeod& aPos, bool aIndex = true);
201 // can't be const right now, navrecord at least needs to fix up the position
202 // after navaids are parsed
206 const std::string mIdent;
209 #endif // of FG_POSITIONED_HXX