From c43b39d0014e5667e4e618472bcfb3d17cad3d39 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sun, 22 Jan 2017 00:38:23 +0100 Subject: [PATCH 1/9] Sketcher: BSpline creation mode end on right-click ================================================== Now the BSpline ends with right-click, but creates the BSpline if at least two poles have been entered. If continous creation mode is enabled, then it only exits when right-clicking without having entered any pole. --- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 1a24e4091..ca98a43a5 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -4495,6 +4495,14 @@ public: sketchgui->drawEdit(EditCurve); EditCurve.resize(2); applyCursor(); + + sugConstr.clear(); + + std::vector sugConstr1; + sugConstr.push_back(sugConstr1); + + CurrentConstraint=0; + /* It is ok not to call to purgeHandler * in continuous creation mode because the * handler is destroyed by the quit() method on pressing the @@ -4506,6 +4514,47 @@ public: } return true; } + + virtual void quit(void) { + // We must see if we need to create a BSpline before cancelling everything + // and now just like any other Handler, + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + + bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); + + if (CurrentConstraint > 1) { + // create bspline from existing poles + Mode=STATUS_CLOSE; + EditCurve.pop_back(); + this->releaseButton(Base::Vector2d(0.f,0.f)); + } + else if(CurrentConstraint == 1) { + // if we just have one point and we can not close anything, then cancel this creation but continue according to continuous mode + if(!continuousMode){ + DrawSketchHandler::quit(); + } + else { + // This code disregards existing data and enables the continuous creation mode. + Mode = STATUS_SEEK_FIRST_CONTROLPOINT; + EditCurve.clear(); + sketchgui->drawEdit(EditCurve); + EditCurve.resize(2); + applyCursor(); + + sugConstr.clear(); + + std::vector sugConstr1; + sugConstr.push_back(sugConstr1); + + CurrentConstraint=0; + } + } + else { // we have no data (CurrentConstraint == 0) so user when right-clicking really wants to exit + DrawSketchHandler::quit(); + } + } + protected: SELECT_MODE Mode; From f4a882093b0a0ad0a83c6e95143902d82826fa91 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 23 Jan 2017 23:28:22 +0100 Subject: [PATCH 2/9] Sketcher: InternalAligment Python extension to InternalAlignmentIndex ===================================================================== Extension of Constraint Python code to consider the case with 4 ints, where the last int is InternalAligmentIndex for InternalAligment constraint --- src/Mod/Sketcher/App/ConstraintPyImp.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Mod/Sketcher/App/ConstraintPyImp.cpp b/src/Mod/Sketcher/App/ConstraintPyImp.cpp index a7d980956..fb944a153 100644 --- a/src/Mod/Sketcher/App/ConstraintPyImp.cpp +++ b/src/Mod/Sketcher/App/ConstraintPyImp.cpp @@ -290,6 +290,28 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) this->getConstraintPtr()->ThirdPos = (Sketcher::PointPos) intArg4; return 0; } + else if (strstr(ConstraintType,"InternalAlignment") != NULL) { // InteralAlignment with InternalElementIndex argument + this->getConstraintPtr()->Type = InternalAlignment; + + valid = true; + + if(strstr(ConstraintType,"BSplineControlPoint") != NULL) { + this->getConstraintPtr()->AlignmentType=BSplineControlPoint; + } + else { + this->getConstraintPtr()->AlignmentType=Undef; + valid = false; + } + + if (valid) { + this->getConstraintPtr()->First = intArg1; + this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) intArg2; + this->getConstraintPtr()->Second = intArg3; + this->getConstraintPtr()->InternalAlignmentIndex = intArg4; + return 0; + } + + } if (valid) { this->getConstraintPtr()->First = intArg1; this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) intArg2; From bdc81aae2e4b34655ede6c5840a837c149f1f5eb Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 23 Jan 2017 00:06:11 +0100 Subject: [PATCH 3/9] Sketcher: BSpline Creation - pole circle on click ================================================= This method creates the pole circles on every click. This allows to properly detect the closing of the curve --- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 154 +++++++++++++++++++--- 1 file changed, 133 insertions(+), 21 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index ca98a43a5..08baa6633 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -4326,6 +4326,8 @@ public: , EditCurve(2) , CurrentConstraint(0) , ConstrMethod(constructionMethod) + , IsClosed(false) + , FirstPoleGeoId(-2000) { std::vector sugConstr1; sugConstr.push_back(sugConstr1); @@ -4382,20 +4384,101 @@ public: EditCurve[0] = onSketchPos; Mode = STATUS_SEEK_ADDITIONAL_CONTROLPOINTS; + + // insert circle point for pole, defer internal alignment constraining. + try { + Gui::Command::openCommand("Add Pole circle"); + + //Add pole + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addGeometry(Part.Circle(App.Vector(%f,%f,0),App.Vector(0,0,1),10),True)", + sketchgui->getObject()->getNameInDocument(), + EditCurve[0].x,EditCurve[0].y); + + } + catch (const Base::Exception& e) { + Base::Console().Error("%s\n", e.what()); + Gui::Command::abortCommand(); + + static_cast(sketchgui->getObject())->solve(); + + return false; + } + + Gui::Command::commitCommand(); + + static_cast(sketchgui->getObject())->solve(); + + FirstPoleGeoId = getHighestCurveIndex(); + + // add auto constraints on pole + if (sugConstr[CurrentConstraint].size() > 0) { + createAutoConstraints(sugConstr[CurrentConstraint], FirstPoleGeoId, Sketcher::mid); + } + + static_cast(sketchgui->getObject())->solve(); + std::vector sugConstrN; sugConstr.push_back(sugConstrN); CurrentConstraint++; + } else if (Mode == STATUS_SEEK_ADDITIONAL_CONTROLPOINTS) { EditCurve[EditCurve.size()-1] = onSketchPos; - // finish adding controlpoints on double click - if (EditCurve[EditCurve.size()-2] == EditCurve[EditCurve.size()-1]) { - EditCurve.pop_back(); - Mode = STATUS_CLOSE; + // check if coincident with first pole + for(std::vector::const_iterator it = sugConstr[CurrentConstraint].begin(); it != sugConstr[CurrentConstraint].end(); it++) { + if( (*it).Type == Sketcher::Coincident && (*it).GeoId == FirstPoleGeoId && (*it).PosId == Sketcher::mid ) { + + IsClosed = true; + } } - else { + + if (IsClosed) { + Mode = STATUS_CLOSE; + + if (ConstrMethod == 1) { // if periodic we do not need the last pole + EditCurve.pop_back(); + sugConstr.pop_back(); + + return true; + } + + + } + + // insert circle point for pole, defer internal alignment constraining. + try { + + Gui::Command::openCommand("Add Pole circle"); + + //Add pole + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addGeometry(Part.Circle(App.Vector(%f,%f,0),App.Vector(0,0,1),10),True)", + sketchgui->getObject()->getNameInDocument(), + EditCurve[EditCurve.size()-1].x,EditCurve[EditCurve.size()-1].y); + + } + catch (const Base::Exception& e) { + Base::Console().Error("%s\n", e.what()); + Gui::Command::abortCommand(); + + static_cast(sketchgui->getObject())->solve(); + + return false; + } + + Gui::Command::commitCommand(); + + static_cast(sketchgui->getObject())->solve(); + + // add auto constraints on pole + if (sugConstr[CurrentConstraint].size() > 0) { + createAutoConstraints(sugConstr[CurrentConstraint], FirstPoleGeoId + EditCurve.size()-1, Sketcher::mid); + } + + static_cast(sketchgui->getObject())->solve(); + + if (!IsClosed) { EditCurve.resize(EditCurve.size() + 1); // add one place for a pole std::vector sugConstrN; sugConstr.push_back(sugConstrN); @@ -4432,24 +4515,36 @@ public: try { - Gui::Command::openCommand("Add B-spline curve"); + Gui::Command::openCommand("Add B-spline curve"); - //Add arc of parabola - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addGeometry(Part.BSplineCurve" - "(%s,%s)," - "%s)", - sketchgui->getObject()->getNameInDocument(), - controlpoints.c_str(), - ConstrMethod == 0 ?"False":"True", - geometryCreationMode==Construction?"True":"False"); + //Add arc of parabola + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.addGeometry(Part.BSplineCurve" + "(%s,%s)," + "%s)", + sketchgui->getObject()->getNameInDocument(), + controlpoints.c_str(), + ConstrMethod == 0 ?"False":"True", + geometryCreationMode==Construction?"True":"False"); - currentgeoid++; + currentgeoid++; + + // Constraint pole circles to bspline. + for(size_t i = 0; i < EditCurve.size(); i++) { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',%d,%d,%d,%d)) ", + sketchgui->getObject()->getNameInDocument(),FirstPoleGeoId+i,Sketcher::mid,currentgeoid,i); + + if(i == 0) { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Radius',%d,%f)) ", + sketchgui->getObject()->getNameInDocument(),FirstPoleGeoId,round( (EditCurve[1]-EditCurve[0]).Length()/6 )); + } + else { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Equal',%d,%d)) ", + sketchgui->getObject()->getNameInDocument(),FirstPoleGeoId,FirstPoleGeoId+i); + } + } + - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.ExposeInternalGeometry(%d)", - sketchgui->getObject()->getNameInDocument(), - currentgeoid); } catch (const Base::Exception& e) { @@ -4469,7 +4564,7 @@ public: Gui::Command::commitCommand(); - int poleindex=0; + /*int poleindex=0; for(std::vector>::iterator it=sugConstr.begin(); it != sugConstr.end(); it++, poleindex++) { // add auto constraints if ((*it).size() > 0) { @@ -4477,6 +4572,19 @@ public: (*it).clear(); } } + static_cast(sketchgui->getObject())->solve();*/ + + /*if (IsClosed && ConstrMethod == 0) { // closed but not periodic + Gui::Command::openCommand("Add endpoint coincident constraints"); + + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Coincident',%i,%i,%i,%i)) " + ,sketchgui->getObject()->getNameInDocument() + ,currentgeoid, Sketcher::start, currentgeoid, Sketcher::end); + + Gui::Command::commitCommand(); + }*/ + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool autoRecompute = hGrp->GetBool("AutoRecompute",false); @@ -4502,6 +4610,7 @@ public: sugConstr.push_back(sugConstr1); CurrentConstraint=0; + IsClosed=false; /* It is ok not to call to purgeHandler * in continuous creation mode because the @@ -4548,6 +4657,7 @@ public: sugConstr.push_back(sugConstr1); CurrentConstraint=0; + IsClosed=false; } } else { // we have no data (CurrentConstraint == 0) so user when right-clicking really wants to exit @@ -4564,6 +4674,8 @@ protected: int CurrentConstraint; int ConstrMethod; + bool IsClosed; + int FirstPoleGeoId; }; DEF_STD_CMD_A(CmdSketcherCreateBSpline) From 38fc7071c78808a6fee6335f23ff0c67c9ac9dce Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Tue, 24 Jan 2017 00:26:45 +0100 Subject: [PATCH 4/9] Sketcher: BSpline Creation solver call reduction --- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 08baa6633..22cd65136 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -4407,7 +4407,7 @@ public: Gui::Command::commitCommand(); - static_cast(sketchgui->getObject())->solve(); + //static_cast(sketchgui->getObject())->solve(); FirstPoleGeoId = getHighestCurveIndex(); @@ -4469,7 +4469,7 @@ public: Gui::Command::commitCommand(); - static_cast(sketchgui->getObject())->solve(); + //static_cast(sketchgui->getObject())->solve(); // add auto constraints on pole if (sugConstr[CurrentConstraint].size() > 0) { From ec8c5145475edcbf17ef338149c1e05206e3e600 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Tue, 24 Jan 2017 00:33:55 +0100 Subject: [PATCH 5/9] Sketcher: BSpline Creation acceleration - pole constraining on pole creation --- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 39 +++++------------------ 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 22cd65136..67613a59d 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -4457,6 +4457,14 @@ public: sketchgui->getObject()->getNameInDocument(), EditCurve[EditCurve.size()-1].x,EditCurve[EditCurve.size()-1].y); + if(EditCurve.size() == 2) { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Radius',%d,%f)) ", + sketchgui->getObject()->getNameInDocument(), FirstPoleGeoId, round( (EditCurve[1]-EditCurve[0]).Length()/6 )); + } + + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Equal',%d,%d)) ", + sketchgui->getObject()->getNameInDocument(), FirstPoleGeoId, FirstPoleGeoId+ EditCurve.size()-1); + } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); @@ -4533,15 +4541,6 @@ public: for(size_t i = 0; i < EditCurve.size(); i++) { Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',%d,%d,%d,%d)) ", sketchgui->getObject()->getNameInDocument(),FirstPoleGeoId+i,Sketcher::mid,currentgeoid,i); - - if(i == 0) { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Radius',%d,%f)) ", - sketchgui->getObject()->getNameInDocument(),FirstPoleGeoId,round( (EditCurve[1]-EditCurve[0]).Length()/6 )); - } - else { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Equal',%d,%d)) ", - sketchgui->getObject()->getNameInDocument(),FirstPoleGeoId,FirstPoleGeoId+i); - } } @@ -4564,28 +4563,6 @@ public: Gui::Command::commitCommand(); - /*int poleindex=0; - for(std::vector>::iterator it=sugConstr.begin(); it != sugConstr.end(); it++, poleindex++) { - // add auto constraints - if ((*it).size() > 0) { - createAutoConstraints((*it), currentgeoid+1+poleindex, Sketcher::mid); - (*it).clear(); - } - } - static_cast(sketchgui->getObject())->solve();*/ - - /*if (IsClosed && ConstrMethod == 0) { // closed but not periodic - Gui::Command::openCommand("Add endpoint coincident constraints"); - - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Coincident',%i,%i,%i,%i)) " - ,sketchgui->getObject()->getNameInDocument() - ,currentgeoid, Sketcher::start, currentgeoid, Sketcher::end); - - Gui::Command::commitCommand(); - }*/ - - - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool autoRecompute = hGrp->GetBool("AutoRecompute",false); From cc31dac143ae72a4a481c6526f1815a63a40ae57 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Tue, 24 Jan 2017 13:47:17 +0100 Subject: [PATCH 6/9] Sketcher: BSpline Creation improvement - Add constraints by groups --- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 67613a59d..3e5455363 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -4538,13 +4538,19 @@ public: currentgeoid++; // Constraint pole circles to bspline. - for(size_t i = 0; i < EditCurve.size(); i++) { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',%d,%d,%d,%d)) ", - sketchgui->getObject()->getNameInDocument(),FirstPoleGeoId+i,Sketcher::mid,currentgeoid,i); + std::stringstream cstream; + + cstream << "conList = []\n"; + + for (size_t i = 0; i < EditCurve.size(); i++) { + cstream << "conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint'," << FirstPoleGeoId+i + << "," << Sketcher::mid << "," << currentgeoid << "," << i << "))\n"; } - - + cstream << "App.ActiveDocument."<< sketchgui->getObject()->getNameInDocument() << ".addConstraint(conList)\n"; + + Gui::Command::doCommand(Gui::Command::Doc, cstream.str().c_str()); + } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); From bad73abe84dba2aeb5314ac8e572643ea4f3d150 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Tue, 24 Jan 2017 23:32:22 +0100 Subject: [PATCH 7/9] Sketcher: BSpline Creation fix - Remove introduced pole if creation cancelled --- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 3e5455363..bffbf1b57 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -4623,6 +4623,7 @@ public: } else if(CurrentConstraint == 1) { // if we just have one point and we can not close anything, then cancel this creation but continue according to continuous mode + sketchgui->getDocument()->undo(1); if(!continuousMode){ DrawSketchHandler::quit(); } From 6ad51826d42ace9f0dc7d7a0540208206abc422e Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Wed, 25 Jan 2017 00:03:05 +0100 Subject: [PATCH 8/9] Sketcher: BSpline Creation - as single command for one-step undo --- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 27 +++++++++++++++------- src/Mod/Sketcher/Gui/DrawSketchHandler.cpp | 15 ++++++++---- src/Mod/Sketcher/Gui/DrawSketchHandler.h | 4 +++- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index bffbf1b57..6dafdcbb9 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -4405,7 +4405,7 @@ public: return false; } - Gui::Command::commitCommand(); + //Gui::Command::commitCommand(); //static_cast(sketchgui->getObject())->solve(); @@ -4413,7 +4413,7 @@ public: // add auto constraints on pole if (sugConstr[CurrentConstraint].size() > 0) { - createAutoConstraints(sugConstr[CurrentConstraint], FirstPoleGeoId, Sketcher::mid); + createAutoConstraints(sugConstr[CurrentConstraint], FirstPoleGeoId, Sketcher::mid, false); } static_cast(sketchgui->getObject())->solve(); @@ -4450,7 +4450,7 @@ public: // insert circle point for pole, defer internal alignment constraining. try { - Gui::Command::openCommand("Add Pole circle"); + //Gui::Command::openCommand("Add Pole circle"); //Add pole Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addGeometry(Part.Circle(App.Vector(%f,%f,0),App.Vector(0,0,1),10),True)", @@ -4475,16 +4475,16 @@ public: return false; } - Gui::Command::commitCommand(); + //Gui::Command::commitCommand(); //static_cast(sketchgui->getObject())->solve(); // add auto constraints on pole if (sugConstr[CurrentConstraint].size() > 0) { - createAutoConstraints(sugConstr[CurrentConstraint], FirstPoleGeoId + EditCurve.size()-1, Sketcher::mid); + createAutoConstraints(sugConstr[CurrentConstraint], FirstPoleGeoId + EditCurve.size()-1, Sketcher::mid, false); } - static_cast(sketchgui->getObject())->solve(); + //static_cast(sketchgui->getObject())->solve(); if (!IsClosed) { EditCurve.resize(EditCurve.size() + 1); // add one place for a pole @@ -4523,7 +4523,7 @@ public: try { - Gui::Command::openCommand("Add B-spline curve"); + //Gui::Command::openCommand("Add B-spline curve"); //Add arc of parabola Gui::Command::doCommand(Gui::Command::Doc, @@ -4623,7 +4623,18 @@ public: } else if(CurrentConstraint == 1) { // if we just have one point and we can not close anything, then cancel this creation but continue according to continuous mode - sketchgui->getDocument()->undo(1); + //sketchgui->getDocument()->undo(1); + + Gui::Command::abortCommand(); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + else + static_cast(sketchgui->getObject())->solve(); + if(!continuousMode){ DrawSketchHandler::quit(); } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp index fb4554e7a..cc8a783ec 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp @@ -383,15 +383,18 @@ int DrawSketchHandler::seekAutoConstraint(std::vector &suggested } void DrawSketchHandler::createAutoConstraints(const std::vector &autoConstrs, - int geoId1, Sketcher::PointPos posId1) + int geoId1, Sketcher::PointPos posId1, bool createowncommand /*= true*/) { if (!sketchgui->Autoconstraints.getValue()) return; // If Autoconstraints property is not set quit if (autoConstrs.size() > 0) { - // Open the Command - Gui::Command::openCommand("Add auto constraints"); - + + if(createowncommand) { + // Open the Command + Gui::Command::openCommand("Add auto constraints"); + } + // Iterate through constraints std::vector::const_iterator it = autoConstrs.begin(); for (; it != autoConstrs.end(); ++it) { @@ -512,7 +515,9 @@ void DrawSketchHandler::createAutoConstraints(const std::vector break; } - Gui::Command::commitCommand(); + if(createowncommand) { + Gui::Command::commitCommand(); + } //Gui::Command::updateActive(); // There is already an recompute in each command creation, this is redundant. } } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.h b/src/Mod/Sketcher/Gui/DrawSketchHandler.h index b71337405..cbdd47a14 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.h @@ -82,8 +82,10 @@ public: int seekAutoConstraint(std::vector &suggestedConstraints, const Base::Vector2d &Pos, const Base::Vector2d &Dir, AutoConstraint::TargetType type = AutoConstraint::VERTEX); + // createowncommand indicates whether a separate command shall be create and committed (for example for undo purposes) or not + // is not it is the responsibility of the developer to create and commit the command appropriately. void createAutoConstraints(const std::vector &autoConstrs, - int geoId, Sketcher::PointPos pointPos=Sketcher::none); + int geoId, Sketcher::PointPos pointPos=Sketcher::none, bool createowncommand = true); void setPositionText(const Base::Vector2d &Pos, const SbString &text); void setPositionText(const Base::Vector2d &Pos); From 80e7ece4292cf2673602830d5d2d1070c635f806 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Thu, 26 Jan 2017 23:32:10 +0100 Subject: [PATCH 9/9] Sketcher: BSpline - avoid tiny circles on removal of equality --- src/Mod/Sketcher/App/Sketch.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Mod/Sketcher/App/Sketch.cpp b/src/Mod/Sketcher/App/Sketch.cpp index f9a441449..32b306c65 100644 --- a/src/Mod/Sketcher/App/Sketch.cpp +++ b/src/Mod/Sketcher/App/Sketch.cpp @@ -671,6 +671,32 @@ int Sketch::addBSpline(const Part::GeomBSplineCurve &bspline, bool fixed) std::vector mult = bsp->getMultiplicities(); int degree = bsp->getDegree(); bool periodic = bsp->isPeriodic(); + + // OCC hack + // c means there is a constraint on that weight, nc no constraint + // OCC provides normalized weights when polynomic [1 1 1] [c c c] and unnormalized weights when rational [5 1 5] [c nc c] + // then when changing from polynomic to rational, after the first solve any not-constrained pole circle gets normalized to 1. + // This only happens when changing from polynomic to rational, any subsequent change remains unnormalized [5 1 5] [c nc nc] + // This creates a visual problem that one of the poles shrinks to 1 mm when deleting an equality constraint. + + int lastoneindex = -1; + int countones = 0; + double lastnotone = 1.0; + + for(size_t i = 0; i < weights.size(); i++) { + if(weights[i] != 1.0) { + lastnotone = weights[i]; + } + else { // is 1.0 + lastoneindex = i; + countones++; + } + } + + if (countones == 1) + weights[lastoneindex] = (lastnotone * 0.99); + + // end hack Base::Vector3d startPnt = bsp->getStartPoint(); Base::Vector3d endPnt = bsp->getEndPoint();