Part: Add function BRepOffsetAPI_MakeOffsetFix::Replace() to replace unwanted curve type with a B-Spline curve

This commit is contained in:
wmayer
2022-04-11 14:13:36 +02:00
parent ef5d7fa64e
commit 60442c2712
2 changed files with 72 additions and 0 deletions

View File

@@ -24,8 +24,14 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRep_Builder.hxx>
# include <BRepAdaptor_Curve.hxx>
# include <BRepBuilderAPI_MakeEdge.hxx>
# include <BRepBuilderAPI_MakeWire.hxx>
# include <Geom_BSplineCurve.hxx>
# include <Precision.hxx>
# include <ShapeConstruct_Curve.hxx>
# include <Standard_Version.hxx>
# include <Standard_ConstructionError.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Compound.hxx>
@@ -217,3 +223,63 @@ Standard_Boolean BRepOffsetAPI_MakeOffsetFix::IsDeleted (const TopoDS_Shape& S)
{
return mkOffset.IsDeleted(S);
}
TopoDS_Shape BRepOffsetAPI_MakeOffsetFix::Replace(GeomAbs_CurveType type, const TopoDS_Shape& S) const
{
if (S.IsNull())
throw Standard_ConstructionError("Input shape is null");
// Nothing to do
if (type == GeomAbs_BSplineCurve)
return S;
if (S.ShapeType() == TopAbs_COMPOUND) {
BRep_Builder builder;
TopoDS_Compound comp;
builder.MakeCompound(comp);
comp.Location(S.Location());
TopExp_Explorer xp(S, TopAbs_WIRE);
while (xp.More()) {
TopoDS_Wire wire = TopoDS::Wire(xp.Current());
wire = ReplaceEdges(type, wire);
builder.Add(comp, wire);
xp.Next();
}
return comp;
}
else if (S.ShapeType() == TopAbs_WIRE) {
return ReplaceEdges(type, TopoDS::Wire(S));
}
else {
throw Standard_ConstructionError("Wrong shape type");
}
}
TopoDS_Wire BRepOffsetAPI_MakeOffsetFix::ReplaceEdges(GeomAbs_CurveType type, const TopoDS_Wire& wire) const
{
BRepBuilderAPI_MakeWire mkWire;
for (TopExp_Explorer xp(wire, TopAbs_EDGE); xp.More(); xp.Next()) {
TopoDS_Edge edge = TopoDS::Edge(xp.Current());
TopLoc_Location edgeLocation = edge.Location();
BRepAdaptor_Curve curve(edge);
if (curve.GetType() == type) {
ShapeConstruct_Curve scc;
double u = curve.FirstParameter();
double v = curve.LastParameter();
Handle(Geom_BSplineCurve) spline = scc.ConvertToBSpline(curve.Curve().Curve(), u, v, Precision::Confusion());
if (!spline.IsNull()) {
BRepBuilderAPI_MakeEdge mkEdge(spline, u, v);
edge = mkEdge.Edge();
edge.Location(edgeLocation);
}
}
mkWire.Add(edge);
}
return mkWire.Wire();
}