From 70aee605cbad79eca27233c7189e6217953de2a4 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 21 Dec 2016 22:08:54 +0100 Subject: [PATCH] refs #840, value classes for ground elevation plane Can be used as single point elevation or plane covering an airport --- src/blackmisc/geo/elevationplane.cpp | 105 ++++++++++++++++++++++ src/blackmisc/geo/elevationplane.h | 91 +++++++++++++++++++ src/blackmisc/geo/geo.h | 1 + src/blackmisc/geo/registermetadatageo.cpp | 1 + 4 files changed, 198 insertions(+) create mode 100644 src/blackmisc/geo/elevationplane.cpp create mode 100644 src/blackmisc/geo/elevationplane.h diff --git a/src/blackmisc/geo/elevationplane.cpp b/src/blackmisc/geo/elevationplane.cpp new file mode 100644 index 000000000..66b02916a --- /dev/null +++ b/src/blackmisc/geo/elevationplane.cpp @@ -0,0 +1,105 @@ +/* Copyright (C) 2016 + * 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. + */ + +#include "elevationplane.h" +#include "blackmisc/pq/length.h" +#include "blackmisc/propertyindex.h" + +using namespace BlackMisc::PhysicalQuantities; + +namespace BlackMisc +{ + namespace Geo + { + QString CElevationPlane::convertToQString(bool i18n) const + { + QString s = "Geodetic: {%1, %2, %3} radius: %4"; + return s.arg(this->latitude().valueRoundedWithUnit(6, i18n), + this->longitude().valueRoundedWithUnit(6, i18n), + this->geodeticHeight().valueRoundedWithUnit(6, i18n), + this->m_radius.valueRoundedWithUnit(2, i18n) + ); + } + + bool CElevationPlane::isNull() const + { + return m_radius.isNull(); + } + + bool CElevationPlane::isWithinRange(const ICoordinateGeodetic &coordinate) const + { + if (m_radius.isNull()) { return false; } + const CLength d = this->calculateGreatCircleDistance(coordinate); + const bool inRange = m_radius >= d; + return inRange; + } + + void CElevationPlane::setSinglePointRadius() + { + m_radius = singlePointRadius(); + } + + void CElevationPlane::setMinorAirportRadius() + { + m_radius = minorAirportRadius(); + } + + void CElevationPlane::setMajorAirportRadius() + { + m_radius = majorAirportRadius(); + } + + CVariant CElevationPlane::propertyByIndex(const BlackMisc::CPropertyIndex &index) const + { + if (index.isMyself()) { return CVariant::from(*this); } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexRadius: + return m_radius.propertyByIndex(index.copyFrontRemoved()); + default: + break; + } + return CCoordinateGeodetic::propertyByIndex(index); + } + + void CElevationPlane::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) + { + if (index.isMyself()) { (*this) = variant.to(); return; } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexRadius: + this->m_radius.setPropertyByIndex(index.copyFrontRemoved(), variant); + break; + default: + CCoordinateGeodetic::setPropertyByIndex(index, variant); + break; + } + } + + const CLength &CElevationPlane::singlePointRadius() + { + static const CLength l(10.0, CLengthUnit::m()); + return l; + } + + const CLength &CElevationPlane::minorAirportRadius() + { + static const CLength l(500.0, CLengthUnit::m()); + return l; + } + + const CLength &CElevationPlane::majorAirportRadius() + { + static const CLength l(1000.0, CLengthUnit::m()); + return l; + } + } // namespace +} // namespace diff --git a/src/blackmisc/geo/elevationplane.h b/src/blackmisc/geo/elevationplane.h new file mode 100644 index 000000000..2e25970ef --- /dev/null +++ b/src/blackmisc/geo/elevationplane.h @@ -0,0 +1,91 @@ +/* Copyright (C) 2016 + * 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_GEO_ELEVATIONPLANE_H +#define BLACKMISC_GEO_ELEVATIONPLANE_H + +#include "blackmisc/blackmiscexport.h" +#include "blackmisc/geo/coordinategeodetic.h" + +namespace BlackMisc +{ + namespace Geo + { + //! Plane of same elevation, can be a single point or larger area (e.g. airport) + class BLACKMISC_EXPORT CElevationPlane : + public CValueObject + { + public: + //! Properties by index + enum ColumnIndex + { + IndexRadius = BlackMisc::CPropertyIndex::GlobalIndexCElevationPlane + }; + + //! Default constructor + CElevationPlane() {} + + //! Constructor + using CValueObject::CValueObject; + + //! Radius + const BlackMisc::PhysicalQuantities::CLength &getRadius() const { return m_radius; } + + //! Radius + void setRadius(const BlackMisc::PhysicalQuantities::CLength &radius) { m_radius = radius; } + + //! Existing value + bool isNull() const; + + //! Check if elevation is within radius and can be used + bool isWithinRange(const BlackMisc::Geo::ICoordinateGeodetic &coordinate) const; + + //! Treat as single point as obtained from simulator + void setSinglePointRadius(); + + //! Treat as elevation of a small airport + void setMinorAirportRadius(); + + //! Treat as elevation of a small airport + void setMajorAirportRadius(); + + //! \copydoc BlackMisc::Mixin::Index::propertyByIndex + CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; + + //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex + void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant); + + //! \copydoc BlackMisc::Mixin::String::toQString + QString convertToQString(bool i18n = false) const; + + //! Radius for single point + static const BlackMisc::PhysicalQuantities::CLength &singlePointRadius(); + + //! Radius for minor airport + static const BlackMisc::PhysicalQuantities::CLength &minorAirportRadius(); + + //! Radius for major airport + static const BlackMisc::PhysicalQuantities::CLength &majorAirportRadius(); + + private: + BlackMisc::PhysicalQuantities::CLength m_radius { 0, nullptr }; //!< elevation is valid in radius + + BLACK_METACLASS( + CElevationPlane, + BLACK_METAMEMBER(radius) + ); + }; + } // namespace +} // namespace + +Q_DECLARE_METATYPE(BlackMisc::Geo::CElevationPlane) + +#endif // guard diff --git a/src/blackmisc/geo/geo.h b/src/blackmisc/geo/geo.h index 8eb8b4c95..996e5db0f 100644 --- a/src/blackmisc/geo/geo.h +++ b/src/blackmisc/geo/geo.h @@ -19,5 +19,6 @@ #include "blackmisc/geo/latitude.h" #include "blackmisc/geo/longitude.h" #include "blackmisc/geo/coordinategeodetic.h" +#include "blackmisc/geo/elevationplane.h" #endif // guard diff --git a/src/blackmisc/geo/registermetadatageo.cpp b/src/blackmisc/geo/registermetadatageo.cpp index 3e8731414..822f9b566 100644 --- a/src/blackmisc/geo/registermetadatageo.cpp +++ b/src/blackmisc/geo/registermetadatageo.cpp @@ -19,6 +19,7 @@ namespace BlackMisc CCoordinateGeodetic::registerMetadata(); CLatitude::registerMetadata(); CLongitude::registerMetadata(); + CElevationPlane::registerMetadata(); } } // ns } // ns