@@ -86,7 +86,10 @@ class DrawSketchHandlerLine: public DrawSketchHandlerLineBase
8686 explicit DrawSketchHandlerLine (
8787 ConstructionMethod constrMethod = ConstructionMethod::OnePointLengthAngle)
8888 : DrawSketchHandlerLineBase(constrMethod)
89- , length(0.0 ) {};
89+ , length(0.0 )
90+ , lengthSign(0 )
91+ , widthSign(0 )
92+ , capturedDirection(0.0 , 0.0 ) {};
9093 ~DrawSketchHandlerLine () override = default ;
9194
9295private:
@@ -237,10 +240,23 @@ class DrawSketchHandlerLine: public DrawSketchHandlerLineBase
237240 }
238241 }
239242
243+ void onReset () override
244+ {
245+ lengthSign = 0 ;
246+ widthSign = 0 ;
247+ capturedDirection = Base::Vector2d (0.0 , 0.0 );
248+ toolWidgetManager.resetControls ();
249+ }
250+
240251private:
241252 Base::Vector2d startPoint, endPoint;
242253 double length;
243254
255+ // These store the direction sign when OVP is first set to prevent sign flipping
256+ int lengthSign, widthSign;
257+ // Direction tracking to check once OVP is locked
258+ Base::Vector2d capturedDirection;
259+
244260 void createShape (bool onlyeditoutline) override
245261 {
246262 Q_UNUSED (onlyeditoutline);
@@ -427,12 +443,17 @@ void DSHLineControllerBase::doEnforceControlParameters(Base::Vector2d& onSketchP
427443 if (fabs (width) < Precision::Confusion ()
428444 && fourthParam->hasFinishedEditing ) {
429445 unsetOnViewParameter (thirdParam.get ());
446+ handler->lengthSign = 0 ;
430447 return ;
431448 }
432449 }
433450 }
434- int sign = (onSketchPos.x - handler->startPoint .x ) >= 0 ? 1 : -1 ;
435- onSketchPos.x = handler->startPoint .x + sign * length;
451+ // get sign on the first time we set the OVP label, so it won't get flipped
452+ // with mouse next time
453+ if (handler->lengthSign == 0 ) {
454+ handler->lengthSign = (onSketchPos.x - handler->startPoint .x ) >= 0 ? 1 : -1 ;
455+ }
456+ onSketchPos.x = handler->startPoint .x + handler->lengthSign * length;
436457 }
437458
438459 if (fourthParam->isSet ) {
@@ -444,12 +465,15 @@ void DSHLineControllerBase::doEnforceControlParameters(Base::Vector2d& onSketchP
444465 if (fabs (length) < Precision::Confusion ()
445466 && thirdParam->hasFinishedEditing ) {
446467 unsetOnViewParameter (fourthParam.get ());
468+ handler->widthSign = 0 ;
447469 return ;
448470 }
449471 }
450472 }
451- int sign = (onSketchPos.y - handler->startPoint .y ) >= 0 ? 1 : -1 ;
452- onSketchPos.y = handler->startPoint .y + sign * width;
473+ if (handler->widthSign == 0 ) {
474+ handler->widthSign = (onSketchPos.y - handler->startPoint .y ) >= 0 ? 1 : -1 ;
475+ }
476+ onSketchPos.y = handler->startPoint .y + handler->widthSign * width;
453477 }
454478 }
455479 else if (handler->constructionMethod () == ConstructionMethod::OnePointLengthAngle) {
@@ -460,20 +484,29 @@ void DSHLineControllerBase::doEnforceControlParameters(Base::Vector2d& onSketchP
460484 }
461485 double length = dir.Length ();
462486
487+ if (fourthParam->isSet ) {
488+ const double angle = Base::toRadians (fourthParam->getValue ());
489+ const Base::Vector2d ovpDir (cos (angle), sin (angle));
490+ handler->capturedDirection = ovpDir;
491+ }
492+ else {
493+ handler->capturedDirection = dir.Normalize ();
494+ }
495+
463496 if (thirdParam->isSet ) {
464497 length = thirdParam->getValue ();
465498 if (length < Precision::Confusion () && thirdParam->hasFinishedEditing ) {
466499 unsetOnViewParameter (thirdParam.get ());
500+ handler->capturedDirection = Base::Vector2d (0.0 , 0.0 );
467501 return ;
468502 }
469503
470- onSketchPos = handler->startPoint + length * dir. Normalize () ;
504+ onSketchPos = handler->startPoint + length * handler-> capturedDirection ;
471505 }
472-
473- if (fourthParam->isSet ) {
474- double angle = Base::toRadians (fourthParam->getValue ());
475- Base::Vector2d ovpDir (cos (angle), sin (angle));
476- onSketchPos.ProjectToLine (onSketchPos - handler->startPoint , ovpDir);
506+ else if (fourthParam->isSet ) {
507+ // only angle is set, project current position onto that angle
508+ onSketchPos.ProjectToLine (onSketchPos - handler->startPoint ,
509+ handler->capturedDirection );
477510 onSketchPos += handler->startPoint ;
478511 }
479512 }
@@ -490,6 +523,8 @@ void DSHLineControllerBase::doEnforceControlParameters(Base::Vector2d& onSketchP
490523 && (onSketchPos - handler->startPoint ).Length () < Precision::Confusion ()) {
491524 unsetOnViewParameter (thirdParam.get ());
492525 unsetOnViewParameter (fourthParam.get ());
526+ handler->lengthSign = 0 ;
527+ handler->widthSign = 0 ;
493528 }
494529 } break ;
495530 default :
0 commit comments