Skip to content

Commit e011262

Browse files
committed
Placing MessageHandlers (Console and PerComponent) in SofaRuntime.init()
1 parent 99d1127 commit e011262

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

bindings/Sofa/src/SofaPython3/Sofa/Core/Submodule_Core.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ along with sofaqtquick. If not, see <http://www.gnu.org/licenses/>.
2929
#include <sofa/helper/logging/Messaging.h>
3030
using sofa::helper::logging::Message;
3131

32-
#include <sofa/core/logging/PerComponentLoggingMessageHandler.h>
33-
using sofa::helper::logging::MessageDispatcher;
34-
using sofa::helper::logging::MainPerComponentLoggingMessageHandler;
35-
36-
3732
#include <sofa/core/objectmodel/BaseNode.h>
3833
#include <sofa/core/objectmodel/BaseContext.h>
3934
#include <sofa/core/behavior/BaseForceField.h>
@@ -113,8 +108,6 @@ PYBIND11_MODULE(Core, core)
113108
#Sofa.Core.WriteAccessor
114109
)doc";
115110

116-
MessageDispatcher::addHandler(&MainPerComponentLoggingMessageHandler::getInstance()) ;
117-
118111
moduleAddPythonScriptEvent();
119112
moduleAddDataDict(core);
120113
moduleAddDataDictIterator(core);
@@ -132,12 +125,10 @@ PYBIND11_MODULE(Core, core)
132125
moduleAddDataEngine(core);
133126
moduleAddForceField(core);
134127
moduleAddObjectFactory(core);
135-
136128
moduleAddNode(core);
137129
moduleAddNodeIterator(core);
138130
moduleAddPrefab(core);
139131
moduleAddBaseLink(core);
140-
141132
}
142133

143134
} ///namespace sofapython3

bindings/Sofa/src/SofaPython3/Sofa/Simulation/Submodule_Simulation.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ using sofa::simulation::Simulation;
4141

4242
#include <sofa/core/visual/VisualParams.h>
4343
#include <sofa/helper/logging/MessageDispatcher.h>
44-
using sofa::helper::logging::MessageDispatcher;
4544
#include <sofa/helper/logging/ConsoleMessageHandler.h>
45+
#include <sofa/core/logging/PerComponentLoggingMessageHandler.h>
46+
using sofa::helper::logging::MessageDispatcher;
47+
using sofa::helper::logging::MainPerComponentLoggingMessageHandler;
4648
#include "Submodule_Simulation_doc.h"
4749

4850
namespace py = pybind11;
@@ -59,11 +61,7 @@ PYBIND11_MODULE(Simulation, simulation)
5961

6062
simulation.def("print", [](Node* n){ sofa::simulation::getSimulation()->print(n); }, sofapython3::doc::simulation::print);
6163
simulation.def("animate", [](Node* n, SReal dt=0.0){ sofa::simulation::getSimulation()->animate(n, dt); },sofapython3::doc::simulation::animate);
62-
simulation.def("init", [](Node* n){
63-
sofa::simulation::getSimulation()->init(n);
64-
MessageDispatcher::clearHandlers();
65-
MessageDispatcher::addHandler(new sofa::helper::logging::ConsoleMessageHandler());
66-
}, sofapython3::doc::simulation::init);
64+
simulation.def("init", [](Node* n) { sofa::simulation::getSimulation()->init(n); }, sofapython3::doc::simulation::init);
6765
simulation.def("initVisual", [](Node* n){ n->getVisualLoop()->initStep(sofa::core::visual::VisualParams::defaultInstance()); });
6866
simulation.def("reset", [](Node* n){ sofa::simulation::getSimulation()->reset(n); }, sofapython3::doc::simulation::reset);
6967
simulation.def("load", [](const std::string & name) {

bindings/SofaRuntime/src/SofaPython3/SofaRuntime/Module_SofaRuntime.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ using sofapython3::SceneLoaderPY3;
6565

6666
#include <SofaPython3/DataHelper.h>
6767

68+
#include <sofa/helper/logging/MessageDispatcher.h>
69+
#include <sofa/helper/logging/ConsoleMessageHandler.h>
70+
#include <sofa/core/logging/PerComponentLoggingMessageHandler.h>
71+
using sofa::helper::logging::MessageDispatcher;
72+
using sofa::helper::logging::MainPerComponentLoggingMessageHandler;
73+
using sofa::helper::logging::MainConsoleMessageHandler;
74+
6875
namespace sofapython3
6976
{
7077

@@ -130,6 +137,12 @@ PYBIND11_MODULE(SofaRuntime, m) {
130137
return simpleapi::importPlugin(name);
131138
}, "import a sofa plugin into the current environment");
132139

140+
m.def("init", []() {
141+
MessageDispatcher::clearHandlers();
142+
MessageDispatcher::addHandler(&MainConsoleMessageHandler::getInstance());
143+
MessageDispatcher::addHandler(&MainPerComponentLoggingMessageHandler::getInstance());
144+
});
145+
133146
m.add_object("DataRepository", py::cast(&sofa::helper::system::DataRepository));
134147
m.add_object("PluginRepository", py::cast(&sofa::helper::system::PluginRepository));
135148

0 commit comments

Comments
 (0)