Salome HOME
Merge branch 'Dev_GroupsRevision'
[modules/shaper.git] / src / BuildPlugin / BuildPlugin_Validators.cpp
index 244ddb6e4f7ae9d0ed8ee89500e2c8e8b6c2b8a5..833536d400a170fd6f1d89cc6b12cab67d8e8baa 100644 (file)
@@ -112,12 +112,6 @@ bool BuildPlugin_ValidatorBaseForBuild::isValid(const AttributePtr& theAttribute
         continue;
       }
     }
-
-    if(!aShape->isEqual(aContextShape)) {
-      // Local selection on body does not allowed.
-      theError = "Selected shape is in the local selection. Only global selection is allowed.";
-      return false;
-    }
   }
 
   return true;
@@ -192,6 +186,9 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr<ModelAPI_Fe
     return false;
   }
 
+  bool hasEdgesOrWires = false;
+  bool hasFaces = false;
+
   // Collect base shapes.
   ListOfShape anEdges;
   for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
@@ -204,13 +201,23 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr<ModelAPI_Fe
       }
       aShape = aSelection->context()->shape();
     }
+    if (aShape->shapeType() == GeomAPI_Shape::FACE) {
+      // skip faces exploding
+      hasFaces = true;
+      continue;
+    }
+
     for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
+      hasEdgesOrWires = true;
       GeomShapePtr anEdge = anExp.current();
       anEdges.push_back(anEdge);
     }
   }
 
-  if(anEdges.empty()) {
+  if (hasFaces && hasEdgesOrWires) {
+    theError = "Faces and edges/wires should be selected together.";
+    return false;
+  } else if (hasEdgesOrWires && anEdges.empty()) {
     theError = "Objects are not selected.";
     return false;
   }
@@ -235,20 +242,22 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr<ModelAPI_Fe
     }
   }
 
-  // Check that they are planar.
-  std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_ShapeTools::findPlane(anEdges);
-  if(!aPln.get()) {
-    theError = "Selected object(s) should belong to only one plane.";
-    return false;
-  }
+  if (!anEdges.empty()) {
+    // Check that they are planar.
+    std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_ShapeTools::findPlane(anEdges);
+    if(!aPln.get()) {
+      theError = "Selected object(s) should belong to only one plane.";
+      return false;
+    }
 
-  // Check that selected objects have closed contours.
-  ListOfShape aFaces;
-  GeomAlgoAPI_SketchBuilder::createFaces(aPln->location(), aPln->xDirection(),
-                                         aPln->direction(), anEdges, aFaces);
-  if(aFaces.empty()) {
-    theError = "Selected objects do not generate closed contour.";
-    return false;
+    // Check that selected objects have closed contours.
+    ListOfShape aFaces;
+    GeomAlgoAPI_SketchBuilder::createFaces(aPln->location(), aPln->xDirection(),
+                                           aPln->direction(), anEdges, aFaces);
+    if(aFaces.empty()) {
+      theError = "Selected objects do not generate closed contour.";
+      return false;
+    }
   }
 
   return true;
@@ -359,3 +368,53 @@ bool BuildPlugin_ValidatorSubShapesSelection::isValid(const AttributePtr& theAtt
 
   return true;
 }
+
+
+//=================================================================================================
+bool BuildPlugin_ValidatorFillingSelection::isValid(const AttributePtr& theAttribute,
+                                                      const std::list<std::string>& theArguments,
+                                                      Events_InfoMessage& theError) const
+{
+  // Get base objects list.
+  if (theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
+    std::string aMsg =
+      "Error: BuildPlugin_ValidatorFillingSelection does not support attribute type \""
+      "%1\"\n Only \"%2\" supported.";
+    Events_InfoMessage("BuildPlugin_Validators", aMsg).
+      arg(theAttribute->attributeType()).arg(ModelAPI_AttributeSelectionList::typeId()).send();
+    return false;
+  }
+  AttributeSelectionListPtr aSelectionList =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+  if (!aSelectionList.get()) {
+    theError = "Could not get selection list.";
+    return false;
+  }
+
+  FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
+
+  // Check selected shapes.
+  for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+    AttributeSelectionPtr aSelectionAttrInList = aSelectionList->value(anIndex);
+    if (!aSelectionAttrInList.get()) {
+      theError = "Empty attribute in list.";
+      return false;
+    }
+
+    // Check shape exists.
+    GeomShapePtr aShapeInList = aSelectionAttrInList->value();
+    if (!aShapeInList.get()) {
+      theError = "Object has no shape";
+      return false;
+    }
+
+    // Check shape type.
+    GeomAPI_Shape::ShapeType aType = aShapeInList->shapeType();
+    if (aType != GeomAPI_Shape::EDGE && aType != GeomAPI_Shape::WIRE) {
+      theError = "Incorrect objects selected";
+      return false;
+    }
+  }
+
+  return true;
+}