Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
[modules/shaper.git] / src / PartSet / PartSet_Validators.cpp
index f35b3ae05158f7ca8f4b125776f5eb274fd0a0d2..fa7ac518f60a1696c8a4b04f5b88cc7392107735 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        PartSet_Validators.cpp
 // Created:     09 July 2014
 // Author:      Vitaly SMETANNIKOV
 
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeReference.h>
 
 #include <list>
+#ifdef _DEBUG
+#include <iostream>
+#endif
 
 int shapesNbPoints(const ModuleBase_ISelection* theSelection)
 {
@@ -52,7 +58,7 @@ int shapesNbLines(const ModuleBase_ISelection* theSelection)
 
 bool PartSet_DistanceValidator::isValid(const ModuleBase_ISelection* theSelection) const
 {
-  int aCount = shapesNbPoints(theSelection);
+  int aCount = shapesNbPoints(theSelection) + shapesNbLines(theSelection);
   return (aCount > 0) && (aCount < 3);
 }
 
@@ -95,7 +101,11 @@ bool PartSet_RadiusValidator::isValid(const ModuleBase_ISelection* theSelection)
   return (aCount > 0) && (aCount < 2);
 }
 
-
+bool PartSet_RigidValidator::isValid(const ModuleBase_ISelection* theSelection) const
+{
+  int aCount = shapesNbLines(theSelection);
+  return (aCount > 0) && (aCount < 2);
+}
 
 bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, 
                                                 const std::list<std::string>& theArguments,
@@ -130,6 +140,20 @@ bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
       }
     }
   }
+  // Check selection attributes
+  anAttrs = theFeature->data()->attributes(ModelAPI_AttributeReference::type());
+  if (anAttrs.size() > 0) {
+    std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+    for(; anAttr != anAttrs.end(); anAttr++) {
+      if (*anAttr) {
+        std::shared_ptr<ModelAPI_AttributeReference> aRef = 
+          std::dynamic_pointer_cast<ModelAPI_AttributeReference>(*anAttr);
+        // check the object is already presented
+        if (aRef->isInitialized() && aRef->value() == theObject)
+          return false;
+      }
+    }
+  }
   return true;
 }
 
@@ -146,4 +170,4 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
 {
   // not implemented
   return true;
-}
\ No newline at end of file
+}