return true;
}
-void setParameterName(std::shared_ptr<ParametersPlugin_Parameter> theParameter, const std::string& theName)
+void setParameterName(ResultParameterPtr theResultParameter, const std::string& theName)
{
- theParameter->data()->blockSendAttributeUpdated(true);
- theParameter->data()->setName(theName);
- theParameter->string(ParametersPlugin_Parameter::VARIABLE_ID())->setValue(theName);
- theParameter->data()->blockSendAttributeUpdated(false);
+ theResultParameter->data()->blockSendAttributeUpdated(true);
+ theResultParameter->data()->setName(theName);
+ theResultParameter->data()->blockSendAttributeUpdated(false);
+
+ std::shared_ptr<ParametersPlugin_Parameter> aParameter =
+ std::dynamic_pointer_cast<ParametersPlugin_Parameter>(
+ ModelAPI_Feature::feature(theResultParameter));
+
+ aParameter->data()->blockSendAttributeUpdated(true);
+ aParameter->data()->setName(theName);
+ aParameter->string(ParametersPlugin_Parameter::VARIABLE_ID())->setValue(theName);
+ aParameter->data()->blockSendAttributeUpdated(false);
}
void ParametersPlugin_EvalListener::processObjectRenamedEvent(
if (!aMessage.get() || aMessage->oldName().empty() || aMessage->newName().empty())
return;
- // check that the renamed object is a result
+ // check if the renamed object is a result perameter
ResultParameterPtr aResultParameter =
std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aMessage->object());
if (!aResultParameter.get())
return;
// get parameter feature for the result
- FeaturePtr aFeature = aResultParameter->document()->feature(aResultParameter);
std::shared_ptr<ParametersPlugin_Parameter> aParameter =
- std::dynamic_pointer_cast<ParametersPlugin_Parameter>(aFeature);
+ std::dynamic_pointer_cast<ParametersPlugin_Parameter>(
+ ModelAPI_Feature::feature(aResultParameter));
if (!aParameter.get())
return;
- // rename a parameter attributes
- // short way:
- //aParameter->string(ParametersPlugin_Parameter::VARIABLE_ID())->setValue(aMessage->newName());
- //aParameter->execute();
- // manual way:
- setParameterName(aParameter, aMessage->newName());
-
+ // try to update the parameter feature according the new name
+ setParameterName(aResultParameter, aMessage->newName());
// TODO(spo): replace with ModelAPI_Session::get()->validators()->validate(aParameter, ParametersPlugin_Parameter::VARIABLE_ID())
// when ModelAPI_ValidatorsFactory::validate(const std::shared_ptr<ModelAPI_Feature>& theFeature, const std::string& theAttribute) const
// is ready
if (!isValidAttribute(aParameter->string(ParametersPlugin_Parameter::VARIABLE_ID()))) {
- setParameterName(aParameter, aMessage->oldName());
+ setParameterName(aResultParameter, aMessage->oldName());
return;
}
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_ResultParameter.h>
+#include <ModelAPI_Tools.h>
ParametersPlugin_VariableValidator::ParametersPlugin_VariableValidator()
{
const std::list<std::string>& theArguments) const
{
AttributeStringPtr aStrAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
- bool result = isVariable(aStrAttr->value());
+ bool result = isVariable(aStrAttr->value()) && isUnique(theAttribute, aStrAttr->value());
return result;
}
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;
+}
+
ParametersPlugin_ExpressionValidator::ParametersPlugin_ExpressionValidator()
{