From ca18f98c430d2c81cf9aa05f870b019fb6419a90 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 19 Oct 2015 23:29:13 +0100 Subject: [PATCH] refs #484 Added value class for working with X-Plane nav data, CNavDataReference. --- src/blackmisc/geo/geoobjectlist.cpp | 2 + src/blackmisc/geo/geoobjectlist.h | 8 +- .../simulation/xplane/navdatareference.cpp | 58 ++++++++++++ .../simulation/xplane/navdatareference.h | 94 +++++++++++++++++++ 4 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 src/blackmisc/simulation/xplane/navdatareference.cpp create mode 100644 src/blackmisc/simulation/xplane/navdatareference.h diff --git a/src/blackmisc/geo/geoobjectlist.cpp b/src/blackmisc/geo/geoobjectlist.cpp index 59666f9ee..f113a151a 100644 --- a/src/blackmisc/geo/geoobjectlist.cpp +++ b/src/blackmisc/geo/geoobjectlist.cpp @@ -12,6 +12,7 @@ #include "blackmisc/aviation/atcstationlist.h" #include "blackmisc/aviation/airportlist.h" #include "blackmisc/simulation/simulatedaircraftlist.h" +#include "blackmisc/simulation/xplane/navdatareference.h" using namespace BlackMisc::PhysicalQuantities; @@ -115,6 +116,7 @@ namespace BlackMisc template class IGeoObjectList; template class IGeoObjectList; template class IGeoObjectList; + template class IGeoObjectList; template class IGeoObjectWithRelativePositionList; template class IGeoObjectWithRelativePositionList; diff --git a/src/blackmisc/geo/geoobjectlist.h b/src/blackmisc/geo/geoobjectlist.h index 2d8bdd1af..a7eda6746 100644 --- a/src/blackmisc/geo/geoobjectlist.h +++ b/src/blackmisc/geo/geoobjectlist.h @@ -32,6 +32,12 @@ namespace BlackMisc { class CSimulatedAircraft; class CSimulatedAircraftList; + + namespace XPlane + { + class CNavDataReference; + class CNavDataReferenceList; + } } namespace Geo @@ -41,7 +47,6 @@ namespace BlackMisc class IGeoObjectList { public: - /*! * Find 0..n objects within range of given coordinate * \param coordinate other position @@ -71,6 +76,7 @@ namespace BlackMisc extern template class BLACKMISC_EXPORT_TEMPLATE IGeoObjectList; extern template class BLACKMISC_EXPORT_TEMPLATE IGeoObjectList; extern template class BLACKMISC_EXPORT_TEMPLATE IGeoObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE IGeoObjectList; //! \endcond //! List of objects with geo coordinates. diff --git a/src/blackmisc/simulation/xplane/navdatareference.cpp b/src/blackmisc/simulation/xplane/navdatareference.cpp new file mode 100644 index 000000000..d962b6417 --- /dev/null +++ b/src/blackmisc/simulation/xplane/navdatareference.cpp @@ -0,0 +1,58 @@ +/* Copyright (C) 2015 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#include "blackmisc/simulation/xplane/navdatareference.h" + +namespace BlackMisc +{ + namespace Simulation + { + namespace XPlane + { + CNavDataReference::CNavDataReference() = default; + + CNavDataReference::CNavDataReference(int id, const Geo::CLatitude &latitude, const Geo::CLongitude &longitude) : + m_id(id), + m_position(latitude, longitude, {}) + {} + + CNavDataReference::CNavDataReference(int id, float latitudeDegrees, float longitudeDegrees) : + m_id(id), + m_position(latitudeDegrees, longitudeDegrees, 0) + {} + + CVariant CNavDataReference::propertyByIndex(const BlackMisc::CPropertyIndex &index) const + { + if (index.isMyself()) { return CVariant::from(*this); } + return ICoordinateGeodetic::canHandleIndex(index) ? + ICoordinateGeodetic::propertyByIndex(index) : + CValueObject::propertyByIndex(index); + } + + void CNavDataReference::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index) + { + if (index.isMyself()) { (*this) = variant.to(); return; } + CValueObject::setPropertyByIndex(variant, index); + } + + QString CNavDataReference::convertToQString(bool i18n) const + { + return QString::number(id()) + ":" + m_position.convertToQString(i18n); + } + + CNavDataReferenceList::CNavDataReferenceList() = default; + + CNavDataReferenceList::CNavDataReferenceList(const CSequence &other) : + CSequence(other) + {} + } + } +} diff --git a/src/blackmisc/simulation/xplane/navdatareference.h b/src/blackmisc/simulation/xplane/navdatareference.h new file mode 100644 index 000000000..a65a07a2a --- /dev/null +++ b/src/blackmisc/simulation/xplane/navdatareference.h @@ -0,0 +1,94 @@ +/* Copyright (C) 2015 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKMISC_SIMULATION_XPLANE_NAVDATAREFERENCE_H +#define BLACKMISC_SIMULATION_XPLANE_NAVDATAREFERENCE_H + +#include "blackmisc/sequence.h" +#include "blackmisc/geo/geoobjectlist.h" +#include "blackmisc/geo/coordinategeodetic.h" + +namespace BlackMisc +{ + namespace Simulation + { + namespace XPlane + { + /*! + * Reference to an entry in X-Plane's navigation data (airport, navaid, fix, etc.) with its position. + */ + class BLACKMISC_EXPORT CNavDataReference : public CValueObject, public Geo::ICoordinateGeodetic + { + public: + //! Default constructor. + CNavDataReference(); + + //! Construct from a navdata reference ID and position. + CNavDataReference(int id, const Geo::CLatitude &latitude, const Geo::CLongitude &longitude); + + //! Construct from a navdata reference ID and position. + CNavDataReference(int id, float latitudeDegrees, float longitudeDegrees); + + //! Return the navdata reference ID. + int id() const { return m_id; } + + virtual Geo::CLatitude latitude() const override { return m_position.latitude(); } + virtual Geo::CLongitude longitude() const override { return m_position.longitude(); } + virtual const PhysicalQuantities::CLength &geodeticHeight() const override { return m_position.geodeticHeight(); } + virtual QVector3D normalVector() const override { return m_position.normalVector(); } + + //! \copydoc CValueObject::propertyByIndex + CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; + + //! \copydoc CValueObject::setPropertyByIndex + void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index); + + //! \copydoc CValueObject::convertToQString + QString convertToQString(bool i18n = false) const; + + private: + BLACK_ENABLE_TUPLE_CONVERSION(CNavDataReference) + int m_id = 0; + Geo::CCoordinateGeodetic m_position; + }; + + /*! + * List of X-Plane navigation data entries (airports, navaids, fixes, etc) with their positions. + */ + class BLACKMISC_EXPORT CNavDataReferenceList : + public CSequence, + public Geo::IGeoObjectList, + public Mixin::MetaType + { + public: + BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CNavDataReferenceList) + + //! Default constructor. + CNavDataReferenceList(); + + //! Construct from a base class object. + CNavDataReferenceList(const CSequence &other); + }; + } + } +} + +Q_DECLARE_METATYPE(BlackMisc::Simulation::XPlane::CNavDataReference) +Q_DECLARE_METATYPE(BlackMisc::Simulation::XPlane::CNavDataReferenceList) +Q_DECLARE_METATYPE(BlackMisc::CSequence) +Q_DECLARE_METATYPE(BlackMisc::CCollection) + +BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Simulation::XPlane::CNavDataReference, ( + attr(o.m_id), + attr(o.m_position) +)) + +#endif