Skip to content

Commit

Permalink
Merge pull request #120 from dpaulat/feature/map-cursor-info
Browse files Browse the repository at this point in the history
Add Map Cursor Info
  • Loading branch information
dpaulat authored Jan 7, 2024
2 parents 9df9c09 + f54f6d1 commit 03f4b48
Show file tree
Hide file tree
Showing 42 changed files with 1,406 additions and 230 deletions.
3 changes: 2 additions & 1 deletion scwx-qt/source/scwx/qt/gl/draw/draw_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ bool DrawItem::RunMousePicking(
const QMapLibreGL::CustomLayerRenderParameters& /* params */,
const QPointF& /* mouseLocalPos */,
const QPointF& /* mouseGlobalPos */,
const glm::vec2& /* mouseCoords */)
const glm::vec2& /* mouseCoords */,
const common::Coordinate& /* mouseGeoCoords */)
{
// By default, the draw item is not picked
return false;
Expand Down
9 changes: 6 additions & 3 deletions scwx-qt/source/scwx/qt/gl/draw/draw_item.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <scwx/qt/gl/gl.hpp>
#include <scwx/common/geographic.hpp>

#include <memory>

Expand Down Expand Up @@ -41,14 +42,16 @@ class DrawItem
* @param [in] mouseLocalPos Mouse cursor widget position
* @param [in] mouseGlobalPos Mouse cursor screen position
* @param [in] mouseCoords Mouse cursor location in map screen coordinates
* @param [in] mouseGeoCoords Mouse cursor location in geographic coordinates
*
* @return true if the draw item was picked, otherwise false
*/
virtual bool
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
const QPointF& mouseLocalPos,
const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords);
const QPointF& mouseLocalPos,
const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords,
const common::Coordinate& mouseGeoCoords);

protected:
void
Expand Down
3 changes: 2 additions & 1 deletion scwx-qt/source/scwx/qt/gl/draw/geo_icons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,8 @@ bool GeoIcons::RunMousePicking(
const QMapLibreGL::CustomLayerRenderParameters& params,
const QPointF& /* mouseLocalPos */,
const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords)
const glm::vec2& mouseCoords,
const common::Coordinate& /* mouseGeoCoords */)
{
std::unique_lock lock {p->iconMutex_};

Expand Down
7 changes: 4 additions & 3 deletions scwx-qt/source/scwx/qt/gl/draw/geo_icons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ class GeoIcons : public DrawItem
void Deinitialize() override;

bool RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
const QPointF& mouseLocalPos,
const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords) override;
const QPointF& mouseLocalPos,
const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords,
const common::Coordinate& mouseGeoCoords) override;

/**
* Sets the visibility of the geo icons.
Expand Down
3 changes: 2 additions & 1 deletion scwx-qt/source/scwx/qt/gl/draw/placefile_icons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,8 @@ bool PlacefileIcons::RunMousePicking(
const QMapLibreGL::CustomLayerRenderParameters& params,
const QPointF& /* mouseLocalPos */,
const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords)
const glm::vec2& mouseCoords,
const common::Coordinate& /* mouseGeoCoords */)
{
std::unique_lock lock {p->iconMutex_};

Expand Down
7 changes: 4 additions & 3 deletions scwx-qt/source/scwx/qt/gl/draw/placefile_icons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ class PlacefileIcons : public DrawItem
void Deinitialize() override;

bool RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
const QPointF& mouseLocalPos,
const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords) override;
const QPointF& mouseLocalPos,
const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords,
const common::Coordinate& mouseGeoCoords) override;

/**
* Resets and prepares the draw item for adding a new set of icons.
Expand Down
3 changes: 2 additions & 1 deletion scwx-qt/source/scwx/qt/gl/draw/placefile_lines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@ bool PlacefileLines::RunMousePicking(
const QMapLibreGL::CustomLayerRenderParameters& params,
const QPointF& /* mouseLocalPos */,
const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords)
const glm::vec2& mouseCoords,
const common::Coordinate& /* mouseGeoCoords */)
{
std::unique_lock lock {p->lineMutex_};

Expand Down
7 changes: 4 additions & 3 deletions scwx-qt/source/scwx/qt/gl/draw/placefile_lines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ class PlacefileLines : public DrawItem
void Deinitialize() override;

bool RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
const QPointF& mouseLocalPos,
const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords) override;
const QPointF& mouseLocalPos,
const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords,
const common::Coordinate& mouseGeoCoords) override;

