Salome HOME
Issue #17342: 3D Model defeaturing
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Validators.cpp
index 3201919963d87895b72c3d660af34fdc5061022d..6426d94739bba43533d8efb7910e3ad6f1be5298 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// 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
 //
 
 #include "FeaturesPlugin_Validators.h"
 #include "FeaturesPlugin_BooleanFuse.h"
 #include "FeaturesPlugin_BooleanCommon.h"
 #include "FeaturesPlugin_BooleanSmash.h"
+#include "FeaturesPlugin_Extrusion.h"
+#include "FeaturesPlugin_Pipe.h"
 #include "FeaturesPlugin_Union.h"
 
 #include <Events_InfoMessage.h>
 
 #include <ModelAPI_Attribute.h>
+#include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
@@ -52,6 +54,7 @@
 #include <GeomAPI_ShapeIterator.h>
 
 #include <GeomAlgoAPI_CompoundBuilder.h>
+#include <GeomAlgoAPI_Prism.h>
 #include <GeomAlgoAPI_ShapeBuilder.h>
 #include <GeomAlgoAPI_ShapeTools.h>
 #include <GeomAlgoAPI_WireBuilder.h>
@@ -67,8 +70,10 @@ bool FeaturesPlugin_ValidatorPipePath::isValid(const AttributePtr& theAttribute,
   AttributeSelectionPtr aPathAttrSelection =
     std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
   if(!aPathAttrSelection.get()) {
+// LCOV_EXCL_START
     theError = "Error: This validator can only work with path selector in \"Pipe\" feature.";
     return false;
+// LCOV_EXCL_STOP
   }
 
   GeomShapePtr aPathShape = aPathAttrSelection->value();
@@ -88,7 +93,84 @@ bool FeaturesPlugin_ValidatorPipePath::isValid(const AttributePtr& theAttribute,
 }
 
 //==================================================================================================
-bool FeaturesPlugin_ValidatorPipeLocations::isValid(
+bool FeaturesPlugin_ValidatorPipeLocations::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()) {
+// LCOV_EXCL_START
+    theError =
+      "Error: This validator can only work with selection list attributes in \"Pipe\" feature.";
+    return false;
+// LCOV_EXCL_STOP
+  }
+  std::shared_ptr<FeaturesPlugin_Pipe> aFeature =
+    std::dynamic_pointer_cast<FeaturesPlugin_Pipe>(theAttribute->owner());
+
+  AttributeSelectionPtr aPathSelection = aFeature->selection(FeaturesPlugin_Pipe::PATH_OBJECT_ID());
+  if (!aPathSelection.get()) {
+// LCOV_EXCL_START
+    theError = "Error: Path not selected.";
+    return false;
+// LCOV_EXCL_STOP
+  }
+
+  GeomShapePtr aPathShape = aPathSelection->value();
+  if (!aPathShape.get()) {
+    ResultPtr aContext = aPathSelection->context();
+    if (!aContext.get()) {
+      FeaturePtr aContFeat = aPathSelection->contextFeature();
+      if (!aContFeat.get() || !aContFeat->results().size()) {
+        theError = "Error: Empty selection context.";
+        return false;
+      }
+    }
+    aPathShape = aContext->shape();
+  }
+
+  if (!aPathShape.get()) {
+    theError = "Error: Empty path shape.";
+    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()) {
+      FeaturePtr aContFeat = anAttrSelection->contextFeature();
+      if (!aContFeat.get() || !aContFeat->results().size()) {
+        theError = "Error: Empty selection context.";
+        return false;
+      }
+    }
+    std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
+    if (!aShape.get() && aContext.get()) {
+      GeomShapePtr aContextShape = aContext->shape();
+      aShape = aContextShape;
+    }
+    if (!aShape.get()) {
+      theError = "Error: Empty shape.";
+      return false;
+    }
+
+    if (!aPathShape->isSubShape(aShape)) {
+      theError = "Error: Location should be a vertex subshape from path shape.";
+      return false;
+    }
+  }
+
+  return true;
+}
+
+//==================================================================================================
+// LCOV_EXCL_START
+bool FeaturesPlugin_ValidatorPipeLocationsNumber::isValid(
   const std::shared_ptr<ModelAPI_Feature>& theFeature,
   const std::list<std::string>& theArguments,
   Events_InfoMessage& theError) const
