From f38485ada2c22961fe170c257ba8c2b81df04b3c Mon Sep 17 00:00:00 2001 From: matthiasdanner Date: Sun, 20 Jul 2025 19:46:49 +0200 Subject: [PATCH] Sketcher: Add second arc helper on diameter constraint (#22579) * add second arc helper on diameter constraint * fix linter warnings --------- Co-authored-by: Matthias Danner <28687794+matthiasdanner@users.noreply.github.com> --- src/Gui/SoDatumLabel.cpp | 56 ++++++------------- .../Gui/EditModeConstraintCoinManager.cpp | 22 ++++++-- .../Gui/EditModeConstraintCoinManager.h | 2 +- 3 files changed, 35 insertions(+), 45 deletions(-) diff --git a/src/Gui/SoDatumLabel.cpp b/src/Gui/SoDatumLabel.cpp index b946d96b1a..251a34c9c9 100644 --- a/src/Gui/SoDatumLabel.cpp +++ b/src/Gui/SoDatumLabel.cpp @@ -1303,35 +1303,18 @@ void SoDatumLabel::drawDistance(const SbVec3f* points) // Draw arc helpers if needed float range1 = this->param4.getValue(); if (range1 != 0.0) { - float startangle1 = this->param3.getValue(); + float startAngle1 = this->param3.getValue(); float radius1 = this->param5.getValue(); - SbVec3f center = points[2]; - int countSegments = std::max(6, abs(int(50.0 * range1 / (2 * std::numbers::pi)))); - double segment = range1 / (countSegments - 1); - - glBegin(GL_LINE_STRIP); - for (int i = 0; i < countSegments; i++) { - double theta = startangle1 + segment * i; - SbVec3f v1 = center + SbVec3f(radius1 * cos(theta), radius1 * sin(theta), 0); - glVertex2f(v1[0], v1[1]); - } - glEnd(); + SbVec3f center1 = points[2]; + glDrawArc(center1, radius1, startAngle1, startAngle1 + range1); } + float range2 = this->param7.getValue(); if (range2 != 0.0) { - float startangle2 = this->param6.getValue(); + float startAngle2 = this->param6.getValue(); float radius2 = this->param8.getValue(); - SbVec3f center = points[3]; - int countSegments = std::max(6, abs(int(50.0 * range2 / (2 * std::numbers::pi)))); - double segment = range2 / (countSegments - 1); - - glBegin(GL_LINE_STRIP); - for (int i = 0; i < countSegments; i++) { - double theta = startangle2 + segment * i; - SbVec3f v1 = center + SbVec3f(radius2 * cos(theta), radius2 * sin(theta), 0); - glVertex2f(v1[0], v1[1]); - } - glEnd(); + SbVec3f center2 = points[3]; + glDrawArc(center2, radius2, startAngle2, startAngle2 + range2); } } @@ -1343,7 +1326,7 @@ void SoDatumLabel::drawRadiusOrDiameter(const SbVec3f* points, float& angle, SbV SbVec3f dir = (p2-p1); SbVec3f center = p1; - double radius = (p2 - p1).length(); + float radius = (p2 - p1).length(); if (this->datumtype.getValue() == DIAMETER) { center = (p1 + p2) / 2; radius = radius / 2; @@ -1412,20 +1395,17 @@ void SoDatumLabel::drawRadiusOrDiameter(const SbVec3f* points, float& angle, SbV glEnd(); } - // Draw arc helper if needed - float startangle = this->param3.getValue(); - float range = this->param4.getValue(); - if (range != 0.0) { - int countSegments = std::max(6, abs(int(50.0 * range / (2 * std::numbers::pi)))); - double segment = range / (countSegments - 1); + // Draw arc helpers if needed + float startHelperRange = this->param4.getValue(); + if (startHelperRange != 0.0) { + float startHelperAngle = this->param3.getValue(); + glDrawArc(center, radius, startHelperAngle, startHelperAngle + startHelperRange); + } - glBegin(GL_LINE_STRIP); - for (int i = 0; i < countSegments; i++) { - double theta = startangle + segment * i; - SbVec3f v1 = center + SbVec3f(radius * cos(theta), radius * sin(theta), 0); - glVertex2f(v1[0], v1[1]); - } - glEnd(); + float endHelperRange = this->param6.getValue(); + if (endHelperRange != 0.0) { + float endHelperAngle = this->param5.getValue(); + glDrawArc(center, radius, endHelperAngle, endHelperAngle + endHelperRange); } } diff --git a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp index 8e25ea1bc8..6fccb92413 100644 --- a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp +++ b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp @@ -1457,8 +1457,10 @@ Restart: assert(Constr->First >= -extGeoCount && Constr->First < intGeoCount); Base::Vector3d pnt1(0., 0., 0.), pnt2(0., 0., 0.); - double helperStartAngle = 0.; - double helperRange = 0.; + double startHelperAngle = 0.; + double startHelperRange = 0.; + double endHelperAngle = 0.; + double endHelperRange = 0.; if (Constr->First == GeoEnum::GeoUndef) { break; @@ -1477,12 +1479,18 @@ Restart: angle = (startAngle + endAngle) / 2; } - findHelperAngles(helperStartAngle, - helperRange, + findHelperAngles(startHelperAngle, + startHelperRange, angle, startAngle, endAngle); + findHelperAngles(endHelperAngle, + endHelperRange, + angle + pi, + startAngle, + endAngle); + Base::Vector3d center = arc->getCenter(); pnt1 = center - radius * Base::Vector3d(cos(angle), sin(angle), 0.); pnt2 = center + radius * Base::Vector3d(cos(angle), sin(angle), 0.); @@ -1515,8 +1523,10 @@ Restart: asciiText->datumtype = SoDatumLabel::DIAMETER; asciiText->param1 = Constr->LabelDistance; asciiText->param2 = Constr->LabelPosition; - asciiText->param3 = helperStartAngle; - asciiText->param4 = helperRange; + asciiText->param3 = static_cast(startHelperAngle); + asciiText->param4 = static_cast(startHelperRange); + asciiText->param5 = static_cast(endHelperAngle); + asciiText->param6 = static_cast(endHelperRange); asciiText->pnts.setNum(2); SbVec3f* verts = asciiText->pnts.startEditing(); diff --git a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.h b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.h index 8db7b6d798..e5ce3a1a6d 100644 --- a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.h +++ b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.h @@ -253,7 +253,7 @@ private: /// Find helper angle for radius/diameter constraint void findHelperAngles(double& helperStartAngle, - double& helperAngle, + double& helperRange, double angle, double startAngle, double endAngle);