]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/FeaturesPlugin/FeaturesPlugin_Validators.cpp
Salome HOME
Implementation of 3D Fillet operation
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Validators.cpp
index 107815387167cc41b77a3484e754f0eaeb1f4f2b..4c53bcbb2bf6b58047f571810267a58d4d249803 100644 (file)
@@ -1,11 +1,26 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File:        FeaturesPlugin_Validators.cpp
-// Created:     22 March 2016
-// Author:      Dmitry Bobylev
+// Copyright (C) 2014-2017  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// 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
+//
+// 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_Union.h"
 
 #include <Events_InfoMessage.h>
@@ -44,7 +59,7 @@ bool FeaturesPlugin_ValidatorPipePath::isValid(const AttributePtr& theAttribute,
                                                const std::list<std::string>& theArguments,
                                                Events_InfoMessage& theError) const
 {
-  AttributeSelectionPtr aPathAttrSelection = 
+  AttributeSelectionPtr aPathAttrSelection =
     std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
   if(!aPathAttrSelection.get()) {
     theError = "Error: This validator can only work with path selector in \"Pipe\" feature.";
@@ -58,7 +73,7 @@ bool FeaturesPlugin_ValidatorPipePath::isValid(const AttributePtr& theAttribute,
     return false;
   }
   GeomShapePtr aContextShape = aContext->shape();
-  if(aPathShape.get() && aPathShape->shapeType() == GeomAPI_Shape::WIRE && 
+  if(aPathShape.get() && aPathShape->shapeType() == GeomAPI_Shape::WIRE &&
       !aPathShape->isEqual(aContextShape)) {
     theError = "Error: Local selection of wires not allowed.";
     return false;
@@ -108,7 +123,7 @@ bool FeaturesPlugin_ValidatorPipeLocations::isValid(
     return false;
   }
 
-  if(aLocationsSelectionList->size() > 0 && 
+  if(aLocationsSelectionList->size() > 0 &&
      aLocationsSelectionList->size() != aBaseObjectsSelectionList->size()) {
     theError = "Error: Number of locations should be the same as base objects.";
     return false;
@@ -118,7 +133,7 @@ bool FeaturesPlugin_ValidatorPipeLocations::isValid(
 }
 
 //==================================================================================================
-bool FeaturesPlugin_ValidatorPipeLocations::isNotObligatory(std::string theFeature, 
+bool FeaturesPlugin_ValidatorPipeLocations::isNotObligatory(std::string theFeature,
                                                             std::string theAttribute)
 {
   return false;
@@ -142,8 +157,6 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
     return false;
   }
 
-  std::set<ResultConstructionPtr> aSelectedSketches;
-  std::set<ResultConstructionPtr> aSelectedSketchesFromObjects;
   GeomAPI_DataMapOfShapeShape aSelectedWiresFromObjects;
   std::string anAttributeType = theAttribute->attributeType();
   if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
@@ -157,10 +170,10 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
         return false;
       }
 
-      ResultConstructionPtr aResultConstruction = 
+      ResultConstructionPtr aResultConstruction =
         std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
       if(!aResultConstruction.get()) {
-        // It is not a result construction. 
+        // It is not a result construction.
         // If shape is compound check that it contains only faces and edges.
         GeomShapePtr aShape = aSelectionAttr->value();
         if(!aShape.get()) {
@@ -185,22 +198,9 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
       GeomShapePtr aContextShape = aResultConstruction->shape();
       if(!aShape.get()) {
         // Whole sketch selected.
-        if(aSelectedSketchesFromObjects.find(aResultConstruction) !=
-            aSelectedSketchesFromObjects.cend()) {
-          theError = "Error: Object from this sketch is already selected. "
-                     "Sketch is not allowed for selection.";
-          return false;
-        }
-
-        aSelectedSketches.insert(aResultConstruction);
+        continue;
       } else {
         // Object from sketch selected.
-        if(aSelectedSketches.find(aResultConstruction) != aSelectedSketches.cend()) {
-          theError = "Error: Whole sketch with this object is already selected. "
-                     "Don't allow to select this object.";
-          return false;
-        }
-
         for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::WIRE); anExp.more(); anExp.next()) {
           GeomShapePtr aWire = anExp.current();
           if(aWire->orientation() != GeomAPI_Shape::FORWARD) {
@@ -209,13 +209,12 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
           }
 
           if(aSelectedWiresFromObjects.isBound(aWire)) {
-            theError = 
+            theError =
               "Error: Objects with such wire already selected. Don't allow to select this object.";
             return false;
           }
 
           aSelectedWiresFromObjects.bind(aWire, aWire);
-          aSelectedSketchesFromObjects.insert(aResultConstruction);
         }
       }
     }
@@ -224,6 +223,73 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
   return true;
 }
 
+//==================================================================================================
+bool FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects::isValid(
+  const std::shared_ptr<ModelAPI_Feature>& theFeature,
+  const std::list<std::string>& theArguments,
+  Events_InfoMessage& theError) const
+{
+  const std::string aBaseObjectsID = theArguments.front();
+
+  AttributeSelectionListPtr aListAttr = theFeature->selectionList(aBaseObjectsID);
+  if(!aListAttr.get()) {
+    theError = "Error: Could not get \"%1\" attribute.";
+    theError.arg(aBaseObjectsID);
+    return false;
+  }
+
+  std::set<ResultConstructionPtr> aSelectedSketches;
+  std::set<ResultConstructionPtr> aSelectedSketchesFromObjects;
+
+  for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
+    AttributeSelectionPtr aSelectionAttr = aListAttr->value(anIndex);
+    ResultPtr aContext = aSelectionAttr->context();
+    if(!aContext.get()) {
+      theError = "Error: Empty context.";
+      return false;
+    }
+
+    ResultConstructionPtr aResultConstruction =
+      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+    if(!aResultConstruction.get()) {
+      // It is not a result construction.
+      continue;
+    }
+
+    GeomShapePtr aShape = aSelectionAttr->value();
+    GeomShapePtr aContextShape = aResultConstruction->shape();
+    if(!aShape.get()) {
+      // Whole sketch selected.
+      aSelectedSketches.insert(aResultConstruction);
+    } else {
+      // Object from sketch selected.
+      aSelectedSketchesFromObjects.insert(aResultConstruction);
+    }
+  }
+
+
+  for(std::set<ResultConstructionPtr>::const_iterator anIt = aSelectedSketches.cbegin();
+      anIt != aSelectedSketches.cend();
+      ++anIt) {
+    ResultConstructionPtr aResultConstruction = *anIt;
+    if(aSelectedSketchesFromObjects.find(aResultConstruction) !=
+        aSelectedSketchesFromObjects.cend()) {
+      theError = "Sketch and objects from it can not be selected at the same time.";
+      return false;
+    }
+  }
+
+  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,
@@ -236,7 +302,7 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
 
   std::string anAttributeType = theAttribute->attributeType();
   if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
-    AttributeSelectionListPtr aListAttr = 
+    AttributeSelectionListPtr aListAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
     for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
       // If at least one attribute is invalid, the result is false.
@@ -246,7 +312,7 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
     }
   } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
     // Getting context.
-    AttributeSelectionPtr anAttr = 
+    AttributeSelectionPtr anAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
     ResultPtr aContext = anAttr->context();
     if(!aContext.get()) {
@@ -264,7 +330,7 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
       return false;
     }
 
-    ResultConstructionPtr aConstruction = 
+    ResultConstructionPtr aConstruction =
       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
     if(aConstruction.get()) {
       // Construciotn selected. Check that is is not infinite.
@@ -280,7 +346,7 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
         }
       } else {
         // Shape on construction selected. Check that it is a face or wire.
-        if(aShape->shapeType() == GeomAPI_Shape::WIRE || 
+        if(aShape->shapeType() == GeomAPI_Shape::WIRE ||
            aShape->shapeType() == GeomAPI_Shape::FACE) {
           return true;
         }
@@ -380,7 +446,7 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isValid(
     return false;
   }
 
-  std::list<std::string>::const_iterator 
+  std::list<std::string>::const_iterator
     anArgsIt = theArguments.begin(), aLast = theArguments.end();
 
   AttributePtr aCheckAttribute = theFeature->attribute(*anArgsIt);
@@ -413,7 +479,7 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isValid(
   std::shared_ptr<GeomAPI_Edge> aDirEdge(new GeomAPI_Edge(aDirShape));
 
   // If faces selected check that direction not parallel with them.
-  AttributeSelectionListPtr aListAttr = 
+  AttributeSelectionListPtr aListAttr =
     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aCheckAttribute);
   for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
     AttributeSelectionPtr anAttr = aListAttr->value(anIndex);
@@ -422,9 +488,9 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isValid(
       aShapeInList = anAttr->context()->shape();
     }
     bool isParallel = true;
-    if(aShapeInList->shapeType() == GeomAPI_Shape::FACE || 
+    if(aShapeInList->shapeType() == GeomAPI_Shape::FACE ||
        aShapeInList->shapeType() == GeomAPI_Shape::SHELL) {
-      for(GeomAPI_ShapeExplorer 
+      for(GeomAPI_ShapeExplorer
           anExp(aShapeInList, GeomAPI_Shape::FACE); anExp.more(); anExp.next()) {
         std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(anExp.current()));
         isParallel = GeomAlgoAPI_ShapeTools::isParallel(aDirEdge, aFace);
@@ -433,7 +499,7 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isValid(
         }
       }
     } else if(aShapeInList->shapeType() == GeomAPI_Shape::COMPOUND) {
-      std::shared_ptr<GeomAPI_PlanarEdges> aPlanarEdges = 
+      std::shared_ptr<GeomAPI_PlanarEdges> aPlanarEdges =
         std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapeInList);
       if(aPlanarEdges.get()) {
         std::shared_ptr<GeomAPI_Dir> aSketchDir = aPlanarEdges->norm();
@@ -450,7 +516,7 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isValid(
       isParallel = false;
     }
     if(isParallel) {
-      theError = 
+      theError =
         "Error: Direction is parallel to one of the selected face or face on selected shell.";
       return false;
     }
@@ -460,7 +526,7 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isValid(
 }
 
 //==================================================================================================
-bool FeaturesPlugin_ValidatorExtrusionDir::isNotObligatory(std::string theFeature, 
+bool FeaturesPlugin_ValidatorExtrusionDir::isNotObligatory(std::string theFeature,
                                                            std::string theAttribute)
 {
   return false;
@@ -476,7 +542,7 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isShapesCanBeEmpty(const AttributePtr
 
   std::string anAttributeType = theAttribute->attributeType();
   if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
-    AttributeSelectionListPtr aListAttr = 
+    AttributeSelectionListPtr aListAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
     for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
       // If at least one attribute is invalid, the result is false.
@@ -486,7 +552,7 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isShapesCanBeEmpty(const AttributePtr
     }
   } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
     // Getting context.
-    AttributeSelectionPtr anAttr = 
+    AttributeSelectionPtr anAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
     ResultPtr aContext = anAttr->context();
     if(!aContext.get()) {
@@ -519,10 +585,10 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt
                                                        const std::list<std::string>& theArguments,
                                                        Events_InfoMessage& theError) const
 {
-  AttributeSelectionListPtr anAttrSelectionList = 
+  AttributeSelectionListPtr anAttrSelectionList =
     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
   if(!anAttrSelectionList.get()) {
-    theError = 
+    theError =
       "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
     return false;
   }
@@ -543,8 +609,11 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt
     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();
@@ -560,24 +629,75 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt
       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) {
+      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;
+    }
+
+    ResultCompSolidPtr aContextOwner = ModelAPI_Tools::compSolidOwner(aContext);
+    GeomShapePtr anOwner = aContextOwner.get() ? aContextOwner->shape() : aContext->shape();
+    if (!aBaseSolid)
+      aBaseSolid = anOwner;
+    else if (!aBaseSolid->isEqual(anOwner)) {
+      theError = "Error: Sub-shapes of different solids have been selected.";
+      return false;
     }
   }
 
@@ -589,7 +709,7 @@ bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& the
                                                        const std::list<std::string>& theArguments,
                                                        Events_InfoMessage& theError) const
 {
-  AttributeSelectionListPtr anAttrSelectionList = 
+  AttributeSelectionListPtr anAttrSelectionList =
     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
   if(!anAttrSelectionList.get()) {
     theError = "Error: This validator can only work with selection list in \"Partition\" feature.";
@@ -610,14 +730,14 @@ bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& the
     }
 
     ResultPtr aContext = aSelectAttr->context();
-    ResultConstructionPtr aResultConstruction = 
+    ResultConstructionPtr aResultConstruction =
       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
     if(aResultConstruction.get()) {
       theError = "Error: Only body shapes and construction planes are allowed for selection.";
       return false;
     }
 
-    ResultCompSolidPtr aResultCompsolid = 
+    ResultCompSolidPtr aResultCompsolid =
       std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aContext);
     if(aResultCompsolid.get()) {
       continue;
@@ -636,10 +756,10 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePt
                                                      const std::list<std::string>& theArguments,
                                                      Events_InfoMessage& theError) const
 {
-  AttributeSelectionListPtr aSubShapesAttrList = 
+  AttributeSelectionListPtr aSubShapesAttrList =
     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
   if(!aSubShapesAttrList.get()) {
-    theError = 
+    theError =
       "Error: This validator can only work with selection list in \"Remove Sub-Shapes\" feature.";
     return false;
   }
@@ -694,7 +814,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.";
@@ -724,6 +844,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);
@@ -752,7 +877,7 @@ bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttr
                                                      const std::list<std::string>& theArguments,
                                                      Events_InfoMessage& theError) const
 {
-  AttributeSelectionListPtr aBaseObjectsAttrList = 
+  AttributeSelectionListPtr aBaseObjectsAttrList =
     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
   if(!aBaseObjectsAttrList.get()) {
     theError = "Error: This validator can only work with selection list in \"%1\" feature.";
@@ -763,11 +888,28 @@ 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();
+
+    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;
+    }
+
+    ResultCompSolidPtr aResult =
+      std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aContext);
     if(!aResult.get()) {
       continue;
     }
+
     if(aResult->numberOfSubs() > 0) {
       theError = "Error: Whole compsolids not allowed for selection.";
       return false;
@@ -791,7 +933,7 @@ bool FeaturesPlugin_ValidatorUnionArguments::isValid(
   }
 
   // Get base objects attribute list.
-  AttributeSelectionListPtr aBaseObejctsAttrList = 
+  AttributeSelectionListPtr aBaseObejctsAttrList =
     theFeature->selectionList(FeaturesPlugin_Union::BASE_OBJECTS_ID());
   if(!aBaseObejctsAttrList.get()) {
     theError = "Error: Could not get \"%1\" attribute.";
@@ -800,17 +942,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.";