Salome HOME
Fix for crash on multi-selection of group-vertices on imported body with Shift-key...
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetExprEditor.cpp
index 64ca2e312ca86254fae29a9ef714f6902c1a50da..346b324c810e66a937512785773a0ca3b7d9f66f 100644 (file)
 #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 <ModelAPI_ResultParameter.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeDouble.h>
 
 #include <Config_WidgetAPI.h>
 
@@ -27,6 +29,7 @@
 #include <QSize>
 #include <QShortcut>
 #include <QScrollBar>
+#include <QFontMetrics>
 
 #include <memory>
 #include <string>
@@ -149,6 +152,12 @@ ModuleBase_WidgetExprEditor::ModuleBase_WidgetExprEditor(QWidget* theParent,
   QVBoxLayout* aMainLay = new QVBoxLayout(this);
   ModuleBase_Tools::adjustMargins(aMainLay);
 
+  myResultLabel = new QLabel(this);
+  myResultLabel->setWordWrap(true);
+  QFontMetrics fm(myResultLabel->font());
+  myResultLabel->setMinimumHeight(fm.height() * 2); // set 2 line height as minimum
+  myResultLabel->setAlignment(Qt::AlignLeft|Qt::AlignBottom);
+  aMainLay->addWidget(myResultLabel);
   myEditor = new ExpressionEditor(this);
   myEditor->setMinimumHeight(20);
   aMainLay->addWidget(myEditor);
@@ -171,6 +180,25 @@ bool ModuleBase_WidgetExprEditor::storeValueCustom() const
   QString aWidgetValue = myEditor->toPlainText();
   aStringAttr->setValue(aWidgetValue.toStdString());
   updateObject(myFeature);
+
+  // Try to get the value
+  QString aStateMsg;
+  std::string anErrorMessage = myFeature->error();
+  if (anErrorMessage.empty()) {
+    ResultParameterPtr aParam =
+      std::dynamic_pointer_cast<ModelAPI_ResultParameter>(myFeature->firstResult());
+    if(aParam.get()) {
+      AttributeDoublePtr aValueAttr =
+        aParam->data()->real(ModelAPI_ResultParameter::VALUE());
+      if (aValueAttr.get()) {
+        double aValue = aValueAttr->value();
+        aStateMsg = "Result: " + QString::number(aValue);
+      }
+    }
+  } else {
+    aStateMsg = QString::fromStdString(anErrorMessage);
+  }
+  myResultLabel->setText(aStateMsg);
   return true;
 }