+ }
+
+ // 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()) {
+ StdFail_NotDone::Raise("Cut operation can not be performed on the given shapes");
+ }
+ aCut = BO.Shape();
+ }
+ if (isCompound) {
+ // check result of this step: if it is a compound (boolean operations
+ // allways return a compound), we add all sub-shapes of it.
+ // This allows to avoid adding empty compounds,
+ // resulting from CUT of parts
+ if (aCut.ShapeType() == TopAbs_COMPOUND) {
+ TopoDS_Iterator aCompIter (aCut);
+ for (; aCompIter.More(); aCompIter.Next()) {
+ // add shape in a result
+ B.Add(C, aCompIter.Value());
+ }
+ }
+ else {
+ // add shape in a result
+ B.Add(C, aCut);
+ }
+ }
+ else
+ aShape = aCut;
+ }
+
+ if (isCompound) {
+ /*
+ TopTools_ListOfShape listShapeC;
+ AddSimpleShapes(C, listShapeC);
+ TopTools_ListIteratorOfListOfShape itSubC (listShapeC);
+ bool isOnlySolids = true;
+ for (; itSubC.More(); itSubC.Next()) {
+ TopoDS_Shape aValueC = itSubC.Value();
+ if (aValueC.ShapeType() != TopAbs_SOLID) isOnlySolids = false;
+ }
+ if (isOnlySolids)
+ aShape = GEOMImpl_GlueDriver::GlueFaces(C, Precision::Confusion());
+ else
+ aShape = C;
+ */
+
+ // As GlueFaces has been improved to keep all kind of shapes
+ TopExp_Explorer anExp (C, TopAbs_VERTEX);
+ if (anExp.More())
+ aShape = GEOMImpl_GlueDriver::GlueFaces(C, Precision::Confusion(), Standard_True);
+ else
+ aShape = C;
+ }
+ }
+
+ // perform FUSE operation
+ else if (aType == BOOLEAN_FUSE) {
+ /* Fix for NPAL15379: refused
+ // Check arguments
+ TopTools_ListOfShape listShape1, listShape2;
+ AddSimpleShapes(aShape1, listShape1);
+ AddSimpleShapes(aShape2, listShape2);
+
+ Standard_Boolean isIntersect = Standard_False;
+
+ if (listShape1.Extent() > 1 && !isIntersect) {
+ // check intersections inside the first compound
+ TopTools_ListIteratorOfListOfShape it1 (listShape1);
+ for (; it1.More() && !isIntersect; it1.Next()) {
+ TopoDS_Shape aValue1 = it1.Value();
+ TopTools_ListIteratorOfListOfShape it2 (listShape1);
+ for (; it2.More() && !isIntersect; it2.Next()) {
+ TopoDS_Shape aValue2 = it2.Value();
+ if (aValue2 != aValue1) {
+ BRepAlgoAPI_Section BO (aValue1, aValue2);
+ if (BO.IsDone()) {
+ TopoDS_Shape aSect = BO.Shape();
+ TopExp_Explorer anExp (aSect, TopAbs_EDGE);
+ if (anExp.More()) {
+ isIntersect = Standard_True;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (listShape2.Extent() > 1 && !isIntersect) {
+ // check intersections inside the second compound
+ TopTools_ListIteratorOfListOfShape it1 (listShape2);
+ for (; it1.More() && !isIntersect; it1.Next()) {
+ TopoDS_Shape aValue1 = it1.Value();
+ TopTools_ListIteratorOfListOfShape it2 (listShape2);
+ for (; it2.More() && !isIntersect; it2.Next()) {
+ TopoDS_Shape aValue2 = it2.Value();
+ if (aValue2 != aValue1) {
+ BRepAlgoAPI_Section BO (aValue1, aValue2);
+ if (BO.IsDone()) {
+ TopoDS_Shape aSect = BO.Shape();
+ TopExp_Explorer anExp (aSect, TopAbs_EDGE);
+ if (anExp.More()) {
+ isIntersect = Standard_True;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (isIntersect) {
+ // have intersections inside compounds
+ // check intersections between compounds
+ TopTools_ListIteratorOfListOfShape it1 (listShape1);
+ for (; it1.More(); it1.Next()) {
+ TopoDS_Shape aValue1 = it1.Value();
+ TopTools_ListIteratorOfListOfShape it2 (listShape2);
+ for (; it2.More(); it2.Next()) {
+ TopoDS_Shape aValue2 = it2.Value();
+ if (aValue2 != aValue1) {
+ BRepAlgoAPI_Section BO (aValue1, aValue2);
+ if (BO.IsDone()) {
+ TopoDS_Shape aSect = BO.Shape();
+ TopExp_Explorer anExp (aSect, TopAbs_EDGE);
+ if (anExp.More()) {
+ StdFail_NotDone::Raise("Bad argument for Fuse: compound with intersecting sub-shapes");
+ }
+ }
+ }
+ }
+ }
+ }
+ */
+
+ // Perform