+ if (!aStrAttr->isInitialized()) {
+ theError = "Attribute \"%1\" is not initialized.";
+ theError.arg(aStrAttr->id());
+ return false;
+ }
+ bool isEmptyExpr = aStrAttr->value().empty();
+ if (isEmptyExpr) {
+ theError = "Attribute \"%1\" value is empty.";
+ theError.arg(aStrAttr->id());
+ return false;
+ }
+ if (!ModelAPI_Expression::isVariable(aStrAttr->value())) {
+ theError = "Incorrect variable name.";
+ return false;
+ }
+ if (!isUnique(theAttribute, aStrAttr->value())) {
+ theError = "Variable name is not unique.";
+ return false;
+ }
+ return true;
+}
+
+bool ParametersPlugin_VariableValidator::isUnique(const AttributePtr& theAttribute,
+ const std::string& theString) const
+{
+ DocumentPtr aDocument = theAttribute->owner()->document();
+ for (int anIndex = 0, aSize = aDocument->size(ModelAPI_ResultParameter::group());
+ anIndex < aSize; ++anIndex) {
+ ObjectPtr aParamObj = aDocument->object(ModelAPI_ResultParameter::group(), anIndex);
+ if (aParamObj->data()->name() != theString)
+ continue;
+ ResultParameterPtr aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aParamObj);
+ if (!aParam.get())
+ continue;
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aParam);
+ if (aFeature == theAttribute->owner())
+ continue;
+ return false;
+ }
+ return true;