mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 03:00:06 +00:00 
			
		
		
		
	Display the selected speed units for level 2 data
This commit is contained in:
		
							parent
							
								
									a29256d77e
								
							
						
					
					
						commit
						3df6363211
					
				
					 8 changed files with 117 additions and 16 deletions
				
			
		|  | @ -395,15 +395,25 @@ bool RadarProductLayer::RunMousePicking( | ||||||
|             std::string suffix {}; |             std::string suffix {}; | ||||||
|             std::string hoverText; |             std::string hoverText; | ||||||
| 
 | 
 | ||||||
|  |             // Determine units from radar product view
 | ||||||
|  |             units = radarProductView->units(); | ||||||
|  |             if (!units.empty()) | ||||||
|  |             { | ||||||
|  |                f = f * radarProductView->unit_scale(); | ||||||
|  |             } | ||||||
|  |             else | ||||||
|  |             { | ||||||
|                std::shared_ptr<common::ColorTable> colorTable = |                std::shared_ptr<common::ColorTable> colorTable = | ||||||
|                   radarProductView->color_table(); |                   radarProductView->color_table(); | ||||||
| 
 | 
 | ||||||
|                if (colorTable != nullptr) |                if (colorTable != nullptr) | ||||||
|                { |                { | ||||||
|                // Scale data value according to the color table, and get units
 |                   // Scale data value according to the color table, and get
 | ||||||
|  |                   // units
 | ||||||
|                   f     = f * colorTable->scale() + colorTable->offset(); |                   f     = f * colorTable->scale() + colorTable->offset(); | ||||||
|                   units = colorTable->units(); |                   units = colorTable->units(); | ||||||
|                } |                } | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
|             if (code.has_value() && |             if (code.has_value() && | ||||||
|                 code.value() == wsr88d::DataLevelCode::Topped) |                 code.value() == wsr88d::DataLevelCode::Topped) | ||||||
|  |  | ||||||
|  | @ -4,6 +4,7 @@ | ||||||
| #include <unordered_map> | #include <unordered_map> | ||||||
| 
 | 
 | ||||||
| #include <boost/algorithm/string.hpp> | #include <boost/algorithm/string.hpp> | ||||||
|  | #include <units/velocity.h> | ||||||
| 
 | 
 | ||||||
| namespace scwx | namespace scwx | ||||||
| { | { | ||||||
|  | @ -15,8 +16,8 @@ namespace types | ||||||
| static const std::unordered_map<AccumulationUnits, std::string> | static const std::unordered_map<AccumulationUnits, std::string> | ||||||
|    accumulationUnitsAbbreviation_ {{AccumulationUnits::Inches, "in"}, |    accumulationUnitsAbbreviation_ {{AccumulationUnits::Inches, "in"}, | ||||||
|                                    {AccumulationUnits::Millimeters, "mm"}, |                                    {AccumulationUnits::Millimeters, "mm"}, | ||||||
|                                    {AccumulationUnits::User, "?"}, |                                    {AccumulationUnits::User, ""}, | ||||||
|                                    {AccumulationUnits::Unknown, "?"}}; |                                    {AccumulationUnits::Unknown, ""}}; | ||||||
| 
 | 
 | ||||||
| static const std::unordered_map<AccumulationUnits, std::string> | static const std::unordered_map<AccumulationUnits, std::string> | ||||||
|    accumulationUnitsName_ {{AccumulationUnits::Inches, "Inches"}, |    accumulationUnitsName_ {{AccumulationUnits::Inches, "Inches"}, | ||||||
|  | @ -27,8 +28,8 @@ static const std::unordered_map<AccumulationUnits, std::string> | ||||||
| static const std::unordered_map<EchoTopsUnits, std::string> | static const std::unordered_map<EchoTopsUnits, std::string> | ||||||
|    echoTopsUnitsAbbreviation_ {{EchoTopsUnits::Kilofeet, "kft"}, |    echoTopsUnitsAbbreviation_ {{EchoTopsUnits::Kilofeet, "kft"}, | ||||||
|                                {EchoTopsUnits::Kilometers, "km"}, |                                {EchoTopsUnits::Kilometers, "km"}, | ||||||
|                                {EchoTopsUnits::User, "?"}, |                                {EchoTopsUnits::User, ""}, | ||||||
|                                {EchoTopsUnits::Unknown, "?"}}; |                                {EchoTopsUnits::Unknown, ""}}; | ||||||
| 
 | 
 | ||||||
| static const std::unordered_map<EchoTopsUnits, std::string> echoTopsUnitsName_ { | static const std::unordered_map<EchoTopsUnits, std::string> echoTopsUnitsName_ { | ||||||
|    {EchoTopsUnits::Kilofeet, "Kilofeet"}, |    {EchoTopsUnits::Kilofeet, "Kilofeet"}, | ||||||
|  | @ -41,8 +42,8 @@ static const std::unordered_map<SpeedUnits, std::string> | ||||||
|                             {SpeedUnits::Knots, "kts"}, |                             {SpeedUnits::Knots, "kts"}, | ||||||
|                             {SpeedUnits::MilesPerHour, "mph"}, |                             {SpeedUnits::MilesPerHour, "mph"}, | ||||||
|                             {SpeedUnits::MetersPerSecond, "m/s"}, |                             {SpeedUnits::MetersPerSecond, "m/s"}, | ||||||
|                             {SpeedUnits::User, "?"}, |                             {SpeedUnits::User, ""}, | ||||||
|                             {SpeedUnits::Unknown, "?"}}; |                             {SpeedUnits::Unknown, ""}}; | ||||||
| 
 | 
 | ||||||
| static const std::unordered_map<SpeedUnits, std::string> speedUnitsName_ { | static const std::unordered_map<SpeedUnits, std::string> speedUnitsName_ { | ||||||
|    {SpeedUnits::KilometersPerHour, "Kilometers per hour"}, |    {SpeedUnits::KilometersPerHour, "Kilometers per hour"}, | ||||||
|  | @ -52,6 +53,18 @@ static const std::unordered_map<SpeedUnits, std::string> speedUnitsName_ { | ||||||
|    {SpeedUnits::User, "User-defined"}, |    {SpeedUnits::User, "User-defined"}, | ||||||
|    {SpeedUnits::Unknown, "?"}}; |    {SpeedUnits::Unknown, "?"}}; | ||||||
| 
 | 
 | ||||||
|  | static constexpr auto speedUnitsBase_ = units::meters_per_second<float> {1.0f}; | ||||||
|  | static const std::unordered_map<SpeedUnits, float> speedUnitsScale_ { | ||||||
|  |    {SpeedUnits::KilometersPerHour, | ||||||
|  |     (speedUnitsBase_ / units::kilometers_per_hour<float> {1.0f})}, | ||||||
|  |    {SpeedUnits::Knots, (speedUnitsBase_ / units::knots<float> {1.0f})}, | ||||||
|  |    {SpeedUnits::MilesPerHour, | ||||||
|  |     (speedUnitsBase_ / units::miles_per_hour<float> {1.0f})}, | ||||||
|  |    {SpeedUnits::MetersPerSecond, | ||||||
|  |     (speedUnitsBase_ / units::meters_per_second<float> {1.0f})}, | ||||||
|  |    {SpeedUnits::User, 1.0f}, | ||||||
|  |    {SpeedUnits::Unknown, 1.0f}}; | ||||||
|  | 
 | ||||||
| SCWX_GET_ENUM(AccumulationUnits, | SCWX_GET_ENUM(AccumulationUnits, | ||||||
|               GetAccumulationUnitsFromName, |               GetAccumulationUnitsFromName, | ||||||
|               accumulationUnitsName_) |               accumulationUnitsName_) | ||||||
|  | @ -88,6 +101,11 @@ const std::string& GetSpeedUnitsName(SpeedUnits units) | ||||||
|    return speedUnitsName_.at(units); |    return speedUnitsName_.at(units); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | float GetSpeedUnitsScale(SpeedUnits units) | ||||||
|  | { | ||||||
|  |    return speedUnitsScale_.at(units); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| } // namespace types
 | } // namespace types
 | ||||||
| } // namespace qt
 | } // namespace qt
 | ||||||
| } // namespace scwx
 | } // namespace scwx
 | ||||||
|  |  | ||||||
|  | @ -58,6 +58,7 @@ EchoTopsUnits      GetEchoTopsUnitsFromName(const std::string& name); | ||||||
| const std::string& GetSpeedUnitsAbbreviation(SpeedUnits units); | const std::string& GetSpeedUnitsAbbreviation(SpeedUnits units); | ||||||
| const std::string& GetSpeedUnitsName(SpeedUnits units); | const std::string& GetSpeedUnitsName(SpeedUnits units); | ||||||
| SpeedUnits         GetSpeedUnitsFromName(const std::string& name); | SpeedUnits         GetSpeedUnitsFromName(const std::string& name); | ||||||
|  | float              GetSpeedUnitsScale(SpeedUnits units); | ||||||
| 
 | 
 | ||||||
| } // namespace types
 | } // namespace types
 | ||||||
