Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sofa/framework/Core/src/sofa/core/objectmodel/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class SOFA_CORE_API Base : public IntrusiveObject
void addOutputsToCallback(const std::string& name, std::initializer_list<BaseData*> outputs);


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

/// Accessor to the object name
Expand Down
9 changes: 8 additions & 1 deletion Sofa/framework/Core/src/sofa/core/objectmodel/BaseData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,17 @@ bool BaseData::setParent(BaseData* parent, const std::string& path)
return true;
}

std::string BaseData::getPathName() const
{
if(m_owner)
return m_owner->getPathName()+"."+getName();
return "";
}

std::string BaseData::getLinkPath() const
{
if(m_owner)
return "@"+m_owner->getPathName()+"."+getName();
return "@"+getPathName();
return "";
}

Expand Down
1 change: 1 addition & 0 deletions Sofa/framework/Core/src/sofa/core/objectmodel/BaseData.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class SOFA_CORE_API BaseData : public DDGNode

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

/// Return whether this %Data can be used as a linkPath.
///
Expand Down
29 changes: 13 additions & 16 deletions Sofa/framework/Core/src/sofa/core/objectmodel/BaseObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,22 +342,19 @@ SReal BaseObject::getTime() const
return getContext()->getTime();
}

std::string BaseObject::getPathName() const {

const BaseContext* context = this->getContext();
std::string result = "";
if( context )
{
const BaseNode* node = context->toBaseNode();
if( node ) {
result += node->getPathName();
if (node->getPathName() != "/")
result += "/";
}

}
result += getName();
return result;
std::string BaseObject::getPathName() const
{
auto node = dynamic_cast<const BaseNode*>(getContext());
if(!node)
return "";

auto pathname = node->getPathName();
std::stringstream tmp;
tmp << pathname;
if (pathname != "/")
tmp << "/";
tmp << getName();
return tmp.str();
}

} // namespace sofa::core::objectmodel
Expand Down
Loading