Salome HOME
Issue #2308: 1.1.2.4 Faces in “Union”
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Validators.cpp
index ec5414da94edfb5cb816b0dbad50e895c128346d..853037100234b21d18cd5330d293e58593c780bd 100644 (file)
 // License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 //
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
 //
 
 #include "FeaturesPlugin_Validators.h"
 
+#include "FeaturesPlugin_Boolean.h"
 #include "FeaturesPlugin_Union.h"
 
 #include <Events_InfoMessage.h>
@@ -607,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();
@@ -625,7 +630,7 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt
     }
 
     int aShapeType = aShape->shapeType();
-    if(anOperationType == 1) {
+    if(anOperationType == FeaturesPlugin_Boolean::BOOL_FUSE) {
       // Fuse operation. Allow to select edges, faces and solids.
       if(aShapeType != GeomAPI_Shape::EDGE &&
          aShapeType != GeomAPI_Shape::FACE &&
@@ -635,6 +640,14 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt
         theError = "Error: Selected shape has the wrong type.";
         return false;
       }
+    } else if (anOperationType == FeaturesPlugin_Boolean::BOOL_FILL) {
+      if(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;
+      }
     } else {
       if(aShapeType != GeomAPI_Shape::SOLID &&
          aShapeType != GeomAPI_Shape::COMPSOLID &&
@@ -758,7 +771,7 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(
   Events_InfoMessage& theError) const
 {
   static const std::string aBaseShapeID = "base_shape";
-  static const std::string aSubShapesID = "subshapes";
+  static const std::string aSubShapesID = "subshapes_to_keep";
 
   if(theFeature->getKind() != "Remove_SubShapes") {
     theError = "Error: Feature \"%1\" does not supported by this validator.";
@@ -788,6 +801,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);
@@ -827,11 +845,28 @@ bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttr
   for(int anIndex = 0; anIndex < aBaseObjectsAttrList->size(); ++anIndex) {
     bool isSameFound = false;
     AttributeSelectionPtr anAttrSelectionInList = aBaseObjectsAttrList->value(anIndex);
+    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>(anAttrSelectionInList->context());
+      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;
@@ -864,17 +899,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.";