| } // namespace qt
 | } // namespace qt
 | ||||||
|  |  | ||||||
|  | @ -1,4 +1,6 @@ | ||||||
| #include <scwx/qt/view/level2_product_view.hpp> | #include <scwx/qt/view/level2_product_view.hpp> | ||||||
|  | #include <scwx/qt/settings/unit_settings.hpp> | ||||||
|  | #include <scwx/qt/types/unit_types.hpp> | ||||||
| #include <scwx/qt/util/geographic_lib.hpp> | #include <scwx/qt/util/geographic_lib.hpp> | ||||||
| #include <scwx/common/constants.hpp> | #include <scwx/common/constants.hpp> | ||||||
| #include <scwx/util/logger.hpp> | #include <scwx/util/logger.hpp> | ||||||
|  | @ -68,17 +70,33 @@ public: | ||||||
|        savedScale_ {0.0f}, |        savedScale_ {0.0f}, | ||||||
|        savedOffset_ {0.0f} |        savedOffset_ {0.0f} | ||||||
|    { |    { | ||||||
|  |       auto& unitSettings = settings::UnitSettings::Instance(); | ||||||
|  | 
 | ||||||
|       coordinates_.resize(kMaxCoordinates_); |       coordinates_.resize(kMaxCoordinates_); | ||||||
| 
 | 
 | ||||||
|       SetProduct(product); |       SetProduct(product); | ||||||
|  | 
 | ||||||
|  |       speedUnitsCallbackUuid_ = | ||||||
|  |          unitSettings.speed_units().RegisterValueChangedCallback( | ||||||
|  |             [this](const std::string& value) { UpdateSpeedUnits(value); }); | ||||||
|  | 
 | ||||||
|  |       UpdateSpeedUnits(unitSettings.speed_units().GetValue()); | ||||||
|    } |    } | ||||||
|    ~Level2ProductViewImpl() { threadPool_.join(); }; |    ~Level2ProductViewImpl() | ||||||
|  |    { | ||||||
|  |       auto& unitSettings = settings::UnitSettings::Instance(); | ||||||
|  |       unitSettings.speed_units().UnregisterValueChangedCallback( | ||||||
|  |          speedUnitsCallbackUuid_); | ||||||
|  | 
 | ||||||
|  |       threadPool_.join(); | ||||||
|  |    }; | ||||||
| 
 | 
 | ||||||
