Skip to content

Commit 9514a08

Browse files
Remove Sofa.Components (#456)
* Remove Sofa.Components. I suspect this code to have been integrated in the SofaPython3 by mistake and to have never worked. By looking at it it may be an experiment to allow syntax like this import Sofa.Components Sofa.Components.MechanicalObject() ... * Example on how to fix pybind11 type forward declaration so stubgens knows about them. The problem: Depending on the definition order of the binded classes, there may have incorrect types if Base is useing BaseData... but BaseData is only binded after Base. The PR propose a solution for that using a decidcated "forward" registration patter. * Update tests to take into account removal of Sofa.Components. * FIXUP
1 parent e858992 commit 9514a08

File tree

16 files changed

+36
-216
lines changed

16 files changed

+36
-216
lines changed

bindings/Modules/tests/SofaConstraintSolver/matrix_access.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import unittest
22
import Sofa.Core
3-
import Sofa.Components
43
from Sofa import SofaConstraintSolver
54

65
class Test(unittest.TestCase):

bindings/Modules/tests/SofaLinearSolver/matrix_access.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import unittest
22
import Sofa.Core
3-
import Sofa.Components
43
from Sofa import SofaLinearSolver
54

65
class Test(unittest.TestCase):

bindings/Sofa/Bindings.SofaConfig.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ find_package(SofaPython3 QUIET REQUIRED COMPONENTS Plugin)
88
# Required by Bindings.Sofa.Helper, Bindings.Sofa.Types
99
find_package(Sofa.Core QUIET REQUIRED)
1010

11-
# Required by Bindings.Sofa.Core, Bindings.Sofa.Components
11+
# Required by Bindings.Sofa.Core
1212
find_package(Sofa.Simulation.Core QUIET REQUIRED)
1313

1414
# Required by Bindings.Sofa.Core

bindings/Sofa/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
project(Bindings.Sofa)
22

33
set(SOFABINDINGS_MODULE_LIST
4-
Components
54
Core
65
Helper
76
Simulation

bindings/Sofa/package/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@
161161
import Sofa.Core
162162
import Sofa.Simulation
163163
import Sofa.Types
164-
import Sofa.Components
165164
import SofaTypes
166165

167166
from .prefab import *

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

Lines changed: 0 additions & 21 deletions
This file was deleted.

bindings/Sofa/src/SofaPython3/Sofa/Components/Submodule_Components.cpp

Lines changed: 0 additions & 142 deletions
This file was deleted.

bindings/Sofa/src/SofaPython3/Sofa/Components/Submodule_Components.h

Lines changed: 0 additions & 30 deletions
This file was deleted.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ using sofa::helper::WriteOnlyAccessor;
3434

3535
#include <SofaPython3/PythonFactory.h>
3636

37+
#include <SofaPython3/Sofa/Core/Binding_BaseData.h>
38+
#include <SofaPython3/Sofa/Core/Binding_BaseLink.h>
3739
#include <SofaPython3/Sofa/Core/Binding_LinkPath.h>
3840
#include <SofaPython3/Sofa/Core/Binding_Base.h>
3941
#include <SofaPython3/Sofa/Core/Binding_Base_doc.h>
@@ -449,6 +451,9 @@ py::object BindingBase::setDataValues(Base& self, py::kwargs kwargs)
449451

450452
void moduleAddBase(py::module &m)
451453
{
454+
moduleForwardAddBaseData(m);
455+
moduleForwardAddBaseLink(m);
456+
452457
py::class_<Base, py_shared_ptr<Base>> base(m, "Base", py::dynamic_attr(), doc::base::BaseClass);
453458
/// set & get the name as string. The alternative is to access the data field using
454459
/// obj.name.value = "aName"

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,24 @@ std::string getValueTypeString(BaseData* data)
192192
return data->getValueTypeInfo()->name();
193193
}
194194

195+
auto getPythonClassForBaseData(py::module& m)
196+
{
197+
/// Register the BaseData binding into the pybind11 system.
198+
static py::class_<BaseData, std::unique_ptr<sofa::core::objectmodel::BaseData, pybind11::nodelete>> data(m, "Data", sofapython3::doc::baseData::BaseDataClass);
199+
return data;
200+
}
201+
202+
void moduleForwardAddBaseData(py::module& m)
203+
{
204+
getPythonClassForBaseData(m);
205+
}
206+
195207
void moduleAddBaseData(py::module& m)
196208
{
197209
/// Register the BaseData binding into the pybind11 system.
198-
py::class_<BaseData, std::unique_ptr<sofa::core::objectmodel::BaseData, pybind11::nodelete>> data(m, "Data", sofapython3::doc::baseData::BaseDataClass);
210+
//py::class_<BaseData, std::unique_ptr<sofa::core::objectmodel::BaseData, pybind11::nodelete>> data(m, "Data", sofapython3::doc::baseData::BaseDataClass);
211+
212+
auto data =getPythonClassForBaseData(m);
199213
data.def("getName", [](BaseData& b){ return b.getName(); }, sofapython3::doc::baseData::getName);
200214
data.def("setName", [](BaseData& b, const std::string& s){ b.setName(s); }, sofapython3::doc::baseData::setName);
201215
data.def("getCounter", [](BaseData& self) { return self.getCounter(); }, sofapython3::doc::baseData::getCounter);

0 commit comments

Comments
 (0)