From 7c606b85ffeccd6ee5a83befe28f0047760c0e65 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Thu, 4 Nov 2021 22:25:06 -0500 Subject: [PATCH] Add toolbox for radar display control --- scwx-qt/source/scwx/qt/main/main_window.cpp | 49 +++++++++ scwx-qt/source/scwx/qt/main/main_window.hpp | 2 + scwx-qt/source/scwx/qt/main/main_window.ui | 113 +++++++++++++++++++- scwx-qt/ts/scwx_en_US.ts | 30 ++++++ wxdata/include/scwx/common/products.hpp | 35 ++++++ wxdata/include/scwx/util/iterator.hpp | 35 ++++++ wxdata/source/scwx/common/products.cpp | 60 +++++++++++ wxdata/wxdata.cmake | 7 +- 8 files changed, 325 insertions(+), 6 deletions(-) create mode 100644 wxdata/include/scwx/common/products.hpp create mode 100644 wxdata/include/scwx/util/iterator.hpp create mode 100644 wxdata/source/scwx/common/products.cpp diff --git a/scwx-qt/source/scwx/qt/main/main_window.cpp b/scwx-qt/source/scwx/qt/main/main_window.cpp index 8e006269..b2e04284 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.cpp +++ b/scwx-qt/source/scwx/qt/main/main_window.cpp @@ -2,6 +2,12 @@ #include "./ui_main_window.h" #include +#include +#include + +#include + +#include namespace scwx { @@ -10,6 +16,8 @@ namespace qt namespace main { +static const std::string logPrefix_ = "[scwx::qt::main::main_window] "; + MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow) { @@ -20,6 +28,20 @@ MainWindow::MainWindow(QWidget* parent) : settings.setCacheDatabaseMaximumSize(20 * 1024 * 1024); ui->centralwidget->layout()->addWidget(new map::MapWidget(settings)); + + // Add Level2 Products + QLayout* level2Layout = new ui::FlowLayout(); + ui->level2Products->setLayout(level2Layout); + + for (common::Level2Product product : common::Level2ProductIterator()) + { + QToolButton* toolButton = new QToolButton(); + toolButton->setText( + QString::fromStdString(common::GetLevel2Name(product))); + toolButton->setStatusTip( + tr(common::GetLevel2Description(product).c_str())); + level2Layout->addWidget(toolButton); + } } MainWindow::~MainWindow() @@ -27,6 +49,33 @@ MainWindow::~MainWindow() delete ui; } +void MainWindow::showEvent(QShowEvent* event) +{ + QMainWindow::showEvent(event); + + // Cycle through each item in the toolbox to render + QToolBox* toolbox = ui->radarToolbox; + int currentIndex = toolbox->currentIndex(); + for (int i = 0; i < toolbox->count(); i++) + { + toolbox->setCurrentIndex(i); + } + toolbox->setCurrentIndex(currentIndex); + + // Set each level 2 product's tool button to the same size + int level2MaxWidth = 0; + for (QWidget* widget : ui->level2Products->findChildren()) + { + level2MaxWidth = std::max(level2MaxWidth, widget->width()); + } + for (QWidget* widget : ui->level2Products->findChildren()) + { + widget->setMinimumWidth(level2MaxWidth); + } + + resizeDocks({ui->radarToolboxDock}, {150}, Qt::Horizontal); +} + } // namespace main } // namespace qt } // namespace scwx diff --git a/scwx-qt/source/scwx/qt/main/main_window.hpp b/scwx-qt/source/scwx/qt/main/main_window.hpp index a31020ed..8073b51e 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.hpp +++ b/scwx-qt/source/scwx/qt/main/main_window.hpp @@ -24,6 +24,8 @@ public: MainWindow(QWidget* parent = nullptr); ~MainWindow(); + void showEvent(QShowEvent* event) override; + private: Ui::MainWindow* ui; }; diff --git a/scwx-qt/source/scwx/qt/main/main_window.ui b/scwx-qt/source/scwx/qt/main/main_window.ui index c52bfa20..2a34fcf9 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.ui +++ b/scwx-qt/source/scwx/qt/main/main_window.ui @@ -6,15 +6,15 @@ 0 0 - 800 - 600 + 1024 + 768 MainWindow - + 0 @@ -34,12 +34,117 @@ 0 0 - 800 + 1024 21 + + + Toolbox + + + 1 + + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + + Radar Sites + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Radar Products + + + + + + Level 2 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Product Settings + + + + + + Elevation + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + diff --git a/scwx-qt/ts/scwx_en_US.ts b/scwx-qt/ts/scwx_en_US.ts index c9c86b53..0a994763 100644 --- a/scwx-qt/ts/scwx_en_US.ts +++ b/scwx-qt/ts/scwx_en_US.ts @@ -8,5 +8,35 @@ MainWindow + + + Toolbox + + + + + Radar Sites + + + + + Radar Products + + + + + Level 2 + + + + + Product Settings + + + + + Elevation + + diff --git a/wxdata/include/scwx/common/products.hpp b/wxdata/include/scwx/common/products.hpp new file mode 100644 index 00000000..10b94dea --- /dev/null +++ b/wxdata/include/scwx/common/products.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include + +#include + +namespace scwx +{ +namespace common +{ + +const std::string LEVEL2_GROUP_ID = "L2"; + +enum class Level2Product +{ + Reflectivity, + Velocity, + SpectrumWidth, + DifferentialReflectivity, + DifferentialPhase, + CorrelationCoefficient, + ClutterFilterPowerRemoved, + Unknown +}; +typedef util::Iterator + Level2ProductIterator; + +const std::string& GetLevel2Name(Level2Product product); +const std::string& GetLevel2Description(Level2Product product); +const Level2Product GetLevel2Product(const std::string& id); + +} // namespace common +} // namespace scwx diff --git a/wxdata/include/scwx/util/iterator.hpp b/wxdata/include/scwx/util/iterator.hpp new file mode 100644 index 00000000..9750a58a --- /dev/null +++ b/wxdata/include/scwx/util/iterator.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include + +namespace scwx +{ +namespace util +{ + +template +class Iterator +{ + typedef typename std::underlying_type::type value_t; + int value_; + +public: + Iterator(const T& v) : value_(static_cast(v)) {} + Iterator() : value_(static_cast(beginValue)) {} + Iterator operator++() + { + ++value_; + return *this; + } + T operator*() { return static_cast(value_); } + Iterator begin() { return *this; } // Default constructor + Iterator end() + { + static const Iterator endIterator = ++Iterator(endValue); + return endIterator; + } + bool operator!=(const Iterator& i) { return value_ != i.value_; } +}; + +} // namespace util +} // namespace scwx diff --git a/wxdata/source/scwx/common/products.cpp b/wxdata/source/scwx/common/products.cpp new file mode 100644 index 00000000..94cb9318 --- /dev/null +++ b/wxdata/source/scwx/common/products.cpp @@ -0,0 +1,60 @@ +#include + +#include + +namespace scwx +{ +namespace common +{ + +static const std::unordered_map level2Name_ { + {Level2Product::Reflectivity, "REF"}, + {Level2Product::Velocity, "VEL"}, + {Level2Product::SpectrumWidth, "SW"}, + {Level2Product::DifferentialReflectivity, "ZDR"}, + {Level2Product::DifferentialPhase, "PHI"}, + {Level2Product::CorrelationCoefficient, "RHO"}, + {Level2Product::ClutterFilterPowerRemoved, "CFP"}, + {Level2Product::Unknown, "?"}}; + +static const std::unordered_map level2Description_ { + {Level2Product::Reflectivity, "Reflectivity"}, + {Level2Product::Velocity, "Velocity"}, + {Level2Product::SpectrumWidth, "Spectrum Width"}, + {Level2Product::DifferentialReflectivity, "Differential Reflectivity"}, + {Level2Product::DifferentialPhase, "Differential Phase"}, + {Level2Product::CorrelationCoefficient, "Correlation Coefficient"}, + {Level2Product::ClutterFilterPowerRemoved, "Clutter Filter Power Removed"}, + {Level2Product::Unknown, "?"}}; + +const std::string& GetLevel2Name(Level2Product product) +{ + return level2Name_.at(product); +} + +const std::string& GetLevel2Description(Level2Product product) +{ + return level2Description_.at(product); +} + +const Level2Product GetLevel2Product(const std::string& name) +{ + auto result = std::find_if( + level2Name_.cbegin(), + level2Name_.cend(), + [&](const std::pair& pair) -> bool { + return pair.second == name; + }); + + if (result != level2Name_.cend()) + { + return result->first; + } + else + { + return Level2Product::Unknown; + } +} + +} // namespace common +} // namespace scwx diff --git a/wxdata/wxdata.cmake b/wxdata/wxdata.cmake index 70f8e762..bfeff763 100644 --- a/wxdata/wxdata.cmake +++ b/wxdata/wxdata.cmake @@ -4,9 +4,12 @@ find_package(Boost) set(HDR_COMMON include/scwx/common/color_table.hpp include/scwx/common/constants.hpp + include/scwx/common/products.hpp include/scwx/common/types.hpp) -set(SRC_COMMON source/scwx/common/color_table.cpp) -set(HDR_UTIL include/scwx/util/rangebuf.hpp +set(SRC_COMMON source/scwx/common/color_table.cpp + source/scwx/common/products.cpp) +set(HDR_UTIL include/scwx/util/iterator.hpp + include/scwx/util/rangebuf.hpp include/scwx/util/vectorbuf.hpp) set(SRC_UTIL source/scwx/util/rangebuf.cpp source/scwx/util/vectorbuf.cpp)