From 4442fa709e332b7c5ce854da155cdd4b4a07b17f Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Thu, 11 Apr 2024 08:26:27 +0200 Subject: [PATCH] Sketcher: Dimension tool : add arc length --- src/Mod/Sketcher/Gui/CommandConstraints.cpp | 80 ++++++++++++++------- 1 file changed, 53 insertions(+), 27 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index 14740c697b..e279cd1502 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -2018,45 +2018,51 @@ protected: int geoId = selCircleArc[0].GeoId; bool reverseOrder = isRadiusDoF(geoId); - if (availableConstraint == AvailableConstraint::FIRST) { - if (!reverseOrder) { + if (reverseOrder) { + if (availableConstraint == AvailableConstraint::FIRST) { + restartCommand(QT_TRANSLATE_NOOP("Command", "Add arc angle constraint")); + createArcAngleConstrain(geoId, onSketchPos); + selAllowed = true; + } + if (availableConstraint == AvailableConstraint::SECOND) { + restartCommand(QT_TRANSLATE_NOOP("Command", "Add arc length constraint")); + createArcLengthConstrain(geoId, onSketchPos); + } + if (availableConstraint == AvailableConstraint::THIRD) { restartCommand(QT_TRANSLATE_NOOP("Command", "Add Radius constraint")); createRadiusDiameterConstrain(geoId, onSketchPos, true); } - else { - restartCommand(QT_TRANSLATE_NOOP("Command", "Add arc angle constraint")); - createArcAngleConstrain(geoId, onSketchPos); - } - selAllowed = true; - } - if (availableConstraint == AvailableConstraint::SECOND) { - restartCommand(QT_TRANSLATE_NOOP("Command", "Add Radius constraint")); - createRadiusDiameterConstrain(geoId, onSketchPos, reverseOrder); - if (!isArcOfCircle(*Obj->getGeometry(geoId))) { - //This way if key is pressed again it goes back to FIRST + if (availableConstraint == AvailableConstraint::FOURTH) { + restartCommand(QT_TRANSLATE_NOOP("Command", "Add Radius constraint")); + createRadiusDiameterConstrain(geoId, onSketchPos, false); availableConstraint = AvailableConstraint::RESET; } } - if (availableConstraint == AvailableConstraint::THIRD) { - if (!reverseOrder) { - restartCommand(QT_TRANSLATE_NOOP("Command", "Add arc angle constraint")); - createArcAngleConstrain(geoId, onSketchPos); + else { + if (availableConstraint == AvailableConstraint::FIRST) { + restartCommand(QT_TRANSLATE_NOOP("Command", "Add Radius constraint")); + createRadiusDiameterConstrain(geoId, onSketchPos, true); + selAllowed = true; } - else { + if (availableConstraint == AvailableConstraint::SECOND) { restartCommand(QT_TRANSLATE_NOOP("Command", "Add Radius constraint")); createRadiusDiameterConstrain(geoId, onSketchPos, false); - } - availableConstraint = AvailableConstraint::RESET; - } - /* - bool firstCstr = true; - if (availableConstraint != AvailableConstraint::FIRST) { - firstCstr = false; - if (!isArcOfCircle(*geom)) { + if (!isArcOfCircle(*Obj->getGeometry(geoId))) { //This way if key is pressed again it goes back to FIRST availableConstraint = AvailableConstraint::RESET; } - }*/ + } + if (availableConstraint == AvailableConstraint::THIRD) { + restartCommand(QT_TRANSLATE_NOOP("Command", "Add arc angle constraint")); + createArcAngleConstrain(geoId, onSketchPos); + } + if (availableConstraint == AvailableConstraint::FOURTH) { + restartCommand(QT_TRANSLATE_NOOP("Command", "Add arc length constraint")); + createArcLengthConstrain(geoId, onSketchPos); + availableConstraint = AvailableConstraint::RESET; + } + } + } void makeCts_2Circle(bool& selAllowed, Base::Vector2d onSketchPos) @@ -2429,6 +2435,26 @@ protected: moveConstraint(ConStr.size() - 1, onSketchPos); } + void createArcLengthConstrain(int GeoId, Base::Vector2d onSketchPos) { + const Part::Geometry* geom = Obj->getGeometry(GeoId); + if (isArcOfCircle(*geom)) { + + const auto* arc = static_cast(geom); + double ActLength = arc->getAngle(false) * arc->getRadius(); + + Gui::cmdAppObjectArgs(Obj, "addConstraint(Sketcher.Constraint('Distance',%d,%f))", + GeoId, ActLength); + + const std::vector& ConStr = Obj->Constraints.getValues(); + if (isPointOrSegmentFixed(Obj, GeoId) || constraintCreationMode == Reference) { + // it is a constraint on a external line, make it non-driving + Gui::cmdAppObjectArgs(Obj, "setDriving(%i,%s)", ConStr.size() - 1, "False"); + } + numberOfConstraintsCreated++; + moveConstraint(ConStr.size() - 1, onSketchPos); + } + } + void createArcAngleConstrain(int GeoId, Base::Vector2d onSketchPos) { const Part::Geometry* geom = Obj->getGeometry(GeoId); if (isArcOfCircle(*geom)) {