From 158f1b402461ec8b41189ce7352213b4824f5fba Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Thu, 27 Aug 2026 15:49:18 +0200 Subject: [PATCH 1/7] [Refactor] Merge Context into BaseContext with compatibility layer - BaseContext is now a concrete class with Data members (is_activated, worldGravity_, dt_, time_, animate_, d_isSleeping, d_canChangeSleepingState) - All Context methods implemented in BaseContext - Node now inherits directly from BaseNode and BaseContext (instead of Context) - Context class kept as compatibility layer, inheriting from BaseContext - Updated includes in Contact.h, UniformMass.inl, VisualStyle.cpp, Main.cpp - Fixed casts in Node.cpp to use BaseContext instead of Context Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- .../src/sofa/component/mass/UniformMass.inl | 2 +- .../src/sofa/component/visual/VisualStyle.cpp | 2 +- .../Core/src/sofa/core/collision/Contact.h | 2 +- .../src/sofa/core/objectmodel/BaseContext.cpp | 102 +++++++++++++++-- .../src/sofa/core/objectmodel/BaseContext.h | 54 ++++++--- .../src/sofa/core/objectmodel/Context.cpp | 108 ++++-------------- .../Core/src/sofa/core/objectmodel/Context.h | 25 ++-- .../Core/src/sofa/simulation/Node.cpp | 9 +- .../Core/src/sofa/simulation/Node.h | 6 +- .../projects/sofaProjectExample/Main.cpp | 2 +- 10 files changed, 174 insertions(+), 138 deletions(-) diff --git a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl index e69dee976cc..97296af7047 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl +++ b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Sofa/Component/Visual/src/sofa/component/visual/VisualStyle.cpp b/Sofa/Component/Visual/src/sofa/component/visual/VisualStyle.cpp index f8348acb19d..d5f0a86ef0e 100644 --- a/Sofa/Component/Visual/src/sofa/component/visual/VisualStyle.cpp +++ b/Sofa/Component/Visual/src/sofa/component/visual/VisualStyle.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include namespace sofa::component::visual diff --git a/Sofa/framework/Core/src/sofa/core/collision/Contact.h b/Sofa/framework/Core/src/sofa/core/collision/Contact.h index 395330d7a94..7ebb2d5c7c6 100644 --- a/Sofa/framework/Core/src/sofa/core/collision/Contact.h +++ b/Sofa/framework/Core/src/sofa/core/collision/Contact.h @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.cpp index f457a402182..443a1553af1 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.cpp @@ -33,7 +33,18 @@ namespace sofa::core::objectmodel { BaseContext::BaseContext() -{} + : is_activated(initData(&is_activated, true, "activated", "To Activate a node")) + , worldGravity_(initData(&worldGravity_, Vec3(SReal(0),SReal(-9.81),SReal(0)),"gravity","Gravity in the world coordinate system")) + , dt_(initData(&dt_,SReal(0.01),"dt","Time step")) + , time_(initData(&time_,SReal(0.),"time","Current time")) + , animate_(initData(&animate_,false,"animate","Animate the Simulation(applied at initialization only)")) + , d_isSleeping(initData(&d_isSleeping, false, "sleeping", "The node is sleeping, and thus ignored by visitors.")) + , d_canChangeSleepingState(initData(&d_canChangeSleepingState, false, "canChangeSleepingState", "The node can change its sleeping state.")) +{ + animate_.setReadOnly(true); + dt_.setReadOnly(true); + time_.setReadOnly(true); +} BaseContext::~BaseContext() {} @@ -51,38 +62,90 @@ BaseContext* BaseContext::getDefault() //////////////// /// The Context is active -bool BaseContext::isActive() const { return true; } +bool BaseContext::isActive() const { return is_activated.getValue(); } + +/// State of the context +void BaseContext::setActive(bool val) +{ + is_activated.setValue(val); +} -/// The Context is not sleeping by default -bool BaseContext::isSleeping() const { return false; } +/// The Context is sleeping +bool BaseContext::isSleeping() const +{ + return d_isSleeping.getValue(); +} + +/// The Context can change its sleeping state +bool BaseContext::canChangeSleepingState() const +{ + return d_canChangeSleepingState.getValue(); +} -/// The Context can not change its sleeping state by default -bool BaseContext::canChangeSleepingState() const { return false; } +/// Sleeping state of the context +void BaseContext::setSleeping(bool val) +{ + d_isSleeping.setValue(val); +} +/// Sleeping state change of the context +void BaseContext::setChangeSleepingState(bool val) +{ + d_canChangeSleepingState.setValue(val); +} /// Gravity in the world coordinate system const BaseContext::Vec3& BaseContext::getGravity() const { - static const Vec3 G(SReal(0),SReal(-9.81), SReal(0)); - return G; + return worldGravity_.getValue(); +} + +/// Gravity in local coordinates +void BaseContext::setGravity(const Vec3& g) +{ + worldGravity_.setValue(g); } /// Simulation timestep SReal BaseContext::getDt() const { - return 0.01; + return dt_.getValue(); } /// Simulation time SReal BaseContext::getTime() const { - return 0.0; + return time_.getValue(); } /// Animation flag bool BaseContext::getAnimate() const { - return true; + return animate_.getValue(); +} + +/// Simulation timestep +void BaseContext::setDt(SReal dt) +{ + dt_.setValue(dt); +} + +/// Animation flag +void BaseContext::setAnimate(bool val) +{ + animate_.setValue(val); +} + +/// Simulation time +void BaseContext::setTime(SReal t) +{ + time_.setValue(t); +} + +/// Display flags: Gravity +void BaseContext::setDisplayWorldGravity(bool val) +{ + worldGravity_.setDisplayed(val); } @@ -208,4 +271,21 @@ void BaseContext::notifyMoveSlave(core::objectmodel::BaseComponent* /*previousMa { } +////////////////// +// Copy methods // +////////////////// + +void BaseContext::copyContext(const BaseContext& c) +{ + copySimulationContext(c); +} + +void BaseContext::copySimulationContext(const BaseContext& c) +{ + worldGravity_.setValue(c.getGravity()); ///< Gravity IN THE WORLD COORDINATE SYSTEM. + setDt(c.getDt()); + setTime(c.getTime()); + setAnimate(c.getAnimate()); +} + } // namespace sofa::core::objectmodel diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.h b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.h index 32fcce8c84b..4c35142f420 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.h +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.h @@ -26,6 +26,7 @@ #include #include #include +#include namespace sofa::simulation { @@ -58,6 +59,15 @@ class SOFA_CORE_API BaseContext : public virtual Base BaseContext(); ~BaseContext() override; + // Data members from Context + Data is_activated; ///< To Activate a node + Data worldGravity_; ///< Gravity in the world coordinate system + Data dt_; ///< Time step + Data time_; ///< Current time + Data animate_; ///< Animate the Simulation(applied at initialization only) + Data d_isSleeping; ///< The node is sleeping, and thus ignored by visitors. + Data d_canChangeSleepingState; ///< The node can change its sleeping state. + private: BaseContext(const BaseContext&); BaseContext& operator=(const BaseContext& ); @@ -74,33 +84,35 @@ class SOFA_CORE_API BaseContext : public virtual Base /// @{ /// The Context is active - virtual bool isActive() const; + virtual bool isActive() const override; /// State of the context - virtual void setActive(bool) {} + virtual void setActive(bool val) override; /// Sleeping state of the context - virtual bool isSleeping() const; + virtual bool isSleeping() const override; /// Whether the context can change its sleeping state or not - virtual bool canChangeSleepingState() const; + virtual bool canChangeSleepingState() const override; /// Simulation time - virtual SReal getTime() const; + virtual SReal getTime() const override; /// Simulation timestep - virtual SReal getDt() const; + virtual SReal getDt() const override; /// Animation flag - virtual bool getAnimate() const; + virtual bool getAnimate() const override; /// @} + /// Simulation time + virtual void setTime(SReal t); + /// Gravity in local coordinates - virtual const Vec3& getGravity() const; + virtual const Vec3& getGravity() const override; /// Gravity in local coordinates - virtual void setGravity( const Vec3& ) - { } + virtual void setGravity( const Vec3& g) override; /// Get the root context of the graph virtual BaseContext* getRootContext() const; @@ -316,24 +328,28 @@ class SOFA_CORE_API BaseContext : public virtual Base /// @name Parameters Setters /// @{ - /// Simulation timestep - virtual void setDt( SReal /*dt*/ ) - { } + virtual void setDt( SReal dt ) override; /// Animation flag - virtual void setAnimate(bool /*val*/) - { } + virtual void setAnimate(bool val) override; /// Sleeping state of the context - virtual void setSleeping(bool /*val*/) - { } + virtual void setSleeping(bool val) override; /// Sleeping state change of the context - virtual void setChangeSleepingState(bool /*val*/) - { } + virtual void setChangeSleepingState(bool val) override; + + /// Display flags: Gravity + virtual void setDisplayWorldGravity(bool val); /// @} + /// Copy the context variables from the given instance + void copyContext(const BaseContext& c); + + /// Copy the context variables of visualization from the given instance + void copySimulationContext(const BaseContext& c); + /// @name Variables Setters /// @{ diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/Context.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/Context.cpp index 2c9c3ec331f..c3851a92ae7 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Context.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/Context.cpp @@ -24,121 +24,61 @@ namespace sofa::core::objectmodel { -Context::Context() - : is_activated(initData(&is_activated, true, "activated", "To Activate a node")) - , worldGravity_(initData(&worldGravity_, Vec3(SReal(0),SReal(-9.81),SReal(0)),"gravity","Gravity in the world coordinate system")) - , dt_(initData(&dt_,SReal(0.01),"dt","Time step")) - , time_(initData(&time_,SReal(0.),"time","Current time")) - , animate_(initData(&animate_,false,"animate","Animate the Simulation(applied at initialization only)")) - , d_isSleeping(initData(&d_isSleeping, false, "sleeping", "The node is sleeping, and thus ignored by visitors.")) - , d_canChangeSleepingState(initData(&d_canChangeSleepingState, false, "canChangeSleepingState", "The node can change its sleeping state.")) -{ - animate_.setReadOnly(true); - dt_.setReadOnly(true); - time_.setReadOnly(true); -} +// Context constructor - BaseContext constructor already initializes all Data members +Context::Context() = default; /// The Context is active -bool Context::isActive() const {return is_activated.getValue();} +bool Context::isActive() const { return BaseContext::isActive(); } /// State of the context -void Context::setActive(bool val) -{ - is_activated.setValue(val); -} +void Context::setActive(bool val) { BaseContext::setActive(val); } /// The Context is sleeping -bool Context::isSleeping() const -{ - return d_isSleeping.getValue(); -} +bool Context::isSleeping() const { return BaseContext::isSleeping(); } /// Sleeping state of the context -void Context::setSleeping(bool val) -{ - d_isSleeping.setValue(val); -} +void Context::setSleeping(bool val) { BaseContext::setSleeping(val); } /// The Context can change its sleeping state -bool Context::canChangeSleepingState() const -{ - return d_canChangeSleepingState.getValue(); -} +bool Context::canChangeSleepingState() const { return BaseContext::canChangeSleepingState(); } /// Sleeping state change of the context -void Context::setChangeSleepingState(bool val) -{ - d_canChangeSleepingState.setValue(val); -} - - +void Context::setChangeSleepingState(bool val) { BaseContext::setChangeSleepingState(val); } /// Simulation timestep -SReal Context::getDt() const -{ - return dt_.getValue(); -} +SReal Context::getDt() const { return BaseContext::getDt(); } /// Simulation time -SReal Context::getTime() const -{ - return time_.getValue(); -} +SReal Context::getTime() const { return BaseContext::getTime(); } /// Gravity vector in world coordinates -const Context::Vec3& Context::getGravity() const -{ - return worldGravity_.getValue(); -} +const Context::Vec3& Context::getGravity() const { return BaseContext::getGravity(); } /// Animation flag -bool Context::getAnimate() const -{ - return animate_.getValue(); -} - -//=============================================================================== +bool Context::getAnimate() const { return BaseContext::getAnimate(); } /// Simulation timestep -void Context::setDt(SReal dt) -{ - dt_.setValue(dt); -} +void Context::setDt(SReal dt) { BaseContext::setDt(dt); } /// Simulation time -void Context::setTime(SReal t) -{ - time_.setValue(t); -} +void Context::setTime(SReal t) { BaseContext::setTime(t); } /// Gravity vector -void Context::setGravity(const Vec3& g) -{ - worldGravity_ .setValue(g); -} +void Context::setGravity(const Vec3& g) { BaseContext::setGravity(g); } /// Animation flag -void Context::setAnimate(const bool val) -{ - animate_.setValue(val); -} +void Context::setAnimate(bool val) { BaseContext::setAnimate(val); } -//====================== -void Context::copyContext(const Context& c) -{ - // BUGFIX 12/01/06 (Jeremie A.): Can't use operator= on the class as it will copy other data in the BaseContext class (such as name)... - // *this = c; +/// Display flags: Gravity +void Context::setDisplayWorldGravity(bool val) { BaseContext::setDisplayWorldGravity(val); } - copySimulationContext(c); -} +//====================== +void Context::copyContext(const Context& c) { BaseContext::copyContext(c); } +void Context::copySimulationContext(const Context& c) { BaseContext::copySimulationContext(c); } -void Context::copySimulationContext(const Context& c) -{ - worldGravity_.setValue(c.getGravity()); ///< Gravity IN THE WORLD COORDINATE SYSTEM. - setDt(c.getDt()); - setTime(c.getTime()); - setAnimate(c.getAnimate()); -} +// Additional compatibility: allow copying from BaseContext +void Context::copyContext(const BaseContext& c) { BaseContext::copyContext(c); } +void Context::copySimulationContext(const BaseContext& c) { BaseContext::copySimulationContext(c); } } // namespace sofa::core::objectmodel diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h b/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h index 87d38b769b0..c44712147ff 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h @@ -27,26 +27,27 @@ namespace sofa::core::objectmodel { /** - * \brief Implementation of BaseContext, storing all shared parameters in Datas. - * + * \brief Compatibility layer - Context is now a subclass of BaseContext. + * All functionality has been merged into BaseContext. + * This class is kept for backward compatibility with existing code. */ class SOFA_CORE_API Context : public BaseContext { public: SOFA_CLASS(Context, BaseContext); - Data is_activated; ///< To Activate a node - Data worldGravity_; ///< Gravity in the world coordinate system - Data dt_; ///< Time step - Data time_; ///< Current time - Data animate_; ///< Animate the Simulation(applied at initialization only) - Data d_isSleeping; ///< The node is sleeping, and thus ignored by visitors. - Data d_canChangeSleepingState; ///< The node can change its sleeping state. + // All Data members are inherited from BaseContext + using BaseContext::is_activated; + using BaseContext::worldGravity_; + using BaseContext::dt_; + using BaseContext::time_; + using BaseContext::animate_; + using BaseContext::d_isSleeping; + using BaseContext::d_canChangeSleepingState; protected: Context(); - virtual ~Context() override - {} + virtual ~Context() override = default; public: /// @name Parameters @@ -97,7 +98,7 @@ class SOFA_CORE_API Context : public BaseContext void setChangeSleepingState(bool val) override; /// Display flags: Gravity - virtual void setDisplayWorldGravity(bool val) { worldGravity_.setDisplayed(val); } + virtual void setDisplayWorldGravity(bool val); /// @} diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp index 11a9c821a38..857a9dd4abc 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp @@ -77,7 +77,6 @@ using core::objectmodel::BaseNode; Node::Node(const std::string& nodename, Node* parent) : core::objectmodel::BaseNode() - , sofa::core::objectmodel::Context() , child(initLink("child", "Child nodes")) , object(initLink("object","All objects attached to this node")) @@ -871,7 +870,7 @@ void Node::updateVisualContext() { initializeContexts(); - dmsg_info_when(debug_)<<"Node::updateVisualContext, node = "< #include -#include +#include #include #include #include From 994d78764e7e7a14d52d5c2b48456f729cf02070 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Thu, 27 Aug 2026 17:16:07 +0200 Subject: [PATCH 2/7] FIXUP --- Sofa/framework/Core/CMakeLists.txt | 1 - .../src/sofa/core/objectmodel/BaseContext.h | 40 +++++++++---------- .../Core/src/sofa/simulation/Node.cpp | 4 +- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/Sofa/framework/Core/CMakeLists.txt b/Sofa/framework/Core/CMakeLists.txt index 8e02de279d4..02cfdf4d4d6 100644 --- a/Sofa/framework/Core/CMakeLists.txt +++ b/Sofa/framework/Core/CMakeLists.txt @@ -314,7 +314,6 @@ set(SOURCE_FILES ${SRC_ROOT}/objectmodel/ClassInfo.cpp ${SRC_ROOT}/objectmodel/ComponentState.cpp ${SRC_ROOT}/objectmodel/ConfigurationSetting.cpp - ${SRC_ROOT}/objectmodel/Context.cpp ${SRC_ROOT}/objectmodel/ContextObject.cpp ${SRC_ROOT}/objectmodel/DDGNode.cpp ${SRC_ROOT}/objectmodel/Data.cpp diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.h b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.h index 4c35142f420..711b38f81a4 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.h +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.h @@ -55,11 +55,15 @@ class SOFA_CORE_API BaseContext : public virtual Base using Vec3 = sofa::type::Vec3; -protected: BaseContext(); ~BaseContext() override; - // Data members from Context +private: + BaseContext(const BaseContext&); + BaseContext& operator=(const BaseContext& ); + +public: + /// Data members from Context Data is_activated; ///< To Activate a node Data worldGravity_; ///< Gravity in the world coordinate system Data dt_; ///< Time step @@ -68,11 +72,6 @@ class SOFA_CORE_API BaseContext : public virtual Base Data d_isSleeping; ///< The node is sleeping, and thus ignored by visitors. Data d_canChangeSleepingState; ///< The node can change its sleeping state. -private: - BaseContext(const BaseContext&); - BaseContext& operator=(const BaseContext& ); - -public: /// Get the default Context object, that contains the default values for /// all parameters and can be used when no local context is defined. static BaseContext* getDefault(); @@ -84,35 +83,34 @@ class SOFA_CORE_API BaseContext : public virtual Base /// @{ /// The Context is active - virtual bool isActive() const override; + virtual bool isActive() const ; /// State of the context - virtual void setActive(bool val) override; + virtual void setActive(bool val) ; /// Sleeping state of the context - virtual bool isSleeping() const override; + virtual bool isSleeping() const ; /// Whether the context can change its sleeping state or not - virtual bool canChangeSleepingState() const override; + virtual bool canChangeSleepingState() const ; /// Simulation time - virtual SReal getTime() const override; + virtual SReal getTime() const ; /// Simulation timestep - virtual SReal getDt() const override; + virtual SReal getDt() const ; /// Animation flag - virtual bool getAnimate() const override; + virtual bool getAnimate() const ; /// @} /// Simulation time virtual void setTime(SReal t); - /// Gravity in local coordinates - virtual const Vec3& getGravity() const override; + virtual const Vec3& getGravity() const; /// Gravity in local coordinates - virtual void setGravity( const Vec3& g) override; + virtual void setGravity( const Vec3& g); /// Get the root context of the graph virtual BaseContext* getRootContext() const; @@ -329,16 +327,16 @@ class SOFA_CORE_API BaseContext : public virtual Base /// @{ /// Simulation timestep - virtual void setDt( SReal dt ) override; + virtual void setDt( SReal dt ); /// Animation flag - virtual void setAnimate(bool val) override; + virtual void setAnimate(bool val); /// Sleeping state of the context - virtual void setSleeping(bool val) override; + virtual void setSleeping(bool val); /// Sleeping state change of the context - virtual void setChangeSleepingState(bool val) override; + virtual void setChangeSleepingState(bool val); /// Display flags: Gravity virtual void setDisplayWorldGravity(bool val); diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp index 857a9dd4abc..09e23794549 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp @@ -1812,7 +1812,7 @@ void Node::updateContext() // if one day we refactor that part, maybe it would be better to have // an an explicit context-relationship and trigger a warning in case like the following one // saying there is an ambiguity and query scene designer to deambiguiate it. - copyContext(*static_cast(firstParent)); + copyContext(*static_cast(static_cast(firstParent))); } updateSimulationContext(); @@ -1834,7 +1834,7 @@ void Node::updateSimulationContext() // if one day we refactor that part, maybe it would be better to have // an an explicit context-relationship and trigger a warning in case like the following one // saying there is an ambiguity and query scene designer to deambiguiate it. - copySimulationContext(*static_cast(firstParent)); + copySimulationContext(*static_cast(static_cast(firstParent))); } // if there is no parent... initialize all the context objects. From aa2827ceb3e0e6dad5558d4966f931b849093580 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Tue, 1 Sep 2026 10:28:25 +0200 Subject: [PATCH 3/7] Replace Context by an alias to BaseContext. --- .../src/sofa/core/objectmodel/Context.cpp | 84 ------------------- .../Core/src/sofa/core/objectmodel/Context.h | 79 +---------------- 2 files changed, 1 insertion(+), 162 deletions(-) delete mode 100644 Sofa/framework/Core/src/sofa/core/objectmodel/Context.cpp diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/Context.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/Context.cpp deleted file mode 100644 index c3851a92ae7..00000000000 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Context.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture * -* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * -* * -* This program is free software; you can redistribute it and/or modify it * -* under the terms of the GNU Lesser General Public License as published by * -* the Free Software Foundation; either version 2.1 of the License, or (at * -* your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, but WITHOUT * -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * -* for more details. * -* * -* You should have received a copy of the GNU Lesser General Public License * -* along with this program. If not, see . * -******************************************************************************* -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#include - -namespace sofa::core::objectmodel -{ - -// Context constructor - BaseContext constructor already initializes all Data members -Context::Context() = default; - -/// The Context is active -bool Context::isActive() const { return BaseContext::isActive(); } - -/// State of the context -void Context::setActive(bool val) { BaseContext::setActive(val); } - -/// The Context is sleeping -bool Context::isSleeping() const { return BaseContext::isSleeping(); } - -/// Sleeping state of the context -void Context::setSleeping(bool val) { BaseContext::setSleeping(val); } - -/// The Context can change its sleeping state -bool Context::canChangeSleepingState() const { return BaseContext::canChangeSleepingState(); } - -/// Sleeping state change of the context -void Context::setChangeSleepingState(bool val) { BaseContext::setChangeSleepingState(val); } - -/// Simulation timestep -SReal Context::getDt() const { return BaseContext::getDt(); } - -/// Simulation time -SReal Context::getTime() const { return BaseContext::getTime(); } - -/// Gravity vector in world coordinates -const Context::Vec3& Context::getGravity() const { return BaseContext::getGravity(); } - -/// Animation flag -bool Context::getAnimate() const { return BaseContext::getAnimate(); } - -/// Simulation timestep -void Context::setDt(SReal dt) { BaseContext::setDt(dt); } - -/// Simulation time -void Context::setTime(SReal t) { BaseContext::setTime(t); } - -/// Gravity vector -void Context::setGravity(const Vec3& g) { BaseContext::setGravity(g); } - -/// Animation flag -void Context::setAnimate(bool val) { BaseContext::setAnimate(val); } - -/// Display flags: Gravity -void Context::setDisplayWorldGravity(bool val) { BaseContext::setDisplayWorldGravity(val); } - -//====================== -void Context::copyContext(const Context& c) { BaseContext::copyContext(c); } - -void Context::copySimulationContext(const Context& c) { BaseContext::copySimulationContext(c); } - -// Additional compatibility: allow copying from BaseContext -void Context::copyContext(const BaseContext& c) { BaseContext::copyContext(c); } -void Context::copySimulationContext(const BaseContext& c) { BaseContext::copySimulationContext(c); } -} // namespace sofa::core::objectmodel - diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h b/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h index c44712147ff..01bdcce7af7 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h @@ -29,84 +29,7 @@ namespace sofa::core::objectmodel /** * \brief Compatibility layer - Context is now a subclass of BaseContext. * All functionality has been merged into BaseContext. - * This class is kept for backward compatibility with existing code. */ -class SOFA_CORE_API Context : public BaseContext -{ -public: - SOFA_CLASS(Context, BaseContext); - - // All Data members are inherited from BaseContext - using BaseContext::is_activated; - using BaseContext::worldGravity_; - using BaseContext::dt_; - using BaseContext::time_; - using BaseContext::animate_; - using BaseContext::d_isSleeping; - using BaseContext::d_canChangeSleepingState; - -protected: - Context(); - virtual ~Context() override = default; - -public: - /// @name Parameters - /// @{ - - /// The Context is active - bool isActive() const override; - /// State of the context - void setActive(bool val) override; - - /// The Context is sleeping - bool isSleeping() const override; - - /// The Context can change its sleeping state - bool canChangeSleepingState() const override; - - /// Gravity in local coordinates - const Vec3& getGravity() const override; - /// Gravity in local coordinates - void setGravity( const Vec3& ) override; - - /// Simulation timestep - SReal getDt() const override; - - /// Simulation time - SReal getTime() const override; - - /// Animation flag - bool getAnimate() const override; - /// @} - - /// @name Parameters Setters - /// @{ - - /// Simulation timestep - void setDt( SReal dt ) override; - - /// Simulation time - virtual void setTime( SReal t ); - - /// Animation flag - void setAnimate(bool val) override; - - /// Sleeping state of the context - void setSleeping(bool val) override; - - /// Sleeping state change of the context - void setChangeSleepingState(bool val) override; - - /// Display flags: Gravity - virtual void setDisplayWorldGravity(bool val); - - /// @} - - /// Copy the context variables from the given instance - void copyContext(const Context& c); - - /// Copy the context variables of visualization from the given instance - void copySimulationContext(const Context& c); +using Context = BaseContext; -}; } // namespace sofa::core::objectmodel From 3834f211f213577c29a97a0c37d1416a8fe97bb2 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Wed, 2 Sep 2026 16:02:46 +0200 Subject: [PATCH 4/7] Attempt to avoid the instantiation of the sptr in BaseContext. To fix compilation issue on windows. --- .../Core/src/sofa/core/objectmodel/BaseContext.cpp | 11 +++++++++++ .../Core/src/sofa/core/objectmodel/BaseContext.h | 10 ++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.cpp index 443a1553af1..41e85dd8156 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.cpp @@ -271,6 +271,17 @@ void BaseContext::notifyMoveSlave(core::objectmodel::BaseComponent* /*previousMa { } +bool BaseContext::addObject( sptr, TypeOfInsertion ) +{ + return false; +} + +bool BaseContext::removeObject( sptr ) +{ + return false; +} + + ////////////////// // Copy methods // ////////////////// diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.h b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.h index 711b38f81a4..1e78dda651c 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.h +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.h @@ -376,16 +376,10 @@ class SOFA_CORE_API BaseContext : public virtual Base /// @{ /// Add an object, or return false if not supported - virtual bool addObject( sptr /*obj*/, TypeOfInsertion = TypeOfInsertion::AtEnd) - { - return false; - } + virtual bool addObject( sptr /*obj*/, TypeOfInsertion = TypeOfInsertion::AtEnd); /// Remove an object, or return false if not supported - virtual bool removeObject( sptr /*obj*/ ) - { - return false; - } + virtual bool removeObject( sptr /*obj*/ ); /// @} From ac18686933d5a10b8b1e33140a8af172cc4b8f41 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Fri, 4 Sep 2026 10:38:42 +0200 Subject: [PATCH 5/7] Update Sofa/framework/Core/src/sofa/core/objectmodel/Context.h Co-authored-by: Alex Bilger --- Sofa/framework/Core/src/sofa/core/objectmodel/Context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h b/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h index 01bdcce7af7..bd39233cb87 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h @@ -27,7 +27,7 @@ namespace sofa::core::objectmodel { /** - * \brief Compatibility layer - Context is now a subclass of BaseContext. + * \brief Compatibility layer - Context is now an alias of BaseContext. * All functionality has been merged into BaseContext. */ using Context = BaseContext; From 50cb78afa914f7e83b239e00c5e85525392174e1 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Wed, 9 Sep 2026 11:38:10 +0200 Subject: [PATCH 6/7] Add deprecation layer --- Sofa/framework/Core/src/sofa/core/config.h.in | 7 +++++++ Sofa/framework/Core/src/sofa/core/objectmodel/Context.h | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Sofa/framework/Core/src/sofa/core/config.h.in b/Sofa/framework/Core/src/sofa/core/config.h.in index 2215e894724..616e0e3ede1 100644 --- a/Sofa/framework/Core/src/sofa/core/config.h.in +++ b/Sofa/framework/Core/src/sofa/core/config.h.in @@ -127,3 +127,10 @@ SOFA_ATTRIBUTE_DEPRECATED("v26.06", "v29.06", "Use toBaseComponent instead.") #define SOFA_CORE_DEPRECATED_RENAME_CREATORMAP_OBJECTTEMPLATECREATORMAP() \ SOFA_ATTRIBUTE_DISABLED("v25.12", "v26.06", "Type CreatorMap has been renamed to ObjectTemplateCreatorMap.") #endif + +#ifdef SOFA_BUILD_SOFA_CORE +#define SOFA_CORE_DEPRECATED_REMOVE_CONTEXT() +#else +#define SOFA_CORE_DEPRECATED_REMOVE_CONTEXT() \ +SOFA_ATTRIBUTE_DISABLED("v26.12", "v27.12", "Use BaseContext instead of Context.") +#endif \ No newline at end of file diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h b/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h index bd39233cb87..63d4d47c207 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h @@ -30,6 +30,6 @@ namespace sofa::core::objectmodel * \brief Compatibility layer - Context is now an alias of BaseContext. * All functionality has been merged into BaseContext. */ -using Context = BaseContext; +using Context SOFA_CORE_DEPRECATED_REMOVE_CONTEXT() = BaseContext; } // namespace sofa::core::objectmodel From 05e034ecfe336ae50581cd8d3d302869a9a68cff Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Thu, 10 Sep 2026 15:01:41 +0200 Subject: [PATCH 7/7] Apply suggestion from @fredroy Co-authored-by: Frederick Roy --- Sofa/framework/Core/src/sofa/core/objectmodel/Context.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h b/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h index 63d4d47c207..1a270030a33 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h @@ -23,6 +23,9 @@ #include #include +SOFA_HEADER_DEPRECATED("v26.12", "v27.12", "sofa/core/objectmodel/BaseContext.h") + + namespace sofa::core::objectmodel {