Skip to content

Commit 1c72584

Browse files
damienmarchalalxbilgerhugtalbot
authored
[Sofa.Core] Add getPathName in BaseData (#5759)
* [Sofa.Core] Add a getPathName() method in BaseData There was no method to get the PathName() to a BaseData only a linkpath (so with the "@" prefix indicating a link). I add the missing feature and make some minor cleaning * FIXUP * Update Sofa/framework/Core/src/sofa/core/objectmodel/BaseData.cpp Co-authored-by: Alex Bilger <alxbilger@users.noreply.github.com> * Update Sofa/framework/Core/src/sofa/core/objectmodel/BaseObject.cpp --------- Co-authored-by: Alex Bilger <alxbilger@users.noreply.github.com> Co-authored-by: Hugo <hugo.talbot@sofa-framework.org>
1 parent e8aeba5 commit 1c72584

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

Sofa/framework/Core/src/sofa/core/objectmodel/Base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class SOFA_CORE_API Base : public IntrusiveObject
9797
void addOutputsToCallback(const std::string& name, std::initializer_list<BaseData*> outputs);
9898

9999

100+
/// Returns the path to the Base. it is possible to use different character as separator.
100101
virtual std::string getPathName() const { return ""; }
101102

102103
/// Accessor to the object name

Sofa/framework/Core/src/sofa/core/objectmodel/BaseData.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,17 @@ bool BaseData::setParent(BaseData* parent, const std::string& path)
140140
return true;
141141
}
142142

143+
std::string BaseData::getPathName() const
144+
{
145+
if(m_owner)
146+
return m_owner->getPathName()+"."+getName();
147+
return getName();
148+
}
149+
143150
std::string BaseData::getLinkPath() const
144151
{
145152
if(m_owner)
146-
return "@"+m_owner->getPathName()+"."+getName();
153+
return "@"+getPathName();
147154
return "";
148155
}
149156

Sofa/framework/Core/src/sofa/core/objectmodel/BaseData.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ class SOFA_CORE_API BaseData : public DDGNode
194194

195195
/// If we use the Data as a link and not as value directly
196196
virtual std::string getLinkPath() const;
197+
std::string getPathName()const;
197198

198199
/// Return whether this %Data can be used as a linkPath.
199200
///

Sofa/framework/Core/src/sofa/core/objectmodel/BaseObject.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -342,22 +342,19 @@ SReal BaseObject::getTime() const
342342
return getContext()->getTime();
343343
}
344344

345-
std::string BaseObject::getPathName() const {
346-
347-
const BaseContext* context = this->getContext();
348-
std::string result = "";
349-
if( context )
350-
{
351-
const BaseNode* node = context->toBaseNode();
352-
if( node ) {
353-
result += node->getPathName();
354-
if (node->getPathName() != "/")
355-
result += "/";
356-
}
357-
358-
}
359-
result += getName();
360-
return result;
345+
std::string BaseObject::getPathName() const
346+
{
347+
auto node = dynamic_cast<const BaseNode*>(getContext());
348+
if(!node)
349+
return getName();
350+
351+
auto pathname = node->getPathName();
352+
std::stringstream tmp;
353+
tmp << pathname;
354+
if (pathname != "/")
355+
tmp << "/";
356+
tmp << getName();
357+
return tmp.str();
361358
}
362359

363360
} // namespace sofa::core::objectmodel

0 commit comments

Comments
 (0)