Skip to content

Commit 35f8089

Browse files
committed
use TopologyAccessor in DiagonalMass
1 parent ebccfb1 commit 35f8089

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,17 @@
2121
******************************************************************************/
2222
#pragma once
2323

24+
#include <sofa/component/mass/RigidMassType.h>
25+
#include <sofa/component/mass/VecMassType.h>
2426
#include <sofa/component/mass/config.h>
25-
26-
#include <sofa/type/vector.h>
27-
#include <sofa/type/Vec.h>
28-
#include <sofa/defaulttype/VecTypes.h>
29-
#include <sofa/defaulttype/RigidTypes.h>
3027
#include <sofa/core/behavior/Mass.h>
31-
#include <sofa/core/topology/TopologyData.h>
28+
#include <sofa/core/behavior/TopologyAccessor.h>
3229
#include <sofa/core/objectmodel/DataFileName.h>
33-
34-
#include <sofa/component/mass/VecMassType.h>
35-
#include <sofa/component/mass/RigidMassType.h>
30+
#include <sofa/core/topology/TopologyData.h>
31+
#include <sofa/defaulttype/RigidTypes.h>
32+
#include <sofa/defaulttype/VecTypes.h>
33+
#include <sofa/type/Vec.h>
34+
#include <sofa/type/vector.h>
3635

3736
#include <type_traits>
3837

@@ -60,10 +59,10 @@ public :
6059
* @tparam GeometricalTypes type of the geometry, i.e type of the state associated with the topology (if the topology and the mass relates to the same state, this will be the same as DataTypes)
6160
*/
6261
template <class DataTypes, class GeometricalTypes = DataTypes>
63-
class DiagonalMass : public core::behavior::Mass<DataTypes>
62+
class DiagonalMass : public core::behavior::Mass<DataTypes>, public virtual sofa::core::behavior::TopologyAccessor
6463
{
6564
public:
66-
SOFA_CLASS(SOFA_TEMPLATE2(DiagonalMass,DataTypes, GeometricalTypes), SOFA_TEMPLATE(core::behavior::Mass,DataTypes));
65+
SOFA_CLASS2(SOFA_TEMPLATE2(DiagonalMass,DataTypes, GeometricalTypes), SOFA_TEMPLATE(core::behavior::Mass,DataTypes), sofa::core::behavior::TopologyAccessor);
6766

6867
using TMassType = typename sofa::component::mass::MassType<DataTypes>::type;
6968

@@ -113,8 +112,6 @@ class DiagonalMass : public core::behavior::Mass<DataTypes>
113112
/// value defining the initialization process of the mass (0 : totalMass, 1 : massDensity, 2 : vertexMass)
114113
int m_initializationProcess;
115114

116-
/// Link to be set to the topology container in the component graph.
117-
SingleLink<DiagonalMass<DataTypes, GeometricalTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology;
118115
/// Link to be set to the MechanicalObject associated with the geometry
119116
SingleLink<DiagonalMass<DataTypes, GeometricalTypes>, sofa::core::behavior::MechanicalState<GeometricalTypes>, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_geometryState;
120117

Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ DiagonalMass<DataTypes, GeometricalTypes>::DiagonalMass()
5050
, d_showCenterOfGravity( initData(&d_showCenterOfGravity, false, "showGravityCenter", "Display the center of gravity of the system" ) )
5151
, d_showAxisSize( initData(&d_showAxisSize, 1.0f, "showAxisSizeFactor", "Factor length of the axis displayed (only used for rigids)" ) )
5252
, d_fileMass( initData(&d_fileMass, "filename", "Xsp3.0 file to specify the mass parameters" ) )
53-
, l_topology(initLink("topology", "link to the topology container"))
5453
, l_geometryState(initLink("geometryState", "link to the MechanicalObject associated with the geometry"))
5554
, m_massTopologyType(sofa::geometry::ElementType::UNKNOWN)
5655
{
@@ -756,22 +755,9 @@ void DiagonalMass<DataTypes, GeometricalTypes>::initTopologyHandlers()
756755
template <class DataTypes, class GeometricalTypes>
757756
bool DiagonalMass<DataTypes, GeometricalTypes>::checkTopology()
758757
{
759-
if (l_topology.empty())
760-
{
761-
msg_info() << "Link \"topology\" to the Topology container should be set to ensure right behavior. First Topology found in current context will be used.";
762-
l_topology.set(this->getContext()->getMeshTopologyLink());
763-
}
764-
765-
if (l_topology.get() == nullptr)
766-
{
767-
msg_error() << "No topology component found at path: " << l_topology.getLinkedPath() << ", nor in current context: " << this->getContext()->name;
768-
sofa::core::objectmodel::BaseObject::d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid);
758+
this->validateTopology();
759+
if (this->isComponentStateInvalid())
769760
return false;
770-
}
771-
else
772-
{
773-
msg_info() << "Topology path used: '" << l_topology.getLinkedPath() << "'";
774-
}
775761

776762
if (l_geometryState.empty())
777763
{

0 commit comments

Comments
 (0)