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>
This commit is contained in:
matthiasdanner
2025-07-20 19:46:49 +02:00
committed by GitHub
parent 538b6e042c
commit f38485ada2
3 changed files with 35 additions and 45 deletions

View File

@@ -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);
}
}

View File

@@ -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<float>(startHelperAngle);
asciiText->param4 = static_cast<float>(startHelperRange);
asciiText->param5 = static_cast<float>(endHelperAngle);
asciiText->param6 = static_cast<float>(endHelperRange);
asciiText->pnts.setNum(2);
SbVec3f* verts = asciiText->pnts.startEditing();

View File

@@ -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);