Salome HOME
Issue #2273: Error when reading HDF and Python dump
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Validators.cpp
index ed22a6420b086cae59f833b975ccedc47b0d3e5a..3c6fcc3471828c096c8eab647290c5953d7dcec4 100755 (executable)
@@ -1565,3 +1565,47 @@ bool SketchPlugin_HasNoConstraint::isValid(const AttributePtr& theAttribute,
   }
   return true;
 }
+
+bool SketchPlugin_ReplicationReferenceValidator::isValid(
+    const AttributePtr& theAttribute,
+    const std::list<std::string>& theArguments,
+    Events_InfoMessage& theError) const
+{
+  AttributeRefAttrPtr aRefAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+  if (!aRefAttr)
+  {
+    theError = "Incorrect attribute";
+    return false;
+  }
+
+  ObjectPtr anOwner;
+  if (aRefAttr->isObject())
+    anOwner = aRefAttr->object();
+  else
+  {
+    AttributePtr anAttr = aRefAttr->attr();
+    anOwner = anAttr->owner();
+  }
+  FeaturePtr anAttrOwnerFeature = ModelAPI_Feature::feature(anOwner);
+  if (!anAttrOwnerFeature)
+    return true;
+  AttributeBooleanPtr aCopyAttr = anAttrOwnerFeature->boolean(SketchPlugin_SketchEntity::COPY_ID());
+  if (!aCopyAttr || !aCopyAttr->value())
+    return true; // feature is not a copy, thus valid
+
+  // check the copy feature is already referred by the "Multi" feature
+  FeaturePtr aMultiFeature = ModelAPI_Feature::feature(theAttribute->owner());
+  AttributeRefListPtr aRefList = aMultiFeature->reflist(theArguments.front());
+  for (int i = 0; i < aRefList->size(); ++i)
+  {
+    FeaturePtr aRefOwner = ModelAPI_Feature::feature(aRefList->object(i));
+    if (aRefOwner == anAttrOwnerFeature)
+    {
+      theError = "Attribute refers to the object generated by this feature";
+      return false;
+    }
+  }
+
+  return true;
+}