Salome HOME
Change the paradigm of versioning of Boolean Operations on the Python API level.
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_BooleanFuse.cpp
index 497d529e43ad221c3941eac83a2529ac3fce4750..e8c47bae5987183a12948851c5969286f22dfe0c 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Session.h>
 #include <GeomAlgoAPI_Boolean.h>
 #include <GeomAlgoAPI_MakeShapeList.h>
 #include <GeomAlgoAPI_PaveFiller.h>
+#include <GeomAlgoAPI_ShapeBuilder.h>
 #include <GeomAlgoAPI_ShapeTools.h>
 #include <GeomAlgoAPI_Tools.h>
 #include <GeomAlgoAPI_UnifySameDomain.h>
+
 #include <GeomAPI_ShapeExplorer.h>
+#include <GeomAPI_ShapeIterator.h>
 
 //==================================================================================================
 FeaturesPlugin_BooleanFuse::FeaturesPlugin_BooleanFuse()
@@ -55,6 +59,8 @@ void FeaturesPlugin_BooleanFuse::initAttributes()
 
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_LIST_ID());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TOOL_LIST_ID());
+
+  initVersion(THE_VERSION_1, selectionList(OBJECT_LIST_ID()), selectionList(TOOL_LIST_ID()));
 }
 
 //==================================================================================================
@@ -95,6 +101,9 @@ void FeaturesPlugin_BooleanFuse::execute()
     return;
   }
 
+  // version of FUSE feature
+  int aFuseVersion = version();
+
   // Collecting all solids which will be fused.
   ListOfShape aSolidsToFuse;
   aSolidsToFuse.insert(aSolidsToFuse.end(), anObjects.begin(), anObjects.end());
@@ -102,9 +111,10 @@ void FeaturesPlugin_BooleanFuse::execute()
 
   // Collecting solids from compsolids which will not be modified
   // in boolean operation and will be added to result.
+  bool isProcessCompsolid = !isSimpleCreation || aFuseVersion >= THE_FUSE_VERSION_1;
   ListOfShape aShapesToAdd;
   for (ObjectHierarchy::Iterator anObjectsIt = anObjectsHierarchy.Begin();
-       !isSimpleCreation && anObjectsIt != anObjectsHierarchy.End();
+       isProcessCompsolid && anObjectsIt != anObjectsHierarchy.End();
        ++anObjectsIt) {
     GeomShapePtr anObject = *anObjectsIt;
     GeomShapePtr aParent = anObjectsHierarchy.Parent(anObject, false);
@@ -133,8 +143,11 @@ void FeaturesPlugin_BooleanFuse::execute()
       aMakeShapeList->appendAlgo(aCutAlgo);
     }
   }
-  anOriginalShapes.insert(anOriginalShapes.end(), anEdgesAndFaces.begin(),
-                          anEdgesAndFaces.end());
+
+  if (aShapesToAdd.empty() || !aCuttedEdgesAndFaces) {
+    anOriginalShapes.insert(anOriginalShapes.end(), anEdgesAndFaces.begin(),
+                            anEdgesAndFaces.end());
+  }
 
   // If we have compsolids then cut with not used solids all others.
   if (!aShapesToAdd.empty()) {
@@ -221,6 +234,12 @@ void FeaturesPlugin_BooleanFuse::execute()
     aMakeShapeList->appendAlgo(aUnifyAlgo);
   }
 
+  if (aFuseVersion == THE_VERSION_1) {
+    // merge hierarchies of compounds containing objects and tools
+    // and append the result of the FUSE operation
+    aShape = keepUnusedSubsOfCompound(aShape, anObjectsHierarchy, aToolsHierarchy, aMakeShapeList);
+  }
+
   int aResultIndex = 0;
 
   ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);