Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.0
authorsbh <sergey.belash@opencascade.com>
Mon, 6 Apr 2015 17:56:37 +0000 (20:56 +0300)
committersbh <sergey.belash@opencascade.com>
Mon, 6 Apr 2015 17:56:37 +0000 (20:56 +0300)
Conflicts:
src/ModelAPI/CMakeLists.txt
src/ModuleBase/ModuleBase_WidgetFactory.cpp

27 files changed:
CMakeCommon/FindPython.cmake
src/Config/CMakeLists.txt
src/Config/Config_Keywords.h
src/Model/CMakeLists.txt
src/Model/Model_Document.cpp
src/Model/Model_Document.h
src/Model/Model_ResultParameter.cpp [new file with mode: 0644]
src/Model/Model_ResultParameter.h [new file with mode: 0644]
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI.i
src/ModelAPI/ModelAPI_Document.h
src/ModelAPI/ModelAPI_ResultParameter.cpp [new file with mode: 0644]
src/ModelAPI/ModelAPI_ResultParameter.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_ResultParameters.h [deleted file]
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_WidgetExprEditor.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetExprEditor.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetLineEdit.cpp
src/ParametersPlugin/CMakeLists.txt
src/ParametersPlugin/ParametersPlugin_Parameter.cpp
src/ParametersPlugin/ParametersPlugin_Parameter.h
src/ParametersPlugin/ParametersPlugin_PyInterp.cpp [new file with mode: 0644]
src/ParametersPlugin/ParametersPlugin_PyInterp.h [new file with mode: 0644]
src/ParametersPlugin/plugin-Parameters.xml
src/XGUI/XGUI_PartDataModel.cpp
src/XGUI/pictures/expression.png

index c5352896e0d9e5e832066302ec65e80cb588b372..d48364e6797550c9b3aa2e5c7f2ebb3d2fbf4376 100644 (file)
@@ -1,5 +1,7 @@
 ## Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 
+UNSET(PYTHON_INCLUDE_DIRS)
+UNSET(PYTHON_LIBRARIES)
 
 IF(WIN32)
     IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
@@ -12,15 +14,16 @@ ElSE()
 ENDIF()
 
 IF(WIN32)
-  FILE(TO_CMAKE_PATH "$ENV{PYTHONHOME}/libs/${PYTHON_LIBRARY_FILE}" PYTHON_LIBRARY)
+  FILE(TO_CMAKE_PATH "$ENV{PYTHONHOME}/libs/${PYTHON_LIBRARY_FILE}" PATH_PYTHON_LIBRARY)
 ElSE()
-  FILE(TO_CMAKE_PATH "$ENV{PYTHONHOME}/lib/${PYTHON_LIBRARY_FILE}" PYTHON_LIBRARY)
+  FILE(TO_CMAKE_PATH "$ENV{PYTHONHOME}/lib/${PYTHON_LIBRARY_FILE}" PATH_PYTHON_LIBRARY)
 ENDIF()
+FILE(TO_CMAKE_PATH $ENV{PYTHON_INCLUDE} PATH_PYTHON_INCLUDE_DIR)
+
+SET(PYTHON_INCLUDE_DIR ${PATH_PYTHON_INCLUDE_DIR} CACHE PATH "path to where Python.h is found" FORCE)
+SET(PYTHON_LIBRARY ${PATH_PYTHON_LIBRARY} CACHE FILEPATH "path to the python library" FORCE)
 
-FILE(TO_CMAKE_PATH $ENV{PYTHON_INCLUDE} PYTHON_INCLUDE_DIR)
 FIND_PACKAGE(PythonLibs REQUIRED)
 FIND_PACKAGE(PythonInterp REQUIRED)
 
 INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIR})
-#MESSAGE(STATUS "PYTHON_LIBRARIES: " ${PYTHON_LIBRARIES})
-#MESSAGE(STATUS "PYTHON_INCLUDE_DIR: " ${PYTHON_INCLUDE_DIR})
index 591c8489afc4d829063bf3c1d5388dd34b1496a1..0837555e7350b4e8419e7a660d8f0c6f9879cf46 100644 (file)
@@ -4,7 +4,7 @@ INCLUDE(Common)
 INCLUDE(XMLProcessing)
 
 INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/src/Events
