From b5af3d38c36932087bf9d769a826f42b3a8cae8c Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sat, 24 Feb 2024 16:19:25 -0500 Subject: [PATCH] Toposhape/Part: Transfer in replacEShape and removEShape --- src/Mod/Part/App/TopoShape.h | 42 +++++++++++++++++++++++++ src/Mod/Part/App/TopoShapeExpansion.cpp | 37 +++++++++++++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index b5840144f3..b972b6a5d7 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -1041,6 +1041,48 @@ public: double tol3d = 0.0, double tolBound = 0.0, double tolAngluar = 0.0); + /* Make a shape with some subshapes replaced + * + * @param source: the source shape + * @param s: replacement mapping the existing sub shape of source to new shapes + * + * @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 &replacEShape(const TopoShape &source, const std::vector > &s); + /* Make a new shape using this shape with some subshapes replaced by others + * + * @param s: replacement mapping the existing sub shape of source to new shapes + * + * @return Return the new shape. The TopoShape itself is not modified. + */ + TopoShape replacEShape(const std::vector > &s) const { + return TopoShape(0,Hasher).replacEShape(*this,s); + } + + /* Make a shape with some subshapes removed + * + * @param source: the source shape + * @param s: the subshapes to be removed + * + * @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 &removEShape(const TopoShape &source, const std::vector& s); + /* Make a new shape using this shape with some subshapes removed + * + * @param s: the subshapes to be removed + * + * @return Return the new shape. The TopoShape itself is not modified. + */ + TopoShape removEShape(const std::vector& s) const { + return TopoShape(0,Hasher).removEShape(*this,s); + } + /** Make shape using generalized fusion and return the modified sub shapes * diff --git a/src/Mod/Part/App/TopoShapeExpansion.cpp b/src/Mod/Part/App/TopoShapeExpansion.cpp index b6829b3260..e60c7780b2 100644 --- a/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -3059,7 +3059,7 @@ TopoShape& TopoShape::makeElementSolid(const TopoShape& shape, const char* op) } return *this; } - + TopoShape& TopoShape::makeElementMirror(const TopoShape& shape, const gp_Ax2& ax2, const char* op) { if (!op) { @@ -3108,6 +3108,41 @@ TopoShape& TopoShape::makeElementSlices(const TopoShape& shape, return makeElementCompound(wires, op, SingleShapeCompoundCreationPolicy::returnShape); } +TopoShape &TopoShape::replacEShape(const TopoShape &shape, + const std::vector > &s) +{ + if(shape.isNull()) + HANDLE_NULL_SHAPE; + BRepTools_ReShape reshape; + std::vector shapes; + shapes.reserve(s.size()+1); + for (auto &v : s) { + if(v.first.isNull() || v.second.isNull()) + HANDLE_NULL_INPUT; + reshape.Replace(v.first.getShape(), v.second.getShape()); + shapes.push_back(v.second); + } + shapes.push_back(shape); + setShape(reshape.Apply(shape.getShape(),TopAbs_SHAPE)); + mapSubElement(shapes); + return *this; +} + +TopoShape &TopoShape::removEShape(const TopoShape &shape, const std::vector& s) +{ + if(shape.isNull()) + HANDLE_NULL_SHAPE; + BRepTools_ReShape reshape; + for(auto &sh : s) { + if(sh.isNull()) + HANDLE_NULL_INPUT; + reshape.Remove(sh.getShape()); + } + setShape(reshape.Apply(shape.getShape(), TopAbs_SHAPE)); + mapSubElement(shape); + return *this; +} + TopoShape& TopoShape::makeElementFillet(const TopoShape& shape, const std::vector& edges, double radius1,