Skip to content

Commit 5e2b474

Browse files
committed
Squashed merge of PR #5443
commit 25bdd97 Merge: 48fa61d 912335e Author: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Date: Fri Apr 10 09:39:49 2026 +0200 Merge branch 'master' into 2025_sprintsed_BehaviorModel commit 48fa61d Merge: 25ab6f4 fb6ac6c Author: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Date: Tue Jan 6 11:34:38 2026 +0100 Merge branch 'master' into 2025_sprintsed_BehaviorModel commit 25ab6f4 Author: lbinria <77280433+lbinria@users.noreply.github.com> Date: Mon May 12 16:53:02 2025 +0200 [Framework] Apply template method design pattern to BehaviorModel
1 parent 258af4a commit 5e2b474

9 files changed

Lines changed: 41 additions & 12 deletions

File tree

Sofa/GUI/Component/src/sofa/gui/component/performer/MouseInteractor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ bool BaseMouseInteractor::removeInteractionPerformer( InteractionPerformer *i)
8080
}
8181
}
8282

83-
void BaseMouseInteractor::updatePosition(SReal )
83+
void BaseMouseInteractor::doUpdatePosition(SReal )
8484
{
8585
for (const auto perf : performers)
8686
{

Sofa/GUI/Component/src/sofa/gui/component/performer/MouseInteractor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class SOFA_GUI_COMPONENT_API BaseMouseInteractor : public core::BehaviorModel
6666
void addInteractionPerformer(InteractionPerformer *i);
6767
bool removeInteractionPerformer( InteractionPerformer *i);
6868
//Called at each time step: launch all the performers
69-
void updatePosition( SReal dt) override;
69+
void doUpdatePosition( SReal dt) override;
7070
//Propagate an event in case to all the performers
7171
void handleEvent(core::objectmodel::Event *e) override;
7272

Sofa/framework/Core/src/sofa/core/BehaviorModel.h

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,46 @@ class SOFA_CORE_API BehaviorModel : public virtual sofa::core::objectmodel::Base
4848
/// Destructor
4949
~BehaviorModel() override {}
5050

51+
/// Computation of a new simulation step.
52+
virtual void doUpdatePosition(SReal /*dt*/) = 0;
53+
54+
virtual bool doAddBBox(SReal* /*minBBox*/, SReal* /*maxBBox*/)
55+
{
56+
return false;
57+
}
58+
5159
private:
5260
BehaviorModel(const BehaviorModel& n) = delete;
5361
BehaviorModel& operator=(const BehaviorModel& n) = delete;
5462

5563
public:
56-
/// Computation of a new simulation step.
57-
virtual void updatePosition(SReal dt) = 0;
5864

59-
virtual bool addBBox(SReal* /*minBBox*/, SReal* /*maxBBox*/)
65+
/**
66+
* !!! WARNING since v25.12 !!!
67+
*
68+
* The template method pattern has been applied to this part of the API.
69+
* This method calls the newly introduced method "doUpdatePosition" internally,
70+
* which is the method to override from now on.
71+
*
72+
**/
73+
virtual void updatePosition(SReal dt) final
6074
{
61-
return false;
75+
//TODO (SPRINT SED 2025): Component state mechamism
76+
this->doUpdatePosition(dt);
77+
}
78+
79+
/**
80+
* !!! WARNING since v25.12 !!!
81+
*
82+
* The template method pattern has been applied to this part of the API.
83+
* This method calls the newly introduced method "doAddBBox" internally,
84+
* which is the method to override from now on.
85+
*
86+
**/
87+
virtual bool addBBox(SReal* minBBox, SReal* maxBBox) final
88+
{
89+
//TODO (SPRINT SED 2025): Component state mechamism
90+
return this->doAddBBox(minBBox, maxBBox);
6291
}
6392

6493
bool insertInNode( objectmodel::BaseNode* node ) override;

Sofa/framework/Helper/test/system/TestPluginA/ComponentC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void MyBehaviorModel::reinit()
5454
{
5555
}
5656

57-
void MyBehaviorModel::updatePosition(double /*dt*/)
57+
void MyBehaviorModel::doUpdatePosition(double /*dt*/)
5858
{
5959
}
6060

Sofa/framework/Helper/test/system/TestPluginA/ComponentC.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class MyBehaviorModel : public sofa::core::BehaviorModel
5252
public:
5353
virtual void init();
5454
virtual void reinit();
55-
virtual void updatePosition(double dt);
55+
void doUpdatePosition(double dt) override;
5656

5757
protected:
5858
Data<unsigned> customUnsignedData; ///< Example of unsigned data with custom widget

applications/plugins/SofaEulerianFluid/Fluid2D.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void Fluid2D::reset()
8383
init();
8484
}
8585

86-
void Fluid2D::updatePosition(SReal dt)
86+
void Fluid2D::doUpdatePosition(SReal dt)
8787
{
8888
fnext->step(fluid, ftemp, (real)dt);
8989
Grid2D* p = fluid; fluid=fnext; fnext=p;

applications/plugins/SofaEulerianFluid/Fluid2D.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class SOFA_EULERIAN_FLUID_API Fluid2D : public sofa::core::BehaviorModel
6868

6969
void reset() override;
7070

71-
void updatePosition(SReal dt) override;
71+
void doUpdatePosition(SReal dt) override;
7272

7373
void draw(const sofa::core::visual::VisualParams* vparams) override;
7474

applications/plugins/SofaEulerianFluid/Fluid3D.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void Fluid3D::reset()
9191
init();
9292
}
9393

94-
void Fluid3D::updatePosition(SReal dt)
94+
void Fluid3D::doUpdatePosition(SReal dt)
9595
{
9696
fnext->gravity = getContext()->getGravity()/f_cellwidth.getValue();
9797
fnext->step(fluid, ftemp, (real)dt);

applications/plugins/SofaEulerianFluid/Fluid3D.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class SOFA_EULERIAN_FLUID_API Fluid3D : public sofa::core::BehaviorModel
7272

7373
void reset() override;
7474

75-
void updatePosition(SReal dt) override;
75+
void doUpdatePosition(SReal dt) override;
7676

7777
void draw(const sofa::core::visual::VisualParams* vparams) override;
7878

0 commit comments

Comments
 (0)