Salome HOME
Copyright update 2021
[modules/shaper.git] / src / ParametersPlugin / ParametersPlugin_WidgetParamsMgr.cpp
index 9078329662e93044b3d61496b2e572539f63be1d..62a432a8b95cd06c72969d2843b5290e2d00c267 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2021  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
 #include <GeomDataAPI_Point2D.h>
 
 #include <ModuleBase_Tools.h>
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_IViewer.h>
 
 #include <Events_Loop.h>
+#include <Config_PropManager.h>
 
 #include <QLayout>
 #include <QPushButton>
@@ -50,6 +53,7 @@
 #include <QEvent>
 #include <QKeyEvent>
 #include <QDialogButtonBox>
+#include <QShortcut>
 
 enum ColumnType {
   Col_Name,
@@ -176,9 +180,9 @@ void ParametersPlugin_TreeWidget::closeEditor(QWidget* theEditor,
 /////////////////////////////////////////////////////////////////////////////////////////////////
 
 ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theParent,
-  const Config_WidgetAPI* theData)
+  const Config_WidgetAPI* theData, ModuleBase_IWorkshop* theWorkshop)
   : ModuleBase_ModelDialogWidget(theParent, theData),
-  isUpplyBlocked(false)
+  myWorkshop(theWorkshop), isUpplyBlocked(false)
 {
   QVBoxLayout* aLayout = new QVBoxLayout(this);
 
@@ -238,6 +242,13 @@ ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theP
   connect(myAddBtn, SIGNAL(clicked(bool)), SLOT(onAdd()));
   aBtnLayout->addWidget(myAddBtn);
 
+  QString aAddStr(Config_PropManager::string("Shortcuts", "add_parameter_shortcut").c_str());
+  if (aAddStr.isEmpty())
+    aAddStr = "Ctrl+A";
+
+  QShortcut* aAddShc = new QShortcut(QKeySequence(aAddStr), myAddBtn);
+  connect(aAddShc, SIGNAL(activated()), SLOT(onAdd()));
+
   myInsertBtn = new QPushButton(translate("Insert"), this);
   connect(myInsertBtn, SIGNAL(clicked(bool)), SLOT(onInsert()));
   aBtnLayout->addWidget(myInsertBtn);
@@ -374,27 +385,28 @@ QList<QStringList> ParametersPlugin_WidgetParamsMgr::
         } else {
           if (!theFeatureList.contains(aReferenced)) {
             QStringList aValNames;
-            aValNames << aReferenced->data()->name().c_str();
+            aValNames << QString::fromStdWString(aReferenced->data()->name());
 
             std::string aId = aAttr->attributeType();
             if (aId == ModelAPI_AttributeDouble::typeId()) {
               AttributeDoublePtr aDouble =
                 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aAttr);
-              aValNames << aDouble->text().c_str();
+              aValNames << QString::fromStdWString(aDouble->text());
               aValNames << QString::number(aDouble->value());
             }
             else if (aId == ModelAPI_AttributeInteger::typeId()) {
               AttributeIntegerPtr aInt =
                 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(aAttr);
-              aValNames << aInt->text().c_str();
+              aValNames << QString::fromStdWString(aInt->text());
               aValNames << QString::number(aInt->value());
             }
             else if (aId == GeomDataAPI_Point::typeId()) {
               std::shared_ptr<GeomDataAPI_Point> aPnt =
                 std::dynamic_pointer_cast<GeomDataAPI_Point>(aAttr);
 
-              QString aExpr = QString("%1,%2,%3").arg(aPnt->textX().c_str()).
-                arg(aPnt->textY().c_str()).arg(aPnt->textZ().c_str());
+              QString aExpr = QString("%1,%2,%3").arg(QString::fromStdWString(aPnt->textX())).
+                                                  arg(QString::fromStdWString(aPnt->textY())).
+                                                  arg(QString::fromStdWString(aPnt->textZ()));
               aValNames << aExpr;
 
               QString aRes = QString("%1,%2,%3").arg(aPnt->x()).arg(aPnt->y()).arg(aPnt->z());
@@ -404,8 +416,8 @@ QList<QStringList> ParametersPlugin_WidgetParamsMgr::
               std::shared_ptr<GeomDataAPI_Point2D> aPnt =
                 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
 
-              QString aExpr = QString("%1,%2").arg(aPnt->textX().c_str()).
-                arg(aPnt->textY().c_str());
+              QString aExpr = QString("%1,%2").arg(QString::fromStdWString(aPnt->textX())).
+                                               arg(QString::fromStdWString(aPnt->textY()));
               aValNames << aExpr;
 
               QString aRes = QString("%1,%2").arg(aPnt->x()).arg(aPnt->y());
@@ -444,8 +456,7 @@ QList<QStringList> ParametersPlugin_WidgetParamsMgr::
     } else
       aValues << aExpr.c_str();
 
-    std::string aErr =
-      aParameter->data()->string(ParametersPlugin_Parameter::EXPRESSION_ERROR_ID())->value();
+    aErr = aParameter->data()->string(ParametersPlugin_Parameter::EXPRESSION_ERROR_ID())->value();
     if (aErr.empty()) {
       AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
       aValues << QString::number(aValueAttribute->value());
@@ -758,7 +769,7 @@ bool ParametersPlugin_WidgetParamsMgr::hasName(const QString& theName) const
   int aCurrent = myDelegate->editIndex().row();
   int i = 0;
   foreach(FeaturePtr aFeature, myParametersList) {
-    if ((i != aCurrent) && (aFeature->data()->name() == theName.toStdString()))
+    if ((i != aCurrent) && (aFeature->data()->name() == theName.toStdWString()))
       return true;
     i++;
   }
@@ -848,4 +859,5 @@ void ParametersPlugin_WidgetParamsMgr::onShowPreview()
   SessionPtr aMgr = ModelAPI_Session::get();
   aMgr->blockAutoUpdate(false);
   aMgr->blockAutoUpdate(true);
-}
\ No newline at end of file
+  myWorkshop->viewer()->update();
+}