X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNavaids%2Fpositioned.hxx;h=37f8910c1bd616a09221ef81e08ba9dafc684c8b;hb=0cdb9d4efb249dd85b7e56d1885d8183de231373;hp=3c26835061ef1cc38d19ffa749cd8c59f10881e4;hpb=812485d623f5a58f722f40d14bcd23430c2ac6f9;p=flightgear.git diff --git a/src/Navaids/positioned.hxx b/src/Navaids/positioned.hxx index 3c2683506..37f8910c1 100644 --- a/src/Navaids/positioned.hxx +++ b/src/Navaids/positioned.hxx @@ -41,6 +41,7 @@ public: SEAPORT, RUNWAY, TAXIWAY, + PAVEMENT, PARK_STAND, FIX, VOR, @@ -71,9 +72,22 @@ public: const std::string& ident() const { return mIdent; } + /** + * Return the name of this positioned. By default this is the same as the + * ident, but for many derived classes it's more meaningful - the aiport or + * navaid name, for example. + */ + virtual const std::string& name() const + { return mIdent; } + const SGGeod& geod() const { return mPosition; } + /** + * Compute the cartesian position associated with this object + */ + SGVec3d cart() const; + SGBucket bucket() const; double latitude() const @@ -87,27 +101,95 @@ public: /** * Predicate class to support custom filtering of FGPositioned queries + * Default implementation of this passes any FGPositioned instance. */ class Filter { public: virtual ~Filter() { ; } - virtual bool pass(FGPositioned* aPos) const = 0; + /** + * Over-rideable filter method. Default implementation returns true. + */ + virtual bool pass(FGPositioned* aPos) const + { return true; } + + virtual Type minType() const + { return INVALID; } + + virtual Type maxType() const + { return INVALID; } + + /** + * Test if this filter has a non-empty type range + */ + bool hasTypeRange() const; + + /** + * Assuming hasTypeRange is true, test if a given type passes the range + */ + bool passType(Type aTy) const; bool operator()(FGPositioned* aPos) const { return pass(aPos); } }; - static List findWithinRange(const SGGeod& aPos, double aRangeNm, const Filter& aFilter); - - static List findWithinRangeByType(const SGGeod& aPos, double aRangeNm, Type aTy); + class TypeFilter : public Filter + { + public: + TypeFilter(Type aTy) : mType(aTy) { ; } + virtual bool pass(FGPositioned* aPos) const + { return (mType == aPos->type()); } + private: + const Type mType; + }; + + static List findWithinRange(const SGGeod& aPos, double aRangeNm, Filter* aFilter = NULL); + + static FGPositionedRef findClosestWithIdent(const std::string& aIdent, const SGGeod& aPos, Filter* aFilter = NULL); + + /** + * Find the next item with the specified partial ID, after the 'current' item + * Note this function is not hyper-efficient, particular where the partial id + * spans a large number of candidates. + * + * @param aCur - Current item, or NULL to retrieve the first item with partial id + * @param aId - the (partial) id to lookup + */ + static FGPositionedRef findNextWithPartialId(FGPositionedRef aCur, const std::string& aId, Filter* aFilter = NULL); + + /** + * As above, but searches using an offset index + */ + static FGPositionedRef findWithPartialId(const std::string& aId, Filter* aFilter, int aOffset, bool& aNext); - static FGPositionedRef findClosestWithIdent(const std::string& aIdent, double aLat, double aLon); + /** + * As above, but search names instead of idents + */ + static FGPositionedRef findWithPartialName(const std::string& aName, Filter* aFilter, int aOffset, bool& aNext); - static FGPositionedRef findClosestWithIdent(const std::string& aIdent, const SGGeod& aPos); + /** + * Find all items with the specified ident, and return then sorted by + * distance from a position + * + * @param aFilter - optional filter on items + */ + static List findAllWithIdentSortedByRange(const std::string& aIdent, const SGGeod& aPos, Filter* aFilter = NULL); + + /** + * As above, but searches names instead of idents + */ + static List findAllWithNameSortedByRange(const std::string& aName, const SGGeod& aPos, Filter* aFilter = NULL); - static List findAllWithIdent(const std::string& aIdent); + /** + * Find the closest item to a position, which pass the specified filter + * A cutoff range in NM must be specified, to constrain the search acceptably. + * Very large cutoff values will make this slow. + * + * @result The closest item passing the filter, or NULL + * @param aCutoffNm - maximum distance to search within, in nautical miles + */ + static FGPositionedRef findClosest(const SGGeod& aPos, double aCutoffNm, Filter* aFilter = NULL); /** * Find the closest N items to a position, which pass the specified filter @@ -115,25 +197,46 @@ public: * Very large cutoff values will make this slow. * * @result The matches (possibly less than N, depending on the filter and cutoff), - * sorted by distance from the search pos + * sorted by distance from the search pos * @param aN - number of matches to find * @param aCutoffNm - maximum distance to search within, in nautical miles */ - static List findClosestN(const SGGeod& aPos, unsigned int aN, double aCutoffNm, const Filter& aFilter); + static List findClosestN(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter = NULL); /** - * Debug helper, map a type to a human-readable string + * Find the closest match based on partial id (with an offset to allow selecting the n-th closest). + * Cutoff distance is limited internally, to avoid making this very slow. + */ + static FGPositionedRef findClosestWithPartialId(const SGGeod& aPos, const std::string& aId, Filter* aFilter, int aOffset, bool& aNext); + + /** + * As above, but matches on name + */ + static FGPositionedRef findClosestWithPartialName(const SGGeod& aPos, const std::string& aName, Filter* aFilter, int aOffset, bool& aNext); + + + /** + * Map a candidate type string to a real type. Returns INVALID if the string + * does not correspond to a defined type. + */ + static Type typeFromName(const std::string& aName); + + /** + * Map a type to a human-readable string */ static const char* nameForType(Type aTy); + + static FGPositioned* createUserWaypoint(const std::string& aIdent, const SGGeod& aPos); protected: - FGPositioned(Type ty, const std::string& aIdent, double aLat, double aLon, double aElev); - FGPositioned(Type ty, const std::string& aIdent, const SGGeod& aPos); + FGPositioned(Type ty, const std::string& aIdent, const SGGeod& aPos, bool aIndex = true); - SGGeod mPosition; // can't be const right now + // can't be const right now, navrecord at least needs to fix up the position + // after navaids are parsed + SGGeod mPosition; - Type mType; - std::string mIdent; + const Type mType; + const std::string mIdent; }; #endif // of FG_POSITIONED_HXX