From 7128cf7989baba2abd83f7816ab4fb3dc8c3f569 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Fri, 23 Aug 2019 19:10:58 +0800 Subject: [PATCH] Sketcher: fix lost of constraint in undo/redo --- src/Mod/Sketcher/App/SketchObject.cpp | 11 ++++------- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 9a3ad5ea9f..2a9d407239 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -176,6 +176,7 @@ App::DocumentObjectExecReturn *SketchObject::execute(void) // setup and diagnose the sketch try { rebuildExternalGeometry(); + Constraints.acceptGeometry(getCompleteGeometry()); } catch (const Base::Exception& e) { Base::Console().Error("%s\nClear constraints to external geometry\n", e.what()); @@ -912,9 +913,7 @@ int SketchObject::delGeometry(int GeoId, bool deleteinternalgeo) } this->Geometry.setValues(newVals); - this->Constraints.setValues(newConstraints); - for (Constraint* it : newConstraints) - delete it; + this->Constraints.setValues(std::move(newConstraints)); this->Constraints.acceptGeometry(getCompleteGeometry()); rebuildVertexIndex(); @@ -5357,9 +5356,7 @@ int SketchObject::delExternal(int ExtGeoId) } solverNeedsUpdate=true; - Constraints.setValues(newConstraints); - for (Constraint* it : newConstraints) - delete it; + Constraints.setValues(std::move(newConstraints)); Constraints.acceptGeometry(getCompleteGeometry()); rebuildVertexIndex(); return 0; @@ -5429,7 +5426,7 @@ int SketchObject::delConstraintsToExternal() } } - Constraints.setValues(newConstraints); + Constraints.setValues(std::move(newConstraints)); Constraints.acceptGeometry(getCompleteGeometry()); if(noRecomputes) // if we do not have a recompute, the sketch must be solved to update the DoF of the solver diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 1db7dea438..a70daf4bf1 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -4327,6 +4327,16 @@ Restart: SoSeparator *sep = static_cast(edit->constrGroup->getChild(i)); const Constraint *Constr = *it; + if(Constr->First < -extGeoCount || Constr->First >= intGeoCount + || (Constr->Second!=Constraint::GeoUndef + && (Constr->Second < -extGeoCount || Constr->Second >= intGeoCount)) + || (Constr->Third!=Constraint::GeoUndef + && (Constr->Third < -extGeoCount || Constr->Third >= intGeoCount))) + { + // Constraint can refer to non-existent geometry during undo/redo + continue; + } + // distinquish different constraint types to build up switch (Constr->Type) { case Block: