From 01ba165d9aea24dbc40452f0e250009bdf41e9f6 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Fri, 18 Sep 2015 16:11:55 +0200 Subject: [PATCH] Bug fix: deletion of groups of external geometry ================================================ Issue reported inter alia here: http://forum.freecadweb.org/viewtopic.php?f=10&t=12380#p99456 How to reproduce: 1. Make an external geometry hexagon (make a hexagon, pad it, make a sketch on a hexagonal face and make all the lines external geometry) 2. Box select the external lines and press "del" On the first pressing of "del" 3 lines were deleted and 3 remained, select again, on the second press 1 remains, select again, on the last press all are deleted. Why? Internal and External geometry were handled together in a single set. Group deletion of geometry is effected starting from the highest index, so that upon deleting an element, the index of the remaining elements does not change. Handling both groups together caused that the external geometry was actually deleted on the inversed order (as they are (decreasing) negative values for representation, but increasing positive indexes in the external geometry array). Solution: Internal and External geometries are handled separatedly --- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 36 ++++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index dc9bc0d3f..225f1fb17 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -4756,24 +4756,30 @@ bool ViewProviderSketch::onDelete(const std::vector &subList) edit->PreselectCross = -1; edit->PreselectConstraintSet.clear(); - std::set delGeometries, delCoincidents, delConstraints; + std::set delInternalGeometries, delExternalGeometries, delCoincidents, delConstraints; // go through the selected subelements for (std::vector::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) { if (it->size() > 4 && it->substr(0,4) == "Edge") { int GeoId = std::atoi(it->substr(4,4000).c_str()) - 1; - delGeometries.insert(GeoId); + if( GeoId >= 0 ) + delInternalGeometries.insert(GeoId); + else + delExternalGeometries.insert(-3-GeoId); } else if (it->size() > 12 && it->substr(0,12) == "ExternalEdge") { int GeoId = std::atoi(it->substr(12,4000).c_str()) - 1; - GeoId = -GeoId - 3; - delGeometries.insert(GeoId); + delExternalGeometries.insert(GeoId); } else if (it->size() > 6 && it->substr(0,6) == "Vertex") { int VtId = std::atoi(it->substr(6,4000).c_str()) - 1; int GeoId; Sketcher::PointPos PosId; getSketchObject()->getGeoVertexIndex(VtId, GeoId, PosId); if (getSketchObject()->getGeometry(GeoId)->getTypeId() - == Part::GeomPoint::getClassTypeId()) - delGeometries.insert(GeoId); + == Part::GeomPoint::getClassTypeId()) { + if(GeoId>=0) + delInternalGeometries.insert(GeoId); + else + delExternalGeometries.insert(-3-GeoId); + } else delCoincidents.insert(VtId); } else if (*it == "RootPoint") { @@ -4805,14 +4811,20 @@ bool ViewProviderSketch::onDelete(const std::vector &subList) } } - for (rit = delGeometries.rbegin(); rit != delGeometries.rend(); rit++) { + for (rit = delInternalGeometries.rbegin(); rit != delInternalGeometries.rend(); rit++) { try { - if (*rit >= 0) - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.delGeometry(%i)" + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.delGeometry(%i)" ,getObject()->getNameInDocument(), *rit); - else if (*rit < -2) // external geometry - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.delExternal(%i)" - ,getObject()->getNameInDocument(), -3-*rit); + } + catch (const Base::Exception& e) { + Base::Console().Error("%s\n", e.what()); + } + } + + for (rit = delExternalGeometries.rbegin(); rit != delExternalGeometries.rend(); rit++) { + try { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.delExternal(%i)" + ,getObject()->getNameInDocument(), *rit); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what());