From 01cd4abbba7ea2e3d529a626fee197b818439cfe Mon Sep 17 00:00:00 2001 From: logari81 Date: Tue, 17 Jul 2012 12:49:37 +0200 Subject: [PATCH] Sketcher: rewrite ViewProviderSketch::onDelete method --- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 68 ++++++++++++++------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index caeb79b03..b1d478d13 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -2987,13 +2987,44 @@ Sketcher::SketchObject *ViewProviderSketch::getSketchObject(void) const bool ViewProviderSketch::onDelete(const std::vector &subList) { - //FIXME use the selection subelements instead of the Sel Sets... if (edit) { - // We must tmp. block the signaling because otherwise we empty the sets while - // looping through them which may cause a crash - this->blockConnection(true); + std::vector selection = Gui::Selection().getSelectionEx(); + const std::vector &SubNames = selection[0].getSubNames(); + + Gui::Selection().clearSelection(); + resetPreselectPoint(); + edit->PreselectCurve = -1; + edit->PreselectCross = -1; + edit->PreselectConstraint = -1; + + std::set delGeometries, 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()); + delGeometries.insert(GeoId); + } else if (it->size() > 12 && it->substr(0,12) == "ExternalEdge") { + int GeoId = std::atoi(it->substr(12,4000).c_str()); + GeoId = -GeoId - 3; + delGeometries.insert(GeoId); + } else if (it->size() > 6 && it->substr(0,6) == "Vertex") { + int VtId = std::atoi(it->substr(6,4000).c_str()); + int GeoId; + Sketcher::PointPos PosId; + getSketchObject()->getGeoVertexIndex(VtId, GeoId, PosId); + if (getSketchObject()->getGeometry(GeoId)->getTypeId() + == Part::GeomPoint::getClassTypeId()) + delGeometries.insert(GeoId); + else + delCoincidents.insert(VtId); + } else if (it->size() > 10 && it->substr(0,10) == "Constraint") { + int ConstrId = std::atoi(it->substr(10,4000).c_str()); + delConstraints.insert(ConstrId); + } + } + std::set::const_reverse_iterator rit; - for (rit = edit->SelConstraintSet.rbegin(); rit != edit->SelConstraintSet.rend(); rit++) { + for (rit = delConstraints.rbegin(); rit != delConstraints.rend(); rit++) { try { Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.delConstraint(%i)" ,getObject()->getNameInDocument(), *rit); @@ -3003,7 +3034,17 @@ bool ViewProviderSketch::onDelete(const std::vector &subList) } } - for (rit = edit->SelCurvSet.rbegin(); rit != edit->SelCurvSet.rend(); rit++) { + 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()); + } + } + + for (rit = delGeometries.rbegin(); rit != delGeometries.rend(); rit++) { try { if (*rit >= 0) Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.delGeometry(%i)" @@ -3016,22 +3057,7 @@ bool ViewProviderSketch::onDelete(const std::vector &subList) Base::Console().Error("%s\n", e.what()); } } - for (rit = edit->SelPointSet.rbegin(); rit != edit->SelPointSet.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()); - } - } - this->blockConnection(false); - Gui::Selection().clearSelection(); - resetPreselectPoint(); - edit->PreselectCurve = -1; - edit->PreselectCross = -1; - edit->PreselectConstraint = -1; this->drawConstraintIcons(); this->updateColor(); // if in edit not delete the object