Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <sofa/core/behavior/Mass.inl>
#include <sofa/core/fwd.h>
#include <sofa/core/visual/VisualParams.h>
#include <sofa/core/objectmodel/Context.h>
#include <sofa/core/objectmodel/BaseContext.h>
#include <sofa/helper/accessor.h>
#include <sofa/defaulttype/DataTypeInfo.h>
#include <sofa/component/mass/AddMToMatrixFunctor.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <sofa/component/visual/VisualStyle.h>

#include <sofa/core/visual/VisualParams.h>
#include <sofa/core/objectmodel/Context.h>
#include <sofa/core/objectmodel/BaseContext.h>
#include <sofa/core/ObjectFactory.h>
#include <sofa/simulation/Node.h>
namespace sofa::component::visual
Expand Down
1 change: 0 additions & 1 deletion Sofa/framework/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sofa/framework/Core/src/sofa/core/collision/Contact.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <sofa/core/collision/DetectionOutput.h>
#include <sofa/core/collision/Intersection.h>
#include <sofa/core/objectmodel/Context.h>
#include <sofa/core/objectmodel/BaseContext.h>
#include <sofa/helper/Factory.h>

#include <vector>
Expand Down
7 changes: 7 additions & 0 deletions Sofa/framework/Core/src/sofa/core/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
113 changes: 102 additions & 11 deletions Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{}
Expand All @@ -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);
}


Expand Down Expand Up @@ -208,4 +271,32 @@ void BaseContext::notifyMoveSlave(core::objectmodel::BaseComponent* /*previousMa
{
}

bool BaseContext::addObject( sptr<sofa::core::objectmodel::BaseComponent>, TypeOfInsertion )
{
return false;
}

bool BaseContext::removeObject( sptr<sofa::core::objectmodel::BaseComponent> )
{
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
62 changes: 35 additions & 27 deletions Sofa/framework/Core/src/sofa/core/objectmodel/BaseContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <sofa/core/objectmodel/ClassInfo.h>
#include <sofa/core/objectmodel/TypeOfInsertion.h>
#include <sofa/core/ComponentNameHelper.h>
#include <sofa/core/objectmodel/Data.h>

namespace sofa::simulation
{
Expand Down Expand Up @@ -54,7 +55,6 @@ class SOFA_CORE_API BaseContext : public virtual Base

using Vec3 = sofa::type::Vec3;

protected:
BaseContext();
~BaseContext() override;

Expand All @@ -63,6 +63,15 @@ class SOFA_CORE_API BaseContext : public virtual Base
BaseContext& operator=(const BaseContext& );

public:
/// Data members from Context
Data<bool> is_activated; ///< To Activate a node
Data<Vec3> worldGravity_; ///< Gravity in the world coordinate system
Data<SReal> dt_; ///< Time step
Data<SReal> time_; ///< Current time
Data<bool> animate_; ///< Animate the Simulation(applied at initialization only)
Data<bool> d_isSleeping; ///< The node is sleeping, and thus ignored by visitors.
Data<bool> 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();
Expand All @@ -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;
Expand Down Expand Up @@ -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
/// @{

Expand Down Expand Up @@ -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<sofa::core::objectmodel::BaseComponent> /*obj*/, TypeOfInsertion = TypeOfInsertion::AtEnd)
{
return false;
}
virtual bool addObject( sptr<sofa::core::objectmodel::BaseComponent> /*obj*/, TypeOfInsertion = TypeOfInsertion::AtEnd);

/// Remove an object, or return false if not supported
virtual bool removeObject( sptr<sofa::core::objectmodel::BaseComponent> /*obj*/ )
{
return false;
}
virtual bool removeObject( sptr<sofa::core::objectmodel::BaseComponent> /*obj*/ );

/// @}

Expand Down
Loading
Loading