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/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/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/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/BaseContext.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.cpp index f457a402182..41e85dd8156 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 not change its sleeping state by default -bool BaseContext::canChangeSleepingState() const { return false; } +/// The Context can change its sleeping state +bool BaseContext::canChangeSleepingState() const +{ + return d_canChangeSleepingState.getValue(); +} +/// 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,32 @@ void BaseContext::notifyMoveSlave(core::objectmodel::BaseComponent* /*previousMa { } +bool BaseContext::addObject( sptr, TypeOfInsertion ) +{ + return false; +} + +bool BaseContext::removeObject( sptr ) +{ + return false; +} + + +////////////////// +// 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..1e78dda651c 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 { @@ -54,7 +55,6 @@ class SOFA_CORE_API BaseContext : public virtual Base using Vec3 = sofa::type::Vec3; -protected: BaseContext(); ~BaseContext() override; @@ -63,6 +63,15 @@ class SOFA_CORE_API BaseContext : public virtual Base 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 + 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. + /// 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(); @@ -74,33 +83,34 @@ class SOFA_CORE_API BaseContext : public virtual Base /// @{ /// The Context is active - virtual bool isActive() const; + virtual bool isActive() const ; /// State of the context - virtual void setActive(bool) {} + virtual void setActive(bool val) ; /// Sleeping state of the context - virtual bool isSleeping() const; + virtual bool isSleeping() const ; /// Whether the context can change its sleeping state or not - virtual bool canChangeSleepingState() const; + virtual bool canChangeSleepingState() const ; /// Simulation time - virtual SReal getTime() const; + virtual SReal getTime() const ; /// Simulation timestep - virtual SReal getDt() const; + virtual SReal getDt() const ; /// Animation flag - virtual bool getAnimate() const; + virtual bool getAnimate() const ; /// @} + /// Simulation time + virtual void setTime(SReal t); /// Gravity in local coordinates virtual const Vec3& getGravity() const; /// Gravity in local coordinates - virtual void setGravity( const Vec3& ) - { } + virtual void setGravity( const Vec3& g); /// Get the root context of the graph virtual BaseContext* getRootContext() const; @@ -316,24 +326,28 @@ class SOFA_CORE_API BaseContext : public virtual Base /// @name Parameters Setters /// @{ - /// Simulation timestep - virtual void setDt( SReal /*dt*/ ) - { } + virtual void setDt( SReal dt ); /// Animation flag - virtual void setAnimate(bool /*val*/) - { } + virtual void setAnimate(bool val); /// Sleeping state of the context - virtual void setSleeping(bool /*val*/) - { } + virtual void setSleeping(bool val); /// Sleeping state change of the context - virtual void setChangeSleepingState(bool /*val*/) - { } + virtual void setChangeSleepingState(bool val); + + /// 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 /// @{ @@ -362,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*/ ); /// @} 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 2c9c3ec331f..00000000000 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Context.cpp +++ /dev/null @@ -1,144 +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::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); -} - -/// The Context is active -bool Context::isActive() const {return is_activated.getValue();} - -/// State of the context -void Context::setActive(bool val) -{ - is_activated.setValue(val); -} - -/// The Context is sleeping -bool Context::isSleeping() const -{ - return d_isSleeping.getValue(); -} - -/// Sleeping state of the context -void Context::setSleeping(bool val) -{ - d_isSleeping.setValue(val); -} - -/// The Context can change its sleeping state -bool Context::canChangeSleepingState() const -{ - return d_canChangeSleepingState.getValue(); -} - -/// Sleeping state change of the context -void Context::setChangeSleepingState(bool val) -{ - d_canChangeSleepingState.setValue(val); -} - - - -/// Simulation timestep -SReal Context::getDt() const -{ - return dt_.getValue(); -} - -/// Simulation time -SReal Context::getTime() const -{ - return time_.getValue(); -} - -/// Gravity vector in world coordinates -const Context::Vec3& Context::getGravity() const -{ - return worldGravity_.getValue(); -} - -/// Animation flag -bool Context::getAnimate() const -{ - return animate_.getValue(); -} - -//=============================================================================== - -/// Simulation timestep -void Context::setDt(SReal dt) -{ - dt_.setValue(dt); -} - -/// Simulation time -void Context::setTime(SReal t) -{ - time_.setValue(t); -} - -/// Gravity vector -void Context::setGravity(const Vec3& g) -{ - worldGravity_ .setValue(g); -} - -/// Animation flag -void Context::setAnimate(const bool val) -{ - animate_.setValue(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; - - 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()); -} -} // 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..1a270030a33 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/Context.h @@ -23,89 +23,16 @@ #include #include +SOFA_HEADER_DEPRECATED("v26.12", "v27.12", "sofa/core/objectmodel/BaseContext.h") + + namespace sofa::core::objectmodel { /** - * \brief Implementation of BaseContext, storing all shared parameters in Datas. - * + * \brief Compatibility layer - Context is now an alias of BaseContext. + * All functionality has been merged into BaseContext. */ -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. - -protected: - Context(); - virtual ~Context() override - {} - -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) { worldGravity_.setDisplayed(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 SOFA_CORE_DEPRECATED_REMOVE_CONTEXT() = BaseContext; -}; } // namespace sofa::core::objectmodel diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.cpp index 11a9c821a38..09e23794549 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