From e7b44d28663279f4a813d0fef94d8c149af24bb0 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 10 Mar 2014 13:35:41 +0100 Subject: [PATCH] + fixes #0001339: Crash when giving sketch with external geometry a new support (face) after the original support was deleted --- src/Mod/Sketcher/App/SketchObject.cpp | 48 ++++++++++++++++++++++++++- src/Mod/Sketcher/App/SketchObject.h | 2 ++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 89fdd3e81..21828ddba 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -1177,6 +1177,33 @@ int SketchObject::delExternal(int ExtGeoId) return 0; } +int SketchObject::delConstraintsToExternal() +{ + const std::vector< Constraint * > &constraints = Constraints.getValues(); + std::vector< Constraint * > newConstraints(0); + int GeoId = -3; + for (std::vector::const_iterator it = constraints.begin(); + it != constraints.end(); ++it) { + if ((*it)->First > GeoId && (*it)->Second > GeoId) { + Constraint *copiedConstr = (*it)->clone(); + newConstraints.push_back(copiedConstr); + } + } + + try { + rebuildExternalGeometry(); + } + catch (const Base::Exception& e) { + Base::Console().Error("%s\n", e.what()); + return -1; + } + + Constraints.setValues(newConstraints); + Constraints.acceptGeometry(getCompleteGeometry()); + rebuildVertexIndex(); + return 0; +} + const Part::Geometry* SketchObject::getGeometry(int GeoId) const { if (GeoId >= 0) { @@ -1543,8 +1570,27 @@ void SketchObject::Restore(XMLReader &reader) void SketchObject::onChanged(const App::Property* prop) { - if (prop == &Geometry || prop == &Constraints) + if (prop == &Geometry || prop == &Constraints) { Constraints.checkGeometry(getCompleteGeometry()); + } + else if (prop == &ExternalGeometry) { + // make sure not to change anything while restoring this object + if (!isRestoring()) { + // external geometry was cleared + if (ExternalGeometry.getSize() == 0) { + delConstraintsToExternal(); + } + } + } + else if (prop == &Support) { + // make sure not to change anything while restoring this object + if (!isRestoring()) { + // support face was cleared + if (!Support.getValue()) { + delConstraintsToExternal(); + } + } + } Part::Part2DObject::onChanged(prop); } diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 3be95167c..5d193612f 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -72,6 +72,8 @@ public: int delConstraint(int ConstrId); int delConstraintOnPoint(int GeoId, PointPos PosId, bool onlyCoincident=true); int delConstraintOnPoint(int VertexId, bool onlyCoincident=true); + /// Deletes all constraints referencing an external geometry + int delConstraintsToExternal(); /// transfers all contraints of a point to a new point int transferConstraints(int fromGeoId, PointPos fromPosId, int toGeoId, PointPos toPosId); /// add an external geometry reference