From cf7422af4f597330d7daa6bdcfcb14bc1c42812a Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 4 Jan 2021 11:16:35 +0100 Subject: [PATCH] Sketcher: Expose delGeometries function to Python --- src/Mod/Sketcher/App/SketchObjectPy.xml | 5 +++ src/Mod/Sketcher/App/SketchObjectPyImp.cpp | 38 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/Mod/Sketcher/App/SketchObjectPy.xml b/src/Mod/Sketcher/App/SketchObjectPy.xml index 86b984fc23..11f340481c 100644 --- a/src/Mod/Sketcher/App/SketchObjectPy.xml +++ b/src/Mod/Sketcher/App/SketchObjectPy.xml @@ -28,6 +28,11 @@ delete a geometric object from the sketch + + + delete a list of geometric objects from the sketch, including any internal alignment geometry thereof + + delete all the geometry objects and constraints from the sketch except external geometry diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp index 82104c4d4e..2d6cb7f481 100644 --- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp @@ -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 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, ""))