-                     ${PYTHON_INCLUDE_DIRS}) 
+                     ${PYTHON_INCLUDE_DIR}) 
 
 SET(PROJECT_HEADERS
   Config_def.h
index bc115a764f1ee1e1f5603126505031e3be70452f..a9f44bf63b4a5adc2a7b79184d03b00e5e0031db 100644 (file)
@@ -31,6 +31,7 @@ const static char* WDG_SHAPE_SELECTOR = "shape_selector";
 const static char* WDG_CHOICE = "choice";
 const static char* WDG_DOUBLEVALUE_EDITOR = "doublevalue_editor";
 const static char* WDG_FILE_SELECTOR= "file_selector";
+const static char* WDG_EXPR_EDITOR = "expr_editor";
 // Containers
 const static char* WDG_GROUP = "groupbox";
 const static char* WDG_CHECK_GROUP = "check_groupbox";
index ef4c82c12077d0ba4b2d4067fcf226634c746b2b..eef87c35f0ab499310e9e2537fa811087cd2ddce 100644 (file)
@@ -26,6 +26,7 @@ SET(PROJECT_HEADERS
     Model_ResultConstruction.h
     Model_ResultPart.h
     Model_ResultGroup.h
+    Model_ResultParameter.h
     Model_FeatureValidator.h
 )
 
@@ -52,6 +53,7 @@ SET(PROJECT_SOURCES
     Model_ResultConstruction.cpp
     Model_ResultPart.cpp
     Model_ResultGroup.cpp
+    Model_ResultParameter.cpp
     Model_FeatureValidator.cpp
 )
 
index d88015148a1b96f8a2cda6490f8e5ec74b13b7cf..71019bc6d50f4baa503565c0b455b7da4773e737 100644 (file)
@@ -15,6 +15,7 @@
 #include <Model_ResultGroup.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_CompositeFeature.h>
+
 #include <Events_Loop.h>
 #include <Events_Error.h>
 
@@ -1222,6 +1223,23 @@ std::shared_ptr<ModelAPI_ResultGroup> Model_Document::createGroup(
   return aResult;
 }
 
+std::shared_ptr<ModelAPI_ResultParameter> Model_Document::createParameter(
+      const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
+{
+  TDF_Label aLab = resultLabel(theFeatureData, theIndex);
+  TDataStd_Comment::Set(aLab, ModelAPI_ResultParameter::group().c_str());
+  ObjectPtr anOldObject = object(aLab);
+  std::shared_ptr<ModelAPI_ResultParameter> aResult;
+  if (anOldObject) {
+    aResult = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(anOldObject);
+  }
+  if (!aResult) {
+    aResult = std::shared_ptr<ModelAPI_ResultParameter>(new ModelAPI_ResultParameter);
+    storeResult(theFeatureData, aResult, theIndex);
+  }
+  return aResult;
+}
+
 std::shared_ptr<ModelAPI_Feature> Model_Document::feature(
     const std::shared_ptr<ModelAPI_Result>& theResult)
 {
index 59631304e0ee4bf0bc51293e51d4212f5fedcca5..453422ffcf9900e7f3cf846c1dd3ece339a3f5e8 100644 (file)
@@ -11,6 +11,7 @@
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
+#include <ModelAPI_ResultParameter.h>
 
 #include <TDocStd_Document.hxx>
 #include <NCollection_DataMap.hxx>
@@ -142,6 +143,9 @@ class Model_Document : public ModelAPI_Document
   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_ResultGroup> createGroup(
       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
 
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_ResultParameter> createParameter(
+      const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
+
   //! Returns a feature by result (owner of result)
   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature>
     feature(const std::shared_ptr<ModelAPI_Result>& theResult);
diff --git a/src/Model/Model_ResultParameter.cpp b/src/Model/Model_ResultParameter.cpp
new file mode 100644 (file)
index 0000000..641155b
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        Model_ResultParameter.h
+// Created:     02 Apr 2015
+// Author:      Sergey BELASH
+
+#ifndef MODEL_RESULTPARAMETER_H_
+#define MODEL_RESULTPARAMETER_H_
+
+#include "Model.h"
+#include <Model_Document.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultParameter.h>
+
+/**\class Model_ResultParameter
+ * \ingroup DataModel
+ * \brief
+ */
+class Model_ResultParameter : public ModelAPI_ResultParameter
+{
+ public:
+  MODEL_EXPORT virtual ~Model_ResultParameter();
+  MODEL_EXPORT virtual void initAttributes();
+
+ protected:
+  Model_ResultParameter();
+
+  friend class Model_Document;
+};
+
+#endif
diff --git a/src/Model/Model_ResultParameter.h b/src/Model/Model_ResultParameter.h
new file mode 100644 (file)
index 0000000..08c3e2d
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        Model_ResultParameter.cpp
+// Created:     02 Apr 2015
+// Author:      Sergey BELASH
+
+#include "Model_ResultParameter.h"
+
+Model_ResultParameter::~Model_ResultParameter()
+{
+
+}
+
+void Model_ResultParameter::initAttributes()
+{
+  data()->addAttribute(ModelAPI_ResultParameter::VALUE(),
+                       ModelAPI_AttributeDouble::typeId());
+}
+
+
+Model_ResultParameter::Model_ResultParameter()
+{
+  setIsConcealed(false);
+}
index 27df7d5652434ab9fd45e260ccbaec56cd29b51d..249ee64ac25822fe2cac6c51fbe3d0bb99f91797 100644 (file)
@@ -32,7 +32,7 @@ SET(PROJECT_HEADERS
     ModelAPI_ResultBody.h
     ModelAPI_ResultConstruction.h
     ModelAPI_ResultGroup.h
-    ModelAPI_ResultParameters.h
+    ModelAPI_ResultParameter.h
     ModelAPI_ResultPart.h
     ModelAPI_Session.h
     ModelAPI_Tools.h
@@ -68,6 +68,7 @@ SET(PROJECT_SOURCES
     ModelAPI_Session.cpp
     ModelAPI_ShapeValidator.cpp
     ModelAPI_Tools.cpp
+    ModelAPI_ResultParameter.cpp
     ModelAPI_AttributeValidator.cpp
 )
 
@@ -81,11 +82,10 @@ ADD_LIBRARY(ModelAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
 SET_TARGET_PROPERTIES(ModelAPI PROPERTIES LINKER_LANGUAGE CXX)
 TARGET_LINK_LIBRARIES(ModelAPI ${PROJECT_LIBRARIES})
 
-INCLUDE_DIRECTORIES(
-  ../Config 
-  ../Events
-  ../GeomAPI
-  ../GeomAlgoAPI
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Config 
+                    ${PROJECT_SOURCE_DIR}/src/Events
+                    ${PROJECT_SOURCE_DIR}/src/GeomAPI
+                    ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
 )
 
 
index bd8cc724a39efec30c605993c166a9373e7bea5c..0c23dc012860884f10790dd1e0fa675ecdbbdd65 100644 (file)
@@ -35,7 +35,7 @@
   #include "ModelAPI_ResultConstruction.h"
   #include "ModelAPI_ResultBody.h"
   #include "ModelAPI_ResultPart.h"
-  #include "ModelAPI_ResultParameters.h"
+  #include "ModelAPI_ResultParameter.h"
   #include "ModelAPI_ResultGroup.h"
   #include "ModelAPI_Tools.h"
 
@@ -95,7 +95,7 @@
 %shared_ptr(ModelAPI_ResultBody)
 %shared_ptr(ModelAPI_ResultPart)
 %shared_ptr(ModelAPI_ResultGroup)
-%shared_ptr(ModelAPI_ResultParameters)
+%shared_ptr(ModelAPI_ResultParameter)
 
 // all supported interfaces
 %include "ModelAPI_Document.h"
 %include "ModelAPI_ResultBody.h"
 %include "ModelAPI_ResultPart.h"
 %include "ModelAPI_ResultGroup.h"
-%include "ModelAPI_ResultParameters.h"
+%include "ModelAPI_ResultParameter.h"
 %include "ModelAPI_Tools.h"
 
 // std::list -> [] 
index cbb1d5b01288ab45c130724502b9b8c8839544cb..8093123bd4ee523c3b2c9e5da27dd9150b952e91 100644 (file)
@@ -21,6 +21,7 @@ class ModelAPI_ResultConstruction;
 class ModelAPI_ResultBody;
 class ModelAPI_ResultPart;
 class ModelAPI_ResultGroup;
+class ModelAPI_ResultParameter;
 class ModelAPI_Data;
 
 /**\class ModelAPI_Document
@@ -98,6 +99,9 @@ public:
   virtual std::shared_ptr<ModelAPI_ResultGroup> createGroup(
       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
 
+  virtual std::shared_ptr<ModelAPI_ResultParameter> createParameter(
+      const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
+
   //! Returns a feature by result (owner of result)
   virtual std::shared_ptr<ModelAPI_Feature> feature(
       const std::shared_ptr<ModelAPI_Result>& theResult) = 0;
diff --git a/src/ModelAPI/ModelAPI_ResultParameter.cpp b/src/ModelAPI/ModelAPI_ResultParameter.cpp
new file mode 100644 (file)
index 0000000..781fe33
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModelAPI_ResultParameter.h
+// Created:     07 Jul 2014
+// Author:      Vitaly SMETANNIKOV
+
+#include "ModelAPI_ResultParameter.h"
+#include <ModelAPI_AttributeDouble.h>
+
+void ModelAPI_ResultParameter::initAttributes()
+{
+  data()->addAttribute(ModelAPI_ResultParameter::VALUE(),
+                       ModelAPI_AttributeDouble::typeId());
+}
diff --git a/src/ModelAPI/ModelAPI_ResultParameter.h b/src/ModelAPI/ModelAPI_ResultParameter.h
new file mode 100644 (file)
index 0000000..f4b4734
--- /dev/null
@@ -0,0 +1,48 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModelAPI_ResultParameter.h
+// Created:     07 Jul 2014
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef MODELAPI_RESULTPARAMETER_H_
+#define MODELAPI_RESULTPARAMETER_H_
+
+#include "ModelAPI_Result.h"
+
+/**\class ModelAPI_ResultParameter
+ * \ingroup DataModel
+ * \brief The construction element result of a feature.
+ *
+ * Provides a shape that may be displayed in the viewer.
+ * Intermediate, light result that in many cases produces a result on the fly.
+ */
+class ModelAPI_ResultParameter : public ModelAPI_Result
+{
+ public:
+  /// Returns the group identifier of this result
+  virtual std::string groupName()
+  {
+    return group();
+  }
+
+  /// Returns the group identifier of this result
+  inline static std::string group()
+  {
+    static std::string MY_GROUP = "Parameters";
+    return MY_GROUP;
+  }
+
+  inline static const std::string& VALUE()
+  {
+    static const std::string MY_VALUE_ID("Value");
+    return MY_VALUE_ID;
+  }
+
+  MODELAPI_EXPORT virtual void initAttributes();
+
+};
+
+//! Pointer on feature object
+typedef std::shared_ptr<ModelAPI_ResultParameter> ResultParameterPtr;
+
+#endif
diff --git a/src/ModelAPI/ModelAPI_ResultParameters.h b/src/ModelAPI/ModelAPI_ResultParameters.h
deleted file mode 100644 (file)
index 3b8bd15..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModelAPI_ResultParameters.h
-// Created:     07 Jul 2014
-// Author:      Vitaly SMETANNIKOV
-
-#ifndef ModelAPI_ResultParameters_H_
-#define ModelAPI_ResultParameters_H_
-
-#include "ModelAPI_Result.h"
-
-/**\class ModelAPI_ResultParameters
- * \ingroup DataModel
- * \brief The construction element result of a feature.
- *
- * Provides a shape that may be displayed in the viewer.
- * Intermediate, light result that in many cases produces a result on the fly.
- */
-class ModelAPI_ResultParameters : public ModelAPI_Result
-{
- public:
-  /// Returns the group identifier of this result
-  virtual std::string groupName()
-  {
-    return group();
-  }
-
-  /// Returns the group identifier of this result
-  inline static std::string group()
-  {
-    static std::string MY_GROUP = "Parameters";
-    return MY_GROUP;
-  }
-};
-
-//! Pointer on feature object
-typedef std::shared_ptr<ModelAPI_ResultParameters> ResultParametersPtr;
-
-#endif
index b623713fc7ef550ae99d708c8e438e319631705e..3f5ba997f88d382f3d80ec29308c6b6c435a1a43 100644 (file)
@@ -51,6 +51,7 @@ SET(PROJECT_HEADERS
        ModuleBase_WidgetSwitch.h
        ModuleBase_WidgetToolbox.h
        ModuleBase_WidgetValidated.h
+       ModuleBase_WidgetExprEditor.h
 )
 
 SET(PROJECT_SOURCES
@@ -92,6 +93,7 @@ SET(PROJECT_SOURCES
        ModuleBase_WidgetSwitch.cpp
        ModuleBase_WidgetToolbox.cpp
        ModuleBase_WidgetValidated.cpp
+       ModuleBase_WidgetExprEditor.cpp
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/ModuleBase/ModuleBase_WidgetExprEditor.cpp b/src/ModuleBase/ModuleBase_WidgetExprEditor.cpp
new file mode 100644 (file)
index 0000000..64ca2e3
--- /dev/null
@@ -0,0 +1,207 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+/*
+ * ModuleBase_WidgetExprEditor.cpp
+ *
+ *  Created on: Aug 28, 2014
+ *      Author: sbh
+ */
+
+#include <ModuleBase_WidgetExprEditor.h>
+#include <ModuleBase_Tools.h>
+
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_Validator.h>
+
+#include <Config_WidgetAPI.h>
+
+#include <QVBoxLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QObject>
+#include <QString>
+#include <QStringListModel>
+#include <QCompleter>
+#include <QSize>
+#include <QShortcut>
+#include <QScrollBar>
+
+#include <memory>
+#include <string>
+
+ExpressionEditor::ExpressionEditor(QWidget* theParent)
+: QPlainTextEdit(theParent)
+{
+  myCompleter = new QCompleter(this);
+  myCompleter->setWidget(this);
+  myCompleter->setCompletionMode(QCompleter::PopupCompletion);
+
+  myCompleterModel = new QStringListModel(this);
+  myCompleter->setModel(myCompleterModel);
+  // Use sorted model to accelerate completion (QCompleter will use binary search)
+  myCompleter->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
+  myCompleter->setCaseSensitivity(Qt::CaseInsensitive);
+
+  connect(myCompleter, SIGNAL(activated(const QString&)),
+          this,        SLOT(insertCompletion(const QString&)));
+  (void) new QShortcut(QKeySequence(tr("Ctrl+Space", "Complete")),
+                       this, SLOT(performCompletion()));
+}
+
+ExpressionEditor::~ExpressionEditor()
+{
+
+}
+
+void ExpressionEditor::setCompletionList(QStringList& theList)
+{
+  theList.sort();
+  theList.removeDuplicates();
+  myCompleterModel->setStringList(theList);
+}
+
+void ExpressionEditor::insertCompletion(const QString& theCompletion, bool isSingleWord)
+{
+  QTextCursor aCursor = textCursor();
+  int numberOfCharsToComplete = theCompletion.length() -
+      myCompleter->completionPrefix().length();
+  int insertionPosition = aCursor.position();
+  aCursor.insertText(theCompletion.right(numberOfCharsToComplete));
+  if (isSingleWord) {
+    aCursor.setPosition(insertionPosition);
+    aCursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
+    myCompletedAndSelected = true;
+  }
+  setTextCursor(aCursor);
+}
+
+void ExpressionEditor::performCompletion()
+{
+  QTextCursor aCursor = textCursor();
+  aCursor.select(QTextCursor::WordUnderCursor);
+  const QString aPrefix = aCursor.selectedText();
+  if (!aPrefix.isEmpty() && aPrefix.at(aPrefix.length() - 1).isLetter()) {
+    performCompletion(aPrefix);
+  }
+}
+
+void ExpressionEditor::performCompletion(const QString& theCompletionPrefix)
+{
+  //populate model?
+  if (theCompletionPrefix != myCompleter->completionPrefix()) {
+    myCompleter->setCompletionPrefix(theCompletionPrefix);
+    myCompleter->popup()->setCurrentIndex(myCompleter->completionModel()->index(0, 0));
+  }
+  if (myCompleter->completionCount() == 1) {
+    insertCompletion(myCompleter->currentCompletion(), true);
+  } else {
+    QRect aRect = cursorRect();
+    aRect.setWidth(myCompleter->popup()->sizeHintForColumn(0)
+                  + myCompleter->popup()->verticalScrollBar()->sizeHint().width());
+    myCompleter->complete(aRect);
+  }
+}
+
+void ExpressionEditor::keyPressEvent(QKeyEvent* theEvent)
+{
+  if (myCompletedAndSelected && handledCompletedAndSelected(theEvent))
+    return;
+  myCompletedAndSelected = false;
+  if (myCompleter->popup()->isVisible()) {
+    switch (theEvent->key()) {
+      case Qt::Key_Up:
+      case Qt::Key_Down:
+      case Qt::Key_Enter:
+      case Qt::Key_Return:
+      case Qt::Key_Escape:
+        theEvent->ignore();
+        return;
+      default:
+        myCompleter->popup()->hide();
+        break;
+    }
+  }
+  QPlainTextEdit::keyPressEvent(theEvent);
+}
+
+bool ExpressionEditor::handledCompletedAndSelected(QKeyEvent* theEvent)
+{
+  myCompletedAndSelected = false;
+  QTextCursor aCursor = textCursor();
+  switch (theEvent->key()) {
+    case Qt::Key_Enter:
+    case Qt::Key_Return: aCursor.clearSelection(); break;
+    case Qt::Key_Escape: aCursor.removeSelectedText(); break;
+    default: return false;
+  }
+  setTextCursor(aCursor);
+  theEvent->accept();
+  return true;
+}
+
+ModuleBase_WidgetExprEditor::ModuleBase_WidgetExprEditor(QWidget* theParent,
+                                                     const Config_WidgetAPI* theData,
+                                                     const std::string& theParentId)
+    : ModuleBase_ModelWidget(theParent, theData, theParentId)
+{
+  QVBoxLayout* aMainLay = new QVBoxLayout(this);
+  ModuleBase_Tools::adjustMargins(aMainLay);
+
+  myEditor = new ExpressionEditor(this);
+  myEditor->setMinimumHeight(20);
+  aMainLay->addWidget(myEditor);
+  this->setLayout(aMainLay);
+
+  connect(myEditor, SIGNAL(textChanged()), this, SLOT(onTextChanged()));
+}
+
+ModuleBase_WidgetExprEditor::~ModuleBase_WidgetExprEditor()
+{
+}
+
+bool ModuleBase_WidgetExprEditor::storeValueCustom() const
+{
+  // A rare case when plugin was not loaded. 
+  if(!myFeature)
+    return false;
+  DataPtr aData = myFeature->data();
+  AttributeStringPtr aStringAttr = aData->string(attributeID());
+  QString aWidgetValue = myEditor->toPlainText();
+  aStringAttr->setValue(aWidgetValue.toStdString());
+  updateObject(myFeature);
+  return true;
+}
+
+bool ModuleBase_WidgetExprEditor::restoreValue()
+{
+  // A rare case when plugin was not loaded. 
+  if(!myFeature)
+    return false;
+  DataPtr aData = myFeature->data();
+  AttributeStringPtr aStringAttr = aData->string(attributeID());
+
+  bool isBlocked = myEditor->blockSignals(true);
+  QTextCursor aCursor = myEditor->textCursor();
+  int pos = aCursor.position();
+  std::string aRestoredStr = aStringAttr->value();
+  myEditor->setPlainText(QString::fromStdString(aRestoredStr));
+  aCursor.setPosition(pos);
+  myEditor->setTextCursor(aCursor);
+  myEditor->blockSignals(isBlocked);
+
+  return true;
+}
+
+QList<QWidget*> ModuleBase_WidgetExprEditor::getControls() const
+{
+  QList<QWidget*> result;
+  result << myEditor;
+  return result;
+}
+
+void ModuleBase_WidgetExprEditor::onTextChanged()
+{
+  storeValue();
+}
diff --git a/src/ModuleBase/ModuleBase_WidgetExprEditor.h b/src/ModuleBase/ModuleBase_WidgetExprEditor.h
new file mode 100644 (file)
index 0000000..41a209f
--- /dev/null
@@ -0,0 +1,85 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+/*
+ * ModuleBase_WidgetExprEditor.h
+ *
+ *  Created on: Oct 8, 2014
+ *      Author: sbh
+ */
+
+#ifndef MODULEBASE_WIDGETEXPREDITOR_H_
+#define MODULEBASE_WIDGETEXPREDITOR_H_
+
+#include <ModuleBase.h>
+#include <ModuleBase_ModelWidget.h>
+
+#include <QList>
+#include <QString>
+#include <QStringList>
+#include <QPlainTextEdit>
+
+class QWidget;
+class QStringListModel;
+class QCompleter;
+
+class ExpressionEditor: public QPlainTextEdit
+{
+  Q_OBJECT
+
+ public:
+  explicit ExpressionEditor(QWidget* theParent = 0);
+  virtual ~ExpressionEditor();
+
+  void setCompletionList(QStringList&);
+
+ public slots:
+  void insertCompletion(const QString&, bool isSingleWord = false);
+  void performCompletion();
+
+ protected:
+  void performCompletion(const QString& theCompletionPrefix);
+  virtual void keyPressEvent(QKeyEvent* theEvent);
+  bool handledCompletedAndSelected(QKeyEvent* theEvent);
+
+ private:
+  QStringListModel* myCompleterModel;
+  QCompleter* myCompleter;
+  bool myCompletedAndSelected;
+};
+
+/**
+* \ingroup GUI
+* TODO(sbh) add doc
+*/
+class MODULEBASE_EXPORT ModuleBase_WidgetExprEditor : public ModuleBase_ModelWidget
+{
+  Q_OBJECT
+ public:
+  /// Constructor
+  /// \param theParent the parent object
+  /// \param theData the widget configuration.
+  /// \param theParentId is Id of a parent of the current attribute
+  ModuleBase_WidgetExprEditor(QWidget* theParent,
+                                const Config_WidgetAPI* theData,
+                                const std::string& theParentId);
+  virtual ~ModuleBase_WidgetExprEditor();
+
+  virtual bool restoreValue();
+
+  virtual QList<QWidget*> getControls() const;
+
+ public slots:
+   /// A slot for processing text changed event
+  void onTextChanged();
+
+protected:
+  /// Saves the internal parameters to the given feature
+  /// \return True in success
+  virtual bool storeValueCustom() const;
+
+private:
+   /// A line edit control
+  ExpressionEditor* myEditor;
+};
+
+#endif /* MODULEBASE_WIDGETEXPREDITOR_H_ */
index 6925ee993efa84fad1448ebf86bd84900368af51..c9561a13ba458fddc63d95e139bcaa1c7bc18fb1 100644 (file)
 
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_OperationDescription.h>
-//#include <ModuleBase_WidgetFeatureOrAttribute.h>
-//#include <ModuleBase_WidgetFeature.h>
 #include <ModuleBase_WidgetEditor.h>
 #include <ModuleBase_WidgetSwitch.h>
 #include <ModuleBase_WidgetShapeSelector.h>
 #include <ModuleBase_WidgetDoubleValue.h>
 #include <ModuleBase_WidgetBoolValue.h>
-//#include <ModuleBase_WidgetPoint2dDistance.h>
 #include <ModuleBase_WidgetFileSelector.h>
 #include <ModuleBase_WidgetChoice.h>
 #include <ModuleBase_IWorkshop.h>
@@ -31,6 +28,7 @@
 #include <ModuleBase_PageBase.h>
 #include <ModuleBase_PageGroupBox.h>
 #include <ModuleBase_PageWidget.h>
+#include <ModuleBase_WidgetExprEditor.h>
 
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Session.h>
@@ -115,50 +113,45 @@ void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage)
   thePage->alignToTop();
 }
 
-ModuleBase_ModelWidget* ModuleBase_WidgetFactory
-::createWidgetByType(const std::string& theType, QWidget* theParent)
+ModuleBase_ModelWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType,
+                                                                     QWidget* theParent)
 {
   ModuleBase_ModelWidget* result = NULL;
 
   if (theType == WDG_INFO) {
     result = new ModuleBase_WidgetLabel(theParent, myWidgetApi, myParentId);
-
   } else if (theType == WDG_DOUBLEVALUE) {
     result = new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi, myParentId);
-
   } else if (theType == WDG_SHAPE_SELECTOR) {
-    result =  new ModuleBase_WidgetShapeSelector(theParent, myWorkshop, myWidgetApi, myParentId);
-
+    result = new ModuleBase_WidgetShapeSelector(theParent, myWorkshop, myWidgetApi, myParentId);
   } else if (theType == WDG_BOOLVALUE) {
     result = new ModuleBase_WidgetBoolValue(theParent, myWidgetApi, myParentId);
-
+  //} else if (theType == WDG_DOUBLEVALUE_EDITOR) {
+  //  result = new ModuleBase_WidgetEditor(theParent, myWidgetApi, myParentId);
   } else if (theType == WDG_FILE_SELECTOR) {
     result = new ModuleBase_WidgetFileSelector(theParent, myWidgetApi, myParentId);
-
   } else if (theType == WDG_CHOICE) {
-    result = new ModuleBase_WidgetChoice(theParent, myWidgetApi,myParentId);
-
+    result = new ModuleBase_WidgetChoice(theParent, myWidgetApi, myParentId);
   } else if (theType == WDG_STRINGVALUE) {
-    result = new ModuleBase_WidgetLineEdit(theParent, myWidgetApi,myParentId);
-
+    result = new ModuleBase_WidgetLineEdit(theParent, myWidgetApi, myParentId);
+  } else if (theType == WDG_EXPR_EDITOR) {
+    result = new ModuleBase_WidgetExprEditor(theParent, myWidgetApi, myParentId);
   } else if (theType == WDG_MULTISELECTOR) {
-    result = new ModuleBase_WidgetMultiSelector(theParent, myWorkshop, myWidgetApi,myParentId);
-
+    result = new ModuleBase_WidgetMultiSelector(theParent, myWorkshop, myWidgetApi, myParentId);
   } else if (theType == WDG_TOOLBOX) {
     result = new ModuleBase_WidgetToolbox(theParent, myWidgetApi, myParentId);
-
   } else if (theType == WDG_SWITCH) {
     result = new ModuleBase_WidgetSwitch(theParent, myWidgetApi, myParentId);
-
   } else if (theType == WDG_TOOLBOX_BOX || theType == WDG_SWITCH_CASE) {
     // Do nothing for "box" and "case"
     result = NULL;
   } else {
-    result = myWorkshop->module()->createWidgetByType(theType, theParent, myWidgetApi,
-                                                      myParentId);
-#ifdef _DEBUG
-    if (!result) {qDebug("ModuleBase_WidgetFactory::fillWidget: find bad widget type");}
-#endif
+    result = myWorkshop->module()->createWidgetByType(theType, theParent, myWidgetApi, myParentId);
+    #ifdef _DEBUG
+    if (!result) {
+      qDebug("ModuleBase_WidgetFactory::fillWidget: find bad widget type");
+    }
+    #endif
   }
   if (result) {
     myModelWidgets.append(result);
index 9c4a1b00f068fd36b0ef838b9320ca9f5a9f0a5b..1f1dbd5349d34d63f97060c31ba924cdd8075f1d 100644 (file)
@@ -33,10 +33,15 @@ ModuleBase_WidgetLineEdit::ModuleBase_WidgetLineEdit(QWidget* theParent,
 {
   QFormLayout* aMainLay = new QFormLayout(this);
   ModuleBase_Tools::adjustMargins(aMainLay);
-  QString aTitle = QString::fromStdString(theData->widgetLabel());
+  QString aLabelText = QString::fromStdString(theData->widgetLabel());
+  QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
+  QLabel* aLabel = new QLabel(aLabelText, this);
+  if (!aLabelIcon.isEmpty())
+    aLabel->setPixmap(QPixmap(aLabelIcon));
+
   myLineEdit = new QLineEdit(this);
   myLineEdit->setMinimumHeight(20);
-  aMainLay->addRow(aTitle, myLineEdit);
+  aMainLay->addRow(aLabel, myLineEdit);
   this->setLayout(aMainLay);
 
   connect(myLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged()));
index 287e84b23c27c556481b9399001efca617f8130c..f6e54ea57418fac97638706cd04079ad9d982309 100644 (file)
@@ -1,32 +1,42 @@
 INCLUDE(Common)
-
-INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events
-                    ${PROJECT_SOURCE_DIR}/src/Config
-                    ${PROJECT_SOURCE_DIR}/src/ModelAPI
-) 
+INCLUDE(FindPython)
 
 SET(PROJECT_HEADERS
     ParametersPlugin.h
     ParametersPlugin_Plugin.h
     ParametersPlugin_Parameter.h
+    ParametersPlugin_PyInterp.h
 )
  
 SET(PROJECT_SOURCES
     ParametersPlugin_Plugin.cpp
     ParametersPlugin_Parameter.cpp
+    ParametersPlugin_PyInterp.cpp
 )
 
 SET(XML_RESOURCES
     plugin-Parameters.xml
 )
 
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events
+                    ${PROJECT_SOURCE_DIR}/src/Config
+                    ${PROJECT_SOURCE_DIR}/src/ModelAPI
+                    ${PROJECT_SOURCE_DIR}/src/GeomAPI
+                    ${SUIT_INCLUDE}
+                    ${PYTHON_INCLUDE_DIR}
+) 
+
+MESSAGE(STATUS "PYTHON_LIBRARIES (ParametersPlugin): ${PYTHON_LIBRARIES}")
+
 SET(PROJECT_LIBRARIES
     Events
     Config
     ModelAPI
+    ${PyInterp}
+    ${PYTHON_LIBRARIES}
 )
 
-ADD_DEFINITIONS(-DPARAMETERSPLUGIN_EXPORTS)
+ADD_DEFINITIONS(-DPARAMETERSPLUGIN_EXPORTS -DHAVE_DEBUG_PYTHON)
 ADD_LIBRARY(ParametersPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES})
 
 TARGET_LINK_LIBRARIES(ParametersPlugin ${PROJECT_LIBRARIES})
index c3d72d272cb2997402be0256a4283f7f1e6d54d8..073c83cb59a879a2414d6bed2d787d2435f10b88 100644 (file)
@@ -5,18 +5,74 @@
 // Author:      sbh
 
 #include "ParametersPlugin_Parameter.h"
+#include <ParametersPlugin_PyInterp.h>
+
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_ResultParameter.h>
+#include <ModelAPI_AttributeDouble.h>
+
+#include <string>
+#include <sstream>
 
 ParametersPlugin_Parameter::ParametersPlugin_Parameter()
 {
+  myInterp = new ParametersPlugin_PyInterp();
+  myInterp->initialize();
+}
+
+ParametersPlugin_Parameter::~ParametersPlugin_Parameter()
+{
+  delete myInterp;
 }
 
 void ParametersPlugin_Parameter::initAttributes()
 {
-  data()->addAttribute(ParametersPlugin_Parameter::VARIABLE_ID(), ModelAPI_AttributeString::typeId());
-  data()->addAttribute(ParametersPlugin_Parameter::EXPRESSION_ID(), ModelAPI_AttributeString::typeId());
+  data()->addAttribute(ParametersPlugin_Parameter::VARIABLE_ID(),
+                       ModelAPI_AttributeString::typeId());
+  data()->addAttribute(ParametersPlugin_Parameter::EXPRESSION_ID(),
+                       ModelAPI_AttributeString::typeId());
 }
 
 void ParametersPlugin_Parameter::execute()
 {
+  std::string anExpression = string(ParametersPlugin_Parameter::EXPRESSION_ID())->value();
+  if(anExpression.empty())
+    return;
+
+  ResultParameterPtr aParameterResult = document()->createParameter(data());
+  // Value
+  AttributeDoublePtr aValueAttribute = aParameterResult->data()->real(ModelAPI_ResultParameter::VALUE());
+  double aValue = evaluate(anExpression);
+  aValueAttribute->setValue(aValue);
+  setResult(aParameterResult);
+  // Name
+  std::string aName = string(ParametersPlugin_Parameter::VARIABLE_ID())->value();
+  std::ostringstream sstream;
+  sstream << aValue;
+  std::string aParamValue = sstream.str();
+  data()->setName(aName + " ("+ aParamValue + ")");
+  aParameterResult->data()->setName(aName);
+}
+
+double ParametersPlugin_Parameter::evaluate(std::string theExpression)
+{
+  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());
+    std::ostringstream sstream;
+    sstream << aValueAttribute->value();
+    std::string aParamValue = sstream.str();
+    aContext.push_back(aParamName + "=" + aParamValue);
+  }
+  myInterp->extendLocalContext(aContext);
+  std::string outError;
+  return myInterp->evaluate(theExpression, outError);
+
 }
index e7574fd2a758d943fcafbcbabfa833de9c5545f5..66cd99bfa282b5c157835d90675578760a45f370 100644 (file)
 #include "ParametersPlugin.h"
 #include <ModelAPI_Feature.h>
 
+class ParametersPlugin_PyInterp;
+
 class ParametersPlugin_Parameter : public ModelAPI_Feature
 {
  public:
+  virtual ~ParametersPlugin_Parameter();
+
   /// Extrusion kind
   inline static const std::string& ID()
   {
@@ -49,6 +53,12 @@ class ParametersPlugin_Parameter : public ModelAPI_Feature
 
   /// Use plugin manager for features creation
   ParametersPlugin_Parameter();
+
+ protected:
+  double evaluate(std::string);
+
+ private:
+  ParametersPlugin_PyInterp* myInterp;
 };
 
 #endif
diff --git a/src/ParametersPlugin/ParametersPlugin_PyInterp.cpp b/src/ParametersPlugin/ParametersPlugin_PyInterp.cpp
new file mode 100644 (file)
index 0000000..c3546ea
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * ParametersPlugin_PyInterp.cpp
+ *
+ *  Created on: Apr 2, 2015
+ *      Author: sbh
+ */
+
+#include <ParametersPlugin_PyInterp.h>
+
+#include <string>
+
+ParametersPlugin_PyInterp::ParametersPlugin_PyInterp()
+: PyInterp_Interp()
+{
+}
+
+ParametersPlugin_PyInterp::~ParametersPlugin_PyInterp()
+{
+}
+
+std::list<std::string> ParametersPlugin_PyInterp::compile(const std::string& theExpression)
+{
+  PyGILState_STATE aGilState = PyGILState_Ensure();
+  std::list<std::string>  res = this->_compile(theExpression);
+  PyGILState_Release(aGilState);
+  return res;
+}
+
+void ParametersPlugin_PyInterp::extendLocalContext(const std::list<std::string>& theParameters)
+{
+  PyGILState_STATE aGilState = PyGILState_Ensure();
+  this->_extendLocalContext(theParameters);
+  PyGILState_Release(aGilState);
+}
+
+double ParametersPlugin_PyInterp::evaluate(const std::string& theExpression,
+                                           std::string& theError)
+{
+  PyGILState_STATE aGilState = PyGILState_Ensure();
+  double res = this->_evaluate(theExpression, theError);
+  PyGILState_Release(aGilState);
+  return res;
+}
+
+
+std::list<std::string> ParametersPlugin_PyInterp::_compile(const std::string& theExpression)
+{
+
+  std::list<std::string> aResult;
+  PyObject *aCodeopModule = PyImport_AddModule("codeop");
+  if(!aCodeopModule) { // Fatal error. No way to go on.
+    PyErr_Print();
+    return aResult;
+  }
+
+  PyObject *aCodePyObj =
+      PyObject_CallMethod(aCodeopModule, "compile_command", "(s)", theExpression.c_str());
+
+  if(!aCodePyObj || aCodePyObj == Py_None || !PyCode_Check(aCodePyObj)) {
+    Py_XDECREF(aCodePyObj);
+    return aResult;
+  }
+
+  PyCodeObject* aCodeObj = (PyCodeObject*) aCodePyObj;
+  // co_names should be tuple, but can be changed in modern versions of python (>2.7.3)
+  if(!PyTuple_Check(aCodeObj->co_names))
+    return aResult;
+  
+  int params_size = PyTuple_Size(aCodeObj->co_names);
+  if (params_size > 0) {
+    for (int i = 0; i < params_size; i++) {
+      PyObject* aParamObj = PyTuple_GetItem(aCodeObj->co_names, i);
+      PyObject* aParamObjStr = PyObject_Str(aParamObj);
+      std::string aParamName(PyString_AsString(aParamObjStr));
+      aResult.push_back(aParamName);
+      Py_XDECREF(aParamObjStr);
+    }
+  }
+  Py_XDECREF(aCodeObj);
+  return aResult;
+}
+
+void ParametersPlugin_PyInterp::_extendLocalContext(const std::list<std::string>& theParameters)
+{
+  if (theParameters.empty())
+    return;
+  std::list<std::string>::const_iterator it = theParameters.begin();
+  for ( ; it != theParameters.cend(); it++) {
+    std::string aParamValue = *it;
+    simpleRun(aParamValue.c_str(), false);
+  }
+}
+
+
+double ParametersPlugin_PyInterp::_evaluate(const std::string& theExpression, std::string& theError)
+{
+  PyCodeObject* anExprCode = (PyCodeObject *) Py_CompileString(theExpression.c_str(),
+                                                               "<string>", Py_eval_input);
+  if(!anExprCode) {
+    theError = errorMessage();
+    Py_XDECREF(anExprCode);
+    return 0.;
+  }
+
+  PyObject* anEvalResult = PyEval_EvalCode(anExprCode, _global_context, _local_context);
+  if(!anEvalResult) {
+    theError = errorMessage();
+    Py_XDECREF(anExprCode);
+    Py_XDECREF(anEvalResult);
+    return 0.;
+  }
+
+  PyObject* anEvalStrObj = PyObject_Str(anEvalResult);
+  std::string anEvalStr(PyString_AsString(anEvalStrObj));
+  Py_XDECREF(anExprCode);
+  Py_XDECREF(anEvalResult);
+  Py_XDECREF(anEvalStrObj);
+  return std::stod(anEvalStr);
+}
+
+std::string ParametersPlugin_PyInterp::errorMessage()
+{
+  std::string aPyError;
+  if (PyErr_Occurred()) {
+    PyObject *pstr, *ptype, *pvalue, *ptraceback;
+    PyErr_Fetch(&ptype, &pvalue, &ptraceback);
+    PyErr_NormalizeException(&ptype, &pvalue, &ptraceback);
+    pstr = PyObject_Str(pvalue);
+    aPyError = std::string(PyString_AsString(pstr));
+    Py_XDECREF(pstr);
+    Py_XDECREF(ptype);
+    Py_XDECREF(pvalue);
+    Py_XDECREF(ptraceback);
+  }
+  return aPyError;
+}
diff --git a/src/ParametersPlugin/ParametersPlugin_PyInterp.h b/src/ParametersPlugin/ParametersPlugin_PyInterp.h
new file mode 100644 (file)
index 0000000..6bb2a21
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * ParametersPlugin_PyInterp.h
+ *
+ *  Created on: Apr 2, 2015
+ *      Author: sbh
+ */
+
+#ifndef PARAMETERSPLUGIN_PYINTERP_H_
+#define PARAMETERSPLUGIN_PYINTERP_H_
+
+#include <PyInterp_Interp.h>
+#include <ParametersPlugin.h>
+
+#include <list>
+#include <string>
+
+class PARAMETERSPLUGIN_EXPORT ParametersPlugin_PyInterp : public PyInterp_Interp
+{
+ public:
+  ParametersPlugin_PyInterp();
+  virtual ~ParametersPlugin_PyInterp();
+
+  std::list<std::string> compile(const std::string&);
+  void extendLocalContext(const std::list<std::string>&);
+  double evaluate(const std::string&, std::string&);
+
+ protected:
+  std::list<std::string> _compile(const std::string&);
+  void _extendLocalContext(const std::list<std::string>&);
+  double _evaluate(const std::string&, std::string&);
+  std::string errorMessage();
+};
+
+#endif /* PARAMETERSPLUGIN_PYINTERP_H_ */
index 63ba2ab685faf77272fc85da7ff3c8276946a8dd..027f50c246e8de829531bd99f0f5f3f8190583ac 100644 (file)
@@ -4,8 +4,8 @@
   <workbench id="Part">
     <group id="Parameters">
       <feature id="Parameter" title="New Variable" tooltip="Creates a variable" icon=":pictures/expression.png">
-        <stringvalue id="variable" label="Name"/>
-        <stringvalue id="expression" icon="Value"/>
+        <stringvalue id="variable" label="Name" icon=":pictures/expression.png"/>
+        <expr_editor id="expression"/>
       </feature>
     </group>
   </workbench>
index 567ad5677e050e0d4923001afdbc3a23f2a75709..3faa7bd6db81fdf1c8c3ae5d152879123e827ee8 100644 (file)
@@ -12,7 +12,7 @@
 #include <ModelAPI_Object.h>
 #include <ModelAPI_ResultPart.h>
 #include <ModelAPI_ResultConstruction.h>
-#include <ModelAPI_ResultParameters.h>
+#include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultGroup.h>
 
@@ -46,7 +46,7 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
           return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex));
         case ParamObject: {
           DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
-          ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultParameters::group(), theIndex.row());
+          ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultParameter::group(), theIndex.row());
           if (aObject)
             return aObject->data()->name().c_str();
         }
