From af28db9e97f06d3cf7b438c128e45d1046be341f Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Wed, 2 Mar 2016 22:58:38 +0100 Subject: [PATCH] Add CVisibilityLayer and CVisibilityLayerList refs #579 --- src/blackmisc/propertyindex.h | 1 + src/blackmisc/weather/gridpoint.cpp | 4 +- src/blackmisc/weather/gridpoint.h | 11 +++ .../weather/registermetadataweather.cpp | 2 + src/blackmisc/weather/visibilitylayer.cpp | 75 +++++++++++++++ src/blackmisc/weather/visibilitylayer.h | 91 +++++++++++++++++++ src/blackmisc/weather/visibilitylayerlist.cpp | 33 +++++++ src/blackmisc/weather/visibilitylayerlist.h | 55 +++++++++++ src/blackmisc/weather/weather.h | 2 + .../weatherdata/gfs/weatherdatagfs.cpp | 2 +- 10 files changed, 274 insertions(+), 2 deletions(-) create mode 100644 src/blackmisc/weather/visibilitylayer.cpp create mode 100644 src/blackmisc/weather/visibilitylayer.h create mode 100644 src/blackmisc/weather/visibilitylayerlist.cpp create mode 100644 src/blackmisc/weather/visibilitylayerlist.h diff --git a/src/blackmisc/propertyindex.h b/src/blackmisc/propertyindex.h index 2a22bf4c5..3e27f34c6 100644 --- a/src/blackmisc/propertyindex.h +++ b/src/blackmisc/propertyindex.h @@ -72,6 +72,7 @@ namespace BlackMisc GlobalIndexCWindLayer = 4300, GlobalIndexCTemperatureLayer = 4400, GlobalIndexCGridPoint = 4500, + GlobalIndexCVisibilityLayer = 4600, GlobalIndexICoordinateGeodetic = 5000, GlobalIndexCCoordinateGeodetic = 5100, GlobalIndexCClient = 6000, diff --git a/src/blackmisc/weather/gridpoint.cpp b/src/blackmisc/weather/gridpoint.cpp index d31b21c33..c14eaa311 100644 --- a/src/blackmisc/weather/gridpoint.cpp +++ b/src/blackmisc/weather/gridpoint.cpp @@ -23,9 +23,11 @@ namespace BlackMisc CGridPoint::CGridPoint(const Geo::CLatitude &latitude, const Geo::CLongitude longitude, const CCloudLayerList &cloudLayers, const CTemperatureLayerList &temperatureLayers, + const CVisibilityLayerList &visibilityLayers, const CWindLayerList &windLayers) : m_latitude(latitude), m_longitude(longitude), m_cloudLayers(cloudLayers), - m_temperatureLayers(temperatureLayers), m_windLayers(windLayers) + m_temperatureLayers(temperatureLayers), m_visibilityLayers(visibilityLayers), + m_windLayers(windLayers) { } CVariant CGridPoint::propertyByIndex(const BlackMisc::CPropertyIndex &index) const diff --git a/src/blackmisc/weather/gridpoint.h b/src/blackmisc/weather/gridpoint.h index 89b754929..f920d9225 100644 --- a/src/blackmisc/weather/gridpoint.h +++ b/src/blackmisc/weather/gridpoint.h @@ -20,6 +20,7 @@ #include "blackmisc/geo/longitude.h" #include "blackmisc/weather/cloudlayerlist.h" #include "blackmisc/weather/temperaturelayerlist.h" +#include "blackmisc/weather/visibilitylayerlist.h" #include "blackmisc/weather/windlayerlist.h" namespace BlackMisc @@ -49,6 +50,7 @@ namespace BlackMisc CGridPoint(const Geo::CLatitude &latitude, const Geo::CLongitude longitude, const CCloudLayerList &cloudLayers, const CTemperatureLayerList &temperatureLayers, + const CVisibilityLayerList &visibilityLayers, const CWindLayerList &windLayers); //! Set latitude @@ -75,6 +77,12 @@ namespace BlackMisc //! Get temperature layers CTemperatureLayerList getTemperatureLayers() const { return m_temperatureLayers; } + //! Set visibility layers + void setVisibilityLayers(const CVisibilityLayerList &visibilityLayers) { m_visibilityLayers = visibilityLayers; } + + //! Get visibility layers + CVisibilityLayerList getVisibilityLayers() const { return m_visibilityLayers; } + //! Set wind layers void setWindLayers(const CWindLayerList &windLayers) { m_windLayers = windLayers; } @@ -96,7 +104,9 @@ namespace BlackMisc Geo::CLongitude m_longitude; CCloudLayerList m_cloudLayers; CTemperatureLayerList m_temperatureLayers; + CVisibilityLayerList m_visibilityLayers; CWindLayerList m_windLayers; + }; } // namespace } // namespace @@ -107,6 +117,7 @@ BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Weather::CGridPoint, ( attr(o.m_longitude), attr(o.m_cloudLayers), attr(o.m_temperatureLayers), + attr(o.m_visibilityLayers), attr(o.m_windLayers) )) diff --git a/src/blackmisc/weather/registermetadataweather.cpp b/src/blackmisc/weather/registermetadataweather.cpp index a24a3d2bc..f1073e9bf 100644 --- a/src/blackmisc/weather/registermetadataweather.cpp +++ b/src/blackmisc/weather/registermetadataweather.cpp @@ -25,6 +25,8 @@ namespace BlackMisc CPresentWeatherList::registerMetadata(); CTemperatureLayer::registerMetadata(); CTemperatureLayerList::registerMetadata(); + CVisibilityLayer::registerMetadata(); + CVisibilityLayerList::registerMetadata(); CWeatherDataPluginInfo::registerMetadata(); CWeatherDataPluginInfoList::registerMetadata(); CWeatherGrid::registerMetadata(); diff --git a/src/blackmisc/weather/visibilitylayer.cpp b/src/blackmisc/weather/visibilitylayer.cpp new file mode 100644 index 000000000..f332d7aa5 --- /dev/null +++ b/src/blackmisc/weather/visibilitylayer.cpp @@ -0,0 +1,75 @@ +/* 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 "blackmisc/weather/visibilitylayer.h" +#include "blackmisc/propertyindex.h" +#include "blackmisc/blackmiscfreefunctions.h" +#include "blackmisc/variant.h" + +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Aviation; + +namespace BlackMisc +{ + namespace Weather + { + + CVisibilityLayer::CVisibilityLayer(const BlackMisc::Aviation::CAltitude &base, + const BlackMisc::Aviation::CAltitude &top, + const PhysicalQuantities::CLength &visibility) : + m_base(base), m_top(top), m_visibility(visibility) + { } + + CVariant CVisibilityLayer::propertyByIndex(const BlackMisc::CPropertyIndex &index) const + { + if (index.isMyself()) { return CVariant::from(*this); } + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexBase: + return CVariant::fromValue(m_base); + case IndexTop: + return CVariant::fromValue(m_top); + case IndexVisibility: + return CVariant::fromValue(m_visibility); + default: + return CValueObject::propertyByIndex(index); + } + } + + void CVisibilityLayer::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index) + { + if (index.isMyself()) { (*this) = variant.to(); return; } + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexBase: + setBase(variant.value()); + break; + case IndexTop: + setTop(variant.value()); + break; + case IndexVisibility: + setVisibility(variant.value()); + break; + default: + CValueObject::setPropertyByIndex(variant, index); + break; + } + } + + QString CVisibilityLayer::convertToQString(bool /** i18n **/) const + { + QString visibilityAsString = QString("Visibility: %1 from %2 to %3"); + visibilityAsString = visibilityAsString.arg(m_visibility.toQString(), m_base.toQString(), m_top.toQString()); + return visibilityAsString; + } + + } // namespace +} // namespace diff --git a/src/blackmisc/weather/visibilitylayer.h b/src/blackmisc/weather/visibilitylayer.h new file mode 100644 index 000000000..39cf0ce12 --- /dev/null +++ b/src/blackmisc/weather/visibilitylayer.h @@ -0,0 +1,91 @@ +/* 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_WEATHER_VISIBILITYLAYER_H +#define BLACKMISC_WEATHER_VISIBILITYLAYER_H + +#include "blackmisc/blackmiscexport.h" +#include "blackmisc/valueobject.h" +#include "blackmisc/propertyindex.h" +#include "blackmisc/aviation/altitude.h" +#include "blackmisc/pq/length.h" + +namespace BlackMisc +{ + namespace Weather + { + /*! + * Value object for a visibility layer + */ + class BLACKMISC_EXPORT CVisibilityLayer : public CValueObject + { + public: + //! Properties by index + enum ColumnIndex + { + IndexBase = BlackMisc::CPropertyIndex::GlobalIndexCVisibilityLayer, + IndexTop, + IndexVisibility, + }; + + //! Default constructor. + CVisibilityLayer() = default; + + //! Constructor + CVisibilityLayer(const BlackMisc::Aviation::CAltitude &base, + const BlackMisc::Aviation::CAltitude &top, + const PhysicalQuantities::CLength &visibility); + + //! Set base + void setBase(const BlackMisc::Aviation::CAltitude &base) { m_base = base; } + + //! Get base + BlackMisc::Aviation::CAltitude getBase() const { return m_base; } + + //! Set top + void setTop(const BlackMisc::Aviation::CAltitude &top) { m_top = top; } + + //! Get top + BlackMisc::Aviation::CAltitude getTop() const { return m_top; } + + //! Set visibility + void setVisibility(const PhysicalQuantities::CLength &visibility) { m_visibility = visibility; } + + //! Get visibility + PhysicalQuantities::CLength getVisibility() const { return m_visibility; } + + //! \copydoc BlackMisc::Mixin::Index::propertyByIndex + CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; + + //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex + void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index); + + //! \copydoc BlackMisc::Mixin::String::toQString + QString convertToQString(bool i18n = false) const; + + private: + BLACK_ENABLE_TUPLE_CONVERSION(CVisibilityLayer) + BlackMisc::Aviation::CAltitude m_base; + BlackMisc::Aviation::CAltitude m_top; + PhysicalQuantities::CLength m_visibility; + }; + + } // namespace +} // namespace + +Q_DECLARE_METATYPE(BlackMisc::Weather::CVisibilityLayer) +BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Weather::CVisibilityLayer, ( + attr(o.m_base), + attr(o.m_top), + attr(o.m_visibility) + )) + +#endif // guard diff --git a/src/blackmisc/weather/visibilitylayerlist.cpp b/src/blackmisc/weather/visibilitylayerlist.cpp new file mode 100644 index 000000000..d42d77958 --- /dev/null +++ b/src/blackmisc/weather/visibilitylayerlist.cpp @@ -0,0 +1,33 @@ +/* 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 "visibilitylayerlist.h" + +using namespace BlackMisc::Aviation; + +namespace BlackMisc +{ + namespace Weather + { + CVisibilityLayerList::CVisibilityLayerList(const CSequence &other) : + CSequence(other) + { } + + bool CVisibilityLayerList::containsBase(const CAltitude &base) const + { + return contains(&CVisibilityLayer::getBase, base); + } + + CVisibilityLayer CVisibilityLayerList::findByBase(const CAltitude &base) const + { + return findFirstByOrDefault(&CVisibilityLayer::getBase, base); + } + + } // namespace +} // namespace diff --git a/src/blackmisc/weather/visibilitylayerlist.h b/src/blackmisc/weather/visibilitylayerlist.h new file mode 100644 index 000000000..f2a4e2072 --- /dev/null +++ b/src/blackmisc/weather/visibilitylayerlist.h @@ -0,0 +1,55 @@ +/* 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_WEATHER_VISIBILITYLAYERLIST_H +#define BLACKMISC_WEATHER_VISIBILITYLAYERLIST_H + +#include "visibilitylayer.h" +#include "blackmisc/blackmiscexport.h" +#include "blackmisc/sequence.h" + +namespace BlackMisc +{ + namespace Weather + { + /*! + * Value object encapsulating a set of visibility layers + */ + class BLACKMISC_EXPORT CVisibilityLayerList : + public CSequence, + public BlackMisc::Mixin::MetaType + { + public: + BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CVisibilityLayerList) + + //! Default constructor. + CVisibilityLayerList() = default; + + //! Initializer list constructor. + CVisibilityLayerList(std::initializer_list il) : CSequence(il) {} + + //! Construct from a base class object. + CVisibilityLayerList(const CSequence &other); + + //! Contains visibility layer with base? + bool containsBase(const BlackMisc::Aviation::CAltitude &base) const; + + //! Find visibility layer by base + CVisibilityLayer findByBase(const BlackMisc::Aviation::CAltitude &base) const; + }; + + } //namespace +} // namespace + +Q_DECLARE_METATYPE(BlackMisc::Weather::CVisibilityLayerList) +Q_DECLARE_METATYPE(BlackMisc::CSequence) + +#endif //guard diff --git a/src/blackmisc/weather/weather.h b/src/blackmisc/weather/weather.h index f6c0c2e83..7ad369f44 100644 --- a/src/blackmisc/weather/weather.h +++ b/src/blackmisc/weather/weather.h @@ -26,6 +26,8 @@ #include "blackmisc/weather/presentweatherlist.h" #include "blackmisc/weather/temperaturelayer.h" #include "blackmisc/weather/temperaturelayerlist.h" +#include "blackmisc/weather/visibilitylayer.h" +#include "blackmisc/weather/visibilitylayerlist.h" #include "blackmisc/weather/weatherdataplugininfo.h" #include "blackmisc/weather/weatherdataplugininfolist.h" #include "blackmisc/weather/weathergrid.h" diff --git a/src/plugins/weatherdata/gfs/weatherdatagfs.cpp b/src/plugins/weatherdata/gfs/weatherdatagfs.cpp index ed1627d1a..aecacce90 100644 --- a/src/plugins/weatherdata/gfs/weatherdatagfs.cpp +++ b/src/plugins/weatherdata/gfs/weatherdatagfs.cpp @@ -270,7 +270,7 @@ namespace BlackWxPlugin CLatitude latitude(gfsGridPoint.latitude, CAngleUnit::deg()); CLongitude longitude(gfsGridPoint.longitude, CAngleUnit::deg()); - BlackMisc::Weather::CGridPoint gridPoint(latitude, longitude, cloudLayers, temperatureLayers, windLayers); + BlackMisc::Weather::CGridPoint gridPoint(latitude, longitude, cloudLayers, temperatureLayers, {}, windLayers); m_weatherGrid.insert(gridPoint); } }