Salome HOME
Issue #1863: Edit multi-lines
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Validators.cpp
index 7cf005d96cc3cfb2aa1b9c88d5dea37b4ab9ac3a..107815387167cc41b77a3484e754f0eaeb1f4f2b 100644 (file)
@@ -6,35 +6,46 @@
 
 #include "FeaturesPlugin_Validators.h"
 
+#include "FeaturesPlugin_Union.h"
+
+#include <Events_InfoMessage.h>
+
 #include <ModelAPI_Attribute.h>
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_ResultConstruction.h>
-
-#include <Events_Error.h>
+#include <ModelAPI_Tools.h>
 
 #include <GeomValidators_BodyShapes.h>
 #include <GeomValidators_FeatureKind.h>
 #include <GeomValidators_ShapeType.h>
 
 #include <GeomAPI_DataMapOfShapeShape.h>
+#include <GeomAPI_Lin.h>
 #include <GeomAPI_PlanarEdges.h>
 #include <GeomAPI_ShapeExplorer.h>
 #include <GeomAPI_ShapeIterator.h>
 
+#include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_ShapeBuilder.h>
 #include <GeomAlgoAPI_ShapeTools.h>
 #include <GeomAlgoAPI_WireBuilder.h>
 
+#define _USE_MATH_DEFINES
+#include <math.h>
+
 //==================================================================================================
 bool FeaturesPlugin_ValidatorPipePath::isValid(const AttributePtr& theAttribute,
                                                const std::list<std::string>& theArguments,
-                                               std::string& theError) const
+                                               Events_InfoMessage& theError) const
 {
-  AttributeSelectionPtr aPathAttrSelection = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+  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.";
     return false;
@@ -47,7 +58,8 @@ bool FeaturesPlugin_ValidatorPipePath::isValid(const AttributePtr& theAttribute,
     return false;
   }
   GeomShapePtr aContextShape = aContext->shape();
-  if(aPathShape.get() && aPathShape->shapeType() == GeomAPI_Shape::WIRE && !aPathShape->isEqual(aContextShape)) {
+  if(aPathShape.get() && aPathShape->shapeType() == GeomAPI_Shape::WIRE && 
+      !aPathShape->isEqual(aContextShape)) {
     theError = "Error: Local selection of wires not allowed.";
     return false;
   }
@@ -56,22 +68,25 @@ bool FeaturesPlugin_ValidatorPipePath::isValid(const AttributePtr& theAttribute,
 }
 
 //==================================================================================================
-bool FeaturesPlugin_ValidatorPipeLocations::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
-                                                    const std::list<std::string>& theArguments,
-                                                    std::string& theError) const
+bool FeaturesPlugin_ValidatorPipeLocations::isValid(
+  const std::shared_ptr<ModelAPI_Feature>& theFeature,
+  const std::list<std::string>& theArguments,
+  Events_InfoMessage& theError) const
 {
   static const std::string aCreationMethodID = "creation_method";
   static const std::string aBaseObjectsID = "base_objects";
   static const std::string aLocationsID = "locations_objects";
 
   if(theFeature->getKind() != "Pipe") {
-    theError = "Error: Feature \"" + theFeature->getKind() + "\" does not supported by this validator.";
+    theError = "Error: Feature \"%1\" does not supported by this validator.";
+    theError.arg(theFeature->getKind());
     return false;
   }
 
   AttributeStringPtr aCreationMethodAttr = theFeature->string(aCreationMethodID);
   if(!aCreationMethodAttr.get()) {
-    theError = "Error: Could not get \"" + aCreationMethodID + "\" attribute.";
+    theError = "Error: Could not get \"%1\" attribute.";
+    theError.arg(aCreationMethodID);
     return false;
   }
 
@@ -81,17 +96,20 @@ bool FeaturesPlugin_ValidatorPipeLocations::isValid(const std::shared_ptr<ModelA
 
   AttributeSelectionListPtr aBaseObjectsSelectionList = theFeature->selectionList(aBaseObjectsID);
   if(!aBaseObjectsSelectionList.get()) {
-    theError = "Error: Could not get \"" + aBaseObjectsID + "\" attribute.";
+    theError = "Error: Could not get \"%1\" attribute.";
+    theError.arg(aBaseObjectsID);
     return false;
   }
 
   AttributeSelectionListPtr aLocationsSelectionList = theFeature->selectionList(aLocationsID);
   if(!aLocationsSelectionList.get()) {
-    theError = "Error: Could not get \"" + aBaseObjectsID + "\" attribute.";
+    theError = "Error: Could not get \"%1\" attribute.";
+    theError.arg(aBaseObjectsID);
     return false;
   }
 
-  if(aLocationsSelectionList->size() > 0 && aLocationsSelectionList->size() != aBaseObjectsSelectionList->size()) {
+  if(aLocationsSelectionList->size() > 0 && 
+     aLocationsSelectionList->size() != aBaseObjectsSelectionList->size()) {
     theError = "Error: Number of locations should be the same as base objects.";
     return false;
   }
@@ -100,7 +118,8 @@ bool FeaturesPlugin_ValidatorPipeLocations::isValid(const std::shared_ptr<ModelA
 }
 
 //==================================================================================================
-bool FeaturesPlugin_ValidatorPipeLocations::isNotObligatory(std::string theFeature, std::string theAttribute)
+bool FeaturesPlugin_ValidatorPipeLocations::isNotObligatory(std::string theFeature, 
+                                                            std::string theAttribute)
 {
   return false;
 }
@@ -108,7 +127,7 @@ bool FeaturesPlugin_ValidatorPipeLocations::isNotObligatory(std::string theFeatu
 //==================================================================================================
 bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theAttribute,
                                                         const std::list<std::string>& theArguments,
-                                                        std::string& theError) const
+                                                        Events_InfoMessage& theError) const
 {
   if(theArguments.empty()) {
     theError = "Error: Validator parameters is empty.";
@@ -128,29 +147,57 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
   GeomAPI_DataMapOfShapeShape aSelectedWiresFromObjects;
   std::string anAttributeType = theAttribute->attributeType();
   if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
-    AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+    AttributeSelectionListPtr aListAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
     for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
       AttributeSelectionPtr aSelectionAttr = aListAttr->value(anIndex);
-      ResultConstructionPtr aContext = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aSelectionAttr->context());
+      ResultPtr aContext = aSelectionAttr->context();
       if(!aContext.get()) {
-        // It is not a result construction, continue.
+        theError = "Error: Empty context.";
+        return false;
+      }
+
+      ResultConstructionPtr aResultConstruction = 
+        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.
+        GeomShapePtr aShape = aSelectionAttr->value();
+        if(!aShape.get()) {
+          aShape = aContext->shape();
+        }
+
+        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
+                && aSubShape->shapeType() != GeomAPI_Shape::FACE) {
+              theError = "Error: Compound should contain only faces and edges.";
+              return false;
+            }
+          }
+        }
+
         continue;
       }
 
       GeomShapePtr aShape = aSelectionAttr->value();
