From 6210b602de6a1db9a3c7c44641fd7c30546f6397 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sun, 5 Nov 2017 07:29:19 +0100 Subject: [PATCH] Sketcher: Python command to delete all internal geometry and constraints of an sketch --- src/Mod/Sketcher/App/SketchObject.cpp | 17 +++++++++++++++++ src/Mod/Sketcher/App/SketchObject.h | 2 ++ src/Mod/Sketcher/App/SketchObjectPy.xml | 5 +++++ src/Mod/Sketcher/App/SketchObjectPyImp.cpp | 17 +++++++++++++++++ 4 files changed, 41 insertions(+) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index e8abc3d5dd..5dabd4fbe3 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -722,6 +722,23 @@ int SketchObject::delGeometry(int GeoId, bool deleteinternalgeo) return 0; } +int SketchObject::deleteAllGeometry() +{ + std::vector< Part::Geometry * > newVals(0); + std::vector< Constraint * > newConstraints(0); + + this->Geometry.setValues(newVals); + this->Constraints.setValues(newConstraints); + + this->Constraints.acceptGeometry(getCompleteGeometry()); + rebuildVertexIndex(); + + if(noRecomputes) // if we do not have a recompute, the sketch must be solved to update the DoF of the solver + solve(); + + return 0; +} + int SketchObject::toggleConstruction(int GeoId) { const std::vector< Part::Geometry * > &vals = getInternalGeometry(); diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 4ceceff49c..c7b1c642c5 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -97,6 +97,8 @@ public: \retval int - 0 if successful */ int delGeometry(int GeoId, bool deleteinternalgeo = true); + /// deletes all the elements/constraints of the sketch except for external geometry + int deleteAllGeometry(); /// add all constraints in the list int addConstraints(const std::vector &ConstraintList); /// add constraint diff --git a/src/Mod/Sketcher/App/SketchObjectPy.xml b/src/Mod/Sketcher/App/SketchObjectPy.xml index b7ae64f7ea..917f6496f6 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 all the geometry objects and constraints from the sketch except external geometry + + switch a geometry to a construction line diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp index 3e497a2a6b..2b65a0229d 100644 --- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp @@ -213,6 +213,23 @@ PyObject* SketchObjectPy::delGeometry(PyObject *args) Py_Return; } +PyObject* SketchObjectPy::deleteAllGeometry(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + + if (this->getSketchObjectPtr()->deleteAllGeometry()) { + std::stringstream str; + str << "Unable to delete Geometry"; + PyErr_SetString(PyExc_ValueError, str.str().c_str()); + return 0; + } + + Py_Return; +} + + + PyObject* SketchObjectPy::toggleConstruction(PyObject *args) { int Index;