mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-01-01 04:10:34 +05:00
PAL12470: Cannot use boolean operations on COMPOUNDs and COMPSOLIDs. Workaround OCCT limitation, performing boolean operations on sub-shapes and then gathering results in a compound.
This commit is contained in:
parent
cff8a10b8f
commit
6dba78d6b9
@ -18,19 +18,25 @@
|
|||||||
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <Standard_Stream.hxx>
|
|
||||||
|
|
||||||
#include <GEOMImpl_BooleanDriver.hxx>
|
#include <GEOMImpl_BooleanDriver.hxx>
|
||||||
#include <GEOMImpl_IBoolean.hxx>
|
#include <GEOMImpl_IBoolean.hxx>
|
||||||
#include <GEOMImpl_Types.hxx>
|
#include <GEOMImpl_Types.hxx>
|
||||||
|
#include <GEOMImpl_GlueDriver.hxx>
|
||||||
#include <GEOM_Function.hxx>
|
#include <GEOM_Function.hxx>
|
||||||
|
|
||||||
|
#include <BRep_Builder.hxx>
|
||||||
#include <BRepAlgo.hxx>
|
#include <BRepAlgo.hxx>
|
||||||
#include <BRepAlgoAPI_Common.hxx>
|
#include <BRepAlgoAPI_Common.hxx>
|
||||||
#include <BRepAlgoAPI_Cut.hxx>
|
#include <BRepAlgoAPI_Cut.hxx>
|
||||||
#include <BRepAlgoAPI_Fuse.hxx>
|
#include <BRepAlgoAPI_Fuse.hxx>
|
||||||
#include <BRepAlgoAPI_Section.hxx>
|
#include <BRepAlgoAPI_Section.hxx>
|
||||||
#include <TopoDS_Shape.hxx>
|
#include <TopoDS_Shape.hxx>
|
||||||
|
#include <TopoDS_Compound.hxx>
|
||||||
|
#include <TopoDS_Iterator.hxx>
|
||||||
|
#include <TopTools_MapOfShape.hxx>
|
||||||
|
#include <TopTools_ListOfShape.hxx>
|
||||||
|
#include <TopTools_ListIteratorOfListOfShape.hxx>
|
||||||
|
#include <Precision.hxx>
|
||||||
|
|
||||||
#include <Standard_ConstructionError.hxx>
|
#include <Standard_ConstructionError.hxx>
|
||||||
#include <StdFail_NotDone.hxx>
|
#include <StdFail_NotDone.hxx>
|
||||||
@ -54,6 +60,30 @@ GEOMImpl_BooleanDriver::GEOMImpl_BooleanDriver()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddSimpleShapes(TopoDS_Shape theShape, TopTools_ListOfShape& theList)
|
||||||
|
{
|
||||||
|
if (theShape.ShapeType() != TopAbs_COMPOUND &&
|
||||||
|
theShape.ShapeType() != TopAbs_COMPSOLID) {
|
||||||
|
theList.Append(theShape);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TopTools_MapOfShape mapShape;
|
||||||
|
TopoDS_Iterator It (theShape, Standard_True, Standard_True);
|
||||||
|
|
||||||
|
for (; It.More(); It.Next()) {
|
||||||
|
TopoDS_Shape aShape_i = It.Value();
|
||||||
|
if (mapShape.Add(aShape_i)) {
|
||||||
|
if (aShape_i.ShapeType() == TopAbs_COMPOUND ||
|
||||||
|
aShape_i.ShapeType() == TopAbs_COMPSOLID) {
|
||||||
|
AddSimpleShapes(aShape_i, theList);
|
||||||
|
} else {
|
||||||
|
theList.Append(aShape_i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
//function : Execute
|
//function : Execute
|
||||||
//purpose :
|
//purpose :
|
||||||
@ -73,38 +103,137 @@ Standard_Integer GEOMImpl_BooleanDriver::Execute(TFunction_Logbook& log) const
|
|||||||
TopoDS_Shape aShape1 = aRefShape1->GetValue();
|
TopoDS_Shape aShape1 = aRefShape1->GetValue();
|
||||||
TopoDS_Shape aShape2 = aRefShape2->GetValue();
|
TopoDS_Shape aShape2 = aRefShape2->GetValue();
|
||||||
if (!aShape1.IsNull() && !aShape2.IsNull()) {
|
if (!aShape1.IsNull() && !aShape2.IsNull()) {
|
||||||
|
|
||||||
|
// perform COMMON operation
|
||||||
if (aType == BOOLEAN_COMMON) {
|
if (aType == BOOLEAN_COMMON) {
|
||||||
BRepAlgoAPI_Common BO (aShape1, aShape2);
|
BRep_Builder B;
|
||||||
// BO.Build();
|
TopoDS_Compound C;
|
||||||
|
B.MakeCompound(C);
|
||||||
|
|
||||||
|
TopTools_ListOfShape listShape1, listShape2;
|
||||||
|
AddSimpleShapes(aShape1, listShape1);
|
||||||
|
AddSimpleShapes(aShape2, listShape2);
|
||||||
|
|
||||||
|
Standard_Boolean isCompound =
|
||||||
|
(listShape1.Extent() > 1 || listShape2.Extent() > 1);
|
||||||
|
|
||||||
|
TopTools_ListIteratorOfListOfShape itSub1 (listShape1);
|
||||||
|
for (; itSub1.More(); itSub1.Next()) {
|
||||||
|
TopoDS_Shape aValue1 = itSub1.Value();
|
||||||
|
TopTools_ListIteratorOfListOfShape itSub2 (listShape2);
|
||||||
|
for (; itSub2.More(); itSub2.Next()) {
|
||||||
|
TopoDS_Shape aValue2 = itSub2.Value();
|
||||||
|
BRepAlgoAPI_Common BO (aValue1, aValue2);
|
||||||
if (!BO.IsDone()) {
|
if (!BO.IsDone()) {
|
||||||
StdFail_NotDone::Raise("Requested boolean operation can not be performed on the given shapes");
|
StdFail_NotDone::Raise("Common operation can not be performed on the given shapes");
|
||||||
}
|
}
|
||||||
|
if (isCompound)
|
||||||
|
B.Add(C, BO.Shape());
|
||||||
|
else
|
||||||
aShape = BO.Shape();
|
aShape = BO.Shape();
|
||||||
} else if (aType == BOOLEAN_CUT) {
|
}
|
||||||
BRepAlgoAPI_Cut BO (aShape1, aShape2);
|
}
|
||||||
|
|
||||||
|
if (isCompound)
|
||||||
|
aShape = GEOMImpl_GlueDriver::GlueFaces(C, Precision::Confusion());
|
||||||
|
}
|
||||||
|
|
||||||
|
// perform CUT operation
|
||||||
|
else if (aType == BOOLEAN_CUT) {
|
||||||
|
BRep_Builder B;
|
||||||
|
TopoDS_Compound C;
|
||||||
|
B.MakeCompound(C);
|
||||||
|
|
||||||
|
TopTools_ListOfShape listShapes, listTools;
|
||||||
|
AddSimpleShapes(aShape1, listShapes);
|
||||||
|
AddSimpleShapes(aShape2, listTools);
|
||||||
|
|
||||||
|
Standard_Boolean isCompound = (listShapes.Extent() > 1);
|
||||||
|
|
||||||
|
TopTools_ListIteratorOfListOfShape itSub1 (listShapes);
|
||||||
|
for (; itSub1.More(); itSub1.Next()) {
|
||||||
|
TopoDS_Shape aCut = itSub1.Value();
|
||||||
|
// tools
|
||||||
|
TopTools_ListIteratorOfListOfShape itSub2 (listTools);
|
||||||
|
for (; itSub2.More(); itSub2.Next()) {
|
||||||
|
TopoDS_Shape aTool = itSub2.Value();
|
||||||
|
BRepAlgoAPI_Cut BO (aCut, aTool);
|
||||||
if (!BO.IsDone()) {
|
if (!BO.IsDone()) {
|
||||||
StdFail_NotDone::Raise("Requested boolean operation can not be performed on the given shapes");
|
StdFail_NotDone::Raise("Cut operation can not be performed on the given shapes");
|
||||||
}
|
}
|
||||||
aShape = BO.Shape();
|
aCut = BO.Shape();
|
||||||
} else if (aType == BOOLEAN_FUSE) {
|
}
|
||||||
|
if (isCompound)
|
||||||
|
B.Add(C, aCut);
|
||||||
|
else
|
||||||
|
aShape = aCut;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isCompound)
|
||||||
|
aShape = GEOMImpl_GlueDriver::GlueFaces(C, Precision::Confusion());
|
||||||
|
}
|
||||||
|
|
||||||
|
// perform FUSE operation
|
||||||
|
else if (aType == BOOLEAN_FUSE) {
|
||||||
|
// check shapes to provide special processing for compounds and compsolids
|
||||||
|
if (aShape1.ShapeType() == TopAbs_COMPOUND ||
|
||||||
|
aShape1.ShapeType() == TopAbs_COMPSOLID ||
|
||||||
|
aShape2.ShapeType() == TopAbs_COMPOUND ||
|
||||||
|
aShape2.ShapeType() == TopAbs_COMPSOLID) {
|
||||||
|
// at least one of arguments is complex
|
||||||
|
StdFail_NotDone::Raise("Fuse operation aborted: one of arguments is a complex shape");
|
||||||
|
} else {
|
||||||
|
// simple arguments
|
||||||
BRepAlgoAPI_Fuse BO (aShape1, aShape2);
|
BRepAlgoAPI_Fuse BO (aShape1, aShape2);
|
||||||
if (!BO.IsDone()) {
|
if (!BO.IsDone()) {
|
||||||
StdFail_NotDone::Raise("Requested boolean operation can not be performed on the given shapes");
|
StdFail_NotDone::Raise("Fuse operation can not be performed on the given shapes");
|
||||||
}
|
}
|
||||||
aShape = BO.Shape();
|
aShape = BO.Shape();
|
||||||
} else if (aType == BOOLEAN_SECTION) {
|
}
|
||||||
BRepAlgoAPI_Section BO (aShape1, aShape2);
|
}
|
||||||
|
|
||||||
|
// perform SECTION operation
|
||||||
|
else if (aType == BOOLEAN_SECTION) {
|
||||||
|
BRep_Builder B;
|
||||||
|
TopoDS_Compound C;
|
||||||
|
B.MakeCompound(C);
|
||||||
|
|
||||||
|
TopTools_ListOfShape listShape1, listShape2;
|
||||||
|
AddSimpleShapes(aShape1, listShape1);
|
||||||
|
AddSimpleShapes(aShape2, listShape2);
|
||||||
|
|
||||||
|
Standard_Boolean isCompound =
|
||||||
|
(listShape1.Extent() > 1 || listShape2.Extent() > 1);
|
||||||
|
|
||||||
|
TopTools_ListIteratorOfListOfShape itSub1 (listShape1);
|
||||||
|
for (; itSub1.More(); itSub1.Next()) {
|
||||||
|
TopoDS_Shape aValue1 = itSub1.Value();
|
||||||
|
TopTools_ListIteratorOfListOfShape itSub2 (listShape2);
|
||||||
|
for (; itSub2.More(); itSub2.Next()) {
|
||||||
|
TopoDS_Shape aValue2 = itSub2.Value();
|
||||||
|
BRepAlgoAPI_Section BO (aValue1, aValue2);
|
||||||
if (!BO.IsDone()) {
|
if (!BO.IsDone()) {
|
||||||
StdFail_NotDone::Raise("Requested boolean operation can not be performed on the given shapes");
|
StdFail_NotDone::Raise("Section operation can not be performed on the given shapes");
|
||||||
}
|
}
|
||||||
|
if (isCompound)
|
||||||
|
B.Add(C, BO.Shape());
|
||||||
|
else
|
||||||
aShape = BO.Shape();
|
aShape = BO.Shape();
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isCompound)
|
||||||
|
aShape = C;
|
||||||
|
}
|
||||||
|
|
||||||
|
// UNKNOWN operation
|
||||||
|
else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aShape.IsNull()) return 0;
|
if (aShape.IsNull()) return 0;
|
||||||
if (!BRepAlgo::IsValid(aShape)) {
|
if (!BRepAlgo::IsValid(aShape)) {
|
||||||
Standard_ConstructionError::Raise("Boolean aborted : non valid shape result");
|
Standard_ConstructionError::Raise("Boolean operation aborted : non valid shape result");
|
||||||
}
|
}
|
||||||
|
|
||||||
aFunction->SetValue(aShape);
|
aFunction->SetValue(aShape);
|
||||||
|
Loading…
Reference in New Issue
Block a user