From c8f11877555759b7fe3732da281bb22b0ffd5d80 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Thu, 2 May 2024 00:20:00 -0500 Subject: [PATCH] Display selected units for level 3 data --- scwx-qt/source/scwx/qt/types/unit_types.cpp | 29 ++++ scwx-qt/source/scwx/qt/types/unit_types.hpp | 2 + .../scwx/qt/view/level3_product_view.cpp | 131 +++++++++++++++++- 3 files changed, 158 insertions(+), 4 deletions(-) diff --git a/scwx-qt/source/scwx/qt/types/unit_types.cpp b/scwx-qt/source/scwx/qt/types/unit_types.cpp index 71d6288c..fbab05da 100644 --- a/scwx-qt/source/scwx/qt/types/unit_types.cpp +++ b/scwx-qt/source/scwx/qt/types/unit_types.cpp @@ -25,6 +25,16 @@ static const std::unordered_map {AccumulationUnits::User, "User-defined"}, {AccumulationUnits::Unknown, "?"}}; +static constexpr auto accumulationUnitsBase_ = units::millimeters {1.0f}; +static const std::unordered_map + accumulationUnitsScale_ { + {AccumulationUnits::Inches, + (accumulationUnitsBase_ / units::inches {1.0f})}, + {AccumulationUnits::Millimeters, + (accumulationUnitsBase_ / units::millimeters {1.0f})}, + {AccumulationUnits::User, 1.0f}, + {AccumulationUnits::Unknown, 1.0f}}; + static const std::unordered_map echoTopsUnitsAbbreviation_ {{EchoTopsUnits::Kilofeet, "kft"}, {EchoTopsUnits::Kilometers, "km"}, @@ -37,6 +47,15 @@ static const std::unordered_map echoTopsUnitsName_ { {EchoTopsUnits::User, "User-defined"}, {EchoTopsUnits::Unknown, "?"}}; +static constexpr auto echoTopsUnitsBase_ = units::kilometers {1.0f}; +static const std::unordered_map echoTopsUnitsScale_ { + {EchoTopsUnits::Kilofeet, + (echoTopsUnitsBase_ / units::feet {1000.0f})}, + {EchoTopsUnits::Kilometers, + (echoTopsUnitsBase_ / units::kilometers {1.0f})}, + {EchoTopsUnits::User, 1.0f}, + {EchoTopsUnits::Unknown, 1.0f}}; + static const std::unordered_map otherUnitsName_ { {OtherUnits::Default, "Default"}, {OtherUnits::User, "User-defined"}, @@ -87,6 +106,11 @@ const std::string& GetAccumulationUnitsName(AccumulationUnits units) return accumulationUnitsName_.at(units); } +float GetAccumulationUnitsScale(AccumulationUnits units) +{ + return accumulationUnitsScale_.at(units); +} + const std::string& GetEchoTopsUnitsAbbreviation(EchoTopsUnits units) { return echoTopsUnitsAbbreviation_.at(units); @@ -97,6 +121,11 @@ const std::string& GetEchoTopsUnitsName(EchoTopsUnits units) return echoTopsUnitsName_.at(units); } +float GetEchoTopsUnitsScale(EchoTopsUnits units) +{ + return echoTopsUnitsScale_.at(units); +} + const std::string& GetOtherUnitsName(OtherUnits units) { return otherUnitsName_.at(units); diff --git a/scwx-qt/source/scwx/qt/types/unit_types.hpp b/scwx-qt/source/scwx/qt/types/unit_types.hpp index 2fd1c5ab..fd1a012b 100644 --- a/scwx-qt/source/scwx/qt/types/unit_types.hpp +++ b/scwx-qt/source/scwx/qt/types/unit_types.hpp @@ -59,10 +59,12 @@ typedef scwx::util:: const std::string& GetAccumulationUnitsAbbreviation(AccumulationUnits units); const std::string& GetAccumulationUnitsName(AccumulationUnits units); AccumulationUnits GetAccumulationUnitsFromName(const std::string& name); +float GetAccumulationUnitsScale(AccumulationUnits units); const std::string& GetEchoTopsUnitsAbbreviation(EchoTopsUnits units); const std::string& GetEchoTopsUnitsName(EchoTopsUnits units); EchoTopsUnits GetEchoTopsUnitsFromName(const std::string& name); +float GetEchoTopsUnitsScale(EchoTopsUnits units); const std::string& GetOtherUnitsName(OtherUnits units); OtherUnits GetOtherUnitsFromName(const std::string& name); diff --git a/scwx-qt/source/scwx/qt/view/level3_product_view.cpp b/scwx-qt/source/scwx/qt/view/level3_product_view.cpp index cca7d1c0..cd6765bc 100644 --- a/scwx-qt/source/scwx/qt/view/level3_product_view.cpp +++ b/scwx-qt/source/scwx/qt/view/level3_product_view.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include #include #include @@ -31,11 +33,22 @@ static const auto logger_ = util::Logger::Create(logPrefix_); static constexpr uint16_t RANGE_FOLDED = 1u; +static const std::unordered_map + categoryUnits_ { + {common::Level3ProductCategory::Reflectivity, "dBZ"}, + {common::Level3ProductCategory::DifferentialReflectivity, "dB"}, + {common::Level3ProductCategory::SpecificDifferentialPhase, + common::Unicode::kDegree + "/km"}, + {common::Level3ProductCategory::CorrelationCoefficient, "%"}, + {common::Level3ProductCategory::VerticallyIntegratedLiquid, + "kg/m\302\262"}}; + class Level3ProductView::Impl { public: explicit Impl(const std::string& product) : product_ {product}, + category_ {common::GetLevel3CategoryByAwipsId(product)}, graphicMessage_ {nullptr}, colorTable_ {}, colorTableLut_ {}, @@ -45,10 +58,48 @@ public: savedScale_ {0.0f}, savedOffset_ {0.0f} { - } - ~Impl() = default; + auto& unitSettings = settings::UnitSettings::Instance(); - std::string product_; + accumulationUnitsCallbackUuid_ = + unitSettings.accumulation_units().RegisterValueChangedCallback( + [this](const std::string& value) + { UpdateAccumulationUnits(value); }); + echoTopsUnitsCallbackUuid_ = + unitSettings.echo_tops_units().RegisterValueChangedCallback( + [this](const std::string& value) { UpdateEchoTopsUnits(value); }); + otherUnitsCallbackUuid_ = + unitSettings.other_units().RegisterValueChangedCallback( + [this](const std::string& value) { UpdateOtherUnits(value); }); + speedUnitsCallbackUuid_ = + unitSettings.speed_units().RegisterValueChangedCallback( + [this](const std::string& value) { UpdateSpeedUnits(value); }); + + UpdateAccumulationUnits(unitSettings.accumulation_units().GetValue()); + UpdateEchoTopsUnits(unitSettings.echo_tops_units().GetValue()); + UpdateOtherUnits(unitSettings.other_units().GetValue()); + UpdateSpeedUnits(unitSettings.speed_units().GetValue()); + } + ~Impl() + { + auto& unitSettings = settings::UnitSettings::Instance(); + + unitSettings.accumulation_units().UnregisterValueChangedCallback( + accumulationUnitsCallbackUuid_); + unitSettings.echo_tops_units().UnregisterValueChangedCallback( + echoTopsUnitsCallbackUuid_); + unitSettings.other_units().UnregisterValueChangedCallback( + otherUnitsCallbackUuid_); + unitSettings.speed_units().UnregisterValueChangedCallback( + speedUnitsCallbackUuid_); + }; + + void UpdateAccumulationUnits(const std::string& name); + void UpdateEchoTopsUnits(const std::string& name); + void UpdateOtherUnits(const std::string& name); + void UpdateSpeedUnits(const std::string& name); + + std::string product_; + common::Level3ProductCategory category_; std::shared_ptr graphicMessage_; @@ -63,6 +114,16 @@ public: std::uint16_t savedLogStart_ {20u}; float savedLogScale_ {1.0f}; float savedLogOffset_ {0.0f}; + + boost::uuids::uuid accumulationUnitsCallbackUuid_ {}; + boost::uuids::uuid echoTopsUnitsCallbackUuid_ {}; + boost::uuids::uuid otherUnitsCallbackUuid_ {}; + boost::uuids::uuid speedUnitsCallbackUuid_ {}; + types::AccumulationUnits accumulationUnits_ { + types::AccumulationUnits::Unknown}; + types::EchoTopsUnits echoTopsUnits_ {types::EchoTopsUnits::Unknown}; + types::OtherUnits otherUnits_ {types::OtherUnits::Unknown}; + types::SpeedUnits speedUnits_ {types::SpeedUnits::Unknown}; }; Level3ProductView::Level3ProductView( @@ -145,11 +206,52 @@ uint16_t Level3ProductView::color_table_max() const float Level3ProductView::unit_scale() const { + switch (p->category_) + { + case common::Level3ProductCategory::Velocity: + case common::Level3ProductCategory::SpectrumWidth: + return types::GetSpeedUnitsScale(p->speedUnits_); + + case common::Level3ProductCategory::EchoTops: + return types::GetEchoTopsUnitsScale(p->echoTopsUnits_); + + case common::Level3ProductCategory::PrecipitationAccumulation: + return types::GetAccumulationUnitsScale(p->accumulationUnits_); + + default: + break; + } + return 1.0f; } std::string Level3ProductView::units() const { + switch (p->category_) + { + case common::Level3ProductCategory::Velocity: + case common::Level3ProductCategory::SpectrumWidth: + return types::GetSpeedUnitsAbbreviation(p->speedUnits_); + + case common::Level3ProductCategory::EchoTops: + return types::GetEchoTopsUnitsAbbreviation(p->echoTopsUnits_); + + case common::Level3ProductCategory::PrecipitationAccumulation: + return types::GetAccumulationUnitsAbbreviation(p->accumulationUnits_); + + default: + break; + } + + if (p->otherUnits_ == types::OtherUnits::Default) + { + auto it = categoryUnits_.find(p->category_); + if (it != categoryUnits_.cend()) + { + return it->second; + } + } + return {}; } @@ -175,9 +277,30 @@ std::string Level3ProductView::GetRadarProductName() const return p->product_; } +void Level3ProductView::Impl::UpdateAccumulationUnits(const std::string& name) +{ + accumulationUnits_ = types::GetAccumulationUnitsFromName(name); +} + +void Level3ProductView::Impl::UpdateEchoTopsUnits(const std::string& name) +{ + echoTopsUnits_ = types::GetEchoTopsUnitsFromName(name); +} + +void Level3ProductView::Impl::UpdateOtherUnits(const std::string& name) +{ + otherUnits_ = types::GetOtherUnitsFromName(name); +} + +void Level3ProductView::Impl::UpdateSpeedUnits(const std::string& name) +{ + speedUnits_ = types::GetSpeedUnitsFromName(name); +} + void Level3ProductView::SelectProduct(const std::string& productName) { - p->product_ = productName; + p->product_ = productName; + p->category_ = common::GetLevel3CategoryByAwipsId(productName); } std::vector>