Skip to content

Commit c31f49f

Browse files
committed
Adding the binding of the getCategories() method
1 parent d3c7367 commit c31f49f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ using sofa::helper::system::PluginRepository;
4848
using sofa::simulation::SceneLoaderFactory;
4949
using sofa::simulation::SceneLoader;
5050

51+
//
52+
#include <pybind11/stl.h>
53+
#include <sofa/core/ObjectFactory.h>
54+
using sofa::core::ObjectFactory;
55+
#include <sofa/core/CategoryLibrary.h>
56+
using sofa::core::CategoryLibrary;
57+
//
58+
59+
5160
#include <SofaPython3/SceneLoaderPY3.h>
5261
using sofapython3::SceneLoaderPY3;
5362

@@ -68,6 +77,7 @@ using sofapython3::SceneLoaderPY3;
6877
namespace sofapython3
6978
{
7079

80+
7181
class SofaInitializer
7282
{
7383
public:
@@ -85,7 +95,25 @@ class SofaInitializer
8595
}
8696
};
8797

98+
static std::vector<std::string> getCategories(std::string className)
99+
{
100+
std::vector<std::string> categories;
101+
ObjectFactory* factory = ObjectFactory::getInstance();
88102

103+
if (factory->hasCreator(className))
104+
{
105+
ObjectFactory::ClassEntry entry = factory->getEntry(className);
106+
ObjectFactory::CreatorMap::iterator it2 = entry.creatorMap.begin();
107+
108+
if( it2 != entry.creatorMap.end())
109+
{
110+
ObjectFactory::Creator::SPtr c = it2->second;
111+
const sofa::core::objectmodel::BaseClass* objClass = c->getClass();
112+
CategoryLibrary::getCategories(objClass,categories);
113+
}
114+
}
115+
return categories ;
116+
}
89117

90118
static SofaInitializer s;
91119

@@ -132,6 +160,7 @@ PYBIND11_MODULE(SofaRuntime, m) {
132160

133161
m.add_object("DataRepository", py::cast(&sofa::helper::system::DataRepository));
134162
m.add_object("PluginRepository", py::cast(&sofa::helper::system::PluginRepository));
163+
m.def("getCategories", &getCategories);
135164

136165
addSubmoduleTimer(m);
137166
}

0 commit comments

Comments
 (0)