Salome HOME
Unit test for issue #2817: Cut on heterogeneous arguments failed
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_BooleanCut.cpp
index cb87cb69a2626a41167884ddbea5a5162db9bee4..e00e3e9ff251b0f3af56ead3f56e2241346c4fd4 100644 (file)
@@ -35,8 +35,6 @@
 #include <GeomAPI_ShapeExplorer.h>
 #include <GeomAPI_ShapeIterator.h>
 
-static const int THE_CUT_VERSION_1 = 20190506;
-
 //==================================================================================================
 FeaturesPlugin_BooleanCut::FeaturesPlugin_BooleanCut()
 : FeaturesPlugin_Boolean(FeaturesPlugin_Boolean::BOOL_CUT)
@@ -47,13 +45,13 @@ FeaturesPlugin_BooleanCut::FeaturesPlugin_BooleanCut()
 void FeaturesPlugin_BooleanCut::initAttributes()
 {
   FeaturesPlugin_Boolean::initAttributes();
-  initVersion(THE_CUT_VERSION_1);
+  initVersion(BOP_VERSION_9_4(), selectionList(OBJECT_LIST_ID()), selectionList(TOOL_LIST_ID()));
 }
 
 //==================================================================================================
 void FeaturesPlugin_BooleanCut::execute()
 {
-  ObjectHierarchy anObjects, aTools;
+  GeomAPI_ShapeHierarchy anObjects, aTools;
   ListOfShape aPlanes;
 
   // Getting objects and tools
@@ -63,15 +61,12 @@ void FeaturesPlugin_BooleanCut::execute()
 
   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;
   }
 
-  // version of CUT feature
-  int aCutVersion = version();
-
   std::vector<FeaturesPlugin_Tools::ResultBaseAlgo> aResultBaseAlgoList;
   ListOfShape aResultShapesList;
   std::string anError;
@@ -79,7 +74,7 @@ void FeaturesPlugin_BooleanCut::execute()
   std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
 
   GeomShapePtr aResultCompound;
-  if (aCutVersion == THE_CUT_VERSION_1) {
+  if (data()->version() == BOP_VERSION_9_4()) {
     // merge hierarchies of compounds containing objects and tools
     aResultCompound =
         keepUnusedSubsOfCompound(GeomShapePtr(), anObjects, aTools, aMakeShapeList);
@@ -87,71 +82,46 @@ void FeaturesPlugin_BooleanCut::execute()
 
   // 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(),
+                               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(),
+                                anObjects, aParent, aTools.objects(), ListOfShape(),
                                 aResultIndex, aResultBaseAlgoList, aResultShapesList,
                                 aResultCompound);
       }
     } else {
       // process object as is
       isOk = processObject(GeomAlgoAPI_Tools::BOOL_CUT,
-                           anObject, aTools.Objects(), aPlanes,
+                           anObject, aTools.objects(), aPlanes,
                            aResultIndex, aResultBaseAlgoList, aResultShapesList,
                            aResultCompound);
     }
   }
 
-  GeomAPI_ShapeIterator aShapeIt(aResultCompound);
-  if (aShapeIt.more()) {
-    std::shared_ptr<ModelAPI_ResultBody> aResultBody =
-        document()->createBody(data(), aResultIndex);
-
-    ListOfShape anObjectList = anObjects.Objects();
-    ListOfShape aToolsList = aTools.Objects();
-    FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
-                                             anObjectList,
-                                             aToolsList,
-                                             aMakeShapeList,
-                                             aResultCompound);
-    setResult(aResultBody, aResultIndex++);
-
-    // merge algorithms
-    FeaturesPlugin_Tools::ResultBaseAlgo aRBA;
-    aRBA.resultBody = aResultBody;
-    aRBA.baseShape = anObjectList.front();
-    for (std::vector<FeaturesPlugin_Tools::ResultBaseAlgo>::iterator
-         aRBAIt = aResultBaseAlgoList.begin();
-         aRBAIt != aResultBaseAlgoList.end(); ++aRBAIt) {
-      aMakeShapeList->appendAlgo(aRBAIt->makeShape);
-    }
-    aRBA.makeShape = aMakeShapeList;
-    aResultBaseAlgoList.clear();
-    aResultBaseAlgoList.push_back(aRBA);
-  }
+  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.
   if (!aResultCompound)
     aResultCompound = GeomAlgoAPI_CompoundBuilder::compound(aResultShapesList);
   FeaturesPlugin_Tools::loadDeletedShapes(aResultBaseAlgoList,
-                                          aTools.Objects(),
+                                          aTools.objects(),
                                           aResultCompound);
 
   // remove the rest results if there were produced in the previous pass