Salome HOME
Commit of the current operation if the preselection is activated.
[modules/shaper.git] / src / PartSet / PartSet_Validators.cpp
index 7a976bda33749c371cf392ef0478f5217e0edfc6..31fd4c048b0f9587e26b76c1e86e0cf63a1bd3d8 100644 (file)
 #include <GeomAbs_CurveType.hxx>
 #include <ModuleBase_ISelection.h>
 
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeReference.h>
+
 #include <list>
 
 int shapesNbPoints(const ModuleBase_ISelection* theSelection)
@@ -92,3 +96,69 @@ bool PartSet_RadiusValidator::isValid(const ModuleBase_ISelection* theSelection)
   return (aCount > 0) && (aCount < 2);
 }
 
+
+
+bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, 
+                                                const std::list<std::string>& theArguments,
+                                                const ObjectPtr& theObject) const
+{
+  // Check RefAttr attributes
+  std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
+    theFeature->data()->attributes(ModelAPI_AttributeRefAttr::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_AttributeRefAttr> aRef = 
+          std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
+        // check the object is already presented
+        if (aRef->isObject() && aRef->object() == theObject)
+          return false;
+      }
+    }
+  }
+  // Check selection attributes
+  anAttrs = theFeature->data()->attributes(ModelAPI_AttributeSelection::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_AttributeSelection> aRef = 
+          std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(*anAttr);
+        // check the object is already presented
+        if (aRef->isInitialized() && aRef->context() == theObject)
+          return false;
+      }
+    }
+  }
+  // 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;
+}
+
+bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, 
+                                                const std::list<std::string>& theArguments,
+                                                const AttributePtr& theAttribute) const
+{
+  // not implemented
+  return true;
+}
+
+bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute, 
+                                                const std::list<std::string>& theArguments) const
+{
+  // not implemented
+  return true;
+}
\ No newline at end of file