-      GeomShapePtr aContextShape = aContext->shape();
+      GeomShapePtr aContextShape = aResultConstruction->shape();
       if(!aShape.get()) {
         // Whole sketch selected.
-        if(aSelectedSketchesFromObjects.find(aContext) != aSelectedSketchesFromObjects.cend()) {
-          theError = "Error: Object from this sketch is already selected. Sketch is not allowed for selection.";
+        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(aContext);
+        aSelectedSketches.insert(aResultConstruction);
       } else {
         // Object from sketch selected.
-        if(aSelectedSketches.find(aContext) != aSelectedSketches.cend()) {
-          theError = "Error: Whole sketch with this object is already selected. Don't allow to select this object.";
+        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;
         }
 
@@ -162,12 +209,13 @@ 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.";
+            theError = 
+              "Error: Objects with such wire already selected. Don't allow to select this object.";
             return false;
           }
 
           aSelectedWiresFromObjects.bind(aWire, aWire);
-          aSelectedSketchesFromObjects.insert(aContext);
+          aSelectedSketchesFromObjects.insert(aResultConstruction);
         }
       }
     }
@@ -178,8 +226,8 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
 
 //==================================================================================================
 bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const AttributePtr& theAttribute,
-                                                                 const std::list<std::string>& theArguments,
-                                                                 std::string& theError) const
+                                                        const std::list<std::string>& theArguments,
+                                                        Events_InfoMessage& theError) const
 {
   if(!theAttribute.get()) {
     theError = "Error: Empty attribute.";
@@ -188,7 +236,8 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
 
   std::string anAttributeType = theAttribute->attributeType();
   if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
-    AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+    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.
       if(!isValidAttribute(aListAttr->value(anIndex), theArguments, theError)) {
@@ -197,7 +246,8 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
     }
   } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
     // Getting context.
-    AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+    AttributeSelectionPtr anAttr = 
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
     ResultPtr aContext = anAttr->context();
     if(!aContext.get()) {
       theError = "Error: Attribute have empty context.";
@@ -214,7 +264,8 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
       return false;
     }
 
-    ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+    ResultConstructionPtr aConstruction = 
+      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
     if(aConstruction.get()) {
       // Construciotn selected. Check that is is not infinite.
       if(aConstruction->isInfinite()) {
@@ -229,7 +280,8 @@ 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 || aShape->shapeType() == GeomAPI_Shape::FACE) {
+        if(aShape->shapeType() == GeomAPI_Shape::WIRE || 
+           aShape->shapeType() == GeomAPI_Shape::FACE) {
           return true;
         }
       }
@@ -239,25 +291,30 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
 
     if(!aShape->isEqual(aContextShape)) {
       // Local selection on body does not allowed.
-      theError = "Error: Selected shape is in the local selection. Only global selection is allowed.";
+      theError =
+        "Error: Selected shape is in the local selection. Only global selection is allowed.";
       return false;
     }
 
     // Check that object is a shape with allowed type.
     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), and whole objects with shape types: ";
-      std::list<std::string>::const_iterator anIt = theArguments.cbegin();
-      theError += *anIt;
-      for(++anIt; anIt != theArguments.cend(); ++anIt) {
-        theError += ", " + *anIt;
+      theError = "Error: Selected shape has unacceptable type. Acceptable types are: faces or "
+                 "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) {
+        if (!anArgumentString.empty())
+          anArgumentString += ", ";
+        anArgumentString += *anIt;
       }
+      theError.arg(anArgumentString);
       return false;
     }
 
   } else {
-    theError = "Error: Attribute \"" + anAttributeType + "\" does not supported by this validator.";
+    theError = "Error: Attribute \"%1\" does not supported by this validator.";
+    theError.arg(anAttributeType);
     return false;
   }
 
