Salome HOME
Make extrusions features correctly eat as a base a whole sketch feature selection.
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Validators.cpp
index ec5414da94edfb5cb816b0dbad50e895c128346d..4ab4e48cc1b151bcff7fe87fe58f2b25c0355846 100644 (file)
 // License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 //
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
 //
 
 #include "FeaturesPlugin_Validators.h"
 
+#include "FeaturesPlugin_Boolean.h"
+#include "FeaturesPlugin_BooleanFuse.h"
+#include "FeaturesPlugin_BooleanSmash.h"
 #include "FeaturesPlugin_Union.h"
 
 #include <Events_InfoMessage.h>
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_Feature.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_Tools.h>
 
 #include <GeomValidators_BodyShapes.h>
+#include <GeomValidators_Face.h>
 #include <GeomValidators_FeatureKind.h>
 #include <GeomValidators_ShapeType.h>
 
 #include <GeomAPI_DataMapOfShapeShape.h>
 #include <GeomAPI_Lin.h>
 #include <GeomAPI_PlanarEdges.h>
+#include <GeomAPI_Pln.h>
 #include <GeomAPI_ShapeExplorer.h>
 #include <GeomAPI_ShapeIterator.h>
 
@@ -130,13 +136,6 @@ bool FeaturesPlugin_ValidatorPipeLocations::isValid(
   return true;
 }
 
-//==================================================================================================
-bool FeaturesPlugin_ValidatorPipeLocations::isNotObligatory(std::string theFeature,
-                                                            std::string theAttribute)
-{
-  return false;
-}
-
 //==================================================================================================
 bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theAttribute,
                                                         const std::list<std::string>& theArguments,
@@ -280,14 +279,6 @@ bool FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects::isValid(
   return true;
 }
 
-//==================================================================================================
-bool FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects::isNotObligatory(
-    std::string theFeature,
-    std::string theAttribute)
-{
-  return false;
-}
-
 //==================================================================================================
 bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const AttributePtr& theAttribute,
                                                         const std::list<std::string>& theArguments,
@@ -523,13 +514,6 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isValid(
   return true;
 }
 
-//==================================================================================================
-bool FeaturesPlugin_ValidatorExtrusionDir::isNotObligatory(std::string theFeature,
-                                                           std::string theAttribute)
-{
-  return false;
-}
-
 //==================================================================================================
 bool FeaturesPlugin_ValidatorExtrusionDir::isShapesCanBeEmpty(const AttributePtr& theAttribute,
                                                               Events_InfoMessage& theError) const
@@ -590,8 +574,9 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt
       "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
     return false;
   }
-  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
-  int anOperationType = aFeature->integer("bool_type")->value();
+  std::shared_ptr<FeaturesPlugin_Boolean> aFeature =
+    std::dynamic_pointer_cast<FeaturesPlugin_Boolean>(theAttribute->owner());
+  FeaturesPlugin_Boolean::OperationType anOperationType = aFeature->operationType();
 
   for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
     AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
@@ -601,47 +586,113 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt
     }
     ResultPtr aContext = anAttrSelection->context();
     if(!aContext.get()) {
-      theError = "Error: Empty selection context.";
-      return false;
+      FeaturePtr aContFeat = anAttrSelection->contextFeature();
+      if (!aContFeat.get()) {
+        theError = "Error: Empty selection context.";
+        return false;
+      }
     }
     ResultConstructionPtr aResultConstruction =
       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
     if(aResultConstruction.get()) {
-      theError = "Error: Result construction not allowed for selection.";
-      return false;
+      if (anOperationType != FeaturesPlugin_Boolean::BOOL_FILL
+          || theAttribute->id() != FeaturesPlugin_Boolean::TOOL_LIST_ID()) {
+        theError = "Error: Result construction not allowed for selection.";
+        return false;
+      }
     }
     std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
-    GeomShapePtr aContextShape = aContext->shape();
     if(!aShape.get()) {
+      GeomShapePtr aContextShape = aContext->shape();
       aShape = aContextShape;
     }
     if(!aShape.get()) {
       theError = "Error: Empty shape.";
       return false;
     }
