]> git.mxchange.org Git - flightgear.git/blobdiff - src/Navaids/positioned.hxx
commradio: improvements for atis speech
[flightgear.git] / src / Navaids / positioned.hxx
index f6cf3cf372e9c8273efa6901b06529c70c2aabee..012edb0b18d0ae7cda9c3e556d09942eab726bd2 100644 (file)
 #ifndef FG_POSITIONED_HXX
 #define FG_POSITIONED_HXX
 
+#include <cassert>
+#include <string>
 #include <vector>
+#include <stdint.h>
 
+#include <simgear/sg_inlines.h>
 #include <simgear/structure/SGSharedPtr.hxx>
-#include <simgear/bucket/newbucket.hxx>
+#include <simgear/math/SGMath.hxx>
 
 class FGPositioned;
-
 typedef SGSharedPtr<FGPositioned> FGPositionedRef;
+typedef std::vector<FGPositionedRef> FGPositionedList;
+
+typedef int64_t PositionedID;
+typedef std::vector<PositionedID> PositionedIDVec;
+
+namespace flightgear { class NavDataCache; }
 
 class FGPositioned : public SGReferenced
 {
@@ -40,74 +49,171 @@ public:
     HELIPORT,
     SEAPORT,
     RUNWAY,
+    HELIPAD,
     TAXIWAY,
-    PARK_STAND,
+    PAVEMENT,
+    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<FGPositionedRef> List;
-  
   virtual ~FGPositioned();
   
   Type type() const
   { return mType; }
 
+  const char* typeString() const
+  { return nameForType(mType); }
+
   const std::string& ident() const
   { return mIdent; }
 
-  const SGGeod& geod() const
-  { return mPosition; }
+  /**
+   * 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; }
 
-  SGBucket bucket() const;
+  virtual const SGGeod& geod() const
+  { return mPosition; }
   
+  PositionedID guid() const
+  { return mGuid; }
+
+  /**
+   *  The cartesian position associated with this object
+   */
+  virtual const SGVec3d& cart() const;
+
   double latitude() const
-  { return mPosition.getLatitudeDeg(); }
+  { return geod().getLatitudeDeg(); }
   
   double longitude() const
-  { return mPosition.getLongitudeDeg(); }
+  { return geod().getLongitudeDeg(); }
   
   double elevation() const
-  { return mPosition.getElevationFt(); }
+  { return geod().getElevationFt(); }
   
+  double elevationM() const
+  { return geod().getElevationM(); }
+
   /**
    * 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; }
+    
     
     bool operator()(FGPositioned* aPos) const
     { return pass(aPos); }
   };
   
-  static List findWithinRange(const SGGeod& aPos, double aRangeNm, const Filter& aFilter);
+  class TypeFilter : public Filter
+  {
+  public:
+    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 List findWithinRangeByType(const SGGeod& aPos, double aRangeNm, Type aTy);
+    static TypeFilter fromString(const std::string& aFilterSpec);
+  private:
+      
+    std::vector<Type> types;
+    Type mMinType, mMaxType;
+  };
+  
+  static FGPositionedList findWithinRange(const SGGeod& aPos, double aRangeNm, Filter* aFilter);
+  
+  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);
 
-  static FGPositionedRef findClosestWithIdent(const std::string& aIdent, double aLat, double aLon);
+  static FGPositionedRef findFirstWithIdent(const std::string& aIdent, Filter* aFilter);
+
+  /**
+   * Find all items with the specified ident
+   * @param aFilter - optional filter on items
+   */
+  static FGPositionedList findAllWithIdent(const std::string& aIdent, Filter* aFilter = NULL, bool aExact = true);
   
-  static FGPositionedRef findClosestWithIdent(const std::string& aIdent, const SGGeod& aPos);
+  /**
+   * As above, but searches names instead of idents
+   */
+  static FGPositionedList findAllWithName(const std::string& aName, Filter* aFilter = NULL, bool aExact = true);
   
-  static List findAllWithIdent(const std::string& aIdent);
+  /**
+   * Sort an FGPositionedList by distance from a position
+   */
+  static void sortByRange(FGPositionedList&, const SGGeod& aPos);
+  
+  /**
+   * 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,28 +221,74 @@ 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 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<class T>
+  static SGSharedPtr<T> loadById(PositionedID id)
+  {
+    return static_pointer_cast<T>( loadByIdImpl(id) );
+  }
+
+  template<class T>
+  static SGSharedPtr<T> loadById(const PositionedIDVec& id_vec, size_t index)
+  {
+    assert(index >= 0 && index < id_vec.size());
+    return loadById<T>(id_vec[index]);
+  }
+
+  template<class T>
+  static std::vector<SGSharedPtr<T> > loadAllById(const PositionedIDVec& id_vec)
+  {
+    std::vector<SGSharedPtr<T> > vec(id_vec.size());
+
+    for(size_t i = 0; i < id_vec.size(); ++i)
+      vec[i] = loadById<T>(id_vec[i]);
+
+    return vec;
+  }
+
   /**
-   * Debug helper, map a type to a human-readable string
+   * 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, double aLat, double aLon, double aElev);
-  
-  FGPositioned(Type ty, const std::string& aIdent, const SGGeod& aPos);
-  
-  SGGeod mPosition; // can't be const right now
-  
-//private: // make private once FGFix and FGRunway are heap-based
-  FGPositioned();
+  friend class flightgear::NavDataCache;
+
+  FGPositioned(PositionedID aGuid, Type ty, const std::string& aIdent, const SGGeod& aPos);
+
+  void modifyPosition(const SGGeod& newPos);
+  void invalidatePosition();
+
+  static FGPositionedRef loadByIdImpl(PositionedID id);
+
+  const PositionedID mGuid;
+  const Type mType;
+  const std::string mIdent;
   
-  Type mType;
-  std::string mIdent;
+private:
+  SG_DISABLE_COPY(FGPositioned);
+
+  const SGGeod mPosition;
+  const SGVec3d mCart;
 };
 
 #endif // of FG_POSITIONED_HXX