@@ -136,16 +218,19 @@ bool FeaturesPlugin_ValidatorPipeLocations::isValid(
 
   return true;
 }
+// LCOV_EXCL_STOP
 
 //==================================================================================================
 bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theAttribute,
                                                         const std::list<std::string>& theArguments,
                                                         Events_InfoMessage& theError) const
 {
+// LCOV_EXCL_START
   if(theArguments.empty()) {
     theError = "Error: Validator parameters is empty.";
     return false;
   }
+// LCOV_EXCL_STOP
 
   // Checking attribute.
   if(!isValidAttribute(theAttribute, theArguments, theError)) {
@@ -172,7 +257,7 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
         std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
       if(!aResultConstruction.get()) {
         // It is not a result construction.
-        // If shape is compound check that it contains only faces and edges.
+        // If shape is compound check that it contains only faces, edges or vertices.
         GeomShapePtr aShape = aSelectionAttr->value();
         if(!aShape.get()) {
           if (aContext.get()) {
@@ -186,9 +271,10 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
         if(aShape->shapeType() == GeomAPI_Shape::COMPOUND) {
           for(GeomAPI_ShapeIterator anIt(aShape); anIt.more(); anIt.next()) {
             GeomShapePtr aSubShape = anIt.current();
-            if(aSubShape->shapeType() != GeomAPI_Shape::EDGE
+            if(aSubShape->shapeType() != GeomAPI_Shape::VERTEX
+                && aSubShape->shapeType() != GeomAPI_Shape::EDGE
                 && aSubShape->shapeType() != GeomAPI_Shape::FACE) {
-              theError = "Error: Compound should contain only faces and edges.";
+              theError = "Error: Compound should contain only faces, edges or vertices.";
               return false;
             }
           }
@@ -213,7 +299,7 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
 
           if(aSelectedWiresFromObjects.isBound(aWire)) {
             theError =
-              "Error: Objects with such wire already selected. Don't allow to select this object.";
+              "Error: Objects with this wire already selected. Don't allow to select this object.";
             return false;
           }
 
@@ -236,9 +322,11 @@ bool FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects::isValid(
 
   AttributeSelectionListPtr aListAttr = theFeature->selectionList(aBaseObjectsID);
   if(!aListAttr.get()) {
+// LCOV_EXCL_START
     theError = "Error: Could not get \"%1\" attribute.";
     theError.arg(aBaseObjectsID);
     return false;
+// LCOV_EXCL_STOP
   }
 
   std::set<ResultConstructionPtr> aSelectedSketches;
@@ -296,8 +384,10 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
                                                         Events_InfoMessage& theError) const
 {
   if(!theAttribute.get()) {
+// LCOV_EXCL_START
     theError = "Error: Empty attribute.";
     return false;
+// LCOV_EXCL_STOP
   }
 
   std::string anAttributeType = theAttribute->attributeType();
@@ -338,7 +428,7 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
     if (aContext.get())
       aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
     if(aConstruction.get()) {
-      // Construciotn selected. Check that is is not infinite.
+      // Construction selected. Check that it is not infinite.
       if(aConstruction->isInfinite()) {
         theError = "Error: Infinite constructions is not allowed as base.";
         return false;
@@ -357,7 +447,6 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
           return true;
         }
       }
-
       return false;
     }
 
@@ -372,7 +461,7 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
     GeomValidators_ShapeType aShapeTypeValidator;
     if(!aShapeTypeValidator.isValid(anAttr, theArguments, theError)) {
       theError = "Error: Selected shape has unacceptable type. Acceptable types are: faces or "
-                 "wires on sketch, whole sketch(if it has at least one face), "
+                 "wires on sketch, whole sketch (if it has at least one face), "
                  "and whole objects with shape types: %1";
       std::string anArgumentString;
       for(auto anIt = theArguments.cbegin(); anIt != theArguments.cend(); ++anIt) {
@@ -385,15 +474,18 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
     }
 
   } else {
+// LCOV_EXCL_START
     theError = "Error: Attribute \"%1\" does not supported by this validator.";
     theError.arg(anAttributeType);
     return false;
+// LCOV_EXCL_STOP
   }
 
   return true;
 }
 
 //==================================================================================================
+// LCOV_EXCL_START
 bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theAttribute,
                                                         const std::list<std::string>& theArguments,
                                                         Events_InfoMessage& theError) const
@@ -440,6 +532,7 @@ bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theA
   bool aValid = !aFeatureKind && aPlanarFace;
   return aValid;
 }
+// LCOV_EXCL_STOP
 
 //==================================================================================================
 bool FeaturesPlugin_ValidatorExtrusionDir::isValid(
@@ -448,8 +541,10 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isValid(
                                                Events_InfoMessage& theError) const
 {
   if(theArguments.size() != 2) {
+// LCOV_EXCL_START
     theError = "Error: Validator should be used with 2 parameters for extrusion.";
     return false;
+// LCOV_EXCL_STOP
   }
 
   std::list<std::string>::const_iterator
@@ -474,10 +569,16 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isValid(
       if(aContext.get()) {
         aDirShape = aContext->shape();
       }
+
+      if (aDirShape.get() && aDirShape->isCompound()) {
+        GeomAPI_ShapeIterator anIt(aDirShape);
+        aDirShape = anIt.current();
+      }
     }
   }
 
-  if(!aDirShape.get()) {
+  if(!aDirShape.get() || aDirShape->isNull() ||
+     aDirShape->shapeType() != GeomAPI_Shape::EDGE) {
     // Check that dir can be empty.
     if(!isShapesCanBeEmpty(aCheckAttribute, theError)) {
       theError = "Error: Base objects list contains vertex or edge, so attribute \"%1\" "
@@ -542,9 +643,11 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isValid(
 bool FeaturesPlugin_ValidatorExtrusionDir::isShapesCanBeEmpty(const AttributePtr& theAttribute,
                                                               Events_InfoMessage& theError) const
 {
+// LCOV_EXCL_START
   if(!theAttribute.get()) {
     return true;
   }
+// LCOV_EXCL_STOP
 
   std::string anAttributeType = theAttribute->attributeType();
   if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
@@ -586,6 +689,99 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isShapesCanBeEmpty(const AttributePtr
   return true;
 }
 
+//==================================================================================================
+bool FeaturesPlugin_ValidatorExtrusionBoundaryFace::isValid(
+    const AttributePtr& theAttribute,
+    const std::list<std::string>& theArguments,
+    Events_InfoMessage& theError) const
+{
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+
+  // Collect all necessary attributes and try to build prism
+
+  // base face
+  AttributeSelectionListPtr aBaseShapeAttr =
+      aFeature->selectionList(FeaturesPlugin_Extrusion::BASE_OBJECTS_ID());
+  ListOfShape aBaseShapeList;
+  std::string anError;
+  if (!FeaturesPlugin_Tools::getShape(aBaseShapeAttr, true, aBaseShapeList, anError)) {
+    theError = anError;
+    return false;
+  }
+
+  // direction
+  AttributeSelectionPtr aSelection =
+      aFeature->selection(FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID());
+  GeomShapePtr aShape = aSelection->value();
+  if (!aShape.get() && aSelection->context().get())
+    aShape = aSelection->context()->shape();
+
+  GeomEdgePtr anEdge;
+  if (aShape.get()) {
+    if (aShape->isEdge())
+      anEdge = aShape->edge();
+    else if (aShape->isCompound()) {
+      GeomAPI_ShapeIterator anIt(aShape);
+      anEdge = anIt.current()->edge();
+    }
+  }
+
+  std::shared_ptr<GeomAPI_Dir> aDir;
+  if (anEdge.get() && anEdge->isLine())
+    aDir = anEdge->line()->direction();
+
+  // from/to shapes
+  GeomShapePtr aFromShape, aToShape;
+  aSelection = aFeature->selection(FeaturesPlugin_Extrusion::TO_OBJECT_ID());
+  if (aSelection.get()) {
+    aToShape = aSelection->value();
+    if (!aToShape.get() && aSelection->context().get())
+      aToShape = aSelection->context()->shape();
+    if (aToShape.get() && aToShape->isCompound()) {
+      GeomAPI_ShapeIterator anIt(aToShape);
+      aToShape = anIt.current();
+    }
+    if (aToShape.get() && !aToShape->isFace()) {
+      theError = "\"To\" shape is not a face";
+      return false;
+    }
+  }
+  aSelection = aFeature->selection(FeaturesPlugin_Extrusion::FROM_OBJECT_ID());
+  if (aSelection.get()) {
+    aFromShape = aSelection->value();
+    if (!aFromShape.get() && aSelection->context().get())
+      aFromShape = aSelection->context()->shape();
+    if (aFromShape.get() && aFromShape->isCompound()) {
+      GeomAPI_ShapeIterator anIt(aFromShape);
+      aFromShape = anIt.current();
+    }
+    if (aFromShape.get() && !aFromShape->isFace()) {
+      theError = "\"From\" shape is not a face";
+      return false;
+    }
+  }
+
+  double aToSize = aFeature->real(FeaturesPlugin_Extrusion::TO_OFFSET_ID())->value();
+  double aFromSize = aFeature->real(FeaturesPlugin_Extrusion::FROM_OFFSET_ID())->value();
+
+  // check extrusion
+  for (ListOfShape::iterator anIt = aBaseShapeList.begin(); anIt != aBaseShapeList.end(); anIt++) {
+    std::shared_ptr<GeomAPI_Shape> aBaseShape = *anIt;
+
+    std::shared_ptr<GeomAlgoAPI_Prism> aPrismAlgo(
+        new GeomAlgoAPI_Prism(aBaseShape, aDir, aToShape, aToSize, aFromShape, aFromSize));
+    bool isFailed = GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aPrismAlgo,
+                                                                    FeaturesPlugin_Extrusion::ID(),
+                                                                    anError);
+    if (isFailed) {
+      theError = anError;
+      return false;
+    }
+  }
+
+  return true;
+}
+
 //==================================================================================================
 bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAttribute,
                                                        const std::list<std::string>& theArguments,
@@ -594,9 +790,11 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt
   AttributeSelectionListPtr anAttrSelectionList =
     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
   if(!anAttrSelectionList.get()) {
+// LCOV_EXCL_START
     theError =
       "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
     return false;
+// LCOV_EXCL_STOP
   }
   std::shared_ptr<FeaturesPlugin_Boolean> aFeature =
     std::dynamic_pointer_cast<FeaturesPlugin_Boolean>(theAttribute->owner());
@@ -683,9 +881,11 @@ bool FeaturesPlugin_ValidatorFilletSelection::isValid(const AttributePtr& theAtt
   AttributeSelectionListPtr anAttrSelectionList =
     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
   if(!anAttrSelectionList.get()) {
+// LCOV_EXCL_START
     theError =
       "Error: This validator can only work with selection list attributes in \"Fillet\" feature.";
     return false;
+// LCOV_EXCL_STOP
   }
 
   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
@@ -716,6 +916,11 @@ bool FeaturesPlugin_ValidatorFilletSelection::isValid(const AttributePtr& theAtt
     ResultBodyPtr aContextOwner = ModelAPI_Tools::bodyOwner(aContext);
     GeomShapePtr anOwner = aContextOwner.get() ? aContextOwner->shape() : aContext->shape();
 
+    if (!anOwner) {
+      theError = "Error: wrong feature is selected.";
+      return false;
+    }
+
     if (anOwner->shapeType() != GeomAPI_Shape::SOLID &&
         anOwner->shapeType() != GeomAPI_Shape::COMPSOLID) {
       theError = "Error: Not all selected shapes are sub-shapes of solids.";
@@ -741,8 +946,10 @@ bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& the
   AttributeSelectionListPtr anAttrSelectionList =
     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
   if(!anAttrSelectionList.get()) {
+// LCOV_EXCL_START
     theError = "Error: This validator can only work with selection list in \"Partition\" feature.";
     return false;
+// LCOV_EXCL_STOP
   }
 
   for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
@@ -799,9 +1006,11 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePt
   AttributeSelectionListPtr aSubShapesAttrList =
     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
   if(!aSubShapesAttrList.get()) {
+// LCOV_EXCL_START
     theError =
       "Error: This validator can only work with selection list in \"Remove Sub-Shapes\" feature.";
     return false;
+// LCOV_EXCL_STOP
   }
 
   static const std::string aBaseShapeID = "base_shape";
@@ -809,9 +1018,11 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePt
   AttributeSelectionPtr aShapeAttrSelection = aFeature->selection(aBaseShapeID);
 
   if(!aShapeAttrSelection.get()) {
+// LCOV_EXCL_START
     theError = "Error: Could not get \"%1\" attribute.";
     theError.arg(aBaseShapeID);
     return false;
+// LCOV_EXCL_STOP
   }
 
   GeomShapePtr aBaseShape = aShapeAttrSelection->value();
@@ -833,7 +1044,8 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePt
     bool isSameFound = false;
     AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
     GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
-    for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt) {
+    for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt)
+    {
       if ((*anIt)->isEqual(aShapeToAdd)) {
         isSameFound = true;
         break;
@@ -857,6 +1069,7 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(
   static const std::string aBaseShapeID = "base_shape";
   static const std::string aSubShapesID = "subshapes_to_keep";
 
+// LCOV_EXCL_START
   if(theFeature->getKind() != "Remove_SubShapes") {
     theError = "Error: Feature \"%1\" does not supported by this validator.";
     theError.arg(theFeature->getKind());
@@ -876,6 +1089,7 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(
     theError.arg(aSubShapesID);
     return false;
   }
+// LCOV_EXCL_STOP
 
   // Copy base shape.
   GeomShapePtr aBaseShape = aShapeAttrSelection->value();
@@ -907,6 +1121,7 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(
 }
 
 //==================================================================================================
+// LCOV_EXCL_START
 bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttribute,
                                                      const std::list<std::string>& theArguments,
                                                      Events_InfoMessage& theError) const
@@ -956,6 +1171,7 @@ bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttr
 
   return true;
 }
+// LCOV_EXCL_STOP
 
 //==================================================================================================
 bool FeaturesPlugin_ValidatorUnionArguments::isValid(
@@ -963,6 +1179,7 @@ bool FeaturesPlugin_ValidatorUnionArguments::isValid(
   const std::list<std::string>& theArguments,
   Events_InfoMessage& theError) const
 {
+// LCOV_EXCL_START
   // Check feature kind.
   if(theFeature->getKind() != FeaturesPlugin_Union::ID()) {
     theError = "Error: This validator supports only \"%1\" feature.";
@@ -978,6 +1195,7 @@ bool FeaturesPlugin_ValidatorUnionArguments::isValid(
     theError.arg(FeaturesPlugin_Union::BASE_OBJECTS_ID());
     return false;
   }
+// LCOV_EXCL_STOP
 
   // Get all shapes.
   GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::COMPSOLID;
@@ -995,14 +1213,10 @@ bool FeaturesPlugin_ValidatorUnionArguments::isValid(
 
   // Make compound and find connected.
   GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aBaseShapesList);
-  ListOfShape aCombined, aFree;
-  GeomAlgoAPI_ShapeTools::combineShapes(
-    aCompound,
-    aType,
-    aCombined,
-    aFree);
-
-  if(aFree.size() > 0 || aCombined.size() > 1) {
+  ListOfShape aResults;
+  GeomAlgoAPI_ShapeTools::combineShapes(aCompound, aType, aResults);
+
+  if(aResults.size() > 1 || (aResults.size() == 1 && aResults.front()->shapeType() > aType)) {
     theError = "Error: Not all shapes have shared topology.";
     return false;
   }
@@ -1015,9 +1229,11 @@ bool FeaturesPlugin_ValidatorConcealedResult::isValid(const AttributePtr& theAtt
                                             Events_InfoMessage& theError) const
 {
   if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
+// LCOV_EXCL_START
     theError = "Error: The attribute with the %1 type is not processed";
     theError.arg(theAttribute->attributeType());
     return false;
+// LCOV_EXCL_STOP
   }
 
   AttributeReferencePtr aRefAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeReference>
@@ -1078,81 +1294,52 @@ bool FeaturesPlugin_ValidatorBooleanArguments::isValid(
   const std::list<std::string>& theArguments,
   Events_InfoMessage& theError) const
 {
+// LCOV_EXCL_START
   if (theArguments.size() != 2)
   {
     theError = "Wrong number of arguments (expected 2).";
     return false;
   }
+// LCOV_EXCL_STOP
 
-  int anObjectsNb = 0, aToolsNb = 0;
-  //int anOperationType = 0;
+  int anObjectsToolsNb[2] = { 0,  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)
+  for (int* anArgNbIt = anObjectsToolsNb; anIt != aLast; ++anIt, ++anArgNbIt) {
+    AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
+    if (anAttrSelList)
     {
-      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())
+      *anArgNbIt = anAttrSelList->size();
+      if (isAllInSameCompSolid) {
+        for (int anIndex = 0; anIndex < *anArgNbIt; ++anIndex)
         {
-          if (aCompSolid.get())
+          AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
+          ResultPtr aContext = anAttr->context();
+          ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
+          if (aResCompSolidPtr.get())
           {
-            isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
+            if (aCompSolid.get())
+            {
+              isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
+            }
+            else
+            {
+              aCompSolid = aResCompSolidPtr;
+            }
           }
           else
           {
-            aCompSolid = aResCompSolidPtr;
+            isAllInSameCompSolid = false;
+            break;
           }
         }
-        else
-        {
-          isAllInSameCompSolid = false;
-          break;
-        }
       }
     }
   }
-  anIt++;
 
   std::shared_ptr<FeaturesPlugin_Boolean> aFeature =
     std::dynamic_pointer_cast<FeaturesPlugin_Boolean>(theFeature);
@@ -1161,7 +1348,7 @@ bool FeaturesPlugin_ValidatorBooleanArguments::isValid(
   if (anOperationType == FeaturesPlugin_Boolean::BOOL_FUSE)
   {
     // Fuse operation
-    if (anObjectsNb + aToolsNb < 2)
+    if (anObjectsToolsNb[0] + anObjectsToolsNb[1] < 2)
     {
       theError = "Not enough arguments for Fuse operation.";
       return false;
@@ -1174,12 +1361,12 @@ bool FeaturesPlugin_ValidatorBooleanArguments::isValid(
   }
   else
   {
-    if (anObjectsNb < 1)
+    if (anObjectsToolsNb[0] < 1) // check number of objects
     {
       theError = "Objects not selected.";
       return false;
     }
-    if (aToolsNb < 1)
+    if (anObjectsToolsNb[1] < 1) // check number of tools
     {
       theError = "Tools not selected.";
       return false;
@@ -1195,6 +1382,7 @@ bool FeaturesPlugin_ValidatorBooleanArguments::isValid(
 }
 
 //=================================================================================================
+// LCOV_EXCL_START
 bool FeaturesPlugin_ValidatorBooleanArguments::isNotObligatory(std::string theFeature,
                                                                std::string theAttribute)
 {
@@ -1205,6 +1393,7 @@ bool FeaturesPlugin_ValidatorBooleanArguments::isNotObligatory(std::string theFe
 
   return false;
 }
+// LCOV_EXCL_STOP
 
 //==================================================================================================
 bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid(
@@ -1218,9 +1407,11 @@ bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid(
   AttributeSelectionListPtr anAttrSelectionList =
     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
   if (!aFeature.get() || !anAttrSelectionList.get()) {
+// LCOV_EXCL_START
     theError =
       "Error: Validator used in wrong feature or attribute";
     return false;
+// LCOV_EXCL_STOP
   }
 
   AttributeSelectionListPtr anOtherAttrSelectionList;
@@ -1246,9 +1437,12 @@ bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid(
 
     ResultPtr aContext = anAttrSelection->context();
     std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
-    GeomShapePtr aContextShape = aContext->shape();
     if (!aShape.get()) {
-      aShape = aContextShape;
+      if (!aContext.get()) {
+        theError = "Error: Empty selection.";
+        return false;
+      }
+      aShape = aContext->shape();
     }
 
     if (aShape->isSolid() || aShape->isCompSolid()) {
@@ -1328,15 +1522,6 @@ bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid(
         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();
@@ -1357,6 +1542,7 @@ bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid(
 }
 
 //==================================================================================================
+// LCOV_EXCL_START
 bool FeaturesPlugin_IntersectionSelection::isValid(const AttributePtr& theAttribute,
                                                    const std::list<std::string>& theArguments,
                                                    Events_InfoMessage& theError) const
@@ -1425,8 +1611,10 @@ bool FeaturesPlugin_IntersectionSelection::isValid(const AttributePtr& theAttrib
 
   return true;
 }
+// LCOV_EXCL_STOP
 
 //==================================================================================================
+// LCOV_EXCL_START
 bool FeaturesPlugin_ValidatorBooleanFuseSelection::isValid(
   const AttributePtr& theAttribute,
   const std::list<std::string>& theArguments,
@@ -1478,6 +1666,7 @@ bool FeaturesPlugin_ValidatorBooleanFuseSelection::isValid(
 
   return true;
 }
+// LCOV_EXCL_STOP
 
 //=================================================================================================
 bool FeaturesPlugin_ValidatorBooleanFuseArguments::isValid(
@@ -1485,10 +1674,12 @@ bool FeaturesPlugin_ValidatorBooleanFuseArguments::isValid(
   const std::list<std::string>& theArguments,
   Events_InfoMessage& theError) const
 {
+// LCOV_EXCL_START
   if (theArguments.size() != 2) {
     theError = "Wrong number of arguments (expected 2).";
     return false;
   }
+// LCOV_EXCL_STOP
 
   std::shared_ptr<FeaturesPlugin_BooleanFuse> aFeature =
     std::dynamic_pointer_cast<FeaturesPlugin_BooleanFuse>(theFeature);
@@ -1551,15 +1742,13 @@ bool FeaturesPlugin_ValidatorBooleanFuseArguments::isValid(
   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;
 }
 
 //=================================================================================================
+// LCOV_EXCL_START
 bool FeaturesPlugin_ValidatorBooleanFuseArguments::isNotObligatory(
   std::string theFeature,
   std::string theAttribute)
@@ -1570,8 +1759,10 @@ bool FeaturesPlugin_ValidatorBooleanFuseArguments::isNotObligatory(
 
   return false;
 }
+// LCOV_EXCL_STOP
 
 //==================================================================================================
+// LCOV_EXCL_START
 bool FeaturesPlugin_ValidatorBooleanCommonSelection::isValid(
   const AttributePtr& theAttribute,
   const std::list<std::string>& theArguments,
@@ -1592,7 +1783,7 @@ bool FeaturesPlugin_ValidatorBooleanCommonSelection::isValid(
       return false;
     }
     ResultPtr aContext = anAttrSelection->context();
-    if (!aContext.get()) {
+    if (!aContext.get() && !anAttrSelection->contextFeature().get()) {
       theError = "Error: Empty selection context.";
       return false;
     }
@@ -1605,7 +1796,10 @@ bool FeaturesPlugin_ValidatorBooleanCommonSelection::isValid(
       }
     }
     std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
-    GeomShapePtr aContextShape = aContext->shape();
+    GeomShapePtr aContextShape;
+    if (aContext.get()) {
+      aContextShape = aContext->shape();
+    }
     if (!aShape.get()) {
       aShape = aContextShape;
     }
@@ -1613,7 +1807,7 @@ bool FeaturesPlugin_ValidatorBooleanCommonSelection::isValid(
       theError = "Error: Empty shape.";
       return false;
     }
-    if (!aShape->isEqual(aContextShape)) {
+    if (aContextShape.get() && !aShape->isEqual(aContextShape)) {
       theError = "Error: Local selection not allowed.";
       return false;
     }
@@ -1626,6 +1820,7 @@ bool FeaturesPlugin_ValidatorBooleanCommonSelection::isValid(
 
   return true;
 }
+// LCOV_EXCL_STOP
 
 //=================================================================================================
 bool FeaturesPlugin_ValidatorBooleanCommonArguments::isValid(
@@ -1634,8 +1829,10 @@ bool FeaturesPlugin_ValidatorBooleanCommonArguments::isValid(
   Events_InfoMessage& theError) const
 {
   if (theArguments.size() != 2) {
+// LCOV_EXCL_START
     theError = "Wrong number of arguments (expected 2).";
     return false;
+// LCOV_EXCL_STOP
   }
 
   std::shared_ptr<FeaturesPlugin_BooleanCommon> aFeature =
@@ -1672,9 +1869,50 @@ bool FeaturesPlugin_ValidatorBooleanCommonArguments::isValid(
 }
 
 //=================================================================================================
+// LCOV_EXCL_START
 bool FeaturesPlugin_ValidatorBooleanCommonArguments::isNotObligatory(
   std::string theFeature,
   std::string theAttribute)
 {
   return false;
 }
+// LCOV_EXCL_STOP
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorDefeaturingSelection::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()) {
+    // LCOV_EXCL_START
+    theError = "Error: This validator can only work with selection list attributes.";
+    return false;
+    // LCOV_EXCL_STOP
+  }
+
+  // Check selected entities are sub-shapes of solid or compsolid
+  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;
+    }
+
+    GeomShapePtr aContextShape = aContext->shape();
+    if (aContextShape->shapeType() != GeomAPI_Shape::SOLID) {
+      theError = "Error: Not all selected shapes are sub-shapes of solids.";
+      return false;
+    }
+  }
+
+  return true;
+}