Skip to content

Commit ada5769

Browse files
authored
Renamed BAseObject to BaseComponent and use the right class name (#601)
1 parent dee06b8 commit ada5769

File tree

8 files changed

+88
-85
lines changed

8 files changed

+88
-85
lines changed

bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_BaseObject.cpp renamed to bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_BaseComponent.cpp

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
******************************************************************************/
2020

2121
#include <SofaPython3/Sofa/Core/Binding_Base.h>
22-
#include <SofaPython3/Sofa/Core/Binding_BaseObject.h>
23-
#include <SofaPython3/Sofa/Core/Binding_BaseObject_doc.h>
22+
#include <SofaPython3/Sofa/Core/Binding_BaseComponent.h>
23+
#include <SofaPython3/Sofa/Core/Binding_BaseComponent_doc.h>
2424
#include <SofaPython3/Sofa/Core/Binding_Controller.h>
2525
#include <SofaPython3/PythonFactory.h>
2626

@@ -61,11 +61,11 @@ namespace py { using namespace pybind11; }
6161

6262
using sofa::core::objectmodel::BaseData;
6363
using sofa::core::objectmodel::Base;
64-
using sofa::core::objectmodel::BaseObject;
64+
using sofa::core::objectmodel::BaseComponent;
6565

6666
namespace sofapython3
6767
{
68-
py::object getItem(const BaseObject& self, const std::string& path)
68+
py::object getItem(const BaseComponent& self, const std::string& path)
6969
{
7070
if (path.empty())
7171
return py::cast(self);
@@ -79,27 +79,27 @@ py::object getItem(const BaseObject& self, const std::string& path)
7979
throw py::value_error("Invalid syntax"); // should never get there
8080
}
8181

82-
std::string getLinkPath(const BaseObject *self)
82+
std::string getLinkPath(const BaseComponent *self)
8383
{
8484
return std::string("@")+self->getPathName();
8585
}
8686

87-
void computeBBox(BaseObject *self)
87+
void computeBBox(BaseComponent *self)
8888
{
8989
self->computeBBox(sofa::core::execparams::defaultInstance(), false);
9090
}
9191

92-
py::list getSlaves(BaseObject &self)
92+
py::list getSlaves(BaseComponent &self)
9393
{
94-
const BaseObject::VecSlaves& slaves = self.getSlaves();
94+
const BaseComponent::VecSlaves& slaves = self.getSlaves();
9595
py::list slaveList;
9696
for (auto slave : slaves){
9797
slaveList.append(py::cast(slave));
9898
}
9999
return slaveList;
100100
}
101101

102-
py::object getContext(const BaseObject &self)
102+
py::object getContext(const BaseComponent &self)
103103
{
104104
const sofa::core::objectmodel::BaseContext* context = self.getContext();
105105
if (context){
@@ -108,16 +108,16 @@ py::object getContext(const BaseObject &self)
108108
return py::none();
109109
}
110110

111-
py::object getMaster(const BaseObject &self)
111+
py::object getMaster(const BaseComponent &self)
112112
{
113-
const BaseObject* master = self.getMaster();
113+
const BaseComponent* master = self.getMaster();
114114
if (master){
115115
return py::cast(master);
116116
}
117117
return py::none();
118118
}
119119

120-
py::object getTarget(BaseObject *self)
120+
py::object getTarget(BaseComponent *self)
121121
{
122122
if (!self)
123123
return py::none();
@@ -133,7 +133,7 @@ py::object getTarget(BaseObject *self)
133133
return py::none() ;
134134
}
135135

136-
py::object getCategories(BaseObject *self)
136+
py::object getCategories(BaseComponent *self)
137137
{
138138
std::vector<std::string> categories;
139139
const sofa::core::objectmodel::BaseClass* c=self->getClass();
@@ -142,12 +142,12 @@ py::object getCategories(BaseObject *self)
142142
return std::move(l);
143143
}
144144

145-
std::string getAsACreateObjectParameter(BaseObject *self)
145+
std::string getAsACreateObjectParameter(BaseComponent *self)
146146
{
147147
return getLinkPath(self);
148148
}
149149

150-
void setSrc(BaseObject &self, char *valueString, BaseObject *loader)
150+
void setSrc(BaseComponent &self, char *valueString, BaseComponent *loader)
151151
{
152152
self.setSrc(valueString,loader);
153153
}
@@ -166,7 +166,7 @@ void setSrc(BaseObject &self, char *valueString, BaseObject *loader)
166166
/// In the example above, node1 and node2 can be inferred as being nodes without performing any checks.
167167
/// object1 can be a node or an object, but cannot be a datafield nor a link
168168
/// value can be a node or an object (if object1 is a node), or must be a data (if object1 is an object)
169-
py::object __getitem__(BaseObject &self, std::string s)
169+
py::object __getitem__(BaseComponent &self, std::string s)
170170
{
171171
if (s[0] == '.')
172172
s.erase(s.begin());
@@ -189,49 +189,49 @@ py::object __getitem__(BaseObject &self, std::string s)
189189
return getItem(self, s);
190190
}
191191

192-
auto getBaseObjectBinding(py::module& m)
192+
auto getBaseComponentBinding(py::module& m)
193193
{
194-
/// Register the BaseObject binding into the pybind11 typing system
195-
static py::class_<BaseObject, Base, py_shared_ptr<BaseObject>>p(m, "Object", sofapython3::doc::baseObject::Class);
194+
/// Register the BaseComponent binding into the pybind11 typing system
195+
static py::class_<BaseComponent, Base, py_shared_ptr<BaseComponent>>p(m, "Object", sofapython3::doc::BaseComponent::Class);
196196
return p;
197197
}
198198

199-
void moduleForwardAddBaseObject(py::module& m)
199+
void moduleForwardAddBaseComponent(py::module& m)
200200
{
201-
getBaseObjectBinding(m);
201+
getBaseComponentBinding(m);
202202
}
203203

204-
void moduleAddBaseObject(py::module& m)
204+
void moduleAddBaseComponent(py::module& m)
205205
{
206-
auto p = getBaseObjectBinding(m);
206+
auto p = getBaseComponentBinding(m);
207207

208-
/// Register the BaseObject binding into the downcasting subsystem
209-
PythonFactory::registerType<sofa::core::objectmodel::BaseObject>(
208+
/// Register the BaseComponent binding into the downcasting subsystem
209+
PythonFactory::registerType<sofa::core::objectmodel::BaseComponent>(
210210
[](sofa::core::objectmodel::Base* object)
211211
{
212-
return py::cast(py_shared_ptr<sofa::core::objectmodel::BaseObject>(object->toBaseObject()));
212+
return py::cast(py_shared_ptr<sofa::core::objectmodel::BaseComponent>(object->toBaseComponent()));
213213
});
214214

215-
p.def("init", &BaseObject::init, sofapython3::doc::baseObject::init);
216-
p.def("reinit", &BaseObject::reinit, sofapython3::doc::baseObject::reinit);
217-
p.def("getPathName", &BaseObject::getPathName, sofapython3::doc::baseObject::getPathName);
218-
p.def("getLinkPath", [](const BaseObject &self){ return std::string("@") + self.getPathName(); }, sofapython3::doc::baseObject::getLink);
219-
p.def("getSlaves", getSlaves, sofapython3::doc::baseObject::getSlaves);
220-
p.def("getContext", getContext, sofapython3::doc::baseObject::getContext);
221-
p.def("getMaster", getMaster, sofapython3::doc::baseObject::getMaster);
222-
p.def("addSlave", &BaseObject::addSlave, sofapython3::doc::baseObject::addSlave);
223-
p.def("storeResetState", &BaseObject::storeResetState, sofapython3::doc::baseObject::storeResetState);
224-
p.def("reset", &BaseObject::reset, sofapython3::doc::baseObject::reset);
225-
p.def("getTarget", getTarget, sofapython3::doc::baseObject::getTarget);
226-
p.def("getCategories", getCategories, sofapython3::doc::baseObject::getCategories);
227-
p.def("bwdInit", &BaseObject::bwdInit, sofapython3::doc::baseObject::bwdInit);
228-
p.def("cleanup", &BaseObject::cleanup, sofapython3::doc::baseObject::cleanup);
229-
p.def("computeBBox", &computeBBox, sofapython3::doc::baseObject::computeBBox);
230-
p.def("getLinkPath", &getLinkPath, sofapython3::doc::baseObject::getLinkPath);
231-
p.def("getAsACreateObjectParameter", getAsACreateObjectParameter, sofapython3::doc::baseObject::getAsACreateObjectParameter);
232-
p.def("setSrc", setSrc, sofapython3::doc::baseObject::setSrc);
233-
p.def("computeBBox", &BaseObject::computeBBox, sofapython3::doc::baseObject::computeBBox);
234-
p.def("__getitem__", __getitem__, sofapython3::doc::baseObject::__getitem__);
215+
p.def("init", &BaseComponent::init, sofapython3::doc::BaseComponent::init);
216+
p.def("reinit", &BaseComponent::reinit, sofapython3::doc::BaseComponent::reinit);
217+
p.def("getPathName", &BaseComponent::getPathName, sofapython3::doc::BaseComponent::getPathName);
218+
p.def("getLinkPath", [](const BaseComponent &self){ return std::string("@") + self.getPathName(); }, sofapython3::doc::BaseComponent::getLink);
219+
p.def("getSlaves", getSlaves, sofapython3::doc::BaseComponent::getSlaves);
220+
p.def("getContext", getContext, sofapython3::doc::BaseComponent::getContext);
221+
p.def("getMaster", getMaster, sofapython3::doc::BaseComponent::getMaster);
222+
p.def("addSlave", &BaseComponent::addSlave, sofapython3::doc::BaseComponent::addSlave);
223+
p.def("storeResetState", &BaseComponent::storeResetState, sofapython3::doc::BaseComponent::storeResetState);
224+
p.def("reset", &BaseComponent::reset, sofapython3::doc::BaseComponent::reset);
225+
p.def("getTarget", getTarget, sofapython3::doc::BaseComponent::getTarget);
226+
p.def("getCategories", getCategories, sofapython3::doc::BaseComponent::getCategories);
227+
p.def("bwdInit", &BaseComponent::bwdInit, sofapython3::doc::BaseComponent::bwdInit);
228+
p.def("cleanup", &BaseComponent::cleanup, sofapython3::doc::BaseComponent::cleanup);
229+
p.def("computeBBox", &computeBBox, sofapython3::doc::BaseComponent::computeBBox);
230+
p.def("getLinkPath", &getLinkPath, sofapython3::doc::BaseComponent::getLinkPath);
231+
p.def("getAsACreateObjectParameter", getAsACreateObjectParameter, sofapython3::doc::BaseComponent::getAsACreateObjectParameter);
232+
p.def("setSrc", setSrc, sofapython3::doc::BaseComponent::setSrc);
233+
p.def("computeBBox", &BaseComponent::computeBBox, sofapython3::doc::BaseComponent::computeBBox);
234+
p.def("__getitem__", __getitem__, sofapython3::doc::BaseComponent::__getitem__);
235235
}
236236

237237
} /// namespace sofapython3

bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_BaseObject.h renamed to bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_BaseComponent.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
namespace sofapython3
2727
{
2828

29-
pybind11::object getItem(const sofa::core::objectmodel::BaseObject & self, const std::string& path);
29+
pybind11::object getItem(const sofa::core::objectmodel::BaseComponent & self, const std::string& path);
3030

31-
void moduleForwardAddBaseObject(pybind11::module &m);
32-
void moduleAddBaseObject(pybind11::module &m);
31+
void moduleForwardAddBaseComponent(pybind11::module &m);
32+
void moduleAddBaseComponent(pybind11::module &m);
3333

3434
} /// namespace sofapython
3535

bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_BaseObject_doc.h renamed to bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_BaseComponent_doc.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#pragma once
2222

23-
namespace sofapython3::doc::baseObject
23+
namespace sofapython3::doc::BaseComponent
2424
{
2525
static auto Class =
2626
R"(
@@ -61,41 +61,41 @@ static auto reinit =
6161
)";
6262
static auto getPathName =
6363
R"(
64-
Return the full path name of this baseObject
64+
Return the full path name of this BaseComponent
6565
:rtype: string
6666
)";
6767

6868
static auto getLink =
6969
R"(
70-
Return the link of the baseObject
71-
:param self: the baseObject itself
72-
:type self: baseObject
70+
Return the link of the BaseComponent
71+
:param self: the BaseComponent itself
72+
:type self: BaseComponent
7373
:rtype: string
7474
)";
7575

7676
static auto getSlaves =
7777
R"(
78-
Return the slaves of the baseObject.
78+
Return the slaves of the BaseComponent.
7979
:rtype: list
8080
)";
8181

