From 8d3c20f06e802f4c98400bbe7be807f2b20bbbb9 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Thu, 25 Jan 2018 14:40:57 +0100 Subject: [PATCH] Sketcher: Avoid single tangency plus coincident when preexisting single tangency ================================================================================ fixes #3299 (remaining) Draw a line. Draw an arc. Make edge to edge tangency. Select endpoints. Try to create a coincident constraint. You now get an Endpoint-to-Endpoint tangency. --- src/Mod/Sketcher/Gui/CommandConstraints.cpp | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index dadc6af75a..f16ff8a05c 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -2312,6 +2312,41 @@ void CmdSketcherConstrainCoincident::activated(int iMsg) // check if this coincidence is already enforced (even indirectly) bool constraintExists=Obj->arePointsCoincident(GeoId1,PosId1,GeoId2,PosId2); + // check for a preexisting edge-to-edge tangency + const std::vector< Constraint * > &cvals = Obj->Constraints.getValues(); + + int j=0; + for (std::vector::const_iterator it = cvals.begin(); it != cvals.end(); ++it,++j) { + if( (*it)->Type == Sketcher::Tangent && + (*it)->FirstPos == Sketcher::none && (*it)->SecondPos == Sketcher::none && + (*it)->Third == Constraint::GeoUndef && + (((*it)->First == GeoId1 && (*it)->Second == GeoId2) || + ((*it)->Second == GeoId1 && (*it)->First == GeoId2)) ) { + + Gui::Command::openCommand("swap edge tangency with ptp tangency"); + + if(constraintExists) { + // try to remove any pre-existing direct coincident constraints + Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.delConstraintOnPoint(%i,%i)", + selection[0].getFeatName(), GeoId1, PosId1); + } + + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.delConstraint(%i)" + ,selection[0].getFeatName(), j); + + doendpointtangency(Obj, selection[0], GeoId1, GeoId2, PosId1, PosId2); + + commitCommand(); + tryAutoRecomputeIfNotSolve(Obj); + + QMessageBox::information(Gui::getMainWindow(), QObject::tr("Constraint Substitution"), + QObject::tr("Endpoint to endpoint tangency was applied instead.")); + + getSelection().clearSelection(); + return; + } + } + if (!constraintExists) { constraintsAdded = true; Gui::Command::doCommand(