2015-10-24 19:40:41 -05:00
|
|
|
// positioned.hxx - base class for objects which are positioned
|
2008-09-08 17:50:06 +00:00
|
|
|
//
|
|
|
|
// Copyright (C) 2008 James Turner
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
#ifndef FG_POSITIONED_HXX
|
|
|
|
#define FG_POSITIONED_HXX
|
|
|
|
|
2013-03-04 16:31:37 +01:00
|
|
|
#include <cassert>
|
2012-03-03 13:37:43 +01:00
|
|
|
#include <string>
|
2008-09-08 17:50:06 +00:00
|
|
|
#include <vector>
|
2012-08-28 00:26:36 +01:00
|
|
|
#include <stdint.h>
|
2008-09-08 17:50:06 +00:00
|
|
|
|
2012-09-25 00:31:17 +01:00
|
|
|
#include <simgear/sg_inlines.h>
|
2008-09-08 17:50:06 +00:00
|
|
|
#include <simgear/structure/SGSharedPtr.hxx>
|
2010-05-02 21:57:08 +00:00
|
|
|
#include <simgear/math/SGMath.hxx>
|
2008-09-08 17:50:06 +00:00
|
|
|
|
|
|
|
class FGPositioned;
|
|
|
|
typedef SGSharedPtr<FGPositioned> FGPositionedRef;
|
2013-03-06 23:21:29 +01:00
|
|
|
typedef std::vector<FGPositionedRef> FGPositionedList;
|
2008-09-08 17:50:06 +00:00
|
|
|
|
2012-08-28 00:26:36 +01:00
|
|
|
typedef int64_t PositionedID;
|
|
|
|
typedef std::vector<PositionedID> PositionedIDVec;
|
|
|
|
|
|
|
|
namespace flightgear { class NavDataCache; }
|
|
|
|
|
2008-09-08 17:50:06 +00:00
|
|
|
class FGPositioned : public SGReferenced
|
|
|
|
{
|
|
|
|
public:
|
2015-12-01 00:01:27 +00:00
|
|
|
static const PositionedID TRANSIENT_ID;
|
2008-09-08 17:50:06 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
INVALID = 0,
|
|
|
|
AIRPORT,
|
|
|
|
HELIPORT,
|
|
|
|
SEAPORT,
|
|
|
|
RUNWAY,
|
2013-02-20 23:35:32 +01:00
|
|
|
HELIPAD,
|
2008-09-08 17:50:06 +00:00
|
|
|
TAXIWAY,
|
2009-06-14 17:43:29 +00:00
|
|
|
PAVEMENT,
|
2009-10-11 12:37:13 +01:00
|
|
|
WAYPOINT,
|
2008-09-08 17:50:06 +00:00
|
|
|
FIX,
|
|
|
|
NDB,
|
2012-08-28 00:26:36 +01:00
|
|
|
VOR,
|
2008-09-08 17:50:06 +00:00
|
|
|
ILS,
|
|
|
|
LOC,
|
|
|
|
GS,
|
|
|
|
OM,
|
|
|
|
MM,
|
|
|
|
IM,
|
2012-08-28 00:26:36 +01:00
|
|
|
/// important that DME & TACAN are adjacent to keep the TacanFilter
|
|
|
|
/// efficient - DMEs are proxies for TACAN/VORTAC stations
|
2008-09-08 17:50:06 +00:00
|
|
|
DME,
|
|
|
|
TACAN,
|
2012-08-28 00:26:36 +01:00
|
|
|
MOBILE_TACAN,
|
2008-09-08 17:50:06 +00:00
|
|
|
OBSTACLE,
|
2012-08-28 00:26:36 +01:00
|
|
|
/// 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,
|
2011-05-25 07:50:15 +01:00
|
|
|
FREQ_GROUND,
|
|
|
|
FREQ_TOWER,
|
2008-09-08 17:50:06 +00:00
|
|
|
FREQ_ATIS,
|
2011-05-25 07:50:15 +01:00
|
|
|
FREQ_AWOS,
|
|
|
|
FREQ_APP_DEP,
|
|
|
|
FREQ_ENROUTE,
|
|
|
|
FREQ_CLEARANCE,
|
|
|
|
FREQ_UNICOM,
|
2012-09-25 00:31:17 +01:00
|
|
|
// groundnet items
|
|
|
|
PARKING, ///< parking position - might be a gate, or stand
|
|
|
|
TAXI_NODE,
|
2013-03-02 13:44:20 +00:00
|
|
|
// POI items
|
|
|
|
COUNTRY,
|
|
|
|
CITY,
|
|
|
|
TOWN,
|
2013-03-03 14:17:37 +01:00
|
|
|
VILLAGE,
|
2013-03-02 13:44:20 +00:00
|
|
|
|
2008-09-08 17:50:06 +00:00
|
|
|
LAST_TYPE
|
|
|
|
} Type;
|
|
|
|
|
|
|
|
virtual ~FGPositioned();
|
|
|
|
|
|
|
|
Type type() const
|
|
|
|
{ return mType; }
|
|
|
|
|
Add FGPositioned static methods: isAirportType(), isRunwayType(), isNavaidType()
For consistency, define these three static methods in FGPositioned.
FGPositioned::isAirportType() is the same as FGAirport::isAirportType()
(piece of code moved from airport.cxx to positioned.cxx, and
FGAirport::isAirportType() now calls FGPositioned::isAirportType()).
- FGPositioned::isAirportType() returns true for AIRPORT, HELIPORT,
SEAPORT;
- FGPositioned::isRunwayType() returns true for RUNWAY;
- FGPositioned::isNavaidType() returns true for NDB, VOR, ILS, LOC, GS,
DME, TACAN.
2017-11-15 22:05:10 +01:00
|
|
|
// True for the following types: AIRPORT, HELIPORT, SEAPORT.
|
|
|
|
// False for other types, as well as if pos == nullptr.
|
|
|
|
static bool isAirportType(FGPositioned* pos);
|
|
|
|
// True for the following type: RUNWAY.
|
|
|
|
// False for other types, as well as if pos == nullptr.
|
|
|
|
static bool isRunwayType(FGPositioned* pos);
|
|
|
|
// True for the following types: NDB, VOR, ILS, LOC, GS, DME, TACAN.
|
|
|
|
// False for other types, as well as if pos == nullptr.
|
|
|
|
static bool isNavaidType(FGPositioned* pos);
|
|
|
|
|
2013-03-06 01:04:18 +01:00
|
|
|
const char* typeString() const
|
|
|
|
{ return nameForType(mType); }
|
|
|
|
|
2008-09-08 17:50:06 +00:00
|
|
|
const std::string& ident() const
|
|
|
|
{ return mIdent; }
|
|
|
|
|
2008-12-09 07:58:46 +00:00
|
|
|
/**
|
|
|
|
* 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; }
|
|
|
|
|
2014-03-01 20:18:02 +01:00
|
|
|
virtual const SGGeod& geod() const
|
2008-09-08 17:50:06 +00:00
|
|
|
{ return mPosition; }
|
2012-08-28 00:26:36 +01:00
|
|
|
|
|
|
|
PositionedID guid() const
|
|
|
|
{ return mGuid; }
|
2008-09-08 17:50:06 +00:00
|
|
|
|
2008-12-25 23:11:43 +00:00
|
|
|
/**
|
2010-08-14 19:16:28 +01:00
|
|
|
* The cartesian position associated with this object
|
2008-12-25 23:11:43 +00:00
|
|
|
*/
|
2014-03-01 20:18:02 +01:00
|
|
|
virtual const SGVec3d& cart() const;
|
2008-12-25 23:11:43 +00:00
|
|
|
|
2008-09-08 17:50:06 +00:00
|
|
|
double latitude() const
|
2014-03-01 20:18:02 +01:00
|
|
|
{ return geod().getLatitudeDeg(); }
|
2008-09-08 17:50:06 +00:00
|
|
|
|
|
|
|
double longitude() const
|
2014-03-01 20:18:02 +01:00
|
|
|
{ return geod().getLongitudeDeg(); }
|
2008-09-08 17:50:06 +00:00
|
|
|
|
|
|
|
double elevation() const
|
2014-03-01 20:18:02 +01:00
|
|
|
{ return geod().getElevationFt(); }
|
2008-09-08 17:50:06 +00:00
|
|
|
|
2013-03-04 16:31:37 +01:00
|
|
|
double elevationM() const
|
2014-03-01 20:18:02 +01:00
|
|
|
{ return geod().getElevationM(); }
|
2013-03-04 16:31:37 +01:00
|
|
|
|
2008-09-08 17:50:06 +00:00
|
|
|
/**
|
|
|
|
* Predicate class to support custom filtering of FGPositioned queries
|
2008-12-09 07:58:46 +00:00
|
|
|
* Default implementation of this passes any FGPositioned instance.
|
2008-09-08 17:50:06 +00:00
|
|
|
*/
|
|
|
|
class Filter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~Filter() { ; }
|
|
|
|
|
2008-12-09 07:58:46 +00:00
|
|
|
/**
|
|
|
|
* Over-rideable filter method. Default implementation returns true.
|
|
|
|
*/
|
|
|
|
virtual bool pass(FGPositioned* aPos) const
|
|
|
|
{ return true; }
|
2008-09-08 17:50:06 +00:00
|
|
|
|
2009-01-08 21:11:08 +00:00
|
|
|
virtual Type minType() const
|
|
|
|
{ return INVALID; }
|
|
|
|
|
|
|
|
virtual Type maxType() const
|
|
|
|
{ return INVALID; }
|
|
|
|
|
|
|
|
|
2008-09-08 17:50:06 +00:00
|
|
|
bool operator()(FGPositioned* aPos) const
|
|
|
|
{ return pass(aPos); }
|
|
|
|
};
|
|
|
|
|
2008-12-09 07:58:46 +00:00
|
|
|
class TypeFilter : public Filter
|
|
|
|
{
|
|
|
|
public:
|
2013-03-27 20:47:40 +00:00
|
|
|
TypeFilter(Type aTy = INVALID);
|
2018-12-02 13:38:33 +01:00
|
|
|
|
|
|
|
TypeFilter(std::initializer_list<Type> types);
|
|
|
|
|
|
|
|
bool pass(FGPositioned* aPos) const override;
|
2012-08-28 00:26:36 +01:00
|
|
|
|
2018-12-02 13:38:33 +01:00
|
|
|
Type minType() const override
|
2012-08-28 00:26:36 +01:00
|
|
|
{ return mMinType; }
|
|
|
|
|
2018-12-02 13:38:33 +01:00
|
|
|
Type maxType() const override
|
2012-08-28 00:26:36 +01:00
|
|
|
{ return mMaxType; }
|
|
|
|
|
2011-05-25 07:50:15 +01:00
|
|
|
void addType(Type aTy);
|
2013-03-27 20:47:40 +00:00
|
|
|
|
|
|
|
static TypeFilter fromString(const std::string& aFilterSpec);
|
2008-12-09 07:58:46 +00:00
|
|
|
private:
|
2013-03-27 20:47:40 +00:00
|
|
|
|
2012-08-28 00:26:36 +01:00
|
|
|
std::vector<Type> types;
|
2018-12-02 13:38:33 +01:00
|
|
|
Type mMinType = LAST_TYPE,
|
|
|
|
mMaxType = INVALID;
|
2008-12-09 07:58:46 +00:00
|
|
|
};
|
2012-12-18 10:23:44 +00:00
|
|
|
|
2014-03-19 17:24:52 +01:00
|
|
|
static FGPositionedList findWithinRange(const SGGeod& aPos, double aRangeNm, Filter* aFilter);
|
2012-12-18 10:23:44 +00:00
|
|
|
|
2013-03-06 23:21:29 +01:00
|
|
|
static FGPositionedList findWithinRangePartial(const SGGeod& aPos, double aRangeNm, Filter* aFilter, bool& aPartial);
|
2008-12-09 07:58:46 +00:00
|
|
|
|
|
|
|
static FGPositionedRef findClosestWithIdent(const std::string& aIdent, const SGGeod& aPos, Filter* aFilter = NULL);
|
2012-08-28 00:26:36 +01:00
|
|
|
|
2014-03-19 17:24:52 +01:00
|
|
|
static FGPositionedRef findFirstWithIdent(const std::string& aIdent, Filter* aFilter);
|
2012-08-28 00:26:36 +01:00
|
|
|
|
2009-09-27 23:12:58 +00:00
|
|
|
/**
|
2010-08-14 19:16:28 +01:00
|
|
|
* Find all items with the specified ident
|
|
|
|
* @param aFilter - optional filter on items
|
2009-10-05 19:58:24 +00:00
|
|
|
*/
|
2013-03-06 23:21:29 +01:00
|
|
|
static FGPositionedList findAllWithIdent(const std::string& aIdent, Filter* aFilter = NULL, bool aExact = true);
|
2009-09-27 23:12:58 +00:00
|
|
|
|
2008-12-09 07:58:46 +00:00
|
|
|
/**
|
2010-08-14 19:16:28 +01:00
|
|
|
* As above, but searches names instead of idents
|
2008-12-09 07:58:46 +00:00
|
|
|
*/
|
2013-03-06 23:21:29 +01:00
|
|
|
static FGPositionedList findAllWithName(const std::string& aName, Filter* aFilter = NULL, bool aExact = true);
|
2008-09-08 17:50:06 +00:00
|
|
|
|
2009-10-05 19:58:24 +00:00
|
|
|
/**
|
2010-08-14 19:16:28 +01:00
|
|
|
* Sort an FGPositionedList by distance from a position
|
2009-10-05 19:58:24 +00:00
|
|
|
*/
|
2013-03-06 23:21:29 +01:00
|
|
|
static void sortByRange(FGPositionedList&, const SGGeod& aPos);
|
2009-10-05 19:58:24 +00:00
|
|
|
|
2008-12-09 07:58:46 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
2008-09-08 17:50:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the closest N items 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 matches (possibly less than N, depending on the filter and cutoff),
|
2009-09-27 23:12:58 +00:00
|
|
|
* sorted by distance from the search pos
|
2008-09-08 17:50:06 +00:00
|
|
|
* @param aN - number of matches to find
|
|
|
|
* @param aCutoffNm - maximum distance to search within, in nautical miles
|
|
|
|
*/
|
2013-03-06 23:21:29 +01:00
|
|
|
static FGPositionedList findClosestN(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter = NULL);
|
2012-12-30 17:01:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Same as above, but with a time-bound in msec too.
|
|
|
|
*/
|
2013-03-06 23:21:29 +01:00
|
|
|
static FGPositionedList findClosestNPartial(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter,
|
2012-12-30 17:01:48 +00:00
|
|
|
bool& aPartial);
|
2008-09-08 17:50:06 +00:00
|
|
|
|
2013-03-04 16:31:37 +01:00
|
|
|
template<class T>
|
2013-03-06 23:21:29 +01:00
|
|
|
static SGSharedPtr<T> loadById(PositionedID id)
|
2013-03-04 16:31:37 +01:00
|
|
|
{
|
2013-03-06 23:21:29 +01:00
|
|
|
return static_pointer_cast<T>( loadByIdImpl(id) );
|
2013-03-04 16:31:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
2013-03-06 23:21:29 +01:00
|
|
|
static SGSharedPtr<T> loadById(const PositionedIDVec& id_vec, size_t index)
|
2013-03-04 16:31:37 +01:00
|
|
|
{
|
|
|
|
assert(index >= 0 && index < id_vec.size());
|
|
|
|
return loadById<T>(id_vec[index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
2013-03-06 23:21:29 +01:00
|
|
|
static std::vector<SGSharedPtr<T> > loadAllById(const PositionedIDVec& id_vec)
|
2013-03-04 16:31:37 +01:00
|
|
|
{
|
2013-03-06 23:21:29 +01:00
|
|
|
std::vector<SGSharedPtr<T> > vec(id_vec.size());
|
2013-03-04 16:31:37 +01:00
|
|
|
|
|
|
|
for(size_t i = 0; i < id_vec.size(); ++i)
|
|
|
|
vec[i] = loadById<T>(id_vec[i]);
|
|
|
|
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
2013-03-06 23:21:29 +01:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2017-02-25 14:48:54 +01:00
|
|
|
static FGPositionedRef createUserWaypoint(const std::string& aIdent, const SGGeod& aPos);
|
2013-03-27 20:47:40 +00:00
|
|
|
static bool deleteUserWaypoint(const std::string& aIdent);
|
2013-03-06 23:21:29 +01:00
|
|
|
protected:
|
|
|
|
friend class flightgear::NavDataCache;
|
|
|
|
|
|
|
|
FGPositioned(PositionedID aGuid, Type ty, const std::string& aIdent, const SGGeod& aPos);
|
|
|
|
|
|
|
|
void modifyPosition(const SGGeod& newPos);
|
2014-03-02 16:52:00 +01:00
|
|
|
void invalidatePosition();
|
2013-03-06 23:21:29 +01:00
|
|
|
|
|
|
|
static FGPositionedRef loadByIdImpl(PositionedID id);
|
|
|
|
|
2012-08-28 00:26:36 +01:00
|
|
|
const PositionedID mGuid;
|
2008-12-24 14:48:30 +00:00
|
|
|
const Type mType;
|
|
|
|
const std::string mIdent;
|
2012-09-25 00:31:17 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
SG_DISABLE_COPY(FGPositioned);
|
2014-03-01 20:18:02 +01:00
|
|
|
|
|
|
|
const SGGeod mPosition;
|
|
|
|
const SGVec3d mCart;
|
2008-09-08 17:50:06 +00:00
|
|
|
};
|
|
|
|
|
2018-05-07 16:40:38 +01:00
|
|
|
template <class T>
|
|
|
|
T* fgpositioned_cast(FGPositioned* p)
|
|
|
|
{
|
|
|
|
if (T::isType(p->type())) {
|
|
|
|
return static_cast<T*>(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
T* fgpositioned_cast(FGPositionedRef p)
|
|
|
|
{
|
|
|
|
if (!p) return nullptr;
|
|
|
|
|
|
|
|
if (T::isType(p->type())) {
|
|
|
|
return static_cast<T*>(p.ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2008-09-08 17:50:06 +00:00
|
|
|
#endif // of FG_POSITIONED_HXX
|