diff --git a/PluginExample_test/MyBehaviorModel_test.cpp b/PluginExample_test/MyBehaviorModel_test.cpp index e746b52..55e2540 100644 --- a/PluginExample_test/MyBehaviorModel_test.cpp +++ b/PluginExample_test/MyBehaviorModel_test.cpp @@ -26,16 +26,17 @@ using std::vector; #include using sofa::testing::BaseTest; - using ::testing::Types; +using namespace pluginexample; + namespace { class MyBehaviorModel_test : public BaseTest, public ::testing::WithParamInterface { public: - using MyBehaviorModel = sofa::component::behaviormodel::MyBehaviorModel; + using MyBehaviorModel = pluginexample::MyBehaviorModel; void doTearDown() override { diff --git a/src/PluginExample/MyBehaviorModel.cpp b/src/PluginExample/MyBehaviorModel.cpp index 904b992..80d9cb0 100644 --- a/src/PluginExample/MyBehaviorModel.cpp +++ b/src/PluginExample/MyBehaviorModel.cpp @@ -24,7 +24,7 @@ #include -namespace sofa::component::behaviormodel +namespace pluginexample { MyBehaviorModel::MyBehaviorModel() @@ -52,8 +52,11 @@ void MyBehaviorModel::updatePosition(double dt) SOFA_UNUSED(dt); } -int MyBehaviorModelClass = core::RegisterObject("Dummy component with a custom widget.").add< MyBehaviorModel >(); - +void registerMyBehaviorModel(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Dummy component with a custom widget.") + .add< MyBehaviorModel >()); +} -} // namespace sofa::component::behaviormodel +} // namespace pluginexample diff --git a/src/PluginExample/MyBehaviorModel.h b/src/PluginExample/MyBehaviorModel.h index 7c6742e..47c788d 100644 --- a/src/PluginExample/MyBehaviorModel.h +++ b/src/PluginExample/MyBehaviorModel.h @@ -26,7 +26,7 @@ #include -namespace sofa::component::behaviormodel +namespace pluginexample { /** @@ -52,5 +52,5 @@ class SOFA_PLUGINEXAMPLE_API MyBehaviorModel : public sofa::core::BehaviorModel }; -} // sofa::component::behaviormodel +} // namespace pluginexample diff --git a/src/PluginExample/MyDataWidgetUnsigned.cpp b/src/PluginExample/MyDataWidgetUnsigned.cpp index 417f9cf..83b85cf 100644 --- a/src/PluginExample/MyDataWidgetUnsigned.cpp +++ b/src/PluginExample/MyDataWidgetUnsigned.cpp @@ -24,7 +24,7 @@ #include -namespace sofa::gui::qt +namespace pluginexample { /* @@ -112,4 +112,4 @@ void MyDataWidgetUnsigned::change() } -} // namespace sofa::gui::qt +} // namespace pluginexample \ No newline at end of file diff --git a/src/PluginExample/MyDataWidgetUnsigned.h b/src/PluginExample/MyDataWidgetUnsigned.h index e14b98f..64f1a73 100644 --- a/src/PluginExample/MyDataWidgetUnsigned.h +++ b/src/PluginExample/MyDataWidgetUnsigned.h @@ -31,7 +31,7 @@ #include -namespace sofa::gui::qt +namespace pluginexample { /** @@ -65,4 +65,4 @@ protected slots: }; -} // namespace sofa::gui::qt +} // namespace pluginexample \ No newline at end of file diff --git a/src/PluginExample/MyMappingPendulumInPlane.cpp b/src/PluginExample/MyMappingPendulumInPlane.cpp index c482911..ec32394 100644 --- a/src/PluginExample/MyMappingPendulumInPlane.cpp +++ b/src/PluginExample/MyMappingPendulumInPlane.cpp @@ -27,21 +27,21 @@ #include -namespace sofa::component::mapping +namespace pluginexample { using namespace sofa::defaulttype; - -int MyMappingPendulumInPlaneClass = core::RegisterObject("Mapping from an angle to a point in 2D") +void registerMyMappingPendulumInPlane(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Mapping from an angle to a point in 2D.") .add< MyMappingPendulumInPlane >() - .add< MyMappingPendulumInPlane >() -; + .add< MyMappingPendulumInPlane >()); +} template class SOFA_PLUGINEXAMPLE_API MyMappingPendulumInPlane; template class SOFA_PLUGINEXAMPLE_API MyMappingPendulumInPlane; -} // namespace sofa::component::mapping - +} // namespace pluginexample diff --git a/src/PluginExample/MyMappingPendulumInPlane.h b/src/PluginExample/MyMappingPendulumInPlane.h index 362ecf7..8a091fb 100644 --- a/src/PluginExample/MyMappingPendulumInPlane.h +++ b/src/PluginExample/MyMappingPendulumInPlane.h @@ -28,7 +28,7 @@ #include -namespace sofa::component::mapping +namespace pluginexample { using type::vector; @@ -84,5 +84,5 @@ class MyMappingPendulumInPlane: public core::Mapping vector gap; }; -} // namespace sofa::component::mapping +} // namespace pluginexample diff --git a/src/PluginExample/MyMappingPendulumInPlane.inl b/src/PluginExample/MyMappingPendulumInPlane.inl index 4cf1413..319e793 100644 --- a/src/PluginExample/MyMappingPendulumInPlane.inl +++ b/src/PluginExample/MyMappingPendulumInPlane.inl @@ -32,7 +32,7 @@ using std::cerr; using std::endl; -namespace sofa::component::mapping +namespace pluginexample { using helper::ReadAccessor; @@ -206,4 +206,4 @@ void MyMappingPendulumInPlane::applyDJT(const core::MechanicalParams* m } -} // namespace sofa::component::mapping +} // namespace pluginexample diff --git a/src/PluginExample/MyProjectiveConstraintSet.cpp b/src/PluginExample/MyProjectiveConstraintSet.cpp index 21d7052..f95c58a 100644 --- a/src/PluginExample/MyProjectiveConstraintSet.cpp +++ b/src/PluginExample/MyProjectiveConstraintSet.cpp @@ -24,21 +24,22 @@ #include -namespace sofa::component::projectiveconstraintset +namespace pluginexample { - + using namespace sofa::defaulttype; - -int MyProjectiveConstraintSetClass = core::RegisterObject("just an example of templated component") +void registerMyProjectiveConstraintSet(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Just an example of templated component.") .add< MyProjectiveConstraintSet >() .add< MyProjectiveConstraintSet >() - .add< MyProjectiveConstraintSet >() -; + .add< MyProjectiveConstraintSet >()); +} template class SOFA_PLUGINEXAMPLE_API MyProjectiveConstraintSet; template class SOFA_PLUGINEXAMPLE_API MyProjectiveConstraintSet; -} // namespace sofa::component::projectiveconstraintset +} // namespace pluginexample diff --git a/src/PluginExample/MyProjectiveConstraintSet.h b/src/PluginExample/MyProjectiveConstraintSet.h index 68e015e..9f9e45c 100644 --- a/src/PluginExample/MyProjectiveConstraintSet.h +++ b/src/PluginExample/MyProjectiveConstraintSet.h @@ -28,7 +28,7 @@ #include -namespace sofa::component::projectiveconstraintset +namespace pluginexample { template diff --git a/src/PluginExample/MyProjectiveConstraintSet.inl b/src/PluginExample/MyProjectiveConstraintSet.inl index 145b815..7518796 100644 --- a/src/PluginExample/MyProjectiveConstraintSet.inl +++ b/src/PluginExample/MyProjectiveConstraintSet.inl @@ -24,7 +24,7 @@ #include -namespace sofa::component::projectiveconstraintset +namespace pluginexample { template @@ -52,4 +52,4 @@ void MyProjectiveConstraintSet::reinit() -} // namespace sofa::component::projectiveconstraintset +} // namespace pluginexample diff --git a/src/PluginExample/MyVisualModel.cpp b/src/PluginExample/MyVisualModel.cpp index 7358c51..d1aabbc 100644 --- a/src/PluginExample/MyVisualModel.cpp +++ b/src/PluginExample/MyVisualModel.cpp @@ -24,7 +24,7 @@ #include -namespace sofa::component::visual +namespace pluginexample { MyVisualModel::MyVisualModel() @@ -44,8 +44,11 @@ void MyVisualModel::reinit() { } -int MyVisualModelClass = core::RegisterObject("Dummy visual component.").add< MyVisualModel >(); - +void registerMyVisualModel(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(core::ObjectRegistrationData("Dummy visual component.") + .add< MyVisualModel >()); +} -} // namespace sofa::component::visual +} // namespace pluginexample diff --git a/src/PluginExample/MyVisualModel.h b/src/PluginExample/MyVisualModel.h index 7777a91..50bdf8e 100644 --- a/src/PluginExample/MyVisualModel.h +++ b/src/PluginExample/MyVisualModel.h @@ -27,7 +27,7 @@ #include -namespace sofa::component::visual +namespace pluginexample { /** @@ -53,5 +53,5 @@ class SOFA_PLUGINEXAMPLE_API MyVisualModel : public sofa::component::visual::Vis }; -} // sofa::component::visual +} // namespace pluginexample diff --git a/src/PluginExample/config.h.in b/src/PluginExample/config.h.in index f43f092..cfe0a78 100644 --- a/src/PluginExample/config.h.in +++ b/src/PluginExample/config.h.in @@ -23,6 +23,9 @@ #include +// adding SOFA namespace to ease using SOFA classes within the plugin +using namespace sofa; + #define PLUGINEXAMPLE_VERSION @PROJECT_VERSION@ #ifdef SOFA_BUILD_PLUGINEXAMPLE @@ -32,3 +35,8 @@ # define SOFA_PLUGINEXAMPLE_API SOFA_IMPORT_DYNAMIC_LIBRARY #endif +namespace pluginexample +{ + constexpr const char* MODULE_NAME = "@PROJECT_NAME@"; + constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@"; +} // namespace pluginexample \ No newline at end of file diff --git a/src/PluginExample/initPluginExample.cpp b/src/PluginExample/initPluginExample.cpp index 305b98c..ad32107 100644 --- a/src/PluginExample/initPluginExample.cpp +++ b/src/PluginExample/initPluginExample.cpp @@ -23,49 +23,63 @@ #include using sofa::core::ObjectFactory; +#include -extern "C" { - SOFA_PLUGINEXAMPLE_API void initExternalModule(); - SOFA_PLUGINEXAMPLE_API const char* getModuleName(); - SOFA_PLUGINEXAMPLE_API const char* getModuleVersion(); - SOFA_PLUGINEXAMPLE_API const char* getModuleLicense(); - SOFA_PLUGINEXAMPLE_API const char* getModuleDescription(); - SOFA_PLUGINEXAMPLE_API const char* getModuleComponentList(); -} - -void initExternalModule() +namespace pluginexample { - static bool first = true; - if (first) + extern void registerMyBehaviorModel(sofa::core::ObjectFactory* factory); + extern void registerMyMappingPendulumInPlane(sofa::core::ObjectFactory* factory); + extern void registerMyProjectiveConstraintSet(sofa::core::ObjectFactory* factory); + extern void registerMyVisualModel(sofa::core::ObjectFactory* factory); + + + extern "C" { + SOFA_PLUGINEXAMPLE_API void initExternalModule(); + SOFA_PLUGINEXAMPLE_API const char* getModuleName(); + SOFA_PLUGINEXAMPLE_API const char* getModuleVersion(); + SOFA_PLUGINEXAMPLE_API const char* getModuleLicense(); + SOFA_PLUGINEXAMPLE_API const char* getModuleDescription(); + SOFA_PLUGINEXAMPLE_API void registerObjects(sofa::core::ObjectFactory* factory); + } + + void initExternalModule() { - first = false; + static bool first = true; + if (first) + { + first = false; + + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + } } -} -const char* getModuleName() -{ - return sofa_tostring(SOFA_TARGET); -} + const char* getModuleName() + { + return MODULE_NAME; + } -const char* getModuleVersion() -{ - return sofa_tostring(PLUGINEXAMPLE_VERSION); -} + const char* getModuleVersion() + { + return MODULE_VERSION; + } -const char* getModuleLicense() -{ - return "LGPL"; -} + const char* getModuleLicense() + { + return "LGPL"; + } -const char* getModuleDescription() -{ - return "Simple example of a Sofa plugin."; -} + const char* getModuleDescription() + { + return "Simple example of a Sofa plugin."; + } -const char* getModuleComponentList() -{ - /// string containing the names of the classes provided by the plugin - static std::string classes = ObjectFactory::getInstance()->listClassesFromTarget(sofa_tostring(SOFA_TARGET)); - return classes.c_str(); -} + void registerObjects(sofa::core::ObjectFactory* factory) + { + registerMyBehaviorModel(factory); + registerMyMappingPendulumInPlane(factory); + registerMyProjectiveConstraintSet(factory); + registerMyVisualModel(factory); + } +} \ No newline at end of file