From a7aa33f8860d0b8e5ca63f16aa055347d437a7c3 Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Thu, 29 Aug 2024 11:37:51 +0200 Subject: [PATCH 1/2] Sketcher: Circle DSH: fix seekSecond case of doEnforceControlParameters --- .../Sketcher/Gui/DrawSketchHandlerCircle.h | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerCircle.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerCircle.h index 5f5fab870d..7bee4c9eda 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerCircle.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerCircle.h @@ -72,6 +72,7 @@ public: explicit DrawSketchHandlerCircle(ConstructionMethod constrMethod = ConstructionMethod::Center) : DrawSketchHandlerCircleBase(constrMethod) , radius(0.0) + , isDiameter(true) {} ~DrawSketchHandlerCircle() override = default; @@ -303,6 +304,7 @@ private: private: Base::Vector2d centerPoint, firstPoint, secondPoint; double radius; + bool isDiameter; }; template<> @@ -371,6 +373,16 @@ void DSHCircleController::configureToolWidget() 1, Gui::BitmapFactory().iconFromTheme("Sketcher_Create3PointCircle")); } + + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/Mod/Sketcher/dimensioning"); + bool dimensioningDiameter = hGrp->GetBool("DimensioningDiameter", true); + bool dimensioningRadius = hGrp->GetBool("DimensioningRadius", true); + + if (dimensioningRadius && !dimensioningDiameter) { + handler->isDiameter = false; + } } onViewParameters[OnViewParameter::First]->setLabelType(Gui::SoDatumLabel::DISTANCEX); @@ -419,7 +431,8 @@ void DSHCircleControllerBase::doEnforceControlParameters(Base::Vector2d& onSketc if (handler->constructionMethod() == DrawSketchHandlerCircle::ConstructionMethod::Center) { if (onViewParameters[OnViewParameter::Third]->isSet) { - double radius = onViewParameters[OnViewParameter::Third]->getValue(); + double radius = (handler->isDiameter ? 0.5 : 1) + * onViewParameters[OnViewParameter::Third]->getValue(); if (radius < Precision::Confusion()) { unsetOnViewParameter(onViewParameters[OnViewParameter::Third].get()); return; @@ -622,20 +635,15 @@ void DSHCircleController::addConstraints() }; auto constraintradius = [&]() { - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( - "User parameter:BaseApp/Preferences/Mod/Sketcher/dimensioning"); - bool dimensioningDiameter = hGrp->GetBool("DimensioningDiameter", true); - bool dimensioningRadius = hGrp->GetBool("DimensioningRadius", true); - - if (dimensioningRadius && !dimensioningDiameter) { + if (handler->isDiameter) { Gui::cmdAppObjectArgs(handler->sketchgui->getObject(), - "addConstraint(Sketcher.Constraint('Radius',%d,%f)) ", + "addConstraint(Sketcher.Constraint('Diameter',%d,%f)) ", firstCurve, - handler->radius); + handler->radius * 2); } else { Gui::cmdAppObjectArgs(handler->sketchgui->getObject(), - "addConstraint(Sketcher.Constraint('Diameter',%d,%f)) ", + "addConstraint(Sketcher.Constraint('Radius',%d,%f)) ", firstCurve, handler->radius); } From dca9c0ca3bd40a766775d746d65898b30827499d Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Thu, 29 Aug 2024 12:49:07 +0200 Subject: [PATCH 2/2] Sketcher: Fix problem where preselectAtPoint was called after the autoconstraints being generated, hence having no effect. By adding updateDataAndDrawToPosition after we regenerate the correct autoconstraint. We cannot just move the mouseMove to after preselectAtPoint because we need to have the enforced position. --- src/Mod/Sketcher/Gui/DrawSketchController.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Mod/Sketcher/Gui/DrawSketchController.h b/src/Mod/Sketcher/Gui/DrawSketchController.h index 5d26a03069..714a6bda87 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchController.h +++ b/src/Mod/Sketcher/Gui/DrawSketchController.h @@ -565,6 +565,9 @@ protected: auto currentstate = handler->state(); // ensure that object at point is preselected, so that autoconstraints are generated handler->preselectAtPoint(lastControlEnforcedPosition); + // We have to redo an update to regenerate the correct autoconstraints after the + // preselectAtPoint. + handler->updateDataAndDrawToPosition(lastControlEnforcedPosition); doChangeDrawSketchHandlerMode();