]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Small refactoring: separate storing a compound of sub-results.
authorazv <azv@opencascade.com>
Mon, 13 May 2019 13:24:58 +0000 (16:24 +0300)
committerazv <azv@opencascade.com>
Mon, 13 May 2019 13:24:58 +0000 (16:24 +0300)
src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp
src/FeaturesPlugin/FeaturesPlugin_Boolean.h
src/FeaturesPlugin/FeaturesPlugin_BooleanCommon.cpp
src/FeaturesPlugin/FeaturesPlugin_BooleanCut.cpp
src/FeaturesPlugin/FeaturesPlugin_BooleanFill.cpp

index 44612077c4e4a4a35119df1dc5c578fc399fb871..066bf02af3c038979b3b535fa332e8c266f9da08 100644 (file)
@@ -488,6 +488,42 @@ GeomShapePtr FeaturesPlugin_Boolean::keepUnusedSubsOfCompound(
   return aResultShape;
 }
 
+//=================================================================================================
+void FeaturesPlugin_Boolean::storeResult(
+    const ListOfShape& theObjects,
+    const ListOfShape& theTools,
+    const GeomShapePtr theResultShape,
+    int& theResultIndex,
+    std::shared_ptr<GeomAlgoAPI_MakeShapeList> theMakeShapeList,
+    std::vector<FeaturesPlugin_Tools::ResultBaseAlgo>& theResultBaseAlgoList)
+{
+  if (!theResultShape)
+    return;
+
+  std::shared_ptr<ModelAPI_ResultBody> aResultBody =
+      document()->createBody(data(), theResultIndex);
+
+  FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
+                                           theObjects,
+                                           theTools,
+                                           theMakeShapeList,
+                                           theResultShape);
+  setResult(aResultBody, theResultIndex++);
+
+  // merge algorithms
+  FeaturesPlugin_Tools::ResultBaseAlgo aRBA;
+  aRBA.resultBody = aResultBody;
+  aRBA.baseShape = theObjects.front();
+  for (std::vector<FeaturesPlugin_Tools::ResultBaseAlgo>::iterator
+       aRBAIt = theResultBaseAlgoList.begin();
+       aRBAIt != theResultBaseAlgoList.end(); ++aRBAIt) {
+    theMakeShapeList->appendAlgo(aRBAIt->makeShape);
+  }
+  aRBA.makeShape = theMakeShapeList;
+  theResultBaseAlgoList.clear();
+  theResultBaseAlgoList.push_back(aRBA);
+}
+
 //=================================================================================================
 int FeaturesPlugin_Boolean::version()
 {
index 6fe5a24d623432c64a60cba9d3a4fbc00b29c382..c18d2eb67fb8e78061bd0eb85eaa657aeb5ef28a 100644 (file)
@@ -223,6 +223,14 @@ protected:
       const ObjectHierarchy& theToolsHierarchy,
       std::shared_ptr<GeomAlgoAPI_MakeShapeList> theMakeShapeList);
 
+  /// Store result shape if it is not empty and increase results counter
+  void storeResult(const ListOfShape& theObjects,
+                   const ListOfShape& theTools,
+                   const GeomShapePtr theResultShape,
+                   int& theResultIndex,
+                   std::shared_ptr<GeomAlgoAPI_MakeShapeList> theMakeShapeList,
+                   std::vector<FeaturesPlugin_Tools::ResultBaseAlgo>& theResultBaseAlgoList);
+
   /// Return version of the feature
   int version();
 
index 9dd105a9d5e42a6c606b99d2db199194572f910e..9911d4283860bf99dc98e2fdf8d14e3baf51a18a 100644 (file)
@@ -188,33 +188,8 @@ void FeaturesPlugin_BooleanCommon::execute()
       }
     }
 
-    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
index cb87cb69a2626a41167884ddbea5a5162db9bee4..07ba068f7c88aab7e85f1e2ed5e172d6a4f53543 100644 (file)
@@ -118,33 +118,8 @@ void FeaturesPlugin_BooleanCut::execute()
     }
   }
 
-  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.
index 94630430f3a50a4ad73daea8aabe68b0958d63ec..08d50f6f66a654e449af1c1640596b7f2a9fce68 100644 (file)
@@ -120,33 +120,8 @@ void FeaturesPlugin_BooleanFill::execute()
     }
   }
 
-  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.