@@ -267,14 +324,16 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
 //==================================================================================================
 bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theAttribute,
                                                         const std::list<std::string>& theArguments,
-                                                        std::string& theError) const
+                                                        Events_InfoMessage& theError) const
 {
   if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
-    theError = "Error: The attribute with the " + theAttribute->attributeType() + " type is not processed";
+    theError = "Error: The attribute with the %1 type is not processed";
+    theError.arg(theAttribute->attributeType());
     return false;
   }
   if (theArguments.size() != 2) {
-    theError = "Error: Wrong parameters in XML definition for " + theAttribute->attributeType() + " type";
+    theError = "Error: Wrong parameters in XML definition for %1 type";
+    theError.arg(theAttribute->attributeType());
     return false;
   }
   // first argument is for the base attribute, second - for skipping feature kind
@@ -283,7 +342,8 @@ bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theA
   FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
   AttributePtr aBaseAttribute = aFeature->attribute(aBaseAttributeId);
   if (!aBaseAttribute.get()) {
-    theError = "Wrong parameters in XML definition for " + theAttribute->attributeType() + " type";
+    theError = "Wrong parameters in XML definition for %1 type";
+    theError.arg(theAttribute->attributeType());
     return false;
   }
   if (aBaseAttribute->isInitialized()) // when base list of composite feature is already filled,
@@ -310,60 +370,105 @@ bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theA
 }
 
 //==================================================================================================
