Sketcher: Expose delGeometries function to Python

This commit is contained in:
Abdullah Tahiri
2021-01-04 11:16:35 +01:00
committed by abdullahtahiriyo
parent 37836ed666
commit cf7422af4f
2 changed files with 43 additions and 0 deletions

View File

@@ -28,6 +28,11 @@
<UserDocu>delete a geometric object from the sketch</UserDocu>
</Documentation>
</Methode>
<Methode Name="delGeometries">
<Documentation>
<UserDocu>delete a list of geometric objects from the sketch, including any internal alignment geometry thereof</UserDocu>
</Documentation>
</Methode>
<Methode Name="deleteAllGeometry">
<Documentation>
<UserDocu>delete all the geometry objects and constraints from the sketch except external geometry</UserDocu>

View File

@@ -216,6 +216,44 @@ PyObject* SketchObjectPy::delGeometry(PyObject *args)
Py_Return;
}
PyObject* SketchObjectPy::delGeometries(PyObject *args)
{
PyObject *pcObj;
if (!PyArg_ParseTuple(args, "O", &pcObj))
return 0;
if (PyObject_TypeCheck(pcObj, &(PyList_Type)) ||
PyObject_TypeCheck(pcObj, &(PyTuple_Type)) ) {
std::vector<int> geoIdList;
Py::Sequence list(pcObj);
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
#if PY_MAJOR_VERSION >= 3
if (PyLong_Check((*it).ptr()))
geoIdList.push_back(PyLong_AsLong((*it).ptr()));
#else
if (PyInt_Check((*it).ptr()))
geoIdList.push_back(PyInt_AsLong((*it).ptr()));
#endif
}
if(this->getSketchObjectPtr()->delGeometries(geoIdList)) {
std::stringstream str;
str << "Not able to delete geometries";
PyErr_SetString(PyExc_ValueError, str.str().c_str());
return 0;
}
Py_Return;
}
std::string error = std::string("type must be list of GeoIds, not ");
error += pcObj->ob_type->tp_name;
throw Py::TypeError(error);
}
PyObject* SketchObjectPy::deleteAllGeometry(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))