From ada2f9326a73ab9d86fc79ebbd454ca0dc2ca5fa Mon Sep 17 00:00:00 2001 From: jfa Date: Wed, 15 Nov 2023 13:51:53 +0000 Subject: [PATCH] 0033433: Shape Healing - Implement a new mode to keep initial types of curves. Fix processing of Bezier and BSpline edges. --- src/ShapeFix/ShapeFix_Wire.cxx | 36 ++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/ShapeFix/ShapeFix_Wire.cxx b/src/ShapeFix/ShapeFix_Wire.cxx index b54d03ab11..187786b95e 100644 --- a/src/ShapeFix/ShapeFix_Wire.cxx +++ b/src/ShapeFix/ShapeFix_Wire.cxx @@ -1478,17 +1478,45 @@ Standard_Boolean ShapeFix_Wire::FixCurves(const Standard_Integer theIdx) else if (aCurve3d->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) { Handle(Geom_BSplineCurve) anOld = Handle(Geom_BSplineCurve)::DownCast(aCurve3d); + + if (anOld->Pole(1).Distance(aGeomEnds[0]) > Precision::Confusion() || + anOld->Pole(anOld->NbPoles()).Distance(aGeomEnds[1]) > Precision::Confusion()) { + // FAIL1 means we cannot fix Bezier or B-Spline curve + // because its ends do not correspond to first and last poles + // (i.e. it is a piece of entire curve) + myLastFixStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 ); + return false; + } + + Handle(Geom_Geometry) aNewG = anOld->Copy(); + Handle(Geom_BSplineCurve) aNewC = Handle(Geom_BSplineCurve)::DownCast(aNewG); int p = anEnds[0].Distance(aGeomEnds[0]) < anEnds[1].Distance(aGeomEnds[0]) ? 0 : 2; - anOld->SetPole(1, anEnds[p]); - anOld->SetPole(anOld->NbPoles(), anEnds[2-p]); + aNewC->SetPole(1, anEnds[p]); + aNewC->SetPole(anOld->NbPoles(), anEnds[2-p]); + TopoDS_Edge aNewEdge = BRepBuilderAPI_MakeEdge(aNewC).Edge(); + anSbwd->Set(aNewEdge, theIdx); return true; } else if (aCurve3d->IsKind(STANDARD_TYPE(Geom_BezierCurve))) { Handle(Geom_BezierCurve) anOld = Handle(Geom_BezierCurve)::DownCast(aCurve3d); + + if (anOld->Pole(1).Distance(aGeomEnds[0]) > Precision::Confusion() || + anOld->Pole(anOld->NbPoles()).Distance(aGeomEnds[1]) > Precision::Confusion()) { + // FAIL1 means we cannot fix Bezier or B-Spline curve + // because its ends do not correspond to first and last poles + // (i.e. it is a piece of entire curve) + myLastFixStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 ); + return false; + } + + Handle(Geom_Geometry) aNewG = anOld->Copy(); + Handle(Geom_BezierCurve) aNewC = Handle(Geom_BezierCurve)::DownCast(aNewG); int p = anEnds[0].Distance(aGeomEnds[0]) < anEnds[1].Distance(aGeomEnds[0]) ? 0 : 2; - anOld->SetPole(1, anEnds[p]); - anOld->SetPole(anOld->NbPoles(), anEnds[2-p]); + aNewC->SetPole(1, anEnds[p]); + aNewC->SetPole(anOld->NbPoles(), anEnds[2-p]); + TopoDS_Edge aNewEdge = BRepBuilderAPI_MakeEdge(aNewC).Edge(); + anSbwd->Set(aNewEdge, theIdx); return true; }