Sketcher: Chamfer Fix #13049

This commit is contained in:
PaddleStroke
2024-03-28 10:22:16 +01:00
committed by Chris Hennes
parent 3aa0241dc9
commit 6f817fa190

View File

@@ -2117,6 +2117,8 @@ int SketchObject::fillet(int GeoId1, int GeoId2, const Base::Vector3d& refPnt1,
Base::Vector3d p1, p2;
PointPos PosId1 = PointPos::none;
PointPos PosId2 = PointPos::none;
PointPos filletPosId1 = PointPos::none;
PointPos filletPosId2 = PointPos::none;
int filletId;
if (geo1->is<Part::GeomLineSegment>() && geo2->is<Part::GeomLineSegment>()) {
@@ -2146,11 +2148,11 @@ int SketchObject::fillet(int GeoId1, int GeoId2, const Base::Vector3d& refPnt1,
return -1;
}
p1 = arc->getStartPoint();
p2 = arc->getEndPoint();
p1 = arc->getStartPoint(/*emulateCCW=*/true);
p2 = arc->getEndPoint(/*emulateCCW=*/true);
dist1.ProjectToLine(arc->getStartPoint(/*emulateCCW=*/true) - intersection, dir1);
dist2.ProjectToLine(arc->getStartPoint(/*emulateCCW=*/true) - intersection, dir2);
dist1.ProjectToLine(p1 - intersection, dir1);
dist2.ProjectToLine(p1 - intersection, dir2);
filletId = addGeometry(arc.get());
if (trim) {
@@ -2165,6 +2167,19 @@ int SketchObject::fillet(int GeoId1, int GeoId2, const Base::Vector3d& refPnt1,
delConstraintOnPoint(GeoId2, PosId2, false);
}
if (dist1.Length() < dist2.Length()) {
filletPosId1 = PointPos::start;
filletPosId2 = PointPos::end;
movePoint(GeoId1, PosId1, p1, false, true);
movePoint(GeoId2, PosId2, p2, false, true);
}
else {
filletPosId1 = PointPos::end;
filletPosId2 = PointPos::start;
movePoint(GeoId1, PosId1, p2, false, true);
movePoint(GeoId2, PosId2, p1, false, true);
}
auto tangent1 = std::make_unique<Sketcher::Constraint>();
auto tangent2 = std::make_unique<Sketcher::Constraint>();
@@ -2172,24 +2187,13 @@ int SketchObject::fillet(int GeoId1, int GeoId2, const Base::Vector3d& refPnt1,
tangent1->First = GeoId1;
tangent1->FirstPos = PosId1;
tangent1->Second = filletId;
tangent1->SecondPos = filletPosId1;
tangent2->Type = Sketcher::Tangent;
tangent2->First = GeoId2;
tangent2->FirstPos = PosId2;
tangent2->Second = filletId;
if (dist1.Length() < dist2.Length()) {
tangent1->SecondPos = PointPos::start;
tangent2->SecondPos = PointPos::end;
movePoint(GeoId1, PosId1, arc->getStartPoint(/*emulateCCW=*/true), false, true);
movePoint(GeoId2, PosId2, arc->getEndPoint(/*emulateCCW=*/true), false, true);
}
else {
tangent1->SecondPos = PointPos::end;
tangent2->SecondPos = PointPos::start;
movePoint(GeoId1, PosId1, arc->getEndPoint(/*emulateCCW=*/true), false, true);
movePoint(GeoId2, PosId2, arc->getStartPoint(/*emulateCCW=*/true), false, true);
}
tangent2->SecondPos = filletPosId2;
addConstraint(std::move(tangent1));
addConstraint(std::move(tangent2));
@@ -2620,8 +2624,8 @@ int SketchObject::fillet(int GeoId1, int GeoId2, const Base::Vector3d& refPnt1,
arc->setCenter(filletcenterpoint.first);
arc->setRange(startAngle, endAngle, /*emulateCCWXY=*/true);
p1 = arc->getStartPoint();
p2 = arc->getEndPoint();
p1 = arc->getStartPoint(true);
p2 = arc->getEndPoint(true);
// add arc to sketch geometry
filletId = addGeometry(arc);
@@ -2655,6 +2659,21 @@ int SketchObject::fillet(int GeoId1, int GeoId2, const Base::Vector3d& refPnt1,
delConstraintOnPoint(GeoId1, PosId1, false);
delConstraintOnPoint(GeoId2, PosId2, false);
double dist1 = (refp1 - p1).Length();
double dist2 = (refp1 - p2).Length();
if (dist1 < dist2) {
filletPosId1 = PointPos::start;
filletPosId2 = PointPos::end;
movePoint(GeoId1, PosId1, p1, false, true);
movePoint(GeoId2, PosId2, p2, false, true);
}
else {
filletPosId1 = PointPos::end;
filletPosId2 = PointPos::start;
movePoint(GeoId1, PosId1, p2, false, true);
movePoint(GeoId2, PosId2, p1, false, true);
}
auto* tangent1 = new Sketcher::Constraint();
auto* tangent2 = new Sketcher::Constraint();
@@ -2663,29 +2682,13 @@ int SketchObject::fillet(int GeoId1, int GeoId2, const Base::Vector3d& refPnt1,
tangent1->First = GeoId1;
tangent1->FirstPos = PosId1;
tangent1->Second = filletId;
tangent1->SecondPos = filletPosId1;
tangent2->Type = Sketcher::Tangent;
tangent2->First = GeoId2;
tangent2->FirstPos = PosId2;
tangent2->Second = filletId;
double dist1 = (refp1 - arc->getStartPoint(true)).Length();
double dist2 = (refp1 - arc->getEndPoint(true)).Length();
// Base::Console().Log("dists_refpoint_to_arc_sp_ep: (%f);(%f)",dist1,dist2);
if (dist1 < dist2) {
tangent1->SecondPos = PointPos::start;
tangent2->SecondPos = PointPos::end;
movePoint(GeoId1, PosId1, arc->getStartPoint(true), false, true);
movePoint(GeoId2, PosId2, arc->getEndPoint(true), false, true);
}
else {
tangent1->SecondPos = PointPos::end;
tangent2->SecondPos = PointPos::start;
movePoint(GeoId1, PosId1, arc->getEndPoint(true), false, true);
movePoint(GeoId2, PosId2, arc->getStartPoint(true), false, true);
}
tangent2->SecondPos = filletPosId2;
addConstraint(tangent1);
addConstraint(tangent2);
@@ -2709,16 +2712,17 @@ int SketchObject::fillet(int GeoId1, int GeoId2, const Base::Vector3d& refPnt1,
line->setPoints(p1, p2);
int lineGeoId = addGeometry(line.get());
auto coinc1 = std::make_unique<Sketcher::Constraint>();
auto coinc2 = std::make_unique<Sketcher::Constraint>();
coinc1->Type = Sketcher::Coincident;
coinc1->First = lineGeoId;
coinc1->FirstPos = PointPos::start;
coinc1->FirstPos = filletPosId1;
coinc2->Type = Sketcher::Coincident;
coinc2->First = lineGeoId;
coinc2->FirstPos = PointPos::end;
coinc2->FirstPos = filletPosId2;
if (trim) {
coinc1->Second = GeoId1;