]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.0
authorsbh <sergey.belash@opencascade.com>
Wed, 15 Apr 2015 11:52:09 +0000 (14:52 +0300)
committersbh <sergey.belash@opencascade.com>
Wed, 15 Apr 2015 11:52:09 +0000 (14:52 +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
src/PartSet/PartSet_WidgetPoint2d.cpp
src/PartSet/PartSet_WidgetPoint2d.h

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 ece600bcddd493160514769d14f839a4dbe6b18d..70840ccff61641a071de1ab711ca1ba972df0a98 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;
 }
index d2c65a27f018a24c843d8e9a7c1fcc4d4b6f0b0f..10f6de95fd65dc663d5e28d6d00fcbcab2f4ebed 100644 (file)
@@ -14,7 +14,7 @@
 #include <XGUI_Selection.h>
 #include <XGUI_OperationMgr.h>
 
-#include <ModuleBase_ParamSpinBox.h>
+#include <ModuleBase_DoubleSpinBox.h>
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_IViewWindow.h>
 
@@ -70,7 +70,7 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
     aLabel->setPixmap(QPixmap(":pictures/x_point.png"));
     aGroupLay->addWidget(aLabel, 0, 0);
 
-    myXSpin = new ModuleBase_ParamSpinBox(myGroupBox);
+    myXSpin = new ModuleBase_DoubleSpinBox(myGroupBox);
     myXSpin->setMinimum(-DBL_MAX);
     myXSpin->setMaximum(DBL_MAX);
     myXSpin->setToolTip(tr("X"));
@@ -84,7 +84,7 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
     aLabel->setPixmap(QPixmap(":pictures/y_point.png"));
     aGroupLay->addWidget(aLabel, 1, 0);
 
-    myYSpin = new ModuleBase_ParamSpinBox(myGroupBox);
+    myYSpin = new ModuleBase_DoubleSpinBox(myGroupBox);
     myYSpin->setMinimum(-DBL_MAX);
     myYSpin->setMaximum(DBL_MAX);
     myYSpin->setToolTip(tr("Y"));
index 133ac4fa6b28ca564c075b3bd92dcc6a12614cbc..e39011c9054e32484b65472bdf9bdda846078354 100644 (file)
@@ -18,7 +18,7 @@
 
 class ModelAPI_Feature;
 class ModuleBase_IWorkshop;
-class ModuleBase_ParamSpinBox;
+class ModuleBase_DoubleSpinBox;
 class ModuleBase_IViewWindow;
 class GeomAPI_Pnt2d;
 class XGUI_Workshop;
@@ -130,8 +130,8 @@ private slots:
   XGUI_Workshop* myWorkshop;
 
   QGroupBox* myGroupBox;  ///< the parent group box for all intenal widgets
-  ModuleBase_ParamSpinBox* myXSpin;  ///< the spin box for the X coordinate
-  ModuleBase_ParamSpinBox* myYSpin;  ///< the spin box for the Y coordinate
+  ModuleBase_DoubleSpinBox* myXSpin;  ///< the spin box for the X coordinate
+  ModuleBase_DoubleSpinBox* myYSpin;  ///< the spin box for the Y coordinate
 
   //std::string myOptionParam;  /// Parameter name which has to be taken from previous feature