Salome HOME
updated copyright message
[modules/shaper.git] / src / CollectionPlugin / CollectionPlugin_Validators.cpp
index 7620506cf3d0b57e97c7e45efb1bf55d3cf7af50..3fd3e1f320805f5f53915cb406017b23eab31424 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -26,7 +26,7 @@
 
 
 bool CollectionPlugin_FieldValidator::isValid(const FeaturePtr& theFeature,
-  const std::list<std::string>& theArguments,
+  const std::list<std::string>& /*theArguments*/,
   Events_InfoMessage& theError) const
 {
   AttributeSelectionListPtr aSelList =
@@ -100,3 +100,29 @@ bool CollectionPlugin_GroupOperationAttributeValidator::isValid(
   }
   return true;
 }
+
+bool CollectionPlugin_GroupSelectionValidator::isValid(
+    const AttributePtr& theAttribute,
+    const std::list<std::string>& /*theArguments*/,
+    Events_InfoMessage& theError) const
+{
+  AttributeSelectionListPtr aSelList =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+  if (!aSelList) {
+    theError = "Error: This validator can only work with selection list of attributes";
+    return false;
+  }
+
+  for (int anIndex = 0; anIndex < aSelList->size(); ++anIndex) {
+    AttributeSelectionPtr aCurSelection = aSelList->value(anIndex);
+    FeaturePtr aCurFeature = aCurSelection->contextFeature();
+    ResultPtr aGroupResult = aCurFeature.get() ? aCurFeature->lastResult()
+                                               : aCurSelection->context();
+    if (!aGroupResult.get() || aGroupResult->groupName() == ModelAPI_ResultGroup::group()) {
+      theError = "Error: Whole group mustn't be selected.";
+      return false;
+    }
+  }
+
+  return true;
+}