#include #include #include #include #include #include namespace scwx { namespace qt { namespace map { static const std::string logPrefix_ = "scwx::qt::map::placefile_layer"; 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) : self_ {self}, placefileName_ {placefileName}, placefileIcons_ {std::make_shared(context)}, placefilePolygons_ { std::make_shared(context)}, placefileText_ { std::make_shared(context, placefileName)} { ConnectSignals(); } ~Impl() = default; void ConnectSignals(); void AddIcon(const std::shared_ptr& di); void AddPolygon(const std::shared_ptr& di); void AddText(const std::shared_ptr& di); PlacefileLayer* self_; std::string placefileName_; bool dirty_ {true}; std::shared_ptr placefileIcons_; std::shared_ptr placefilePolygons_; std::shared_ptr placefileText_; }; PlacefileLayer::PlacefileLayer(std::shared_ptr context, const std::string& placefileName) : DrawLayer(context), p(std::make_unique(this, context, placefileName)) { AddDrawItem(p->placefileIcons_); AddDrawItem(p->placefilePolygons_); AddDrawItem(p->placefileText_); } PlacefileLayer::~PlacefileLayer() = default; void PlacefileLayer::Impl::ConnectSignals() { auto placefileManager = manager::PlacefileManager::Instance(); QObject::connect(placefileManager.get(), &manager::PlacefileManager::PlacefileUpdated, self_, [this](const std::string& name) { if (name == placefileName_) { dirty_ = true; } }); } std::string PlacefileLayer::placefile_name() const { return p->placefileName_; } void PlacefileLayer::set_placefile_name(const std::string& placefileName) { p->placefileName_ = placefileName; p->dirty_ = true; p->placefileText_->set_placefile_name(placefileName); } void PlacefileLayer::Initialize() { logger_->debug("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) { gl::OpenGLFunctions& gl = context()->gl(); // Set OpenGL blend mode for transparency gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); std::shared_ptr placefileManager = manager::PlacefileManager::Instance(); auto placefile = placefileManager->placefile(p->placefileName_); // Render placefile if (placefile != nullptr) { bool thresholded = placefileManager->placefile_thresholded(placefile->name()); p->placefileIcons_->set_thresholded(thresholded); p->placefilePolygons_->set_thresholded(thresholded); p->placefileText_->set_thresholded(thresholded); if (p->dirty_) { // Reset Placefile Icons p->placefileIcons_->Reset(); 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_) { case gr::Placefile::ItemType::Text: p->AddText( std::static_pointer_cast(drawItem)); break; case gr::Placefile::ItemType::Icon: p->AddIcon( std::static_pointer_cast(drawItem)); break; case gr::Placefile::ItemType::Polygon: p->AddPolygon( std::static_pointer_cast( drawItem)); break; default: break; } } if (p->dirty_) { // Finish Placefile Polygons p->placefilePolygons_->FinishPolygons(); } } DrawLayer::Render(params); SCWX_GL_CHECK_ERROR(); } void PlacefileLayer::Deinitialize() { logger_->debug("Deinitialize()"); DrawLayer::Deinitialize(); } } // namespace map } // namespace qt } // namespace scwx