|    void |    void | ||||||
|    ComputeCoordinates(std::shared_ptr<wsr88d::rda::ElevationScan> radarData); |    ComputeCoordinates(std::shared_ptr<wsr88d::rda::ElevationScan> radarData); | ||||||
| 
 | 
 | ||||||
|    void SetProduct(const std::string& productName); |    void SetProduct(const std::string& productName); | ||||||
|    void SetProduct(common::Level2Product product); |    void SetProduct(common::Level2Product product); | ||||||
|  |    void UpdateSpeedUnits(const std::string& name); | ||||||
| 
 | 
 | ||||||
|    Level2ProductView* self_; |    Level2ProductView* self_; | ||||||
| 
 | 
 | ||||||
|  | @ -116,6 +134,9 @@ public: | ||||||
|    std::shared_ptr<common::ColorTable> savedColorTable_; |    std::shared_ptr<common::ColorTable> savedColorTable_; | ||||||
|    float                               savedScale_; |    float                               savedScale_; | ||||||
|    float                               savedOffset_; |    float                               savedOffset_; | ||||||
|  | 
 | ||||||
|  |    boost::uuids::uuid speedUnitsCallbackUuid_ {}; | ||||||
|  |    types::SpeedUnits  speedUnits_ {types::SpeedUnits::Unknown}; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| Level2ProductView::Level2ProductView( | Level2ProductView::Level2ProductView( | ||||||
|  | @ -221,6 +242,36 @@ std::chrono::system_clock::time_point Level2ProductView::sweep_time() const | ||||||
|    return p->sweepTime_; |    return p->sweepTime_; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | float Level2ProductView::unit_scale() const | ||||||
|  | { | ||||||
|  |    switch (p->dataBlockType_) | ||||||
|  |    { | ||||||
|  |    case wsr88d::rda::DataBlockType::MomentVel: | ||||||
|  |    case wsr88d::rda::DataBlockType::MomentSw: | ||||||
|  |       return types::GetSpeedUnitsScale(p->speedUnits_); | ||||||
|  | 
 | ||||||
|  |    default: | ||||||
|  |       break; | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    return 1.0f; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | std::string Level2ProductView::units() const | ||||||
|  | { | ||||||
|  |    switch (p->dataBlockType_) | ||||||
|  |    { | ||||||
|  |    case wsr88d::rda::DataBlockType::MomentVel: | ||||||
|  |    case wsr88d::rda::DataBlockType::MomentSw: | ||||||
|  |       return types::GetSpeedUnitsAbbreviation(p->speedUnits_); | ||||||
|  | 
 | ||||||
|  |    default: | ||||||
|  |       break; | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    return {}; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| uint16_t Level2ProductView::vcp() const | uint16_t Level2ProductView::vcp() const | ||||||
| { | { | ||||||
|    return p->vcp_; |    return p->vcp_; | ||||||
|  | @ -323,6 +374,11 @@ void Level2ProductViewImpl::SetProduct(common::Level2Product product) | ||||||
|    } |    } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void Level2ProductViewImpl::UpdateSpeedUnits(const std::string& name) | ||||||
|  | { | ||||||
|  |    speedUnits_ = types::GetSpeedUnitsFromName(name); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void Level2ProductView::UpdateColorTableLut() | void Level2ProductView::UpdateColorTableLut() | ||||||
| { | { | ||||||
|    if (p->momentDataBlock0_ == nullptr || //
 |    if (p->momentDataBlock0_ == nullptr || //
 | ||||||
|  |  | ||||||
|  | @ -35,6 +35,8 @@ public: | ||||||
|    float                                 elevation() const override; |    float                                 elevation() const override; | ||||||
|    float                                 range() const override; |    float                                 range() const override; | ||||||
|    std::chrono::system_clock::time_point sweep_time() const override; |    std::chrono::system_clock::time_point sweep_time() const override; | ||||||
|  |    float                                 unit_scale() const override; | ||||||
|  |    std::string                           units() const override; | ||||||
|    std::uint16_t                         vcp() const override; |    std::uint16_t                         vcp() const override; | ||||||
|    const std::vector<float>&             vertices() const override; |    const std::vector<float>&             vertices() const override; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -143,6 +143,16 @@ uint16_t Level3ProductView::color_table_max() const | ||||||
|    } |    } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | float Level3ProductView::unit_scale() const | ||||||
|  | { | ||||||
|  |    return 1.0f; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | std::string Level3ProductView::units() const | ||||||
|  | { | ||||||
|  |    return {}; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| std::shared_ptr<wsr88d::rpg::GraphicProductMessage> | std::shared_ptr<wsr88d::rpg::GraphicProductMessage> | ||||||
| Level3ProductView::graphic_product_message() const | Level3ProductView::graphic_product_message() const | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -30,6 +30,8 @@ public: | ||||||
|                  color_table_lut() const override; |                  color_table_lut() const override; | ||||||
|    std::uint16_t color_table_min() const override; |    std::uint16_t color_table_min() const override; | ||||||
|    std::uint16_t color_table_max() const override; |    std::uint16_t color_table_max() const override; | ||||||
|  |    float         unit_scale() const override; | ||||||
|  |    std::string   units() const override; | ||||||
| 
 | 
 | ||||||
|    void LoadColorTable(std::shared_ptr<common::ColorTable> colorTable) override; |    void LoadColorTable(std::shared_ptr<common::ColorTable> colorTable) override; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -42,6 +42,8 @@ public: | ||||||
|    virtual float                                 elevation() const; |    virtual float                                 elevation() const; | ||||||
|    virtual float                                 range() const; |    virtual float                                 range() const; | ||||||
|    virtual std::chrono::system_clock::time_point sweep_time() const; |    virtual std::chrono::system_clock::time_point sweep_time() const; | ||||||
|  |    virtual float                                 unit_scale() const = 0; | ||||||
|  |    virtual std::string                           units() const      = 0; | ||||||
|    virtual std::uint16_t                         vcp() const        = 0; |    virtual std::uint16_t                         vcp() const        = 0; | ||||||
|    virtual const std::vector<float>&             vertices() const   = 0; |    virtual const std::vector<float>&             vertices() const   = 0; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat