Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a6632a1
cleaning add functions
Lucas-TJ Dec 22, 2025
5c9c02a
Merge branch 'sofa-framework:master' into fix_add_from_link
Lucas-TJ May 19, 2026
5f2acb7
Merge branch 'sofa-framework:master' into fix_add_from_link
Lucas-TJ May 21, 2026
206b1be
Merge branch 'sofa-framework:master' into fix_add_from_link
Lucas-TJ May 27, 2026
108cd53
Merge branch 'master' into fix_add_from_link
Lucas-TJ May 28, 2026
3c2c5db
Merge branch 'sofa-framework:master' into fix_add_from_link
Lucas-TJ Jun 17, 2026
9ded891
add unit test
Lucas-TJ Jun 18, 2026
3201a16
Merge branch 'sofa-framework:master' into fix_add_from_link
Lucas-TJ Jun 18, 2026
e271ba2
Merge branch 'sofa-framework:master' into fix_add_from_link
Lucas-TJ Jul 24, 2026
9ada962
[Project] Start dev phase v26.12 (#6195)
hugtalbot Jul 28, 2026
71f6e04
[Scene] TetrahedronHyperelasticityFEMForceField.scn: add correct plug…
fredroy Jul 29, 2026
0c1e65c
[CORE] Add remove function in BaseLink (#6130)
Lucas-TJ Jul 29, 2026
bc53413
[Tests] Fix LCPForceFeedbackTests (#6213)
bakpaul Jul 29, 2026
416737e
[Plugins] Set SofaImplicitField as supported plugin (#6189)
bakpaul Jul 30, 2026
33acf3a
[Engine] Rename VolumeFromTetrahedrons to VolumeFromVolumetricElement…
alxbilger Jul 30, 2026
246108d
[Mapper] Missing `override` keyword (#6215)
alxbilger Jul 30, 2026
48c059a
cleaning add functions
Lucas-TJ Dec 22, 2025
6ab4044
add unit test
Lucas-TJ Jun 18, 2026
b84f7b5
[CORE] Add remove function in BaseLink (#6130)
Lucas-TJ Jul 29, 2026
3e4784c
[CORE] Add remove function in BaseLink (#6130)
Lucas-TJ Jul 29, 2026
2e78dc5
cleaning add functions
Lucas-TJ Dec 22, 2025
359eefe
add unit test
Lucas-TJ Jun 18, 2026
70c08be
Merge branch 'master' into fix_add_from_link
Lucas-TJ Jul 30, 2026
c48cee3
cleaning
Lucas-TJ Jul 30, 2026
0e7f361
cleaning
Lucas-TJ Jul 30, 2026
cf24261
restore and rename functions in Link.h
Lucas-TJ Jul 31, 2026
089ae6f
cleaning
Lucas-TJ Jul 31, 2026
f0621d2
cleaning
Lucas-TJ Jul 31, 2026
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
24 changes: 24 additions & 0 deletions Sofa/framework/Core/simutest/objectmodel/BaseLink_simutest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,30 @@ TEST_F(BaseLink_test, remove)
ASSERT_FALSE(owner.l_target.remove(nullptr));
}

TEST_F(BaseLink_test, add)
{
FakeComponent Component1;
Component1.setName("Component1");
FakeComponent Component2;
Component2.setName("Component2");
FakeComponent Component3;
Component3.setName("Component3");

FakeComponent* ptr;
ptr = &Component2;

EXPECT_EQ(Component1.l_target.getValueString(), "");

Component1.l_target.add(ptr);
EXPECT_EQ(Component1.l_target.getValueString(), "@Component2");

ptr = &Component3;

Component1.l_target.add(ptr);
EXPECT_EQ(Component1.l_target.getValueString(), "@Component2 @Component3");
}


//////////////////////// Testing valid path //////////////////////////////////////
class MultiLink_simutest : public BaseLink_test {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void BaseComponent::addSlave(BaseComponent::SPtr s)
if (previous == this) return;
if (previous)
previous->l_slaves.remove(s.get());
l_slaves.add(s);
l_slaves.add(s.get());
if (previous)
this->getContext()->notifyMoveSlave(previous.get(), this, s.get());
else
Expand Down
2 changes: 2 additions & 0 deletions Sofa/framework/Core/src/sofa/core/objectmodel/BaseLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class SOFA_CORE_API BaseLink

/// Add a new target to the link.
bool add(Base* baseptr, const std::string& path) { return _doAdd_(baseptr, path); }
bool add(Base* baseptr) { return _doAdd_(baseptr); }

/// Change the link's target at the provided index.
bool set(Base* baseptr, size_t index=0) { return _doSet_(baseptr, index); }
Expand All @@ -183,6 +184,7 @@ class SOFA_CORE_API BaseLink
virtual void _doSetOwner_(Base* owner) = 0;
virtual Base* _doGet_(const size_t=0) const = 0;
virtual bool _doAdd_(Base* target, const std::string&) = 0;
virtual bool _doAdd_(Base*) = 0;
virtual void _doClear_() = 0;
virtual std::string _doGetLinkedPath_(const size_t=0) const = 0;
virtual bool _doRemove_(Base* target) = 0;
Expand Down
28 changes: 23 additions & 5 deletions Sofa/framework/Core/src/sofa/core/objectmodel/Link.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class TLink : public BaseLink
return true;
}

bool add(DestPtr v)
bool addDestPtr(DestPtr v)
{
if (!v)
return false;
Expand All @@ -387,7 +387,7 @@ class TLink : public BaseLink
return true;
}

bool add(DestPtr v, const std::string& path)
bool addDestPtrPath(DestPtr v, const std::string& path)
{
if (!v && path.empty())
return false;
Expand Down Expand Up @@ -503,7 +503,25 @@ class TLink : public BaseLink
}

/// TLink:adding accepts nullptr (for a not yet resolved link).
return TLink::add(destptr, path);
return TLink::addDestPtrPath(destptr, path);
}

bool _doAdd_(Base* baseptr) override

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure that this method has the same visibility than the base class (it should stay protected)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, _doAdd_ function is protected like the base class.

{
/// If the pointer is null and the path empty we do nothing
if(!baseptr)
return false;

/// Downcast the pointer to a compatible type and
/// If the types are not compatible with the Link we returns false
auto destptr = castTo<DestType*>(baseptr);
if(!destptr)
{
return false;
}

/// TLink:adding accepts nullptr (for a not yet resolved link).
return TLink::addDestPtr(destptr);
}

/// Returns false on type mismatch
Expand Down Expand Up @@ -577,7 +595,7 @@ class MultiLink : public TLink<TOwnerType,TDestType,TFlags|BaseLink::FLAG_MULTIL
MultiLink(const BaseLink::InitLink<OwnerType>& init, DestPtr val)
: Inherit(init), m_validator(nullptr)
{
if (val) this->add(val);
if (val) this->addDestPtr(val);
}

virtual ~MultiLink()
Expand Down Expand Up @@ -654,7 +672,7 @@ class SingleLink : public TLink<TOwnerType,TDestType,TFlags&~BaseLink::FLAG_MULT
SingleLink(const BaseLink::InitLink<OwnerType>& init, DestPtr val)
: Inherit(init), m_validator(nullptr)
{
if (val) this->add(val);
if (val) this->addDestPtr(val);
}

virtual ~SingleLink()
Expand Down
4 changes: 2 additions & 2 deletions Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ bool Node::doAddObject(sofa::core::objectmodel::BaseComponent::SPtr sobj, sofa::
{
this->setObjectContext(sobj);
if(insertionLocation == sofa::core::objectmodel::TypeOfInsertion::AtEnd)
object.add(sobj);
object.add(sobj.get());
else
object.addBegin(sobj);

Expand Down Expand Up @@ -1182,7 +1182,7 @@ void Node::doAddChild(BaseNode::SPtr node)
{
const Node::SPtr dagnode = sofa::core::objectmodel::SPtr_static_cast<Node>(node);
setDirtyDescendancy();
child.add(dagnode);
child.add(dagnode.get());
dagnode->l_parents.add(this);
dagnode->l_parents.updateLinks(); // to fix load-time unresolved links
}
Expand Down
Loading