/**
* Resets and prepares the draw item for adding a new set of lines.
Expand Down
3 changes: 2 additions & 1 deletion scwx-qt/source/scwx/qt/gl/draw/placefile_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ bool PlacefileText::RunMousePicking(
const QMapLibreGL::CustomLayerRenderParameters& /* params */,
const QPointF& /* mouseLocalPos */,
const QPointF& mouseGlobalPos,
const glm::vec2& /* mouseCoords */)
const glm::vec2& /* mouseCoords */,
const common::Coordinate& /* mouseGeoCoords */)
{
bool itemPicked = false;

Expand Down
7 changes: 4 additions & 3 deletions scwx-qt/source/scwx/qt/gl/draw/placefile_text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ class PlacefileText : public DrawItem
void Deinitialize() override;

bool RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
const QPointF& mouseLocalPos,
const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords) override;
const QPointF& mouseLocalPos,
const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords,
const common::Coordinate& mouseGeoCoords) override;

/**
* Resets and prepares the draw item for adding a new set of text.
Expand Down
58 changes: 57 additions & 1 deletion scwx-qt/source/scwx/qt/main/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <scwx/common/products.hpp>
#include <scwx/common/vcp.hpp>
#include <scwx/util/logger.hpp>
#include <scwx/util/time.hpp>

#include <boost/asio/post.hpp>
#include <boost/asio/thread_pool.hpp>
Expand All @@ -42,6 +43,7 @@
#include <QMessageBox>
#include <QSplitter>
#include <QStandardPaths>
#include <QTimer>
#include <QToolButton>

#if !defined(_MSC_VER)
Expand Down Expand Up @@ -125,7 +127,11 @@ class MainWindowImpl : public QObject
positionManager_->TrackLocation(true);
}
}
~MainWindowImpl() { threadPool_.join(); }
~MainWindowImpl()
{
clockTimer_.stop();
threadPool_.join();
}

void AddRadarSitePreset(const std::string& id);
void AsyncSetup();
Expand Down Expand Up @@ -169,6 +175,9 @@ class MainWindowImpl : public QObject

ui::Level3ProductsWidget* level3ProductsWidget_;

QLabel* coordinateLabel_ {nullptr};
QLabel* timeLabel_ {nullptr};

ui::AlertDockWidget* alertDockWidget_;
ui::AnimationDockWidget* animationDockWidget_;
ui::AboutDialog* aboutDialog_;
Expand All @@ -179,6 +188,8 @@ class MainWindowImpl : public QObject
ui::SettingsDialog* settingsDialog_;
ui::UpdateDialog* updateDialog_;

QTimer clockTimer_ {};

std::shared_ptr<manager::AlertManager> alertManager_;
std::shared_ptr<manager::PlacefileManager> placefileManager_;
std::shared_ptr<manager::PositionManager> positionManager_;
Expand Down Expand Up @@ -317,6 +328,25 @@ MainWindow::MainWindow(QWidget* parent) :
ui->radarToolboxScrollAreaContents->layout()->addItem(
ui->radarToolboxSpacer);

// Status Bar
QWidget* statusBarWidget = new QWidget(this);

p->coordinateLabel_ = new QLabel(this);
p->coordinateLabel_->setFrameShape(QFrame::Shape::Box);
p->coordinateLabel_->setFrameShadow(QFrame::Shadow::Sunken);
p->coordinateLabel_->setVisible(false);

p->timeLabel_ = new QLabel(this);
p->timeLabel_->setFrameShape(QFrame::Shape::Box);
p->timeLabel_->setFrameShadow(QFrame::Shadow::Sunken);
p->timeLabel_->setVisible(false);

QGridLayout* statusBarLayout = new QGridLayout(statusBarWidget);
statusBarLayout->setContentsMargins(0, 0, 0, 0);
statusBarLayout->addWidget(p->coordinateLabel_, 0, 0);
statusBarLayout->addWidget(p->timeLabel_, 0, 1);
ui->statusbar->addPermanentWidget(statusBarWidget);

// ImGui Debug Dialog
p->imGuiDebugDialog_ = new ui::ImGuiDebugDialog(this);

Expand Down Expand Up @@ -715,6 +745,21 @@ void MainWindowImpl::ConnectMapSignals()
}
});

connect(mapWidget,
&map::MapWidget::MouseCoordinateChanged,
this,
[this](common::Coordinate coordinate)
{
const QString latitude = QString::fromStdString(
common::GetLatitudeString(coordinate.latitude_));
const QString longitude = QString::fromStdString(
common::GetLongitudeString(coordinate.longitude_));

coordinateLabel_->setText(
QString("%1, %2").arg(latitude).arg(longitude));
coordinateLabel_->setVisible(true);
});

connect(
mapWidget,
&map::MapWidget::RadarSweepUpdated,
Expand Down Expand Up @@ -986,6 +1031,17 @@ void MainWindowImpl::ConnectOtherSignals()
updateDialog_->UpdateReleaseInfo(latestVersion, latestRelease);
updateDialog_->show();
});

connect(&clockTimer_,
&QTimer::timeout,
this,
[this]()
{
timeLabel_->setText(QString("%1 UTC").arg(QString::fromStdString(
util::TimeString(std::chrono::system_clock::now()))));
timeLabel_->setVisible(true);
});
clockTimer_.start(1000);
}

void MainWindowImpl::AddRadarSitePreset(const std::string& siteId)
Expand Down
4 changes: 2 additions & 2 deletions scwx-qt/source/scwx/qt/manager/radar_product_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ void RadarProductManager::Initialize()
const uint16_t radial =
static_cast<uint16_t>(radialGate / common::MAX_DATA_MOMENT_GATES);

const float angle = radial * 0.5f - 0.25f; // 0.5 degree radial
const float angle = radial * 0.5f; // 0.5 degree radial
const float range = (gate + 1) * gateSize;
const size_t offset = radialGate * 2;

Expand Down Expand Up @@ -477,7 +477,7 @@ void RadarProductManager::Initialize()
const uint16_t radial =
static_cast<uint16_t>(radialGate / common::MAX_DATA_MOMENT_GATES);

const float angle = radial * 1.0f - 0.5f; // 1 degree radial
const float angle = radial * 1.0f; // 1 degree radial
const float range = (gate + 1) * gateSize;
const size_t offset = radialGate * 2;

Expand Down
4 changes: 2 additions & 2 deletions scwx-qt/source/scwx/qt/map/color_table_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void ColorTableLayer::Initialize()
gl.glEnableVertexAttribArray(1);

connect(context()->radar_product_view().get(),
&view::RadarProductView::ColorTableUpdated,
&view::RadarProductView::ColorTableLutUpdated,
this,
[this]() { p->colorTableNeedsUpdate_ = true; });
}
Expand Down Expand Up @@ -142,7 +142,7 @@ void ColorTableLayer::Render(

if (p->colorTableNeedsUpdate_)
{
p->colorTable_ = radarProductView->color_table();
p->colorTable_ = radarProductView->color_table_lut();

gl.glActiveTexture(GL_TEXTURE0);
gl.glBindTexture(GL_TEXTURE_1D, p->texture_);
Expand Down
10 changes: 7 additions & 3 deletions scwx-qt/source/scwx/qt/map/draw_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,20 @@ bool DrawLayer::RunMousePicking(
const QMapLibreGL::CustomLayerRenderParameters& params,
const QPointF& mouseLocalPos,
const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords)
const glm::vec2& mouseCoords,
const common::Coordinate& mouseGeoCoords)
{
bool itemPicked = false;

// For each draw item in the draw list in reverse
for (auto it = p->drawList_.rbegin(); it != p->drawList_.rend(); ++it)
{
// Run mouse picking on each draw item
if ((*it)->RunMousePicking(
params, mouseLocalPos, mouseGlobalPos, mouseCoords))
if ((*it)->RunMousePicking(params,
mouseLocalPos,
mouseGlobalPos,
mouseCoords,
mouseGeoCoords))
{
// If a draw item was picked, don't process additional items
itemPicked = true;
Expand Down
7 changes: 4 additions & 3 deletions scwx-qt/source/scwx/qt/map/draw_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ class DrawLayer : public GenericLayer

virtual bool
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
const QPointF& mouseLocalPos,
const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords) override;
const QPointF& mouseLocalPos,
const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords,
const common::Coordinate& mouseGeoCoords) override;

protected:
void AddDrawItem(const std::shared_ptr<gl::draw::DrawItem>& drawItem);
Expand Down
3 changes: 2 additions & 1 deletion scwx-qt/source/scwx/qt/map/generic_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ bool GenericLayer::RunMousePicking(
const QMapLibreGL::CustomLayerRenderParameters& /* params */,
const QPointF& /* mouseLocalPos */,
const QPointF& /* mouseGlobalPos */,
const glm::vec2& /* mousePos */)
const glm::vec2& /* mousePos */,
const common::Coordinate& /* mouseGeoCoords */)
{
// By default, the layer has nothing to pick
return false;
Expand Down
9 changes: 6 additions & 3 deletions scwx-qt/source/scwx/qt/map/generic_layer.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <scwx/qt/map/map_context.hpp>
#include <scwx/common/geographic.hpp>

#include <memory>

Expand Down Expand Up @@ -36,14 +37,16 @@ class GenericLayer : public QObject
* @param [in] mouseLocalPos Mouse cursor widget position
* @param [in] mouseGlobalPos Mouse cursor screen position
* @param [in] mouseCoords Mouse cursor location in map screen coordinates
* @param [in] mouseGeoCoords Mouse cursor location in geographic coordinates
*
* @return true if a draw item was picked, otherwise false
*/
virtual bool
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
const QPointF& mouseLocalPos,
const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords);
const QPointF& mouseLocalPos,
const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords,
const common::Coordinate& mouseGeoCoords);

signals:
void NeedsRendering();
Expand Down
Loading

0 comments on commit 03f4b48

Please sign in to comment.