X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNavaids%2Fpositioned.hxx;h=8b4fb6a3f8c4b4c86e9816d9ed50677eb86efbb4;hb=b30408b862ae0a300ff32ef90b20cdde9efdd499;hp=27d807a7264c0d0418c8dba72d98e4cff64e240c;hpb=0bce31ae9a80c571b9126427c093b8dc3d3f6820;p=flightgear.git diff --git a/src/Navaids/positioned.hxx b/src/Navaids/positioned.hxx index 27d807a72..8b4fb6a3f 100644 --- a/src/Navaids/positioned.hxx +++ b/src/Navaids/positioned.hxx @@ -21,14 +21,23 @@ #ifndef FG_POSITIONED_HXX #define FG_POSITIONED_HXX +#include +#include #include +#include +#include #include #include class FGPositioned; - typedef SGSharedPtr FGPositionedRef; +typedef std::vector FGPositionedList; + +typedef int64_t PositionedID; +typedef std::vector PositionedIDVec; + +namespace flightgear { class NavDataCache; } class FGPositioned : public SGReferenced { @@ -40,35 +49,57 @@ public: HELIPORT, SEAPORT, RUNWAY, + HELIPAD, TAXIWAY, PAVEMENT, - PARK_STAND, + WAYPOINT, FIX, - VOR, NDB, + VOR, ILS, LOC, GS, OM, MM, IM, +/// important that DME & TACAN are adjacent to keep the TacanFilter +/// efficient - DMEs are proxies for TACAN/VORTAC stations DME, TACAN, + MOBILE_TACAN, OBSTACLE, - WAYPOINT, // user-defined waypoint - FREQ_GND, - FREQ_TWR, +/// an actual airport tower - not a radio comms facility! +/// some airports have multiple towers, eg EHAM, although our data source +/// doesn't necessarily include them + TOWER, + FREQ_GROUND, + FREQ_TOWER, FREQ_ATIS, + FREQ_AWOS, + FREQ_APP_DEP, + FREQ_ENROUTE, + FREQ_CLEARANCE, + FREQ_UNICOM, +// groundnet items + PARKING, ///< parking position - might be a gate, or stand + TAXI_NODE, +// POI items + COUNTRY, + CITY, + TOWN, + VILLAGE, + LAST_TYPE } Type; - typedef std::vector List; - virtual ~FGPositioned(); Type type() const { return mType; } + const char* typeString() const + { return nameForType(mType); } + const std::string& ident() const { return mIdent; } @@ -82,6 +113,9 @@ public: const SGGeod& geod() const { return mPosition; } + + PositionedID guid() const + { return mGuid; } /** * The cartesian position associated with this object @@ -97,6 +131,9 @@ public: double elevation() const { return mPosition.getElevationFt(); } + double elevationM() const + { return mPosition.getElevationM(); } + /** * Predicate class to support custom filtering of FGPositioned queries * Default implementation of this passes any FGPositioned instance. @@ -118,15 +155,6 @@ public: 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); } @@ -135,42 +163,47 @@ public: class TypeFilter : public Filter { public: - TypeFilter(Type aTy) : mType(aTy) { ; } - virtual bool pass(FGPositioned* aPos) const - { return (mType == aPos->type()); } + TypeFilter(Type aTy = INVALID); + virtual bool pass(FGPositioned* aPos) const; + + virtual Type minType() const + { return mMinType; } + + virtual Type maxType() const + { return mMaxType; } + + void addType(Type aTy); + + static TypeFilter fromString(const std::string& aFilterSpec); private: - const Type mType; + + std::vector types; + Type mMinType, mMaxType; }; - static List findWithinRange(const SGGeod& aPos, double aRangeNm, Filter* aFilter = NULL); + static FGPositionedList findWithinRange(const SGGeod& aPos, double aRangeNm, Filter* aFilter = NULL); + + static FGPositionedList findWithinRangePartial(const SGGeod& aPos, double aRangeNm, Filter* aFilter, bool& aPartial); 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); - + + static FGPositionedRef findFirstWithIdent(const std::string& aIdent, Filter* aFilter = NULL); + /** * Find all items with the specified ident * @param aFilter - optional filter on items */ - static List findAllWithIdent(const std::string& aIdent, Filter* aFilter = NULL); + static FGPositionedList findAllWithIdent(const std::string& aIdent, Filter* aFilter = NULL, bool aExact = true); /** * As above, but searches names instead of idents */ - static List findAllWithName(const std::string& aName, Filter* aFilter = NULL); + static FGPositionedList findAllWithName(const std::string& aName, Filter* aFilter = NULL, bool aExact = true); /** * Sort an FGPositionedList by distance from a position */ - static void sortByRange(List&, const SGGeod& aPos); + static void sortByRange(FGPositionedList&, const SGGeod& aPos); /** * Find the closest item to a position, which pass the specified filter @@ -192,33 +225,68 @@ public: * @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, Filter* aFilter = NULL); + static FGPositionedList findClosestN(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter = NULL); + + /** + * Same as above, but with a time-bound in msec too. + */ + static FGPositionedList findClosestNPartial(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter, + bool& aPartial); + template + static SGSharedPtr loadById(PositionedID id) + { + return static_pointer_cast( loadByIdImpl(id) ); + } + + template + static SGSharedPtr loadById(const PositionedIDVec& id_vec, size_t index) + { + assert(index >= 0 && index < id_vec.size()); + return loadById(id_vec[index]); + } + + template + static std::vector > loadAllById(const PositionedIDVec& id_vec) + { + std::vector > vec(id_vec.size()); + + for(size_t i = 0; i < id_vec.size(); ++i) + vec[i] = loadById(id_vec[i]); + + return vec; + } + /** * 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); + static bool deleteUserWaypoint(const std::string& aIdent); protected: - - FGPositioned(Type ty, const std::string& aIdent, const SGGeod& aPos); - - void init(bool aIndexed); - - // can't be const right now, navrecord at least needs to fix up the position - // after navaids are parsed - SGGeod mPosition; - - SGVec3d mCart; // once mPosition is const, this can be const too + friend class flightgear::NavDataCache; + + FGPositioned(PositionedID aGuid, Type ty, const std::string& aIdent, const SGGeod& aPos); + + void modifyPosition(const SGGeod& newPos); + + static FGPositionedRef loadByIdImpl(PositionedID id); + + const PositionedID mGuid; + const SGGeod mPosition; + const SGVec3d mCart; const Type mType; const std::string mIdent; + +private: + SG_DISABLE_COPY(FGPositioned); }; #endif // of FG_POSITIONED_HXX