X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FParametersPlugin%2FParametersPlugin_WidgetParamsMgr.cpp;h=2c75d5696fe947df77851f3b10a98b19c04e5581;hb=9628c44ddd75b2adc08bb7c4ddc690b2e09db3c5;hp=56a65860d70b924519c55990386074129dfb1c43;hpb=31be99a43f28c347bb52f6503ee1585348e4d582;p=modules%2Fshaper.git diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp index 56a65860d..2c75d5696 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2022 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 @@ -12,10 +12,9 @@ // // 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "ParametersPlugin_WidgetParamsMgr.h" @@ -34,9 +33,15 @@ #include #include +#include +#include + #include +#include +#include #include +#include #include #include @@ -48,6 +53,12 @@ #include #include #include +#include +#include + +#ifdef WIN32 +#pragma warning(disable : 4456) // for nested foreach +#endif enum ColumnType { Col_Name, @@ -58,7 +69,6 @@ enum ColumnType { const char* NoName = ""; const char* NoValue = ""; -const char* NotValid = ""; /*! * \ingroup GUI @@ -175,16 +185,17 @@ 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); myTable = new ParametersPlugin_TreeWidget(this); myTable->setColumnCount(4); QStringList aHeaders; - aHeaders << tr("Name") << tr("Expression") << tr("Result") << tr("Comment"); + aHeaders << translate("Name") << translate("Expression") + << translate("Result") << translate("Comment"); myTable->setHeaderLabels(aHeaders); myTable->setColumnWidth(Col_Name, 200); myTable->setColumnWidth(Col_Equation, 100); @@ -207,13 +218,13 @@ ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theP // Define root nodes QStringList aNames; - aNames<setFlags(Qt::ItemIsEnabled); myTable->addTopLevelItem(myParameters); aNames.clear(); - aNames<setFlags(Qt::ItemIsEnabled); myTable->addTopLevelItem(myFeatures); @@ -232,15 +243,26 @@ ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theP aBtnLayout->addStretch(); - myAddBtn = new QPushButton(tr("Add"), this); + myAddBtn = new QPushButton(translate("Add"), this); connect(myAddBtn, SIGNAL(clicked(bool)), SLOT(onAdd())); aBtnLayout->addWidget(myAddBtn); - myInsertBtn = new QPushButton(tr("Insert"), this); + 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); - myRemoveBtn = new QPushButton(tr("Remove"), this); + myImportBtn = new QPushButton(translate("Import file"), this); + connect(myImportBtn, SIGNAL(clicked(bool)), SLOT(onImport())); + aBtnLayout->addWidget(myImportBtn); + + myRemoveBtn = new QPushButton(translate("Remove"), this); connect(myRemoveBtn, SIGNAL(clicked(bool)), SLOT(onRemove())); aBtnLayout->addWidget(myRemoveBtn); @@ -256,7 +278,7 @@ void ParametersPlugin_WidgetParamsMgr::setDialogButtons(QDialogButtonBox* theBut QWidget* aBtnParentWgt = myOkCancelBtn->parentWidget(); QHBoxLayout* aBtnParentLayout = dynamic_cast(aBtnParentWgt->layout()); - QPushButton* aPreviewBtn = new QPushButton(tr("See preview"), aBtnParentWgt); + QPushButton* aPreviewBtn = new QPushButton(translate("See preview"), aBtnParentWgt); aBtnParentLayout->insertWidget(0, aPreviewBtn); aBtnParentLayout->insertStretch(1, 1); connect(aPreviewBtn, SIGNAL(clicked(bool)), SLOT(onShowPreview())); @@ -291,8 +313,7 @@ bool ParametersPlugin_WidgetParamsMgr::storeValueCustom() int aId = 0; foreach(FeaturePtr aFeature, myParametersList) { if (!aValidator.isValid(aFeature->attribute(aAttrId), aArgs, aErr)) { - // TODO(spo): translate - QMessageBox::warning(this, tr("Warning"), aErr.messageString().c_str()); + QMessageBox::warning(this, translate("Warning"), aErr.messageString().c_str()); selectItemScroll(myParameters->child(aId)); return false; } @@ -373,20 +394,43 @@ QList ParametersPlugin_WidgetParamsMgr:: } else { if (!theFeatureList.contains(aReferenced)) { QStringList aValNames; - aValNames << aReferenced->data()->name().c_str(); + aValNames << QString::fromStdWString(aReferenced->data()->name()); - AttributeDoublePtr aDouble = - std::dynamic_pointer_cast(aAttr); - if (aDouble.get()) { - aValNames << aDouble->text().c_str(); + std::string aId = aAttr->attributeType(); + if (aId == ModelAPI_AttributeDouble::typeId()) { + AttributeDoublePtr aDouble = + std::dynamic_pointer_cast(aAttr); + aValNames << QString::fromStdWString(aDouble->text()); aValNames << QString::number(aDouble->value()); - } else { + } + else if (aId == ModelAPI_AttributeInteger::typeId()) { AttributeIntegerPtr aInt = std::dynamic_pointer_cast(aAttr); - if (aInt.get()) { - aValNames << aInt->text().c_str(); - aValNames << QString::number(aInt->value()); - } + aValNames << QString::fromStdWString(aInt->text()); + aValNames << QString::number(aInt->value()); + } + else if (aId == GeomDataAPI_Point::typeId()) { + std::shared_ptr aPnt = + std::dynamic_pointer_cast(aAttr); + + 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()); + aValNames << aRes; + } + else if (aId == GeomDataAPI_Point2D::typeId()) { + std::shared_ptr aPnt = + std::dynamic_pointer_cast(aAttr); + + 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()); + aValNames << aRes; } aItemsList.append(aValNames); theFeatureList.append(aReferenced); @@ -411,18 +455,17 @@ QList ParametersPlugin_WidgetParamsMgr:: std::string aName = aParameter->string(ParametersPlugin_Parameter::VARIABLE_ID())->value(); if (aName.empty()) { - aValues << NoName; + aValues << translate(NoName); } else aValues << aName.c_str(); std::string aExpr = aParameter->string(ParametersPlugin_Parameter::EXPRESSION_ID())->value(); if (aName.empty()) { - aValues << NoValue; + aValues << translate(NoValue); } 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()); @@ -450,6 +493,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; @@ -461,8 +505,8 @@ void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor, while (aText.indexOf(" ") != -1) { aText.replace(" ", ""); } - if (hasName(aText)) { - myMessage = tr("Name '%1' already exists.").arg(aText); + if (hasName(aText, aRow)) { + myMessage = translate("Name '%1' already exists.").arg(aText); QTimer::singleShot(50, this, SLOT(sendWarning())); return; } @@ -487,7 +531,7 @@ void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor, case Col_Comment: { AttributeStringPtr aStringAttr = aFeature->string(ParametersPlugin_Parameter::COMMENT_ID()); - aStringAttr->setValue(aText.toStdString()); + aStringAttr->setValue(aText.toStdWString()); isModified = true; } break; @@ -550,8 +594,8 @@ FeaturePtr ParametersPlugin_WidgetParamsMgr::createParameter() const QTreeWidgetItem* ParametersPlugin_WidgetParamsMgr::createNewItem(QTreeWidgetItem* theParent) const { QStringList aValues; - aValues << NoName; - aValues << NoValue; + aValues << translate(NoName); + aValues << translate(NoValue); QTreeWidgetItem* aItem = new QTreeWidgetItem(aValues); if (theParent == myParameters) { @@ -657,6 +701,27 @@ void ParametersPlugin_WidgetParamsMgr::onRemove() } } +void ParametersPlugin_WidgetParamsMgr::onImport() +{ + std::string aWinText("Select txt file"); + std::string aFileType("Text files (*.txt);;All files (*.*)"); + QString aQPath = QFileDialog::getOpenFileName(nullptr, + aWinText.c_str(), "", + aFileType.c_str()); + if (aQPath.size() == 0) + return; + + std::string aPath(aQPath.toStdString()); + std::shared_ptr aMessage = + std::shared_ptr( + new ModelAPI_ImportParametersMessage(ModelAPI_ImportParametersMessage::eventId())); + aMessage->setFilename(aPath); + Events_Loop::loop()->send(aMessage); + + updateParametersFeatures(); + updateParametersPart(); +} + void ParametersPlugin_WidgetParamsMgr::onUp() { QTreeWidgetItem* aCurrentItem = selectedItem(); @@ -730,12 +795,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.toStdString())) + if ((i != theIndex) && (aFeature->data()->name() == theName.toStdWString())) return true; i++; } @@ -744,7 +808,7 @@ bool ParametersPlugin_WidgetParamsMgr::hasName(const QString& theName) const void ParametersPlugin_WidgetParamsMgr::sendWarning() { - QMessageBox::warning(this, tr("Warning"), myMessage); + QMessageBox::warning(this, translate("Warning"), myMessage); QTreeWidgetItem* aItem = myTable->currentItem(); if (aItem) myTable->editItem(aItem); @@ -766,11 +830,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()); } @@ -785,6 +851,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); } @@ -795,8 +862,9 @@ bool ParametersPlugin_WidgetParamsMgr::isValid() for(int i = 0; i < myParameters->childCount(); i++) { aItem = myParameters->child(i); if ((aItem->text(Col_Name) == NoName) || - (aItem->text(Col_Equation) == NoValue) || - (!ModelAPI_Expression::isVariable(aItem->text(Col_Name).toStdString())) ) { + (aItem->text(Col_Equation) == translate(NoValue)) || + (!ModelAPI_Expression::isVariable(aItem->text(Col_Name).toStdString())) || + (hasName(aItem->text(Col_Name), i)) ) { return false; } } @@ -825,4 +893,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(); +}