diff --git a/Sofa/Component/Collision/Detection/Algorithm/tests/CollisionPipeline_test.cpp b/Sofa/Component/Collision/Detection/Algorithm/tests/CollisionPipeline_test.cpp index 3078fc26c56..a134153c544 100644 --- a/Sofa/Component/Collision/Detection/Algorithm/tests/CollisionPipeline_test.cpp +++ b/Sofa/Component/Collision/Detection/Algorithm/tests/CollisionPipeline_test.cpp @@ -34,9 +34,6 @@ using sofa::core::objectmodel::BaseObject ; #include using sofa::component::collision::detection::algorithm::CollisionPipeline ; -#include -using sofa::simulation::graph::DAGSimulation ; - #include using sofa::simulation::Node ; diff --git a/Sofa/Component/Collision/Detection/Intersection/tests/LocalMinDistance_test.cpp b/Sofa/Component/Collision/Detection/Intersection/tests/LocalMinDistance_test.cpp index 76d43def6a6..566d64d730f 100644 --- a/Sofa/Component/Collision/Detection/Intersection/tests/LocalMinDistance_test.cpp +++ b/Sofa/Component/Collision/Detection/Intersection/tests/LocalMinDistance_test.cpp @@ -29,8 +29,7 @@ using std::string; #include using sofa::testing::BaseSimulationTest; -#include -using sofa::simulation::graph::DAGSimulation ; +#include using sofa::simulation::Node ; #include diff --git a/Sofa/Component/Engine/Analyze/tests/AverageCoord_test.cpp b/Sofa/Component/Engine/Analyze/tests/AverageCoord_test.cpp index 96d9416c4f6..5d755bbcf41 100644 --- a/Sofa/Component/Engine/Analyze/tests/AverageCoord_test.cpp +++ b/Sofa/Component/Engine/Analyze/tests/AverageCoord_test.cpp @@ -27,12 +27,11 @@ using sofa::testing::BaseSimulationTest; #include using sofa::component::statecontainer::MechanicalObject ; -#include +#include using sofa::simulation::Simulation ; using sofa::simulation::Node ; using sofa::core::objectmodel::New ; using sofa::core::objectmodel::BaseData ; -using sofa::simulation::graph::DAGSimulation; #include using sofa::component::engine::analyze::AverageCoord ; diff --git a/Sofa/Component/Engine/Analyze/tests/ClusteringEngine_test.cpp b/Sofa/Component/Engine/Analyze/tests/ClusteringEngine_test.cpp index b57ca438e54..747e930e971 100644 --- a/Sofa/Component/Engine/Analyze/tests/ClusteringEngine_test.cpp +++ b/Sofa/Component/Engine/Analyze/tests/ClusteringEngine_test.cpp @@ -26,12 +26,11 @@ using sofa::testing::BaseSimulationTest; #include using sofa::component::statecontainer::MechanicalObject ; -#include +#include using sofa::simulation::Simulation ; using sofa::simulation::Node ; using sofa::core::objectmodel::New ; using sofa::core::objectmodel::BaseData ; -using sofa::simulation::graph::DAGSimulation; #include using sofa::core::visual::VisualParams; diff --git a/Sofa/Component/Engine/Generate/tests/ExtrudeEdgesAndGenerateQuads_test.cpp b/Sofa/Component/Engine/Generate/tests/ExtrudeEdgesAndGenerateQuads_test.cpp index c7a2fdd853c..65ce5e8a263 100644 --- a/Sofa/Component/Engine/Generate/tests/ExtrudeEdgesAndGenerateQuads_test.cpp +++ b/Sofa/Component/Engine/Generate/tests/ExtrudeEdgesAndGenerateQuads_test.cpp @@ -25,12 +25,11 @@ using sofa::testing::BaseSimulationTest; #include -#include +#include using sofa::simulation::Simulation ; using sofa::simulation::Node ; using sofa::core::objectmodel::New ; using sofa::core::objectmodel::BaseData ; -using sofa::simulation::graph::DAGSimulation; #include using sofa::component::engine::generate::ExtrudeEdgesAndGenerateQuads ; diff --git a/Sofa/Component/Engine/Generate/tests/MergePoints_test.cpp b/Sofa/Component/Engine/Generate/tests/MergePoints_test.cpp index 5f50d949e1f..27457424ec9 100644 --- a/Sofa/Component/Engine/Generate/tests/MergePoints_test.cpp +++ b/Sofa/Component/Engine/Generate/tests/MergePoints_test.cpp @@ -22,8 +22,7 @@ #include using sofa::testing::BaseSimulationTest; -#include -using sofa::simulation::graph::DAGSimulation; +#include using sofa::simulation::Simulation ; using sofa::core::objectmodel::New ; diff --git a/Sofa/Component/Engine/Select/tests/BoxROI_test.cpp b/Sofa/Component/Engine/Select/tests/BoxROI_test.cpp index 08425f2c4cb..9e47440ca84 100644 --- a/Sofa/Component/Engine/Select/tests/BoxROI_test.cpp +++ b/Sofa/Component/Engine/Select/tests/BoxROI_test.cpp @@ -37,9 +37,8 @@ using sofa::core::objectmodel::ComponentState; #include using sofa::component::engine::select::BoxROI; -#include +#include using sofa::simulation::Simulation; -using sofa::simulation::graph::DAGSimulation; #include using sofa::simulation::Node; using sofa::core::objectmodel::BaseObject; diff --git a/Sofa/Component/Engine/Select/tests/ComplementaryROI_test.cpp b/Sofa/Component/Engine/Select/tests/ComplementaryROI_test.cpp index ec055b0321a..48a44458bf9 100644 --- a/Sofa/Component/Engine/Select/tests/ComplementaryROI_test.cpp +++ b/Sofa/Component/Engine/Select/tests/ComplementaryROI_test.cpp @@ -25,12 +25,11 @@ using sofa::testing::BaseSimulationTest; #include -#include +#include using sofa::simulation::Simulation ; using sofa::simulation::Node ; using sofa::core::objectmodel::New ; using sofa::core::objectmodel::BaseData ; -using sofa::simulation::graph::DAGSimulation; #include using sofa::core::visual::VisualParams; diff --git a/Sofa/Component/Engine/Select/tests/MeshROI_test.cpp b/Sofa/Component/Engine/Select/tests/MeshROI_test.cpp index 66867cba9b5..ff9bcf9ee97 100644 --- a/Sofa/Component/Engine/Select/tests/MeshROI_test.cpp +++ b/Sofa/Component/Engine/Select/tests/MeshROI_test.cpp @@ -25,12 +25,11 @@ using sofa::testing::BaseSimulationTest; #include -#include +#include using sofa::simulation::Simulation ; using sofa::simulation::Node ; using sofa::core::objectmodel::New ; using sofa::core::objectmodel::BaseData ; -using sofa::simulation::graph::DAGSimulation; #include using sofa::component::engine::select::MeshROI ; diff --git a/Sofa/Component/Engine/Select/tests/PlaneROI_test.cpp b/Sofa/Component/Engine/Select/tests/PlaneROI_test.cpp index a50e5cb6519..8b7d48f8e2f 100644 --- a/Sofa/Component/Engine/Select/tests/PlaneROI_test.cpp +++ b/Sofa/Component/Engine/Select/tests/PlaneROI_test.cpp @@ -25,12 +25,11 @@ using sofa::testing::BaseSimulationTest; #include -#include +#include using sofa::simulation::Simulation ; using sofa::simulation::Node ; using sofa::core::objectmodel::New ; using sofa::core::objectmodel::BaseData ; -using sofa::simulation::graph::DAGSimulation; #include using sofa::component::engine::select::PlaneROI ; diff --git a/Sofa/Component/Engine/Select/tests/SphereROI_test.cpp b/Sofa/Component/Engine/Select/tests/SphereROI_test.cpp index 0bfb8a12387..317fff9f93c 100644 --- a/Sofa/Component/Engine/Select/tests/SphereROI_test.cpp +++ b/Sofa/Component/Engine/Select/tests/SphereROI_test.cpp @@ -25,12 +25,11 @@ using sofa::testing::BaseSimulationTest; #include -#include +#include using sofa::simulation::Simulation ; using sofa::simulation::Node ; using sofa::core::objectmodel::New ; using sofa::core::objectmodel::BaseData ; -using sofa::simulation::graph::DAGSimulation; #include using sofa::component::engine::select::SphereROI ; diff --git a/Sofa/Component/Engine/Transform/tests/DifferenceEngine_test.cpp b/Sofa/Component/Engine/Transform/tests/DifferenceEngine_test.cpp index d2f7ecddbbd..91d7d47db54 100644 --- a/Sofa/Component/Engine/Transform/tests/DifferenceEngine_test.cpp +++ b/Sofa/Component/Engine/Transform/tests/DifferenceEngine_test.cpp @@ -25,12 +25,11 @@ using sofa::testing::BaseSimulationTest; #include -#include +#include using sofa::simulation::Simulation ; using sofa::simulation::Node ; using sofa::core::objectmodel::New ; using sofa::core::objectmodel::BaseData ; -using sofa::simulation::graph::DAGSimulation; #include using sofa::core::visual::VisualParams; diff --git a/Sofa/Component/Engine/Transform/tests/DilateEngine_test.cpp b/Sofa/Component/Engine/Transform/tests/DilateEngine_test.cpp index bbed29b8fa5..2c64a808610 100644 --- a/Sofa/Component/Engine/Transform/tests/DilateEngine_test.cpp +++ b/Sofa/Component/Engine/Transform/tests/DilateEngine_test.cpp @@ -25,12 +25,11 @@ using sofa::testing::BaseSimulationTest; #include -#include +#include using sofa::simulation::Simulation ; using sofa::simulation::Node ; using sofa::core::objectmodel::New ; using sofa::core::objectmodel::BaseData ; -using sofa::simulation::graph::DAGSimulation; #include using sofa::component::engine::transform::DilateEngine ; diff --git a/Sofa/Component/Engine/Transform/tests/SmoothMeshEngine_test.cpp b/Sofa/Component/Engine/Transform/tests/SmoothMeshEngine_test.cpp index d28d41321e9..303c174e273 100644 --- a/Sofa/Component/Engine/Transform/tests/SmoothMeshEngine_test.cpp +++ b/Sofa/Component/Engine/Transform/tests/SmoothMeshEngine_test.cpp @@ -24,12 +24,11 @@ using sofa::testing::BaseSimulationTest; #include -#include +#include using sofa::simulation::Simulation ; using sofa::simulation::Node ; using sofa::core::objectmodel::New ; using sofa::core::objectmodel::BaseData ; -using sofa::simulation::graph::DAGSimulation; #include using sofa::component::engine::transform::SmoothMeshEngine ; diff --git a/Sofa/Component/IO/Mesh/tests/MeshExporter_test.cpp b/Sofa/Component/IO/Mesh/tests/MeshExporter_test.cpp index 112017d7a2d..c89bc983c1c 100644 --- a/Sofa/Component/IO/Mesh/tests/MeshExporter_test.cpp +++ b/Sofa/Component/IO/Mesh/tests/MeshExporter_test.cpp @@ -33,9 +33,6 @@ using sofa::testing::BaseSimulationTest; #include using sofa::core::objectmodel::BaseObject ; -#include -using sofa::simulation::graph::DAGSimulation ; - #include using sofa::simulation::Node ; diff --git a/Sofa/Component/IO/Mesh/tests/STLExporter_test.cpp b/Sofa/Component/IO/Mesh/tests/STLExporter_test.cpp index 9753bd4101c..1534b318377 100644 --- a/Sofa/Component/IO/Mesh/tests/STLExporter_test.cpp +++ b/Sofa/Component/IO/Mesh/tests/STLExporter_test.cpp @@ -31,9 +31,6 @@ using sofa::testing::BaseSimulationTest; #include using sofa::core::objectmodel::BaseObject ; -#include -using sofa::simulation::graph::DAGSimulation ; - #include using sofa::simulation::Node ; diff --git a/Sofa/Component/IO/Mesh/tests/VisualModelOBJExporter_test.cpp b/Sofa/Component/IO/Mesh/tests/VisualModelOBJExporter_test.cpp index eeb1810bcd0..526563cd35d 100644 --- a/Sofa/Component/IO/Mesh/tests/VisualModelOBJExporter_test.cpp +++ b/Sofa/Component/IO/Mesh/tests/VisualModelOBJExporter_test.cpp @@ -31,9 +31,6 @@ using sofa::testing::BaseSimulationTest; #include using sofa::core::objectmodel::BaseObject ; -#include -using sofa::simulation::graph::DAGSimulation ; - #include using sofa::simulation::Node ; diff --git a/Sofa/Component/Mapping/Linear/tests/BarycentricMapping_test.cpp b/Sofa/Component/Mapping/Linear/tests/BarycentricMapping_test.cpp index 2f923ea9221..4071abd3a44 100644 --- a/Sofa/Component/Mapping/Linear/tests/BarycentricMapping_test.cpp +++ b/Sofa/Component/Mapping/Linear/tests/BarycentricMapping_test.cpp @@ -34,13 +34,12 @@ using sofa::core::topology::BaseMeshTopology; #include using sofa::testing::BaseTest; - using sofa::type::Vec3; using sofa::type::Vec3u; using sofa::core::objectmodel::New; -#include -using sofa::simulation::graph::DAGSimulation; +#include +#include using sofa::simulation::Node ; using sofa::core::objectmodel::New ; using sofa::core::objectmodel::BaseData ; @@ -48,8 +47,6 @@ using sofa::core::objectmodel::BaseData ; #include using sofa::component::statecontainer::MechanicalObject ; -#include - using sofa::defaulttype::Vec3Types; template diff --git a/Sofa/Component/Mapping/Linear/tests/DistanceToPlaneMapping_test.cpp b/Sofa/Component/Mapping/Linear/tests/DistanceToPlaneMapping_test.cpp index 85165f8a9bc..e8fe9ea2215 100644 --- a/Sofa/Component/Mapping/Linear/tests/DistanceToPlaneMapping_test.cpp +++ b/Sofa/Component/Mapping/Linear/tests/DistanceToPlaneMapping_test.cpp @@ -28,9 +28,7 @@ #include "sofa/core/MechanicalParams.h" using sofa::testing::BaseTest; - -#include -using sofa::simulation::graph::DAGSimulation; +#include using sofa::simulation::Node ; using sofa::core::objectmodel::New ; using sofa::core::objectmodel::BaseData ; @@ -53,13 +51,9 @@ class PlaneMappingTest : public testing::Test typedef sofa::type::Vec::spatial_dimensions,typename sofa::Deriv_t::value_type> PlaneNormalType; typedef sofa::type::Vec::spatial_dimensions,typename sofa::Coord_t::value_type> PlanePointType; public: - sofa::simulation::Simulation* createSimpleScene(typename sofa::component::mapping::linear::DistanceToPlaneMapping::SPtr mapping) + Node::SPtr createSimpleScene(typename sofa::component::mapping::linear::DistanceToPlaneMapping::SPtr mapping) { - - - sofa::simulation::Simulation* simu = sofa::simulation::getSimulation(); - - const Node::SPtr node = simu->createNewGraph("root"); + const Node::SPtr node = sofa::simulation::node::createNewNode("root"); typename MechanicalObject::SPtr mechanical = New>(); mechanical->resize(10); @@ -80,7 +74,7 @@ class PlaneMappingTest : public testing::Test EXPECT_NO_THROW( sofa::simulation::node::initRoot(node.get()) ); - return simu; + return node; } PlaneNormalType getPseudoRandomNormal() diff --git a/Sofa/Component/Mass/tests/UniformMass_test.cpp b/Sofa/Component/Mass/tests/UniformMass_test.cpp index b027671c1f5..a7f76feb247 100644 --- a/Sofa/Component/Mass/tests/UniformMass_test.cpp +++ b/Sofa/Component/Mass/tests/UniformMass_test.cpp @@ -30,10 +30,7 @@ using namespace sofa::defaulttype ; using sofa::component::mass::UniformMass ; #include - -#include using sofa::simulation::Simulation ; -using sofa::simulation::graph::DAGSimulation ; #include using sofa::simulation::Node; diff --git a/Sofa/Component/MechanicalLoad/tests/PlaneForceField_test.cpp b/Sofa/Component/MechanicalLoad/tests/PlaneForceField_test.cpp index 20eced1a952..9efb4164b2b 100644 --- a/Sofa/Component/MechanicalLoad/tests/PlaneForceField_test.cpp +++ b/Sofa/Component/MechanicalLoad/tests/PlaneForceField_test.cpp @@ -23,9 +23,8 @@ #include using sofa::testing::BaseSimulationTest; -#include +#include using sofa::simulation::Simulation ; -using sofa::simulation::graph::DAGSimulation ; using sofa::simulation::Node ; using sofa::core::objectmodel::BaseObject ; using sofa::core::objectmodel::BaseData ; @@ -69,8 +68,6 @@ using sofa::component::linearsolver::GraphScatteredMatrix ; using sofa::component::linearsolver::GraphScatteredVector ; using sofa::component::linearsolver::iterative::CGLinearSolver ; -using sofa::simulation::graph::DAGSimulation ; - using sofa::component::mass::UniformMass ; using sofa::component::mechanicalload::PlaneForceField ; diff --git a/Sofa/Component/ODESolver/Backward/tests/StaticSolver_test.cpp b/Sofa/Component/ODESolver/Backward/tests/StaticSolver_test.cpp index 8a78b4dc8fd..ccb1f6fb721 100644 --- a/Sofa/Component/ODESolver/Backward/tests/StaticSolver_test.cpp +++ b/Sofa/Component/ODESolver/Backward/tests/StaticSolver_test.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -32,7 +31,6 @@ using namespace sofa::simulation; using namespace sofa::simpleapi; using namespace sofa::helper::logging; -using sofa::simulation::graph::DAGSimulation; using sofa::component::odesolver::backward::StaticSolver; static constexpr SReal poissonRatio = 0; diff --git a/Sofa/Component/SceneUtility/tests/MessageHandlerComponent_test.cpp b/Sofa/Component/SceneUtility/tests/MessageHandlerComponent_test.cpp index 94b69d307c0..40ed35d0a29 100644 --- a/Sofa/Component/SceneUtility/tests/MessageHandlerComponent_test.cpp +++ b/Sofa/Component/SceneUtility/tests/MessageHandlerComponent_test.cpp @@ -27,9 +27,6 @@ using std::string ; #include #include -#include -using sofa::simulation::graph::DAGSimulation ; - #include using sofa::simulation::Node ; diff --git a/Sofa/framework/Core/src/sofa/core/fwd.h b/Sofa/framework/Core/src/sofa/core/fwd.h index a9ab6b73c8d..ffbc7fb31f3 100644 --- a/Sofa/framework/Core/src/sofa/core/fwd.h +++ b/Sofa/framework/Core/src/sofa/core/fwd.h @@ -73,6 +73,7 @@ namespace sofa::core::objectmodel { class Base; class BaseObject; +class BaseObjectDescription; class BaseNode; class BaseContext; class BaseData; diff --git a/Sofa/framework/SimpleApi/src/sofa/simpleapi/SimpleApi.cpp b/Sofa/framework/SimpleApi/src/sofa/simpleapi/SimpleApi.cpp index 63555fcb1d4..cbaba2bce62 100644 --- a/Sofa/framework/SimpleApi/src/sofa/simpleapi/SimpleApi.cpp +++ b/Sofa/framework/SimpleApi/src/sofa/simpleapi/SimpleApi.cpp @@ -26,9 +26,6 @@ #include using sofa::core::ObjectFactory ; -#include -using sofa::simulation::graph::DAGSimulation ; - #include using sofa::simulation::Node; using sofa::core::objectmodel::BaseObjectDescription ; @@ -60,7 +57,7 @@ void dumpScene(Node::SPtr root) p.execute(root.get()) ; } -Simulation::SPtr createSimulation(const std::string& type) +SimulationSPtr createSimulation(const std::string& type) { if(type!="DAG") { @@ -68,7 +65,7 @@ Simulation::SPtr createSimulation(const std::string& type) return nullptr ; } - return std::make_shared(); + return std::make_shared(); } diff --git a/Sofa/framework/SimpleApi/src/sofa/simpleapi/SimpleApi.h b/Sofa/framework/SimpleApi/src/sofa/simpleapi/SimpleApi.h index e7b6fc4fa82..3b2022a893b 100644 --- a/Sofa/framework/SimpleApi/src/sofa/simpleapi/SimpleApi.h +++ b/Sofa/framework/SimpleApi/src/sofa/simpleapi/SimpleApi.h @@ -22,7 +22,6 @@ #pragma once #include - #include #include @@ -36,15 +35,16 @@ namespace sofa::simpleapi using sofa::core::objectmodel::BaseObject; using sofa::core::objectmodel::BaseObjectDescription; -using sofa::simulation::Simulation ; +using sofa::simulation::Simulation; +using sofa::simulation::SimulationSPtr ; using sofa::simulation::Node ; using sofa::simulation::NodeSPtr ; bool SOFA_SIMPLEAPI_API importPlugin(const std::string& name) ; -Simulation::SPtr SOFA_SIMPLEAPI_API createSimulation(const std::string& type="DAG") ; +SimulationSPtr SOFA_SIMPLEAPI_API createSimulation(const std::string& type="DAG") ; -NodeSPtr SOFA_SIMPLEAPI_API createRootNode( Simulation::SPtr, const std::string& name, +NodeSPtr SOFA_SIMPLEAPI_API createRootNode( SimulationSPtr, const std::string& name, const std::map& params = std::map{} ); NodeSPtr SOFA_SIMPLEAPI_API createRootNode( Simulation* s, const std::string& name, diff --git a/Sofa/framework/Simulation/Common/src/sofa/simulation/common/init.cpp b/Sofa/framework/Simulation/Common/src/sofa/simulation/common/init.cpp index e6622d961b7..ea9a1dfdb2c 100644 --- a/Sofa/framework/Simulation/Common/src/sofa/simulation/common/init.cpp +++ b/Sofa/framework/Simulation/Common/src/sofa/simulation/common/init.cpp @@ -35,7 +35,8 @@ static bool s_initialized = false; static bool s_cleanedUp = false; //create method of Node called if the user wants the default node. The object created will depend on the simulation currently in use. -SOFA_SIMULATION_COMMON_API sofa::helper::Creator NodeClass("default"); +SOFA_SIMULATION_COMMON_API sofa::helper::Creator defaultNodeClassRegistration("default"); +SOFA_SIMULATION_COMMON_API sofa::helper::Creator nodeClassRegistration("Node"); SOFA_SIMULATION_COMMON_API void init() { diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.inl b/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.inl index 14cf15f7a1c..b2467477125 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.inl +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/Node.inl @@ -29,13 +29,9 @@ namespace sofa::simulation template Node::SPtr Node::create( RealObject*, sofa::core::objectmodel::BaseObjectDescription* arg) { - if (Simulation* simulation = getSimulation()) - { - Node::SPtr obj = simulation->createNewNode(arg->getName()); - obj->parse(arg); - return obj; - } - return nullptr; + Node::SPtr obj = getSimulation()->createNewNode(arg->getName()); + obj->parse(arg); + return obj; } } diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/Simulation.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/Simulation.cpp index cfade426869..b96fb431063 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/Simulation.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/Simulation.cpp @@ -78,6 +78,10 @@ using namespace sofa; namespace node { +NodeSPtr createNewNode(const std::string& name){ + return sofa::core::objectmodel::New(name); +} + void initRoot(Node* root) { SCOPED_TIMER("Simulation::init"); @@ -472,19 +476,26 @@ void unload(NodeSPtr root) } } -Simulation::Simulation() +Simulation theSimulation; +Simulation* getSimulation() { - // Safety check; it could be elsewhere, but here is a good place, I guess. - if (!sofa::simulation::core::isInitialized()) - sofa::helper::printUninitializedLibraryWarning("Sofa.Simulation.Core", "sofa::simulation::common::init()"); + return &theSimulation; } -Simulation::~Simulation() -{} +Simulation::Simulation(){} +Simulation::~Simulation(){} -Simulation* getSimulation() +/// create a new graph(or tree) and return its root node. +NodeSPtr Simulation::createNewGraph(const std::string& name) { - return Simulation::theSimulation.get(); + return createNewNode( name ); } +NodeSPtr Simulation::createNewNode(const std::string& name) +{ + return sofa::core::objectmodel::New(name); +} + +bool Simulation::isDirectedAcyclicGraph() { return true; } + } // namespace sofa::simulation diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/Simulation.h b/Sofa/framework/Simulation/Core/src/sofa/simulation/Simulation.h index a6befd116e5..889da81ee05 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/Simulation.h +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/Simulation.h @@ -22,69 +22,11 @@ #pragma once #include -#include -#include +#include +#include namespace sofa::simulation { - class Node; - typedef sofa::core::sptr NodeSPtr; -} - -namespace sofa::simulation -{ - -namespace node -{ - -/// Initialize the objects -void SOFA_SIMULATION_CORE_API initRoot(Node* root); -///Init a node without changing the context of the simulation. -void SOFA_SIMULATION_CORE_API init(Node* node); -/// Print all object in the graph in XML format -void SOFA_SIMULATION_CORE_API exportInXML(Node* root, const char* fileName); -/// Print all object in the graph -void SOFA_SIMULATION_CORE_API print(Node* root); -/// Update contexts. Required before drawing the scene if root flags are modified. -void SOFA_SIMULATION_CORE_API updateVisualContext(Node* root); -/// Execute one timestep. If dt is 0, the dt parameter in the graph will be used -void SOFA_SIMULATION_CORE_API animate(Node* root, SReal dt=0.0); -/// Update the Visual Models: triggers the Mappings -void SOFA_SIMULATION_CORE_API updateVisual(Node* root); -/// Reset to initial state -void SOFA_SIMULATION_CORE_API reset(Node* root); -/// Initialize the textures -void SOFA_SIMULATION_CORE_API initTextures(Node* root); -/// Update contexts. Required before drawing the scene if root flags are modified. -void SOFA_SIMULATION_CORE_API updateContext(Node* root); - -/** Compute the bounding box of the scene. - * If init is set to "true", then minBBox and maxBBox will be initialised to a default value - * @warning MechanicalObjects with showObject member set to false are ignored - * @sa computeTotalBBox(Node* root, SReal* minBBox, SReal* maxBBox) - */ -void SOFA_SIMULATION_CORE_API computeBBox(Node* root, SReal* minBBox, SReal* maxBBox, bool init=true); - -/** Compute the bounding box of the scene. - * Includes all objects, may they be displayed or not. - * @sa computeBBox(Node* root, SReal* minBBox, SReal* maxBBox, bool init=true) - * @deprecated - */ -void SOFA_SIMULATION_CORE_API computeTotalBBox(Node* root, SReal* minBBox, SReal* maxBBox); -/// Render the scene -void SOFA_SIMULATION_CORE_API draw(sofa::core::visual::VisualParams* vparams, Node* root); -/// Export a scene to an OBJ 3D Scene -void SOFA_SIMULATION_CORE_API exportOBJ(Node* root, const char* filename, bool exportMTL = true); -/// Print all objects in the graph in the given file (format is given by the filename extension) -void SOFA_SIMULATION_CORE_API exportGraph(Node* root, const char* filename=nullptr); -/// Dump the current state in the given stream -void SOFA_SIMULATION_CORE_API dumpState( Node* root, std::ofstream& out ); -/// Load a scene from a file -NodeSPtr SOFA_SIMULATION_CORE_API load(const std::string& /* filename */, bool reload = false, const std::vector& sceneArgs = std::vector(0)); -/// Unload a scene from a Node. -void SOFA_SIMULATION_CORE_API unload(NodeSPtr root); - -} /** Main controller of the scene. Defines how the scene is inited at the beginning, and updated at each time step. @@ -103,15 +45,13 @@ class SOFA_SIMULATION_CORE_API Simulation Simulation& operator=(const Simulation& n) = delete; /// create a new graph(or tree) and return its root node. - virtual NodeSPtr createNewGraph(const std::string& name)=0;//Todo replace newNode method + virtual NodeSPtr createNewGraph(const std::string& name);//Todo replace newNode method /// creates and returns a new node. - virtual NodeSPtr createNewNode(const std::string& name)=0; + virtual NodeSPtr createNewNode(const std::string& name); /// Can the simulation handle a directed acyclic graph? - virtual bool isDirectedAcyclicGraph() = 0; - - inline static Simulation::SPtr theSimulation { nullptr }; + virtual bool isDirectedAcyclicGraph(); }; } // namespace sofa::simulation diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/fwd.h b/Sofa/framework/Simulation/Core/src/sofa/simulation/fwd.h index f8ab1cf945e..f17f85db33e 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/fwd.h +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/fwd.h @@ -24,6 +24,7 @@ #include #include #include +#include #include namespace sofa::core::objectmodel { class BaseContext; } @@ -34,7 +35,7 @@ namespace sofa::simulation typedef sofa::core::sptr NodeSPtr; class Simulation; - typedef sofa::core::sptr SimulationSPtr; + using SimulationSPtr = std::shared_ptr; /** Get the (unique) simulation which controls the scene. Automatically creates one if no Simulation has been set. @@ -51,6 +52,57 @@ namespace sofa::simulation::node { SOFA_SIMULATION_CORE_API sofa::core::objectmodel::BaseContext* toBaseContext(Node*); SOFA_SIMULATION_CORE_API Node* getNodeFrom(sofa::core::objectmodel::BaseContext*); + +// Create a new node; +SOFA_SIMULATION_CORE_API NodeSPtr createNewNode(const std::string& name); + +/// Initialize the objects +void SOFA_SIMULATION_CORE_API initRoot(Node* root); +///Init a node without changing the context of the simulation. +void SOFA_SIMULATION_CORE_API init(Node* node); +/// Print all object in the graph in XML format +void SOFA_SIMULATION_CORE_API exportInXML(Node* root, const char* fileName); +/// Print all object in the graph +void SOFA_SIMULATION_CORE_API print(Node* root); +/// Update contexts. Required before drawing the scene if root flags are modified. +void SOFA_SIMULATION_CORE_API updateVisualContext(Node* root); +/// Execute one timestep. If dt is 0, the dt parameter in the graph will be used +void SOFA_SIMULATION_CORE_API animate(Node* root, SReal dt=0.0); +/// Update the Visual Models: triggers the Mappings +void SOFA_SIMULATION_CORE_API updateVisual(Node* root); +/// Reset to initial state +void SOFA_SIMULATION_CORE_API reset(Node* root); +/// Initialize the textures +void SOFA_SIMULATION_CORE_API initTextures(Node* root); +/// Update contexts. Required before drawing the scene if root flags are modified. +void SOFA_SIMULATION_CORE_API updateContext(Node* root); + +/** Compute the bounding box of the scene. + * If init is set to "true", then minBBox and maxBBox will be initialised to a default value + * @warning MechanicalObjects with showObject member set to false are ignored + * @sa computeTotalBBox(Node* root, SReal* minBBox, SReal* maxBBox) + */ +void SOFA_SIMULATION_CORE_API computeBBox(Node* root, SReal* minBBox, SReal* maxBBox, bool init=true); + +/** Compute the bounding box of the scene. + * Includes all objects, may they be displayed or not. + * @sa computeBBox(Node* root, SReal* minBBox, SReal* maxBBox, bool init=true) + * @deprecated + */ +void SOFA_SIMULATION_CORE_API computeTotalBBox(Node* root, SReal* minBBox, SReal* maxBBox); +/// Render the scene +void SOFA_SIMULATION_CORE_API draw(sofa::core::visual::VisualParams* vparams, Node* root); +/// Export a scene to an OBJ 3D Scene +void SOFA_SIMULATION_CORE_API exportOBJ(Node* root, const char* filename, bool exportMTL = true); +/// Print all objects in the graph in the given file (format is given by the filename extension) +void SOFA_SIMULATION_CORE_API exportGraph(Node* root, const char* filename=nullptr); +/// Dump the current state in the given stream +void SOFA_SIMULATION_CORE_API dumpState( Node* root, std::ofstream& out ); +/// Load a scene from a file +NodeSPtr SOFA_SIMULATION_CORE_API load(const std::string& /* filename */, bool reload = false, const std::vector& sceneArgs = std::vector(0)); +/// Unload a scene from a Node. +void SOFA_SIMULATION_CORE_API unload(NodeSPtr root); + } namespace sofa::core diff --git a/Sofa/framework/Simulation/Graph/CMakeLists.txt b/Sofa/framework/Simulation/Graph/CMakeLists.txt index b3d07bd5a51..9e7f4bf0af5 100644 --- a/Sofa/framework/Simulation/Graph/CMakeLists.txt +++ b/Sofa/framework/Simulation/Graph/CMakeLists.txt @@ -14,8 +14,6 @@ set(HEADER_FILES set(SOURCE_FILES ${SOFASIMULATIONGRAPH_SRC}/init.cpp ${SOFASIMULATIONGRAPH_SRC}/initSofaSimulationGraph.cpp - ${SOFASIMULATIONGRAPH_SRC}/DAGNode.cpp - ${SOFASIMULATIONGRAPH_SRC}/DAGSimulation.cpp ) sofa_find_package(Sofa.Simulation.Common REQUIRED) diff --git a/Sofa/framework/Simulation/Graph/src/sofa/simulation/graph/DAGNode.cpp b/Sofa/framework/Simulation/Graph/src/sofa/simulation/graph/DAGNode.cpp index 4507024ebd5..e69de29bb2d 100644 --- a/Sofa/framework/Simulation/Graph/src/sofa/simulation/graph/DAGNode.cpp +++ b/Sofa/framework/Simulation/Graph/src/sofa/simulation/graph/DAGNode.cpp @@ -1,31 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture * -* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * -* * -* This program is free software; you can redistribute it and/or modify it * -* under the terms of the GNU Lesser General Public License as published by * -* the Free Software Foundation; either version 2.1 of the License, or (at * -* your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, but WITHOUT * -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * -* for more details. * -* * -* You should have received a copy of the GNU Lesser General Public License * -* along with this program. If not, see . * -******************************************************************************* -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#include -#include - -namespace sofa::simulation -{ - -//helper::Creator NodeDefaultClass("default"); -static helper::Creator NodeClass("Node"); - -} diff --git a/Sofa/framework/Simulation/Graph/src/sofa/simulation/graph/DAGSimulation.cpp b/Sofa/framework/Simulation/Graph/src/sofa/simulation/graph/DAGSimulation.cpp index baa0bbf1a22..8b137891791 100644 --- a/Sofa/framework/Simulation/Graph/src/sofa/simulation/graph/DAGSimulation.cpp +++ b/Sofa/framework/Simulation/Graph/src/sofa/simulation/graph/DAGSimulation.cpp @@ -1,60 +1 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture * -* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * -* * -* This program is free software; you can redistribute it and/or modify it * -* under the terms of the GNU Lesser General Public License as published by * -* the Free Software Foundation; either version 2.1 of the License, or (at * -* your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, but WITHOUT * -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * -* for more details. * -* * -* You should have received a copy of the GNU Lesser General Public License * -* along with this program. If not, see . * -******************************************************************************* -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#include -#include -#include -#include - -#include -#include -#include - -namespace sofa::simulation::graph -{ - -using namespace sofa::defaulttype; - - -DAGSimulation::DAGSimulation() -{ - // Safety check; it could be elsewhere, but here is a good place, I guess. - if (!sofa::simulation::graph::isInitialized()) - sofa::helper::printUninitializedLibraryWarning("Sofa.Simulation.Graph", "sofa::simulation::graph::init()"); -} - -DAGSimulation::~DAGSimulation() -{ - -} - -Node::SPtr DAGSimulation::createNewGraph(const std::string& name) -{ - return createNewNode( name ); -} - -Node::SPtr DAGSimulation::createNewNode(const std::string& name) -{ - return sofa::core::objectmodel::New(name); -} - -} // namespace sofa::simulation::graph diff --git a/Sofa/framework/Simulation/Graph/src/sofa/simulation/graph/DAGSimulation.h b/Sofa/framework/Simulation/Graph/src/sofa/simulation/graph/DAGSimulation.h index 00f00178a23..c3b2177b424 100644 --- a/Sofa/framework/Simulation/Graph/src/sofa/simulation/graph/DAGSimulation.h +++ b/Sofa/framework/Simulation/Graph/src/sofa/simulation/graph/DAGSimulation.h @@ -29,25 +29,5 @@ namespace sofa::simulation::graph { - -/** Main controller of the scene. -Defines how the scene is inited at the beginning, and updated at each time step. -Derives from BaseObject in order to model the parameters as Datas, which makes their edition easy in the GUI. - */ -class SOFA_SIMULATION_GRAPH_API DAGSimulation: public Simulation -{ -public: - DAGSimulation(); - ~DAGSimulation() override; // this is a terminal class - - /// create a new graph(or tree) and return its root node. - virtual NodeSPtr createNewGraph(const std::string& name) override; - - /// creates and returns a new node. - virtual NodeSPtr createNewNode(const std::string& name) override; - - /// Can the simulation handle a directed acyclic graph? - bool isDirectedAcyclicGraph() override { return true; } -}; - + using DAGSimulation = Simulation; } // namespace sofa::simulation::graph diff --git a/Sofa/framework/Simulation/Graph/src/sofa/simulation/graph/init.cpp b/Sofa/framework/Simulation/Graph/src/sofa/simulation/graph/init.cpp index 4d1fa04597f..d8d62c33432 100644 --- a/Sofa/framework/Simulation/Graph/src/sofa/simulation/graph/init.cpp +++ b/Sofa/framework/Simulation/Graph/src/sofa/simulation/graph/init.cpp @@ -37,7 +37,6 @@ SOFA_SIMULATION_GRAPH_API void init() { sofa::simulation::common::init(); s_initialized = true; - sofa::simulation::Simulation::theSimulation = std::make_shared(); } } diff --git a/applications/plugins/SceneCreator/src/SceneCreator/SceneCreator.cpp b/applications/plugins/SceneCreator/src/SceneCreator/SceneCreator.cpp index 61ab852d8b2..febbd3e8e02 100644 --- a/applications/plugins/SceneCreator/src/SceneCreator/SceneCreator.cpp +++ b/applications/plugins/SceneCreator/src/SceneCreator/SceneCreator.cpp @@ -24,7 +24,6 @@ #include #include -#include #include "GetVectorVisitor.h" #include "GetAssembledSizeVisitor.h" @@ -50,7 +49,6 @@ using namespace sofa::defaulttype ; using type::vector; -using sofa::simulation::graph::DAGSimulation ; using sofa::simulation::GetAssembledSizeVisitor ; using sofa::simulation::GetVectorVisitor ; using sofa::simulation::Node ; diff --git a/applications/plugins/SceneCreator/src/SceneCreator/SceneUtils.cpp b/applications/plugins/SceneCreator/src/SceneCreator/SceneUtils.cpp index 991f3a59e40..70dcebd8692 100644 --- a/applications/plugins/SceneCreator/src/SceneCreator/SceneUtils.cpp +++ b/applications/plugins/SceneCreator/src/SceneCreator/SceneUtils.cpp @@ -22,7 +22,6 @@ #include "SceneCreator.h" #include "SceneUtils.h" -#include #include "GetVectorVisitor.h" #include "GetAssembledSizeVisitor.h" @@ -52,7 +51,6 @@ typedef linearalgebra::FullVector FullVector ; using type::vector; -using sofa::simulation::graph::DAGSimulation ; using sofa::simulation::GetAssembledSizeVisitor ; using sofa::simulation::GetVectorVisitor ; using sofa::simulation::Node ; diff --git a/applications/projects/runSofa/Main.cpp b/applications/projects/runSofa/Main.cpp index 52ddbd3548f..e3f9b385e7d 100644 --- a/applications/projects/runSofa/Main.cpp +++ b/applications/projects/runSofa/Main.cpp @@ -36,7 +36,7 @@ using std::vector; #include #include #include -#include +#include using sofa::simulation::Node; #include #include @@ -59,7 +59,6 @@ using sofa::core::ExecParams ; #include using sofa::helper::Utils; -using sofa::simulation::graph::DAGSimulation; using sofa::helper::system::SetDirectory; using sofa::core::objectmodel::BaseNode ; @@ -471,7 +470,7 @@ int main(int argc, char** argv) const std::vector sceneArgs = sofa::gui::common::ArgumentParser::extra_args(); Node::SPtr groot = sofa::simulation::node::load(fileName, false, sceneArgs); if( !groot ) - groot = sofa::simulation::getSimulation()->createNewGraph(""); + groot = sofa::simulation::node::createNewNode(""); if (!verif.empty()) {