Salome HOME
Task #3079 3.5 Build/Vertex on a whole Sketch
[modules/shaper.git] / src / BuildPlugin / BuildPlugin_Validators.cpp
index 65be3411933356f25d4724b941c2659b693436a4..6b44423f877549b50f43992147414e87f3b68c6e 100644 (file)
@@ -464,7 +464,7 @@ bool BuildPlugin_ValidatorFillingSelection::isValid(const AttributePtr& theAttri
     return false;
   }
 
-  FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
+  //FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
 
   // Check selected shapes.
   for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
@@ -491,3 +491,61 @@ bool BuildPlugin_ValidatorFillingSelection::isValid(const AttributePtr& theAttri
 
   return true;
 }
+
+
+//=================================================================================================
+bool BuildPlugin_ValidatorBaseForVertex::isValid(const AttributePtr& theAttribute,
+                                                 const std::list<std::string>& /*theArguments*/,
+                                                 Events_InfoMessage& theError) const
+{
+  if (!theAttribute.get()) {
+    theError = "Error: empty selection.";
+    return false;
+  }
+
+  AttributeSelectionListPtr aSelectionList =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+  if (!aSelectionList.get()) {
+    theError = "Could not get selection list.";
+    return false;
+  }
+
+  for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+    AttributeSelectionPtr aSelectionAttr = aSelectionList->value(anIndex);
+    if (!aSelectionAttr.get()) {
+      theError = "Empty attribute in list.";
+      return false;
+    }
+
+    // Vertex?
+    bool isVertex = false;
+    GeomShapePtr aShapeInList = aSelectionAttr->value();
+    if (aShapeInList.get()) {
+      isVertex = (aShapeInList->shapeType() == GeomAPI_Shape::VERTEX);
+    }
+
+    if (!isVertex) {
+      // Sketch?
+      FeaturePtr aFeature = aSelectionAttr->contextFeature();
+      if (!aFeature.get()) {
+        ResultPtr aContext = aSelectionAttr->context();
+        if (aContext.get()) {
+          aFeature = ModelAPI_Feature::feature(aContext);
+        }
+      }
+
+      if (aFeature.get()) {
+        std::string aFeatureKind = aFeature->getKind();
+        if (aFeatureKind != "Sketch" &&
+            aFeatureKind != "Point" &&
+            aFeatureKind != "Vertex") {
+          theError = "Error: %1 shape is not allowed for selection.";
+          theError.arg(aFeatureKind);
+          return false;
+        }
+      }
+    }
+  }
+
+  return true;
+}