Skip to content

Commit

Permalink
Merge pull request #422 from alxbilger/json
Browse files Browse the repository at this point in the history
Introduce binding to dump the object factory in json format
  • Loading branch information
bakpaul authored Jul 23, 2024
2 parents 1b5d271 + 812a2e8 commit 0334c20
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <numeric>
#include <sstream>
#include <pybind11/stl.h>
#include <sofa/core/ObjectFactoryJson.h>

using sofa::core::ObjectFactory;
namespace py { using namespace pybind11; }
Expand Down Expand Up @@ -221,6 +222,10 @@ void moduleAddObjectFactory(py::module &m) {
factory.def_property_readonly_static("targets", [](const py::object &){
return getTargets(*ObjectFactory::getInstance());
}, doc::objectmodel::ObjectFactory_targets);

factory.def_static("dump_json", [](){
return sofa::core::ObjectFactoryJson::dump(ObjectFactory::getInstance());
}, doc::objectmodel::ObjectFactory_targets);
}

} /// namespace sofapython3
9 changes: 9 additions & 0 deletions bindings/Sofa/tests/Core/ObjectFactory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import unittest
import Sofa

class Test(unittest.TestCase):

def test_dump_json(self):

json = Sofa.Core.ObjectFactory.dump_json()
self.assertIn("MechanicalObject", json, "MechanicalObject is not found in the json dump of the ObjectFactory")

0 comments on commit 0334c20

Please sign in to comment.