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
57 WAYPOINT, // user-defined waypoint
64 typedef std::vector<FGPositionedRef> List;
66 virtual ~FGPositioned();
71 const std::string& ident() const
74 const SGGeod& geod() const
77 SGBucket bucket() const;
79 double latitude() const
80 { return mPosition.getLatitudeDeg(); }
82 double longitude() const
83 { return mPosition.getLongitudeDeg(); }
85 double elevation() const
86 { return mPosition.getElevationFt(); }
89 * Predicate class to support custom filtering of FGPositioned queries
94 virtual ~Filter() { ; }
96 virtual bool pass(FGPositioned* aPos) const = 0;
98 bool operator()(FGPositioned* aPos) const
99 { return pass(aPos); }
102 static List findWithinRange(const SGGeod& aPos, double aRangeNm, const Filter& aFilter);
104 static List findWithinRangeByType(const SGGeod& aPos, double aRangeNm, Type aTy);
106 static FGPositionedRef findClosestWithIdent(const std::string& aIdent, double aLat, double aLon);
108 static FGPositionedRef findClosestWithIdent(const std::string& aIdent, const SGGeod& aPos);
110 static List findAllWithIdent(const std::string& aIdent);
113 * Find the closest N items to a position, which pass the specified filter
114 * A cutoff range in NM must be specified, to constrain the search acceptably.
115 * Very large cutoff values will make this slow.
117 * @result The matches (possibly less than N, depending on the filter and cutoff),
118 * sorted by distance from the search pos
119 * @param aN - number of matches to find
120 * @param aCutoffNm - maximum distance to search within, in nautical miles
122 static List findClosestN(const SGGeod& aPos, unsigned int aN, double aCutoffNm, const Filter& aFilter);
125 * Debug helper, map a type to a human-readable string
127 static const char* nameForType(Type aTy);
129 FGPositioned(Type ty, const std::string& aIdent, double aLat, double aLon, double aElev);
131 FGPositioned(Type ty, const std::string& aIdent, const SGGeod& aPos);
133 SGGeod mPosition; // can't be const right now
135 //private: // make private once FGFix and FGRunway are heap-based
142 #endif // of FG_POSITIONED_HXX