Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
damienmarchal committed Jan 6, 2025
1 parent 0bc3fb9 commit d90053d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Distances : public core::DataEngine
DistancesInternalData<DataTypes> data;
friend class DistancesInternalData<DataTypes>;

Distances ( sofa::component::topology::container::dynamic::DynamicSparseGridTopologyContainer* hexaTopoContainer, core::behavior::MechanicalState<DataTypes>* targetPointSet );
Distances ();

~Distances() override {}

Expand Down Expand Up @@ -200,14 +200,15 @@ class Distances : public core::DataEngine
template<class T>
static typename T::SPtr create(T*, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg )
{
typename T::SPtr obj = sofa::core::objectmodel::New<T>(
( arg?dynamic_cast<sofa::component::topology::container::dynamic::DynamicSparseGridTopologyContainer*> ( arg->findObject ( arg->getAttribute ( "hexaContainerPath","../.." ) ) ) :nullptr ),
( arg?dynamic_cast<core::behavior::MechanicalState<DataTypes>*> ( arg->findObject ( arg->getAttribute ( "targetPath",".." ) ) ) :nullptr ) );
typename T::SPtr obj = sofa::core::objectmodel::New<T>();

if ( context ) context->addObject ( obj );

if ( arg )
{
obj->hexaContainer = dynamic_cast<sofa::component::topology::container::dynamic::DynamicSparseGridTopologyContainer*> ( arg->findObject ( arg->getAttribute ( "hexaContainerPath","../.." ) ) );
obj->target = dynamic_cast<core::behavior::MechanicalState<DataTypes>*> ( arg->findObject ( arg->getAttribute ( "targetPath",".." ) ) );

if ( arg->getAttribute ( "hexaContainerPath" ) )
{
obj->d_hexaContainerPath.setValue (arg->getAttribute ("hexaContainerPath" ) );
Expand All @@ -218,6 +219,7 @@ class Distances : public core::DataEngine
obj->d_targetPath.setValue (arg->getAttribute ("targetPath" ) );
arg->removeAttribute ( "targetPath" );
}

obj->parse ( arg );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using std::queue;
using sofa::core::loader::VoxelLoader;

template<class DataTypes>
Distances< DataTypes >::Distances ( sofa::component::topology::container::dynamic::DynamicSparseGridTopologyContainer* hexaTopoContainer, core::behavior::MechanicalState<DataTypes>* targetPointSet ) :
Distances< DataTypes >::Distances () :
d_showMapIndex (initData (&d_showMapIndex, (unsigned int)0, "showMapIndex", "Frame DOF index on which display values." ) ),
d_showDistanceMap (initData (&d_showDistanceMap, false, "showDistancesMap", "show the distance for each point of the target point set." ) ),
d_showGoalDistanceMap (initData (&d_showGoalDistanceMap, false, "showGoalDistancesMap", "show the distance for each point of the target point set." ) ),
Expand All @@ -54,9 +54,9 @@ Distances< DataTypes >::Distances ( sofa::component::topology::container::dynami
d_harmonicMaxValue (initData (&d_harmonicMaxValue, 100.0, "harmonicMaxValue", "Max value used to initialize the harmonic distance grid." ) ),
d_fileDistance(initData(&d_fileDistance, "filename", "file containing the result of the computation of the distances")),
d_targetPath(initData(&d_targetPath, "targetPath", "path to the goal point set topology")),
target ( targetPointSet ) ,
d_hexaContainerPath(initData(&d_hexaContainerPath, "hexaContainerPath", "path to the grid used to compute the distances")),
hexaContainer ( hexaTopoContainer )
//target ( targetPointSet ) ,
d_hexaContainerPath(initData(&d_hexaContainerPath, "hexaContainerPath", "path to the grid used to compute the distances"))
//hexaContainer ( hexaTopoContainer )
{
this->addAlias(&d_fileDistance, "d_fileDistance");
d_zonesFramePair.setDisplayed(false); // GUI can not display map.
Expand Down
43 changes: 41 additions & 2 deletions Sofa/framework/Core/src/sofa/core/ObjectFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ namespace sofa::core

class ObjectRegistrationData;

template<class T>
class HasCreateMethod
{
typedef char YesType[1];
typedef char NoType[2];

template<typename C> static YesType& test( decltype (&C::HasCreateMethod) );
template<typename C> static NoType& test(...);

public:
enum { value = sizeof(test<T>(0)) == sizeof(YesType) };
};

typedef std::function<void(sofa::core::objectmodel::Base*, sofa::core::objectmodel::BaseObjectDescription*)> OnCreateCallback ;
class SOFA_CORE_API ObjectFactory
{
Expand Down Expand Up @@ -263,10 +276,36 @@ class ObjectCreator : public ObjectFactory::Creator
RealObject* instance = nullptr;
return RealObject::canCreate(instance, context, arg);
}

objectmodel::BaseObject::SPtr createInstance(objectmodel::BaseContext* context, objectmodel::BaseObjectDescription* arg) override
{
RealObject* instance = nullptr;
return RealObject::create(instance, context, arg);
typename RealObject::SPtr obj;
if constexpr(HasCreateMethod<RealObject>::value)
{
obj = RealObject::create(context, arg);
msg_deprecated() << "This object was created using the RealObject::create method";
}
else{
obj = sofa::core::objectmodel::New<RealObject>();
}

if (obj)
{
if (context)
{
context->addObject(obj);
}
if (arg)
{
obj->parse(arg);
}
}
else
{
msg_info(RealObject::GetClass()->className) << "Cannot create an instance";
}

return obj;
}
const std::type_info& type() override
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class PairInteractionConstraint : public BaseInteractionConstraint, public PairS
template<class T>
static typename T::SPtr create(T* p0, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg)
{
typename T::SPtr obj = core::behavior::BaseInteractionConstraint::create(p0, context, arg);
typename T::SPtr obj = core::behavior::BaseInteractionConstraint::deprecated_create(p0, context, arg);

if (arg)
{
Expand Down
2 changes: 1 addition & 1 deletion Sofa/framework/Core/src/sofa/core/objectmodel/BaseObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class SOFA_CORE_API BaseObject : public virtual Base

/// Construction method called by ObjectFactory.
template<class T>
static typename T::SPtr create(T*, BaseContext* context, BaseObjectDescription* arg)
static typename T::SPtr deprecated_create(T*, BaseContext* context, BaseObjectDescription* arg)
{
typename T::SPtr obj = sofa::core::objectmodel::New<T>();
if (obj)
Expand Down

0 comments on commit d90053d

Please sign in to comment.