diff --git a/scwx-qt/source/scwx/qt/gl/draw/placefile_polygons.cpp b/scwx-qt/source/scwx/qt/gl/draw/placefile_polygons.cpp index 7bb54027..67d04a3d 100644 --- a/scwx-qt/source/scwx/qt/gl/draw/placefile_polygons.cpp +++ b/scwx-qt/source/scwx/qt/gl/draw/placefile_polygons.cpp @@ -91,9 +91,6 @@ public: bool dirty_ {false}; bool thresholded_ {false}; - std::vector> - polygonList_ {}; - boost::container::stable_vector tessCombineBuffer_ {}; std::mutex bufferMutex_ {}; @@ -243,9 +240,6 @@ void PlacefilePolygons::StartPolygons() // Clear the new buffer p->newBuffer_.clear(); p->newThresholdBuffer_.clear(); - - // Clear the polygon list - p->polygonList_.clear(); } void PlacefilePolygons::AddPolygon( @@ -253,7 +247,6 @@ void PlacefilePolygons::AddPolygon( { if (di != nullptr) { - p->polygonList_.emplace_back(di); p->Tessellate(di); } } diff --git a/scwx-qt/source/scwx/qt/map/placefile_layer.cpp b/scwx-qt/source/scwx/qt/map/placefile_layer.cpp index e287be40..3f5c880e 100644 --- a/scwx-qt/source/scwx/qt/map/placefile_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/placefile_layer.cpp @@ -5,6 +5,8 @@ #include #include +#include +#include namespace scwx { @@ -36,14 +38,12 @@ public: void ConnectSignals(); - void AddIcon(const std::shared_ptr& di); - void AddPolygon(const std::shared_ptr& di); - void AddText(const std::shared_ptr& di); - + boost::asio::thread_pool threadPool_ {1}; PlacefileLayer* self_; std::string placefileName_; + std::mutex dataMutex_ {}; bool dirty_ {true}; std::shared_ptr placefileIcons_; @@ -74,7 +74,7 @@ void PlacefileLayer::Impl::ConnectSignals() { if (name == placefileName_) { - dirty_ = true; + self_->ReloadData(); } }); } @@ -99,39 +99,6 @@ void PlacefileLayer::Initialize() DrawLayer::Initialize(); } -void PlacefileLayer::Impl::AddIcon( - const std::shared_ptr& di) -{ - if (!dirty_) - { - return; - } - - placefileIcons_->AddIcon(di); -} - -void PlacefileLayer::Impl::AddPolygon( - const std::shared_ptr& di) -{ - if (!dirty_) - { - return; - }; - - placefilePolygons_->AddPolygon(di); -} - -void PlacefileLayer::Impl::AddText( - const std::shared_ptr& di) -{ - if (!dirty_) - { - return; - }; - - placefileText_->AddText(di); -} - void PlacefileLayer::Render( const QMapLibreGL::CustomLayerRenderParameters& params) { @@ -161,43 +128,30 @@ void PlacefileLayer::Render( p->placefileIcons_->SetIconFiles(placefile->icon_files(), placefile->name()); - // Reset Placefile Polygons - p->placefilePolygons_->StartPolygons(); - // Reset Placefile Text p->placefileText_->Reset(); - } - for (auto& drawItem : placefile->GetDrawItems()) - { - switch (drawItem->itemType_) + for (auto& drawItem : placefile->GetDrawItems()) { - case gr::Placefile::ItemType::Text: - p->AddText( - std::static_pointer_cast(drawItem)); - break; + switch (drawItem->itemType_) + { + case gr::Placefile::ItemType::Text: + p->placefileText_->AddText( + std::static_pointer_cast( + drawItem)); + break; - case gr::Placefile::ItemType::Icon: - p->AddIcon( - std::static_pointer_cast(drawItem)); - break; + case gr::Placefile::ItemType::Icon: + p->placefileIcons_->AddIcon( + std::static_pointer_cast( + drawItem)); + break; - case gr::Placefile::ItemType::Polygon: - p->AddPolygon( - std::static_pointer_cast( - drawItem)); - break; - - default: - break; + default: + break; + } } } - - if (p->dirty_) - { - // Finish Placefile Polygons - p->placefilePolygons_->FinishPolygons(); - } } DrawLayer::Render(params); @@ -212,6 +166,59 @@ void PlacefileLayer::Deinitialize() DrawLayer::Deinitialize(); } +void PlacefileLayer::ReloadData() +{ + // TODO: No longer needed after moving Icon and Text Render items here + p->dirty_ = true; + + boost::asio::post( + p->threadPool_, + [this]() + { + logger_->debug("ReloadData: {}", p->placefileName_); + + std::unique_lock lock {p->dataMutex_}; + + std::shared_ptr placefileManager = + manager::PlacefileManager::Instance(); + + auto placefile = placefileManager->placefile(p->placefileName_); + if (placefile == nullptr) + { + return; + } + + // Reset Placefile Polygons + p->placefilePolygons_->StartPolygons(); + + for (auto& drawItem : placefile->GetDrawItems()) + { + switch (drawItem->itemType_) + { + case gr::Placefile::ItemType::Text: + // TODO + break; + + case gr::Placefile::ItemType::Icon: + // TODO + break; + + case gr::Placefile::ItemType::Polygon: + p->placefilePolygons_->AddPolygon( + std::static_pointer_cast( + drawItem)); + break; + + default: + break; + } + } + + // Finish Placefile Polygons + p->placefilePolygons_->FinishPolygons(); + }); +} + } // namespace map } // namespace qt } // namespace scwx diff --git a/scwx-qt/source/scwx/qt/map/placefile_layer.hpp b/scwx-qt/source/scwx/qt/map/placefile_layer.hpp index 2e07c5c9..68fd38c5 100644 --- a/scwx-qt/source/scwx/qt/map/placefile_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/placefile_layer.hpp @@ -26,6 +26,8 @@ public: void Render(const QMapLibreGL::CustomLayerRenderParameters&) override final; void Deinitialize() override final; + void ReloadData(); + private: class Impl; std::unique_ptr p;