Skip to content
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
5 changes: 3 additions & 2 deletions PluginExample_test/MyBehaviorModel_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ using std::vector;

#include <sofa/testing/BaseTest.h>
using sofa::testing::BaseTest;

using ::testing::Types;

using namespace pluginexample;

namespace {

class MyBehaviorModel_test : public BaseTest,
public ::testing::WithParamInterface<unsigned>
{
public:
using MyBehaviorModel = sofa::component::behaviormodel::MyBehaviorModel;
using MyBehaviorModel = pluginexample::MyBehaviorModel;

void doTearDown() override
{
Expand Down
11 changes: 7 additions & 4 deletions src/PluginExample/MyBehaviorModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <sofa/core/ObjectFactory.h>


namespace sofa::component::behaviormodel
namespace pluginexample
{

MyBehaviorModel::MyBehaviorModel()
Expand Down Expand Up @@ -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

4 changes: 2 additions & 2 deletions src/PluginExample/MyBehaviorModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <sofa/core/BehaviorModel.h>


namespace sofa::component::behaviormodel
namespace pluginexample
{

/**
Expand All @@ -52,5 +52,5 @@ class SOFA_PLUGINEXAMPLE_API MyBehaviorModel : public sofa::core::BehaviorModel
};


} // sofa::component::behaviormodel
} // namespace pluginexample

4 changes: 2 additions & 2 deletions src/PluginExample/MyDataWidgetUnsigned.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <sofa/helper/Factory.h>


namespace sofa::gui::qt
namespace pluginexample
{

/*
Expand Down Expand Up @@ -112,4 +112,4 @@ void MyDataWidgetUnsigned::change()
}


} // namespace sofa::gui::qt
} // namespace pluginexample
4 changes: 2 additions & 2 deletions src/PluginExample/MyDataWidgetUnsigned.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <QString>


namespace sofa::gui::qt
namespace pluginexample
{

/**
Expand Down Expand Up @@ -65,4 +65,4 @@ protected slots:
};


} // namespace sofa::gui::qt
} // namespace pluginexample
14 changes: 7 additions & 7 deletions src/PluginExample/MyMappingPendulumInPlane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@
#include <sofa/defaulttype/VecTypes.h>


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<Vec1Types, Vec3Types> >()
.add< MyMappingPendulumInPlane<Vec1Types, Vec2Types> >()
;
.add< MyMappingPendulumInPlane<Vec1Types, Vec2Types> >());
}

template class SOFA_PLUGINEXAMPLE_API MyMappingPendulumInPlane<Vec1Types, Vec3Types>;
template class SOFA_PLUGINEXAMPLE_API MyMappingPendulumInPlane<Vec1Types, Vec2Types>;



} // namespace sofa::component::mapping

} // namespace pluginexample
4 changes: 2 additions & 2 deletions src/PluginExample/MyMappingPendulumInPlane.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <sofa/helper/OptionsGroup.h>


namespace sofa::component::mapping
namespace pluginexample
{

using type::vector;
Expand Down Expand Up @@ -84,5 +84,5 @@ class MyMappingPendulumInPlane: public core::Mapping<TIn, TOut>
vector<Vec2> gap;
};

} // namespace sofa::component::mapping
} // namespace pluginexample

4 changes: 2 additions & 2 deletions src/PluginExample/MyMappingPendulumInPlane.inl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ using std::cerr;
using std::endl;


namespace sofa::component::mapping
namespace pluginexample
{

using helper::ReadAccessor;
Expand Down Expand Up @@ -206,4 +206,4 @@ void MyMappingPendulumInPlane<In, Out>::applyDJT(const core::MechanicalParams* m
}


} // namespace sofa::component::mapping
} // namespace pluginexample
15 changes: 8 additions & 7 deletions src/PluginExample/MyProjectiveConstraintSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@
#include <sofa/core/ObjectFactory.h>


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<Vec3Types> >()
.add< MyProjectiveConstraintSet<Vec1Types> >()
.add< MyProjectiveConstraintSet<Rigid3Types> >()
;
.add< MyProjectiveConstraintSet<Rigid3Types> >());
}

template class SOFA_PLUGINEXAMPLE_API MyProjectiveConstraintSet<Rigid3Types>;
template class SOFA_PLUGINEXAMPLE_API MyProjectiveConstraintSet<Vec3Types>;



} // namespace sofa::component::projectiveconstraintset
} // namespace pluginexample
2 changes: 1 addition & 1 deletion src/PluginExample/MyProjectiveConstraintSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <sofa/defaulttype/VecTypes.h>


namespace sofa::component::projectiveconstraintset
namespace pluginexample
{

template <class DataTypes>
Expand Down
4 changes: 2 additions & 2 deletions src/PluginExample/MyProjectiveConstraintSet.inl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <PluginExample/MyProjectiveConstraintSet.h>


namespace sofa::component::projectiveconstraintset
namespace pluginexample
{

template <class DataTypes>
Expand Down Expand Up @@ -52,4 +52,4 @@ void MyProjectiveConstraintSet<DataTypes>::reinit()



} // namespace sofa::component::projectiveconstraintset
} // namespace pluginexample
11 changes: 7 additions & 4 deletions src/PluginExample/MyVisualModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <sofa/core/ObjectFactory.h>


namespace sofa::component::visual
namespace pluginexample
{

MyVisualModel::MyVisualModel()
Expand All @@ -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

4 changes: 2 additions & 2 deletions src/PluginExample/MyVisualModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <sofa/component/visual/VisualModelImpl.h>


namespace sofa::component::visual
namespace pluginexample
{

/**
Expand All @@ -53,5 +53,5 @@ class SOFA_PLUGINEXAMPLE_API MyVisualModel : public sofa::component::visual::Vis
};


} // sofa::component::visual
} // namespace pluginexample

8 changes: 8 additions & 0 deletions src/PluginExample/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

#include <sofa/config.h>

// adding SOFA namespace to ease using SOFA classes within the plugin
using namespace sofa;

#define PLUGINEXAMPLE_VERSION @PROJECT_VERSION@

#ifdef SOFA_BUILD_PLUGINEXAMPLE
Expand All @@ -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
86 changes: 50 additions & 36 deletions src/PluginExample/initPluginExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 +23,63 @@

#include <sofa/core/ObjectFactory.h>
using sofa::core::ObjectFactory;
#include <sofa/helper/system/PluginManager.h>

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);
}

}
Loading