Part: Geometry - methods to remove extensions by name and type

This commit is contained in:
Abdullah Tahiri
2019-02-11 16:00:26 +01:00
committed by wmayer
parent 1700760e0b
commit 4d9d3b0c83
4 changed files with 82 additions and 0 deletions

View File

@@ -301,6 +301,28 @@ void Geometry::setExtension(std::unique_ptr<GeometryExtension> && geo)
extensions.push_back(std::move(geo));
}
void Geometry::deleteExtension(Base::Type type)
{
extensions.erase(
std::remove_if( extensions.begin(),
extensions.end(),
[&type](const std::shared_ptr<GeometryExtension>& ext){
return ext->getTypeId() == type;
}),
extensions.end());
}
void Geometry::deleteExtension(std::string name)
{
extensions.erase(
std::remove_if( extensions.begin(),
extensions.end(),
[&name](const std::shared_ptr<GeometryExtension>& ext){
return ext->getName() == name;
}),
extensions.end());
}
void Geometry::createNewTag()
{

View File

@@ -102,6 +102,8 @@ public:
bool hasExtension(Base::Type type) const;
const std::weak_ptr<GeometryExtension> getExtension(Base::Type type) const;
void setExtension(std::unique_ptr<GeometryExtension> &&geo);
void deleteExtension(Base::Type type);
void deleteExtension(std::string name);
protected:
/// create a new tag for the geometry object

View File

@@ -63,6 +63,16 @@ It describes the common behavior of these objects when:
<UserDocu>Sets a geometry extension of the indicated type.</UserDocu>
</Documentation>
</Methode>
<Methode Name="deleteExtensionType" Const="false">
<Documentation>
<UserDocu>Deletes all extensions of the indicated type.</UserDocu>
</Documentation>
</Methode>
<Methode Name="deleteExtensionName" Const="false">
<Documentation>
<UserDocu>Deletes all extensions of the indicated name.</UserDocu>
</Documentation>
</Methode>
<Methode Name="showExtensions" Const="true">
<Documentation>
<UserDocu>Returns a list with information about the geometry extensions.</UserDocu>

View File

@@ -291,6 +291,54 @@ PyObject* GeometryPy::getExtension(PyObject *args)
return 0;
}
PyObject* GeometryPy::deleteExtensionType(PyObject *args)
{
char* o;
if (PyArg_ParseTuple(args, "s", &o)) {
Base::Type type = Base::Type::fromName(o);
if(type != Base::Type::badType()) {
try {
this->getGeometryPtr()->deleteExtension(type);
Py_Return;
}
catch(Base::ValueError e) {
PyErr_SetString(PartExceptionOCCError, e.what());
return 0;
}
}
else
{
PyErr_SetString(PartExceptionOCCError, "Type does not exist");
return 0;
}
}
PyErr_SetString(PartExceptionOCCError, "A string with a type object was expected");
return 0;
}
PyObject* GeometryPy::deleteExtensionName(PyObject *args)
{
char* o;
if (PyArg_ParseTuple(args, "s", &o)) {
try {
this->getGeometryPtr()->deleteExtension(std::string(o));
Py_Return;
}
catch(Base::ValueError e) {
PyErr_SetString(PartExceptionOCCError, e.what());
return 0;
}
}
PyErr_SetString(PartExceptionOCCError, "A string with the name of the extension was expected");
return 0;
}
PyObject* GeometryPy::showExtensions(PyObject *args)
{
if (!PyArg_ParseTuple(args, "")){