Sketcher: Display arc angle and length constraints beyond center point (#22651)

* Allow arc segment length and angle constraints to go past the center point

* fix angle helper lines

* fix linter warning

* fix arc length calculation

---------

Co-authored-by: Matthias Danner <28687794+matthiasdanner@users.noreply.github.com>
This commit is contained in:
matthiasdanner
2025-07-25 13:57:21 +02:00
committed by GitHub
parent 0270515a33
commit 57f251d742
3 changed files with 33 additions and 15 deletions

View File

@@ -1438,21 +1438,23 @@ void SoDatumLabel::drawAngle(const SbVec3f* points, float& angle, SbVec3f& textO
SbVec3f v0(cos(startangle+range/2),sin(startangle+range/2),0);
// leave some space for the text
double textMargin = std::min(0.2F * abs(range), this->imgWidth / (2 * r));
float textMargin = std::min(0.2F * abs(range), this->imgWidth / (2 * r));
textOffset = p0 + v0 * r;
// Draw
glDrawArc(p0, r, startangle, startangle+range/2.-textMargin);
glDrawArc(p0, r, startangle+range/2.+textMargin, endangle);
// Direction vectors for start and end lines
SbVec3f v1(cos(startangle), sin(startangle), 0);
SbVec3f v2(cos(endangle), sin(endangle), 0);
if (range < 0) {
float textMarginDir = 1.;
if (range < 0 || length < 0) {
std::swap(v1, v2);
textMarginDir = -1.;
}
// Draw
glDrawArc(p0, r, startangle, startangle + range / 2.F - textMarginDir * textMargin);
glDrawArc(p0, r, startangle + range / 2.F + textMarginDir * textMargin, endangle);
SbVec3f pnt1 = p0 + (r - endLineLength1) * v1;
SbVec3f pnt2 = p0 + (r + endLineLength12) * v1;

View File

@@ -5055,9 +5055,16 @@ void CmdSketcherConstrainDistance::applyConstraint(std::vector<SelIdPair>& selSe
const Part::Geometry* geom = Obj->getGeometry(GeoId1);
if (isLineSegment(*geom)) {
auto lineSeg = static_cast<const Part::GeomLineSegment*>(geom);
double ActLength = (lineSeg->getEndPoint() - lineSeg->getStartPoint()).Length();
if (isLineSegment(*geom) || isArcOfCircle(*geom)) {
double ActLength = 0.;
if (isLineSegment(*geom)) {
auto lineSeg = static_cast<const Part::GeomLineSegment*>(geom);
ActLength = (lineSeg->getEndPoint() - lineSeg->getStartPoint()).Length();
}
else if (isArcOfCircle(*geom)) {
auto arc = static_cast<const Part::GeomArcOfCircle*>(geom);
ActLength = arc->getAngle(false) * arc->getRadius();
}
openCommand(QT_TRANSLATE_NOOP("Command", "Add length constraint"));
Gui::cmdAppObjectArgs(Obj,

View File

@@ -1862,15 +1862,15 @@ void ViewProviderSketch::moveConstraint(Sketcher::Constraint* Constr, int constN
}
else if (geo->is<Part::GeomArcOfCircle>()) {
auto* arc = static_cast<const Part::GeomArcOfCircle*>(geo);
double radius = arc->getRadius();
Base::Vector3d center = arc->getCenter();
double startangle, endangle;
arc->getRange(startangle, endangle, /*emulateCCW=*/true);
if (Constr->Type == Distance && Constr->Second == GeoEnum::GeoUndef){
//arc length
Base::Vector3d dir = Base::Vector3d(toPos.x, toPos.y, 0.) - arc->getCenter();
Constr->LabelDistance = dir.Length();
double arcAngle = (startangle + endangle) / 2.;
Base::Vector2d arcDirection(std::cos(arcAngle), std::sin(arcAngle));
Base::Vector2d centerToToPos = toPos - Base::Vector2d(center.x, center.y);
Constr->LabelDistance = centerToToPos * arcDirection;
cleanAndDraw();
return;
@@ -1886,8 +1886,10 @@ void ViewProviderSketch::moveConstraint(Sketcher::Constraint* Constr, int constN
Base::Vector3d tmpDir = Base::Vector3d(toPos.x, toPos.y, 0) - p1;
angle = atan2(tmpDir.y, tmpDir.x);
}
if (Constr->Type == Sketcher::Diameter)
double radius = arc->getRadius();
if (Constr->Type == Sketcher::Diameter) {
p1 = center - radius * Base::Vector3d(cos(angle), sin(angle), 0.);
}
p2 = center + radius * Base::Vector3d(cos(angle), sin(angle), 0.);
}
@@ -2070,7 +2072,14 @@ void ViewProviderSketch::moveAngleConstraint(Sketcher::Constraint* constr, int c
}
else if (isArcOfCircle(*geo)) {
const auto* arc = static_cast<const Part::GeomArcOfCircle*>(geo);
p0 = arc->getCenter();
Base::Vector3d center = arc->getCenter();
double startangle, endangle;
arc->getRange(startangle, endangle, /*emulateCCW=*/true);
double arcAngle = (startangle + endangle) / 2.;
Base::Vector2d arcDirection(std::cos(arcAngle), std::sin(arcAngle));
Base::Vector2d centerToToPos = toPos - Base::Vector2d(center.x, center.y);
constr->LabelDistance = centerToToPos * arcDirection;
return;
}
else {
return;