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:
@@ -86,7 +86,7 @@ void ContextPanel::setContext(uLib::ObjectsContext* context) {
|
||||
delete m_vtkContext;
|
||||
}
|
||||
m_vtkContext = new uLib::Vtk::vtkObjectsContext(context);
|
||||
m_vtkView->AddPuppet(*m_vtkContext);
|
||||
// m_vtkView->AddPuppet(*m_vtkContext); // redundant: child puppets are added individually
|
||||
|
||||
// Render viewport and add child puppets when context is updated
|
||||
if (context) {
|
||||
@@ -98,6 +98,13 @@ void ContextPanel::setContext(uLib::ObjectsContext* context) {
|
||||
}
|
||||
});
|
||||
|
||||
uLib::Object::connect(m_vtkContext, &uLib::Vtk::vtkObjectsContext::PuppetRemoved, [this](uLib::Vtk::Puppet* p) {
|
||||
if (this->m_vtkView && p) {
|
||||
this->m_vtkView->RemovePuppet(*p);
|
||||
this->m_vtkView->Render();
|
||||
}
|
||||
});
|
||||
|
||||
// Add any puppets that were created during m_vtkContext's construction
|
||||
for (auto* obj : context->GetObjects()) {
|
||||
if (auto* p = m_vtkContext->GetPuppet(obj)) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,17 +32,17 @@ int main(int argc, char** argv) {
|
||||
StyleManager::applyStyle(&app, "dark");
|
||||
std::cout << "Starting gcompose Qt application..." << std::endl;
|
||||
|
||||
ContainerBox world_box(Vector3f(1, 1, 1));
|
||||
world_box.Scale(Vector3f(2_mm, 2_mm, 2_mm));
|
||||
world_box.SetPosition(Vector3f(-1_mm, -1_mm, -1_mm));
|
||||
// ContainerBox world_box(Vector3f(1, 1, 1));
|
||||
// world_box.Scale(Vector3f(2_mm, 2_mm, 2_mm));
|
||||
// world_box.SetPosition(Vector3f(-1_mm, -1_mm, -1_mm));
|
||||
|
||||
Geant::Scene scene;
|
||||
scene.ConstructWorldBox(world_box.GetSize(), "G4_AIR");
|
||||
scene.Initialize();
|
||||
// Geant::Scene scene;
|
||||
// scene.ConstructWorldBox(world_box.GetSize(), "G4_AIR");
|
||||
// scene.Initialize();
|
||||
|
||||
uLib::ObjectsContext globalContext;
|
||||
globalContext.AddObject(&world_box);
|
||||
globalContext.AddObject(&scene);
|
||||
// globalContext.AddObject(&world_box);
|
||||
// globalContext.AddObject(&scene);
|
||||
|
||||
// 2. Initialize MainWindow (contains embedded VTK QViewport)
|
||||
MainWindow window;
|
||||
|
||||
Reference in New Issue
Block a user