Skip to content

Commit 4fe3969

Browse files
committed
Factorize implementation
1 parent 9971a15 commit 4fe3969

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

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

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,11 @@ void Component_Trampoline::_setattr_(pybind11::object self, const std::string& s
247247

248248

249249

250-
void moduleAddComponent(py::module &m) {
250+
void moduleAddBase(py::module &m, const std::string & name) {
251251
py::class_<Component,
252252
Component_Trampoline,
253253
BaseComponent,
254-
py_shared_ptr<Component>> f(m, "Component",
254+
py_shared_ptr<Component>> f(m, name.c_str(),
255255
py::dynamic_attr(),
256256
sofapython3::doc::controller::controllerClass);
257257

@@ -267,22 +267,10 @@ void moduleAddComponent(py::module &m) {
267267
}
268268

269269
void moduleAddController(py::module &m) {
270-
py::class_<Component,
271-
Component_Trampoline,
272-
BaseComponent,
273-
py_shared_ptr<Component>> f(m, "Controller",
274-
py::dynamic_attr(),
275-
sofapython3::doc::controller::controllerClass);
276-
277-
f.def(py::init(&Component_Trampoline::_init_));
278-
f.def("__setattr__",&Component_Trampoline::_setattr_);
279-
280-
f.def("init", &Component::init);
281-
f.def("reinit", &Component::reinit);
282-
f.def("draw", [](Component& self, sofa::core::visual::VisualParams* params){
283-
self.draw(params);
284-
}, pybind11::return_value_policy::reference);
285-
270+
moduleAddBase(m, "Controller");
271+
}
272+
void moduleAddComponent(py::module &m) {
273+
moduleAddBase(m, "Component");
286274
}
287275

288276

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class Component_Trampoline : public Component
8585
bool m_cacheInitialized = false;
8686
};
8787

88+
void moduleAddBase(pybind11::module &m, const std::string & name);
8889
void moduleAddComponent(pybind11::module &m);
8990
void moduleAddController(pybind11::module &m);
9091

0 commit comments

Comments
 (0)