8282
static auto getContext =
8383
R"(
84-
Return the conext of the baseObject.
84+
Return the conext of the BaseComponent.
8585
:rtype: BaseContext
8686
)";
8787

8888
static auto getMaster =
8989
R"(
90-
Return the master of the baseObject.
91-
:rtype: BaseObject
90+
Return the master of the BaseComponent.
91+
:rtype: BaseComponent
9292
)";
9393

9494
static auto addSlave =
9595
R"(
96-
Add a slave to the master BaseObject.
96+
Add a slave to the master BaseComponent.
9797
:param slave: the slave to be added.
98-
:type slave: BaseObject
98+
:type slave: BaseComponent
9999
)";
100100

101101
static auto storeResetState =
@@ -111,13 +111,13 @@ static auto reset =
111111

112112
static auto getName =
113113
R"(
114-
Accessor to the baseObject name.
114+
Accessor to the BaseComponent name.
115115
:rtype: string
116116
)";
117117

118118
static auto getTarget =
119119
R"(
120-
Return the target (plugin) that contains the current baseObject.
120+
Return the target (plugin) that contains the current BaseComponent.
121121
:rtype: string
122122
)";
123123

@@ -151,13 +151,13 @@ static auto computeBBox =
151151

152152
static auto getLinkPath =
153153
R"(
154-
Return the full path name of this baseObject with an extra prefix '@'
154+
Return the full path name of this BaseComponent with an extra prefix '@'
155155
:rtype: string
156156
)";
157157

