diff --git a/scwx-qt/source/scwx/qt/map/alert_layer.cpp b/scwx-qt/source/scwx/qt/map/alert_layer.cpp index 18efbc81..93a6d2d1 100644 --- a/scwx-qt/source/scwx/qt/map/alert_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/alert_layer.cpp @@ -135,14 +135,14 @@ public: std::size_t lineWidth_ {}; }; - explicit Impl(AlertLayer* self, - std::shared_ptr context, - awips::Phenomenon phenomenon) : + explicit Impl(AlertLayer* self, + const std::shared_ptr& glContext, + awips::Phenomenon phenomenon) : self_ {self}, phenomenon_ {phenomenon}, ibw_ {awips::ibw::GetImpactBasedWarningInfo(phenomenon)}, - geoLines_ {{false, std::make_shared(context)}, - {true, std::make_shared(context)}} + geoLines_ {{false, std::make_shared(glContext)}, + {true, std::make_shared(glContext)}} { UpdateLineData(); ConnectSignals(); @@ -245,12 +245,12 @@ public: std::vector connections_ {}; }; -AlertLayer::AlertLayer(const std::shared_ptr& context, - awips::Phenomenon phenomenon) : +AlertLayer::AlertLayer(const std::shared_ptr& glContext, + awips::Phenomenon phenomenon) : DrawLayer( - context, + glContext, fmt::format("AlertLayer {}", awips::GetPhenomenonText(phenomenon))), - p(std::make_unique(this, context->gl_context(), phenomenon)) + p(std::make_unique(this, glContext, phenomenon)) { for (auto alertActive : {false, true}) { @@ -274,11 +274,11 @@ void AlertLayer::InitializeHandler() } } -void AlertLayer::Initialize() +void AlertLayer::Initialize(const std::shared_ptr& mapContext) { logger_->debug("Initialize: {}", awips::GetPhenomenonText(p->phenomenon_)); - DrawLayer::Initialize(); + DrawLayer::Initialize(mapContext); auto& alertLayerHandler = AlertLayerHandler::Instance(); @@ -296,16 +296,17 @@ void AlertLayer::Initialize() p->ConnectAlertHandlerSignals(); } -void AlertLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) +void AlertLayer::Render(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters& params) { - gl::OpenGLFunctions& gl = context()->gl_context()->gl(); + gl::OpenGLFunctions& gl = gl_context()->gl(); for (auto alertActive : {false, true}) { p->geoLines_.at(alertActive)->set_selected_time(p->selectedTime_); } - DrawLayer::Render(params); + DrawLayer::Render(mapContext, params); SCWX_GL_CHECK_ERROR(); } diff --git a/scwx-qt/source/scwx/qt/map/alert_layer.hpp b/scwx-qt/source/scwx/qt/map/alert_layer.hpp index e14b5d1a..0416ff04 100644 --- a/scwx-qt/source/scwx/qt/map/alert_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/alert_layer.hpp @@ -16,13 +16,14 @@ class AlertLayer : public DrawLayer Q_DISABLE_COPY_MOVE(AlertLayer) public: - explicit AlertLayer(const std::shared_ptr& context, - scwx::awips::Phenomenon phenomenon); + explicit AlertLayer(const std::shared_ptr& glContext, + scwx::awips::Phenomenon phenomenon); ~AlertLayer(); - void Initialize() override final; - void Render(const QMapLibre::CustomLayerRenderParameters&) override final; - void Deinitialize() override final; + void Initialize(const std::shared_ptr& mapContext) final; + void Render(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters&) final; + void Deinitialize() final; static void InitializeHandler(); diff --git a/scwx-qt/source/scwx/qt/map/color_table_layer.cpp b/scwx-qt/source/scwx/qt/map/color_table_layer.cpp index bed9ec23..f9046120 100644 --- a/scwx-qt/source/scwx/qt/map/color_table_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/color_table_layer.cpp @@ -20,44 +20,40 @@ namespace scwx::qt::map static const std::string logPrefix_ = "scwx::qt::map::color_table_layer"; static const auto logger_ = scwx::util::Logger::Create(logPrefix_); -class ColorTableLayerImpl +class ColorTableLayer::Impl { public: - explicit ColorTableLayerImpl() : - shaderProgram_(nullptr), - uMVPMatrixLocation_(GL_INVALID_INDEX), - vbo_ {GL_INVALID_INDEX}, - vao_ {GL_INVALID_INDEX}, - texture_ {GL_INVALID_INDEX}, - colorTable_ {}, - colorTableNeedsUpdate_ {true} - { - } - ~ColorTableLayerImpl() = default; + explicit Impl() = default; + ~Impl() = default; - std::shared_ptr shaderProgram_; + Impl(const Impl&) = delete; + Impl& operator=(const Impl&) = delete; + Impl(const Impl&&) = delete; + Impl& operator=(const Impl&&) = delete; - GLint uMVPMatrixLocation_; - std::array vbo_; - GLuint vao_; - GLuint texture_; + std::shared_ptr shaderProgram_ {nullptr}; - std::vector colorTable_; + GLint uMVPMatrixLocation_ {static_cast(GL_INVALID_INDEX)}; + std::array vbo_ {GL_INVALID_INDEX}; + GLuint vao_ {GL_INVALID_INDEX}; + GLuint texture_ {GL_INVALID_INDEX}; - bool colorTableNeedsUpdate_; + std::vector colorTable_ {}; + + bool colorTableNeedsUpdate_ {true}; }; -ColorTableLayer::ColorTableLayer(const std::shared_ptr& context) : - GenericLayer(context), p(std::make_unique()) +ColorTableLayer::ColorTableLayer(std::shared_ptr glContext) : + GenericLayer(std::move(glContext)), p(std::make_unique()) { } ColorTableLayer::~ColorTableLayer() = default; -void ColorTableLayer::Initialize() +void ColorTableLayer::Initialize(const std::shared_ptr& mapContext) { logger_->debug("Initialize()"); - auto glContext = context()->gl_context(); + auto glContext = gl_context(); gl::OpenGLFunctions& gl = glContext->gl(); @@ -107,20 +103,20 @@ void ColorTableLayer::Initialize() gl.glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, static_cast(0)); gl.glEnableVertexAttribArray(1); - connect(context()->radar_product_view().get(), + connect(mapContext->radar_product_view().get(), &view::RadarProductView::ColorTableLutUpdated, this, [this]() { p->colorTableNeedsUpdate_ = true; }); } void ColorTableLayer::Render( + const std::shared_ptr& mapContext, const QMapLibre::CustomLayerRenderParameters& params) { - gl::OpenGLFunctions& gl = context()->gl_context()->gl(); - auto radarProductView = context()->radar_product_view(); + gl::OpenGLFunctions& gl = gl_context()->gl(); + auto radarProductView = mapContext->radar_product_view(); - if (context()->radar_product_view() == nullptr || - !context()->radar_product_view()->IsInitialized()) + if (radarProductView == nullptr || !radarProductView->IsInitialized()) { // Defer rendering until view is initialized return; @@ -180,11 +176,11 @@ void ColorTableLayer::Render( gl.glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices); gl.glDrawArrays(GL_TRIANGLES, 0, 6); - context()->set_color_table_margins(QMargins {0, 0, 0, 10}); + mapContext->set_color_table_margins(QMargins {0, 0, 0, 10}); } else { - context()->set_color_table_margins(QMargins {}); + mapContext->set_color_table_margins(QMargins {}); } SCWX_GL_CHECK_ERROR(); @@ -194,7 +190,7 @@ void ColorTableLayer::Deinitialize() { logger_->debug("Deinitialize()"); - gl::OpenGLFunctions& gl = context()->gl_context()->gl(); + gl::OpenGLFunctions& gl = gl_context()->gl(); gl.glDeleteVertexArrays(1, &p->vao_); gl.glDeleteBuffers(2, p->vbo_.data()); @@ -204,8 +200,6 @@ void ColorTableLayer::Deinitialize() p->vao_ = GL_INVALID_INDEX; p->vbo_ = {GL_INVALID_INDEX}; p->texture_ = GL_INVALID_INDEX; - - context()->set_color_table_margins(QMargins {}); } } // namespace scwx::qt::map diff --git a/scwx-qt/source/scwx/qt/map/color_table_layer.hpp b/scwx-qt/source/scwx/qt/map/color_table_layer.hpp index ce72f358..17cb505c 100644 --- a/scwx-qt/source/scwx/qt/map/color_table_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/color_table_layer.hpp @@ -5,20 +5,22 @@ namespace scwx::qt::map { -class ColorTableLayerImpl; - class ColorTableLayer : public GenericLayer { + Q_DISABLE_COPY_MOVE(ColorTableLayer) + public: - explicit ColorTableLayer(const std::shared_ptr& context); + explicit ColorTableLayer(std::shared_ptr glContext); ~ColorTableLayer(); - void Initialize() override final; - void Render(const QMapLibre::CustomLayerRenderParameters&) override final; - void Deinitialize() override final; + void Initialize(const std::shared_ptr& mapContext) final; + void Render(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters&) final; + void Deinitialize() final; private: - std::unique_ptr p; + class Impl; + std::unique_ptr p; }; } // namespace scwx::qt::map diff --git a/scwx-qt/source/scwx/qt/map/draw_layer.cpp b/scwx-qt/source/scwx/qt/map/draw_layer.cpp index 8372829c..fbe9a087 100644 --- a/scwx-qt/source/scwx/qt/map/draw_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/draw_layer.cpp @@ -1,10 +1,11 @@ -#include #include #include #include #include #include +#include + #include #include #include @@ -17,12 +18,12 @@ namespace scwx::qt::map static const std::string logPrefix_ = "scwx::qt::map::draw_layer"; static const auto logger_ = scwx::util::Logger::Create(logPrefix_); -class DrawLayerImpl +class DrawLayer::Impl { public: - explicit DrawLayerImpl(std::shared_ptr context, - const std::string& imGuiContextName) : - context_ {std::move(context)}, drawList_ {} + explicit Impl(std::shared_ptr glContext, + const std::string& imGuiContextName) : + glContext_ {std::move(glContext)} { static size_t currentLayerId_ {0u}; imGuiContextName_ = @@ -35,7 +36,7 @@ public: // Initialize ImGui Qt backend ImGui_ImplQt_Init(); } - ~DrawLayerImpl() + ~Impl() { // Set ImGui Context ImGui::SetCurrentContext(imGuiContext_); @@ -51,13 +52,14 @@ public: model::ImGuiContextModel::Instance().DestroyContext(imGuiContextName_); } - DrawLayerImpl(const DrawLayerImpl&) = delete; - DrawLayerImpl& operator=(const DrawLayerImpl&) = delete; - DrawLayerImpl(const DrawLayerImpl&&) = delete; - DrawLayerImpl& operator=(const DrawLayerImpl&&) = delete; + Impl(const Impl&) = delete; + Impl& operator=(const Impl&) = delete; + Impl(const Impl&&) = delete; + Impl& operator=(const Impl&&) = delete; - std::shared_ptr context_; - std::vector> drawList_; + std::shared_ptr glContext_; + + std::vector> drawList_ {}; GLuint textureAtlas_ {GL_INVALID_INDEX}; std::uint64_t textureAtlasBuildCount_ {}; @@ -67,27 +69,27 @@ public: bool imGuiRendererInitialized_ {}; }; -DrawLayer::DrawLayer(const std::shared_ptr& context, - const std::string& imGuiContextName) : - GenericLayer(context), - p(std::make_unique(context, imGuiContextName)) +DrawLayer::DrawLayer(std::shared_ptr glContext, + const std::string& imGuiContextName) : + GenericLayer(glContext), + p(std::make_unique(std::move(glContext), imGuiContextName)) { } DrawLayer::~DrawLayer() = default; -void DrawLayer::Initialize() +void DrawLayer::Initialize(const std::shared_ptr& mapContext) { - p->textureAtlas_ = p->context_->gl_context()->GetTextureAtlas(); + p->textureAtlas_ = p->glContext_->GetTextureAtlas(); for (auto& item : p->drawList_) { item->Initialize(); } - ImGuiInitialize(); + ImGuiInitialize(mapContext); } -void DrawLayer::ImGuiFrameStart() +void DrawLayer::ImGuiFrameStart(const std::shared_ptr& mapContext) { auto defaultFont = manager::FontManager::Instance().GetImGuiFont( types::FontCategory::Default); @@ -96,7 +98,7 @@ void DrawLayer::ImGuiFrameStart() ImGui::SetCurrentContext(p->imGuiContext_); // Start ImGui Frame - ImGui_ImplQt_NewFrame(p->context_->widget()); + ImGui_ImplQt_NewFrame(mapContext->widget()); ImGui_ImplOpenGL3_NewFrame(); ImGui::NewFrame(); ImGui::PushFont(defaultFont->font()); @@ -112,10 +114,10 @@ void DrawLayer::ImGuiFrameEnd() ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } -void DrawLayer::ImGuiInitialize() +void DrawLayer::ImGuiInitialize(const std::shared_ptr& mapContext) { ImGui::SetCurrentContext(p->imGuiContext_); - ImGui_ImplQt_RegisterWidget(p->context_->widget()); + ImGui_ImplQt_RegisterWidget(mapContext->widget()); ImGui_ImplOpenGL3_Init(); p->imGuiRendererInitialized_ = true; } @@ -123,7 +125,7 @@ void DrawLayer::ImGuiInitialize() void DrawLayer::RenderWithoutImGui( const QMapLibre::CustomLayerRenderParameters& params) { - auto glContext = p->context_->gl_context(); + auto& glContext = p->glContext_; gl::OpenGLFunctions& gl = glContext->gl(); p->textureAtlas_ = glContext->GetTextureAtlas(); @@ -146,14 +148,16 @@ void DrawLayer::RenderWithoutImGui( p->textureAtlasBuildCount_ = newTextureAtlasBuildCount; } + void DrawLayer::ImGuiSelectContext() { ImGui::SetCurrentContext(p->imGuiContext_); } -void DrawLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) +void DrawLayer::Render(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters& params) { - ImGuiFrameStart(); + ImGuiFrameStart(mapContext); RenderWithoutImGui(params); ImGuiFrameEnd(); } @@ -169,6 +173,7 @@ void DrawLayer::Deinitialize() } bool DrawLayer::RunMousePicking( + const std::shared_ptr& /* mapContext */, const QMapLibre::CustomLayerRenderParameters& params, const QPointF& mouseLocalPos, const QPointF& mouseGlobalPos, diff --git a/scwx-qt/source/scwx/qt/map/draw_layer.hpp b/scwx-qt/source/scwx/qt/map/draw_layer.hpp index 93d8a54a..f0589eef 100644 --- a/scwx-qt/source/scwx/qt/map/draw_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/draw_layer.hpp @@ -6,21 +6,23 @@ namespace scwx::qt::map { -class DrawLayerImpl; - class DrawLayer : public GenericLayer { + Q_DISABLE_COPY_MOVE(DrawLayer) + public: - explicit DrawLayer(const std::shared_ptr& context, - const std::string& imGuiContextName); + explicit DrawLayer(std::shared_ptr glContext, + const std::string& imGuiContextName); virtual ~DrawLayer(); - virtual void Initialize() override; - virtual void Render(const QMapLibre::CustomLayerRenderParameters&) override; - virtual void Deinitialize() override; + void Initialize(const std::shared_ptr& mapContext) override; + void Render(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters&) override; + void Deinitialize() override; - virtual bool - RunMousePicking(const QMapLibre::CustomLayerRenderParameters& params, + bool + RunMousePicking(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters& params, const QPointF& mouseLocalPos, const QPointF& mouseGlobalPos, const glm::vec2& mouseCoords, @@ -29,15 +31,16 @@ public: protected: void AddDrawItem(const std::shared_ptr& drawItem); - void ImGuiFrameStart(); + void ImGuiFrameStart(const std::shared_ptr& mapContext); void ImGuiFrameEnd(); - void ImGuiInitialize(); + void ImGuiInitialize(const std::shared_ptr& mapContext); void RenderWithoutImGui(const QMapLibre::CustomLayerRenderParameters& params); void ImGuiSelectContext(); private: - std::unique_ptr p; + class Impl; + std::unique_ptr p; }; } // namespace scwx::qt::map diff --git a/scwx-qt/source/scwx/qt/map/generic_layer.cpp b/scwx-qt/source/scwx/qt/map/generic_layer.cpp index 45ebea00..ec88d1f1 100644 --- a/scwx-qt/source/scwx/qt/map/generic_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/generic_layer.cpp @@ -3,26 +3,32 @@ namespace scwx::qt::map { -class GenericLayerImpl +class GenericLayer::Impl { public: - explicit GenericLayerImpl(std::shared_ptr context) : - context_ {std::move(context)} + explicit Impl(std::shared_ptr glContext) : + glContext_ {std::move(glContext)} { } - ~GenericLayerImpl() {} + ~Impl() = default; - std::shared_ptr context_; + Impl(const Impl&) = delete; + Impl& operator=(const Impl&) = delete; + Impl(const Impl&&) = delete; + Impl& operator=(const Impl&&) = delete; + + std::shared_ptr glContext_; }; -GenericLayer::GenericLayer(const std::shared_ptr& context) : - p(std::make_unique(context)) +GenericLayer::GenericLayer(std::shared_ptr glContext) : + p(std::make_unique(std::move(glContext))) { } GenericLayer::~GenericLayer() = default; bool GenericLayer::RunMousePicking( + const std::shared_ptr& /* mapContext */, const QMapLibre::CustomLayerRenderParameters& /* params */, const QPointF& /* mouseLocalPos */, const QPointF& /* mouseGlobalPos */, @@ -34,9 +40,9 @@ bool GenericLayer::RunMousePicking( return false; } -std::shared_ptr GenericLayer::context() const +std::shared_ptr GenericLayer::gl_context() const { - return p->context_; + return p->glContext_; } } // namespace scwx::qt::map diff --git a/scwx-qt/source/scwx/qt/map/generic_layer.hpp b/scwx-qt/source/scwx/qt/map/generic_layer.hpp index c9abdecb..32c95ffc 100644 --- a/scwx-qt/source/scwx/qt/map/generic_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/generic_layer.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -13,23 +14,24 @@ namespace scwx::qt::map { -class GenericLayerImpl; - class GenericLayer : public QObject { Q_OBJECT + Q_DISABLE_COPY_MOVE(GenericLayer) public: - explicit GenericLayer(const std::shared_ptr& context); + explicit GenericLayer(std::shared_ptr glContext); virtual ~GenericLayer(); - virtual void Initialize() = 0; - virtual void Render(const QMapLibre::CustomLayerRenderParameters&) = 0; - virtual void Deinitialize() = 0; + virtual void Initialize(const std::shared_ptr& mapContext) = 0; + virtual void Render(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters&) = 0; + virtual void Deinitialize() = 0; /** * @brief Run mouse picking on the layer. * + * @param [in] mapContext Map context * @param [in] params Custom layer render parameters * @param [in] mouseLocalPos Mouse cursor widget position * @param [in] mouseGlobalPos Mouse cursor screen position @@ -40,7 +42,8 @@ public: * @return true if a draw item was picked, otherwise false */ virtual bool - RunMousePicking(const QMapLibre::CustomLayerRenderParameters& params, + RunMousePicking(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters& params, const QPointF& mouseLocalPos, const QPointF& mouseGlobalPos, const glm::vec2& mouseCoords, @@ -51,10 +54,11 @@ signals: void NeedsRendering(); protected: - std::shared_ptr context() const; + [[nodiscard]] std::shared_ptr gl_context() const; private: - std::unique_ptr p; + class Impl; + std::unique_ptr p; }; } // namespace scwx::qt::map diff --git a/scwx-qt/source/scwx/qt/map/layer_wrapper.cpp b/scwx-qt/source/scwx/qt/map/layer_wrapper.cpp index 8bb5e878..5a60f90b 100644 --- a/scwx-qt/source/scwx/qt/map/layer_wrapper.cpp +++ b/scwx-qt/source/scwx/qt/map/layer_wrapper.cpp @@ -3,21 +3,29 @@ namespace scwx::qt::map { -class LayerWrapperImpl +class LayerWrapper::Impl { public: - explicit LayerWrapperImpl(std::shared_ptr layer) : - layer_ {std::move(layer)} + explicit Impl(std::shared_ptr layer, + std::shared_ptr mapContext) : + layer_ {std::move(layer)}, mapContext_ {std::move(mapContext)} { } - ~LayerWrapperImpl() {} + ~Impl() = default; + + Impl(const Impl&) = delete; + Impl& operator=(const Impl&) = delete; + Impl(const Impl&&) = delete; + Impl& operator=(const Impl&&) = delete; std::shared_ptr layer_; + std::shared_ptr mapContext_; }; -LayerWrapper::LayerWrapper(const std::shared_ptr& layer) : - p(std::make_unique(layer)) +LayerWrapper::LayerWrapper(std::shared_ptr layer, + std::shared_ptr mapContext) : + p(std::make_unique(std::move(layer), std::move(mapContext))) { } LayerWrapper::~LayerWrapper() = default; @@ -30,7 +38,7 @@ void LayerWrapper::initialize() auto& layer = p->layer_; if (layer != nullptr) { - layer->Initialize(); + layer->Initialize(p->mapContext_); } } @@ -39,7 +47,7 @@ void LayerWrapper::render(const QMapLibre::CustomLayerRenderParameters& params) auto& layer = p->layer_; if (layer != nullptr) { - layer->Render(params); + layer->Render(p->mapContext_, params); } } diff --git a/scwx-qt/source/scwx/qt/map/layer_wrapper.hpp b/scwx-qt/source/scwx/qt/map/layer_wrapper.hpp index 6e4cc62e..ae133c29 100644 --- a/scwx-qt/source/scwx/qt/map/layer_wrapper.hpp +++ b/scwx-qt/source/scwx/qt/map/layer_wrapper.hpp @@ -1,16 +1,16 @@ #pragma once #include +#include namespace scwx::qt::map { -class LayerWrapperImpl; - class LayerWrapper : public QMapLibre::CustomLayerHostInterface { public: - explicit LayerWrapper(const std::shared_ptr& layer); + explicit LayerWrapper(std::shared_ptr layer, + std::shared_ptr mapContext); ~LayerWrapper(); LayerWrapper(const LayerWrapper&) = delete; @@ -19,12 +19,13 @@ public: LayerWrapper(LayerWrapper&&) noexcept; LayerWrapper& operator=(LayerWrapper&&) noexcept; - void initialize() override final; - void render(const QMapLibre::CustomLayerRenderParameters&) override final; - void deinitialize() override final; + void initialize() final; + void render(const QMapLibre::CustomLayerRenderParameters&) final; + void deinitialize() final; private: - std::unique_ptr p; + class Impl; + std::unique_ptr p; }; } // namespace scwx::qt::map diff --git a/scwx-qt/source/scwx/qt/map/map_context.cpp b/scwx-qt/source/scwx/qt/map/map_context.cpp index 48cf4afc..1d1b5c4d 100644 --- a/scwx-qt/source/scwx/qt/map/map_context.cpp +++ b/scwx-qt/source/scwx/qt/map/map_context.cpp @@ -16,9 +16,6 @@ public: ~Impl() {} - std::shared_ptr glContext_ { - std::make_shared()}; - std::weak_ptr map_ {}; MapSettings settings_ {}; float pixelRatio_ {1.0f}; @@ -50,11 +47,6 @@ MapContext::~MapContext() = default; MapContext::MapContext(MapContext&&) noexcept = default; MapContext& MapContext::operator=(MapContext&&) noexcept = default; -std::shared_ptr MapContext::gl_context() const -{ - return p->glContext_; -} - std::weak_ptr MapContext::map() const { return p->map_; diff --git a/scwx-qt/source/scwx/qt/map/map_context.hpp b/scwx-qt/source/scwx/qt/map/map_context.hpp index 9cf611a6..ba319b95 100644 --- a/scwx-qt/source/scwx/qt/map/map_context.hpp +++ b/scwx-qt/source/scwx/qt/map/map_context.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -35,8 +34,6 @@ public: MapContext(MapContext&&) noexcept; MapContext& operator=(MapContext&&) noexcept; - [[nodiscard]] std::shared_ptr gl_context() const; - [[nodiscard]] std::weak_ptr map() const; [[nodiscard]] std::string map_copyrights() const; [[nodiscard]] MapProvider map_provider() const; diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index dd839d73..2d408627 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -73,7 +73,6 @@ public: const QMapLibre::Settings& settings) : id_ {id}, uuid_ {boost::uuids::random_generator()()}, - context_ {std::make_shared()}, widget_ {widget}, settings_(settings), map_(), @@ -154,9 +153,9 @@ public: void AddLayer(types::LayerType type, types::LayerDescription description, const std::string& before = {}); - void AddLayer(const std::string& id, - std::shared_ptr layer, - const std::string& before = {}); + void AddLayer(const std::string& id, + const std::shared_ptr& layer, + const std::string& before = {}); void AddLayers(); void AddPlacefileLayer(const std::string& placefileName, const std::string& before); @@ -194,7 +193,9 @@ public: std::size_t id_; boost::uuids::uuid uuid_; - std::shared_ptr context_; + std::shared_ptr context_ {std::make_shared()}; + std::shared_ptr glContext_ { + std::make_shared()}; MapWidget* widget_; QMapLibre::Settings settings_; @@ -1239,7 +1240,7 @@ void MapWidgetImpl::AddLayer(types::LayerType type, // If there is a radar product view, create the radar product layer if (radarProductView != nullptr) { - radarProductLayer_ = std::make_shared(context_); + radarProductLayer_ = std::make_shared(glContext_); AddLayer(layerName, radarProductLayer_, before); } } @@ -1248,7 +1249,7 @@ void MapWidgetImpl::AddLayer(types::LayerType type, auto phenomenon = std::get(description); std::shared_ptr alertLayer = - std::make_shared(context_, phenomenon); + std::make_shared(glContext_, phenomenon); AddLayer(fmt::format("alert.{}", awips::GetPhenomenonCode(phenomenon)), alertLayer, before); @@ -1272,7 +1273,7 @@ void MapWidgetImpl::AddLayer(types::LayerType type, { // Create the map overlay layer case types::InformationLayer::MapOverlay: - overlayLayer_ = std::make_shared(context_); + overlayLayer_ = std::make_shared(glContext_); AddLayer(layerName, overlayLayer_, before); break; @@ -1280,14 +1281,14 @@ void MapWidgetImpl::AddLayer(types::LayerType type, case types::InformationLayer::ColorTable: if (radarProductView != nullptr) { - colorTableLayer_ = std::make_shared(context_); + colorTableLayer_ = std::make_shared(glContext_); AddLayer(layerName, colorTableLayer_, before); } break; // Create the radar site layer case types::InformationLayer::RadarSite: - radarSiteLayer_ = std::make_shared(context_); + radarSiteLayer_ = std::make_shared(glContext_); AddLayer(layerName, radarSiteLayer_, before); connect( radarSiteLayer_.get(), @@ -1303,7 +1304,7 @@ void MapWidgetImpl::AddLayer(types::LayerType type, // Create the location marker layer case types::InformationLayer::Markers: - markerLayer_ = std::make_shared(context_); + markerLayer_ = std::make_shared(glContext_); AddLayer(layerName, markerLayer_, before); break; @@ -1320,7 +1321,7 @@ void MapWidgetImpl::AddLayer(types::LayerType type, if (radarProductView != nullptr) { overlayProductLayer_ = - std::make_shared(context_); + std::make_shared(glContext_); AddLayer(layerName, overlayProductLayer_, before); } break; @@ -1350,7 +1351,7 @@ void MapWidgetImpl::AddPlacefileLayer(const std::string& placefileName, const std::string& before) { std::shared_ptr placefileLayer = - std::make_shared(context_, placefileName); + std::make_shared(glContext_, placefileName); placefileLayers_.push_back(placefileLayer); AddLayer(GetPlacefileLayerName(placefileName), placefileLayer, before); @@ -1367,13 +1368,13 @@ MapWidgetImpl::GetPlacefileLayerName(const std::string& placefileName) return types::GetLayerName(types::LayerType::Placefile, placefileName); } -void MapWidgetImpl::AddLayer(const std::string& id, - std::shared_ptr layer, - const std::string& before) +void MapWidgetImpl::AddLayer(const std::string& id, + const std::shared_ptr& layer, + const std::string& before) { // QMapLibre::addCustomLayer will take ownership of the std::unique_ptr std::unique_ptr pHost = - std::make_unique(layer); + std::make_unique(layer, context_); try { @@ -1542,7 +1543,7 @@ void MapWidget::initializeGL() makeCurrent(); - p->context_->gl_context()->Initialize(); + p->glContext_->Initialize(); // Lock ImGui font atlas prior to new ImGui frame std::shared_lock imguiFontAtlasLock { @@ -1596,7 +1597,7 @@ void MapWidget::paintGL() p->frameDraws_++; - p->context_->gl_context()->StartFrame(); + p->glContext_->StartFrame(); // Handle hotkey updates p->HandleHotkeyUpdates(); @@ -1705,7 +1706,8 @@ void MapWidgetImpl::RunMousePicking() for (auto it = genericLayers_.rbegin(); it != genericLayers_.rend(); ++it) { // Run mouse picking for each layer - if ((*it)->RunMousePicking(params, + if ((*it)->RunMousePicking(context_, + params, lastPos_, lastGlobalPos_, mouseScreenCoordinate, diff --git a/scwx-qt/source/scwx/qt/map/marker_layer.cpp b/scwx-qt/source/scwx/qt/map/marker_layer.cpp index a40e2835..69a22e91 100644 --- a/scwx-qt/source/scwx/qt/map/marker_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/marker_layer.cpp @@ -5,11 +5,11 @@ #include #include +#include + #include #include -#include - namespace scwx::qt::map { @@ -19,15 +19,21 @@ static const auto logger_ = scwx::util::Logger::Create(logPrefix_); class MarkerLayer::Impl { public: - explicit Impl(MarkerLayer* self, std::shared_ptr context) : + explicit Impl(MarkerLayer* self, + const std::shared_ptr& glContext) : self_ {self}, - geoIcons_ {std::make_shared(context)}, + geoIcons_ {std::make_shared(glContext)}, editMarkerDialog_ {std::make_shared()} { ConnectSignals(); } ~Impl() = default; + Impl(const Impl&) = delete; + Impl& operator=(const Impl&) = delete; + Impl(const Impl&&) = delete; + Impl& operator=(const Impl&&) = delete; + void ReloadMarkers(); void ConnectSignals(); @@ -124,19 +130,19 @@ void MarkerLayer::Impl::ReloadMarkers() Q_EMIT self_->NeedsRendering(); } -MarkerLayer::MarkerLayer(const std::shared_ptr& context) : - DrawLayer(context, "MarkerLayer"), - p(std::make_unique(this, context->gl_context())) +MarkerLayer::MarkerLayer(const std::shared_ptr& glContext) : + DrawLayer(glContext, "MarkerLayer"), + p(std::make_unique(this, glContext)) { AddDrawItem(p->geoIcons_); } MarkerLayer::~MarkerLayer() = default; -void MarkerLayer::Initialize() +void MarkerLayer::Initialize(const std::shared_ptr& mapContext) { logger_->debug("Initialize()"); - DrawLayer::Initialize(); + DrawLayer::Initialize(mapContext); p->set_icon_sheets(); p->ReloadMarkers(); @@ -156,11 +162,12 @@ void MarkerLayer::Impl::set_icon_sheets() geoIcons_->FinishIconSheets(); } -void MarkerLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) +void MarkerLayer::Render(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters& params) { - gl::OpenGLFunctions& gl = context()->gl_context()->gl(); + gl::OpenGLFunctions& gl = gl_context()->gl(); - DrawLayer::Render(params); + DrawLayer::Render(mapContext, params); SCWX_GL_CHECK_ERROR(); } diff --git a/scwx-qt/source/scwx/qt/map/marker_layer.hpp b/scwx-qt/source/scwx/qt/map/marker_layer.hpp index 94d49f78..a5f67d2b 100644 --- a/scwx-qt/source/scwx/qt/map/marker_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/marker_layer.hpp @@ -8,14 +8,16 @@ namespace scwx::qt::map class MarkerLayer : public DrawLayer { Q_OBJECT + Q_DISABLE_COPY_MOVE(MarkerLayer) public: - explicit MarkerLayer(const std::shared_ptr& context); + explicit MarkerLayer(const std::shared_ptr& context); ~MarkerLayer(); - void Initialize() override final; - void Render(const QMapLibre::CustomLayerRenderParameters&) override final; - void Deinitialize() override final; + void Initialize(const std::shared_ptr& mapContext) final; + void Render(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters&) final; + void Deinitialize() final; private: class Impl; diff --git a/scwx-qt/source/scwx/qt/map/overlay_layer.cpp b/scwx-qt/source/scwx/qt/map/overlay_layer.cpp index aaff42e9..b7853738 100644 --- a/scwx-qt/source/scwx/qt/map/overlay_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/overlay_layer.cpp @@ -32,16 +32,16 @@ namespace scwx::qt::map static const std::string logPrefix_ = "scwx::qt::map::overlay_layer"; static const auto logger_ = scwx::util::Logger::Create(logPrefix_); -class OverlayLayerImpl +class OverlayLayer::Impl { public: - explicit OverlayLayerImpl(OverlayLayer* self, - std::shared_ptr context) : + explicit Impl(OverlayLayer* self, + const std::shared_ptr& glContext) : self_ {self}, - activeBoxOuter_ {std::make_shared(context)}, - activeBoxInner_ {std::make_shared(context)}, - geoIcons_ {std::make_shared(context)}, - icons_ {std::make_shared(context)}, + activeBoxOuter_ {std::make_shared(glContext)}, + activeBoxInner_ {std::make_shared(glContext)}, + geoIcons_ {std::make_shared(glContext)}, + icons_ {std::make_shared(glContext)}, renderMutex_ {} { auto& generalSettings = settings::GeneralSettings::Instance(); @@ -71,7 +71,7 @@ public: [this](const bool&) { Q_EMIT self_->NeedsRendering(); }); } - ~OverlayLayerImpl() + ~Impl() { auto& generalSettings = settings::GeneralSettings::Instance(); @@ -87,6 +87,11 @@ public: showMapLogoCallbackUuid_); } + Impl(const Impl&) = delete; + Impl& operator=(const Impl&) = delete; + Impl(const Impl&&) = delete; + Impl& operator=(const Impl&&) = delete; + void SetupGeoIcons(); void SetCusorLocation(common::Coordinate coordinate); @@ -151,9 +156,9 @@ public: bool sweepTimePicked_ {false}; }; -OverlayLayer::OverlayLayer(const std::shared_ptr& context) : - DrawLayer(context, "OverlayLayer"), - p(std::make_unique(this, context->gl_context())) +OverlayLayer::OverlayLayer(const std::shared_ptr& glContext) : + DrawLayer(glContext, "OverlayLayer"), + p(std::make_unique(this, glContext)) { AddDrawItem(p->activeBoxOuter_); AddDrawItem(p->activeBoxInner_); @@ -168,13 +173,13 @@ OverlayLayer::~OverlayLayer() p->cursorScaleConnection_.disconnect(); } -void OverlayLayerImpl::SetCusorLocation(common::Coordinate coordinate) +void OverlayLayer::Impl::SetCusorLocation(common::Coordinate coordinate) { geoIcons_->SetIconLocation( cursorIcon_, coordinate.latitude_, coordinate.longitude_); } -void OverlayLayerImpl::SetupGeoIcons() +void OverlayLayer::Impl::SetupGeoIcons() { const std::unique_lock lock {renderMutex_}; @@ -208,13 +213,13 @@ void OverlayLayerImpl::SetupGeoIcons() geoIcons_->FinishIcons(); } -void OverlayLayer::Initialize() +void OverlayLayer::Initialize(const std::shared_ptr& mapContext) { logger_->debug("Initialize()"); - DrawLayer::Initialize(); + DrawLayer::Initialize(mapContext); - auto radarProductView = context()->radar_product_view(); + auto radarProductView = mapContext->radar_product_view(); if (radarProductView != nullptr) { @@ -251,7 +256,7 @@ void OverlayLayer::Initialize() p->icons_->SetIconTexture(p->compassIcon_, p->cardinalPointIconName_, 0); gl::draw::Icons::RegisterEventHandler( p->compassIcon_, - [this](QEvent* ev) + [this, mapContext](QEvent* ev) { switch (ev->type()) { @@ -276,7 +281,7 @@ void OverlayLayer::Initialize() if (mouseEvent->buttons() == Qt::MouseButton::LeftButton && p->lastBearing_ != 0.0) { - auto map = context()->map().lock(); + auto map = mapContext->map().lock(); if (map != nullptr) { map->setBearing(0.0); @@ -295,11 +300,11 @@ void OverlayLayer::Initialize() p->icons_->SetIconTexture(p->mapCenterIcon_, p->mapCenterIconName_, 0); p->mapLogoIcon_ = p->icons_->AddIcon(); - if (context()->map_provider() == MapProvider::Mapbox) + if (mapContext->map_provider() == MapProvider::Mapbox) { p->icons_->SetIconTexture(p->mapLogoIcon_, p->mapboxLogoImageName_, 0); } - else if (context()->map_provider() == MapProvider::MapTiler) + else if (mapContext->map_provider() == MapProvider::MapTiler) { p->icons_->SetIconTexture(p->mapLogoIcon_, p->mapTilerLogoImageName_, 0); } @@ -328,16 +333,17 @@ void OverlayLayer::Initialize() }); } -void OverlayLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) +void OverlayLayer::Render(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters& params) { const std::unique_lock lock {p->renderMutex_}; - gl::OpenGLFunctions& gl = context()->gl_context()->gl(); - auto radarProductView = context()->radar_product_view(); - auto& settings = context()->settings(); - const float pixelRatio = context()->pixel_ratio(); + gl::OpenGLFunctions& gl = gl_context()->gl(); + auto radarProductView = mapContext->radar_product_view(); + auto& settings = mapContext->settings(); + const float pixelRatio = mapContext->pixel_ratio(); - ImGuiFrameStart(); + ImGuiFrameStart(mapContext); p->sweepTimePicked_ = false; @@ -383,7 +389,7 @@ void OverlayLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) p->geoIcons_->SetIconVisible(p->cursorIcon_, cursorIconVisible); if (cursorIconVisible) { - p->SetCusorLocation(context()->mouse_coordinate()); + p->SetCusorLocation(mapContext->mouse_coordinate()); } // Location Icon @@ -507,7 +513,7 @@ void OverlayLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) p->icons_->SetIconVisible(p->mapCenterIcon_, generalSettings.show_map_center().GetValue()); - QMargins colorTableMargins = context()->color_table_margins(); + QMargins colorTableMargins = mapContext->color_table_margins(); if (colorTableMargins != p->lastColorTableMargins_ || p->firstRender_) { // Draw map logo with a 10x10 indent from the bottom left @@ -520,7 +526,7 @@ void OverlayLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) DrawLayer::RenderWithoutImGui(params); - auto mapCopyrights = context()->map_copyrights(); + auto mapCopyrights = mapContext->map_copyrights(); if (mapCopyrights.length() > 0 && generalSettings.show_map_attribution().GetValue()) { @@ -563,29 +569,13 @@ void OverlayLayer::Deinitialize() DrawLayer::Deinitialize(); - auto radarProductView = context()->radar_product_view(); - - if (radarProductView != nullptr) - { - disconnect(radarProductView.get(), - &view::RadarProductView::SweepComputed, - this, - &OverlayLayer::UpdateSweepTimeNextFrame); - } - - disconnect(p->positionManager_.get(), - &manager::PositionManager::LocationTrackingChanged, - this, - nullptr); - disconnect(p->positionManager_.get(), - &manager::PositionManager::PositionUpdated, - this, - nullptr); + disconnect(this); p->locationIcon_ = nullptr; } bool OverlayLayer::RunMousePicking( + const std::shared_ptr& mapContext, const QMapLibre::CustomLayerRenderParameters& params, const QPointF& mouseLocalPos, const QPointF& mouseGlobalPos, @@ -599,7 +589,8 @@ bool OverlayLayer::RunMousePicking( return true; } - return DrawLayer::RunMousePicking(params, + return DrawLayer::RunMousePicking(mapContext, + params, mouseLocalPos, mouseGlobalPos, mouseCoords, diff --git a/scwx-qt/source/scwx/qt/map/overlay_layer.hpp b/scwx-qt/source/scwx/qt/map/overlay_layer.hpp index 731cf766..89e49b6b 100644 --- a/scwx-qt/source/scwx/qt/map/overlay_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/overlay_layer.hpp @@ -5,33 +5,34 @@ namespace scwx::qt::map { -class OverlayLayerImpl; - class OverlayLayer : public DrawLayer { Q_DISABLE_COPY_MOVE(OverlayLayer) public: - explicit OverlayLayer(const std::shared_ptr& context); + explicit OverlayLayer(const std::shared_ptr& glContext); ~OverlayLayer(); - void Initialize() override final; - void Render(const QMapLibre::CustomLayerRenderParameters&) override final; - void Deinitialize() override final; + void Initialize(const std::shared_ptr& mapContext) final; + void Render(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters&) final; + void Deinitialize() final; - bool RunMousePicking( - const QMapLibre::CustomLayerRenderParameters& params, - const QPointF& mouseLocalPos, - const QPointF& mouseGlobalPos, - const glm::vec2& mouseCoords, - const common::Coordinate& mouseGeoCoords, - std::shared_ptr& eventHandler) override final; + bool + RunMousePicking(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters& params, + const QPointF& mouseLocalPos, + const QPointF& mouseGlobalPos, + const glm::vec2& mouseCoords, + const common::Coordinate& mouseGeoCoords, + std::shared_ptr& eventHandler) final; public slots: void UpdateSweepTimeNextFrame(); private: - std::unique_ptr p; + class Impl; + std::unique_ptr p; }; } // namespace scwx::qt::map diff --git a/scwx-qt/source/scwx/qt/map/overlay_product_layer.cpp b/scwx-qt/source/scwx/qt/map/overlay_product_layer.cpp index 00e2f1bd..4684d227 100644 --- a/scwx-qt/source/scwx/qt/map/overlay_product_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/overlay_product_layer.cpp @@ -20,10 +20,10 @@ static const auto logger_ = scwx::util::Logger::Create(logPrefix_); class OverlayProductLayer::Impl { public: - explicit Impl(OverlayProductLayer* self, - std::shared_ptr context) : + explicit Impl(OverlayProductLayer* self, + const std::shared_ptr& glContext) : self_ {self}, - linkedVectors_ {std::make_shared(context)} + linkedVectors_ {std::make_shared(glContext)} { auto& productSettings = settings::ProductSettings::Instance(); @@ -60,7 +60,8 @@ public: stiPastEnabledCallbackUuid_); } - void UpdateStormTrackingInformation(); + void UpdateStormTrackingInformation( + const std::shared_ptr& mapContext); static void HandleLinkedVectorPacket( const std::shared_ptr& packet, @@ -105,11 +106,21 @@ public: }; OverlayProductLayer::OverlayProductLayer( - const std::shared_ptr& context) : - DrawLayer(context, "OverlayProductLayer"), - p(std::make_unique(this, context->gl_context())) + const std::shared_ptr& glContext) : + DrawLayer(glContext, "OverlayProductLayer"), + p(std::make_unique(this, glContext)) { - auto overlayProductView = context->overlay_product_view(); + AddDrawItem(p->linkedVectors_); +} + +OverlayProductLayer::~OverlayProductLayer() = default; + +void OverlayProductLayer::Initialize( + const std::shared_ptr& mapContext) +{ + logger_->debug("Initialize()"); + + auto overlayProductView = mapContext->overlay_product_view(); connect(overlayProductView.get(), &view::OverlayProductView::ProductUpdated, this, @@ -122,31 +133,23 @@ OverlayProductLayer::OverlayProductLayer( } }); - AddDrawItem(p->linkedVectors_); -} + p->UpdateStormTrackingInformation(mapContext); -OverlayProductLayer::~OverlayProductLayer() = default; - -void OverlayProductLayer::Initialize() -{ - logger_->debug("Initialize()"); - - p->UpdateStormTrackingInformation(); - - DrawLayer::Initialize(); + DrawLayer::Initialize(mapContext); } void OverlayProductLayer::Render( + const std::shared_ptr& mapContext, const QMapLibre::CustomLayerRenderParameters& params) { - gl::OpenGLFunctions& gl = context()->gl_context()->gl(); + gl::OpenGLFunctions& gl = gl_context()->gl(); if (p->stiNeedsUpdate_) { - p->UpdateStormTrackingInformation(); + p->UpdateStormTrackingInformation(mapContext); } - DrawLayer::Render(params); + DrawLayer::Render(mapContext, params); SCWX_GL_CHECK_ERROR(); } @@ -155,16 +158,19 @@ void OverlayProductLayer::Deinitialize() { logger_->debug("Deinitialize()"); + disconnect(this); + DrawLayer::Deinitialize(); } -void OverlayProductLayer::Impl::UpdateStormTrackingInformation() +void OverlayProductLayer::Impl::UpdateStormTrackingInformation( + const std::shared_ptr& mapContext) { logger_->debug("Update Storm Tracking Information"); stiNeedsUpdate_ = false; - auto overlayProductView = self_->context()->overlay_product_view(); + auto overlayProductView = mapContext->overlay_product_view(); auto radarProductManager = overlayProductView->radar_product_manager(); auto message = overlayProductView->radar_product_message("NST"); @@ -431,6 +437,7 @@ std::string OverlayProductLayer::Impl::BuildHoverText( } bool OverlayProductLayer::RunMousePicking( + const std::shared_ptr& mapContext, const QMapLibre::CustomLayerRenderParameters& params, const QPointF& mouseLocalPos, const QPointF& mouseGlobalPos, @@ -438,7 +445,8 @@ bool OverlayProductLayer::RunMousePicking( const common::Coordinate& mouseGeoCoords, std::shared_ptr& eventHandler) { - return DrawLayer::RunMousePicking(params, + return DrawLayer::RunMousePicking(mapContext, + params, mouseLocalPos, mouseGlobalPos, mouseCoords, diff --git a/scwx-qt/source/scwx/qt/map/overlay_product_layer.hpp b/scwx-qt/source/scwx/qt/map/overlay_product_layer.hpp index 9db8c02b..5c2fd73e 100644 --- a/scwx-qt/source/scwx/qt/map/overlay_product_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/overlay_product_layer.hpp @@ -7,21 +7,26 @@ namespace scwx::qt::map class OverlayProductLayer : public DrawLayer { + Q_DISABLE_COPY_MOVE(OverlayProductLayer) + public: - explicit OverlayProductLayer(const std::shared_ptr& context); + explicit OverlayProductLayer( + const std::shared_ptr& glContext); ~OverlayProductLayer(); - void Initialize() override final; - void Render(const QMapLibre::CustomLayerRenderParameters&) override final; - void Deinitialize() override final; + void Initialize(const std::shared_ptr& mapContext) final; + void Render(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters&) final; + void Deinitialize() final; - bool RunMousePicking( - const QMapLibre::CustomLayerRenderParameters& params, - const QPointF& mouseLocalPos, - const QPointF& mouseGlobalPos, - const glm::vec2& mouseCoords, - const common::Coordinate& mouseGeoCoords, - std::shared_ptr& eventHandler) override final; + bool + RunMousePicking(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters& params, + const QPointF& mouseLocalPos, + const QPointF& mouseGlobalPos, + const glm::vec2& mouseCoords, + const common::Coordinate& mouseGeoCoords, + std::shared_ptr& eventHandler) final; private: class Impl; diff --git a/scwx-qt/source/scwx/qt/map/placefile_layer.cpp b/scwx-qt/source/scwx/qt/map/placefile_layer.cpp index 7da00a1b..d725850e 100644 --- a/scwx-qt/source/scwx/qt/map/placefile_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/placefile_layer.cpp @@ -21,25 +21,31 @@ static const auto logger_ = scwx::util::Logger::Create(logPrefix_); class PlacefileLayer::Impl { public: - explicit Impl(PlacefileLayer* self, - std::shared_ptr context, - const std::string& placefileName) : + explicit Impl(PlacefileLayer* self, + const std::shared_ptr& glContext, + const std::string& placefileName) : self_ {self}, placefileName_ {placefileName}, - placefileIcons_ {std::make_shared(context)}, - placefileImages_ {std::make_shared(context)}, - placefileLines_ {std::make_shared(context)}, + placefileIcons_ {std::make_shared(glContext)}, + placefileImages_ { + std::make_shared(glContext)}, + placefileLines_ {std::make_shared(glContext)}, placefilePolygons_ { - std::make_shared(context)}, + std::make_shared(glContext)}, placefileTriangles_ { - std::make_shared(context)}, + std::make_shared(glContext)}, placefileText_ { - std::make_shared(context, placefileName)} + std::make_shared(glContext, placefileName)} { ConnectSignals(); } ~Impl() { threadPool_.join(); } + Impl(const Impl&) = delete; + Impl& operator=(const Impl&) = delete; + Impl(const Impl&&) = delete; + Impl& operator=(const Impl&&) = delete; + void ConnectSignals(); void ReloadDataSync(); @@ -60,11 +66,10 @@ public: std::chrono::system_clock::time_point selectedTime_ {}; }; -PlacefileLayer::PlacefileLayer(const std::shared_ptr& context, +PlacefileLayer::PlacefileLayer(const std::shared_ptr& glContext, const std::string& placefileName) : - DrawLayer(context, fmt::format("PlacefileLayer {}", placefileName)), - p(std::make_unique( - this, context->gl_context(), placefileName)) + DrawLayer(glContext, fmt::format("PlacefileLayer {}", placefileName)), + p(std::make_unique(this, glContext, placefileName)) { AddDrawItem(p->placefileImages_); AddDrawItem(p->placefilePolygons_); @@ -114,19 +119,20 @@ void PlacefileLayer::set_placefile_name(const std::string& placefileName) ReloadData(); } -void PlacefileLayer::Initialize() +void PlacefileLayer::Initialize(const std::shared_ptr& mapContext) { logger_->debug("Initialize()"); - DrawLayer::Initialize(); + DrawLayer::Initialize(mapContext); p->selectedTime_ = manager::TimelineManager::Instance()->GetSelectedTime(); } void PlacefileLayer::Render( + const std::shared_ptr& mapContext, const QMapLibre::CustomLayerRenderParameters& params) { - gl::OpenGLFunctions& gl = context()->gl_context()->gl(); + gl::OpenGLFunctions& gl = gl_context()->gl(); std::shared_ptr placefileManager = manager::PlacefileManager::Instance(); @@ -153,7 +159,7 @@ void PlacefileLayer::Render( p->placefileText_->set_selected_time(p->selectedTime_); } - DrawLayer::Render(params); + DrawLayer::Render(mapContext, params); SCWX_GL_CHECK_ERROR(); } diff --git a/scwx-qt/source/scwx/qt/map/placefile_layer.hpp b/scwx-qt/source/scwx/qt/map/placefile_layer.hpp index 9a6d49d1..35f5a81b 100644 --- a/scwx-qt/source/scwx/qt/map/placefile_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/placefile_layer.hpp @@ -10,19 +10,21 @@ namespace scwx::qt::map class PlacefileLayer : public DrawLayer { Q_OBJECT + Q_DISABLE_COPY_MOVE(PlacefileLayer) public: - explicit PlacefileLayer(const std::shared_ptr& context, - const std::string& placefileName); + explicit PlacefileLayer(const std::shared_ptr& glContext, + const std::string& placefileName); ~PlacefileLayer(); std::string placefile_name() const; void set_placefile_name(const std::string& placefileName); - void Initialize() override final; - void Render(const QMapLibre::CustomLayerRenderParameters&) override final; - void Deinitialize() override final; + void Initialize(const std::shared_ptr& mapContext) final; + void Render(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters&) final; + void Deinitialize() final; void ReloadData(); diff --git a/scwx-qt/source/scwx/qt/map/radar_product_layer.cpp b/scwx-qt/source/scwx/qt/map/radar_product_layer.cpp index fbafd997..c1fbd6c4 100644 --- a/scwx-qt/source/scwx/qt/map/radar_product_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/radar_product_layer.cpp @@ -32,67 +32,48 @@ namespace scwx::qt::map static const std::string logPrefix_ = "scwx::qt::map::radar_product_layer"; static const auto logger_ = scwx::util::Logger::Create(logPrefix_); -class RadarProductLayerImpl +class RadarProductLayer::Impl { public: - explicit RadarProductLayerImpl() : - shaderProgram_(nullptr), - uMVPMatrixLocation_(GL_INVALID_INDEX), - uMapScreenCoordLocation_(GL_INVALID_INDEX), - uDataMomentOffsetLocation_(GL_INVALID_INDEX), - uDataMomentScaleLocation_(GL_INVALID_INDEX), - uCFPEnabledLocation_(GL_INVALID_INDEX), - vbo_ {GL_INVALID_INDEX}, - vao_ {GL_INVALID_INDEX}, - texture_ {GL_INVALID_INDEX}, - numVertices_ {0}, - cfpEnabled_ {false}, - colorTableNeedsUpdate_ {false}, - sweepNeedsUpdate_ {false} - { - } - ~RadarProductLayerImpl() = default; + explicit Impl() = default; + ~Impl() = default; - std::shared_ptr shaderProgram_; + Impl(const Impl&) = delete; + Impl& operator=(const Impl&) = delete; + Impl(const Impl&&) = delete; + Impl& operator=(const Impl&&) = delete; - GLint uMVPMatrixLocation_; - GLint uMapScreenCoordLocation_; - GLint uDataMomentOffsetLocation_; - GLint uDataMomentScaleLocation_; - GLint uCFPEnabledLocation_; - std::array vbo_; - GLuint vao_; - GLuint texture_; + std::shared_ptr shaderProgram_ {nullptr}; - GLsizeiptr numVertices_; + GLint uMVPMatrixLocation_ {static_cast(GL_INVALID_INDEX)}; + GLint uMapScreenCoordLocation_ {static_cast(GL_INVALID_INDEX)}; + GLint uDataMomentOffsetLocation_ {static_cast(GL_INVALID_INDEX)}; + GLint uDataMomentScaleLocation_ {static_cast(GL_INVALID_INDEX)}; + GLint uCFPEnabledLocation_ {static_cast(GL_INVALID_INDEX)}; + std::array vbo_ {GL_INVALID_INDEX}; + GLuint vao_ {GL_INVALID_INDEX}; + GLuint texture_ {GL_INVALID_INDEX}; - bool cfpEnabled_; + GLsizeiptr numVertices_ {0}; - bool colorTableNeedsUpdate_; - bool sweepNeedsUpdate_; + bool cfpEnabled_ {false}; + + bool colorTableNeedsUpdate_ {false}; + bool sweepNeedsUpdate_ {false}; }; -RadarProductLayer::RadarProductLayer( - const std::shared_ptr& context) : - GenericLayer(context), p(std::make_unique()) +RadarProductLayer::RadarProductLayer(std::shared_ptr glContext) : + GenericLayer(std::move(glContext)), p(std::make_unique()) { - auto radarProductView = context->radar_product_view(); - connect(radarProductView.get(), - &view::RadarProductView::ColorTableLutUpdated, - this, - [this]() { p->colorTableNeedsUpdate_ = true; }); - connect(radarProductView.get(), - &view::RadarProductView::SweepComputed, - this, - [this]() { p->sweepNeedsUpdate_ = true; }); } RadarProductLayer::~RadarProductLayer() = default; -void RadarProductLayer::Initialize() +void RadarProductLayer::Initialize( + const std::shared_ptr& mapContext) { logger_->debug("Initialize()"); - auto glContext = context()->gl_context(); + auto glContext = gl_context(); gl::OpenGLFunctions& gl = glContext->gl(); @@ -145,25 +126,36 @@ void RadarProductLayer::Initialize() // Update radar sweep p->sweepNeedsUpdate_ = true; - UpdateSweep(); + UpdateSweep(mapContext); // Create color table gl.glGenTextures(1, &p->texture_); p->colorTableNeedsUpdate_ = true; - UpdateColorTable(); + UpdateColorTable(mapContext); gl.glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); gl.glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gl.glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + + auto radarProductView = mapContext->radar_product_view(); + connect(radarProductView.get(), + &view::RadarProductView::ColorTableLutUpdated, + this, + [this]() { p->colorTableNeedsUpdate_ = true; }); + connect(radarProductView.get(), + &view::RadarProductView::SweepComputed, + this, + [this]() { p->sweepNeedsUpdate_ = true; }); } -void RadarProductLayer::UpdateSweep() +void RadarProductLayer::UpdateSweep( + const std::shared_ptr& mapContext) { - gl::OpenGLFunctions& gl = context()->gl_context()->gl(); + gl::OpenGLFunctions& gl = gl_context()->gl(); boost::timer::cpu_timer timer; std::shared_ptr radarProductView = - context()->radar_product_view(); + mapContext->radar_product_view(); std::unique_lock sweepLock(radarProductView->sweep_mutex(), std::try_to_lock); @@ -258,16 +250,17 @@ void RadarProductLayer::UpdateSweep() } void RadarProductLayer::Render( + const std::shared_ptr& mapContext, const QMapLibre::CustomLayerRenderParameters& params) { - gl::OpenGLFunctions& gl = context()->gl_context()->gl(); + gl::OpenGLFunctions& gl = gl_context()->gl(); p->shaderProgram_->Use(); // Set OpenGL blend mode for transparency gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - const bool wireframeEnabled = context()->settings().radarWireframeEnabled_; + const bool wireframeEnabled = mapContext->settings().radarWireframeEnabled_; if (wireframeEnabled) { // Set polygon mode to draw wireframe @@ -276,12 +269,12 @@ void RadarProductLayer::Render( if (p->colorTableNeedsUpdate_) { - UpdateColorTable(); + UpdateColorTable(mapContext); } if (p->sweepNeedsUpdate_) { - UpdateSweep(); + UpdateSweep(mapContext); } const float scale = std::pow(2.0, params.zoom) * 2.0f * @@ -323,7 +316,7 @@ void RadarProductLayer::Deinitialize() { logger_->debug("Deinitialize()"); - gl::OpenGLFunctions& gl = context()->gl_context()->gl(); + gl::OpenGLFunctions& gl = gl_context()->gl(); gl.glDeleteVertexArrays(1, &p->vao_); gl.glDeleteBuffers(3, p->vbo_.data()); @@ -339,6 +332,7 @@ void RadarProductLayer::Deinitialize() } bool RadarProductLayer::RunMousePicking( + const std::shared_ptr& mapContext, const QMapLibre::CustomLayerRenderParameters& /* params */, const QPointF& /* mouseLocalPos */, const QPointF& mouseGlobalPos, @@ -352,16 +346,16 @@ bool RadarProductLayer::RunMousePicking( Qt::KeyboardModifier::ShiftModifier) { std::shared_ptr radarProductView = - context()->radar_product_view(); + mapContext->radar_product_view(); - if (context()->radar_site() == nullptr) + if (mapContext->radar_site() == nullptr) { return itemPicked; } // Get distance and altitude of point - const double radarLatitude = context()->radar_site()->latitude(); - const double radarLongitude = context()->radar_site()->longitude(); + const double radarLatitude = mapContext->radar_site()->latitude(); + const double radarLongitude = mapContext->radar_site()->longitude(); const auto distanceMeters = util::GeographicLib::GetDistance(mouseGeoCoords.latitude_, @@ -396,7 +390,7 @@ bool RadarProductLayer::RunMousePicking( util::GeographicLib::GetRadarBeamAltititude( distanceMeters, units::angle::degrees(*elevation), - context()->radar_site()->altitude()); + mapContext->radar_site()->altitude()); const std::string heightUnitName = settings::UnitSettings::Instance().echo_tops_units().GetValue(); @@ -529,15 +523,16 @@ bool RadarProductLayer::RunMousePicking( return itemPicked; } -void RadarProductLayer::UpdateColorTable() +void RadarProductLayer::UpdateColorTable( + const std::shared_ptr& mapContext) { logger_->debug("UpdateColorTable()"); p->colorTableNeedsUpdate_ = false; - gl::OpenGLFunctions& gl = context()->gl_context()->gl(); + gl::OpenGLFunctions& gl = gl_context()->gl(); std::shared_ptr radarProductView = - context()->radar_product_view(); + mapContext->radar_product_view(); const std::vector& colorTable = radarProductView->color_table_lut(); diff --git a/scwx-qt/source/scwx/qt/map/radar_product_layer.hpp b/scwx-qt/source/scwx/qt/map/radar_product_layer.hpp index 4491062b..df5adcc9 100644 --- a/scwx-qt/source/scwx/qt/map/radar_product_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/radar_product_layer.hpp @@ -5,20 +5,22 @@ namespace scwx::qt::map { -class RadarProductLayerImpl; - class RadarProductLayer : public GenericLayer { + Q_DISABLE_COPY_MOVE(RadarProductLayer) + public: - explicit RadarProductLayer(const std::shared_ptr& context); + explicit RadarProductLayer(std::shared_ptr glContext); ~RadarProductLayer(); - void Initialize() override final; - void Render(const QMapLibre::CustomLayerRenderParameters&) override final; - void Deinitialize() override final; + void Initialize(const std::shared_ptr& mapContext) final; + void Render(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters&) final; + void Deinitialize() final; - virtual bool - RunMousePicking(const QMapLibre::CustomLayerRenderParameters& params, + bool + RunMousePicking(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters& params, const QPointF& mouseLocalPos, const QPointF& mouseGlobalPos, const glm::vec2& mouseCoords, @@ -26,11 +28,12 @@ public: std::shared_ptr& eventHandler) override; private: - void UpdateColorTable(); - void UpdateSweep(); + void UpdateColorTable(const std::shared_ptr& mapContext); + void UpdateSweep(const std::shared_ptr& mapContext); private: - std::unique_ptr p; + class Impl; + std::unique_ptr p; }; } // namespace scwx::qt::map diff --git a/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp b/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp index ba748230..418fa2ff 100644 --- a/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp @@ -22,15 +22,21 @@ static const auto logger_ = scwx::util::Logger::Create(logPrefix_); class RadarSiteLayer::Impl { public: - explicit Impl(RadarSiteLayer* self, std::shared_ptr context) : - self_ {self}, geoLines_ {std::make_shared(context)} + explicit Impl(RadarSiteLayer* self, + const std::shared_ptr& glContext) : + self_ {self}, geoLines_ {std::make_shared(glContext)} { } ~Impl() = default; + Impl(const Impl&) = delete; + Impl& operator=(const Impl&) = delete; + Impl(const Impl&&) = delete; + Impl& operator=(const Impl&&) = delete; + void RenderRadarSite(const QMapLibre::CustomLayerRenderParameters& params, std::shared_ptr& radarSite); - void RenderRadarLine(); + void RenderRadarLine(const std::shared_ptr& mapContext); RadarSiteLayer* self_; @@ -50,15 +56,16 @@ public: nullptr, nullptr}; }; -RadarSiteLayer::RadarSiteLayer(const std::shared_ptr& context) : - DrawLayer(context, "RadarSiteLayer"), - p(std::make_unique(this, context->gl_context())) +RadarSiteLayer::RadarSiteLayer( + const std::shared_ptr& glContext) : + DrawLayer(glContext, "RadarSiteLayer"), + p(std::make_unique(this, glContext)) { } RadarSiteLayer::~RadarSiteLayer() = default; -void RadarSiteLayer::Initialize() +void RadarSiteLayer::Initialize(const std::shared_ptr& mapContext) { logger_->debug("Initialize()"); @@ -81,10 +88,11 @@ void RadarSiteLayer::Initialize() AddDrawItem(p->geoLines_); p->geoLines_->set_thresholded(false); - DrawLayer::Initialize(); + DrawLayer::Initialize(mapContext); } void RadarSiteLayer::Render( + const std::shared_ptr& mapContext, const QMapLibre::CustomLayerRenderParameters& params) { p->hoverText_.clear(); @@ -99,7 +107,7 @@ void RadarSiteLayer::Render( return; } - gl::OpenGLFunctions& gl = context()->gl_context()->gl(); + gl::OpenGLFunctions& gl = gl_context()->gl(); // Update map screen coordinate and scale information p->mapScreenCoordLocation_ = util::maplibre::LatLongToScreenCoordinate( @@ -111,7 +119,7 @@ void RadarSiteLayer::Render( p->halfWidth_ = params.width * 0.5f; p->halfHeight_ = params.height * 0.5f; - ImGuiFrameStart(); + ImGuiFrameStart(mapContext); // Radar site ImGui windows shouldn't have padding ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2 {0.0f, 0.0f}); @@ -122,7 +130,7 @@ void RadarSiteLayer::Render( ImGui::PopStyleVar(); - p->RenderRadarLine(); + p->RenderRadarLine(mapContext); DrawLayer::RenderWithoutImGui(params); @@ -192,15 +200,16 @@ void RadarSiteLayer::Impl::RenderRadarSite( } } -void RadarSiteLayer::Impl::RenderRadarLine() +void RadarSiteLayer::Impl::RenderRadarLine( + const std::shared_ptr& mapContext) { if ((QGuiApplication::keyboardModifiers() & Qt::KeyboardModifier::ShiftModifier) && - self_->context()->radar_site() != nullptr) + mapContext->radar_site() != nullptr) { - const auto& mouseCoord = self_->context()->mouse_coordinate(); - const double radarLatitude = self_->context()->radar_site()->latitude(); - const double radarLongitude = self_->context()->radar_site()->longitude(); + const auto& mouseCoord = mapContext->mouse_coordinate(); + const double radarLatitude = mapContext->radar_site()->latitude(); + const double radarLongitude = mapContext->radar_site()->longitude(); geoLines_->SetLineLocation(radarSiteLines_[0], static_cast(mouseCoord.latitude_), @@ -231,6 +240,7 @@ void RadarSiteLayer::Deinitialize() } bool RadarSiteLayer::RunMousePicking( + const std::shared_ptr& /* mapContext */, const QMapLibre::CustomLayerRenderParameters& /* params */, const QPointF& /* mouseLocalPos */, const QPointF& mouseGlobalPos, diff --git a/scwx-qt/source/scwx/qt/map/radar_site_layer.hpp b/scwx-qt/source/scwx/qt/map/radar_site_layer.hpp index e7d2a535..74fc6398 100644 --- a/scwx-qt/source/scwx/qt/map/radar_site_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/radar_site_layer.hpp @@ -11,20 +11,22 @@ class RadarSiteLayer : public DrawLayer Q_DISABLE_COPY_MOVE(RadarSiteLayer) public: - explicit RadarSiteLayer(const std::shared_ptr& context); + explicit RadarSiteLayer(const std::shared_ptr& glContext); ~RadarSiteLayer(); - void Initialize() override final; - void Render(const QMapLibre::CustomLayerRenderParameters&) override final; - void Deinitialize() override final; + void Initialize(const std::shared_ptr& mapContext) final; + void Render(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters&) final; + void Deinitialize() final; - bool RunMousePicking( - const QMapLibre::CustomLayerRenderParameters& params, - const QPointF& mouseLocalPos, - const QPointF& mouseGlobalPos, - const glm::vec2& mouseCoords, - const common::Coordinate& mouseGeoCoords, - std::shared_ptr& eventHandler) override final; + bool + RunMousePicking(const std::shared_ptr& mapContext, + const QMapLibre::CustomLayerRenderParameters& params, + const QPointF& mouseLocalPos, + const QPointF& mouseGlobalPos, + const glm::vec2& mouseCoords, + const common::Coordinate& mouseGeoCoords, + std::shared_ptr& eventHandler) final; signals: void RadarSiteSelected(const std::string& id);