Skip to content

Commit 70ece72

Browse files
authored
Merge branch 'master' into fix_multiconfig_build_sitepackages
2 parents 8ceadfc + 835d78d commit 70ece72

34 files changed

Lines changed: 4703 additions & 48 deletions

bindings/Sofa/package/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ def unloadModules():
195195
for name in toremove:
196196
del(sys.modules[name]) # unload it
197197

198+
def GetVersion():
199+
"""Returns the version of SOFA as a string in the format 'vMM.mm', where MM is the major version and mm is the
200+
minor version.
201+
"""
202+
return Sofa.Helper.GetVersion()
198203

199204
def formatStackForSofa(o):
200205
""" format the stack trace provided as a parameter into a string like that:

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ void moduleAddBaseMeshTopology(py::module& m) {
6565
c.def("getNbTriangles", &BaseMeshTopology::getNbTriangles);
6666
c.def("getNbTetrahedra", &BaseMeshTopology::getNbTetrahedra);
6767
c.def("getNbHexahedra", &BaseMeshTopology::getNbHexahedra);
68+
c.def("getNbPrisms", &BaseMeshTopology::getNbPrisms);
69+
c.def("getNbPyramids", &BaseMeshTopology::getNbPyramids);
6870
c.def("getNbQuads", &BaseMeshTopology::getNbQuads);
6971
c.def("getNbTetras", &BaseMeshTopology::getNbTetras);
7072

7173
c.def("getEdge",
72-
[] (BaseMeshTopology &self, const sofa::Index & index) -> std::array<sofa::Index, 2> {
74+
[] (BaseMeshTopology &self, const sofa::Index & index) -> std::array<sofa::Index, sofa::geometry::Edge::NumberOfNodes> {
7375
const auto & e = self.getEdge(index);
7476
return {{e[0], e[1]}};
7577
},
@@ -78,7 +80,7 @@ void moduleAddBaseMeshTopology(py::module& m) {
7880
);
7981

8082
c.def("getTriangle",
81-
[] (BaseMeshTopology &self, const sofa::Index & index) -> std::array<sofa::Index, 3> {
83+
[] (BaseMeshTopology &self, const sofa::Index & index) -> std::array<sofa::Index, sofa::geometry::Triangle::NumberOfNodes> {
8284
const auto & t = self.getTriangle(index);
8385
return {{t[0], t[1], t[2]}};
8486
},
@@ -87,7 +89,7 @@ void moduleAddBaseMeshTopology(py::module& m) {
8789
);
8890

8991
c.def("getQuad",
90-
[] (BaseMeshTopology &self, const sofa::Index & index) -> std::array<sofa::Index, 4> {
92+
[] (BaseMeshTopology &self, const sofa::Index & index) -> std::array<sofa::Index, sofa::geometry::Quad::NumberOfNodes> {
9193
const auto & q = self.getQuad(index);
9294
return {{q[0], q[1], q[2], q[3]}};
9395
},
@@ -96,7 +98,7 @@ void moduleAddBaseMeshTopology(py::module& m) {
9698
);
9799

98100
c.def("getTetrahedron",
99-
[] (BaseMeshTopology & self, const sofa::Index & index) -> std::array<sofa::Index, 4> {
101+
[] (BaseMeshTopology & self, const sofa::Index & index) -> std::array<sofa::Index, sofa::geometry::Tetrahedron::NumberOfNodes> {
100102
const auto & n = self.getTetrahedron(index);
101103
return {{n[0], n[1], n[2], n[3]}};
102104
},
@@ -105,14 +107,32 @@ void moduleAddBaseMeshTopology(py::module& m) {
105107
);
106108

107109
c.def("getHexahedron",
108-
[] (BaseMeshTopology & self, const sofa::Index & index) -> std::array<sofa::Index, 8> {
110+
[] (BaseMeshTopology & self, const sofa::Index & index) -> std::array<sofa::Index, sofa::geometry::Hexahedron::NumberOfNodes> {
109111
const auto & n = self.getHexahedron(index);
110112
return {{n[0], n[1], n[2], n[3], n[4], n[5], n[6], n[7]}};
111113
},
112114
py::arg("index"),
113115
"Returns the vertices of Hexahedron at index."
114116
);
115117

118+
c.def("getPrism",
119+
[] (BaseMeshTopology & self, const sofa::Index & index) -> std::array<sofa::Index, sofa::geometry::Prism::NumberOfNodes> {
120+
const auto & n = self.getPrism(index);
121+
return {{n[0], n[1], n[2], n[3], n[4], n[5]}};
122+
},
123+
py::arg("index"),
124+
"Returns the vertices of Prism at index."
125+
);
126+
127+
c.def("getPyramid",
128+
[] (BaseMeshTopology & self, const sofa::Index & index) -> std::array<sofa::Index, sofa::geometry::Pyramid::NumberOfNodes> {
129+
const auto & n = self.getPyramid(index);
130+
return {{n[0], n[1], n[2], n[3], n[4]}};
131+
},
132+
py::arg("index"),
133+
"Returns the vertices of Pyramid at index."
134+
);
135+
116136
c.def("getLocalEdgesInTetrahedron",
117137
[] (const BaseMeshTopology & self, const sofa::Index & index) -> std::array<sofa::Index, 2> {
118138
const auto & e = self.getLocalEdgesInTetrahedron(index);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/******************************************************************************
2+
* SofaPython3 plugin *
3+
* (c) 2021 CNRS, University of Lille, INRIA *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU Lesser General Public License as published by *
7+
* the Free Software Foundation; either version 2.1 of the License, or (at *
8+
* your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13+
* for more details. *
14+
* *
15+
* You should have received a copy of the GNU Lesser General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Contact information: contact@sofa-framework.org *
19+
******************************************************************************/
20+
21+
#include <pybind11/pybind11.h>
22+
23+
#include <SofaPython3/PythonFactory.h>
24+
#include <SofaPython3/Sofa/Helper/Binding_Version.h>
25+
26+
#include <iomanip>
27+
#include <sofa/version.h>
28+
29+
30+
/// Makes an alias for the pybind11 namespace to increase readability.
31+
namespace py { using namespace pybind11; }
32+
33+
namespace sofapython3
34+
{
35+
36+
void moduleAddVersion(py::module &m)
37+
{
38+
m.def("GetVersion",
39+
[]()
40+
{
41+
static const std::string sofaVersion = []() {
42+
std::stringstream version;
43+
constexpr auto major = SOFA_VERSION / 10000;
44+
constexpr auto minor = SOFA_VERSION / 100 % 100;
45+
version << 'v'
46+
<< std::setfill('0') << std::setw(2) << major
47+
<< "."
48+
<< std::setfill('0') << std::setw(2) << minor;
49+
return version.str();
50+
}();
51+
return sofaVersion;
52+
},
53+
"Returns the version of SOFA as a string in the format 'vMM.mm', where MM is the major version and mm is the minor version.");
54+
}
55+
56+
57+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/******************************************************************************
2+
* SofaPython3 plugin *
3+
* (c) 2021 CNRS, University of Lille, INRIA *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU Lesser General Public License as published by *
7+
* the Free Software Foundation; either version 2.1 of the License, or (at *
8+
* your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13+
* for more details. *
14+
* *
15+
* You should have received a copy of the GNU Lesser General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Contact information: contact@sofa-framework.org *
19+
******************************************************************************/
20+
21+
#pragma once
22+
23+
#include <pybind11/pybind11.h>
24+
25+
namespace sofapython3
26+
{
27+
28+
void moduleAddVersion(pybind11::module &m);
29+
30+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ project(Bindings.Sofa.Helper)
33
set(HEADER_FILES
44
${CMAKE_CURRENT_SOURCE_DIR}/Binding_Utils.h
55
${CMAKE_CURRENT_SOURCE_DIR}/Binding_Vector.h
6+
${CMAKE_CURRENT_SOURCE_DIR}/Binding_Version.h
67
${CMAKE_CURRENT_SOURCE_DIR}/System/Submodule_System.h
78
${CMAKE_CURRENT_SOURCE_DIR}/Binding_MessageHandler.h
89
${CMAKE_CURRENT_SOURCE_DIR}/System/Binding_FileRepository.h
@@ -13,6 +14,7 @@ set(SOURCE_FILES
1314
${CMAKE_CURRENT_SOURCE_DIR}/Binding_MessageHandler.cpp
1415
${CMAKE_CURRENT_SOURCE_DIR}/Binding_Utils.cpp
1516
${CMAKE_CURRENT_SOURCE_DIR}/Binding_Vector.cpp
17+
${CMAKE_CURRENT_SOURCE_DIR}/Binding_Version.cpp
1618
${CMAKE_CURRENT_SOURCE_DIR}/System/Submodule_System.cpp
1719
${CMAKE_CURRENT_SOURCE_DIR}/System/Binding_FileRepository.cpp
1820
)

bindings/Sofa/src/SofaPython3/Sofa/Helper/Submodule_Helper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <SofaPython3/Sofa/Helper/Binding_MessageHandler.h>
2727
#include <SofaPython3/Sofa/Helper/Binding_Vector.h>
2828
#include <SofaPython3/Sofa/Helper/Binding_Utils.h>
29+
#include <SofaPython3/Sofa/Helper/Binding_Version.h>
2930

3031
/// Makes an alias for the pybind11 namespace to increase readability.
3132
namespace py { using namespace pybind11; }
@@ -153,6 +154,7 @@ PYBIND11_MODULE(Helper, helper)
153154
moduleAddVector(helper);
154155
moduleAddSystem(helper);
155156
moduleAddUtils(helper);
157+
moduleAddVersion(helper);
156158

157159
auto atexit = py::module_::import("atexit");
158160
atexit.attr("register")(py::cpp_function([]() {

bindings/Sofa/src/SofaPython3/Sofa/Simulation/Binding_SceneCheck.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ namespace py { using namespace pybind11; }
2828

2929
void moduleAddSceneCheck(pybind11::module &m)
3030
{
31-
// create a python binding for the C++ class LinearSpring from SofaDeformable
3231
py::class_<sofa::simulation::SceneCheck, std::shared_ptr<sofa::simulation::SceneCheck>> s
3332
(m, "SceneCheck", sofapython3::doc::simulation::SceneCheckClass);
3433

bindings/Sofa/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ set(PYTHON_FILES
2222
${CMAKE_CURRENT_SOURCE_DIR}/Core/Mass.py
2323
${CMAKE_CURRENT_SOURCE_DIR}/Core/MyRestShapeForceField.py
2424
${CMAKE_CURRENT_SOURCE_DIR}/Helper/Message.py
25+
${CMAKE_CURRENT_SOURCE_DIR}/Helper/Version.py
2526
${CMAKE_CURRENT_SOURCE_DIR}/Simulation/Node.py
2627
${CMAKE_CURRENT_SOURCE_DIR}/Simulation/Simulation.py
2728
${CMAKE_CURRENT_SOURCE_DIR}/Types/BoundingBox.py
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Sofa
2+
import Sofa.Helper
3+
import unittest
4+
5+
class GetVersionTest(unittest.TestCase):
6+
"""
7+
Contains unit tests for verifying the existence and format of the `GetVersion` method
8+
in the `Sofa.Helper.Utils` module.
9+
10+
Includes tests to assert that the version is correctly formatted and meets the expected
11+
structure.
12+
"""
13+
def test_exist(self):
14+
self.assertTrue(hasattr(Sofa.Helper, "GetVersion"))
15+
16+
def test_version_format(self):
17+
version = Sofa.Helper.GetVersion()
18+
print(f"SOFA Version: {version}")
19+
self.assertTrue(version.startswith('v'))
20+
version = version.replace('v', '')
21+
self.assertTrue(version.count('.') == 1)
22+
major, minor = version.split('.')
23+
self.assertTrue(major.isdigit())
24+
self.assertTrue(minor.isdigit())
25+
self.assertEqual(len(major), 2)
26+
self.assertEqual(len(minor), 2)

bindings/SofaRuntime/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ project(Bindings.SofaRuntime)
22

33
set(SOURCE_FILES
44
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/SofaRuntime/Module_SofaRuntime.cpp
5+
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/SofaRuntime/PythonMessageHandler.cpp
56
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/SofaRuntime/Timer/Submodule_Timer.cpp
67
)
78

89
set(HEADER_FILES
10+
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/SofaRuntime/PythonMessageHandler.h
911
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/SofaRuntime/Timer/Submodule_Timer.h
1012
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/SofaRuntime/Timer/Submodule_Timer_doc.h
1113
)

0 commit comments

Comments
 (0)