158158
static auto getAsACreateObjectParameter =
159159
R"(
160-
Return the full path name of this baseObject with an extra prefix '@'
160+
Return the full path name of this BaseComponent with an extra prefix '@'
161161
:rtype: string
162162
)";
163163

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#include <sofa/simulation/mechanicalvisitor/MechanicalComputeEnergyVisitor.h>
2626
#include <sofa/core/ComponentNameHelper.h>
2727

28+
#include <sofa/core/objectmodel/BaseComponent.h>
29+
using sofa::core::objectmodel::BaseComponent;
30+
2831
#include <sofa/core/objectmodel/BaseData.h>
2932
using sofa::core::objectmodel::BaseData;
3033

@@ -44,7 +47,7 @@ using sofa::core::ExecParams;
4447
using sofapython3::LinkPath;
4548

4649
#include <SofaPython3/Sofa/Core/Binding_Base.h>
47-
#include <SofaPython3/Sofa/Core/Binding_BaseObject.h>
50+
#include <SofaPython3/Sofa/Core/Binding_BaseComponent.h>
4851
#include <SofaPython3/DataHelper.h>
4952

5053
#include <sofa/core/ObjectFactory.h>
@@ -138,7 +141,7 @@ py::object getItem(Node& self, std::list<std::string>& path)
138141
if (path.empty())
139142
return py::cast(self);
140143
Node* child = self.getChild(path.front());
141-
BaseObject* obj = self.getObject(path.front());
144+
BaseComponent* obj = self.getObject(path.front());
142145
BaseData* data = self.findData(path.front());
143146
if (child)
144147
{
@@ -182,25 +185,25 @@ py_shared_ptr<Node> __init_kwarged__(const std::string& name, const py::kwargs&
182185
/// Method: init (beware this is not the python __init__, this is sofa's init())
183186
void init(Node& self) { self.init(sofa::core::execparams::defaultInstance()); }
184187

185-
py::object addObject(Node& self, BaseObject * object)
188+
py::object addObject(Node& self, BaseComponent * object)
186189
{
187190
try {
188191
if (self.addObject(object))
189192
return PythonFactory::toPython(object);
190193
} catch (...) {
191-
throw py::type_error("Trying to add an object that isn't derived from sofa::core::objectmodel::BaseObject.");
194+
throw py::type_error("Trying to add an object that isn't derived from sofa::core::objectmodel::BaseComponent.");
192195
}
193196
return py::none();
194197
}
195198

196-
void removeObject(Node& self, BaseObject* object)
199+
void removeObject(Node& self, BaseComponent* object)
197200
{
198201
self.removeObject(object);
199202
}
200203

201204
py::object hasObject(Node &n, const std::string &name)
202205
{
203-
BaseObject *object = n.getObject(name);
206+
BaseComponent *object = n.getObject(name);
204207
if (object)
205208
return py::cast(true);
206209
return py::cast(false);
@@ -216,7 +219,7 @@ py::object getObject(Node &n, const std::string &name, const py::kwargs& kwargs)
216219
<< PythonEnvironment::getPythonCallingPointString() ;
217220
}
218221

219-
BaseObject *object = n.getObject(name);
222+
BaseComponent *object = n.getObject(name);
220223
if (object)
221224
return PythonFactory::toPython(object);
222225
return py::none();
@@ -344,9 +347,9 @@ py::object addObjectKwargs(Node* self, const std::string& type, const py::kwargs
344347
/// Implement the addObject function.
345348
py::object addKwargs(Node* self, const py::object& callable, const py::kwargs& kwargs)
346349
{
347-
if(py::isinstance<BaseObject*>(callable))
350+
if(py::isinstance<BaseComponent*>(callable))
348351
{
349-
BaseObject* obj = py::cast<BaseObject*>(callable);
352+
BaseComponent* obj = py::cast<BaseComponent*>(callable);
350353
self->addObject(obj);
351354
return py::cast(obj);
352355
}
@@ -375,7 +378,7 @@ py::object addKwargs(Node* self, const py::object& callable, const py::kwargs& k
375378
Base* base = py::cast<Base*>(c);
376379
if(!py::isinstance<Base*>(c))
377380
{
378-
throw py::value_error("add: the function passed as first argument can only return a Sofa.BaseObject or Sofa.Node object");
381+
throw py::value_error("add: the function passed as first argument can only return a Sofa.BaseComponent or Sofa.Node object");
379382
}
380383

381384
// Set the creation point
@@ -516,7 +519,7 @@ py::object __getattr__(py::object pyself, const std::string& name)
516519
{
517520
Node* selfnode = py::cast<Node*>(pyself);
518521
/// Search in the object lists
519-
BaseObject *object = selfnode->getObject(name);
522+
BaseComponent *object = selfnode->getObject(name);
520523
if (object)
521524
return PythonFactory::toPython(object);
522525

0 commit comments

Comments
 (0)