From f73cf6b3ac1b5ec68599e07fc3f4b73ff6161f37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan?= Date: Fri, 20 Feb 2026 18:54:32 +0100 Subject: [PATCH] ADD: explicit link alternative to mecaObj --- .../TetrahedronDiffusionFEMForceField.h | 1 + .../TetrahedronDiffusionFEMForceField.inl | 28 +++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Sofa/Component/Diffusion/src/sofa/component/diffusion/TetrahedronDiffusionFEMForceField.h b/Sofa/Component/Diffusion/src/sofa/component/diffusion/TetrahedronDiffusionFEMForceField.h index 7b2afa1a710..dfa29262eb2 100644 --- a/Sofa/Component/Diffusion/src/sofa/component/diffusion/TetrahedronDiffusionFEMForceField.h +++ b/Sofa/Component/Diffusion/src/sofa/component/diffusion/TetrahedronDiffusionFEMForceField.h @@ -114,6 +114,7 @@ class TetrahedronDiffusionFEMForceField : public core::behavior::ForceField, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology; + SingleLink, MechObject, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_mecaObj; protected: diff --git a/Sofa/Component/Diffusion/src/sofa/component/diffusion/TetrahedronDiffusionFEMForceField.inl b/Sofa/Component/Diffusion/src/sofa/component/diffusion/TetrahedronDiffusionFEMForceField.inl index 341bbb7c0f3..39360bfc9bb 100644 --- a/Sofa/Component/Diffusion/src/sofa/component/diffusion/TetrahedronDiffusionFEMForceField.inl +++ b/Sofa/Component/Diffusion/src/sofa/component/diffusion/TetrahedronDiffusionFEMForceField.inl @@ -128,6 +128,7 @@ TetrahedronDiffusionFEMForceField::TetrahedronDiffusionFEMForceField( d_tagMeshMechanics(initData(&d_tagMeshMechanics, std::string("meca"),"tagMechanics","Tag of the Mechanical Object.")), d_drawConduc( initData(&d_drawConduc, (bool)false, "drawConduc","To display conductivity map.")) , l_topology(initLink("topology", "link to the topology container")) + , l_mecaObj(initLink("mecaObj", "link to the 3D mechanical MechanicalObject")) , m_topology(nullptr) { this->f_listening.setValue(true); @@ -198,12 +199,29 @@ void TetrahedronDiffusionFEMForceField::init() } /// Get the mechanical object containing the mesh position in 3D - core::objectmodel::Tag mechanicalTag(d_tagMeshMechanics.getValue()); - this->getContext()->get(mechanicalObject, mechanicalTag,sofa::core::objectmodel::BaseContext::SearchUp); - if (mechanicalObject==nullptr) + /// Priority is the explicit link, with a fallback to historical tag-based lookup. + if (!l_mecaObj.empty()) { - msg_error() << "cannot find the mechanical object named '" << mechanicalObject << msgendl; - return; + mechanicalObject = l_mecaObj.get(); + if (mechanicalObject == nullptr) + { + msg_error() << "No MechanicalState found at mecaObj link path '" << l_mecaObj.getLinkedPath() << "'."; + this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid); + return; + } + } + else + { + core::objectmodel::Tag mechanicalTag(d_tagMeshMechanics.getValue()); + this->getContext()->get(mechanicalObject, mechanicalTag, sofa::core::objectmodel::BaseContext::SearchUp); + if (mechanicalObject == nullptr) + { + msg_error() << "No MechanicalState found. Set 'mecaObj' link, or provide a valid 'tagMechanics' (current value: '" + << d_tagMeshMechanics.getValue() << "')."; + this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid); + return; + } + msg_info() << "Using legacy tagMechanics lookup to find MechanicalState with tag '" << d_tagMeshMechanics.getValue() << "'."; } if(d_transverseAnisotropyRatio.getValue()!=1.0)