Salome HOME
Issue #2481: Application error when create fillet
[modules/shaper.git] / src / ParametersPlugin / ParametersPlugin_WidgetParamsMgr.cpp
index 524e92710d5c5ee53d10553cb15f0d4f623aee57..96e10edb14c720706a7f03058c5e5c9059301d4f 100644 (file)
@@ -1,13 +1,29 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File:        ParametersPlugin_WidgetParamsMgr.cpp
-// Created:     11 Apr 2016
-// Author:      Vitaly SMETANNIKOV
+// Copyright (C) 2014-2017  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
 
 #include "ParametersPlugin_WidgetParamsMgr.h"
 #include "ParametersPlugin_Parameter.h"
 #include "ParametersPlugin_Validators.h"
 
+#include <Events_InfoMessage.h>
+
 #include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_AttributeRefList.h>
@@ -15,6 +31,8 @@
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Session.h>
+#include <ModelAPI_Tools.h>
+#include <ModelAPI_Expression.h>
 
 #include <ModuleBase_Tools.h>
 
@@ -29,6 +47,7 @@
 #include <QTimer>
 #include <QEvent>
 #include <QKeyEvent>
+#include <QDialogButtonBox>
 
 enum ColumnType {
   Col_Name,
@@ -41,22 +60,39 @@ const char* NoName = "<NoName>";
 const char* NoValue = "<NoValue>";
 const char* NotValid = "<NotValid>";
 
+/*!
+ * \ingroup GUI
+ * ItemDelegate object in order to redefine items behavior
+ */
 class ParametersPlugin_ItemDelegate : public QStyledItemDelegate
 {
 public:
-  ParametersPlugin_ItemDelegate(QObject* thaParent) : 
+  /// Constructor
+  /// \param thaParent a parent
+  ParametersPlugin_ItemDelegate(QObject* thaParent) :
       QStyledItemDelegate(thaParent) {}
 
-  virtual void paint(QPainter* painter, 
-    const QStyleOptionViewItem& option, 
+  /// Redefinition of virtual method
+  /// \param painter a painter object
+  /// \param option the item options
+  /// \param index the current index
+  virtual void paint(QPainter* painter,
+    const QStyleOptionViewItem& option,
     const QModelIndex& index ) const;
-  
-  virtual QWidget* createEditor(QWidget* parent, 
-                                const QStyleOptionViewItem& option, 
+
+  /// Redefinition of virtual method
+  /// \param parent a parent widget
+  /// \param option the item options
+  /// \param index the current index
+  virtual QWidget* createEditor(QWidget* parent,
+                                const QStyleOptionViewItem& option,
                                 const QModelIndex& index) const;
 
+  /// Returns True if the given index is editable item
+  /// \param theIndex an item index
   bool isEditable(const QModelIndex& theIndex) const;
 
+  /// Returns currently editing index
   QModelIndex editIndex() const { return myEditingIdx; }
 
 private:
@@ -74,16 +110,18 @@ bool ParametersPlugin_ItemDelegate::isEditable(const QModelIndex& theIndex) cons
   return true;
 }
 
-void ParametersPlugin_ItemDelegate::paint(QPainter* painter, 
-                                          const QStyleOptionViewItem& option, 
+void ParametersPlugin_ItemDelegate::paint(QPainter* painter,
+                                          const QStyleOptionViewItem& option,
                                           const QModelIndex& index ) const
 {
   QBrush aBrush = painter->brush();
   QPen aPen = painter->pen();
-  if (!isEditable(index))
+  //if (!isEditable(index))
+  //  painter->setBrush(Qt::lightGray);
+  if (!index.parent().isValid())
     painter->setBrush(Qt::lightGray);
 
-  painter->setPen(Qt::darkGray);
+  painter->setPen(Qt::lightGray);
   painter->drawRect(option.rect);
   painter->setPen(aPen);
 
@@ -91,8 +129,8 @@ void ParametersPlugin_ItemDelegate::paint(QPainter* painter,
   painter->setBrush(aBrush);
 }
 
-QWidget* ParametersPlugin_ItemDelegate::createEditor(QWidget* parent, 
-                                                     const QStyleOptionViewItem& option, 
+QWidget* ParametersPlugin_ItemDelegate::createEditor(QWidget* parent,
+                                                     const QStyleOptionViewItem& option,
                                                      const QModelIndex& index) const
 {
   myEditingIdx = index;
@@ -100,7 +138,8 @@ QWidget* ParametersPlugin_ItemDelegate::createEditor(QWidget* parent,
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
-void ParametersPlugin_TreeWidget::closeEditor(QWidget* theEditor, QAbstractItemDelegate::EndEditHint theHint)
+void ParametersPlugin_TreeWidget::closeEditor(QWidget* theEditor,
+                                              QAbstractItemDelegate::EndEditHint theHint)
 {
   if (theHint == QAbstractItemDelegate::EditNextItem) {
     QModelIndex aCurrent = currentIndex();
@@ -135,15 +174,16 @@ void ParametersPlugin_TreeWidget::closeEditor(QWidget* theEditor, QAbstractItemD
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 
-ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theParent, const Config_WidgetAPI* theData)
-  : ModuleBase_ModelWidget(theParent, theData)
+ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theParent,
+  const Config_WidgetAPI* theData)
+  : ModuleBase_ModelDialogWidget(theParent, theData)
 {
   QVBoxLayout* aLayout = new QVBoxLayout(this);
 
   myTable = new ParametersPlugin_TreeWidget(this);
   myTable->setColumnCount(4);
   QStringList aHeaders;
-  aHeaders << tr("Name") << tr("Equation") << tr("Result") << tr("Comment");
+  aHeaders << tr("Name") << tr("Expression") << tr("Result") << tr("Comment");
   myTable->setHeaderLabels(aHeaders);
   myTable->setColumnWidth(Col_Name, 200);
   myTable->setColumnWidth(Col_Equation, 100);
@@ -158,7 +198,7 @@ ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theP
   connect(myTable, SIGNAL(itemSelectionChanged()), SLOT(onSelectionChanged()));
 
   myDelegate = new ParametersPlugin_ItemDelegate(myTable);
-  connect(myDelegate, SIGNAL(closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint)), 
+  connect(myDelegate, SIGNAL(closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint)),
           SLOT(onCloseEditor(QWidget*, QAbstractItemDelegate::EndEditHint)));
 
   myTable->setItemDelegate(myDelegate);
@@ -168,11 +208,13 @@ ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theP
   QStringList aNames;
   aNames<<tr("Parameters");
   myParameters = new QTreeWidgetItem(aNames);
+  myParameters->setFlags(Qt::ItemIsEnabled);
   myTable->addTopLevelItem(myParameters);
 
   aNames.clear();
   aNames<<tr("Features");
   myFeatures = new QTreeWidgetItem(aNames);
+  myFeatures->setFlags(Qt::ItemIsEnabled);
   myTable->addTopLevelItem(myFeatures);
 
   QHBoxLayout* aBtnLayout = new QHBoxLayout(this);
@@ -219,7 +261,7 @@ void ParametersPlugin_WidgetParamsMgr::selectItemScroll(QTreeWidgetItem* aItem)
   QModelIndex aParent = myTable->model()->index(0, 0);
   int aChildIdx = myParameters->indexOfChild(aItem);
   QModelIndex aIndex = myTable->model()->index(aChildIdx, Col_Name, aParent);
-  myTable->selectionModel()->select(aIndex, 
+  myTable->selectionModel()->select(aIndex,
     QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
   myTable->scrollToItem(aItem);
 }
@@ -230,11 +272,12 @@ bool ParametersPlugin_WidgetParamsMgr::storeValueCustom()
   ParametersPlugin_ExpressionValidator aValidator;
   std::list<std::string> aArgs;
   std::string aAttrId = ParametersPlugin_Parameter::VARIABLE_ID();
-  std::string aErr;
+  Events_InfoMessage aErr;
   int aId = 0;
   foreach(FeaturePtr aFeature, myParametersList) {
     if (!aValidator.isValid(aFeature->attribute(aAttrId), aArgs, aErr)) {
-      QMessageBox::warning(this, tr("Warning"), aErr.c_str());
+      // TODO(spo): translate
+      QMessageBox::warning(this, tr("Warning"), aErr.messageString().c_str());
       selectItemScroll(myParameters->child(aId));
       return false;
     }
@@ -268,7 +311,7 @@ void ParametersPlugin_WidgetParamsMgr::updateParametersFeatures()
   int aNbFeatures = aDoc->numInternalFeatures();
   for (int i = 0; i < aNbFeatures; i++) {
     aParamFeature = aDoc->internalFeature(i);
-    if (aParamFeature->getKind() == ParametersPlugin_Parameter::ID()) {
+    if (aParamFeature && aParamFeature->getKind() == ParametersPlugin_Parameter::ID()) {
       myParametersList.append(aParamFeature);
     }
   }
@@ -276,19 +319,20 @@ void ParametersPlugin_WidgetParamsMgr::updateParametersFeatures()
 
 void ParametersPlugin_WidgetParamsMgr::updateFeaturesPart()
 {
-  updateItem(myFeatures, featuresItems(myParametersList));
+  QList<FeaturePtr> aFeatureList;
+  updateItem(myFeatures, featuresItems(myParametersList, aFeatureList));
 }
 
 void ParametersPlugin_WidgetParamsMgr::updateParametersPart()
 {
   updateItem(myParameters, parametersItems(myParametersList));
-  bool aIsValid = checkIsValid();
+  bool aIsValid = isValid();
   enableButtons(aIsValid);
 }
 
 
 QList<QStringList> ParametersPlugin_WidgetParamsMgr::
-  featuresItems(const QList<FeaturePtr>& theFeatures) const
+  featuresItems(const QList<FeaturePtr>& theFeatures, QList<FeaturePtr>& theFeatureList) const
 {
   QList<QStringList> aItemsList;
   ResultParameterPtr aParam;
@@ -299,29 +343,34 @@ QList<QStringList> ParametersPlugin_WidgetParamsMgr::
     for(aIt = aRefs.cbegin(); aIt != aRefs.cend(); aIt++) {
       std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
       FeaturePtr aReferenced = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
-      if (aReferenced.get()) {
+      if (aReferenced.get() && (aReferenced != aParameter)) {
         if (aReferenced->getKind() == ParametersPlugin_Parameter::ID()) {
           // Find referenced feature Recursive
           QList<FeaturePtr> aList;
           aList.append(aReferenced);
-          QList<QStringList> aItems = featuresItems(aList);
+          QList<QStringList> aItems = featuresItems(aList, theFeatureList);
           aItemsList.append(aItems);
         } else {
-          QStringList aValNames;
-          aValNames << aReferenced->data()->name().c_str();
-
-          AttributeDoublePtr aDouble = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aAttr);
-          if (aDouble.get()) {
-            aValNames << aDouble->text().c_str();
-            aValNames << QString::number(aDouble->value());
-          } else {
-            AttributeIntegerPtr aInt = std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(aAttr);
-            if (aInt.get()) {
-              aValNames << aInt->text().c_str();
-              aValNames << QString::number(aInt->value());
+          if (!theFeatureList.contains(aReferenced)) {
+            QStringList aValNames;
+            aValNames << aReferenced->data()->name().c_str();
+
+            AttributeDoublePtr aDouble =
+              std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aAttr);
+            if (aDouble.get()) {
+              aValNames << aDouble->text().c_str();
+              aValNames << QString::number(aDouble->value());
+            } else {
+              AttributeIntegerPtr aInt =
+                std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(aAttr);
+              if (aInt.get()) {
+                aValNames << aInt->text().c_str();
+                aValNames << QString::number(aInt->value());
+              }
             }
+            aItemsList.append(aValNames);
+            theFeatureList.append(aReferenced);
           }
-          aItemsList.append(aValNames);
         }
       }
     }
@@ -352,7 +401,8 @@ QList<QStringList> ParametersPlugin_WidgetParamsMgr::
     } else
       aValues << aExpr.c_str();
 
-    std::string aErr = aParameter->data()->string(ParametersPlugin_Parameter::EXPRESSION_ERROR_ID())->value();
+    std::string 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());
@@ -374,7 +424,7 @@ void ParametersPlugin_WidgetParamsMgr::onDoubleClick(const QModelIndex& theIndex
   }
 }
 
-void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor, 
+void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor,
                                                      QAbstractItemDelegate::EndEditHint theHint)
 {
   FeaturePtr aFeature = myParametersList.at(myDelegate->editIndex().row());
@@ -388,19 +438,23 @@ void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor,
     {
       AttributeStringPtr aStringAttr = aFeature->string(ParametersPlugin_Parameter::VARIABLE_ID());
       if (!aText.isEmpty()) {
+        while (aText.indexOf(" ") != -1) {
+          aText.replace(" ", "");
+        }
         if (hasName(aText)) {
-          myMessage = tr("Name %1 already exists.").arg(aText);
+          myMessage = tr("Name '%1' already exists.").arg(aText);
           QTimer::singleShot(50, this, SLOT(sendWarning()));
           return;
         }
         aStringAttr->setValue(aText.toStdString());
         isModified = true;
-      } 
+      }
     }
     break;
   case Col_Equation:
     {
-      AttributeStringPtr aStringAttr = aFeature->string(ParametersPlugin_Parameter::EXPRESSION_ID());
+      AttributeStringPtr aStringAttr =
+        aFeature->string(ParametersPlugin_Parameter::EXPRESSION_ID());
       if (!aText.isEmpty()) {
         if (aText != aStringAttr->value().c_str()) {
           aStringAttr->setValue(aText.toStdString());
@@ -426,20 +480,22 @@ void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor,
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
 
-  if (aColumn == Col_Equation)
+  if (aColumn != Col_Comment)
     updateParametersPart();
   updateFeaturesPart();
+
+  onSelectionChanged();
 }
 
-void ParametersPlugin_WidgetParamsMgr::updateItem(QTreeWidgetItem* theItem, 
+void ParametersPlugin_WidgetParamsMgr::updateItem(QTreeWidgetItem* theItem,
                                                   const QList<QStringList>& theFeaturesList)
 {
   if (theFeaturesList.count() != theItem->childCount()) {
     if (theItem->childCount()  < theFeaturesList.count()) {
-      while (theItem->childCount() != theFeaturesList.count()) 
-        theItem->addChild(createNewItem());
+      while (theItem->childCount() != theFeaturesList.count())
+        theItem->addChild(createNewItem(theItem));
     } else {
-      while (theItem->childCount() != theFeaturesList.count()) 
+      while (theItem->childCount() != theFeaturesList.count())
         theItem->removeChild(theItem->child(theItem->childCount() - 1));
     }
   }
@@ -471,14 +527,18 @@ FeaturePtr ParametersPlugin_WidgetParamsMgr::createParameter() const
 }
 
 
-QTreeWidgetItem* ParametersPlugin_WidgetParamsMgr::createNewItem() const
+QTreeWidgetItem* ParametersPlugin_WidgetParamsMgr::createNewItem(QTreeWidgetItem* theParent) const
 {
   QStringList aValues;
   aValues << NoName;
   aValues << NoValue;
 
   QTreeWidgetItem* aItem = new QTreeWidgetItem(aValues);
-  aItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
+  if (theParent == myParameters) {
+    aItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
+    aItem->setForeground(2, Qt::darkGray);
+  } else
+    aItem->setFlags(Qt::NoItemFlags);
   return aItem;
 }
 
@@ -490,7 +550,7 @@ void ParametersPlugin_WidgetParamsMgr::onAdd()
     return;
 
   myParametersList.append(aFeature);
-  updateParametersPart();    
+  updateParametersPart();
 
   QTreeWidgetItem* aItem = myParameters->child(myParameters->childCount() - 1);
 
@@ -558,26 +618,16 @@ void ParametersPlugin_WidgetParamsMgr::onRemove()
   QObjectPtrList anObjects;
   anObjects.append(aCurFeature);
 
-  std::set<FeaturePtr> aDirectRefFeatures, aIndirectRefFeatures;
-  ModuleBase_Tools::findReferences(anObjects, aDirectRefFeatures, aIndirectRefFeatures);
+  std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
+  std::set<FeaturePtr> aFeatures;
+  ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
+  ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
 
-  bool doDeleteReferences = true;
-  if (ModuleBase_Tools::isDeleteFeatureWithReferences(anObjects, aDirectRefFeatures, 
-      aIndirectRefFeatures, this, doDeleteReferences)) {
-
-    std::set<FeaturePtr> aFeaturesToDelete;
-    if (doDeleteReferences) {
-      aFeaturesToDelete = aDirectRefFeatures;
-      aFeaturesToDelete.insert(aIndirectRefFeatures.begin(), aIndirectRefFeatures.end());
-    }
-    aDoc->removeFeature(aCurFeature);
-    std::set<FeaturePtr>::const_iterator anIt = aFeaturesToDelete.begin(),
-                                         aLast = aFeaturesToDelete.end();
-    for (; anIt != aLast; anIt++) {
-      FeaturePtr aFeature = (*anIt);
-      DocumentPtr aDoc = aFeature->document();
-      aDoc->removeFeature(aFeature);
-    }
+  std::set<FeaturePtr> aFeatureRefsToDelete;
+  if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, this, aFeatureRefsToDelete)) {
+    if (!aFeatureRefsToDelete.empty())
+      aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
+    ModelAPI_Tools::removeFeatures(aFeatures, false);
 
     Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
     Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
@@ -606,8 +656,12 @@ void ParametersPlugin_WidgetParamsMgr::onUp()
   else
     aDoc->moveFeature(aCurFeature, myParametersList.at(aCurrentPos - 2));
 
-
-  Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED));
+  // add the updated also the feature that goes down
+  Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
+  static Events_ID EVENT_UPD = Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED);
+  ModelAPI_EventCreator::get()->sendUpdated(myParametersList.at(aCurrentPos - 1), EVENT_UPD);
+  Events_Loop::loop()->flush(EVENT_UPD);
+  Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
   Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
   Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
   updateParametersFeatures();
@@ -635,8 +689,13 @@ void ParametersPlugin_WidgetParamsMgr::onDown()
   SessionPtr aMgr = ModelAPI_Session::get();
   std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
   aDoc->moveFeature(aCurFeature, myParametersList.at(aCurrentPos + 1));
+  // add the updated also the feature that goes up
+  static Events_ID EVENT_UPD = Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED);
+  ModelAPI_EventCreator::get()->sendUpdated(myParametersList.at(aCurrentPos + 1), EVENT_UPD);
 
+  Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
   Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED));
+  Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
   Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
   Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
   updateParametersFeatures();
@@ -666,13 +725,16 @@ bool ParametersPlugin_WidgetParamsMgr::hasName(const QString& theName) const
 void ParametersPlugin_WidgetParamsMgr::sendWarning()
 {
   QMessageBox::warning(this, tr("Warning"), myMessage);
+  QTreeWidgetItem* aItem = myTable->currentItem();
+  if (aItem)
+    myTable->editItem(aItem);
 }
 
 void ParametersPlugin_WidgetParamsMgr::onSelectionChanged()
 {
-  bool isValid = checkIsValid();
-  if (isValid) {
-    QList<QTreeWidgetItem*> aItemsList = myTable->selectedItems();
+  QList<QTreeWidgetItem*> aItemsList = myTable->selectedItems();
+  bool aIsValid = isValid();
+  if (aIsValid) {
     bool isParameter = false;
     foreach(QTreeWidgetItem* aItem, aItemsList) {
       if (aItem->parent() == myParameters) {
@@ -681,41 +743,43 @@ void ParametersPlugin_WidgetParamsMgr::onSelectionChanged()
       }
     }
     myInsertBtn->setEnabled(isParameter);
-    myRemoveBtn->setEnabled(isParameter);
+    //myRemoveBtn->setEnabled(isParameter);
     myUpBtn->setEnabled(isParameter);
     myDownBtn->setEnabled(isParameter);
   } else {
     myInsertBtn->setEnabled(false);
-    myRemoveBtn->setEnabled(false);
+    //myRemoveBtn->setEnabled(false);
     myUpBtn->setEnabled(false);
     myDownBtn->setEnabled(false);
   }
+  myRemoveBtn->setEnabled(!aItemsList.isEmpty());
 }
 
 void ParametersPlugin_WidgetParamsMgr::enableButtons(bool theEnable)
 {
   myAddBtn->setEnabled(theEnable);
-  if (theEnable) 
+  if (theEnable)
     onSelectionChanged();
   else {
     myInsertBtn->setEnabled(theEnable);
-    myRemoveBtn->setEnabled(theEnable);
+    //myRemoveBtn->setEnabled(theEnable);
     myUpBtn->setEnabled(theEnable);
     myDownBtn->setEnabled(theEnable);
   }
+  myOkCancelBtn->button(QDialogButtonBox::Ok)->setEnabled(theEnable);
 }
 
-bool ParametersPlugin_WidgetParamsMgr::checkIsValid()
+bool ParametersPlugin_WidgetParamsMgr::isValid()
 {
   QTreeWidgetItem* aItem;
-  bool aIsValid = true;
   for(int i = 0; i < myParameters->childCount(); i++) {
     aItem = myParameters->child(i);
-    if ((aItem->text(Col_Name) == NoName) || (aItem->text(Col_Equation) == NoValue)) {
-      aIsValid = false;
-      break;
+    if ((aItem->text(Col_Name) == NoName) ||
+        (aItem->text(Col_Equation) == NoValue) ||
+        (!ModelAPI_Expression::isVariable(aItem->text(Col_Name).toStdString())) ) {
+      return false;
     }
   }
-  return aIsValid;
+  return true;
 }