From: Alexey Kondratyev Date: Fri, 29 Oct 2021 12:05:32 +0000 (+0300) Subject: [bos #26444] [EDF] (2021) SHAPER: Improve treatment of parameters X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7464bbefab8bffca63ccfbd54f6543ab25278273;p=modules%2Fshaper.git [bos #26444] [EDF] (2021) SHAPER: Improve treatment of parameters Fix bug with importing not all parameters from file. Update algorithm importing parameters to disabling buttons if list of parameters is invalid. --- diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp index ac367dfac..e911b9821 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp @@ -489,6 +489,7 @@ void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor, FeaturePtr aFeature = myParametersList.at(myDelegate->editIndex().row()); QTreeWidgetItem* aItem = myParameters->child(myDelegate->editIndex().row()); int aColumn = myDelegate->editIndex().column(); + int aRow = myDelegate->editIndex().row(); QString aText = aItem->text(aColumn); bool isModified = false; @@ -500,7 +501,7 @@ void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor, while (aText.indexOf(" ") != -1) { aText.replace(" ", ""); } - if (hasName(aText)) { + if (hasName(aText, aRow)) { myMessage = translate("Name '%1' already exists.").arg(aText); QTimer::singleShot(50, this, SLOT(sendWarning())); return; @@ -792,12 +793,11 @@ void ParametersPlugin_WidgetParamsMgr::onDown() } -bool ParametersPlugin_WidgetParamsMgr::hasName(const QString& theName) const +bool ParametersPlugin_WidgetParamsMgr::hasName(const QString& theName, int theIndex) const { - int aCurrent = myDelegate->editIndex().row(); int i = 0; foreach(FeaturePtr aFeature, myParametersList) { - if ((i != aCurrent) && (aFeature->data()->name() == theName.toStdWString())) + if ((i != theIndex) && (aFeature->data()->name() == theName.toStdWString())) return true; i++; } @@ -828,11 +828,13 @@ void ParametersPlugin_WidgetParamsMgr::onSelectionChanged() //myRemoveBtn->setEnabled(isParameter); myUpBtn->setEnabled(isParameter); myDownBtn->setEnabled(isParameter); + myImportBtn->setEnabled(true); } else { myInsertBtn->setEnabled(false); //myRemoveBtn->setEnabled(false); myUpBtn->setEnabled(false); myDownBtn->setEnabled(false); + myImportBtn->setEnabled(false); } myRemoveBtn->setEnabled(!aItemsList.isEmpty()); } @@ -847,6 +849,7 @@ void ParametersPlugin_WidgetParamsMgr::enableButtons(bool theEnable) //myRemoveBtn->setEnabled(theEnable); myUpBtn->setEnabled(theEnable); myDownBtn->setEnabled(theEnable); + myImportBtn->setEnabled(theEnable); } myOkCancelBtn->button(QDialogButtonBox::Ok)->setEnabled(theEnable); } @@ -858,7 +861,8 @@ bool ParametersPlugin_WidgetParamsMgr::isValid() aItem = myParameters->child(i); if ((aItem->text(Col_Name) == NoName) || (aItem->text(Col_Equation) == translate(NoValue)) || - (!ModelAPI_Expression::isVariable(aItem->text(Col_Name).toStdString())) ) { + (!ModelAPI_Expression::isVariable(aItem->text(Col_Name).toStdString())) || + (hasName(aItem->text(Col_Name), i)) ) { return false; } } diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h index 2a08f023e..6cc543d0d 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h @@ -151,7 +151,7 @@ private: bool isValid(); /// Returns true if parameter with the given name already exists - bool hasName(const QString& theName) const; + bool hasName(const QString& theName, int theIndex) const; /// Enable or disable buttons for parameters managemnt void enableButtons(bool theEnable); diff --git a/src/PythonAPI/model/parameter/import_parameter.py b/src/PythonAPI/model/parameter/import_parameter.py index 3ff86bf8d..3b2a25c06 100644 --- a/src/PythonAPI/model/parameter/import_parameter.py +++ b/src/PythonAPI/model/parameter/import_parameter.py @@ -18,7 +18,7 @@ # from salome.shaper import model -import codecs +import codecs, sys def changeTab(theLine): aResult = theLine.split("#")[0].replace("\t"," ")