Fix boolean operations (#17119)

* add BRepAlgoAPI wrapper files to CMakeList

* introduce wrapper for BRepAlgoAPI_BooleanOperation and derivatives, set sensible default Fuzzyness for boolean operations

* allow default fuzzyness to be set in settings - including off

* backwards compatibility with OCCT 7.3.3 - removed newer paramateres from wrapper

* added missing header

* reverted src/Mod/Part/App/OpenCascadeAll.h to original state

* implement some changes suggested by @wwmayer

* removed unneeded destructor definitions

* moved getDefaultFuzzyValue into its own helper class

* removed unneeded references to base class default constructor

* default to SetRunParallel(Standard_True) as suggested by @FlachyJoe

* fixed license header as requested

* Added new method to autocalculate fuzzyness to BooleanOperation base class and use it for those parts that do not call the obsolete constructor but also do not set precision

* implemented static variable solution as suggested by @wwmayer

* added helix for test case

* Refactoring FCRepAlgoAPI to FCBRepAlgoAPI

* Added Test Case (fuse cylinder with helix with different working and non-working Fuzzy values)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* increased default value of FuzzyBoolean and made tests more robust for compatibility with OCCT 7.3

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fixes for FREECAD_USE_PCH - allow testing of FREECAD_USE_PCH on linux with cmake switch (default OFF)

* removed surplus line - wasn't needed after all

* included precompiled as instructed

* set anti-corruption flag in boolean operations, ensures source shape is not damaged in OCCT 7.1 and higher

* fix #17085

* disable subtests that were too specific for now

* fixed all CLI tests - see comments in Pull Request https://github.com/FreeCAD/FreeCAD/pull/17119#issuecomment-2420772452

* Update src/Mod/PartDesign/PartDesignTests/TestTopologicalNamingProblem.py

suggested updated test by CalligaroV

Co-authored-by: Vincenzo Calligaro <vincenzo.calligaro@gmail.com>

* Update tests/src/Mod/Part/App/TopoShapeExpansion.cpp

suggested updated test by CalligaroV

Co-authored-by: Vincenzo Calligaro <vincenzo.calligaro@gmail.com>

* Update tests/src/Mod/Part/App/TopoShapeExpansion.cpp

suggested updated test by CalligaroV

Co-authored-by: Vincenzo Calligaro <vincenzo.calligaro@gmail.com>

* Update tests/src/Mod/Part/App/TopoShapeExpansion.cpp

suggested updated test by CalligaroV

Co-authored-by: Vincenzo Calligaro <vincenzo.calligaro@gmail.com>

* Update tests/src/Mod/Part/App/TopoShapeExpansion.cpp

suggested updated test by CalligaroV

Co-authored-by: Vincenzo Calligaro <vincenzo.calligaro@gmail.com>

* Update tests/src/Mod/Part/App/TopoShapeExpansion.cpp

suggested updated test by CalligaroV

Co-authored-by: Vincenzo Calligaro <vincenzo.calligaro@gmail.com>

* Update tests/src/Mod/Part/App/TopoShapeExpansion.cpp

suggested updated test by CalligaroV

Co-authored-by: Vincenzo Calligaro <vincenzo.calligaro@gmail.com>

* Update tests/src/Mod/Part/App/TopoShapeExpansion.cpp

suggested updated test by CalligaroV

Co-authored-by: Vincenzo Calligaro <vincenzo.calligaro@gmail.com>

* Update tests/src/Mod/Part/App/TopoShapeExpansion.cpp

suggested updated test by CalligaroV

Co-authored-by: Vincenzo Calligaro <vincenzo.calligaro@gmail.com>

* Update tests/src/Mod/Part/App/TopoShapeExpansion.cpp

suggested updated test by CalligaroV

Co-authored-by: Vincenzo Calligaro <vincenzo.calligaro@gmail.com>

* Update tests/src/Mod/Part/App/TopoShapeExpansion.cpp

suggested updated test by CalligaroV

Co-authored-by: Vincenzo Calligaro <vincenzo.calligaro@gmail.com>

* Update tests/src/Mod/Part/App/TopoShapeExpansion.cpp

suggested updated test by CalligaroV

Co-authored-by: Vincenzo Calligaro <vincenzo.calligaro@gmail.com>

* Update tests/src/Mod/Part/App/TopoShapeExpansion.cpp

suggested updated test by CalligaroV

Co-authored-by: Vincenzo Calligaro <vincenzo.calligaro@gmail.com>

* Update tests/src/Mod/Part/App/TopoShapeExpansion.cpp

suggested updated test by CalligaroV

Co-authored-by: Vincenzo Calligaro <vincenzo.calligaro@gmail.com>

* Update tests/src/Mod/Part/App/TopoShapeExpansion.cpp

Co-authored-by: Vincenzo Calligaro <vincenzo.calligaro@gmail.com>

* remove surplus tests from github suggestion interface bug

* hide the BooleanFuzzy variable - can now be only set by manually editing the config file
i
in FCParamGroup "Boolean"
<FCFloat Name="BooleanFuzzy" Value="10.000000000000"/>

* Suggestion by @FlachyJoe - add validity checks to the base and tool shape in any direct boolean op

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Vincenzo Calligaro <vincenzo.calligaro@gmail.com>
This commit is contained in:
Eric Price
2024-10-21 18:38:51 +02:00
committed by GitHub
parent 5979ebd6f8
commit cf8ad66373
58 changed files with 2098 additions and 189 deletions

View File

@@ -36,12 +36,12 @@
# include <BRep_Builder.hxx>
# include <BRep_Tool.hxx>
# include <BRepAdaptor_Surface.hxx>
# include <BRepAlgoAPI_Common.hxx>
# include <Mod/Part/App/FCBRepAlgoAPI_Common.h>
# include <BRepAdaptor_CompCurve.hxx>
# include <BRepAdaptor_Curve.hxx>
# include <BRepAlgoAPI_Cut.hxx>
# include <BRepAlgoAPI_Fuse.hxx>
# include <BRepAlgoAPI_Section.hxx>
# include <Mod/Part/App/FCBRepAlgoAPI_Cut.h>
# include <Mod/Part/App/FCBRepAlgoAPI_Fuse.h>
# include <Mod/Part/App/FCBRepAlgoAPI_Section.h>
# include <BRepBndLib.hxx>
# include <BRepBuilderAPI_Copy.hxx>
# include <BRepBuilderAPI_FaceError.hxx>
@@ -1698,7 +1698,7 @@ TopoDS_Shape TopoShape::cut(TopoDS_Shape shape) const
return this->_Shape;
if (shape.IsNull())
return this->_Shape;
BRepAlgoAPI_Cut mkCut(this->_Shape, shape);
FCBRepAlgoAPI_Cut mkCut(this->_Shape, shape);
return makeShell(mkCut.Shape());
}
@@ -1706,24 +1706,23 @@ TopoDS_Shape TopoShape::cut(const std::vector<TopoDS_Shape>& shapes, Standard_Re
{
if (this->_Shape.IsNull())
return this->_Shape;
BRepAlgoAPI_Cut mkCut;
FCBRepAlgoAPI_Cut mkCut;
mkCut.SetRunParallel(true);
TopTools_ListOfShape shapeArguments,shapeTools;
shapeArguments.Append(this->_Shape);
for (const auto & shape : shapes) {
if (shape.IsNull())
throw Base::ValueError("Tool shape is null");
if (tolerance > 0.0)
// workaround for http://dev.opencascade.org/index.php?q=node/1056#comment-520
shapeTools.Append(BRepBuilderAPI_Copy(shape).Shape());
else
shapeTools.Append(shape);
shapeTools.Append(shape);
}
mkCut.SetArguments(shapeArguments);
mkCut.SetTools(shapeTools);
if (tolerance > 0.0)
if (tolerance > 0.0) {
mkCut.SetFuzzyValue(tolerance);
} else if (tolerance < 0.0) {
mkCut.setAutoFuzzy();
}
mkCut.Build();
if (!mkCut.IsDone())
throw Base::RuntimeError("Multi cut failed");
@@ -1738,7 +1737,7 @@ TopoDS_Shape TopoShape::common(TopoDS_Shape shape) const
return this->_Shape;
if (shape.IsNull())
return shape;
BRepAlgoAPI_Common mkCommon(this->_Shape, shape);
FCBRepAlgoAPI_Common mkCommon(this->_Shape, shape);
return makeShell(mkCommon.Shape());
}
@@ -1746,24 +1745,23 @@ TopoDS_Shape TopoShape::common(const std::vector<TopoDS_Shape>& shapes, Standard
{
if (this->_Shape.IsNull())
return this->_Shape;
BRepAlgoAPI_Common mkCommon;
FCBRepAlgoAPI_Common mkCommon;
mkCommon.SetRunParallel(true);
TopTools_ListOfShape shapeArguments,shapeTools;
shapeArguments.Append(this->_Shape);
for (const auto & shape : shapes) {
if (shape.IsNull())
throw Base::ValueError("Tool shape is null");
if (tolerance > 0.0)
// workaround for http://dev.opencascade.org/index.php?q=node/1056#comment-520
shapeTools.Append(BRepBuilderAPI_Copy(shape).Shape());
else
shapeTools.Append(shape);
shapeTools.Append(shape);
}
mkCommon.SetArguments(shapeArguments);
mkCommon.SetTools(shapeTools);
if (tolerance > 0.0)
if (tolerance > 0.0) {
mkCommon.SetFuzzyValue(tolerance);
} else if (tolerance < 0.0) {
mkCommon.setAutoFuzzy();
}
mkCommon.Build();
if (!mkCommon.IsDone())
throw Base::RuntimeError("Multi common failed");
@@ -1778,7 +1776,7 @@ TopoDS_Shape TopoShape::fuse(TopoDS_Shape shape) const
return shape;
if (shape.IsNull())
return this->_Shape;
BRepAlgoAPI_Fuse mkFuse(this->_Shape, shape);
FCBRepAlgoAPI_Fuse mkFuse(this->_Shape, shape);
return makeShell(mkFuse.Shape());
}
@@ -1787,23 +1785,22 @@ TopoDS_Shape TopoShape::fuse(const std::vector<TopoDS_Shape>& shapes, Standard_R
if (this->_Shape.IsNull())
Standard_Failure::Raise("Base shape is null");
BRepAlgoAPI_Fuse mkFuse;
FCBRepAlgoAPI_Fuse mkFuse;
mkFuse.SetRunParallel(true);
TopTools_ListOfShape shapeArguments,shapeTools;
shapeArguments.Append(this->_Shape);
for (const auto & shape : shapes) {
if (shape.IsNull())
throw NullShapeException("Tool shape is null");
if (tolerance > 0.0)
// workaround for http://dev.opencascade.org/index.php?q=node/1056#comment-520
shapeTools.Append(BRepBuilderAPI_Copy(shape).Shape());
else
shapeTools.Append(shape);
shapeTools.Append(shape);
}
mkFuse.SetArguments(shapeArguments);
mkFuse.SetTools(shapeTools);
if (tolerance > 0.0)
if (tolerance > 0.0) {
mkFuse.SetFuzzyValue(tolerance);
} else if (tolerance < 0.0) {
mkFuse.setAutoFuzzy();
}
mkFuse.Build();
if (!mkFuse.IsDone())
throw Base::RuntimeError("Multi fuse failed");
@@ -1828,7 +1825,7 @@ TopoDS_Shape TopoShape::section(TopoDS_Shape shape, Standard_Boolean approximate
Standard_Failure::Raise("Base shape is null");
if (shape.IsNull())
Standard_Failure::Raise("Tool shape is null");
BRepAlgoAPI_Section mkSection;
FCBRepAlgoAPI_Section mkSection;
mkSection.Init1(this->_Shape);
mkSection.Init2(shape);
mkSection.Approximation(approximate);
@@ -1845,7 +1842,7 @@ TopoDS_Shape TopoShape::section(const std::vector<TopoDS_Shape>& shapes,
if (this->_Shape.IsNull())
Standard_Failure::Raise("Base shape is null");
BRepAlgoAPI_Section mkSection;
FCBRepAlgoAPI_Section mkSection;
mkSection.SetRunParallel(true);
mkSection.Approximation(approximate);
TopTools_ListOfShape shapeArguments,shapeTools;
@@ -1853,17 +1850,16 @@ TopoDS_Shape TopoShape::section(const std::vector<TopoDS_Shape>& shapes,
for (const auto & shape : shapes) {
if (shape.IsNull())
throw Base::ValueError("Tool shape is null");
if (tolerance > 0.0)
// workaround for http://dev.opencascade.org/index.php?q=node/1056#comment-520
shapeTools.Append(BRepBuilderAPI_Copy(shape).Shape());
else
shapeTools.Append(shape);
shapeTools.Append(shape);
}
mkSection.SetArguments(shapeArguments);
mkSection.SetTools(shapeTools);
if (tolerance > 0.0)
if (tolerance > 0.0) {
mkSection.SetFuzzyValue(tolerance);
} else if (tolerance < 0.0) {
mkSection.setAutoFuzzy();
}
mkSection.Build();
if (!mkSection.IsDone())
throw Base::RuntimeError("Multi section failed");
@@ -1915,15 +1911,14 @@ TopoDS_Shape TopoShape::generalFuse(const std::vector<TopoDS_Shape> &sOthers, St
for (const TopoDS_Shape &it: sOthers) {
if (it.IsNull())
throw NullShapeException("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)
if (tolerance > 0.0) {
mkGFA.SetFuzzyValue(tolerance);
} else if (tolerance < 0.0) {
FCBRepAlgoAPIHelper::setAutoFuzzy(&mkGFA);
}
mkGFA.SetNonDestructive(Standard_True);
mkGFA.Build();
if (!mkGFA.IsDone())