X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FParametersPlugin%2FParametersPlugin_WidgetParamsMgr.cpp;h=fa31070fa9cf2658e91ebd3e1ecd4b29857d5d91;hb=a13f87935d2a6f52f942790b6abc874f1016c9fc;hp=96e10edb14c720706a7f03058c5e5c9059301d4f;hpb=dc7d4d86b58b81684abc9b5a2be8ec30f210c2da;p=modules%2Fshaper.git diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp index 96e10edb1..fa31070fa 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-2019 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,7 @@ #include #include #include +#include enum ColumnType { Col_Name, @@ -58,7 +64,6 @@ enum ColumnType { const char* NoName = ""; const char* NoValue = ""; -const char* NotValid = ""; /*! * \ingroup GUI @@ -175,15 +180,17 @@ void ParametersPlugin_TreeWidget::closeEditor(QWidget* theEditor, ///////////////////////////////////////////////////////////////////////////////////////////////// ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theParent, - const Config_WidgetAPI* theData) - : ModuleBase_ModelDialogWidget(theParent, theData) + const Config_WidgetAPI* theData, ModuleBase_IWorkshop* theWorkshop) + : ModuleBase_ModelDialogWidget(theParent, theData), + 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); @@ -206,13 +213,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); @@ -231,15 +238,22 @@ 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); + myRemoveBtn = new QPushButton(translate("Remove"), this); connect(myRemoveBtn, SIGNAL(clicked(bool)), SLOT(onRemove())); aBtnLayout->addWidget(myRemoveBtn); @@ -248,6 +262,20 @@ ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theP onSelectionChanged(); } +void ParametersPlugin_WidgetParamsMgr::setDialogButtons(QDialogButtonBox* theButtons) +{ + ModuleBase_ModelDialogWidget::setDialogButtons(theButtons); + + QWidget* aBtnParentWgt = myOkCancelBtn->parentWidget(); + QHBoxLayout* aBtnParentLayout = dynamic_cast(aBtnParentWgt->layout()); + + QPushButton* aPreviewBtn = new QPushButton(translate("See preview"), aBtnParentWgt); + aBtnParentLayout->insertWidget(0, aPreviewBtn); + aBtnParentLayout->insertStretch(1, 1); + connect(aPreviewBtn, SIGNAL(clicked(bool)), SLOT(onShowPreview())); +} + + QList ParametersPlugin_WidgetParamsMgr::getControls() const { QList aList; @@ -276,13 +304,17 @@ 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; } aId++; } + // #2813 : make the current feature the latest in the document + std::list allFeatures = myFeature->document()->allFeatures(); + if (!allFeatures.empty()) { + myFeature->document()->setCurrentFeature(*(allFeatures.rbegin()), true); + } return true; } @@ -353,20 +385,42 @@ 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()) { + std::string aId = aAttr->attributeType(); + if (aId == ModelAPI_AttributeDouble::typeId()) { + AttributeDoublePtr aDouble = + std::dynamic_pointer_cast(aAttr); aValNames << aDouble->text().c_str(); 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 << aInt->text().c_str(); + 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()); + 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(aPnt->textX().c_str()). + arg(aPnt->textY().c_str()); + aValNames << aExpr; + + QString aRes = QString("%1,%2").arg(aPnt->x()).arg(aPnt->y()); + aValNames << aRes; } aItemsList.append(aValNames); theFeatureList.append(aReferenced); @@ -391,13 +445,13 @@ 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(); @@ -442,7 +496,7 @@ void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor, aText.replace(" ", ""); } if (hasName(aText)) { - myMessage = tr("Name '%1' already exists.").arg(aText); + myMessage = translate("Name '%1' already exists.").arg(aText); QTimer::singleShot(50, this, SLOT(sendWarning())); return; } @@ -530,8 +584,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) { @@ -715,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++; } @@ -724,7 +778,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); @@ -775,7 +829,7 @@ 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) || + (aItem->text(Col_Equation) == translate(NoValue)) || (!ModelAPI_Expression::isVariable(aItem->text(Col_Name).toStdString())) ) { return false; } @@ -783,3 +837,27 @@ bool ParametersPlugin_WidgetParamsMgr::isValid() return true; } +void ParametersPlugin_WidgetParamsMgr::showEvent(QShowEvent* theEvent) +{ + ModuleBase_ModelDialogWidget::showEvent(theEvent); + SessionPtr aMgr = ModelAPI_Session::get(); + isUpplyBlocked = aMgr->isAutoUpdateBlocked(); + aMgr->blockAutoUpdate(true); + Events_Loop* aLoop = Events_Loop::loop(); + aLoop->flush(aLoop->eventByName(EVENT_AUTOMATIC_RECOMPUTATION_DISABLE)); +} + +void ParametersPlugin_WidgetParamsMgr::hideEvent(QHideEvent* theEvent) +{ + ModuleBase_ModelDialogWidget::hideEvent(theEvent); + SessionPtr aMgr = ModelAPI_Session::get(); + aMgr->blockAutoUpdate(isUpplyBlocked); +} + +void ParametersPlugin_WidgetParamsMgr::onShowPreview() +{ + SessionPtr aMgr = ModelAPI_Session::get(); + aMgr->blockAutoUpdate(false); + aMgr->blockAutoUpdate(true); + myWorkshop->viewer()->update(); +}