Sketcher/Part: Python handling of GeometryExtensions without a Python counterpart
================================================================================= Some geometry extensions do not provide a PyObject as they do not have a Python counterpart as it would serve no purpose to have it. This commit handles this situation making sure to provide the right error to Python or to ignore the extension where appropriate.
This commit is contained in:
committed by
abdullahtahiriyo
parent
40c0f0aa01
commit
9add3ba199
@@ -261,6 +261,10 @@ PyObject* GeometryPy::getExtensionOfType(PyObject *args)
|
||||
PyErr_SetString(PartExceptionOCCError, "Geometry extension does not exist anymore.");
|
||||
return 0;
|
||||
}
|
||||
catch(Base::NotImplementedError) {
|
||||
PyErr_SetString(Part::PartExceptionOCCError, "Geometry extension does not implement a Python counterpart.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -296,6 +300,10 @@ PyObject* GeometryPy::getExtensionOfName(PyObject *args)
|
||||
PyErr_SetString(PartExceptionOCCError, "Geometry extension does not exist anymore.");
|
||||
return 0;
|
||||
}
|
||||
catch(Base::NotImplementedError) {
|
||||
PyErr_SetString(Part::PartExceptionOCCError, "Geometry extension does not implement a Python counterpart.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -408,7 +416,7 @@ PyObject* GeometryPy::getExtensions(PyObject *args)
|
||||
try {
|
||||
const std::vector<std::weak_ptr<const GeometryExtension>> ext = this->getGeometryPtr()->getExtensions();
|
||||
|
||||
PyObject* list = PyList_New(ext.size());
|
||||
PyObject* list = PyList_New(0);
|
||||
|
||||
for (std::size_t i=0; i<ext.size(); ++i) {
|
||||
|
||||
@@ -417,10 +425,17 @@ PyObject* GeometryPy::getExtensions(PyObject *args)
|
||||
|
||||
if(p) {
|
||||
// we create a python copy and add it to the list
|
||||
Py::Tuple tuple;
|
||||
PyObject* cpy = static_cast<GeometryExtensionPy *>(p->getPyObject())->copy(tuple.ptr());
|
||||
|
||||
PyList_SetItem( list, i, cpy);
|
||||
try {
|
||||
Py::Tuple tuple;
|
||||
PyObject* cpy = static_cast<GeometryExtensionPy *>(p->getPyObject())->copy(tuple.ptr());
|
||||
|
||||
PyList_Append( list, cpy);
|
||||
Py_DECREF(cpy);
|
||||
}
|
||||
catch(Base::NotImplementedError) {
|
||||
// silently ignoring extensions not having a Python object
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user