Salome HOME
Make extrusions features correctly eat as a base a whole sketch feature selection.
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Boolean.cpp
index 64072e62accc7b53a9543440a8e4cbe5483051db..99afc6e8dbf6d78c1c37838d639f26fad7caf9f4 100644 (file)
@@ -24,7 +24,6 @@
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeInteger.h>
-#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Session.h>
 #include <map>
 
 //=================================================================================================
-FeaturesPlugin_Boolean::FeaturesPlugin_Boolean()
+FeaturesPlugin_Boolean::FeaturesPlugin_Boolean(const OperationType theOperationType)
+: myOperationType(theOperationType)
 {
 }
 
 //=================================================================================================
 void FeaturesPlugin_Boolean::initAttributes()
 {
-  data()->addAttribute(FeaturesPlugin_Boolean::TYPE_ID(), ModelAPI_AttributeInteger::typeId());
-
   AttributeSelectionListPtr aSelection =
     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
     FeaturesPlugin_Boolean::OBJECT_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
@@ -80,15 +78,14 @@ std::shared_ptr<GeomAPI_Shape> FeaturesPlugin_Boolean::getShape(const std::strin
 }
 
 //=================================================================================================
-void FeaturesPlugin_Boolean::execute()
+FeaturesPlugin_Boolean::OperationType FeaturesPlugin_Boolean::operationType()
 {
-  // Getting operation type.
-  std::shared_ptr<ModelAPI_AttributeInteger> aTypeAttr = std::dynamic_pointer_cast<
-      ModelAPI_AttributeInteger>(data()->attribute(FeaturesPlugin_Boolean::TYPE_ID()));
-  if (!aTypeAttr)
-    return;
-  OperationType aType = (FeaturesPlugin_Boolean::OperationType)aTypeAttr->value();
+  return myOperationType;
+}
 
+//=================================================================================================
+void FeaturesPlugin_Boolean::execute()
+{
   ListOfShape anObjects, aTools, anEdgesAndFaces, aPlanes;
   std::map<std::shared_ptr<GeomAPI_Shape>, ListOfShape> aCompSolidsObjects;
 
@@ -102,7 +99,7 @@ void FeaturesPlugin_Boolean::execute()
       return;
     }
     ResultPtr aContext = anObjectAttr->context();
-    ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
+    ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
     if(aResCompSolidPtr.get()
         && aResCompSolidPtr->shape()->shapeType() == GeomAPI_Shape::COMPSOLID) {
       std::shared_ptr<GeomAPI_Shape> aContextShape = aResCompSolidPtr->shape();
@@ -118,7 +115,7 @@ void FeaturesPlugin_Boolean::execute()
         aCompSolidsObjects[aContextShape].push_back(anObject);
       }
     } else {
-      if(aType != BOOL_FILL
+      if(myOperationType != BOOL_FILL
         && (anObject->shapeType() == GeomAPI_Shape::EDGE
           || anObject->shapeType() == GeomAPI_Shape::FACE))
       {
@@ -141,7 +138,7 @@ void FeaturesPlugin_Boolean::execute()
       ResultPtr aContext = aToolAttr->context();
       aPlanes.push_back(aToolAttr->context()->shape());
     }
-    else if(aType != BOOL_FILL
+    else if (myOperationType != BOOL_FILL
       && (aTool->shapeType() == GeomAPI_Shape::EDGE
         || aTool->shapeType() == GeomAPI_Shape::FACE))
     {
@@ -153,7 +150,7 @@ void FeaturesPlugin_Boolean::execute()
 
   int aResultIndex = 0;
 
-  switch(aType) {
+  switch(myOperationType) {
     case BOOL_CUT:
     case BOOL_COMMON:
     case BOOL_FILL: {
@@ -174,7 +171,7 @@ void FeaturesPlugin_Boolean::execute()
         std::shared_ptr<GeomAlgoAPI_MakeShape> aBoolAlgo;
         GeomShapePtr aResShape;
 
-        switch(aType) {
+        switch(myOperationType) {
           case BOOL_CUT: {
             aBoolAlgo.reset(new GeomAlgoAPI_Boolean(aListWithObject,
                                                     aTools,
@@ -210,7 +207,7 @@ void FeaturesPlugin_Boolean::execute()
 
             aBoolAlgo.reset(new GeomAlgoAPI_Partition(aListWithObject, aToolsWithPlanes));
             aResShape = aBoolAlgo->shape();
-            if(aResShape->shapeType() == GeomAPI_Shape::COMPOUND) {
+            if (aResShape.get() && aResShape->shapeType() == GeomAPI_Shape::COMPOUND) {
               int aSubResultsNb = 0;
               GeomAPI_ShapeIterator anIt(aResShape);
               for(; anIt.more(); anIt.next()) {
@@ -247,18 +244,19 @@ void FeaturesPlugin_Boolean::execute()
         aMakeShapeList.appendAlgo(aBoolAlgo);
 
         if(GeomAlgoAPI_ShapeTools::volume(aResShape) > 1.e-27
-          || (aType != BOOL_CUT && aType != BOOL_COMMON))
+           || (myOperationType != BOOL_CUT && myOperationType != BOOL_COMMON))
         {
           std::shared_ptr<ModelAPI_ResultBody> aResultBody =
             document()->createBody(data(), aResultIndex);
 
           ListOfShape aUsedTools = aTools;
-          if (aType == BOOL_FILL) {
+          if (myOperationType == BOOL_FILL) {
             aUsedTools.insert(aUsedTools.end(), aPlanes.begin(), aPlanes.end());
           }
 
           loadNamingDS(aResultBody, anObject, aUsedTools, aResShape,
-                       aMakeShapeList, *(aBoolAlgo->mapOfSubShapes()), aType == BOOL_FILL);
+                       aMakeShapeList, *(aBoolAlgo->mapOfSubShapes()),
+                       myOperationType == BOOL_FILL);
           setResult(aResultBody, aResultIndex);
           aResultIndex++;
         }
@@ -290,7 +288,7 @@ void FeaturesPlugin_Boolean::execute()
         GeomAlgoAPI_MakeShapeList aMakeShapeList;
         std::shared_ptr<GeomAlgoAPI_MakeShape> aBoolAlgo;
 
-        switch(aType) {
+        switch(myOperationType) {
           case BOOL_CUT: {
             aBoolAlgo.reset(new GeomAlgoAPI_Boolean(aUsedInOperationSolids,
                                                     aTools,
@@ -367,13 +365,13 @@ void FeaturesPlugin_Boolean::execute()
         }
 
         if(GeomAlgoAPI_ShapeTools::volume(aResultShape) > 1.e-27
-          || (aType != BOOL_CUT && aType != BOOL_COMMON))
+           || (myOperationType != BOOL_CUT && myOperationType != BOOL_COMMON))
         {
           std::shared_ptr<ModelAPI_ResultBody> aResultBody =
             document()->createBody(data(), aResultIndex);
 
           ListOfShape aUsedTools = aTools;
-          if (aType == BOOL_FILL) {
+          if (myOperationType == BOOL_FILL) {
             aUsedTools.insert(aUsedTools.end(), aPlanes.begin(), aPlanes.end());
           }
 
@@ -383,7 +381,7 @@ void FeaturesPlugin_Boolean::execute()
                        aResultShape,
                        aMakeShapeList,
                        aMapOfShapes,
-                       aType == BOOL_FILL);
+                       myOperationType == BOOL_FILL);
           setResult(aResultBody, aResultIndex);
           aResultIndex++;
         }