Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing call to super init in Constraint class + component state …
Browse files Browse the repository at this point in the history
…setting
bakpaul authored and fredroy committed Apr 30, 2024
1 parent 30d2e52 commit a134fc0
Showing 4 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -39,18 +39,7 @@ FixedLagrangianConstraint<DataTypes>::FixedLagrangianConstraint(MechanicalState*
template<class DataTypes>
void FixedLagrangianConstraint<DataTypes>::init()
{

Inherit1::init();

if(this->mstate.get())
{
this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Valid);
}
else
{
msg_error(this)<<"Data \'mstate\' not specified, unable to find a compatible mechanical state in the current context";
this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid);
}
}


2 changes: 2 additions & 0 deletions Sofa/framework/Core/src/sofa/core/behavior/Constraint.h
Original file line number Diff line number Diff line change
@@ -59,6 +59,8 @@ class Constraint : public BaseConstraint, public SingleStateAccessor<DataTypes>
Constraint(MechanicalState<DataTypes> *mm = nullptr);

~Constraint() override;

virtual void init() override;
public:
Data<Real> endTime; ///< Time when the constraint becomes inactive (-1 for infinitely active)
virtual bool isActive() const; ///< if false, the constraint does nothing
7 changes: 7 additions & 0 deletions Sofa/framework/Core/src/sofa/core/behavior/Constraint.inl
Original file line number Diff line number Diff line change
@@ -47,6 +47,13 @@ bool Constraint<DataTypes>::isActive() const
return endTime.getValue()>getContext()->getTime();
}

template <class DataTypes>
void Constraint<DataTypes>::init()
{
Inherit1::init();
Inherit2::init();
}

template<class DataTypes>
void Constraint<DataTypes>::getConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v)
{
Original file line number Diff line number Diff line change
@@ -41,13 +41,16 @@ class SingleStateAccessor : public virtual StateAccessor
{
Inherit1::init();

d_componentState.setValue(sofa::core::objectmodel::ComponentState::Valid);

if (!mstate.get())
{
mstate.set(dynamic_cast< MechanicalState<DataTypes>* >(getContext()->getMechanicalState()));

msg_error_when(!mstate) << "No compatible MechanicalState found in the current context. "
"This may be because there is no MechanicalState in the local context, "
"or because the type is not compatible.";
d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid);
}

l_mechanicalStates.clear();

0 comments on commit a134fc0

Please sign in to comment.