-    if(!aShape->isEqual(aContextShape)) {
+    if (aContext.get() && !aShape->isEqual(aContext->shape())) {
       theError = "Error: Local selection not allowed.";
       return false;
     }
 
-    int aShapeType = aShape->shapeType();
-    if(anOperationType == 1) {
-      // Fuse operation. Allow to select edges, faces and solids.
-      if(aShapeType != GeomAPI_Shape::EDGE &&
-         aShapeType != GeomAPI_Shape::FACE &&
-         aShapeType != GeomAPI_Shape::SOLID &&
-         aShapeType != GeomAPI_Shape::COMPSOLID &&
-         aShapeType != GeomAPI_Shape::COMPOUND) {
-        theError = "Error: Selected shape has the wrong type.";
-        return false;
-      }
+    GeomAPI_Shape::ShapeType aShapeType = aShape->shapeType();
+    std::set<GeomAPI_Shape::ShapeType> anAllowedTypes;
+    if(anOperationType == FeaturesPlugin_Boolean::BOOL_FUSE) {
+      anAllowedTypes.insert(GeomAPI_Shape::EDGE);
+      anAllowedTypes.insert(GeomAPI_Shape::FACE);
+      anAllowedTypes.insert(GeomAPI_Shape::SOLID);
+      anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
+      anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
+    } else if (anOperationType == FeaturesPlugin_Boolean::BOOL_FILL
+               || anOperationType == FeaturesPlugin_Boolean::BOOL_CUT)
+    {
+      anAllowedTypes.insert(GeomAPI_Shape::VERTEX);
+      anAllowedTypes.insert(GeomAPI_Shape::EDGE);
+      anAllowedTypes.insert(GeomAPI_Shape::WIRE);
+      anAllowedTypes.insert(GeomAPI_Shape::FACE);
+      anAllowedTypes.insert(GeomAPI_Shape::SHELL);
+      anAllowedTypes.insert(GeomAPI_Shape::SOLID);
+      anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
+      anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
     } else {
-      if(aShapeType != GeomAPI_Shape::SOLID &&
-         aShapeType != GeomAPI_Shape::COMPSOLID &&
-         aShapeType != GeomAPI_Shape::COMPOUND) {
-        theError = "Error: Selected shape has the wrong type.";
-        return false;
-      }
+      anAllowedTypes.insert(GeomAPI_Shape::SOLID);
+      anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
+      anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
+    }
+
+    if(anAllowedTypes.find(aShapeType) == anAllowedTypes.end()
+      || (aResultConstruction.get() && aShapeType != GeomAPI_Shape::FACE)) {
+      theError = "Error: Selected shape has the wrong type.";
+      return false;
+    }
+
+  }
+
+  return true;
+}
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorFilletSelection::isValid(const AttributePtr& theAttribute,
+                                                      const std::list<std::string>& theArguments,
+                                                      Events_InfoMessage& theError) const
+{
+  AttributeSelectionListPtr anAttrSelectionList =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+  if(!anAttrSelectionList.get()) {
+    theError =
+      "Error: This validator can only work with selection list attributes in \"Fillet\" feature.";
+    return false;
+  }
+
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+  // Check all selected entities are sub-shapes of single solid
+  GeomShapePtr aBaseSolid;
+  for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
+    AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
+    if(!anAttrSelection.get()) {
+      theError = "Error: Empty attribute selection.";
+      return false;
+    }
+    ResultPtr aContext = anAttrSelection->context();
+    if(!aContext.get()) {
+      theError = "Error: Empty selection context.";
+      return false;
+    }
+
+    ResultBodyPtr aContextOwner = ModelAPI_Tools::bodyOwner(aContext);
+    GeomShapePtr anOwner = aContextOwner.get() ? aContextOwner->shape() : aContext->shape();
+
+    if (anOwner->shapeType() != GeomAPI_Shape::SOLID &&
+        anOwner->shapeType() != GeomAPI_Shape::COMPSOLID) {
+      theError = "Error: Not all selected shapes are sub-shapes of solids";
+      return false;
+    }
+
+    if (!aBaseSolid)
+      aBaseSolid = anOwner;
+    else if (!aBaseSolid->isEqual(anOwner)) {
+      theError = "Error: Sub-shapes of different solids have been selected.";
+      return false;
     }
   }
 
