Salome HOME
Fix for the issue #654: edition of parameter causes disabling all sub-parameters
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Boolean.cpp
index 555590596688b4b109c84552220276b6da397fa6..7fb46f2c998cac3abd103ee68124d04c81f45a1b 100644 (file)
@@ -12,6 +12,8 @@
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
 
 #include <GeomAlgoAPI_Boolean.h>
 #include <GeomAlgoAPI_MakeShapeList.h>
@@ -20,6 +22,7 @@
 #define FACE 4
 #define _MODIFY_TAG 1
 #define _DELETED_TAG 2
+#define _SUBSOLIDS_TAG 3 /// sub solids will be placed at labels 3, 4, etc. if result is compound of solids
 
 //=================================================================================================
 FeaturesPlugin_Boolean::FeaturesPlugin_Boolean()
@@ -41,6 +44,9 @@ void FeaturesPlugin_Boolean::initAttributes()
     FeaturesPlugin_Boolean::TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
   // extrusion works with faces always
   aSelection->setSelectionType("SOLID");
+
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_LIST_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TOOL_LIST_ID());
 }
 
 //=================================================================================================
@@ -71,9 +77,6 @@ void FeaturesPlugin_Boolean::execute()
 
   // Getting objects.
   AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_Boolean::OBJECT_LIST_ID());
-  if (anObjectsSelList->size() == 0) {
-    return;
-  }
   for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
     std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr = anObjectsSelList->value(anObjectsIndex);
     std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
@@ -85,9 +88,6 @@ void FeaturesPlugin_Boolean::execute()
 
   // Getting tools.
   AttributeSelectionListPtr aToolsSelList = selectionList(FeaturesPlugin_Boolean::TOOL_LIST_ID());
-  if (aToolsSelList->size() == 0) {
-    return;
-  }
   for(int aToolsIndex = 0; aToolsIndex < aToolsSelList->size(); aToolsIndex++) {
     std::shared_ptr<ModelAPI_AttributeSelection> aToolAttr = aToolsSelList->value(aToolsIndex);
     std::shared_ptr<GeomAPI_Shape> aTool = aToolAttr->value();
@@ -98,12 +98,16 @@ void FeaturesPlugin_Boolean::execute()
   }
 
   int aResultIndex = 0;
-  ListOfMakeShape aListOfMakeShape;
-  std::shared_ptr<GeomAPI_DataMapOfShapeShape> aDataMapOfShapes;
 
   switch(aType) {
     case GeomAlgoAPI_Boolean::BOOL_CUT:
     case GeomAlgoAPI_Boolean::BOOL_COMMON:{
+      if(anObjects.empty() || aTools.empty()) {
+        std::string aFeatureError = "Not enough objects for boolean operation";
+        setError(aFeatureError);
+        return;
+      }
+
       // Cut each object with all tools
       for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) {
         std::shared_ptr<GeomAPI_Shape> anObject = *anObjectsIt;
@@ -130,9 +134,6 @@ void FeaturesPlugin_Boolean::execute()
 
         if(GeomAlgoAPI_ShapeProps::volume(aBoolAlgo.shape()) > 1.e-7) {
           std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
-          std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList = std::shared_ptr<GeomAlgoAPI_MakeShapeList>(
-            new GeomAlgoAPI_MakeShapeList(aListOfMakeShape));
-
           LoadNamingDS(aResultBody, anObject, aTools, aBoolAlgo);
           setResult(aResultBody, aResultIndex);
           aResultIndex++;
@@ -141,6 +142,20 @@ void FeaturesPlugin_Boolean::execute()
       break;
     }
     case GeomAlgoAPI_Boolean::BOOL_FUSE: {
+      if(anObjects.empty() && aTools.size() > 1) {
+        anObjects.push_back(aTools.back());
+        aTools.pop_back();
+      }else if(aTools.empty() && anObjects.size() > 1) {
+        aTools.push_back(anObjects.back());
+        anObjects.pop_back();
+      }
+
+      if(anObjects.empty() || aTools.empty()) {
+        std::string aFeatureError = "Not enough objects for boolean operation";
+        setError(aFeatureError);
+        return;
+      }
+
       // Fuse all objects and all tools.
       GeomAlgoAPI_Boolean aBoolAlgo(anObjects, aTools, aType);
 
@@ -162,9 +177,6 @@ void FeaturesPlugin_Boolean::execute()
       }
 
       std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
-      std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList = std::shared_ptr<GeomAlgoAPI_MakeShapeList>(
-        new GeomAlgoAPI_MakeShapeList(aListOfMakeShape));
-
       LoadNamingDS(aResultBody, anObjects.front(), aTools, aBoolAlgo);
       setResult(aResultBody, aResultIndex);
       aResultIndex++;
@@ -190,7 +202,7 @@ void FeaturesPlugin_Boolean::LoadNamingDS(std::shared_ptr<ModelAPI_ResultBody> t
   if(theBaseShape->isEqual(theAlgo.shape())) {
     theResultBody->store(theAlgo.shape());
   } else {
-    theResultBody->storeModified(theBaseShape, theAlgo.shape());
+    theResultBody->storeModified(theBaseShape, theAlgo.shape(), _SUBSOLIDS_TAG);
 
     GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();