Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SceneUtility] Apply new factory registration mechanism #4932

Merged
merged 2 commits into from
Sep 4, 2024
Merged
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 @@ -26,13 +26,15 @@ using sofa::core::objectmodel::BaseNode ;

#include <sofa/core/ObjectFactory.h>
using sofa::core::ObjectFactory ;
using sofa::core::RegisterObject ;

#include <sofa/component/sceneutility/APIVersion.h>
#include <sofa/version.h>
#include <numeric>

namespace sofa::component::sceneutility::_apiversion_
namespace sofa::component::sceneutility
{

namespace _apiversion_
{

APIVersion::APIVersion() :
Expand Down Expand Up @@ -76,7 +78,12 @@ const std::string& APIVersion::getApiLevel()
return d_level.getValue() ;
}

int APIVersionClass = core::RegisterObject("Specify the APIVersion of the component used in a scene.")
.add< APIVersion >();
} // namespace _apiversion_

void registerAPIVersion(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Specify the APIVersion of the component used in a scene.")
.add< APIVersion >());
}

} // namespace sofa::component::sceneutility
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,16 @@ void BaseAddResourceRepository::cleanup()
m_repository->removePath(m_currentAddedPath);
}

void registerAddDataRepository(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Add a path to DataRepository.")
.add< AddDataRepository >());
}

static int AddDataRepositoryClass = core::RegisterObject("Add a path to DataRepository")
.add< AddDataRepository >()
.addAlias("AddResourceRepository") // Backward compatibility
;

static int AddPluginRepositoryClass = core::RegisterObject("Add a path to PluginRepository")
.add< AddPluginRepository >();

void registerAddPluginRepository(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Add a path to PluginRepository.")
.add< AddPluginRepository >());
}

} // namespace sofa::component::sceneutility
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ using sofa::core::RegisterObject ;

#include <sofa/component/sceneutility/InfoComponent.h>

namespace sofa::component::sceneutility::infocomponent
namespace sofa::component::sceneutility
{
int InfoComponentClass = RegisterObject("This object retain the info/error message")
.add< InfoComponent >();
} // namespace sofa::component::sceneutility::infocomponent

void registerInfoComponent(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("This object retain the info/error message.")
.add< InfoComponent >());
}

} // namespace sofa::component::sceneutility
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ using sofa::core::objectmodel::ComponentState ;

using std::string;

namespace sofa::component::sceneutility::makealiascomponent
namespace sofa::component::sceneutility
{

namespace makealiascomponent
{

MakeAliasComponent::MakeAliasComponent() :
Expand Down Expand Up @@ -77,8 +80,12 @@ void MakeAliasComponent::parse ( core::objectmodel::BaseObjectDescription* arg )
d_componentState.setValue(ComponentState::Valid) ;
}

int MakeAliasComponentClass = RegisterObject("This object create an alias to a component name to make the scene more readable. ")
.add< MakeAliasComponent >()
;
} // namespace makealiascomponent

void registerMakeAliasComponent(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("This object creates an alias to a component name to make the scene more readable.")
.add< MakeAliasComponent >());
}

} // namespace sofa::component::sceneutility::makealiascomponent
} // namespace sofa::component::sceneutility
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ using sofa::core::objectmodel::ComponentState ;

using std::string;

namespace sofa::component::sceneutility::makedataaliascomponent
namespace sofa::component::sceneutility
{

namespace makedataaliascomponent
{

MakeDataAliasComponent::MakeDataAliasComponent()
Expand Down Expand Up @@ -107,9 +110,12 @@ void MakeDataAliasComponent::parse ( core::objectmodel::BaseObjectDescription* a

d_componentState.setValue(ComponentState::Valid);
}
} // namespace makedataaliascomponent

int MakeDataAliasComponentClass = RegisterObject("This object create an alias to a data field. ")
.add< MakeDataAliasComponent >()
;
void registerMakeDataAliasComponent(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("This object creates an alias to a data field.")
.add< MakeDataAliasComponent >());
}

} // namespace sofa::component::sceneutility::makedataaliascomponent
} // namespace sofa::component::sceneutility
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ void MessageHandlerComponent::parse ( core::objectmodel::BaseObjectDescription*
m_isValid = true ;
}

int MessageHandlerComponentClass = RegisterObject("This object controls the way Sofa print's "
"info/warning/error/fatal messages. ")
.add< MessageHandlerComponent >()
;


void registerMessageHandlerComponent(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("This object controls the way Sofa print's "
"info/warning/error/fatal messages. ")
.add< MessageHandlerComponent >());
}

////////////////////////// FileMessageHandlerComponent ////////////////////////////////////
FileMessageHandlerComponent::FileMessageHandlerComponent() :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ void PauseAnimationOnEvent::handleEvent(sofa::core::objectmodel::Event* event)
}
}

int PauseAnimationOnEventClass = core::RegisterObject("PauseAnimationOnEvent")
.add< PauseAnimationOnEvent >();



void registerPauseAnimationOnEvent(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("This component pauses the simulation when receiving a PauseEvent.")
.add< PauseAnimationOnEvent >());
}

} // namespace sofa::component::sceneutility
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,25 @@
******************************************************************************/
#include <sofa/component/sceneutility/init.h>
#include <sofa/core/ObjectFactory.h>
#include <sofa/helper/system/PluginManager.h>

namespace sofa::component::sceneutility
{

extern void registerAddDataRepository(sofa::core::ObjectFactory* factory);
extern void registerAddPluginRepository(sofa::core::ObjectFactory* factory);
extern void registerAPIVersion(sofa::core::ObjectFactory* factory);
extern void registerInfoComponent(sofa::core::ObjectFactory* factory);;
extern void registerMakeAliasComponent(sofa::core::ObjectFactory* factory);
extern void registerMakeDataAliasComponent(sofa::core::ObjectFactory* factory);
extern void registerMessageHandlerComponent(sofa::core::ObjectFactory* factory);
extern void registerPauseAnimationOnEvent(sofa::core::ObjectFactory* factory);

extern "C" {
SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule();
SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName();
SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion();
SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory);
}

void initExternalModule()
Expand All @@ -45,11 +57,26 @@ const char* getModuleVersion()
return MODULE_VERSION;
}

void registerObjects(sofa::core::ObjectFactory* factory)
{
registerAddDataRepository(factory);
registerAddPluginRepository(factory);
registerAPIVersion(factory);
registerInfoComponent(factory);;
registerMakeAliasComponent(factory);
registerMakeDataAliasComponent(factory);
registerMessageHandlerComponent(factory);
registerPauseAnimationOnEvent(factory);
}

void init()
{
static bool first = true;
if (first)
{
// make sure that this plugin is registered into the PluginManager
sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME);

first = false;
}
}
Expand Down
1 change: 1 addition & 0 deletions Sofa/Component/src/sofa/component/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void registerObjects(sofa::core::ObjectFactory* factory)
factory->registerObjectsFromPlugin("Sofa.Component.StateContainer");
factory->registerObjectsFromPlugin("Sofa.Component.Setting");
factory->registerObjectsFromPlugin("Sofa.Component.Visual");
factory->registerObjectsFromPlugin("Sofa.Component.SceneUtility");
}

void init()
Expand Down
Loading