-bool FeaturesPlugin_ValidatorCanBeEmpty::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
-                                                 const std::list<std::string>& theArguments,
-                                                 std::string& theError) const
+bool FeaturesPlugin_ValidatorExtrusionDir::isValid(
+                                               const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                               const std::list<std::string>& theArguments,
+                                               Events_InfoMessage& theError) const
 {
   if(theArguments.size() != 2) {
     theError = "Error: Validator should be used with 2 parameters for extrusion.";
     return false;
   }
 
-  std::list<std::string>::const_iterator anArgsIt = theArguments.begin(), aLast = theArguments.end();
+  std::list<std::string>::const_iterator 
+    anArgsIt = theArguments.begin(), aLast = theArguments.end();
 
   AttributePtr aCheckAttribute = theFeature->attribute(*anArgsIt);
   ++anArgsIt;
 
-  if(isShapesCanBeEmpty(aCheckAttribute, theError)) {
-    return true;
-  }
-
+  GeomShapePtr aDirShape;
   AttributeSelectionPtr aSelAttr = theFeature->selection(*anArgsIt);
-  if(!aSelAttr.get()) {
-    theError = "Error: Could not get selection attribute \"" + *anArgsIt + "\".";
-    return false;
+  if(aSelAttr.get()) {
+    aDirShape = aSelAttr->value();
+    if(!aDirShape.get()) {
+      ResultPtr aContext = aSelAttr->context();
+      if(aContext.get()) {
+        aDirShape = aContext->shape();
+      }
+    }
   }
 
-  GeomShapePtr aShape = aSelAttr->value();
-  if(!aShape.get()) {
-    ResultPtr aContext = aSelAttr->context();
-    if(!aContext.get()) {
-      theError = "Error: Base objects list contains vertex or edge, so attribute \"" + *anArgsIt
-               + "\" can not be used with default value. Select direction for extrusion.";
+  if(!aDirShape.get()) {
+    // Check that dir can be empty.
+    if(!isShapesCanBeEmpty(aCheckAttribute, theError)) {
+      theError = "Error: Base objects list contains vertex or edge, so attribute \"%1\" "
+                 "can not be used with default value. Select direction for extrusion.";
+      theError.arg(*anArgsIt);
       return false;
+    } else {
+      return true;
     }
-
-    aShape = aContext->shape();
   }
 
-  if(!aShape.get()) {
-    theError = "Error: Base objects list contains vertex or edge, so attribute \"" + *anArgsIt
-              + "\" can not be used with default value. Select direction for extrusion.";
-    return false;
+  std::shared_ptr<GeomAPI_Edge> aDirEdge(new GeomAPI_Edge(aDirShape));
+
+  // If faces selected check that direction not parallel with them.
+  AttributeSelectionListPtr aListAttr = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aCheckAttribute);
+  for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
+    AttributeSelectionPtr anAttr = aListAttr->value(anIndex);
+    GeomShapePtr aShapeInList = anAttr->value();
+    if(!aShapeInList.get()) {
+      aShapeInList = anAttr->context()->shape();
+    }
+    bool isParallel = true;
+    if(aShapeInList->shapeType() == GeomAPI_Shape::FACE || 
+       aShapeInList->shapeType() == GeomAPI_Shape::SHELL) {
+      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);
+        if(isParallel) {
+          break;
+        }
+      }
+    } else if(aShapeInList->shapeType() == GeomAPI_Shape::COMPOUND) {
+      std::shared_ptr<GeomAPI_PlanarEdges> aPlanarEdges = 
+        std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapeInList);
+      if(aPlanarEdges.get()) {
+        std::shared_ptr<GeomAPI_Dir> aSketchDir = aPlanarEdges->norm();
+        if(aDirEdge->isLine()) {
+          std::shared_ptr<GeomAPI_Dir> aDir = aDirEdge->line()->direction();
+          isParallel = fabs(aSketchDir->angle(aDir) - M_PI / 2.0) < 10e-7;
+        } else {
+          isParallel = false;
+        }
+      } else {
+        isParallel = false;
+      }
+    } else {
+      isParallel = false;
+    }
+    if(isParallel) {
+      theError = 
+        "Error: Direction is parallel to one of the selected face or face on selected shell.";
+      return false;
+    }
   }
 
   return true;
 }
 
 //==================================================================================================
-bool FeaturesPlugin_ValidatorCanBeEmpty::isNotObligatory(std::string theFeature, std::string theAttribute)
+bool FeaturesPlugin_ValidatorExtrusionDir::isNotObligatory(std::string theFeature, 
+                                                           std::string theAttribute)
 {
   return false;
 }
 
 //==================================================================================================
