Salome HOME
Added comment
[modules/shaper.git] / src / PartSet / PartSet_Validators.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 29afcf8..86f6cb9
@@ -21,6 +21,7 @@
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Session.h>
 
@@ -182,9 +183,16 @@ bool PartSet_TangentSelection::isValid(const ModuleBase_ISelection* theSelection
   return false;
 }
 
+bool PartSet_AngleSelection::isValid(const ModuleBase_ISelection* theSelection) const
+{
+  int aCount = shapesNbLines(theSelection);
+  return (aCount > 0) && (aCount < 3);
+}
+
 
 bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute, 
-                                                const std::list<std::string>& theArguments) const
+                                                const std::list<std::string>& theArguments,
+                                                std::string& theError) const
 {
   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
 
@@ -288,6 +296,28 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
       }
     }
   }
+  else if (anAttrType == ModelAPI_AttributeRefList::typeId()) {
+    std::shared_ptr<ModelAPI_AttributeRefList> aCurSelList =
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
+    anAttrs = aFeature->data()->attributes(ModelAPI_AttributeRefList::typeId());
+    if (anAttrs.size() > 0) {
+      std::list<std::shared_ptr<ModelAPI_Attribute>>::iterator anAttrItr = anAttrs.begin();
+      for (; anAttrItr != anAttrs.end(); anAttrItr++){
+        if ((*anAttrItr).get() && (*anAttrItr)->id() != theAttribute->id()){
+          std::shared_ptr<ModelAPI_AttributeRefList> aRefSelList =
+            std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anAttrItr);
+          for (int i = 0; i < aCurSelList->size(); i++) {
+            ObjectPtr aCurSelObject = aCurSelList->object(i);
+            for (int j = 0; j < aRefSelList->size(); j++) {
+              if (aCurSelObject == aRefSelList->object(j)) {
+                return false;
+              }
+            }
+          }
+        }
+      }
+    }
+  }
   return !featureHasReferences(theAttribute);
 }
 
@@ -322,7 +352,8 @@ bool PartSet_DifferentObjectsValidator::featureHasReferences(const AttributePtr&
 }
 
 bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute,
-                                            const std::list<std::string>& theArguments) const
+                                            const std::list<std::string>& theArguments,
+                                            std::string& theError) const
 {
   bool isSketchEntities = true;
   std::set<std::string> anEntityKinds;
@@ -335,11 +366,8 @@ bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute,
   if (anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
     AttributeSelectionListPtr aSelectionListAttr = 
                       std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
-    // it filters only selection list attributes
-    std::string aType = aSelectionListAttr->selectionType().c_str();
     // all context objects should be sketch entities
-    int aSize = aSelectionListAttr->size();
-    for (int i = 0; i < aSelectionListAttr->size() && isSketchEntities; i++) {
+    for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize && isSketchEntities; i++) {
       AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
       ObjectPtr anObject = aSelectAttr->context();
       // a context of the selection attribute is a feature result. It can be a case when the result
@@ -354,6 +382,24 @@ bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute,
       }
     }
   }
+  if (anAttributeType == ModelAPI_AttributeRefList::typeId()) {
+    AttributeRefListPtr aRefListAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
+    // all context objects should be sketch entities
+    for (int i = 0, aSize = aRefListAttr->size(); i < aSize && isSketchEntities; i++) {
+      ObjectPtr anObject = aRefListAttr->object(i);
+      // a context of the selection attribute is a feature result. It can be a case when the result
+      // of the feature is null, e.g. the feature is modified and has not been executed yet.
+      // The validator returns an invalid result here. The case is an extrusion built on a sketch
+      // feature. A new sketch element creation leads to an empty result.
+      if (!anObject.get())
+        isSketchEntities = false;
+      else {
+        FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+        isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end();
+      }
+    }
+  }
   if (anAttributeType == ModelAPI_AttributeRefAttr::typeId()) {
     std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
                      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
@@ -373,8 +419,9 @@ bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute,
 
 
 
-bool PartSet_SameTypeAttrValidator::isValid(
-  const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
+bool PartSet_SameTypeAttrValidator::isValid(const AttributePtr& theAttribute, 
+                                            const std::list<std::string>& theArguments,
+                                            std::string& theError ) const
 {
   // there is a check whether the feature contains a point and a linear edge or two point values
   std::string aParamA = theArguments.front();
@@ -399,8 +446,9 @@ bool PartSet_SameTypeAttrValidator::isValid(
   return false;
 }
 
-bool PartSet_CoincidentAttr::isValid(
-  const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
+bool PartSet_CoincidentAttr::isValid(const AttributePtr& theAttribute, 
+                                     const std::list<std::string>& theArguments,
+                                     std::string& theError) const
 {
   // there is a check whether the feature contains a point and a linear edge or two point values
   std::string aParamA = theArguments.front();