@@ -681,11 +732,22 @@ bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& the
       return false;
     }
 
-    ResultCompSolidPtr aResultCompsolid =
-      std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aContext);
-    if(aResultCompsolid.get()) {
+    ResultBodyPtr aResultBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
+    if(aResultBody.get()) {
       continue;
     }
+    FeaturePtr aResultFeature = aSelectAttr->contextFeature();
+    if(aResultFeature.get()) {
+      bool aOkRes = false;
+      std::list<ResultPtr>::const_iterator aFRes = aResultFeature->results().cbegin();
+      for(; aFRes != aResultFeature->results().cend() && !aOkRes; aFRes++) {
+        ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aFRes);
+        if (aBody.get() && !aBody->isDisabled())
+          aOkRes = true;
+      }
+      if (aOkRes)
+        continue;
+    }
 
     theError = "Error: Only body shapes and construction planes are allowed for selection.";
     return false;
@@ -758,7 +820,7 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(
   Events_InfoMessage& theError) const
 {
   static const std::string aBaseShapeID = "base_shape";
-  static const std::string aSubShapesID = "subshapes";
+  static const std::string aSubShapesID = "subshapes_to_keep";
 
   if(theFeature->getKind() != "Remove_SubShapes") {
     theError = "Error: Feature \"%1\" does not supported by this validator.";
@@ -788,6 +850,11 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(
   }
   GeomShapePtr aResultShape = aBaseShape->emptyCopied();
 
+  if (aSubShapesAttrList->size() == 0) {
+    theError = "Error: Resulting shape is not valid.";
+    return false;
+  }
+
   // Copy sub-shapes from list to new shape.
   for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
     AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
@@ -804,13 +871,6 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(
   return true;
 }
 
-//==================================================================================================
-bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isNotObligatory(std::string theFeature,
-                                                                    std::string theAttribute)
-{
-  return false;
-}
-
 //==================================================================================================
 bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttribute,
                                                      const std::list<std::string>& theArguments,
@@ -827,11 +887,32 @@ bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttr
   for(int anIndex = 0; anIndex < aBaseObjectsAttrList->size(); ++anIndex) {
     bool isSameFound = false;
     AttributeSelectionPtr anAttrSelectionInList = aBaseObjectsAttrList->value(anIndex);
-    ResultCompSolidPtr aResult =
-      std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(anAttrSelectionInList->context());
+    ResultPtr aContext = anAttrSelectionInList->context();
+    if (!aContext.get()) {
+      theError = "Error: selection is invalid.";
+      return false;
+    }
+
+    ResultConstructionPtr aConstruction =
+      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+    if(aConstruction.get()) {
+      theError = "Error: Result construction not allowed for selection.";
+      return false;
+    }
+
+    GeomShapePtr aShape = anAttrSelectionInList->value();
+    GeomShapePtr aContextShape = aContext->shape();
+    if (aShape.get() && aContextShape.get() && !aContextShape->isEqual(aShape)) {
+      theError = "Error: Local selection not allowed.";
+      return false;
+    }
+
+    ResultBodyPtr aResult =
+      std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
     if(!aResult.get()) {
       continue;
     }
+
     if(aResult->numberOfSubs() > 0) {
       theError = "Error: Whole compsolids not allowed for selection.";
       return false;
@@ -864,17 +945,27 @@ bool FeaturesPlugin_ValidatorUnionArguments::isValid(
   }
 
   // Get all shapes.
+  GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::COMPSOLID;
   ListOfShape aBaseShapesList;
   for(int anIndex = 0; anIndex < aBaseObejctsAttrList->size(); ++anIndex) {
     AttributeSelectionPtr anAttrSelectionInList = aBaseObejctsAttrList->value(anIndex);
     GeomShapePtr aShape = anAttrSelectionInList->value();
+    if (!aShape.get()) {
+      continue;
+    }
     aBaseShapesList.push_back(aShape);
+    aType = aShape->shapeType() == GeomAPI_Shape::FACE ? GeomAPI_Shape::SHELL :
+                                                         GeomAPI_Shape::COMPSOLID;
   }
 
-  // Make componud and find connected.
+  // Make compound and find connected.
   GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aBaseShapesList);
   ListOfShape aCombined, aFree;
-  GeomAlgoAPI_ShapeTools::combineShapes(aCompound, GeomAPI_Shape::COMPSOLID, aCombined, aFree);
+  GeomAlgoAPI_ShapeTools::combineShapes(
+    aCompound,
+    aType,
+    aCombined,
+    aFree);
 
   if(aFree.size() > 0 || aCombined.size() > 1) {
     theError = "Error: Not all shapes have shared topology.";
@@ -884,13 +975,6 @@ bool FeaturesPlugin_ValidatorUnionArguments::isValid(
   return true;
 }
 
-//==================================================================================================
-bool FeaturesPlugin_ValidatorUnionArguments::isNotObligatory(std::string theFeature,
-                                                             std::string theAttribute)
-{
-  return false;
-}
-
 bool FeaturesPlugin_ValidatorConcealedResult::isValid(const AttributePtr& theAttribute,
                                             const std::list<std::string>& theArguments,
                                             Events_InfoMessage& theError) const
@@ -935,3 +1019,494 @@ bool FeaturesPlugin_ValidatorConcealedResult::isValid(const AttributePtr& theAtt
 
   return theError.empty();
 }
+
+bool FeaturesPlugin_ValidatorCircular::isValid(const AttributePtr& theAttribute,
+                                               const std::list<std::string>& theArguments,
+                                               Events_InfoMessage& theError) const
+{
+  static std::list<std::string> aEdgeArg(1, "circle");
+  static std::list<std::string> aFaceArg(1, "cylinder");
+
+  Events_InfoMessage aError;
+  bool isValid = GeomValidators_ShapeType().isValid(theAttribute, aEdgeArg, aError);
+  if (!isValid) {
+    isValid = GeomValidators_Face().isValid(theAttribute, aFaceArg, aError);
+    if (!isValid)
+      theError = "The shape neither circle nor cylinder";
+  }
+  return isValid;
+}
+
+//=================================================================================================
+bool FeaturesPlugin_ValidatorBooleanArguments::isValid(
+  const std::shared_ptr<ModelAPI_Feature>& theFeature,
+  const std::list<std::string>& theArguments,
+  Events_InfoMessage& theError) const
+{
+  if (theArguments.size() != 2)
+  {
+    theError = "Wrong number of arguments (expected 2).";
+    return false;
+  }
+
+  int anObjectsNb = 0, aToolsNb = 0;
+  //int anOperationType = 0;
+
+  std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
+
+  bool isAllInSameCompSolid = true;
+  ResultBodyPtr aCompSolid;
+
+  AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
+  if (anAttrSelList)
+  {
+    anObjectsNb = anAttrSelList->size();
+    for (int anIndex = 0; anIndex < anObjectsNb; ++anIndex)
+    {
+      AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
+      ResultPtr aContext = anAttr->context();
+      ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
+      if (aResCompSolidPtr.get())
+      {
+        if (aCompSolid.get())
+        {
+          isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
+        }
+        else
+        {
+          aCompSolid = aResCompSolidPtr;
+        }
+      }
+      else
+      {
+        isAllInSameCompSolid = false;
+        break;
+      }
+    }
+  }
+  anIt++;
+
+
+  anAttrSelList = theFeature->selectionList(*anIt);
+  if (anAttrSelList)
+  {
+    aToolsNb = anAttrSelList->size();
+    if (isAllInSameCompSolid)
+    {
+      for (int anIndex = 0; anIndex < aToolsNb; ++anIndex)
+      {
+        AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
+        ResultPtr aContext = anAttr->context();
+        ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
+        if (aResCompSolidPtr.get())
+        {
+          if (aCompSolid.get())
+          {
+            isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
+          }
+          else
+          {
+            aCompSolid = aResCompSolidPtr;
+          }
+        }
+        else
+        {
+          isAllInSameCompSolid = false;
+          break;
+        }
+      }
+    }
+  }
+  anIt++;
+
+  std::shared_ptr<FeaturesPlugin_Boolean> aFeature =
+    std::dynamic_pointer_cast<FeaturesPlugin_Boolean>(theFeature);
+  FeaturesPlugin_Boolean::OperationType anOperationType = aFeature->operationType();
+
+  if (anOperationType == FeaturesPlugin_Boolean::BOOL_FUSE)
+  {
+    // Fuse operation
+    if (anObjectsNb + aToolsNb < 2)
+    {
+      theError = "Not enough arguments for Fuse operation.";
+      return false;
+    }
+    else if (isAllInSameCompSolid)
+    {
+      theError = "Operations only between sub-shapes of the same shape not allowed.";
+      return false;
+    }
+  }
+  else
+  {
+    if (anObjectsNb < 1)
+    {
+      theError = "Objects not selected.";
+      return false;
+    }
+    if (aToolsNb < 1)
+    {
+      theError = "Tools not selected.";
+      return false;
+    }
+    if (isAllInSameCompSolid)
+    {
+      theError = "Operations only between sub-shapes of the same shape not allowed.";
+      return false;
+    }
+  }
+
+  return true;
+}
+
+//=================================================================================================
+bool FeaturesPlugin_ValidatorBooleanArguments::isNotObligatory(std::string theFeature,
+                                                               std::string theAttribute)
+{
+  if (theAttribute == "main_objects" || theAttribute == "tool_objects")
+  {
+    return true;
+  }
+
+  return false;
+}
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid(
+  const AttributePtr& theAttribute,
+  const std::list<std::string>& theArguments,
+  Events_InfoMessage& theError) const
+{
+  std::shared_ptr<FeaturesPlugin_BooleanSmash> aFeature =
+    std::dynamic_pointer_cast<FeaturesPlugin_BooleanSmash>(theAttribute->owner());
+
+  AttributeSelectionListPtr anAttrSelectionList =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+  if (!aFeature.get() || !anAttrSelectionList.get()) {
+    theError =
+      "Error: Validator used in wrong feature or attribute";
+    return false;
+  }
+
+  AttributeSelectionListPtr anOtherAttrSelectionList;
+  if (theAttribute->id() == FeaturesPlugin_BooleanSmash::OBJECT_LIST_ID()) {
+    anOtherAttrSelectionList =
+      aFeature->selectionList(FeaturesPlugin_BooleanSmash::TOOL_LIST_ID());
+  } else {
+    anOtherAttrSelectionList =
+      aFeature->selectionList(FeaturesPlugin_BooleanSmash::OBJECT_LIST_ID());
+  }
+
+  GeomAPI_Shape::ShapeType aSelectedShapesType = GeomAPI_Shape::SHAPE;
+  GeomAPI_DataMapOfShapeShape aSelectedCompSolidsInOtherList;
+  GeomPlanePtr aFacesPln;
+
+  for (int anIndex = 0; anIndex < anOtherAttrSelectionList->size(); ++anIndex) {
+    AttributeSelectionPtr anAttrSelection = anOtherAttrSelectionList->value(anIndex);
+    ResultPtr aContext = anAttrSelection->context();
+    std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
+    GeomShapePtr aContextShape = aContext->shape();
+    if (!aShape.get()) {
+      aShape = aContextShape;
+    }
+
+    if (aShape->isSolid() || aShape->isCompSolid()) {
+      aSelectedShapesType = GeomAPI_Shape::SOLID;
+      ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
+      if (aResCompSolidPtr.get()) {
+        GeomShapePtr aCompSolidShape = aResCompSolidPtr->shape();
+        aSelectedCompSolidsInOtherList.bind(aCompSolidShape, aCompSolidShape);
+      }
+    } else {
+      aSelectedShapesType = GeomAPI_Shape::FACE;
+      GeomAPI_Face aFace(aShape);
+      aFacesPln = aFace.getPlane();
+      break;
+    }
+  }
+
+  for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
+    AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
+    if (!anAttrSelection.get()) {
+      theError = "Error: Empty attribute selection.";
+      return false;
+    }
+    ResultPtr aContext = anAttrSelection->context();
+    if (!aContext.get()) {
+      theError = "Error: Empty selection context.";
+      return false;
+    }
+    ResultConstructionPtr aResultConstruction =
+      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+    if (aResultConstruction.get()) {
+      theError = "Error: Result construction not allowed for selection.";
+      return false;
+    }
+    std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
+    GeomShapePtr aContextShape = aContext->shape();
+    if (!aShape.get()) {
+      aShape = aContextShape;
+    }
+    if (!aShape.get()) {
+      theError = "Error: Empty shape.";
+      return false;
+    }
+    if (!aShape->isEqual(aContextShape)) {
+      theError = "Error: Local selection not allowed.";
+      return false;
+    }
+
+    if (aSelectedShapesType == GeomAPI_Shape::SHAPE) {
+      // Other list is empty.
+      if (aShape->isSolid() || aShape->isCompSolid()) {
+        aSelectedShapesType = GeomAPI_Shape::SOLID;
+      } else {
+        aSelectedShapesType = GeomAPI_Shape::FACE;
+        GeomAPI_Face aFace(aShape);
+        aFacesPln = aFace.getPlane();
+
+        if (!aFacesPln.get()) {
+          theError = "Error: Only planar faces allowed.";
+          return false;
+        }
+      }
+
+      continue;
+    } else if (aSelectedShapesType == GeomAPI_Shape::SOLID) {
+      if (!aShape->isSolid() && !aShape->isCompSolid()) {
+        theError = "Error: Selected shapes should have the same type.";
+        return false;
+      }
+
+      ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
+      if (aResCompSolidPtr.get()) {
+        GeomShapePtr aCompSolidShape = aResCompSolidPtr->shape();
+        if (aSelectedCompSolidsInOtherList.isBound(aCompSolidShape)) {
+          theError = "Error: Solids from compsolid in other list not allowed.";
+          return false;
+        }
+      }
+    } else {
+      GeomAPI_Face aFace(aShape);
+      GeomPlanePtr aPln = aFace.getPlane();
+
+      if (!aPln.get()) {
+        theError = "Error: Only planar faces allowed.";
+        return false;
+      }
+
+      if (!aFacesPln->isCoincident(aPln)) {
+        theError = "Error: Only coincident faces allowed.";
+        return false;
+      }
+    }
+  }
+
+  return true;
+}
+
+//==================================================================================================
+bool FeaturesPlugin_IntersectionSelection::isValid(const AttributePtr& theAttribute,
+                                                   const std::list<std::string>& theArguments,
+                                                   Events_InfoMessage& theError) const
+{
+  if (!theAttribute.get()) {
+    theError = "Error: empty selection.";
+    return false;
+  }
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+  AttributeSelectionListPtr anAttrSelectionList =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+  for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
+    AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
+    if (!anAttrSelection.get()) {
+      theError = "Error: empty attribute selection.";
+      return false;
+    }
+    ResultPtr aContext = anAttrSelection->context();
+    if (!aContext.get()) {
+      theError = "Error: empty selection context.";
+      return false;
+    }
+    FeaturePtr aFeature = ModelAPI_Feature::feature(aContext);
+    if (!aFeature.get()) {
+      theError = "Error: empty feature.";
+      return false;
+    }
+    std::string aFeatureKind = aFeature->getKind();
+    if (aFeatureKind == "Sketch" ||
+        aFeatureKind == "Plane" ||
+        aFeatureKind == "Axis") {
+      theError = "Error: %1 shape is not allowed for selection.";
+      theError.arg(aFeatureKind);
+      return false;
+    }
+    std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
+    GeomShapePtr aContextShape = aContext->shape();
+    if (!aShape.get()) {
+      aShape = aContextShape;
+    }
+    if (!aShape.get()) {
+      theError = "Error: empty shape.";
+      return false;
+    }
+    if (!aShape->isEqual(aContextShape)) {
+      theError = "Error: Local selection not allowed.";
+      return false;
+    }
+
+    int aShapeType = aShape->shapeType();
+    // Allow to select edges, faces and solids.
+    if (aShapeType != GeomAPI_Shape::EDGE &&
+        aShapeType != GeomAPI_Shape::FACE &&
+        aShapeType != GeomAPI_Shape::SOLID &&
+        aShapeType != GeomAPI_Shape::COMPSOLID &&
+        aShapeType != GeomAPI_Shape::COMPOUND) {
+      theError = "Error: selected shape has the wrong type.";
+      return false;
+    }
+  }
+
+  return true;
+}
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorBooleanFuseSelection::isValid(
+  const AttributePtr& theAttribute,
+  const std::list<std::string>& theArguments,
+  Events_InfoMessage& theError) const
+{
+  AttributeSelectionListPtr anAttrSelectionList =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+  if (!anAttrSelectionList.get()) {
+    theError =
+      "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
+    return false;
+  }
+
+  for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
+    AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
+    if (!anAttrSelection.get()) {
+      theError = "Error: Empty attribute selection.";
+      return false;
+    }
+    ResultPtr aContext = anAttrSelection->context();
+    if (!aContext.get()) {
+      theError = "Error: Empty selection context.";
+      return false;
+    }
+    ResultConstructionPtr aResultConstruction =
+      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+    if (aResultConstruction.get()) {
+      theError = "Error: Result construction not allowed for selection.";
+      return false;
+    }
+    std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
+    GeomShapePtr aContextShape = aContext->shape();
+    if (!aShape.get()) {
+      aShape = aContextShape;
+    }
+    if (!aShape.get()) {
+      theError = "Error: Empty shape.";
+      return false;
+    }
+    if (!aShape->isEqual(aContextShape)) {
+      theError = "Error: Local selection not allowed.";
+      return false;
+    }
+  }
+
+  return true;
+}
+
+//=================================================================================================
+bool FeaturesPlugin_ValidatorBooleanFuseArguments::isValid(
+  const std::shared_ptr<ModelAPI_Feature>& theFeature,
+  const std::list<std::string>& theArguments,
+  Events_InfoMessage& theError) const
+{
+  if (theArguments.size() != 2) {
+    theError = "Wrong number of arguments (expected 2).";
+    return false;
+  }
+
+  std::shared_ptr<FeaturesPlugin_BooleanFuse> aFeature =
+    std::dynamic_pointer_cast<FeaturesPlugin_BooleanFuse>(theFeature);
+
+  int anObjectsNb = 0, aToolsNb = 0;
+
+  std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
+
+  bool isAllInSameCompSolid = true;
+  ResultBodyPtr aCompSolid;
+
+  AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
+  if (anAttrSelList) {
+    anObjectsNb = anAttrSelList->size();
+    for (int anIndex = 0; anIndex < anObjectsNb; ++anIndex) {
+      AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
+      ResultPtr aContext = anAttr->context();
+      ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
+      if (aResCompSolidPtr.get()) {
+        if (aCompSolid.get()) {
+          isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
+        } else {
+          aCompSolid = aResCompSolidPtr;
+        }
+      } else {
+        isAllInSameCompSolid = false;
+        break;
+      }
+    }
+  }
+  anIt++;
+
+  if (aFeature->string(FeaturesPlugin_BooleanFuse::CREATION_METHOD())->value()
+      == FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED()) {
+    anAttrSelList = theFeature->selectionList(*anIt);
+    if (anAttrSelList) {
+      aToolsNb = anAttrSelList->size();
+      if (isAllInSameCompSolid) {
+        for (int anIndex = 0; anIndex < aToolsNb; ++anIndex) {
+          AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
+          ResultPtr aContext = anAttr->context();
+          ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
+          if (aResCompSolidPtr.get()) {
+            if (aCompSolid.get()) {
+              isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
+            } else {
+              aCompSolid = aResCompSolidPtr;
+            }
+          } else {
+            isAllInSameCompSolid = false;
+            break;
+          }
+        }
+      }
+    }
+  }
+
+  anIt++;
+
+  if (anObjectsNb + aToolsNb < 2) {
+    theError = "Not enough arguments for Fuse operation.";
+    return false;
+  } else if (isAllInSameCompSolid) {
+    theError = "Operations only between sub-shapes of the same shape not allowed.";
+    return false;
+  }
+
+  return true;
+}
+
+//=================================================================================================
+bool FeaturesPlugin_ValidatorBooleanFuseArguments::isNotObligatory(
+  std::string theFeature,
+  std::string theAttribute)
+{
+  if (theAttribute == "main_objects" || theAttribute == "tool_objects") {
+    return true;
+  }
+
+  return false;
+}
\ No newline at end of file