refactor: Enhance VTK puppet lifecycle management by explicitly handling puppet removal and synchronizing puppets across all viewports, and remove default scene objects from startup.

This commit is contained in:
AndreaRigoni
2026-03-22 13:20:44 +00:00
parent 324aaa91b7
commit d87f3a984e
3 changed files with 47 additions and 17 deletions

View File

@@ -110,19 +110,42 @@ void MainPanel::setContext(uLib::ObjectsContext* context) {
if (context) {
if (auto* viewport = qobject_cast<uLib::Vtk::QViewport*>(m_firstPane->currentViewport())) {
m_mainVtkContext = new uLib::Vtk::vtkObjectsContext(context);
viewport->AddPuppet(*m_mainVtkContext);
uLib::Object::connect(m_mainVtkContext, &uLib::Vtk::vtkObjectsContext::PuppetAdded, [viewport](uLib::Vtk::Puppet* p) {
if (viewport && p) {
viewport->AddPuppet(*p);
viewport->ZoomAuto();
viewport->Render();
// viewport->AddPuppet(*m_mainVtkContext); // redundant
uLib::Object::connect(m_mainVtkContext, &uLib::Vtk::vtkObjectsContext::PuppetAdded, [this](uLib::Vtk::Puppet* p) {
if (p) {
auto panes = this->findChildren<ViewportPane*>();
for (auto* pane : panes) {
if (auto* vp = qobject_cast<uLib::Vtk::QViewport*>(pane->currentViewport())) {
vp->AddPuppet(*p);
vp->ZoomAuto();
vp->Render();
}
}
}
});
// Add any puppets that were created during m_mainVtkContext's construction
uLib::Object::connect(m_mainVtkContext, &uLib::Vtk::vtkObjectsContext::PuppetRemoved, [this](uLib::Vtk::Puppet* p) {
if (p) {
auto panes = this->findChildren<ViewportPane*>();
for (auto* pane : panes) {
if (auto* vp = qobject_cast<uLib::Vtk::QViewport*>(pane->currentViewport())) {
vp->RemovePuppet(*p);
vp->Render();
}
}
}
});
// Add any puppets that were created during m_mainVtkContext's construction to all panes
auto panes = this->findChildren<ViewportPane*>();
for (auto* obj : context->GetObjects()) {
if (auto* p = m_mainVtkContext->GetPuppet(obj)) {
viewport->AddPuppet(*p);
for (auto* pane : panes) {
if (auto* vp = qobject_cast<uLib::Vtk::QViewport*>(pane->currentViewport())) {
vp->AddPuppet(*p);
}
}
}
}