Salome HOME
Change the paradigm of versioning of Boolean Operations on the Python API level.
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_BooleanCommon.cpp
index 8506bc005022065380d747a0d87702c92945d376..1afe60e8bf1c214270da3ba81fc7f26905463ca3 100644 (file)
 #include "FeaturesPlugin_BooleanCommon.h"
 
 #include <ModelAPI_ResultBody.h>
+#include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Session.h>
 #include <ModelAPI_Tools.h>
+#include <ModelAPI_Validator.h>
 
 #include <GeomAlgoAPI_Boolean.h>
 #include <GeomAlgoAPI_MakeShapeCustom.h>
@@ -35,7 +38,6 @@
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_Tools.h>
 
-
 //==================================================================================================
 FeaturesPlugin_BooleanCommon::FeaturesPlugin_BooleanCommon()
 : FeaturesPlugin_Boolean(FeaturesPlugin_Boolean::BOOL_COMMON)
@@ -49,12 +51,14 @@ void FeaturesPlugin_BooleanCommon::initAttributes()
 
   data()->addAttribute(OBJECT_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
   data()->addAttribute(TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
+
+  initVersion(THE_VERSION_1, selectionList(OBJECT_LIST_ID()), selectionList(TOOL_LIST_ID()));
 }
 
 //==================================================================================================
 void FeaturesPlugin_BooleanCommon::execute()
 {
-  ListOfShape aPlanes, anEdgesAndFaces;
+  ListOfShape aPlanes;
   ObjectHierarchy anObjects, aTools;
 
   bool isSimpleMode = false;
@@ -66,14 +70,14 @@ void FeaturesPlugin_BooleanCommon::execute()
   }
 
   // Getting objects.
-  if (!processAttribute(OBJECT_LIST_ID(), anObjects, aPlanes, anEdgesAndFaces))
+  if (!processAttribute(OBJECT_LIST_ID(), anObjects, aPlanes))
     return;
   // Planes are not supported as objects of COMMON operation
   aPlanes.clear();
 
   // Getting tools.
   if (!isSimpleMode &&
-      !processAttribute(TOOL_LIST_ID(), aTools, aPlanes, anEdgesAndFaces))
+      !processAttribute(TOOL_LIST_ID(), aTools, aPlanes))
     return;
 
   if (anObjects.IsEmpty() || (!isSimpleMode && aTools.IsEmpty() && aPlanes.empty())) {
@@ -82,7 +86,12 @@ void FeaturesPlugin_BooleanCommon::execute()
     return;
   }
 
+  // version of COMMON feature
+  int aCommonVersion = version();
+
   int aResultIndex = 0;
+  GeomShapePtr aResultCompound;
+
   std::string anError;
   std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
   std::vector<FeaturesPlugin_Tools::ResultBaseAlgo> aResultBaseAlgoList;
@@ -106,6 +115,12 @@ void FeaturesPlugin_BooleanCommon::execute()
       aMakeShapeList->appendAlgo(aCommonAlgo);
     }
 
+    if (aCommonVersion == THE_VERSION_1) {
+      // merge hierarchies of compounds containing objects and tools
+      // and append the result of the FUSE operation
+      aShape = keepUnusedSubsOfCompound(aShape, anObjects, aTools, aMakeShapeList);
+    }
+
     GeomAPI_ShapeIterator aShapeIt(aShape);
     if (aShapeIt.more() || aShape->shapeType() == GeomAPI_Shape::VERTEX) {
       std::shared_ptr<ModelAPI_ResultBody> aResultBody =
@@ -132,6 +147,12 @@ void FeaturesPlugin_BooleanCommon::execute()
       aResultShapesList.push_back(aShape);
     }
   } else {
+    if (aCommonVersion == THE_VERSION_1) {
+      // merge hierarchies of compounds containing objects and tools
+      aResultCompound =
+          keepUnusedSubsOfCompound(GeomShapePtr(), anObjects, aTools, aMakeShapeList);
+    }
+
     bool isOk = true;
     for (ObjectHierarchy::Iterator anObjectsIt = anObjects.Begin();
          anObjectsIt != anObjects.End() && isOk;
@@ -146,29 +167,36 @@ void FeaturesPlugin_BooleanCommon::execute()
           // Compound handling
           isOk = processCompound(GeomAlgoAPI_Tools::BOOL_COMMON,
                                  anObjects, aParent, aTools.Objects(),
-                                 aResultIndex, aResultBaseAlgoList, aResultShapesList);
+                                 aResultIndex, aResultBaseAlgoList, aResultShapesList,
+                                 aResultCompound);
         }
         else if (aShapeType == GeomAPI_Shape::COMPSOLID) {
           // Compsolid handling
           isOk = processCompsolid(GeomAlgoAPI_Tools::BOOL_COMMON,
                                   anObjects, aParent, aTools.Objects(), ListOfShape(),
-                                  aResultIndex, aResultBaseAlgoList, aResultShapesList);
+                                  aResultIndex, aResultBaseAlgoList, aResultShapesList,
+                                  aResultCompound);
         }
       } else {
         // process object as is
         isOk = processObject(GeomAlgoAPI_Tools::BOOL_COMMON,
                              anObject, aTools.Objects(), aPlanes,
-                             aResultIndex, aResultBaseAlgoList, aResultShapesList);
+                             aResultIndex, aResultBaseAlgoList, aResultShapesList,
+                             aResultCompound);
       }
     }
+
+    storeResult(anObjects.Objects(), aTools.Objects(), aResultCompound, aResultIndex,
+                aMakeShapeList, aResultBaseAlgoList);
   }
 
   // Store deleted shapes after all results has been proceeded. This is to avoid issue when in one
   // result shape has been deleted, but in another it was modified or stayed.
-  GeomShapePtr aResultShapesCompound = GeomAlgoAPI_CompoundBuilder::compound(aResultShapesList);
+  if (!aResultCompound)
+    aResultCompound = GeomAlgoAPI_CompoundBuilder::compound(aResultShapesList);
   FeaturesPlugin_Tools::loadDeletedShapes(aResultBaseAlgoList,
                                           aTools.Objects(),
-                                          aResultShapesCompound);
+                                          aResultCompound);
 
   // remove the rest results if there were produced in the previous pass
   removeResults(aResultIndex);