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

[Setting] Apply new factory registration mechanism #4931

Merged
merged 2 commits into from
Aug 30, 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,10 +26,11 @@
namespace sofa::component::setting
{

int BackgroundSettingClass = core::RegisterObject("Background setting")
.add< BackgroundSetting >()
.addAlias("Background")
;
void registerBackgroundSetting(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Background setting.")
.add< BackgroundSetting >());
}

BackgroundSetting::BackgroundSetting():
d_color(initData(&d_color, "color", "Color of the background")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
namespace sofa::component::setting
{

int SofaDefaultPathSettingClass = core::RegisterObject("Default Paths for Sofa Application")
.add< SofaDefaultPathSetting >()
.addAlias("SofaDefaultPath")
;
void registerSofaDefaultPathSetting(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Default Paths for Sofa Application.")
.add< SofaDefaultPathSetting >());
}

SofaDefaultPathSetting::SofaDefaultPathSetting():
d_gnuplotPath(initData(&d_gnuplotPath, "gnuplotPath", "Path where will be saved the gnuplot files"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
namespace sofa::component::setting
{

int StatsSettingClass = core::RegisterObject("Stats settings")
.add< StatsSetting >()
.addAlias("Stats")
;
void registerStatsSetting(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Stats settings.")
.add< StatsSetting >());
}

StatsSetting::StatsSetting():
d_dumpState(initData(&d_dumpState, false, "dumpState", "Dump state vectors at each time step of the simulation"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ namespace sofa::component::setting
using namespace sofa::type;
using namespace sofa::helper;

int ViewerSettingClass = core::RegisterObject("Configuration for the Viewer of your application")
.add< ViewerSetting >()
.addAlias("Viewer")
;
void registerViewerSetting(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Configuration for the Viewer of your application.")
.add< ViewerSetting >());
}

ViewerSetting::ViewerSetting()
: d_resolution(initData(&d_resolution, Vec<2,int>(800, 600), "resolution", "resolution of the Viewer"))
Expand Down
19 changes: 19 additions & 0 deletions Sofa/Component/Setting/src/sofa/component/setting/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@
******************************************************************************/
#include <sofa/component/setting/init.h>
#include <sofa/core/ObjectFactory.h>
#include <sofa/helper/system/PluginManager.h>

namespace sofa::component::setting
{

extern void registerBackgroundSetting(sofa::core::ObjectFactory* factory);
extern void registerSofaDefaultPathSetting(sofa::core::ObjectFactory* factory);
extern void registerStatsSetting(sofa::core::ObjectFactory* factory);
extern void registerViewerSetting(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 +53,22 @@ const char* getModuleVersion()
return MODULE_VERSION;
}

void registerObjects(sofa::core::ObjectFactory* factory)
{
registerBackgroundSetting(factory);
registerSofaDefaultPathSetting(factory);
registerStatsSetting(factory);
registerViewerSetting(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 @@ -75,6 +75,7 @@ void registerObjects(sofa::core::ObjectFactory* factory)
{
factory->registerObjectsFromPlugin("Sofa.Component.AnimationLoop");
factory->registerObjectsFromPlugin("Sofa.Component.StateContainer");
factory->registerObjectsFromPlugin("Sofa.Component.Setting");
factory->registerObjectsFromPlugin("Sofa.Component.Visual");
}

Expand Down
7 changes: 6 additions & 1 deletion Sofa/framework/Helper/src/sofa/helper/ComponentChange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,12 @@ const std::map< std::string, Dealiased, std::less<> > dealiasedComponents = {
{"MasterConstraintSolver", Dealiased("v24.12","ConstraintAnimationLoop")},
{"FreeMotionMasterSolver", Dealiased("v24.12","FreeMotionAnimationLoop")},
{"MultiStepMasterSolver", Dealiased("v24.12","MultiStepAnimationLoop")},
{"MultiTagMasterSolver", Dealiased("v24.12","MultiTagAnimationLoop")}
{"MultiTagMasterSolver", Dealiased("v24.12","MultiTagAnimationLoop")},
{"Background", Dealiased("v24.12","BackgroundSetting")},
{"SofaDefaultPath", Dealiased("v24.12","SofaDefaultPathSetting")},
{"Stats", Dealiased("v24.12","StatsSetting")},
{"Viewer", Dealiased("v24.12","ViewerSetting")},

};

} // namespace sofa::helper::lifecycle
Loading