Skip to content

Commit

Permalink
[Config] Introduce SOFA modules data structure (sofa-framework#5148)
Browse files Browse the repository at this point in the history
* Introduce SOFA modules data structure

* apply everywhere

* don't shadow with unique name

* try to fix

* generate unit tests automatically

* remove dependency to string and make modules constexpr

* restore conversion to string

* constexpr

* remove ambiguity

* include modules.h only when necessary
alxbilger authored Jan 9, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 1cbfa03 commit 88320b8
Showing 70 changed files with 956 additions and 651 deletions.
7 changes: 7 additions & 0 deletions Sofa/Component/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -49,3 +49,10 @@ sofa_create_package_with_targets(
INCLUDE_SOURCE_DIR "src"
INCLUDE_INSTALL_DIR "${PROJECT_NAME}"
)

# Tests
# If SOFA_BUILD_TESTS exists and is OFF, then these tests will be auto-disabled
cmake_dependent_option(SOFA_COMPONENT_BUILD_TESTS "Compile the automatic tests" ON "SOFA_BUILD_TESTS OR NOT DEFINED SOFA_BUILD_TESTS" OFF)
if(SOFA_COMPONENT_BUILD_TESTS)
add_subdirectory(test)
endif()
Original file line number Diff line number Diff line change
@@ -76,8 +76,8 @@ class TestCollisionPipeline : public BaseSimulationTest {

void SetUp() override
{
sofa::simpleapi::importPlugin("Sofa.Component.StateContainer");
sofa::simpleapi::importPlugin("Sofa.Component.Collision");
sofa::simpleapi::importPlugin(Sofa.Component.StateContainer);
sofa::simpleapi::importPlugin(Sofa.Component.Collision);
}

void TearDown() override
Original file line number Diff line number Diff line change
@@ -56,8 +56,8 @@ namespace
struct TestLocalMinDistance : public BaseSimulationTest {
void SetUp() override
{
sofa::simpleapi::importPlugin("Sofa.Component.StateContainer");
sofa::simpleapi::importPlugin("Sofa.Component.Collision.Detection.Intersection");
sofa::simpleapi::importPlugin(Sofa.Component.StateContainer);
sofa::simpleapi::importPlugin(Sofa.Component.Collision.Detection.Intersection);
}
void TearDown() override
{
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@

#include <sofa/helper/system/PluginManager.h>
#include <sofa/core/ObjectFactory.h>
#include <sofa/Modules.h>

namespace sofa::component::collision::detection
{
@@ -54,8 +55,8 @@ const char* getModuleVersion()

void registerObjects(sofa::core::ObjectFactory* factory)
{
factory->registerObjectsFromPlugin("Sofa.Component.Collision.Detection.Algorithm");
factory->registerObjectsFromPlugin("Sofa.Component.Collision.Detection.Intersection");
factory->registerObjectsFromPlugin(Sofa.Component.Collision.Detection.Algorithm);
factory->registerObjectsFromPlugin(Sofa.Component.Collision.Detection.Intersection);
}

void init()
4 changes: 2 additions & 2 deletions Sofa/Component/Collision/Geometry/tests/Sphere_test.cpp
Original file line number Diff line number Diff line change
@@ -72,8 +72,8 @@ struct TestSphere : public BaseSimulationTest
{
void SetUp() override
{
sofa::simpleapi::importPlugin("Sofa.Component.StateContainer");
sofa::simpleapi::importPlugin("Sofa.Component.Collision.Geometry");
sofa::simpleapi::importPlugin(Sofa.Component.StateContainer);
sofa::simpleapi::importPlugin(Sofa.Component.Collision.Geometry);

m_proxIntersection = sofa::core::objectmodel::New<MinProximityIntersection>();
m_proxIntersection->setAlarmDistance(1.0);
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@

#include <sofa/helper/system/PluginManager.h>
#include <sofa/core/ObjectFactory.h>
#include <sofa/Modules.h>

namespace sofa::component::collision::response
{
@@ -54,8 +55,8 @@ const char* getModuleVersion()

void registerObjects(sofa::core::ObjectFactory* factory)
{
factory->registerObjectsFromPlugin("Sofa.Component.Collision.Response.Mapper");
factory->registerObjectsFromPlugin("Sofa.Component.Collision.Response.Contact");
factory->registerObjectsFromPlugin(Sofa.Component.Collision.Response.Mapper);
factory->registerObjectsFromPlugin(Sofa.Component.Collision.Response.Contact);
}

void init()
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@

#include <sofa/helper/system/PluginManager.h>
#include <sofa/core/ObjectFactory.h>
#include <sofa/Modules.h>

namespace sofa::component::collision
{
@@ -55,9 +56,9 @@ const char* getModuleVersion()

void registerObjects(sofa::core::ObjectFactory* factory)
{
factory->registerObjectsFromPlugin("Sofa.Component.Collision.Geometry");
factory->registerObjectsFromPlugin("Sofa.Component.Collision.Detection");
factory->registerObjectsFromPlugin("Sofa.Component.Collision.Response");
factory->registerObjectsFromPlugin(Sofa.Component.Collision.Geometry);
factory->registerObjectsFromPlugin(Sofa.Component.Collision.Detection);
factory->registerObjectsFromPlugin(Sofa.Component.Collision.Response);
}

void init()
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@

#include <sofa/core/ObjectFactory.h>
#include <sofa/helper/system/PluginManager.h>
#include <sofa/Modules.h>

namespace sofa::component::constraint::lagrangian
{
@@ -55,9 +56,9 @@ const char* getModuleVersion()

void registerObjects(sofa::core::ObjectFactory* factory)
{
factory->registerObjectsFromPlugin("Sofa.Component.Constraint.Lagrangian.Correction");
factory->registerObjectsFromPlugin("Sofa.Component.Constraint.Lagrangian.Model");
factory->registerObjectsFromPlugin("Sofa.Component.Constraint.Lagrangian.Solver");
factory->registerObjectsFromPlugin(Sofa.Component.Constraint.Lagrangian.Correction);
factory->registerObjectsFromPlugin(Sofa.Component.Constraint.Lagrangian.Model);
factory->registerObjectsFromPlugin(Sofa.Component.Constraint.Lagrangian.Solver);
}

void init()
Original file line number Diff line number Diff line change
@@ -81,9 +81,9 @@ struct FixedProjectiveConstraint_test : public BaseTest
const simulation::Node::SPtr root = simulation->createNewGraph("root");
root->setGravity( type::Vec3(0,0,0) );

simpleapi::createObject(root , "RequiredPlugin", {{"name", "Sofa.Component.LinearSolver.Direct"}}) ;
simpleapi::createObject(root , "RequiredPlugin", {{"name", "Sofa.Component.ODESolver.Forward"}}) ;
simpleapi::createObject(root , "RequiredPlugin", {{"name", "Sofa.Component.ODESolver.Backward"}}) ;
simpleapi::createObject(root , "RequiredPlugin", {{"name", Sofa.Component.LinearSolver.Direct}}) ;
simpleapi::createObject(root , "RequiredPlugin", {{"name", Sofa.Component.ODESolver.Forward}}) ;
simpleapi::createObject(root , "RequiredPlugin", {{"name", Sofa.Component.ODESolver.Backward}}) ;

simulation::Node::SPtr node = createEulerSolverNode(root,"test", integrationScheme);

Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@

#include <sofa/core/ObjectFactory.h>
#include <sofa/helper/system/PluginManager.h>
#include <sofa/Modules.h>

namespace sofa::component::constraint
{
@@ -54,8 +55,8 @@ const char* getModuleVersion()

void registerObjects(sofa::core::ObjectFactory* factory)
{
factory->registerObjectsFromPlugin("Sofa.Component.Constraint.Lagrangian");
factory->registerObjectsFromPlugin("Sofa.Component.Constraint.Projective");
factory->registerObjectsFromPlugin(Sofa.Component.Constraint.Lagrangian);
factory->registerObjectsFromPlugin(Sofa.Component.Constraint.Projective);
}

void init()
6 changes: 3 additions & 3 deletions Sofa/Component/Engine/Select/tests/BoxROI_test.cpp
Original file line number Diff line number Diff line change
@@ -73,9 +73,9 @@ struct BoxROITest : public sofa::testing::BaseTest
void onSetUp() override
{
this->loadPlugins({
"Sofa.Component.StateContainer",
"Sofa.Component.Topology.Container.Dynamic",
"Sofa.Component.Engine.Select"});
Sofa.Component.StateContainer,
Sofa.Component.Topology.Container.Dynamic,
Sofa.Component.Engine.Select});

m_simu = sofa::simulation::getSimulation();
ASSERT_NE(m_simu, nullptr);
6 changes: 3 additions & 3 deletions Sofa/Component/Engine/Select/tests/MeshROI_test.cpp
Original file line number Diff line number Diff line change
@@ -63,9 +63,9 @@ struct MeshROI_test : public BaseSimulationTest,

void SetUp() override
{
simpleapi::importPlugin("Sofa.Component.Engine.Select");
simpleapi::importPlugin("Sofa.Component.Topology.Container.Constant");
simpleapi::importPlugin("Sofa.Component.IO.Mesh");
simpleapi::importPlugin(Sofa.Component.Engine.Select);
simpleapi::importPlugin(Sofa.Component.Topology.Container.Constant);
simpleapi::importPlugin(Sofa.Component.IO.Mesh);

// SetUp3
const string scene2 =
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ struct MeshSubsetEngine_test : public testing::BaseSimulationTest

void SetUp() override
{
simpleapi::importPlugin("Sofa.Component.Engine.Select");
simpleapi::importPlugin(Sofa.Component.Engine.Select);

m_root = simulation::getSimulation()->createNewNode("root");
ASSERT_NE(nullptr, m_root);
9 changes: 5 additions & 4 deletions Sofa/Component/Engine/src/sofa/component/engine/init.cpp
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@

#include <sofa/core/ObjectFactory.h>
#include <sofa/helper/system/PluginManager.h>
#include <sofa/Modules.h>

namespace sofa::component::engine
{
@@ -56,10 +57,10 @@ const char* getModuleVersion()

void registerObjects(sofa::core::ObjectFactory* factory)
{
factory->registerObjectsFromPlugin("Sofa.Component.Engine.Analyze");
factory->registerObjectsFromPlugin("Sofa.Component.Engine.Generate");
factory->registerObjectsFromPlugin("Sofa.Component.Engine.Select");
factory->registerObjectsFromPlugin("Sofa.Component.Engine.Transform");
factory->registerObjectsFromPlugin(Sofa.Component.Engine.Analyze);
factory->registerObjectsFromPlugin(Sofa.Component.Engine.Generate);
factory->registerObjectsFromPlugin(Sofa.Component.Engine.Select);
factory->registerObjectsFromPlugin(Sofa.Component.Engine.Transform);
}

void init()
4 changes: 2 additions & 2 deletions Sofa/Component/IO/Mesh/tests/MeshExporter_test.cpp
Original file line number Diff line number Diff line change
@@ -77,8 +77,8 @@ class MeshExporter_test

void SetUp() override
{
sofa::simpleapi::importPlugin("Sofa.Component.StateContainer");
sofa::simpleapi::importPlugin("Sofa.Component.Topology.Container.Grid");
sofa::simpleapi::importPlugin(Sofa.Component.StateContainer);
sofa::simpleapi::importPlugin(Sofa.Component.Topology.Container.Grid);
}

void TearDown() override
2 changes: 1 addition & 1 deletion Sofa/Component/IO/Mesh/tests/MeshXspLoader_test.cpp
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ class MeshXspLoader_test : public BaseSimulationTest
const Node::SPtr root = sofa::simpleapi::createRootNode(simulation, "root");

sofa::simpleapi::createObject(root, "DefaultAnimationLoop");
sofa::simpleapi::createObject(root, "RequiredPlugin", { { "name","Sofa.Component.IO.Mesh" } });
sofa::simpleapi::createObject(root, "RequiredPlugin", { { "name",Sofa.Component.IO.Mesh } });
auto loader = sofa::simpleapi::createObject(root, "MeshXspLoader",
{{"filename", std::string(SOFA_COMPONENT_IO_MESH_TEST_FILES_DIR)+"test.xs3"}});
sofa::simulation::node::initRoot(root.get());
6 changes: 3 additions & 3 deletions Sofa/Component/IO/Mesh/tests/STLExporter_test.cpp
Original file line number Diff line number Diff line change
@@ -67,9 +67,9 @@ class STLExporter_test : public BaseSimulationTest {

void SetUp() override
{
sofa::simpleapi::importPlugin("Sofa.Component.StateContainer");
sofa::simpleapi::importPlugin("Sofa.Component.Visual");
sofa::simpleapi::importPlugin("Sofa.Component.IO.Mesh");
sofa::simpleapi::importPlugin(Sofa.Component.StateContainer);
sofa::simpleapi::importPlugin(Sofa.Component.Visual);
sofa::simpleapi::importPlugin(Sofa.Component.IO.Mesh);
}

void TearDown() override
3 changes: 2 additions & 1 deletion Sofa/Component/IO/src/sofa/component/io/init.cpp
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@

#include <sofa/core/ObjectFactory.h>
#include <sofa/helper/system/PluginManager.h>
#include <sofa/Modules.h>

namespace sofa::component::io
{
@@ -53,7 +54,7 @@ const char* getModuleVersion()

void registerObjects(sofa::core::ObjectFactory* factory)
{
factory->registerObjectsFromPlugin("Sofa.Component.IO.Mesh");
factory->registerObjectsFromPlugin(Sofa.Component.IO.Mesh);
}

void init()
Original file line number Diff line number Diff line change
@@ -58,9 +58,9 @@ TEST(SparseLDLSolver, EmptyMState)
const sofa::simulation::Node::SPtr root = sofa::simulation::getSimulation()->createNewGraph("root");

const auto plugins = sofa::testing::makeScopedPlugin({
"Sofa.Component.LinearSolver.Direct",
"Sofa.Component.ODESolver.Backward",
"Sofa.Component.StateContainer"});
Sofa.Component.LinearSolver.Direct,
Sofa.Component.ODESolver.Backward,
Sofa.Component.StateContainer});

sofa::simpleapi::createObject(root, "DefaultAnimationLoop");
sofa::simpleapi::createObject(root, "EulerImplicitSolver");
@@ -87,12 +87,12 @@ TEST(SparseLDLSolver, TopologyChangeEmptyMState)
const sofa::simulation::Node::SPtr root = sofa::simulation::getSimulation()->createNewGraph("root");

const auto plugins = sofa::testing::makeScopedPlugin({
"Sofa.Component.LinearSolver.Direct",
"Sofa.Component.Mass",
"Sofa.Component.ODESolver.Backward",
"Sofa.Component.StateContainer",
"Sofa.Component.Topology.Container.Dynamic",
"Sofa.Component.Topology.Utility"});
Sofa.Component.LinearSolver.Direct,
Sofa.Component.Mass,
Sofa.Component.ODESolver.Backward,
Sofa.Component.StateContainer,
Sofa.Component.Topology.Container.Dynamic,
Sofa.Component.Topology.Utility});

sofa::simpleapi::createObject(root, "DefaultAnimationLoop");
sofa::simpleapi::createObject(root, "EulerImplicitSolver");
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@

#include <sofa/core/ObjectFactory.h>
#include <sofa/helper/system/PluginManager.h>
#include <sofa/Modules.h>

namespace sofa::component::linearsolver
{
@@ -56,10 +57,10 @@ const char* getModuleVersion()

void registerObjects(sofa::core::ObjectFactory* factory)
{
factory->registerObjectsFromPlugin("Sofa.Component.LinearSolver.Direct");
factory->registerObjectsFromPlugin("Sofa.Component.LinearSolver.Iterative");
factory->registerObjectsFromPlugin("Sofa.Component.LinearSolver.Ordering");
factory->registerObjectsFromPlugin("Sofa.Component.LinearSolver.Preconditioner");
factory->registerObjectsFromPlugin(Sofa.Component.LinearSolver.Direct);
factory->registerObjectsFromPlugin(Sofa.Component.LinearSolver.Iterative);
factory->registerObjectsFromPlugin(Sofa.Component.LinearSolver.Ordering);
factory->registerObjectsFromPlugin(Sofa.Component.LinearSolver.Preconditioner);
}

void init()
2 changes: 1 addition & 1 deletion Sofa/Component/LinearSystem/tests/MappingGraph_test.cpp
Original file line number Diff line number Diff line change
@@ -176,7 +176,7 @@ TEST(MappingGraph, diamondMapping)
sofa::simulation::Node::SPtr root = simulation->createNewGraph("root");
EXPECT_EQ(root->getName(), "root");

sofa::simpleapi::importPlugin("Sofa.Component.Mapping.Linear");
sofa::simpleapi::importPlugin(Sofa.Component.Mapping.Linear);

const auto top = sofa::core::objectmodel::New<sofa::component::statecontainer::MechanicalObject<sofa::defaulttype::Vec3Types> >();
root->addObject(top);
Original file line number Diff line number Diff line change
@@ -154,7 +154,7 @@ struct SquareDistanceMappingCompare_test : NumericTest<SReal>
{
root = simulation::getSimulation()->createNewNode("root");

simpleapi::createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component"}});
simpleapi::createObject(root, "RequiredPlugin", {{"pluginName", Sofa.Component}});
simpleapi::createObject(root, "DefaultAnimationLoop");
simpleapi::createObject(root, "StringMeshCreator", {{"name", "loader"}, {"resolution", "3"}});

5 changes: 3 additions & 2 deletions Sofa/Component/Mapping/src/sofa/component/mapping/init.cpp
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@

#include <sofa/core/ObjectFactory.h>
#include <sofa/helper/system/PluginManager.h>
#include <sofa/Modules.h>

namespace sofa::component::mapping
{
@@ -53,8 +54,8 @@ const char* getModuleVersion()

void registerObjects(sofa::core::ObjectFactory* factory)
{
factory->registerObjectsFromPlugin("Sofa.Component.Mapping.Linear");
factory->registerObjectsFromPlugin("Sofa.Component.Mapping.NonLinear");
factory->registerObjectsFromPlugin(Sofa.Component.Mapping.Linear);
factory->registerObjectsFromPlugin(Sofa.Component.Mapping.NonLinear);
}

void init()
8 changes: 4 additions & 4 deletions Sofa/Component/Mass/tests/DiagonalMass_test.cpp
Original file line number Diff line number Diff line change
@@ -98,10 +98,10 @@ class DiagonalMass_test : public BaseTest

void SetUp() override
{
sofa::simpleapi::importPlugin("Sofa.Component.Topology.Container.Dynamic");
sofa::simpleapi::importPlugin("Sofa.Component.Topology.Container.Grid");
sofa::simpleapi::importPlugin("Sofa.Component.StateContainer");
sofa::simpleapi::importPlugin("Sofa.Component.Mass");
sofa::simpleapi::importPlugin(Sofa.Component.Topology.Container.Dynamic);
sofa::simpleapi::importPlugin(Sofa.Component.Topology.Container.Grid);
sofa::simpleapi::importPlugin(Sofa.Component.StateContainer);
sofa::simpleapi::importPlugin(Sofa.Component.Mass);

simulation = simulation::getSimulation();
root = simulation::getSimulation()->createNewGraph("root");
8 changes: 4 additions & 4 deletions Sofa/Component/Mass/tests/MeshMatrixMass_test.cpp
Original file line number Diff line number Diff line change
@@ -101,10 +101,10 @@ class MeshMatrixMass_test : public BaseTest

void SetUp() override
{
sofa::simpleapi::importPlugin("Sofa.Component.Topology.Container.Dynamic");
sofa::simpleapi::importPlugin("Sofa.Component.Topology.Container.Grid");
sofa::simpleapi::importPlugin("Sofa.Component.StateContainer");
sofa::simpleapi::importPlugin("Sofa.Component.Mass");
sofa::simpleapi::importPlugin(Sofa.Component.Topology.Container.Dynamic);
sofa::simpleapi::importPlugin(Sofa.Component.Topology.Container.Grid);
sofa::simpleapi::importPlugin(Sofa.Component.StateContainer);
sofa::simpleapi::importPlugin(Sofa.Component.Mass);

simulation = simulation::getSimulation();
root = simulation::getSimulation()->createNewGraph("root");
4 changes: 2 additions & 2 deletions Sofa/Component/Mass/tests/UniformMass_test.cpp
Original file line number Diff line number Diff line change
@@ -79,8 +79,8 @@ struct UniformMassTest : public BaseTest

void SetUp() override
{
sofa::simpleapi::importPlugin("Sofa.Component.StateContainer");
sofa::simpleapi::importPlugin("Sofa.Component.Mass");
sofa::simpleapi::importPlugin(Sofa.Component.StateContainer);
sofa::simpleapi::importPlugin(Sofa.Component.Mass);

todo = true ;
m_simu = sofa::simulation::getSimulation();
Loading

0 comments on commit 88320b8

Please sign in to comment.