From c78027cc5cde95197f4c8b2c056ed3f4f3576aae Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Mon, 19 Feb 2024 21:12:52 -0500 Subject: [PATCH] Toposhape/Part: Transfer in makEGeneralFuse, makeEFuse, makeECut --- src/Mod/Part/App/TopoShape.h | 84 +++++++++++++++++++++++++ src/Mod/Part/App/TopoShapeExpansion.cpp | 67 ++++++++++++++++++++ 2 files changed, 151 insertions(+) diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index df56358cc9..ef1e063f38 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -865,6 +865,74 @@ public: double tolBound = 0.0, double tolAngluar = 0.0); + /** Make shape using generalized fusion and return the modified sub shapes + * + * @param sources: the source shapes + * @param modified: return the modified sub shapes + * @param tol: tolerance + * @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 &makEGeneralFuse(const std::vector &sources, + std::vector > &modified, double tol=0, const char *op=nullptr); + + /** Make a fusion of input shapes + * + * @param sources: the source shapes + * @param op: optional string to be encoded into topo naming for indicating + * the operation + * @param tol: tolerance for the fusion + * + * @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 &makEFuse(const std::vector &sources, const char *op=nullptr, double tol=0); + /** Make a fusion of this shape and an input shape + * + * @param source: the source shape + * @param op: optional string to be encoded into topo naming for indicating + * the operation + * @param tol: tolerance for the fusion + * + * @return Return the new shape. The TopoShape itself is not modified. + */ + TopoShape makEFuse(const TopoShape &source, const char *op=nullptr, double tol=0) const { + return TopoShape(0,Hasher).makEFuse({*this,source},op,tol); + } + + /** Make a boolean cut of this shape with an input shape + * + * @param source: the source shape + * @param op: optional string to be encoded into topo naming for indicating + * the operation + * @param tol: tolerance for the fusion + * + * @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 &makECut(const std::vector &sources, const char *op=nullptr, double tol=0); + /** Make a boolean cut of this shape with an input shape + * + * @param source: the source shape + * @param op: optional string to be encoded into topo naming for indicating + * the operation + * @param tol: tolerance for the fusion + * + * @return Return the new shape. The TopoShape itself is not modified. + */ + TopoShape makECut(const TopoShape &source, const char *op=nullptr, double tol=0) const { + return TopoShape(0,Hasher).makECut({*this,source},op,tol); + } + /** Try to simplify geometry of any linear/planar subshape to line/plane * * @return Return true if the shape is modified @@ -1315,6 +1383,22 @@ public: return makeElementShellFromWires(getSubTopoShapes(TopAbs_WIRE), silent, op); } + /** Make a planar face with the input wires or edges + * + * @param shapes: input shapes. Can be either edges, wires, or compound of + * those two types + * @param op: optional string to be encoded into topo naming for indicating + * the operation + * @param maker: optional type name of the face maker. If not given, + * default to "Part::FaceMakerBullseye" + * @param plane: optional plane of the face. + * + * @return The function creates a planar face. The original content of this + * TopoShape is discarded and replaced with the new shape. The + * function returns the TopoShape itself as a reference so that + * multiple operations can be carried out for the same shape in the + * same line of code. + */ TopoShape& makeElementFace(const std::vector& shapes, const char* op = nullptr, const char* maker = nullptr, diff --git a/src/Mod/Part/App/TopoShapeExpansion.cpp b/src/Mod/Part/App/TopoShapeExpansion.cpp index cd5f6b9bdd..a8396c180b 100644 --- a/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -2544,6 +2544,73 @@ struct MapperThruSections: MapperMaker } }; +TopoShape &TopoShape::makEGeneralFuse(const std::vector &_shapes, + std::vector > &modifies, double tol, const char *op) +{ +#if OCC_VERSION_HEX < 0x060900 + (void)_shapes; + (void)modifies; + (void)tol; + (void)op; + FC_THROWM(Base::NotImplementedError,"GFA is available only in OCC 6.9.0 and up."); +#else + if(!op) op = Part::OpCodes::GeneralFuse; + + if(_shapes.empty()) + HANDLE_NULL_INPUT; + + std::vector shapes(_shapes); + + BRepAlgoAPI_BuilderAlgo mkGFA; + mkGFA.SetRunParallel(true); + TopTools_ListOfShape GFAArguments; + for(auto &shape : shapes) { + if(shape.isNull()) + HANDLE_NULL_INPUT; + if (tol > 0.0) { + // workaround for http://dev.opencascade.org/index.php?q=node/1056#comment-520 + shape = shape.makECopy(); + } + GFAArguments.Append(shape.getShape()); + } + mkGFA.SetArguments(GFAArguments); + if (tol > 0.0) + mkGFA.SetFuzzyValue(tol); +#if OCC_VERSION_HEX >= 0x070000 + mkGFA.SetNonDestructive(Standard_True); +#endif + mkGFA.Build(); + if (!mkGFA.IsDone()) + FC_THROWM(Base::CADKernelError,"GeneralFuse failed"); + makEShape(mkGFA,shapes,op); + modifies.resize(shapes.size()); + int i=0; + for(auto &s : shapes) { + auto &mod = modifies[i++]; + for(TopTools_ListIteratorOfListOfShape it(mkGFA.Modified(s.getShape())); it.More(); it.Next()) { + TopoShape res(Tag); + res.setShape(it.Value()); + mod.push_back(res); + } + mapSubElementsTo(mod); + } + return *this; +#endif +} + +TopoShape &TopoShape::makEFuse(const std::vector &shapes, + const char *op, double tol) +{ + return makEBoolean(Part::OpCodes::Fuse,shapes,op,tol); +} + +TopoShape &TopoShape::makECut(const std::vector &shapes, + const char *op, double tol) +{ + return makEBoolean(Part::OpCodes::Cut,shapes,op,tol); +} + + TopoShape& TopoShape::makeElementShape(BRepBuilderAPI_MakeShape& mkShape, const TopoShape& source, const char* op)