refactor: rename Puppet class to Prop3D across the codebase

This commit is contained in:
AndreaRigoni
2026-04-08 15:47:33 +00:00
parent 77f00a2b8a
commit f7ba4b1a17
63 changed files with 412 additions and 413 deletions

View File

@@ -34,8 +34,8 @@ ObjectsContext::ObjectsContext(uLib::ObjectsContext *context)
}
ObjectsContext::~ObjectsContext() {
for (auto const& [obj, puppet] : m_Puppets) {
delete puppet;
for (auto const& [obj, prop3d] : m_Prop3Ds) {
delete prop3d;
}
m_Assembly->Delete();
}
@@ -48,31 +48,31 @@ void ObjectsContext::Synchronize() {
std::map<uLib::Object*, bool> currentObjects;
for (auto obj : objects) currentObjects[obj] = true;
// Remove puppets for objects no longer in context
for (auto it = m_Puppets.begin(); it != m_Puppets.end(); ) {
// Remove Prop3Ds for objects no longer in context
for (auto it = m_Prop3Ds.begin(); it != m_Prop3Ds.end(); ) {
if (currentObjects.find(it->first) == currentObjects.end()) {
it->second->DisconnectRenderer(nullptr); // If we have a ref to a renderer we should disconnect but Puppet doesn't store it easily
// Actually Puppet::DisconnectRenderer(vtkRenderer*) needs the renderer.
it->second->DisconnectRenderer(nullptr); // If we have a ref to a renderer we should disconnect but Prop3D doesn't store it easily
// Actually Prop3D::DisconnectRenderer(vtkRenderer*) needs the renderer.
// For now we just remove from assembly
if (auto* p3d = vtkProp3D::SafeDownCast(it->second->GetProp()))
m_Assembly->RemovePart(p3d);
this->PuppetRemoved(it->second);
this->Prop3DRemoved(it->second);
delete it->second;
it = m_Puppets.erase(it);
it = m_Prop3Ds.erase(it);
} else {
++it;
}
}
// Add puppets for new objects
// Add Prop3Ds for new objects
for (auto obj : objects) {
if (m_Puppets.find(obj) == m_Puppets.end()) {
Puppet* puppet = this->CreatePuppet(obj);
if (puppet) {
m_Puppets[obj] = puppet;
if (auto* p3d = vtkProp3D::SafeDownCast(puppet->GetProp()))
if (m_Prop3Ds.find(obj) == m_Prop3Ds.end()) {
Prop3D* prop3d = this->CreateProp3D(obj);
if (prop3d) {
m_Prop3Ds[obj] = prop3d;
if (auto* p3d = vtkProp3D::SafeDownCast(prop3d->GetProp()))
m_Assembly->AddPart(p3d);
this->PuppetAdded(puppet);
this->Prop3DAdded(prop3d);
}
}
}
@@ -80,50 +80,50 @@ void ObjectsContext::Synchronize() {
void ObjectsContext::OnObjectAdded(uLib::Object* obj) {
if (!obj) return;
if (m_Puppets.find(obj) == m_Puppets.end()) {
Puppet* puppet = this->CreatePuppet(obj);
if (puppet) {
m_Puppets[obj] = puppet;
if (auto* p3d = vtkProp3D::SafeDownCast(puppet->GetProp()))
if (m_Prop3Ds.find(obj) == m_Prop3Ds.end()) {
Prop3D* prop3d = this->CreateProp3D(obj);
if (prop3d) {
m_Prop3Ds[obj] = prop3d;
if (auto* p3d = vtkProp3D::SafeDownCast(prop3d->GetProp()))
m_Assembly->AddPart(p3d);
this->PuppetAdded(puppet);
this->Prop3DAdded(prop3d);
}
}
}
void ObjectsContext::OnObjectRemoved(uLib::Object* obj) {
if (!obj) return;
auto it = m_Puppets.find(obj);
if (it != m_Puppets.end()) {
auto it = m_Prop3Ds.find(obj);
if (it != m_Prop3Ds.end()) {
// For now we just remove from assembly.
// Puppet::DisconnectRenderer(vtkRenderer*) needs the renderer, but we don't have it here easily.
// Prop3D::DisconnectRenderer(vtkRenderer*) needs the renderer, but we don't have it here easily.
if (auto* p3d = vtkProp3D::SafeDownCast(it->second->GetProp()))
m_Assembly->RemovePart(p3d);
this->PuppetRemoved(it->second);
this->Prop3DRemoved(it->second);
delete it->second;
m_Puppets.erase(it);
m_Prop3Ds.erase(it);
}
}
Puppet* ObjectsContext::GetPuppet(uLib::Object* obj) {
auto it = m_Puppets.find(obj);
if (it != m_Puppets.end()) return it->second;
Prop3D* ObjectsContext::GetProp3D(uLib::Object* obj) {
auto it = m_Prop3Ds.find(obj);
if (it != m_Prop3Ds.end()) return it->second;
return nullptr;
}
void ObjectsContext::Update() {
for (auto const& [obj, puppet] : m_Puppets) {
puppet->Update();
for (auto const& [obj, prop3d] : m_Prop3Ds) {
prop3d->Update();
}
}
void ObjectsContext::SyncFromVtk() {
for (auto const& [obj, puppet] : m_Puppets) {
puppet->SyncFromVtk();
for (auto const& [obj, prop3d] : m_Prop3Ds) {
prop3d->SyncFromVtk();
}
}
Puppet* ObjectsContext::CreatePuppet(uLib::Object* obj) {
Prop3D* ObjectsContext::CreateProp3D(uLib::Object* obj) {
if (!obj) return nullptr;
if (auto* vox = dynamic_cast<uLib::Abstract::VoxImage*>(obj)) {
@@ -148,12 +148,12 @@ Puppet* ObjectsContext::CreatePuppet(uLib::Object* obj) {
return nullptr;
}
void ObjectsContext::PuppetAdded(Puppet* puppet) {
ULIB_SIGNAL_EMIT(ObjectsContext::PuppetAdded, puppet);
void ObjectsContext::Prop3DAdded(Prop3D* prop3d) {
ULIB_SIGNAL_EMIT(ObjectsContext::Prop3DAdded, prop3d);
}
void ObjectsContext::PuppetRemoved(Puppet* puppet) {
ULIB_SIGNAL_EMIT(ObjectsContext::PuppetRemoved, puppet);
void ObjectsContext::Prop3DRemoved(Prop3D* prop3d) {
ULIB_SIGNAL_EMIT(ObjectsContext::Prop3DRemoved, prop3d);
}
} // namespace Vtk