-bool FeaturesPlugin_ValidatorCanBeEmpty::isShapesCanBeEmpty(const AttributePtr& theAttribute,
-                                                            std::string& theError) const
+bool FeaturesPlugin_ValidatorExtrusionDir::isShapesCanBeEmpty(const AttributePtr& theAttribute,
+                                                              Events_InfoMessage& theError) const
 {
   if(!theAttribute.get()) {
     return true;
@@ -371,7 +476,8 @@ bool FeaturesPlugin_ValidatorCanBeEmpty::isShapesCanBeEmpty(const AttributePtr&
 
   std::string anAttributeType = theAttribute->attributeType();
   if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
-    AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+    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.
       if(!isShapesCanBeEmpty(aListAttr->value(anIndex), theError)) {
@@ -380,7 +486,8 @@ bool FeaturesPlugin_ValidatorCanBeEmpty::isShapesCanBeEmpty(const AttributePtr&
     }
   } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
     // Getting context.
-    AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+    AttributeSelectionPtr anAttr = 
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
     ResultPtr aContext = anAttr->context();
     if(!aContext.get()) {
       return false;
@@ -410,11 +517,13 @@ bool FeaturesPlugin_ValidatorCanBeEmpty::isShapesCanBeEmpty(const AttributePtr&
 //==================================================================================================
 bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAttribute,
                                                        const std::list<std::string>& theArguments,
-                                                       std::string& theError) const
+                                                       Events_InfoMessage& theError) const
 {
-  AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+  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.";
+    theError = 
+      "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());
@@ -438,13 +547,19 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt
       return false;
     }
     std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
+    GeomShapePtr aContextShape = aContext->shape();
     if(!aShape.get()) {
-      aShape = aContext->shape();
+      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();
     if(anOperationType == 1) {
       // Fuse operation. Allow to select edges, faces and solids.
@@ -471,10 +586,11 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt
 
 //==================================================================================================
 bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& theAttribute,
-                                                         const std::list<std::string>& theArguments,
-                                                         std::string& theError) const
+                                                       const std::list<std::string>& theArguments,
+                                                       Events_InfoMessage& theError) const
 {
-  AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+  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.";
     return false;
@@ -494,26 +610,37 @@ bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& the
     }
 
     ResultPtr aContext = aSelectAttr->context();
-    ResultConstructionPtr aResultConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+    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 = 
+      std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aContext);
+    if(aResultCompsolid.get()) {
+      continue;
     }
 
     theError = "Error: Only body shapes and construction planes are allowed for selection.";
     return false;
   }
 
+  theError = "";
   return true;
 }
 
 //==================================================================================================
 bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePtr& theAttribute,
-                                                               const std::list<std::string>& theArguments,
-                                                               std::string& theError) const
+                                                     const std::list<std::string>& theArguments,
+                                                     Events_InfoMessage& theError) const
 {
-  AttributeSelectionListPtr aSubShapesAttrList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+  AttributeSelectionListPtr aSubShapesAttrList = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
   if(!aSubShapesAttrList.get()) {
-    theError = "Error: This validator can only work with selection list in \"Remove Sub-Shapes\" feature.";
+    theError = 
+      "Error: This validator can only work with selection list in \"Remove Sub-Shapes\" feature.";
     return false;
   }
 
@@ -522,7 +649,8 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePt
   AttributeSelectionPtr aShapeAttrSelection = aFeature->selection(aBaseShapeID);
 
   if(!aShapeAttrSelection.get()) {
-    theError = "Error: Could not get \"" + aBaseShapeID + "\" attribute.";
+    theError = "Error: Could not get \"%1\" attribute.";
+    theError.arg(aBaseShapeID);
     return false;
   }
 
@@ -560,33 +688,38 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePt
 }
 
 //==================================================================================================
-bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
-                                                            const std::list<std::string>& theArguments,
-                                                            std::string& theError) const
+bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(
+  const std::shared_ptr<ModelAPI_Feature>& theFeature,
+  const std::list<std::string>& theArguments,
+  Events_InfoMessage& theError) const
 {
   static const std::string aBaseShapeID = "base_shape";
   static const std::string aSubShapesID = "subshapes";
 
   if(theFeature->getKind() != "Remove_SubShapes") {
-    theError = "Error: Feature \"" + theFeature->getKind() + "\" does not supported by this validator.";
+    theError = "Error: Feature \"%1\" does not supported by this validator.";
+    theError.arg(theFeature->getKind());
     return false;
   }
 
   AttributeSelectionPtr aShapeAttrSelection = theFeature->selection(aBaseShapeID);
   if(!aShapeAttrSelection.get()) {
-    theError = "Error: Could not get \"" + aBaseShapeID + "\" attribute.";
+    theError = "Error: Could not get \"%1\" attribute.";
+    theError.arg(aBaseShapeID);
     return false;
   }
 
   AttributeSelectionListPtr aSubShapesAttrList = theFeature->selectionList(aSubShapesID);
   if(!aSubShapesAttrList.get()) {
-    theError = "Error: Could not get \"" + aSubShapesID + "\" attribute.";
+    theError = "Error: Could not get \"%1\" attribute.";
+    theError.arg(aSubShapesID);
     return false;
   }
 
   // Copy base shape.
   GeomShapePtr aBaseShape = aShapeAttrSelection->value();
   if(!aBaseShape.get()) {
+    theError = "Error: Base shape is empty.";
     return false;
   }
   GeomShapePtr aResultShape = aBaseShape->emptyCopied();
@@ -613,3 +746,128 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isNotObligatory(std::string
 {
   return false;
 }
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttribute,
+                                                     const std::list<std::string>& theArguments,
+                                                     Events_InfoMessage& theError) const
+{
+  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.";
+    theError.arg(FeaturesPlugin_Union::ID());
+    return false;
+  }
+
+  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());
+    if(!aResult.get()) {
+      continue;
+    }
+    if(aResult->numberOfSubs() > 0) {
+      theError = "Error: Whole compsolids not allowed for selection.";
+      return false;
+    }
+  }
+
+  return true;
+}
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorUnionArguments::isValid(
+  const std::shared_ptr<ModelAPI_Feature>& theFeature,
+  const std::list<std::string>& theArguments,
+  Events_InfoMessage& theError) const
+{
+  // Check feature kind.
+  if(theFeature->getKind() != FeaturesPlugin_Union::ID()) {
+    theError = "Error: This validator supports only \"%1\" feature.";
+    theError.arg(FeaturesPlugin_Union::ID());
+    return false;
+  }
+
+  // Get base objects attribute list.
+  AttributeSelectionListPtr aBaseObejctsAttrList = 
+    theFeature->selectionList(FeaturesPlugin_Union::BASE_OBJECTS_ID());
+  if(!aBaseObejctsAttrList.get()) {
+    theError = "Error: Could not get \"%1\" attribute.";
+    theError.arg(FeaturesPlugin_Union::BASE_OBJECTS_ID());
+    return false;
+  }
+
+  // Get all shapes.
+  ListOfShape aBaseShapesList;
+  for(int anIndex = 0; anIndex < aBaseObejctsAttrList->size(); ++anIndex) {
+    AttributeSelectionPtr anAttrSelectionInList = aBaseObejctsAttrList->value(anIndex);
+    GeomShapePtr aShape = anAttrSelectionInList->value();
+    aBaseShapesList.push_back(aShape);
+  }
+
+  // Make componud and find connected.
+  GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aBaseShapesList);
+  ListOfShape aCombined, aFree;
+  GeomAlgoAPI_ShapeTools::combineShapes(aCompound, GeomAPI_Shape::COMPSOLID, aCombined, aFree);
+
+  if(aFree.size() > 0 || aCombined.size() > 1) {
+    theError = "Error: Not all shapes have shared topology.";
+    return false;
+  }
+
+  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
+{
+  if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
+    theError = "Error: The attribute with the %1 type is not processed";
+    theError.arg(theAttribute->attributeType());
+    return false;
+  }
+
+  AttributeReferencePtr aRefAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeReference>
+                                                                               (theAttribute);
+  ObjectPtr aRefObject = aRefAttribute->value();
+  if (!aRefObject.get()) {
+    theError = "Error: Empty feature.";
+    return false;
+  }
+
+  FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aRefObject);
+  if (!aRefFeature.get()) {
+    theError = "Error: Empty feature.";
+    return false;
+  }
+  std::list<std::shared_ptr<ModelAPI_Result> > aResults;
+  ModelAPI_Tools::getConcealedResults(aRefFeature, aResults);
+
+  size_t aConcealedResults = aResults.size();
+  if (!aConcealedResults && !theArguments.empty()) {
+    // find if these results are touched by the feature in another attribute
+    std::list<std::string>::const_iterator anIt = theArguments.begin();
+    std::string aRecoveredList = *anIt;
+    if (!aRecoveredList.empty()) {
+      std::shared_ptr<ModelAPI_AttributeRefList> aParameterList =
+                                 theAttribute->owner()->data()->reflist(aRecoveredList);
+      if (aParameterList.get())
+        aConcealedResults = aParameterList->size();
+    }
+  }
+
+  if (aConcealedResults == 0)
+    theError = "Error: No concealed results.";
+
+  return theError.empty();
+}