Part Geometry: get an extension from type or name, also from python

This commit is contained in:
Abdullah Tahiri
2019-02-11 17:04:30 +01:00
committed by wmayer
parent afbe1df322
commit 11793ba0b2
4 changed files with 63 additions and 16 deletions

View File

@@ -296,6 +296,16 @@ const std::weak_ptr<GeometryExtension> Geometry::getExtension(Base::Type type) c
throw Base::ValueError("No geometry extension of the requested type.");
}
const std::weak_ptr<GeometryExtension> Geometry::getExtension(std::string name) const
{
for( auto ext : extensions) {
if(ext->getName() == name)
return ext;
}
throw Base::ValueError("No geometry extension with the requested name.");
}
void Geometry::setExtension(std::unique_ptr<GeometryExtension> && geo)
{
bool hasext=false;

View File

@@ -102,6 +102,7 @@ public:
bool hasExtension(Base::Type type) const;
bool hasExtension(std::string name) const;
const std::weak_ptr<GeometryExtension> getExtension(Base::Type type) const;
const std::weak_ptr<GeometryExtension> getExtension(std::string name) const;
void setExtension(std::unique_ptr<GeometryExtension> &&geo);
void deleteExtension(Base::Type type);
void deleteExtension(std::string name);

View File

@@ -53,19 +53,24 @@ It describes the common behavior of these objects when:
<UserDocu>Create a clone of this geometry with the same Tag</UserDocu>
</Documentation>
</Methode>
<Methode Name="hasExtensionType" Const="true">
<Methode Name="hasExtensionOfType" Const="true">
<Documentation>
<UserDocu>Returns a boolean indicating whether a geometry extension of the type indicated as a string exists.</UserDocu>
</Documentation>
</Methode>
<Methode Name="hasExtensionName" Const="true">
<Methode Name="hasExtensionOfName" Const="true">
<Documentation>
<UserDocu>Returns a boolean indicating whether a geometry extension with the name indicated as a string exists.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getExtension" Const="true">
<Methode Name="getExtensionOfType" Const="true">
<Documentation>
<UserDocu>Gets a geometry extension of the indicated type.</UserDocu>
<UserDocu>Gets the first geometry extension of the type indicated by the string.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getExtensionOfName" Const="true">
<Documentation>
<UserDocu>Gets the first geometry extension of the name indicated by the string.</UserDocu>
</Documentation>
</Methode>
<Methode Name="setExtension" Const="false">
@@ -73,12 +78,12 @@ 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">
<Methode Name="deleteExtensionOfType" Const="false">
<Documentation>
<UserDocu>Deletes all extensions of the indicated type.</UserDocu>
</Documentation>
</Methode>
<Methode Name="deleteExtensionName" Const="false">
<Methode Name="deleteExtensionOfName" Const="false">
<Documentation>
<UserDocu>Deletes all extensions of the indicated name.</UserDocu>
</Documentation>

View File

@@ -257,7 +257,7 @@ PyObject* GeometryPy::setExtension(PyObject *args)
return 0;
}
PyObject* GeometryPy::getExtension(PyObject *args)
PyObject* GeometryPy::getExtensionOfType(PyObject *args)
{
char* o;
if (PyArg_ParseTuple(args, "s", &o)) {
@@ -266,18 +266,21 @@ PyObject* GeometryPy::getExtension(PyObject *args)
if(type != Base::Type::badType()) {
try {
const std::weak_ptr<GeometryExtension> ext = this->getGeometryPtr()->getExtension(type);
std::shared_ptr<GeometryExtension> ext(this->getGeometryPtr()->getExtension(type));
std::unique_ptr<GeometryExtension> cext = ext.lock()->copy();
// we create a copy and tranfer this copy's memory management responsibility to Python
GeometryExtension * rext = ext->copy().release();
GeometryExtension * pcext = cext.release();
return pcext->getPyObject();
return rext->getPyObject();
}
catch(Base::ValueError e) {
PyErr_SetString(PartExceptionOCCError, e.what());
return 0;
}
catch(std::bad_weak_ptr e) {
PyErr_SetString(PartExceptionOCCError, "Geometry extension does not exist anymore.");
return 0;
}
}
else
{
@@ -291,7 +294,35 @@ PyObject* GeometryPy::getExtension(PyObject *args)
return 0;
}
PyObject* GeometryPy::hasExtensionType(PyObject *args)
PyObject* GeometryPy::getExtensionOfName(PyObject *args)
{
char* o;
if (PyArg_ParseTuple(args, "s", &o)) {
try {
std::shared_ptr<GeometryExtension> ext(this->getGeometryPtr()->getExtension(std::string(o)));
// we create a copy and tranfer this copy's memory management responsibility to Python
GeometryExtension * rext = ext->copy().release();
return rext->getPyObject();
}
catch(Base::ValueError e) {
PyErr_SetString(PartExceptionOCCError, e.what());
return 0;
}
catch(std::bad_weak_ptr e) {
PyErr_SetString(PartExceptionOCCError, "Geometry extension does not exist anymore.");
return 0;
}
}
PyErr_SetString(PartExceptionOCCError, "A string with the name of the geometry extension was expected");
return 0;
}
PyObject* GeometryPy::hasExtensionOfType(PyObject *args)
{
char* o;
if (PyArg_ParseTuple(args, "s", &o)) {
@@ -319,7 +350,7 @@ PyObject* GeometryPy::hasExtensionType(PyObject *args)
return 0;
}
PyObject* GeometryPy::hasExtensionName(PyObject *args)
PyObject* GeometryPy::hasExtensionOfName(PyObject *args)
{
char* o;
if (PyArg_ParseTuple(args, "s", &o)) {
@@ -338,7 +369,7 @@ PyObject* GeometryPy::hasExtensionName(PyObject *args)
return 0;
}
PyObject* GeometryPy::deleteExtensionType(PyObject *args)
PyObject* GeometryPy::deleteExtensionOfType(PyObject *args)
{
char* o;
if (PyArg_ParseTuple(args, "s", &o)) {
@@ -367,7 +398,7 @@ PyObject* GeometryPy::deleteExtensionType(PyObject *args)
return 0;
}
PyObject* GeometryPy::deleteExtensionName(PyObject *args)
PyObject* GeometryPy::deleteExtensionOfName(PyObject *args)
{
char* o;
if (PyArg_ParseTuple(args, "s", &o)) {