X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FParametersPlugin%2FParametersPlugin_WidgetParamsMgr.cpp;h=2c75d5696fe947df77851f3b10a98b19c04e5581;hb=40949601c4ec555efcc6815c68a6b5e3e71ea3ba;hp=9078329662e93044b3d61496b2e572539f63be1d;hpb=3c987a8d1b88765224e3ac1388afb91eae17e4d3;p=modules%2Fshaper.git diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp index 907832966..2c75d5696 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 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 @@ -37,8 +37,11 @@ #include #include +#include +#include #include +#include #include #include @@ -50,6 +53,12 @@ #include #include #include +#include +#include + +#ifdef WIN32 +#pragma warning(disable : 4456) // for nested foreach +#endif enum ColumnType { Col_Name, @@ -176,9 +185,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,10 +247,21 @@ 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); + 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); @@ -374,27 +394,28 @@ QList 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(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(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 aPnt = std::dynamic_pointer_cast(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 +425,8 @@ QList ParametersPlugin_WidgetParamsMgr:: std::shared_ptr aPnt = std::dynamic_pointer_cast(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 +465,7 @@ QList 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()); @@ -473,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; @@ -484,7 +505,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; @@ -510,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; @@ -680,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(); @@ -753,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++; } @@ -789,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()); } @@ -808,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); } @@ -819,7 +863,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; } } @@ -848,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(); +}