Skip to content

Commit 38ff5db

Browse files
committed
Updated getCategories() method
1 parent f89ac22 commit 38ff5db

File tree

1 file changed

+7
-63
lines changed

1 file changed

+7
-63
lines changed

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

Lines changed: 7 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@
5151
#include <sofa/core/collision/Pipeline.h>
5252
#include <sofa/core/collision/Intersection.h>
5353
#include <sofa/core/objectmodel/ConfigurationSetting.h>
54-
5554
#include <sofa/core/ExecParams.h>
55+
#include <sofa/core/CategoryLibrary.h>
56+
#include <pybind11/stl.h>
57+
5658

5759
/// Makes an alias for the pybind11 namespace to increase readability.
5860
namespace py { using namespace pybind11; }
@@ -133,69 +135,11 @@ py::object getTarget(BaseObject *self)
133135

134136
py::object getCategories(BaseObject *self)
135137
{
136-
const sofa::core::objectmodel::BaseClass* mclass=self->getClass();
137138
std::vector<std::string> categories;
138-
if (mclass->hasParent(sofa::core::objectmodel::ContextObject::GetClass()))
139-
categories.push_back("ContextObject");
140-
if (mclass->hasParent(sofa::core::visual::VisualModel::GetClass()))
141-
categories.push_back("VisualModel");
142-
if (mclass->hasParent(sofa::core::BehaviorModel::GetClass()))
143-
categories.push_back("BehaviorModel");
144-
if (mclass->hasParent(sofa::core::CollisionModel::GetClass()))
145-
categories.push_back("CollisionModel");
146-
if (mclass->hasParent(sofa::core::behavior::BaseMechanicalState::GetClass()))
147-
categories.push_back("MechanicalState");
148-
// A Mass is a technically a ForceField, but we don't want it to appear in the ForceField category
149-
if (mclass->hasParent(sofa::core::behavior::BaseForceField::GetClass()) && !mclass->hasParent(sofa::core::behavior::BaseMass::GetClass()))
150-
categories.push_back("ForceField");
151-
if (mclass->hasParent(sofa::core::behavior::BaseInteractionForceField::GetClass()))
152-
categories.push_back("InteractionForceField");
153-
if (mclass->hasParent(sofa::core::behavior::BaseProjectiveConstraintSet::GetClass()))
154-
categories.push_back("ProjectiveConstraintSet");
155-
if (mclass->hasParent(sofa::core::behavior::BaseConstraintSet::GetClass()))
156-
categories.push_back("ConstraintSet");
157-
if (mclass->hasParent(sofa::core::BaseMapping::GetClass()))
158-
categories.push_back("Mapping");
159-
if (mclass->hasParent(sofa::core::DataEngine::GetClass()))
160-
categories.push_back("Engine");
161-
if (mclass->hasParent(sofa::core::topology::TopologicalMapping::GetClass()))
162-
categories.push_back("TopologicalMapping");
163-
if (mclass->hasParent(sofa::core::behavior::BaseMass::GetClass()))
164-
categories.push_back("Mass");
165-
if (mclass->hasParent(sofa::core::behavior::OdeSolver::GetClass()))
166-
categories.push_back("OdeSolver");
167-
if (mclass->hasParent(sofa::core::behavior::ConstraintSolver::GetClass()))
168-
categories.push_back("ConstraintSolver");
169-
if (mclass->hasParent(sofa::core::behavior::BaseConstraintCorrection::GetClass()))
170-
categories.push_back("ConstraintSolver");
171-
if (mclass->hasParent(sofa::core::behavior::LinearSolver::GetClass()))
172-
categories.push_back("LinearSolver");
173-
if (mclass->hasParent(sofa::core::behavior::BaseAnimationLoop::GetClass()))
174-
categories.push_back("AnimationLoop");
175-
// Just like Mass and ForceField, we don't want TopologyObject to appear in the Topology category
176-
if (mclass->hasParent(sofa::core::topology::Topology::GetClass()) && !mclass->hasParent(sofa::core::topology::BaseTopologyObject::GetClass()))
177-
categories.push_back("Topology");
178-
if (mclass->hasParent(sofa::core::topology::BaseTopologyObject::GetClass()))
179-
categories.push_back("TopologyObject");
180-
if (mclass->hasParent(sofa::core::behavior::BaseController::GetClass()))
181-
categories.push_back("Controller");
182-
if (mclass->hasParent(sofa::core::loader::BaseLoader::GetClass()))
183-
categories.push_back("Loader");
184-
if (mclass->hasParent(sofa::core::collision::CollisionAlgorithm::GetClass()))
185-
categories.push_back("CollisionAlgorithm");
186-
if (mclass->hasParent(sofa::core::collision::Pipeline::GetClass()))
187-
categories.push_back("CollisionAlgorithm");
188-
if (mclass->hasParent(sofa::core::collision::Intersection::GetClass()))
189-
categories.push_back("CollisionAlgorithm");
190-
if (mclass->hasParent(sofa::core::objectmodel::ConfigurationSetting::GetClass()))
191-
categories.push_back("ConfigurationSetting");
192-
if (categories.empty())
193-
categories.push_back("Miscellaneous");
194-
195-
py::list list;
196-
for (unsigned int i=0; i<categories.size(); ++i)
197-
list.append(py::cast(categories[i].c_str())) ;
198-
return list;
139+
const sofa::core::objectmodel::BaseClass* c=self->getClass();
140+
sofa::core::CategoryLibrary::getCategories(c, categories);
141+
py::list l = py::cast(categories);
142+
return std::move(l);
199143
}
200144

201145
std::string getAsACreateObjectParameter(BaseObject *self)

0 commit comments

Comments
 (0)