]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/SketchPlugin/SketchPlugin_Validators.cpp
Salome HOME
Update constraint Mirror.
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Validators.cpp
index 95da79b9513deced964b1fd618ad7cab8ef9f6d2..72f0b61d1cb6872e656d70b75d631b8353ab22c1 100644 (file)
@@ -18,6 +18,8 @@
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Session.h>
 
 #include <GeomValidators_Edge.h>
@@ -211,3 +213,26 @@ bool SketchPlugin_EqualAttrValidator::isValid(
   return true;
 }
 
+bool SketchPlugin_MirrorAttrValidator::isValid(
+  const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
+{
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+  AttributeSelectionListPtr aSelAttr = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+  if (!aSelAttr)
+    return false;
+
+  AttributeRefListPtr aRefListOfMirrored = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+      aFeature->attribute(SketchPlugin_Constraint::ENTITY_C()));
+  std::list<ObjectPtr> aMirroredObjects = aRefListOfMirrored->list();
+
+  for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
+    std::shared_ptr<ModelAPI_AttributeSelection> aSelect = aSelAttr->value(anInd);
+    std::list<ObjectPtr>::iterator aMirIter = aMirroredObjects.begin();
+    for (; aMirIter != aMirroredObjects.end(); aMirIter++)
+      if (aSelect->context() == *aMirIter)
+        return false;
+  }
+  return true;
+}
+