From 952ae46d492db13b94f9ed9f049bf18762aac59f Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Wed, 21 Feb 2024 15:04:15 -0500 Subject: [PATCH] Toposhape/Part: Transfer in makEFillet and makEChamfer --- src/Mod/Part/App/TopoShape.h | 65 +++++++++++++++++++++++++ src/Mod/Part/App/TopoShapeExpansion.cpp | 53 ++++++++++++++++++++ 2 files changed, 118 insertions(+) diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index c057a9a12e..4f0f4c86a5 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -1317,6 +1317,71 @@ public: { return TopoShape(0, Hasher).makeElementBoolean(maker, *this, op, tol); } + + /* Make fillet shape + * + * @param source: the source shape + * @param edges: the edges of the source shape where to make fillets + * @param radius1: the radius of the beginning of the fillet + * @param radius2: the radius of the ending of the fillet + * @param op: optional string to be encoded into topo naming for indicating + * the operation + * + * @return The original content of this TopoShape is discarded and replaced + * with the new shape. The function returns the TopoShape itself as + * a self reference so that multiple operations can be carried out + * for the same shape in the same line of code. + */ + TopoShape &makEFillet(const TopoShape &source, const std::vector &edges, + double radius1, double radius2, const char *op=nullptr); + /* Make fillet shape + * + * @param source: the source shape + * @param edges: the edges of the source shape where to make fillets + * @param radius1: the radius of the beginning of the fillet + * @param radius2: the radius of the ending of the fillet + * @param op: optional string to be encoded into topo naming for indicating + * the operation + * + * @return Return the new shape. The TopoShape itself is not modified. + */ + TopoShape makEFillet(const std::vector &edges, + double radius1, double radius2, const char *op=nullptr) const { + return TopoShape(0,Hasher).makEFillet(*this,edges,radius1,radius2,op); + } + + /* Make chamfer shape + * + * @param source: the source shape + * @param edges: the edges of the source shape where to make chamfers + * @param radius1: the radius of the beginning of the chamfer + * @param radius2: the radius of the ending of the chamfer + * @param op: optional string to be encoded into topo naming for indicating + * the operation + * + * @return The original content of this TopoShape is discarded and replaced + * with the new shape. The function returns the TopoShape itself as + * a self reference so that multiple operations can be carried out + * for the same shape in the same line of code. + */ + TopoShape &makEChamfer(const TopoShape &source, const std::vector &edges, + double radius1, double radius2, const char *op=nullptr, bool flipDirection=false, bool asAngle=false); + /* Make chamfer shape + * + * @param source: the source shape + * @param edges: the edges of the source shape where to make chamfers + * @param radius1: the radius of the beginning of the chamfer + * @param radius2: the radius of the ending of the chamfer + * @param op: optional string to be encoded into topo naming for indicating + * the operation + * + * @return Return the new shape. The TopoShape itself is not modified. + */ + TopoShape makEChamfer(const std::vector &edges, + double radius1, double radius2, const char *op=nullptr, bool flipDirection=false, bool asAngle=false) const { + return TopoShape(0,Hasher).makEChamfer(*this,edges,radius1,radius2,op,flipDirection,asAngle); + } + /* Make draft shape * * @param source: the source shape diff --git a/src/Mod/Part/App/TopoShapeExpansion.cpp b/src/Mod/Part/App/TopoShapeExpansion.cpp index 4f81696abc..df7a65b67e 100644 --- a/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -2594,6 +2594,59 @@ struct MapperThruSections: MapperMaker } }; +TopoShape &TopoShape::makEFillet(const TopoShape &shape, const std::vector &edges, + double radius1, double radius2, const char *op) +{ + if(!op) op = Part::OpCodes::Fillet; + if(shape.isNull()) + HANDLE_NULL_SHAPE; + + if(edges.empty()) + HANDLE_NULL_INPUT; + + BRepFilletAPI_MakeFillet mkFillet(shape.getShape()); + for(auto &e : edges) { + if(e.isNull()) + HANDLE_NULL_INPUT; + const auto &edge = e.getShape(); + if(!shape.findShape(edge)) + FC_THROWM(Base::CADKernelError,"edge does not belong to the shape"); + mkFillet.Add(radius1, radius2, TopoDS::Edge(edge)); + } + return makEShape(mkFillet,shape,op); +} + +TopoShape &TopoShape::makEChamfer(const TopoShape &shape, const std::vector &edges, + double radius1, double radius2, const char *op, bool flipDirection, bool asAngle) +{ + if(!op) op = Part::OpCodes::Chamfer; + if(shape.isNull()) + HANDLE_NULL_SHAPE; + + if(edges.empty()) + HANDLE_NULL_INPUT; + + BRepFilletAPI_MakeChamfer mkChamfer(shape.getShape()); + for(auto &e : edges) { + const auto &edge = e.getShape(); + if(e.isNull()) + HANDLE_NULL_INPUT; + if(!shape.findShape(edge)) + FC_THROWM(Base::CADKernelError,"edge does not belong to the shape"); + //Add edge to fillet algorithm + TopoDS_Shape face; + if(flipDirection) + face = shape.findAncestorsShapes(edge,TopAbs_FACE).back(); + else + face = shape.findAncestorShape(edge,TopAbs_FACE); + if(asAngle) + mkChamfer.AddDA(radius1, radius2, TopoDS::Edge(edge), TopoDS::Face(face)); + else + mkChamfer.Add(radius1, radius2, TopoDS::Edge(edge), TopoDS::Face(face)); + } + return makEShape(mkChamfer,shape,op); +} + TopoShape& TopoShape::makeElementGeneralFuse(const std::vector& _shapes, std::vector>& modifies, double tol,