Salome HOME
Merge branch 'csgroup_IS2'
[modules/shaper.git] / src / BuildPlugin / BuildPlugin_Validators.cpp
index 29bc897b75f56adda3b522d5f18c4b728877822f..5742946746b8d87c1dab120489fd4bfbaf9add93 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2021  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -20,6 +20,7 @@
 #include "BuildPlugin_Validators.h"
 
 #include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeString.h>
 #include <ModelAPI_ResultConstruction.h>
 
 #include <GeomAPI_PlanarEdges.h>
@@ -39,6 +40,8 @@
 #include <GeomValidators_FeatureKind.h>
 #include <GeomValidators_ShapeType.h>
 
+#include <BuildPlugin_Interpolation.h>
+
 #include <SketchPlugin_Sketch.h>
 
 #include <Events_InfoMessage.h>
@@ -660,3 +663,28 @@ bool BuildPlugin_ValidatorBaseForVertex::isValid(const AttributePtr& theAttribut
 
   return true;
 }
+
+//=================================================================================================
+bool BuildPlugin_ValidatorExpressionInterpolation::isValid(const AttributePtr& theAttribute,
+                                                   const std::list<std::string>& /*theArguments*/,
+                                                   Events_InfoMessage& theError) const
+{
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+
+  AttributeStringPtr aStrAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
+  if (!aStrAttr->isInitialized()) {
+    theError = "Attribute \"%1\" is not initialized.";
+    theError.arg(aStrAttr->id());
+    return false;
+  }
+  bool isEmptyExpr = aStrAttr->value().empty();
+  if (isEmptyExpr) {
+    theError = "Expression is empty.";
+    return false;
+  }
+
+  theError = aFeature->string(BuildPlugin_Interpolation::EXPRESSION_ERROR_ID())->value();
+  return theError.empty();
+}
+