]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue 452: PartSet variable namespace is partent for the part's namespace.
authorsbh <sergey.belash@opencascade.com>
Wed, 15 Apr 2015 11:51:58 +0000 (14:51 +0300)
committersbh <sergey.belash@opencascade.com>
Wed, 15 Apr 2015 11:51:58 +0000 (14:51 +0300)
src/ModelAPI/ModelAPI_Tools.cpp
src/ModelAPI/ModelAPI_Tools.h
src/ModuleBase/ModuleBase_DoubleSpinBox.h
src/ModuleBase/ModuleBase_ParamSpinBox.cpp
src/ParametersPlugin/ParametersPlugin_Parameter.cpp

index 27a5fdde28540730509b7955d790908bbdfc4342..1d8e0bf10b089e5011efaf50f7b95f8b7283da82 100644 (file)
@@ -5,29 +5,56 @@
 // Author:      Vitaly Smetannikov
 
 #include "ModelAPI_Tools.h"
-#include <ModelAPI_ResultBody.h>
-#include <ModelAPI_ResultConstruction.h>
-#include <ModelAPI_ResultGroup.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_ResultParameter.h>
+
+#include <list>
 
 namespace ModelAPI_Tools {
 
-  std::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult)
-  {
+std::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult)
+{
 /*
-    ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
-    if (aBody)
-      return aBody->shape();
-
-    ResultConstructionPtr aConstruct = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(
-      theResult);
-    if (aConstruct)
-      return aConstruct->shape();
-
-    ResultGroupPtr aGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(theResult);
-    if (aGroup)
-      return aGroup->shape();
-    return std::shared_ptr<GeomAPI_Shape>();
-    */
-    return theResult->shape();
+  ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+  if (aBody)
+    return aBody->shape();
+
+  ResultConstructionPtr aConstruct = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(
+    theResult);
+  if (aConstruct)
+    return aConstruct->shape();
+
+  ResultGroupPtr aGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(theResult);
+  if (aGroup)
+    return aGroup->shape();
+  return std::shared_ptr<GeomAPI_Shape>();
+  */
+  return theResult->shape();
+}
+
+bool findVariable(const std::string& theName, double& outValue)
+{
+  SessionPtr aSession = ModelAPI_Session::get();
+  std::list<DocumentPtr> aDocList;
+  DocumentPtr aDocument = aSession->activeDocument();
+  DocumentPtr aRootDocument = aSession->moduleDocument();
+  aDocList.push_back(aDocument);
+  if (aDocument != aRootDocument) {
+    aDocList.push_back(aRootDocument);
+  }
+  for(std::list<DocumentPtr>::const_iterator it = aDocList.begin(); it != aDocList.end(); ++it) {
+    ObjectPtr aParamObj = (*it)->objectByName(ModelAPI_ResultParameter::group(), theName);
+    ResultParameterPtr aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aParamObj);
+    if(!aParam.get())
+      continue;
+    AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
+    outValue = aValueAttribute->value();
+    return true;
   }
+  return false;
 }
+
+} // namespace ModelAPI_Tools
index 3804c3c0673f05c12e4ed3c8150f32c90877b1be..9d63757ea0f5ee85d6ed85ccc6560e68d5108df8 100644 (file)
 namespace ModelAPI_Tools {
 /// Returns shape from the given Result object
 MODELAPI_EXPORT std::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult);
+
+/*!
+ * Searches for variable with name \param theName in the active document (Part), when
+ * in the root document (PartSet). If found, set it value in the \param outValue
+ * and returns true.
+ */
+MODELAPI_EXPORT bool findVariable(const std::string& theName, double& outValue);
+
 }
-;
 
 #endif
index 347af2f49461d16ee029323ae620b6fd6352db8f..555cafc36fdeec085b8444ba80c27f7a384732e3 100644 (file)
@@ -1,7 +1,7 @@
 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 
 // File:      ModuleBase_DoubleSpinBox.h
-// Author:    Sergey TELKOV
+// Author:    Sergey BELASH
 //
 #ifndef MODULEBASE_DOUBLESPINBOX_H_
 #define MODULEBASE_DOUBLESPINBOX_H_
index af554aa84f9742bce8e627c4a1d2b1b22300a253..57e21b80b345375dec256c0fe0109f6260bf5957 100644 (file)
@@ -4,6 +4,7 @@
 #include <ModelAPI_Document.h>
 #include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Tools.h>
 
 #include <QKeyEvent>
 #include <QLineEdit>
@@ -234,16 +235,7 @@ bool ModuleBase_ParamSpinBox::findVariable(const QString& theName,
                                            double& outValue) const
 {
 
-  SessionPtr aSession = ModelAPI_Session::get();
-  DocumentPtr aDocument = aSession->activeDocument();
-  ObjectPtr aParamObj = aDocument->objectByName(ModelAPI_ResultParameter::group(),
-                                                theName.toStdString());
-  ResultParameterPtr aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aParamObj);
-  if(!aParam.get())
-    return false;
-  AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
-  outValue = aValueAttribute->value();
-  return true;
+  return ModelAPI_Tools::findVariable(theName.toStdString(), outValue);
 }
 
 /*!
index 413e7dc9bcacf220e88d7737843b866cdf1cde7f..e3bc55ebb5493fcdbb982ec8b2a194d63dda93aa 100644 (file)
@@ -10,6 +10,7 @@
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Tools.h>
 
 #include <string>
 #include <sstream>
 ParametersPlugin_Parameter::ParametersPlugin_Parameter()
 {
   myInterp = new ParametersPlugin_PyInterp();
-  myInterp->initialize();
 }
 
 ParametersPlugin_Parameter::~ParametersPlugin_Parameter()
 {
-  myInterp->destroy();
   delete myInterp;
 }
 
@@ -77,21 +76,22 @@ void ParametersPlugin_Parameter::execute()
 
 double ParametersPlugin_Parameter::evaluate(const std::string& theExpression, std::string& theError)
 {
+  myInterp->initialize();
   std::list<std::string> anExprParams = myInterp->compile(theExpression);
   // find expression's params in the model
   std::list<std::string> aContext;
   std::list<std::string>::iterator it = anExprParams.begin();
   for ( ; it != anExprParams.end(); it++) {
-    std::string aParamName = *it;
-    ObjectPtr aParamObj = document()->objectByName(ModelAPI_ResultParameter::group(), aParamName);
-    ResultParameterPtr aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aParamObj);
-    if(!aParam.get()) continue;
-    AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
+    double aValue;
+    if (!ModelAPI_Tools::findVariable(*it, aValue)) continue;
+
     std::ostringstream sstream;
-    sstream << aValueAttribute->value();
+    sstream << aValue;
     std::string aParamValue = sstream.str();
-    aContext.push_back(aParamName + "=" + aParamValue);
+    aContext.push_back(*it + "=" + aParamValue);
   }
   myInterp->extendLocalContext(aContext);
-  return myInterp->evaluate(theExpression, theError);
+  double result = myInterp->evaluate(theExpression, theError);
+  myInterp->destroy();
+  return result;
 }