1
0
Fork 0

NavData API additions

This commit is contained in:
James Turner 2018-05-07 16:40:38 +01:00
parent 71a1348037
commit 552df27341
9 changed files with 61 additions and 3 deletions

View file

@ -52,6 +52,9 @@ class FGAirport : public FGPositioned
const std::string& name, bool has_metar, Type aType); const std::string& name, bool has_metar, Type aType);
~FGAirport(); ~FGAirport();
static bool isType(FGPositioned::Type ty)
{ return (ty >= FGPositioned::AIRPORT) && (ty <= FGPositioned::SEAPORT); }
const std::string& getId() const { return ident(); } const std::string& getId() const { return ident(); }
const std::string& getName() const { return _name; } const std::string& getName() const { return _name; }
std::string toString() const { return "an airport " + ident(); } std::string toString() const { return "an airport " + ident(); }

View file

@ -451,6 +451,18 @@ FGParkingRef FGGroundNetwork::getParkingByIndex(unsigned int index) const
return FGParkingRef(static_cast<FGParking*>(tn.ptr())); return FGParkingRef(static_cast<FGParking*>(tn.ptr()));
} }
FGParkingRef FGGroundNetwork::findParkingByName(const string &name) const
{
auto it = std::find_if(m_parkings.begin(), m_parkings.end(), [name](const FGParkingRef& p) {
return p->ident() == name;
});
if (it == m_parkings.end())
return nullptr;
return *it;
}
void FGGroundNetwork::addSegment(const FGTaxiNodeRef &from, const FGTaxiNodeRef &to) void FGGroundNetwork::addSegment(const FGTaxiNodeRef &from, const FGTaxiNodeRef &to)
{ {
FGTaxiSegment* seg = new FGTaxiSegment(from, to); FGTaxiSegment* seg = new FGTaxiSegment(from, to);

View file

@ -259,6 +259,8 @@ public:
FGParkingRef getParkingByIndex(unsigned int index) const; FGParkingRef getParkingByIndex(unsigned int index) const;
FGParkingRef findParkingByName(const std::string& name) const;
/** /**
* Find the taxiway segment joining two (ground-net) nodes. Returns * Find the taxiway segment joining two (ground-net) nodes. Returns
* NULL if no such segment exists. * NULL if no such segment exists.

View file

@ -49,6 +49,9 @@ private:
SG_DISABLE_COPY(FGParking); SG_DISABLE_COPY(FGParking);
public: public:
static bool isType(FGPositioned::Type ty)
{ return (ty == FGPositioned::PARKING); }
FGParking(int index, FGParking(int index,
const SGGeod& pos, const SGGeod& pos,
double heading, double radius, double heading, double radius,

View file

@ -38,7 +38,9 @@ class FGRunway : public FGRunwayBase
double _stopway; double _stopway;
PositionedID _ils; PositionedID _ils;
public: public:
static bool isType(FGPositioned::Type ty)
{ return (ty == FGPositioned::RUNWAY); }
FGRunway(PositionedID aGuid, FGRunway(PositionedID aGuid,
PositionedID aAirport, const std::string& rwy_no, PositionedID aAirport, const std::string& rwy_no,
const SGGeod& aGeod, const SGGeod& aGeod,
@ -126,6 +128,9 @@ public:
class FGHelipad : public FGRunwayBase class FGHelipad : public FGRunwayBase
{ {
public: public:
static bool isType(FGPositioned::Type ty)
{ return (ty == FGPositioned::HELIPAD); }
FGHelipad(PositionedID aGuid, FGHelipad(PositionedID aGuid,
PositionedID aAirport, const std::string& rwy_no, PositionedID aAirport, const std::string& rwy_no,
const SGGeod& aGeod, const SGGeod& aGeod,

View file

@ -1713,7 +1713,7 @@ void NavDataCache::abortTransaction()
FGPositionedRef NavDataCache::loadById(PositionedID rowid) FGPositionedRef NavDataCache::loadById(PositionedID rowid)
{ {
if (rowid == 0) { if (rowid < 1) {
return NULL; return NULL;
} }
if (!d) return NULL; if (!d) return NULL;

View file

@ -110,7 +110,12 @@ bool FGNavRecord::isVORTAC() const
void FGNavRecord::setColocatedDME(PositionedID other) void FGNavRecord::setColocatedDME(PositionedID other)
{ {
mColocated = other; mColocated = other;
}
PositionedID FGNavRecord::colocatedDME() const
{
return mColocated;
} }
void FGNavRecord::updateFromXML(const SGGeod& geod, double heading) void FGNavRecord::updateFromXML(const SGGeod& geod, double heading)

View file

@ -56,6 +56,9 @@ class FGNavRecord : public FGPositioned
mutable bool serviceable; // for failure modeling mutable bool serviceable; // for failure modeling
public: public:
static bool isType(FGPositioned::Type ty)
{ return (ty >= FGPositioned::NDB) && (ty <= FGPositioned::DME); }
FGNavRecord( PositionedID aGuid, FGNavRecord( PositionedID aGuid,
Type type, Type type,
const std::string& ident, const std::string& ident,
@ -98,8 +101,11 @@ class FGNavRecord : public FGPositioned
void unbindFromNode(SGPropertyNode* nd) const; void unbindFromNode(SGPropertyNode* nd) const;
void setColocatedDME(PositionedID other); void setColocatedDME(PositionedID other);
bool hasDME() const; bool hasDME() const;
PositionedID colocatedDME() const;
bool isVORTAC() const; bool isVORTAC() const;
void updateFromXML(const SGGeod& geod, double heading); void updateFromXML(const SGGeod& geod, double heading);

View file

@ -302,4 +302,26 @@ private:
const SGVec3d mCart; const SGVec3d mCart;
}; };
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;
}
#endif // of FG_POSITIONED_HXX #endif // of FG_POSITIONED_HXX