Salome HOME
Fix for the problem if disappeared sketch elements (on Apply) inside of sketch in...
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Validators.cpp
index ed019bb64b2018cfc32084f29f9bb1aa0db6a7eb..83ab5ed7515e82e4bd397422b2d8465bb47812ab 100644 (file)
@@ -17,7 +17,9 @@
 #include <GeomValidators_FeatureKind.h>
 #include <GeomValidators_ShapeType.h>
 
+#include <GeomAPI_DataMapOfShapeShape.h>
 #include <GeomAPI_PlanarEdges.h>
+#include <GeomAPI_ShapeExplorer.h>
 #include <GeomAlgoAPI_WireBuilder.h>
 
 //=================================================================================================
@@ -88,6 +90,56 @@ 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()) {
+    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());
+      if(!aContext.get()) {
+        // It is not a result construction, continue.
+        continue;
+      }
+
+      GeomShapePtr aShape = aSelectionAttr->value();
+      GeomShapePtr aContextShape = aContext->shape();
+      if(!aShape.get()) {
+        // Whole sketch selected.
+        if(aSelectedSketchesFromObjects.find(aContext) != aSelectedSketchesFromObjects.cend()) {
+          theError = "Object from this sketch is already selected. Sketch is not allowed for selection.";
+          return false;
+        }
+
+        aSelectedSketches.insert(aContext);
+      } else {
+        // Object from sketch selected.
+        if(aSelectedSketches.find(aContext) != aSelectedSketches.cend()) {
+          theError = "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) {
+            theError = "Wire with wrong orientation selected.";
+            return false;
+          }
+
+          if(aSelectedWiresFromObjects.isBound(aWire)) {
+            theError = "Objects with such wire already selected. Don't allow to select this object.";
+            return false;
+          }
+
+          aSelectedWiresFromObjects.bind(aWire, aWire);
+          aSelectedSketchesFromObjects.insert(aContext);
+        }
+      }
+    }
+  }
+
   return true;
 }
 
@@ -148,6 +200,8 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
           return true;
         }
       }
+
+      return false;
     }
 
     if(!aShape->isEqual(aContextShape)) {
@@ -159,8 +213,8 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
     // Check that object is a shape with allowed type.
     GeomValidators_ShapeType aShapeTypeValidator;
     if(!aShapeTypeValidator.isValid(anAttr, theArguments, theError)) {
-      theError = "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: ";
+      theError = "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) {
@@ -251,7 +305,8 @@ bool FeaturesPlugin_ValidatorCanBeEmpty::isValid(const std::shared_ptr<ModelAPI_
   if(!aShape.get()) {
     ResultPtr aContext = aSelAttr->context();
     if(!aContext.get()) {
-      theError = "Selection attribute \"" + *anArgsIt + "\" can not be empty.";
+      theError = "Base objects list contains vertex or edge, so attribute \"" + *anArgsIt
+               + "\" can not be used with default value. Select direction for extrusion.";
       return false;
     }
 
@@ -259,7 +314,8 @@ bool FeaturesPlugin_ValidatorCanBeEmpty::isValid(const std::shared_ptr<ModelAPI_
   }
 
   if(!aShape.get()) {
-    theError = "Selection attribute \"" + *anArgsIt + "\" can not be empty.";
+    theError = "Base objects list contains vertex or edge, so attribute \"" + *anArgsIt
+              + "\" can not be used with default value. Select direction for extrusion.";
     return false;
   }
 
@@ -343,7 +399,21 @@ bool FeaturesPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribu
   ListOfShape aListOfShapes;
   for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+    if(!aSelection.get()) {
+      theError = "Could not get selection.";
+      return false;
+    }
+    ResultPtr aContext = aSelection->context();
+    if(!aContext.get()) {
+      theError = "Attribute have empty context.";
+      return false;
+    }
+
     GeomShapePtr aShape = aSelection->value();
+    GeomShapePtr aContextShape = aContext->shape();
+    if(!aShape.get()) {
+      aShape = aContextShape;
+    }
     if(!aShape.get()) {
       theError = "Empty shape selected.";
       return false;
@@ -356,14 +426,13 @@ bool FeaturesPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribu
     }
 
     // Check that it is edge on sketch.
-    ResultPtr aContext = aSelection->context();
-    if(!aContext.get()) {
-      theError = "Attribute have empty context.";
-      return false;
-    }
-    GeomShapePtr aContextShape = aContext->shape();
     ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
     if(aConstruction.get()) {
+      if(aConstruction->isInfinite()) {
+        theError = "Inifinte objects not acceptable.";
+        return false;
+      }
+
       std::shared_ptr<GeomAPI_PlanarEdges> anEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aContextShape);
       if(!anEdges.get()) {
         // It is not an edge on the sketch.