@@ -112,7 +112,7 @@ int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const
 
   DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
   if (theParent.internalId() == ParamsFolder)
-    return aRootDoc->size(ModelAPI_ResultParameters::group());
+    return aRootDoc->size(ModelAPI_ResultParameter::group());
 
   if (theParent.internalId() == ConstructFolder)
     return aRootDoc->size(ModelAPI_ResultConstruction::group());
@@ -183,7 +183,7 @@ ObjectPtr XGUI_TopDataModel::object(const QModelIndex& theIndex) const
       return ObjectPtr();
     case ParamObject: {
       DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
-      return aRootDoc->object(ModelAPI_ResultParameters::group(), theIndex.row());
+      return aRootDoc->object(ModelAPI_ResultParameter::group(), theIndex.row());
     }
     case ConstructObject: {
       DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
@@ -204,7 +204,7 @@ QModelIndex XGUI_TopDataModel::findParent(const ObjectPtr& theObject) const
 
 QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const
 {
-  if (theGroup == ModelAPI_ResultParameters::group())
+  if (theGroup == ModelAPI_ResultParameter::group())
     return createIndex(0, 0, (qint32) ParamsFolder);
   if (theGroup == ModelAPI_ResultConstruction::group())
     return createIndex(1, 0, (qint32) ConstructFolder);
@@ -228,7 +228,7 @@ QModelIndex XGUI_TopDataModel::objectIndex(const ObjectPtr& theObject) const
       }
     }
     if (aRow != -1) {
-      if (aGroup == ModelAPI_ResultParameters::group())
+      if (aGroup == ModelAPI_ResultParameter::group())
         return createIndex(aRow, 0, (qint32) ParamObject);
       if (aGroup == ModelAPI_ResultConstruction::group())
         return createIndex(aRow, 0, (qint32) ConstructObject);
@@ -272,7 +272,7 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
         case GroupsFolder:
           return tr("Groups") + QString(" (%1)").arg(rowCount(theIndex));
         case ParamObject: {
-          ObjectPtr aObject = partDocument()->object(ModelAPI_ResultParameters::group(),
+          ObjectPtr aObject = partDocument()->object(ModelAPI_ResultParameter::group(),
                                                      theIndex.row());
           if (aObject)
             return std::dynamic_pointer_cast<ModelAPI_Object>(aObject)->data()->name().c_str();
@@ -369,7 +369,7 @@ int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const
           return 0;
       }
     case ParamsFolder:
-      return partDocument()->size(ModelAPI_ResultParameters::group());
+      return partDocument()->size(ModelAPI_ResultParameter::group());
     case ConstructFolder:
       return partDocument()->size(ModelAPI_ResultConstruction::group());
     case BodiesFolder:
@@ -476,7 +476,7 @@ ObjectPtr XGUI_PartDataModel::object(const QModelIndex& theIndex) const
       return ObjectPtr();
 
     case ParamObject:
-      return partDocument()->object(ModelAPI_ResultParameters::group(), theIndex.row());
+      return partDocument()->object(ModelAPI_ResultParameter::group(), theIndex.row());
     case ConstructObject:
       return partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row());
     case BodiesObject:
@@ -501,7 +501,7 @@ QModelIndex XGUI_PartDataModel::findParent(const ObjectPtr& theObject) const
 
 QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const
 {
-  if (theGroup == ModelAPI_ResultParameters::group())
+  if (theGroup == ModelAPI_ResultParameter::group())
     return createIndex(0, 0, (qint32) ParamsFolder);
   if (theGroup == ModelAPI_ResultConstruction::group())
     return createIndex(1, 0, (qint32) ConstructFolder);
@@ -538,7 +538,7 @@ QModelIndex XGUI_PartDataModel::objectIndex(const ObjectPtr& theObject) const
     }
     if (aRow == -1)
       return aIndex;
-    if (aGroup == ModelAPI_ResultParameters::group())
+    if (aGroup == ModelAPI_ResultParameter::group())
       return createIndex(aRow, 0, (qint32) ParamObject);
     else if (aGroup == ModelAPI_ResultConstruction::group())
       return createIndex(aRow, 0, (qint32) ConstructObject);
index 39dd556e638aaf646e1082eb13cf1ffbecba190b..74ab35722a14844fa64fe2d6e110eb92ea572a1d 100644 (file)
Binary files a/src/XGUI/pictures/expression.png and b/src/XGUI/pictures/expression.png differ