From 41c06b27562e9885ef30dd1a00a8632bc94a1455 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Mon, 2 Sep 2024 10:26:15 +0900 Subject: [PATCH] apply new register mechanism to sceneutility --- .../component/sceneutility/APIVersion.cpp | 15 ++++++++--- .../sceneutility/AddResourceRepository.cpp | 18 +++++++------ .../component/sceneutility/InfoComponent.cpp | 13 ++++++--- .../sceneutility/MakeAliasComponent.cpp | 17 ++++++++---- .../sceneutility/MakeDataAliasComponent.cpp | 16 +++++++---- .../sceneutility/MessageHandlerComponent.cpp | 12 ++++----- .../sceneutility/PauseAnimationOnEvent.cpp | 10 +++---- .../src/sofa/component/sceneutility/init.cpp | 27 +++++++++++++++++++ Sofa/Component/src/sofa/component/init.cpp | 1 + 9 files changed, 92 insertions(+), 37 deletions(-) diff --git a/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/APIVersion.cpp b/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/APIVersion.cpp index 6bb3768e0f2..94f8f46bafb 100644 --- a/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/APIVersion.cpp +++ b/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/APIVersion.cpp @@ -26,13 +26,15 @@ using sofa::core::objectmodel::BaseNode ; #include using sofa::core::ObjectFactory ; -using sofa::core::RegisterObject ; #include #include #include -namespace sofa::component::sceneutility::_apiversion_ +namespace sofa::component::sceneutility +{ + +namespace _apiversion_ { APIVersion::APIVersion() : @@ -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 diff --git a/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/AddResourceRepository.cpp b/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/AddResourceRepository.cpp index 438ff560754..3afbc6b2c91 100644 --- a/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/AddResourceRepository.cpp +++ b/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/AddResourceRepository.cpp @@ -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 diff --git a/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/InfoComponent.cpp b/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/InfoComponent.cpp index f15860a936b..51ed3b80a68 100644 --- a/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/InfoComponent.cpp +++ b/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/InfoComponent.cpp @@ -25,8 +25,13 @@ using sofa::core::RegisterObject ; #include -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 diff --git a/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/MakeAliasComponent.cpp b/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/MakeAliasComponent.cpp index cb81974d15e..fca69383c2d 100644 --- a/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/MakeAliasComponent.cpp +++ b/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/MakeAliasComponent.cpp @@ -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() : @@ -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 diff --git a/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/MakeDataAliasComponent.cpp b/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/MakeDataAliasComponent.cpp index 21927f66fb5..6b660d084d1 100644 --- a/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/MakeDataAliasComponent.cpp +++ b/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/MakeDataAliasComponent.cpp @@ -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() @@ -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 diff --git a/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/MessageHandlerComponent.cpp b/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/MessageHandlerComponent.cpp index 90ac4caf386..71c57151b40 100644 --- a/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/MessageHandlerComponent.cpp +++ b/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/MessageHandlerComponent.cpp @@ -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() : diff --git a/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/PauseAnimationOnEvent.cpp b/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/PauseAnimationOnEvent.cpp index 8c48c9e8875..062bb3ccab8 100644 --- a/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/PauseAnimationOnEvent.cpp +++ b/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/PauseAnimationOnEvent.cpp @@ -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 diff --git a/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/init.cpp b/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/init.cpp index 1a27e0896e6..1daa9e7019f 100644 --- a/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/init.cpp +++ b/Sofa/Component/SceneUtility/src/sofa/component/sceneutility/init.cpp @@ -21,13 +21,25 @@ ******************************************************************************/ #include #include +#include + 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() @@ -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; } } diff --git a/Sofa/Component/src/sofa/component/init.cpp b/Sofa/Component/src/sofa/component/init.cpp index b037b4eea72..36101c18a69 100644 --- a/Sofa/Component/src/sofa/component/init.cpp +++ b/Sofa/Component/src/sofa/component/init.cpp @@ -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()