Skip to content

Commit e6ce502

Browse files
committed
Merge branch 'master' into add_addLink
2 parents e3d83e9 + 8d789ed commit e6ce502

File tree

6 files changed

+48
-2
lines changed

6 files changed

+48
-2
lines changed

bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Base.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ along with sofaqtquick. If not, see <http://www.gnu.org/licenses/>.
2525
2626
********************************************************************/
2727

28-
2928
#include <pybind11/pybind11.h>
3029

3130
#include <pybind11/numpy.h>
@@ -405,6 +404,19 @@ std::string BindingBase::getPathName(Base& self)
405404
{
406405
return self.toBaseNode() ? self.toBaseNode()->getPathName() : self.toBaseObject()->getPathName();
407406
}
407+
408+
py::object BindingBase::setDataValues(Base& self, py::kwargs kwargs)
409+
{
410+
for(auto key : kwargs)
411+
{
412+
BaseData* d = self.findData(py::cast<std::string>(key.first));
413+
if(d!=nullptr)
414+
PythonFactory::fromPython(d, py::cast<py::object>(key.second));
415+
else
416+
throw py::attribute_error("There is no data field named: "+py::cast<std::string>(key.first));
417+
}
418+
return py::none();
419+
}
408420

409421
void moduleAddBase(py::module &m)
410422
{
@@ -441,6 +453,7 @@ void moduleAddBase(py::module &m)
441453
base.def("countLoggedMessages", &BindingBase::countLoggedMessages, sofapython3::doc::base::countLoggedMessages);
442454
base.def("clearLoggedMessages", &BindingBase::clearLoggedMessages, sofapython3::doc::base::clearLoggedMessages);
443455
base.def("getPathName", &BindingBase::getPathName);
456+
base.def("setDataValues", &BindingBase::setDataValues, sofapython3::doc::base::setDataValues);
444457
}
445458

446459
} /// namespace sofapython3

bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class BindingBase
6666
/// Set the data field value from the array.
6767
static void SetDataFromArray(BaseData* data, const py::array& value);
6868
static bool SetData(BaseData* data, pybind11::object value);
69+
static py::object setDataValues(Base& self, py::kwargs kwargs);
6970

7071
static py::list getDataFields(Base& self);
7172
static py::list getLinks(Base& self);

bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Base_doc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ static auto findData =
7070
:type name: string
7171
:return: the data field
7272
)";
73+
static auto setDataValues =
74+
R"(
75+
Set values for a the given data field, multiple pairs of args are allowed.
76+
)";
7377
static auto getDataFields =
7478
R"(
7579
Accessor to the vector containing all the fields of this object

bindings/Sofa/src/SofaPython3/Sofa/Simulation/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ SP3_add_python_module(
1818
MODULE_NAME Simulation
1919
SOURCES ${SOURCE_FILES}
2020
HEADERS ${HEADER_FILES}
21-
DEPENDS SofaHelper SofaCore SofaSimulationCore SofaSimulationGraph SofaBaseVisual
21+
DEPENDS SofaCore SofaSimulationCore SofaSimulationGraph SofaBaseVisual
2222
)

bindings/Sofa/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ set(PYTHON_FILES
2525
${CMAKE_CURRENT_SOURCE_DIR}/Types/Vec3.py
2626
${CMAKE_CURRENT_SOURCE_DIR}/Types/BoundingBox.py
2727
${CMAKE_CURRENT_SOURCE_DIR}/Simulation/Node.py
28+
${CMAKE_CURRENT_SOURCE_DIR}/Simulation/Simulation.py
2829
${CMAKE_CURRENT_SOURCE_DIR}/bench_datacontainer.py
2930
${CMAKE_CURRENT_SOURCE_DIR}/bench_node.py
3031
${CMAKE_CURRENT_SOURCE_DIR}/benchmark.py
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*
2+
import Sofa
3+
import unittest
4+
import Sofa.Core
5+
import Sofa.Types
6+
import Sofa.Simulation
7+
import tempfile
8+
9+
class Test(unittest.TestCase):
10+
def test_load(self):
11+
"""Create a scene and load it to validate the loading function"""
12+
scene="""
13+
<Node name="rootNode" dt="0.005" gravity="0 0 0">
14+
<Node name="child1">
15+
</Node>
16+
<Node name="child2">
17+
</Node>
18+
</Node>
19+
"""
20+
tf = tempfile.NamedTemporaryFile(mode="w+t", suffix=".scn")
21+
tf.file.write(scene)
22+
tf.file.flush()
23+
tt = open(tf.name)
24+
node = Sofa.Simulation.load(tf.name)
25+
self.assertNotEqual(node, None)
26+
self.assertEqual(node.name.value, "rootNode")
27+

0 commit comments

Comments
 (0)