1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "ParametersPlugin_WidgetParamsMgr.h"
21 #include "ParametersPlugin_Parameter.h"
22 #include "ParametersPlugin_Validators.h"
24 #include <Events_InfoMessage.h>
26 #include <ModelAPI_ResultParameter.h>
27 #include <ModelAPI_AttributeString.h>
28 #include <ModelAPI_AttributeRefList.h>
29 #include <ModelAPI_AttributeDouble.h>
30 #include <ModelAPI_AttributeInteger.h>
31 #include <ModelAPI_Events.h>
32 #include <ModelAPI_Session.h>
33 #include <ModelAPI_Tools.h>
34 #include <ModelAPI_Expression.h>
36 #include <GeomDataAPI_Point.h>
37 #include <GeomDataAPI_Point2D.h>
39 #include <ModuleBase_Tools.h>
41 #include <Events_Loop.h>
42 #include <Config_PropManager.h>
45 #include <QPushButton>
46 #include <QToolButton>
47 #include <QStyledItemDelegate>
49 #include <QMessageBox>
53 #include <QDialogButtonBox>
63 const char* NoName = "<NoName>";
64 const char* NoValue = "<NoValue>";
68 * ItemDelegate object in order to redefine items behavior
70 class ParametersPlugin_ItemDelegate : public QStyledItemDelegate
74 /// \param thaParent a parent
75 ParametersPlugin_ItemDelegate(QObject* thaParent) :
76 QStyledItemDelegate(thaParent) {}
78 /// Redefinition of virtual method
79 /// \param painter a painter object
80 /// \param option the item options
81 /// \param index the current index
82 virtual void paint(QPainter* painter,
83 const QStyleOptionViewItem& option,
84 const QModelIndex& index ) const;
86 /// Redefinition of virtual method
87 /// \param parent a parent widget
88 /// \param option the item options
89 /// \param index the current index
90 virtual QWidget* createEditor(QWidget* parent,
91 const QStyleOptionViewItem& option,
92 const QModelIndex& index) const;
94 /// Returns True if the given index is editable item
95 /// \param theIndex an item index
96 bool isEditable(const QModelIndex& theIndex) const;
98 /// Returns currently editing index
99 QModelIndex editIndex() const { return myEditingIdx; }
102 mutable QModelIndex myEditingIdx;
105 bool ParametersPlugin_ItemDelegate::isEditable(const QModelIndex& theIndex) const
107 QModelIndex aParent = theIndex.parent();
108 if (aParent.isValid() && (aParent.row() == 0)) {
109 if (theIndex.column() == 2)
116 void ParametersPlugin_ItemDelegate::paint(QPainter* painter,
117 const QStyleOptionViewItem& option,
118 const QModelIndex& index ) const
120 QBrush aBrush = painter->brush();
121 QPen aPen = painter->pen();
122 //if (!isEditable(index))
123 // painter->setBrush(Qt::lightGray);
124 if (!index.parent().isValid())
125 painter->setBrush(Qt::lightGray);
127 painter->setPen(Qt::lightGray);
128 painter->drawRect(option.rect);
129 painter->setPen(aPen);
131 QStyledItemDelegate::paint(painter, option, index);
132 painter->setBrush(aBrush);
135 QWidget* ParametersPlugin_ItemDelegate::createEditor(QWidget* parent,
136 const QStyleOptionViewItem& option,
137 const QModelIndex& index) const
139 myEditingIdx = index;
140 return QStyledItemDelegate::createEditor(parent, option, index);
143 /////////////////////////////////////////////////////////////////////////////////////////////////
144 void ParametersPlugin_TreeWidget::closeEditor(QWidget* theEditor,
145 QAbstractItemDelegate::EndEditHint theHint)
147 if (theHint == QAbstractItemDelegate::EditNextItem) {
148 QModelIndex aCurrent = currentIndex();
149 QModelIndex aParent = model()->index(0, 0);
150 int aNbRows = model()->rowCount(aParent);
152 switch (aCurrent.column()) {
154 aIdx = model()->index(aCurrent.row(), 1, aParent);
157 if (aCurrent.row() < (aNbRows - 1))
158 aIdx = model()->index(aCurrent.row() + 1, 0, aParent);
160 QTreeWidget::closeEditor(theEditor, QAbstractItemDelegate::NoHint);
165 QTreeWidget::closeEditor(theEditor, theHint);
168 if (aIdx.isValid()) {
169 QTreeWidget::closeEditor(theEditor, QAbstractItemDelegate::NoHint);
170 setCurrentIndex(aIdx);
175 QTreeWidget::closeEditor(theEditor, theHint);
178 /////////////////////////////////////////////////////////////////////////////////////////////////
180 ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theParent,
181 const Config_WidgetAPI* theData)
182 : ModuleBase_ModelDialogWidget(theParent, theData),
183 isUpplyBlocked(false)
185 QVBoxLayout* aLayout = new QVBoxLayout(this);
187 myTable = new ParametersPlugin_TreeWidget(this);
188 myTable->setColumnCount(4);
189 QStringList aHeaders;
190 aHeaders << translate("Name") << translate("Expression")
191 << translate("Result") << translate("Comment");
192 myTable->setHeaderLabels(aHeaders);
193 myTable->setColumnWidth(Col_Name, 200);
194 myTable->setColumnWidth(Col_Equation, 100);
195 myTable->setColumnWidth(Col_Result, 80);
196 myTable->setColumnWidth(Col_Comment, 200);
197 myTable->setMinimumWidth(600);
198 myTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
199 myTable->setSelectionMode(QAbstractItemView::SingleSelection);
201 connect(myTable, SIGNAL(doubleClicked(const QModelIndex&)),
202 SLOT(onDoubleClick(const QModelIndex&)));
203 connect(myTable, SIGNAL(itemSelectionChanged()), SLOT(onSelectionChanged()));
205 myDelegate = new ParametersPlugin_ItemDelegate(myTable);
206 connect(myDelegate, SIGNAL(closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint)),
207 SLOT(onCloseEditor(QWidget*, QAbstractItemDelegate::EndEditHint)));
209 myTable->setItemDelegate(myDelegate);
210 aLayout->addWidget(myTable);
214 aNames<<translate("Parameters");
215 myParameters = new QTreeWidgetItem(aNames);
216 myParameters->setFlags(Qt::ItemIsEnabled);
217 myTable->addTopLevelItem(myParameters);
220 aNames<<translate("Features");
221 myFeatures = new QTreeWidgetItem(aNames);
222 myFeatures->setFlags(Qt::ItemIsEnabled);
223 myTable->addTopLevelItem(myFeatures);
225 QHBoxLayout* aBtnLayout = new QHBoxLayout(this);
227 myUpBtn = new QToolButton(this);
228 myUpBtn->setArrowType(Qt::UpArrow);
229 connect(myUpBtn, SIGNAL(clicked(bool)), SLOT(onUp()));
230 aBtnLayout->addWidget(myUpBtn);
232 myDownBtn = new QToolButton(this);
233 myDownBtn->setArrowType(Qt::DownArrow);
234 connect(myDownBtn, SIGNAL(clicked(bool)), SLOT(onDown()));
235 aBtnLayout->addWidget(myDownBtn);
237 aBtnLayout->addStretch();
239 myAddBtn = new QPushButton(translate("Add"), this);
240 connect(myAddBtn, SIGNAL(clicked(bool)), SLOT(onAdd()));
241 aBtnLayout->addWidget(myAddBtn);
243 QString aAddStr(Config_PropManager::string("Shortcuts", "add_parameter_shortcut").c_str());
244 if (aAddStr.isEmpty())
247 QShortcut* aAddShc = new QShortcut(QKeySequence(aAddStr), myAddBtn);
248 connect(aAddShc, SIGNAL(activated()), SLOT(onAdd()));
250 myInsertBtn = new QPushButton(translate("Insert"), this);
251 connect(myInsertBtn, SIGNAL(clicked(bool)), SLOT(onInsert()));
252 aBtnLayout->addWidget(myInsertBtn);
254 myRemoveBtn = new QPushButton(translate("Remove"), this);
255 connect(myRemoveBtn, SIGNAL(clicked(bool)), SLOT(onRemove()));
256 aBtnLayout->addWidget(myRemoveBtn);
258 aLayout->addLayout(aBtnLayout);
260 onSelectionChanged();
263 void ParametersPlugin_WidgetParamsMgr::setDialogButtons(QDialogButtonBox* theButtons)
265 ModuleBase_ModelDialogWidget::setDialogButtons(theButtons);
267 QWidget* aBtnParentWgt = myOkCancelBtn->parentWidget();
268 QHBoxLayout* aBtnParentLayout = dynamic_cast<QHBoxLayout*>(aBtnParentWgt->layout());
270 QPushButton* aPreviewBtn = new QPushButton(translate("See preview"), aBtnParentWgt);
271 aBtnParentLayout->insertWidget(0, aPreviewBtn);
272 aBtnParentLayout->insertStretch(1, 1);
273 connect(aPreviewBtn, SIGNAL(clicked(bool)), SLOT(onShowPreview()));
277 QList<QWidget*> ParametersPlugin_WidgetParamsMgr::getControls() const
279 QList<QWidget*> aList;
284 void ParametersPlugin_WidgetParamsMgr::selectItemScroll(QTreeWidgetItem* aItem)
286 myTable->clearSelection();
287 QModelIndex aParent = myTable->model()->index(0, 0);
288 int aChildIdx = myParameters->indexOfChild(aItem);
289 QModelIndex aIndex = myTable->model()->index(aChildIdx, Col_Name, aParent);
290 myTable->selectionModel()->select(aIndex,
291 QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
292 myTable->scrollToItem(aItem);
296 bool ParametersPlugin_WidgetParamsMgr::storeValueCustom()
298 ParametersPlugin_ExpressionValidator aValidator;
299 std::list<std::string> aArgs;
300 std::string aAttrId = ParametersPlugin_Parameter::VARIABLE_ID();
301 Events_InfoMessage aErr;
303 foreach(FeaturePtr aFeature, myParametersList) {
304 if (!aValidator.isValid(aFeature->attribute(aAttrId), aArgs, aErr)) {
305 QMessageBox::warning(this, translate("Warning"), aErr.messageString().c_str());
306 selectItemScroll(myParameters->child(aId));
311 // #2813 : make the current feature the latest in the document
312 std::list<FeaturePtr> allFeatures = myFeature->document()->allFeatures();
313 if (!allFeatures.empty()) {
314 myFeature->document()->setCurrentFeature(*(allFeatures.rbegin()), true);
319 bool ParametersPlugin_WidgetParamsMgr::restoreValueCustom()
324 void ParametersPlugin_WidgetParamsMgr::activateCustom()
326 updateParametersFeatures();
327 updateParametersPart();
328 updateFeaturesPart();
330 myFeatures->setExpanded(true);
331 myParameters->setExpanded(true);
334 void ParametersPlugin_WidgetParamsMgr::updateParametersFeatures()
336 myParametersList.clear();
337 FeaturePtr aFeature = feature();
338 DocumentPtr aDoc = aFeature->document();
340 FeaturePtr aParamFeature;
341 int aNbFeatures = aDoc->numInternalFeatures();
342 for (int i = 0; i < aNbFeatures; i++) {
343 aParamFeature = aDoc->internalFeature(i);
344 if (aParamFeature && aParamFeature->getKind() == ParametersPlugin_Parameter::ID()) {
345 myParametersList.append(aParamFeature);
350 void ParametersPlugin_WidgetParamsMgr::updateFeaturesPart()
352 QList<FeaturePtr> aFeatureList;
353 updateItem(myFeatures, featuresItems(myParametersList, aFeatureList));
356 void ParametersPlugin_WidgetParamsMgr::updateParametersPart()
358 updateItem(myParameters, parametersItems(myParametersList));
359 bool aIsValid = isValid();
360 enableButtons(aIsValid);
364 QList<QStringList> ParametersPlugin_WidgetParamsMgr::
365 featuresItems(const QList<FeaturePtr>& theFeatures, QList<FeaturePtr>& theFeatureList) const
367 QList<QStringList> aItemsList;
368 ResultParameterPtr aParam;
369 foreach(FeaturePtr aParameter, theFeatures) {
370 aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aParameter->firstResult());
371 const std::set<std::shared_ptr<ModelAPI_Attribute>>& aRefs = aParam->data()->refsToMe();
372 std::set<std::shared_ptr<ModelAPI_Attribute> >::const_iterator aIt;
373 for(aIt = aRefs.cbegin(); aIt != aRefs.cend(); aIt++) {
374 std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
375 FeaturePtr aReferenced = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
376 if (aReferenced.get() && (aReferenced != aParameter)) {
377 if (aReferenced->getKind() == ParametersPlugin_Parameter::ID()) {
378 // Find referenced feature Recursive
379 QList<FeaturePtr> aList;
380 aList.append(aReferenced);
381 QList<QStringList> aItems = featuresItems(aList, theFeatureList);
382 aItemsList.append(aItems);
384 if (!theFeatureList.contains(aReferenced)) {
385 QStringList aValNames;
386 aValNames << aReferenced->data()->name().c_str();
388 std::string aId = aAttr->attributeType();
389 if (aId == ModelAPI_AttributeDouble::typeId()) {
390 AttributeDoublePtr aDouble =
391 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aAttr);
392 aValNames << aDouble->text().c_str();
393 aValNames << QString::number(aDouble->value());
395 else if (aId == ModelAPI_AttributeInteger::typeId()) {
396 AttributeIntegerPtr aInt =
397 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(aAttr);
398 aValNames << aInt->text().c_str();
399 aValNames << QString::number(aInt->value());
401 else if (aId == GeomDataAPI_Point::typeId()) {
402 std::shared_ptr<GeomDataAPI_Point> aPnt =
403 std::dynamic_pointer_cast<GeomDataAPI_Point>(aAttr);
405 QString aExpr = QString("%1,%2,%3").arg(aPnt->textX().c_str()).
406 arg(aPnt->textY().c_str()).arg(aPnt->textZ().c_str());
409 QString aRes = QString("%1,%2,%3").arg(aPnt->x()).arg(aPnt->y()).arg(aPnt->z());
412 else if (aId == GeomDataAPI_Point2D::typeId()) {
413 std::shared_ptr<GeomDataAPI_Point2D> aPnt =
414 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
416 QString aExpr = QString("%1,%2").arg(aPnt->textX().c_str()).
417 arg(aPnt->textY().c_str());
420 QString aRes = QString("%1,%2").arg(aPnt->x()).arg(aPnt->y());
423 aItemsList.append(aValNames);
424 theFeatureList.append(aReferenced);
434 QList<QStringList> ParametersPlugin_WidgetParamsMgr::
435 parametersItems(const QList<FeaturePtr>& theFeatures) const
437 std::list<std::string> aArgs;
439 QList<QStringList> aItemsList;
440 foreach(FeaturePtr aParameter, theFeatures) {
441 ResultPtr aParam = aParameter->firstResult();
444 std::string aName = aParameter->string(ParametersPlugin_Parameter::VARIABLE_ID())->value();
446 aValues << translate(NoName);
448 aValues << aName.c_str();
450 std::string aExpr = aParameter->string(ParametersPlugin_Parameter::EXPRESSION_ID())->value();
452 aValues << translate(NoValue);
454 aValues << aExpr.c_str();
457 aParameter->data()->string(ParametersPlugin_Parameter::EXPRESSION_ERROR_ID())->value();
459 AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
460 aValues << QString::number(aValueAttribute->value());
462 aValues << aErr.c_str();
464 aValues << aParameter->string(ParametersPlugin_Parameter::COMMENT_ID())->value().c_str();
465 aItemsList.append(aValues);
471 void ParametersPlugin_WidgetParamsMgr::onDoubleClick(const QModelIndex& theIndex)
473 if (myDelegate->isEditable(theIndex)) {
474 myTable->setCurrentIndex(theIndex);
475 myTable->edit(theIndex);
479 void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor,
480 QAbstractItemDelegate::EndEditHint theHint)
482 FeaturePtr aFeature = myParametersList.at(myDelegate->editIndex().row());
483 QTreeWidgetItem* aItem = myParameters->child(myDelegate->editIndex().row());
484 int aColumn = myDelegate->editIndex().column();
485 QString aText = aItem->text(aColumn);
486 bool isModified = false;
491 AttributeStringPtr aStringAttr = aFeature->string(ParametersPlugin_Parameter::VARIABLE_ID());
492 if (!aText.isEmpty()) {
493 while (aText.indexOf(" ") != -1) {
494 aText.replace(" ", "");
496 if (hasName(aText)) {
497 myMessage = translate("Name '%1' already exists.").arg(aText);
498 QTimer::singleShot(50, this, SLOT(sendWarning()));
501 aStringAttr->setValue(aText.toStdString());
508 AttributeStringPtr aStringAttr =
509 aFeature->string(ParametersPlugin_Parameter::EXPRESSION_ID());
510 if (!aText.isEmpty()) {
511 if (aText != aStringAttr->value().c_str()) {
512 aStringAttr->setValue(aText.toStdString());
521 AttributeStringPtr aStringAttr = aFeature->string(ParametersPlugin_Parameter::COMMENT_ID());
522 aStringAttr->setValue(aText.toStdString());
530 Events_Loop* aLoop = Events_Loop::loop();
531 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
532 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
533 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
535 if (aColumn != Col_Comment)
536 updateParametersPart();
537 updateFeaturesPart();
539 onSelectionChanged();
542 void ParametersPlugin_WidgetParamsMgr::updateItem(QTreeWidgetItem* theItem,
543 const QList<QStringList>& theFeaturesList)
545 if (theFeaturesList.count() != theItem->childCount()) {
546 if (theItem->childCount() < theFeaturesList.count()) {
547 while (theItem->childCount() != theFeaturesList.count())
548 theItem->addChild(createNewItem(theItem));
550 while (theItem->childCount() != theFeaturesList.count())
551 theItem->removeChild(theItem->child(theItem->childCount() - 1));
555 foreach(QStringList aFeature, theFeaturesList) {
557 foreach(QString aText, aFeature) {
558 if (aText.length() > 0) {
559 theItem->child(i)->setText(aCol, aText);
560 theItem->child(i)->setToolTip(aCol, aText);
568 FeaturePtr ParametersPlugin_WidgetParamsMgr::createParameter() const
570 SessionPtr aMgr = ModelAPI_Session::get();
571 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
573 FeaturePtr aFeature = aDoc->addFeature(ParametersPlugin_Parameter::ID());
574 if (aFeature.get()) {
575 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
576 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
582 QTreeWidgetItem* ParametersPlugin_WidgetParamsMgr::createNewItem(QTreeWidgetItem* theParent) const
585 aValues << translate(NoName);
586 aValues << translate(NoValue);
588 QTreeWidgetItem* aItem = new QTreeWidgetItem(aValues);
589 if (theParent == myParameters) {
590 aItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
591 aItem->setForeground(2, Qt::darkGray);
593 aItem->setFlags(Qt::NoItemFlags);
598 void ParametersPlugin_WidgetParamsMgr::onAdd()
600 FeaturePtr aFeature = createParameter();
604 myParametersList.append(aFeature);
605 updateParametersPart();
607 QTreeWidgetItem* aItem = myParameters->child(myParameters->childCount() - 1);
609 myTable->scrollToItem(aItem);
610 myTable->setCurrentItem(aItem);
611 myTable->editItem(aItem);
613 enableButtons(false);
616 QTreeWidgetItem* ParametersPlugin_WidgetParamsMgr::selectedItem() const
618 QList<QTreeWidgetItem*> aItemsList = myTable->selectedItems();
619 if (aItemsList.count() == 0)
622 QTreeWidgetItem* aCurrentItem = aItemsList.first();
623 if (aCurrentItem->parent() != myParameters)
630 void ParametersPlugin_WidgetParamsMgr::onInsert()
632 QTreeWidgetItem* aCurrentItem = selectedItem();
636 SessionPtr aMgr = ModelAPI_Session::get();
637 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
639 FeaturePtr aNewFeature = createParameter();
640 if (!aNewFeature.get())
643 int aCurrentPos = myParameters->indexOfChild(aCurrentItem);
644 if (aCurrentPos == 0) {
645 aDoc->moveFeature(aNewFeature, FeaturePtr());
647 FeaturePtr aCurFeature = myParametersList.at(aCurrentPos - 1);
648 aDoc->moveFeature(aNewFeature, aCurFeature);
650 updateParametersFeatures();
651 updateParametersPart();
653 myTable->scrollToItem(aCurrentItem);
654 myTable->setCurrentItem(aCurrentItem);
655 myTable->editItem(aCurrentItem);
658 void ParametersPlugin_WidgetParamsMgr::onRemove()
660 QTreeWidgetItem* aCurrentItem = selectedItem();
664 SessionPtr aMgr = ModelAPI_Session::get();
665 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
667 int aCurrentPos = myParameters->indexOfChild(aCurrentItem);
668 FeaturePtr aCurFeature = myParametersList.at(aCurrentPos);
670 QObjectPtrList anObjects;
671 anObjects.append(aCurFeature);
673 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
674 std::set<FeaturePtr> aFeatures;
675 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
676 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
678 std::set<FeaturePtr> aFeatureRefsToDelete;
679 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, this, aFeatureRefsToDelete)) {
680 if (!aFeatureRefsToDelete.empty())
681 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
682 ModelAPI_Tools::removeFeatures(aFeatures, false);
684 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
685 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
686 updateParametersFeatures();
687 updateFeaturesPart();
688 updateParametersPart();
692 void ParametersPlugin_WidgetParamsMgr::onUp()
694 QTreeWidgetItem* aCurrentItem = selectedItem();
698 int aCurrentPos = myParameters->indexOfChild(aCurrentItem);
699 if (aCurrentPos == 0)
701 FeaturePtr aCurFeature = myParametersList.at(aCurrentPos);
703 SessionPtr aMgr = ModelAPI_Session::get();
704 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
706 if (aCurrentPos == 1)
707 aDoc->moveFeature(aCurFeature, FeaturePtr());
709 aDoc->moveFeature(aCurFeature, myParametersList.at(aCurrentPos - 2));
711 // add the updated also the feature that goes down
712 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
713 static Events_ID EVENT_UPD = Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED);
714 ModelAPI_EventCreator::get()->sendUpdated(myParametersList.at(aCurrentPos - 1), EVENT_UPD);
715 Events_Loop::loop()->flush(EVENT_UPD);
716 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
717 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
718 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
719 updateParametersFeatures();
720 updateParametersPart();
721 updateFeaturesPart();
723 if (aCurrentPos > 0) {
724 aCurrentItem = myParameters->child(aCurrentPos - 1);
725 myTable->setCurrentItem(aCurrentItem);
726 selectItemScroll(aCurrentItem);
730 void ParametersPlugin_WidgetParamsMgr::onDown()
732 QTreeWidgetItem* aCurrentItem = selectedItem();
736 int aCurrentPos = myParameters->indexOfChild(aCurrentItem);
737 if (aCurrentPos == (myParametersList.count() - 1))
739 FeaturePtr aCurFeature = myParametersList.at(aCurrentPos);
741 SessionPtr aMgr = ModelAPI_Session::get();
742 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
743 aDoc->moveFeature(aCurFeature, myParametersList.at(aCurrentPos + 1));
744 // add the updated also the feature that goes up
745 static Events_ID EVENT_UPD = Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED);
746 ModelAPI_EventCreator::get()->sendUpdated(myParametersList.at(aCurrentPos + 1), EVENT_UPD);
748 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
749 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED));
750 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
751 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
752 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
753 updateParametersFeatures();
754 updateParametersPart();
755 updateFeaturesPart();
757 if (aCurrentPos < myParameters->childCount() - 1) {
758 aCurrentItem = myParameters->child(aCurrentPos + 1);
759 myTable->setCurrentItem(aCurrentItem);
760 selectItemScroll(aCurrentItem);
765 bool ParametersPlugin_WidgetParamsMgr::hasName(const QString& theName) const
767 int aCurrent = myDelegate->editIndex().row();
769 foreach(FeaturePtr aFeature, myParametersList) {
770 if ((i != aCurrent) && (aFeature->data()->name() == theName.toStdString()))
777 void ParametersPlugin_WidgetParamsMgr::sendWarning()
779 QMessageBox::warning(this, translate("Warning"), myMessage);
780 QTreeWidgetItem* aItem = myTable->currentItem();
782 myTable->editItem(aItem);
785 void ParametersPlugin_WidgetParamsMgr::onSelectionChanged()
787 QList<QTreeWidgetItem*> aItemsList = myTable->selectedItems();
788 bool aIsValid = isValid();
790 bool isParameter = false;
791 foreach(QTreeWidgetItem* aItem, aItemsList) {
792 if (aItem->parent() == myParameters) {
797 myInsertBtn->setEnabled(isParameter);
798 //myRemoveBtn->setEnabled(isParameter);
799 myUpBtn->setEnabled(isParameter);
800 myDownBtn->setEnabled(isParameter);
802 myInsertBtn->setEnabled(false);
803 //myRemoveBtn->setEnabled(false);
804 myUpBtn->setEnabled(false);
805 myDownBtn->setEnabled(false);
807 myRemoveBtn->setEnabled(!aItemsList.isEmpty());
810 void ParametersPlugin_WidgetParamsMgr::enableButtons(bool theEnable)
812 myAddBtn->setEnabled(theEnable);
814 onSelectionChanged();
816 myInsertBtn->setEnabled(theEnable);
817 //myRemoveBtn->setEnabled(theEnable);
818 myUpBtn->setEnabled(theEnable);
819 myDownBtn->setEnabled(theEnable);
821 myOkCancelBtn->button(QDialogButtonBox::Ok)->setEnabled(theEnable);
824 bool ParametersPlugin_WidgetParamsMgr::isValid()
826 QTreeWidgetItem* aItem;
827 for(int i = 0; i < myParameters->childCount(); i++) {
828 aItem = myParameters->child(i);
829 if ((aItem->text(Col_Name) == NoName) ||
830 (aItem->text(Col_Equation) == translate(NoValue)) ||
831 (!ModelAPI_Expression::isVariable(aItem->text(Col_Name).toStdString())) ) {
838 void ParametersPlugin_WidgetParamsMgr::showEvent(QShowEvent* theEvent)
840 ModuleBase_ModelDialogWidget::showEvent(theEvent);
841 SessionPtr aMgr = ModelAPI_Session::get();
842 isUpplyBlocked = aMgr->isAutoUpdateBlocked();
843 aMgr->blockAutoUpdate(true);
844 Events_Loop* aLoop = Events_Loop::loop();
845 aLoop->flush(aLoop->eventByName(EVENT_AUTOMATIC_RECOMPUTATION_DISABLE));
848 void ParametersPlugin_WidgetParamsMgr::hideEvent(QHideEvent* theEvent)
850 ModuleBase_ModelDialogWidget::hideEvent(theEvent);
851 SessionPtr aMgr = ModelAPI_Session::get();
852 aMgr->blockAutoUpdate(isUpplyBlocked);
855 void ParametersPlugin_WidgetParamsMgr::onShowPreview()
857 SessionPtr aMgr = ModelAPI_Session::get();
858 aMgr->blockAutoUpdate(false);
859 aMgr->blockAutoUpdate(true);