fixed vtk containerbox handler

This commit is contained in:
AndreaRigoni
2026-03-18 21:32:33 +00:00
parent 0e8ac47fcf
commit cca29ef837
16 changed files with 279 additions and 272 deletions

View File

@@ -1,7 +1,9 @@
#include "vtkViewport.h"
#include <vtkPropAssembly.h>
#include <vtkAssembly.h>
#include <vtkPropCollection.h>
#include <vtkProp3D.h>
#include <vtkProp3DCollection.h>
#include <vtkCamera.h>
#include <algorithm>
#include <vtkInteractorStyleTrackballCamera.h>
@@ -126,6 +128,19 @@ void Viewport::SetupPipeline(vtkRenderWindowInteractor* iren)
m_HandlerWidget->GetOverlayRenderer()->SetLayer(1);
}
// Observe InteractionEvent to update the selected puppet when the widget moves it
vtkNew<vtkCallbackCommand> widgetInteractionCallback;
widgetInteractionCallback->SetClientData(this);
widgetInteractionCallback->SetCallback([](vtkObject*, unsigned long, void* clientdata, void*){
auto* self = static_cast<Viewport*>(clientdata);
for (auto* p : self->m_Puppets) {
if (p->IsSelected()) {
p->Update();
}
}
});
m_HandlerWidget->AddObserver(vtkCommand::InteractionEvent, widgetInteractionCallback);
// Picking for selection
m_Picker = vtkSmartPointer<vtkCellPicker>::New();
vtkNew<vtkCallbackCommand> clickCallback;
@@ -145,10 +160,14 @@ void Viewport::SetupPipeline(vtkRenderWindowInteractor* iren)
target = p;
break;
}
auto* assembly = vtkPropAssembly::SafeDownCast(p->GetProp());
if (assembly) {
auto* propAssembly = vtkPropAssembly::SafeDownCast(p->GetProp());
auto* actorAssembly = vtkAssembly::SafeDownCast(p->GetProp());
vtkPropCollection* parts = nullptr;
if (propAssembly) parts = propAssembly->GetParts();
else if (actorAssembly) parts = actorAssembly->GetParts();
if (parts) {
bool found = false;
auto* parts = assembly->GetParts();
parts->InitTraversal();
for (int i=0; i<parts->GetNumberOfItems(); ++i) {
if (parts->GetNextProp() == picked) {