Salome HOME
Merge remote-tracking branch 'remotes/origin/2018_Lot1_Tasks'
[modules/shaper.git] / src / ParametersPlugin / ParametersPlugin_Parameter.cpp
index 075b5eab4f04a60c79cd0b3653fd7d5d41ed195e..ab128d10b10b83c16f0809eda0fb81206001f9c2 100644 (file)
@@ -1,8 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File:        ParametersPlugin_Parameter.cpp
-// Created:     23 MArch 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>
 
@@ -64,8 +78,38 @@ void ParametersPlugin_Parameter::updateName()
   data()->setName(aName);
 
   ResultParameterPtr aParam = document()->createParameter(data());
+  std::string anOldName = aParam->data()->name();
   aParam->data()->setName(aName);
   setResult(aParam);
+
+
+  // #2474 : if parameter name now hides/shows the higher level parameter name,
+  // update the depended expressions
+  DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+  if (aParam->document() != aRootDoc) {
+    std::list<std::string> aNames; // collect names in the root document that must be checked
+    aNames.push_back(aName);
+    if (anOldName != aName) {
+      aNames.push_back(anOldName);
+    }
+    std::list<std::string>::iterator aNIter = aNames.begin();
+    for (; aNIter != aNames.end(); aNIter++) {
+      double aValue;
+      ResultParameterPtr aRootParam;
+      FeaturePtr aThis =
+        std::dynamic_pointer_cast<ModelAPI_Feature>(string(VARIABLE_ID())->owner());
+      if (ModelAPI_Tools::findVariable(aThis, *aNIter, aValue, aRootParam, aRootDoc)) {
+        std::set<std::shared_ptr<ModelAPI_Attribute> > anAttributes =
+          aRootParam->data()->refsToMe();
+        std::set<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anAttributeIt =
+          anAttributes.cbegin();
+        for (; anAttributeIt != anAttributes.cend(); ++anAttributeIt) {
+          const AttributePtr& anAttribute = *anAttributeIt;
+          ModelAPI_AttributeEvalMessage::send(anAttribute, NULL);
+        }
+      }
+    }
+  }
 }
 
 bool ParametersPlugin_Parameter::updateExpression()
@@ -83,6 +127,7 @@ bool ParametersPlugin_Parameter::updateExpression()
   AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
   aValueAttribute->setValue(aValue);
   setResult(aParam);
+
   return true;
 }