-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-/*
- * ParametersPlugin_EvalListener.cpp
- *
- * Created on: Apr 28, 2015
- * Author: sbh
- */
+// Copyright (C) 2014-2017 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
#include <pyconfig.h>
#include <ModelAPI_AttributeValidator.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Events.h>
+#include <ModelAPI_ResultParameter.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Tools.h>
theNewName);
// Issue #588. No need for reevaluating expression.
// Moreover, current history may not contain necessary parameters.
- anExpressionAttribute->owner()->data()->blockSendAttributeUpdated(true);
+ bool aWasBlocked = anExpressionAttribute->owner()->data()->blockSendAttributeUpdated(true);
anExpressionAttribute->setValue(anExpressionString);
- anExpressionAttribute->owner()->data()->blockSendAttributeUpdated(false);
+ anExpressionAttribute->owner()->data()->blockSendAttributeUpdated(aWasBlocked);
}
void ParametersPlugin_EvalListener::renameInAttribute(
const std::string& theNewName)
{
std::set<std::shared_ptr<ModelAPI_Attribute> > anAttributes =
- theResultParameter->data()->refsToMe();
+ theResultParameter->data()->refsToMe();
std::set<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anAttributeIt =
- anAttributes.cbegin();
+ anAttributes.cbegin();
for (; anAttributeIt != anAttributes.cend(); ++anAttributeIt) {
const AttributePtr& anAttribute = *anAttributeIt;
if (anAttribute->attributeType() == ModelAPI_AttributeRefList::typeId()) {
std::shared_ptr<ParametersPlugin_Parameter> aParameter =
- std::dynamic_pointer_cast<ParametersPlugin_Parameter>(
- anAttribute->owner());
+ std::dynamic_pointer_cast<ParametersPlugin_Parameter>(
+ anAttribute->owner());
if (aParameter.get())
// Rename
renameInParameter(aParameter, theOldName, theNewName);
} else
- // Rename
- renameInAttribute(anAttribute, theOldName, theNewName);
+ // Rename
+ renameInAttribute(anAttribute, theOldName, theNewName);
}
}
void setParameterName(ResultParameterPtr theResultParameter, const std::string& theName)
{
- theResultParameter->data()->blockSendAttributeUpdated(true);
+ bool aWasBlocked = theResultParameter->data()->blockSendAttributeUpdated(true);
theResultParameter->data()->setName(theName);
- theResultParameter->data()->blockSendAttributeUpdated(false, false);
+ theResultParameter->data()->blockSendAttributeUpdated(aWasBlocked, false);
std::shared_ptr<ParametersPlugin_Parameter> aParameter =
std::dynamic_pointer_cast<ParametersPlugin_Parameter>(
ModelAPI_Feature::feature(theResultParameter));
- aParameter->data()->blockSendAttributeUpdated(true);
+ std::string anOldName = aParameter->name();
+ aWasBlocked = aParameter->data()->blockSendAttributeUpdated(true);
aParameter->data()->setName(theName);
aParameter->string(ParametersPlugin_Parameter::VARIABLE_ID())->setValue(theName);
- aParameter->data()->blockSendAttributeUpdated(false);
+ aParameter->data()->blockSendAttributeUpdated(aWasBlocked);
}
void ParametersPlugin_EvalListener::processObjectRenamedEvent(
// 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(aResultParameter, aMessage->oldName());
+ //setParameterName(aResultParameter, aMessage->oldName());
+ if (myOldNames.find(aParameter.get()) == myOldNames.end())
+ myOldNames[aParameter.get()] = aMessage->oldName();
return;
}
- renameInDependents(aResultParameter, aMessage->oldName(), aMessage->newName());
+ std::string anOldName = aMessage->oldName();
+ if (myOldNames.find(aParameter.get()) != myOldNames.end()) {
+ anOldName = myOldNames[aParameter.get()];
+ myOldNames.erase(aParameter.get());
+ aParameter->execute(); // to enable result because of previously incorrect name
+ }
+
+ renameInDependents(aResultParameter, anOldName, aMessage->newName());
}
void ParametersPlugin_EvalListener::processReplaceParameterEvent(