Merge pull request #12517 from bgbsww/bgbsww-toponamingMakeElementGeneralFuse

Toponaming/Part:  make element generalfuse, fuse, cut
This commit is contained in:
Chris Hennes
2024-02-21 08:25:12 -06:00
committed by GitHub
3 changed files with 284 additions and 24 deletions

View File

@@ -745,7 +745,7 @@ public:
/** Refine the input shape by merging faces/edges that share the same geometry
*
* @param source: input shape
* @param shape: input shape
* @param op: optional string to be encoded into topo naming for indicating
* the operation
* @param no_fail: if throwException, throw exception if failed to refine. Or else,
@@ -756,7 +756,7 @@ public:
* itself as a self reference so that multiple operations can be
* carried out for the same shape in the same line of code.
*/
TopoShape& makeElementRefine(const TopoShape& source,
TopoShape& makeElementRefine(const TopoShape& shape,
const char* op = nullptr,
RefineFail no_fail = RefineFail::throwException);
@@ -865,6 +865,83 @@ 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& makeElementGeneralFuse(const std::vector<TopoShape>& sources,
std::vector<std::vector<TopoShape>>& 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& makeElementFuse(const std::vector<TopoShape>& 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
makeElementFuse(const TopoShape& source, const char* op = nullptr, double tol = 0) const
{
return TopoShape(0, Hasher).makeElementFuse({*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&
makeElementCut(const std::vector<TopoShape>& 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
makeElementCut(const TopoShape& source, const char* op = nullptr, double tol = 0) const
{
return TopoShape(0, Hasher).makeElementCut({*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 +1392,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<TopoShape>& shapes,
const char* op = nullptr,
const char* maker = nullptr,

View File

@@ -1220,7 +1220,7 @@ TopoShape& TopoShape::makeShapeWithElementMap(const TopoDS_Shape& shape,
}
int newShapeIndex = newInfo.find(newShape);
if (newShapeIndex == 0) {
// This warning occurs in makERevolve. It generates
// This warning occurs in makeElementRevolve. It generates
// some shape from a vertex that never made into the
// final shape. There may be incomingShape cases there.
if (FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_LOG)) {
@@ -2459,11 +2459,7 @@ TopoShape::makeElementCopy(const TopoShape& shape, const char* op, bool copyGeom
}
TopoShape tmp(shape);
#if OCC_VERSION_HEX >= 0x070000
tmp.setShape(BRepBuilderAPI_Copy(shape.getShape(), copyGeom, copyMesh).Shape(), false);
#else
tmp.setShape(BRepBuilderAPI_Copy(shape.getShape()).Shape(), false);
#endif
if (op || (shape.Tag && shape.Tag != Tag)) {
setShape(tmp._Shape);
initCache();
@@ -2544,6 +2540,74 @@ struct MapperThruSections: MapperMaker
}
};
TopoShape& TopoShape::makeElementGeneralFuse(const std::vector<TopoShape>& _shapes,
std::vector<std::vector<TopoShape>>& modifies,
double tol,
const char* op)
{
if (!op) {
op = Part::OpCodes::GeneralFuse;
}
if (_shapes.empty()) {
FC_THROWM(NullShapeException, "Null input shape");
}
std::vector<TopoShape> shapes(_shapes);
BRepAlgoAPI_BuilderAlgo mkGFA;
mkGFA.SetRunParallel(true);
TopTools_ListOfShape GFAArguments;
for (auto& shape : shapes) {
if (shape.isNull()) {
FC_THROWM(NullShapeException, "Null input shape");
}
if (tol > 0.0) {
// workaround for http://dev.opencascade.org/index.php?q=node/1056#comment-520
shape = shape.makeElementCopy();
}
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");
}
makeElementShape(mkGFA, shapes, op);
modifies.resize(shapes.size());
int index = 0;
for (auto& shape : shapes) {
auto& mod = modifies[index++];
for (TopTools_ListIteratorOfListOfShape it(mkGFA.Modified(shape.getShape())); it.More();
it.Next()) {
TopoShape res(Tag);
res.setShape(it.Value());
mod.push_back(res);
}
mapSubElementsTo(mod);
}
return *this;
}
TopoShape&
TopoShape::makeElementFuse(const std::vector<TopoShape>& shapes, const char* op, double tol)
{
return makeElementBoolean(Part::OpCodes::Fuse, shapes, op, tol);
}
TopoShape&
TopoShape::makeElementCut(const std::vector<TopoShape>& shapes, const char* op, double tol)
{
return makeElementBoolean(Part::OpCodes::Cut, shapes, op, tol);
}
TopoShape& TopoShape::makeElementShape(BRepBuilderAPI_MakeShape& mkShape,
const TopoShape& source,
const char* op)
@@ -2734,7 +2798,7 @@ TopoShape& TopoShape::makeElementFace(const std::vector<TopoShape>& shapes,
// Update: one of the cause is related to OCC bug in
// BRepBuilder_FindPlane, A possible call sequence is,
//
// makEOffset2D() -> TopoShape::findPlane() -> BRepLib_FindSurface
// makeElementOffset2D() -> TopoShape::findPlane() -> BRepLib_FindSurface
//
// See code comments in findPlane() for the description of the bug and
// work around.