Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,13 +621,27 @@ py::object getForceField(Node *self, unsigned int index)

py::object getMechanicalState(Node *self)
{
sofa::core::behavior::BaseMechanicalState* state = self->mechanicalState.get();
if (self->mechanicalState.empty())
{
return py::none();
}
sofa::core::behavior::BaseMechanicalState* state = self->mechanicalState[0];
if (state) {
return PythonFactory::toPython(sofa::core::castToBase(state));
}
return py::none();
}

py::list getMechanicalStates(Node *self)
{
py::list states;
for (const auto& state : self->mechanicalState)
{
states.append(PythonFactory::toPython(sofa::core::castToBase(state)));
}
return states;
}


py::object hasIntegrationScheme(Node *self)
{
Expand Down Expand Up @@ -722,6 +736,7 @@ void moduleAddNode(py::module &m) {
p.def("hasIntegrationScheme", &hasIntegrationScheme, sofapython3::doc::sofa::core::Node::hasIntegrationScheme);
p.def("getForceField", &getForceField, sofapython3::doc::sofa::core::Node::getForceField);
p.def("getMechanicalState", &getMechanicalState, sofapython3::doc::sofa::core::Node::getMechanicalState);
p.def("getMechanicalStates", &getMechanicalStates, "Get the list of all the mechanical states of the node.");
p.def("getMechanicalMapping", &getMechanicalMapping, sofapython3::doc::sofa::core::Node::getMechanicalMapping);
p.def("sendEvent", &sendEvent, sofapython3::doc::sofa::core::Node::sendEvent);
p.def("computeEnergy", &computeEnergy, sofapython3::doc::sofa::core::Node::computeEnergy);
Expand Down
2 changes: 1 addition & 1 deletion bindings/Sofa/tests/Core/BaseLink.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_isMultiLink(self):
root = create_scene("root")
root.addObject("MechanicalObject", name="t")
link = root.findLink("mechanicalState")
self.assertFalse(link.isMultiLink())
self.assertTrue(link.isMultiLink())
root.addChild("aChild")
link = root.findLink("child")
self.assertTrue(link.isMultiLink())
Expand Down
Loading