From 40459e73cd35c85df7c669e6640d983e26fd90d7 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Tue, 2 Jan 2018 15:50:09 +0100 Subject: [PATCH] Sketcher: Remove errors in reporting view while deleting ======================================================= fixes #2275 https://freecadweb.org/tracker/view.php?id=2275 Deletion of coincidents rely on selected vertex. The original code was trying to delete a coincident without checking whether one was there. The implementation now relies on checking whether a coincident is present. --- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 39 ++++++++++++++++----- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index c0871101a1..8b7f90d63d 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -5855,8 +5855,11 @@ bool ViewProviderSketch::onDelete(const std::vector &subList) delConstraints.insert(ConstrId); } } + // We stored the vertices, but is there really a coincident constraint? Check + const std::vector< Sketcher::Constraint * > &vals = getSketchObject()->Constraints.getValues(); + + std::set::const_reverse_iterator rit; - std::set::const_reverse_iterator rit; for (rit = delConstraints.rbegin(); rit != delConstraints.rend(); ++rit) { try { Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.delConstraint(%i)" @@ -5868,13 +5871,33 @@ bool ViewProviderSketch::onDelete(const std::vector &subList) } for (rit = delCoincidents.rbegin(); rit != delCoincidents.rend(); ++rit) { - try { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.delConstraintOnPoint(%i)" - ,getObject()->getNameInDocument(), *rit); - } - catch (const Base::Exception& e) { - Base::Console().Error("%s\n", e.what()); - } + int GeoId; + PointPos PosId; + + if (*rit == GeoEnum::RtPnt) { // RootPoint + GeoId = Sketcher::GeoEnum::RtPnt; + PosId = start; + } else { + getSketchObject()->getGeoVertexIndex(*rit, GeoId, PosId); + } + + if(GeoId != Constraint::GeoUndef) { + + for (std::vector< Sketcher::Constraint * >::const_iterator it= vals.begin(); it != vals.end(); ++it) { + + if ( ((*it)->Type == Sketcher::Coincident) && (((*it)->First == GeoId && (*it)->FirstPos == PosId) || + ((*it)->Second == GeoId && (*it)->SecondPos == PosId)) ) { + try { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.delConstraintOnPoint(%i,%i)" + ,getObject()->getNameInDocument(), GeoId, (int)PosId); + } + catch (const Base::Exception& e) { + Base::Console().Error("%s\n", e.what()); + } + break; + } + } + } } for (rit = delInternalGeometries.rbegin(); rit != delInternalGeometries.rend(); ++rit) {