diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 02c6f6423..ee36eedc7 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -1510,6 +1510,42 @@ TopoDS_Compound TopoShape::slices(const Base::Vector3d& dir, const std::vector &sOthers, Standard_Real tolerance, std::vector* mapInOut) const +{ + if (this->_Shape.IsNull()) + Standard_Failure::Raise("Base shape is null"); +#if OCC_VERSION_HEX <= 0x060900 + throw Base::Exception("GFA is available only in OCC 6.9.0 and up."); +#else + BRepAlgoAPI_BuilderAlgo mkGFA; + TopTools_ListOfShape GFAArguments; + GFAArguments.Append(this->_Shape); + for (const TopoDS_Shape &it: sOthers) { + if (it.IsNull()) + throw Base::Exception("Tool shape is null"); + if (tolerance > 0.0) + // workaround for http://dev.opencascade.org/index.php?q=node/1056#comment-520 + GFAArguments.Append(BRepBuilderAPI_Copy(it).Shape()); + else + GFAArguments.Append(it); + } + mkGFA.SetArguments(GFAArguments); + if (tolerance > 0.0) + mkGFA.SetFuzzyValue(tolerance); + mkGFA.SetNonDestructive(Standard_True); + mkGFA.Build(); + if (!mkGFA.IsDone()) + throw Base::Exception("MultiFusion failed"); + TopoDS_Shape resShape = mkGFA.Shape(); + if (mapInOut){ + for(TopTools_ListIteratorOfListOfShape it(GFAArguments); it.More(); it.Next()){ + mapInOut->push_back(mkGFA.Modified(it.Value())); + } + } + return resShape; +#endif +} + TopoDS_Shape TopoShape::makePipe(const TopoDS_Shape& profile) const { if (this->_Shape.IsNull()) diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 74b3ad359..56b56fcb1 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -153,6 +153,28 @@ public: TopoDS_Shape section(TopoDS_Shape) const; std::list slice(const Base::Vector3d&, double) const; TopoDS_Compound slices(const Base::Vector3d&, const std::vector&) const; + /** + * @brief generalFuse: run general fuse algorithm between this and shapes + * supplied as sOthers + * + * @param sOthers (input): list of shapes to run the algorithm between + * (this is automatically added to the list) + * + * @param tolerance (input): fuzzy value (pass zero to disable fuzzyness + * and use shape tolerances only) + * + * @param mapInOut (output): pointer to list of lists, to write the info + * which shapes in result came from which argument shape. The length of + * list is equal to length of sOthers+1. First element is a list of shapes + * that came from shape of this, and the rest are those that come from + * shapes in sOthers. If the info is not needed, nullptr can be passed. + * + * @return compound of slices that can be combined to reproduce results of + * cut, fuse, common. The shapes share edges and faces where they touch. + * For example, if input shapes are two intersecting spheres, GFA returns + * three solids: two cuts and common. + */ + TopoDS_Shape generalFuse(const std::vector &sOthers, Standard_Real tolerance, std::vector* mapInOut = nullptr) const; //@} /** Sweeping */