Skip to content

Commit 24d5af0

Browse files
authored
Merge pull request #7 from hugtalbot/202502_clean_and_registration
Update with the new registration mechanism
2 parents 7b5bf99 + 76b2a00 commit 24d5af0

4 files changed

Lines changed: 65 additions & 41 deletions

File tree

src/SofaMJEDFEM/MJEDTetrahedralForceField.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ namespace sofa::component::forcefield
3434
using namespace sofa::defaulttype;
3535

3636
// Register in the Factory
37-
int MJEDTetrahedralForceFieldClass = core::RegisterObject("Tetrahedral FEM model of visco-hyperelastic material using MJED")
38-
.add< MJEDTetrahedralForceField<Vec3Types> >()
39-
;
37+
void registerMJEDTetrahedralForceField(sofa::core::ObjectFactory* factory)
38+
{
39+
factory->registerObjects(core::ObjectRegistrationData("Tetrahedral FEM model of visco-hyperelastic material using MJED")
40+
.add< MJEDTetrahedralForceField<Vec3Types> >());
41+
}
4042

4143
template class SOFA_MJED_FEM_API MJEDTetrahedralForceField<Vec3Types>;
4244

src/SofaMJEDFEM/MJEDTetrahedralForceField.inl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ void MJEDTetrahedralForceField<DataTypes>::createTetrahedronRestInformation(unsi
114114
materialTermArray = myMaterial->getMaterialTermArray();
115115
typename vector<HyperelasticMatTerm *>::iterator it;
116116
it=materialTermArray.begin();
117-
int id=0;
118117
std::vector<Real> number;
119118
Real coefficient=0;
120119
tinfo.coeff.resize(0);
@@ -181,7 +180,6 @@ void MJEDTetrahedralForceField<DataTypes>::createTetrahedronRestInformation(unsi
181180
tinfo.Lij_second_k.push_back( Lijsecond );
182181
}
183182

184-
id++;
185183
tinfo.functionf.push_back(1);
186184
tinfo.functiong.push_back(1);
187185
tinfo.functionDf.push_back(0);

src/SofaMJEDFEM/config.h.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,9 @@
3232
#else
3333
# define SOFA_MJED_FEM_API SOFA_IMPORT_DYNAMIC_LIBRARY
3434
#endif
35+
36+
namespace sofamjedfem
37+
{
38+
constexpr const char* MODULE_NAME = "@PROJECT_NAME@";
39+
constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@";
40+
} // namespace sofamjedfem

src/SofaMJEDFEM/initSofaMJEDFEM.cpp

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,54 +21,72 @@
2121
******************************************************************************/
2222
#include <SofaMJEDFEM/config.h>
2323
#include <sofa/core/ObjectFactory.h>
24+
#include <sofa/helper/system/PluginManager.h>
25+
2426
using sofa::core::ObjectFactory;
2527

26-
namespace sofa::component
28+
namespace sofamjedfem
2729
{
30+
extern void registerMJEDTetrahedralForceField(sofa::core::ObjectFactory *factory);
31+
} // namespace sofamjedfem
2832

29-
extern "C" {
30-
SOFA_MJED_FEM_API void initExternalModule();
31-
SOFA_MJED_FEM_API const char* getModuleName();
32-
SOFA_MJED_FEM_API const char* getModuleVersion();
33-
SOFA_MJED_FEM_API const char* getModuleLicense();
34-
SOFA_MJED_FEM_API const char* getModuleDescription();
35-
SOFA_MJED_FEM_API const char* getModuleComponentList();
36-
}
3733

38-
void initExternalModule()
34+
namespace sofa::component
3935
{
40-
static bool first = true;
41-
if (first)
36+
using namespace sofamjedfem;
37+
38+
extern "C" {
39+
SOFA_MJED_FEM_API void initExternalModule();
40+
SOFA_MJED_FEM_API const char* getModuleName();
41+
SOFA_MJED_FEM_API const char* getModuleVersion();
42+
SOFA_MJED_FEM_API const char* getModuleLicense();
43+
SOFA_MJED_FEM_API const char* getModuleDescription();
44+
SOFA_MJED_FEM_API const char* getModuleComponentList();
45+
SOFA_MJED_FEM_API void registerObjects(sofa::core::ObjectFactory* factory);
46+
}
47+
48+
void initExternalModule()
4249
{
43-
first = false;
50+
static bool first = true;
51+
if (first)
52+
{
53+
// make sure that this plugin is registered into the PluginManager
54+
sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME);
55+
56+
first = false;
57+
}
4458
}
45-
}
4659

47-
const char* getModuleName()
48-
{
49-
return sofa_tostring(SOFA_TARGET);
50-
}
60+
const char* getModuleName()
61+
{
62+
return sofa_tostring(SOFA_TARGET);
63+
}
5164

52-
const char* getModuleVersion()
53-
{
54-
return sofa_tostring(SOFAMJEDFEM_VERSION);
55-
}
65+
const char* getModuleVersion()
66+
{
67+
return sofa_tostring(SOFAMJEDFEM_VERSION);
68+
}
5669

57-
const char* getModuleLicense()
58-
{
59-
return "LGPL";
60-
}
70+
const char* getModuleLicense()
71+
{
72+
return "LGPL";
73+
}
6174

62-
const char* getModuleDescription()
63-
{
64-
return "This plugin implements the Multiplicative Jacobian Energy Decomposition or MJED method.";
65-
}
75+
const char* getModuleDescription()
76+
{
77+
return "This plugin implements the Multiplicative Jacobian Energy Decomposition or MJED method.";
78+
}
6679

67-
const char* getModuleComponentList()
68-
{
69-
/// string containing the names of the classes provided by the plugin
70-
static std::string classes = ObjectFactory::getInstance()->listClassesFromTarget(sofa_tostring(SOFA_TARGET));
71-
return classes.c_str();
72-
}
80+
const char* getModuleComponentList()
81+
{
82+
/// string containing the names of the classes provided by the plugin
83+
static std::string classes = ObjectFactory::getInstance()->listClassesFromTarget(sofa_tostring(SOFA_TARGET));
84+
return classes.c_str();
85+
}
86+
87+
void registerObjects(sofa::core::ObjectFactory* factory)
88+
{
89+
registerMJEDTetrahedralForceField(factory);
90+
}
7391

7492
} // namespace sofa::component

0 commit comments

Comments
 (0)