Skip to content

Commit 5c12fc4

Browse files
committed
[Sofa.Core] Add getLinkPath() in the Base binding.
1 parent f1bd435 commit 5c12fc4

4 files changed

Lines changed: 31 additions & 3 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,13 @@ std::string BindingBase::getPathName(Base& self)
387387
{
388388
return self.toBaseNode() ? self.toBaseNode()->getPathName() : self.toBaseObject()->getPathName();
389389
}
390-
390+
391+
std::string BindingBase::getLinkPath(Base& self)
392+
{
393+
return "@"+getPathName(self);
394+
}
395+
396+
391397
py::object BindingBase::setDataValues(Base& self, py::kwargs kwargs)
392398
{
393399
for(auto key : kwargs)
@@ -435,7 +441,8 @@ void moduleAddBase(py::module &m)
435441
base.def("getLoggedMessagesAsString", &BindingBase::getLoggedMessagesAsString, sofapython3::doc::base::getLoggedMessagesAsString);
436442
base.def("countLoggedMessages", &BindingBase::countLoggedMessages, sofapython3::doc::base::countLoggedMessages);
437443
base.def("clearLoggedMessages", &BindingBase::clearLoggedMessages, sofapython3::doc::base::clearLoggedMessages);
438-
base.def("getPathName", &BindingBase::getPathName);
444+
base.def("getPathName", &BindingBase::getPathName, sofapython3::doc::base::setDataValues);
445+
base.def("getPathName", &BindingBase::getLinkPath, sofapython3::doc::base::setDataValues);
439446
base.def("setDataValues", &BindingBase::setDataValues, sofapython3::doc::base::setDataValues);
440447
}
441448

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class BindingBase
6464
static pybind11::object countLoggedMessages(sofa::core::objectmodel::Base& self);
6565
static pybind11::object clearLoggedMessages(sofa::core::objectmodel::Base& self);
6666
static std::string getPathName(sofa::core::objectmodel::Base& self);
67+
static std::string getLinkPath(sofa::core::objectmodel::Base& self);
6768
};
6869

6970

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ static auto findData =
6363
:type name: string
6464
:return: the data field
6565
)";
66+
static auto getLinkPath =
67+
R"(
68+
returns the path name as a parsable string.
69+
eg:
70+
if object.getPathName() is "/child1/object"
71+
then the linkPath is @"/child1/object"
72+
)";
73+
static auto getPathName =
74+
R"(
75+
returns the path name as a string.
76+
.. code-block:: python
77+
a = Sofa.Core.Node("root")
78+
b.addObject("Camera", name="camera")
79+
b.getPathName() # should returns "/root/camera"
80+
```
81+
)";
6682
static auto setDataValues =
6783
R"(
6884
Set values for a the given data field, multiple pairs of args are allowed.

bindings/Sofa/tests/Core/Base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ def test_getTemplateName(self):
123123
c = root.addObject("MechanicalObject", name="t")
124124
self.assertEqual(c.getTemplateName(),"Vec3d")
125125

126-
126+
def test_getLinkPath(self):
127+
root = create_scene("root")
128+
obj = root.addObject("MechanicalObject", name="obj")
129+
self.assertEqual(obj.getPathName(),"/obj")
130+
self.assertEqual(obj.getLinkPath(),"@/obj")
127131

128132
def test_addExistingDataAsParentOfNewData(self):
129133
# TODO(@marques-bruno)

0 commit comments

Comments
 (0)