From c2329d9623bd15b9d307c2fa8d557bda3b8a29f8 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Wed, 1 May 2024 23:13:23 -0500 Subject: [PATCH] Complete level 2 default units --- .../scwx/qt/view/level2_product_view.cpp | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/scwx-qt/source/scwx/qt/view/level2_product_view.cpp b/scwx-qt/source/scwx/qt/view/level2_product_view.cpp index 7fd8df11..5caa386f 100644 --- a/scwx-qt/source/scwx/qt/view/level2_product_view.cpp +++ b/scwx-qt/source/scwx/qt/view/level2_product_view.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,14 @@ static const std::unordered_map + productUnits_ { + {common::Level2Product::Reflectivity, "dBZ"}, + {common::Level2Product::DifferentialReflectivity, "dB"}, + {common::Level2Product::DifferentialPhase, common::Unicode::kDegree}, + {common::Level2Product::CorrelationCoefficient, "%"}, + {common::Level2Product::ClutterFilterPowerRemoved, "dB"}}; + class Level2ProductViewImpl { public: @@ -76,15 +85,22 @@ public: SetProduct(product); + otherUnitsCallbackUuid_ = + unitSettings.other_units().RegisterValueChangedCallback( + [this](const std::string& value) { UpdateOtherUnits(value); }); speedUnitsCallbackUuid_ = unitSettings.speed_units().RegisterValueChangedCallback( [this](const std::string& value) { UpdateSpeedUnits(value); }); + UpdateOtherUnits(unitSettings.other_units().GetValue()); UpdateSpeedUnits(unitSettings.speed_units().GetValue()); } ~Level2ProductViewImpl() { auto& unitSettings = settings::UnitSettings::Instance(); + + unitSettings.other_units().UnregisterValueChangedCallback( + otherUnitsCallbackUuid_); unitSettings.speed_units().UnregisterValueChangedCallback( speedUnitsCallbackUuid_); @@ -96,6 +112,7 @@ public: void SetProduct(const std::string& productName); void SetProduct(common::Level2Product product); + void UpdateOtherUnits(const std::string& name); void UpdateSpeedUnits(const std::string& name); Level2ProductView* self_; @@ -135,7 +152,9 @@ public: float savedScale_; float savedOffset_; + boost::uuids::uuid otherUnitsCallbackUuid_ {}; boost::uuids::uuid speedUnitsCallbackUuid_ {}; + types::OtherUnits otherUnits_ {types::OtherUnits::Unknown}; types::SpeedUnits speedUnits_ {types::SpeedUnits::Unknown}; }; @@ -244,10 +263,10 @@ std::chrono::system_clock::time_point Level2ProductView::sweep_time() const float Level2ProductView::unit_scale() const { - switch (p->dataBlockType_) + switch (p->product_) { - case wsr88d::rda::DataBlockType::MomentVel: - case wsr88d::rda::DataBlockType::MomentSw: + case common::Level2Product::Velocity: + case common::Level2Product::SpectrumWidth: return types::GetSpeedUnitsScale(p->speedUnits_); default: @@ -259,16 +278,25 @@ float Level2ProductView::unit_scale() const std::string Level2ProductView::units() const { - switch (p->dataBlockType_) + switch (p->product_) { - case wsr88d::rda::DataBlockType::MomentVel: - case wsr88d::rda::DataBlockType::MomentSw: + case common::Level2Product::Velocity: + case common::Level2Product::SpectrumWidth: return types::GetSpeedUnitsAbbreviation(p->speedUnits_); default: break; } + if (p->otherUnits_ == types::OtherUnits::Default) + { + auto it = productUnits_.find(p->product_); + if (it != productUnits_.cend()) + { + return it->second; + } + } + return {}; } @@ -374,6 +402,11 @@ void Level2ProductViewImpl::SetProduct(common::Level2Product product) } } +void Level2ProductViewImpl::UpdateOtherUnits(const std::string& name) +{ + otherUnits_ = types::GetOtherUnitsFromName(name); +} + void Level2ProductViewImpl::UpdateSpeedUnits(const std::string& name) { speedUnits_ = types::GetSpeedUnitsFromName(name);