Salome HOME
Fix SIGSEGV on model.checkPythonDump() in GUI
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_BooleanCut.cpp
index e6ba621a43b6989a76370b3108d104f7160e4f29..3095f40fdfde59cca6ea5b8cee03bc3fc96b00a8 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2022  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -19,8 +19,6 @@
 
 #include "FeaturesPlugin_BooleanCut.h"
 
-#include "FeaturesPlugin_Tools.h"
-
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Tools.h>
@@ -41,65 +39,88 @@ FeaturesPlugin_BooleanCut::FeaturesPlugin_BooleanCut()
 {
 }
 
+//==================================================================================================
+void FeaturesPlugin_BooleanCut::initAttributes()
+{
+  FeaturesPlugin_Boolean::initAttributes();
+  initVersion(BOP_VERSION_9_4(), selectionList(OBJECT_LIST_ID()), selectionList(TOOL_LIST_ID()));
+}
+
 //==================================================================================================
 void FeaturesPlugin_BooleanCut::execute()
 {
-  ObjectHierarchy anObjects, aTools;
-  ListOfShape aPlanes, anEdgesAndFaces;
+  GeomAPI_ShapeHierarchy anObjects, aTools;
+  ListOfShape aPlanes;
 
   // Getting objects and tools
-  if (!processAttribute(OBJECT_LIST_ID(), anObjects, aPlanes, anEdgesAndFaces) ||
-      !processAttribute(TOOL_LIST_ID(), aTools, aPlanes, anEdgesAndFaces))
+  if (!processAttribute(OBJECT_LIST_ID(), anObjects, aPlanes) ||
+      !processAttribute(TOOL_LIST_ID(), aTools, aPlanes))
     return;
 
   int aResultIndex = 0;
 
-  if(anObjects.IsEmpty() || aTools.IsEmpty()) {
+  if(anObjects.empty() || aTools.empty()) {
     std::string aFeatureError = "Error: Not enough objects for boolean operation.";
     setError(aFeatureError);
     return;
   }
 
-  std::vector<FeaturesPlugin_Tools::ResultBaseAlgo> aResultBaseAlgoList;
+  std::vector<ModelAPI_Tools::ResultBaseAlgo> aResultBaseAlgoList;
   ListOfShape aResultShapesList;
   std::string anError;
 
+  std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
+
+  GeomShapePtr aResultCompound;
+  if (data()->version() == BOP_VERSION_9_4()) {
+    // merge hierarchies of compounds containing objects and tools
+    aResultCompound =
+        keepUnusedSubsOfCompound(GeomShapePtr(), anObjects, aTools, aMakeShapeList);
+  }
+
   // For solids cut each object with all tools.
   bool isOk = true;
-  for (ObjectHierarchy::Iterator anObjectsIt = anObjects.Begin();
-       anObjectsIt != anObjects.End() && isOk;
+  for (GeomAPI_ShapeHierarchy::iterator anObjectsIt = anObjects.begin();
+       anObjectsIt != anObjects.end() && isOk;
        ++anObjectsIt) {
     GeomShapePtr anObject = *anObjectsIt;
-    GeomShapePtr aParent = anObjects.Parent(anObject);
+    GeomShapePtr aParent = anObjects.parent(anObject);
 
     if (aParent) {
       GeomAPI_Shape::ShapeType aShapeType = aParent->shapeType();
       if (aShapeType == GeomAPI_Shape::COMPOUND) {
         // Compound handling
         isOk = processCompound(GeomAlgoAPI_Tools::BOOL_CUT,
-                               anObjects, aParent, aTools.Objects(),
-                               aResultIndex, aResultBaseAlgoList, aResultShapesList);
+                               anObjects, aParent, aTools.objects(),
+                               aResultIndex, aResultBaseAlgoList, aResultShapesList,
+                               aResultCompound);
       }
       else if (aShapeType == GeomAPI_Shape::COMPSOLID) {
         // Compsolid handling
         isOk = processCompsolid(GeomAlgoAPI_Tools::BOOL_CUT,
-                                anObjects, aParent, aTools.Objects(), ListOfShape(),
-                                aResultIndex, aResultBaseAlgoList, aResultShapesList);
+                                anObjects, aParent, aTools.objects(), ListOfShape(),
+                                aResultIndex, aResultBaseAlgoList, aResultShapesList,
+                                aResultCompound);
       }
     } else {
       // process object as is
       isOk = processObject(GeomAlgoAPI_Tools::BOOL_CUT,
-                           anObject, aTools.Objects(), aPlanes,
-                           aResultIndex, aResultBaseAlgoList, aResultShapesList);
+                           anObject, aTools.objects(), aPlanes,
+                           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);
-  FeaturesPlugin_Tools::loadDeletedShapes(aResultBaseAlgoList,
-                                          aTools.Objects(),
-                                          aResultShapesCompound);
+  if (!aResultCompound)
+    aResultCompound = GeomAlgoAPI_CompoundBuilder::compound(aResultShapesList);
+  ModelAPI_Tools::loadDeletedShapes(aResultBaseAlgoList,
+                                          aTools.objects(),
+                                          aResultCompound);
 
   // remove the rest results if there were produced in the previous pass
   removeResults(aResultIndex);