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>
44 #include <QPushButton>
45 #include <QToolButton>
46 #include <QStyledItemDelegate>
48 #include <QMessageBox>
52 #include <QDialogButtonBox>
61 const char* NoName = "<NoName>";
62 const char* NoValue = "<NoValue>";
66 * ItemDelegate object in order to redefine items behavior
68 class ParametersPlugin_ItemDelegate : public QStyledItemDelegate
72 /// \param thaParent a parent
73 ParametersPlugin_ItemDelegate(QObject* thaParent) :
74 QStyledItemDelegate(thaParent) {}
76 /// Redefinition of virtual method
77 /// \param painter a painter object
78 /// \param option the item options
79 /// \param index the current index
80 virtual void paint(QPainter* painter,
81 const QStyleOptionViewItem& option,
82 const QModelIndex& index ) const;
84 /// Redefinition of virtual method
85 /// \param parent a parent widget
86 /// \param option the item options
87 /// \param index the current index
88 virtual QWidget* createEditor(QWidget* parent,
89 const QStyleOptionViewItem& option,
90 const QModelIndex& index) const;
92 /// Returns True if the given index is editable item
93 /// \param theIndex an item index
94 bool isEditable(const QModelIndex& theIndex) const;
96 /// Returns currently editing index
97 QModelIndex editIndex() const { return myEditingIdx; }
100 mutable QModelIndex myEditingIdx;
103 bool ParametersPlugin_ItemDelegate::isEditable(const QModelIndex& theIndex) const
105 QModelIndex aParent = theIndex.parent();
106 if (aParent.isValid() && (aParent.row() == 0)) {
107 if (theIndex.column() == 2)
114 void ParametersPlugin_ItemDelegate::paint(QPainter* painter,
115 const QStyleOptionViewItem& option,
116 const QModelIndex& index ) const
118 QBrush aBrush = painter->brush();
119 QPen aPen = painter->pen();
120 //if (!isEditable(index))
121 // painter->setBrush(Qt::lightGray);
122 if (!index.parent().isValid())
123 painter->setBrush(Qt::lightGray);
125 painter->setPen(Qt::lightGray);
126 painter->drawRect(option.rect);
127 painter->setPen(aPen);
129 QStyledItemDelegate::paint(painter, option, index);
130 painter->setBrush(aBrush);
133 QWidget* ParametersPlugin_ItemDelegate::createEditor(QWidget* parent,
134 const QStyleOptionViewItem& option,
135 const QModelIndex& index) const
137 myEditingIdx = index;
138 return QStyledItemDelegate::createEditor(parent, option, index);
141 /////////////////////////////////////////////////////////////////////////////////////////////////
142 void ParametersPlugin_TreeWidget::closeEditor(QWidget* theEditor,
143 QAbstractItemDelegate::EndEditHint theHint)
145 if (theHint == QAbstractItemDelegate::EditNextItem) {
146 QModelIndex aCurrent = currentIndex();
147 QModelIndex aParent = model()->index(0, 0);
148 int aNbRows = model()->rowCount(aParent);
150 switch (aCurrent.column()) {
152 aIdx = model()->index(aCurrent.row(), 1, aParent);
155 if (aCurrent.row() < (aNbRows - 1))
156 aIdx = model()->index(aCurrent.row() + 1, 0, aParent);
158 QTreeWidget::closeEditor(theEditor, QAbstractItemDelegate::NoHint);
163 QTreeWidget::closeEditor(theEditor, theHint);
166 if (aIdx.isValid()) {
167 QTreeWidget::closeEditor(theEditor, QAbstractItemDelegate::NoHint);
168 setCurrentIndex(aIdx);
173 QTreeWidget::closeEditor(theEditor, theHint);
176 /////////////////////////////////////////////////////////////////////////////////////////////////
178 ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theParent,
179 const Config_WidgetAPI* theData)
180 : ModuleBase_ModelDialogWidget(theParent, theData),
181 isUpplyBlocked(false)
183 QVBoxLayout* aLayout = new QVBoxLayout(this);
185 myTable = new ParametersPlugin_TreeWidget(this);
186 myTable->setColumnCount(4);
187 QStringList aHeaders;
188 aHeaders << translate("Name") << translate("Expression")
189 << translate("Result") << translate("Comment");
190 myTable->setHeaderLabels(aHeaders);
191 myTable->setColumnWidth(Col_Name, 200);
192 myTable->setColumnWidth(Col_Equation, 100);
193 myTable->setColumnWidth(Col_Result, 80);
194 myTable->setColumnWidth(Col_Comment, 200);
195 myTable->setMinimumWidth(600);
196 myTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
197 myTable->setSelectionMode(QAbstractItemView::SingleSelection);
199 connect(myTable, SIGNAL(doubleClicked(const QModelIndex&)),
200 SLOT(onDoubleClick(const QModelIndex&)));
201 connect(myTable, SIGNAL(itemSelectionChanged()), SLOT(onSelectionChanged()));
203 myDelegate = new ParametersPlugin_ItemDelegate(myTable);
204 connect(myDelegate, SIGNAL(closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint)),
205 SLOT(onCloseEditor(QWidget*, QAbstractItemDelegate::EndEditHint)));
207 myTable->setItemDelegate(myDelegate);
208 aLayout->addWidget(myTable);
212 aNames<<translate("Parameters");
213 myParameters = new QTreeWidgetItem(aNames);
214 myParameters->setFlags(Qt::ItemIsEnabled);
215 myTable->addTopLevelItem(myParameters);
218 aNames<<translate("Features");
219 myFeatures = new QTreeWidgetItem(aNames);
220 myFeatures->setFlags(Qt::ItemIsEnabled);
221 myTable->addTopLevelItem(myFeatures);
223 QHBoxLayout* aBtnLayout = new QHBoxLayout(this);
225 myUpBtn = new QToolButton(this);
226 myUpBtn->setArrowType(Qt::UpArrow);
227 connect(myUpBtn, SIGNAL(clicked(bool)), SLOT(onUp()));
228 aBtnLayout->addWidget(myUpBtn);
230 myDownBtn = new QToolButton(this);
231 myDownBtn->setArrowType(Qt::DownArrow);
232 connect(myDownBtn, SIGNAL(clicked(bool)), SLOT(onDown()));
233 aBtnLayout->addWidget(myDownBtn);
235 aBtnLayout->addStretch();
237 myAddBtn = new QPushButton(translate("Add"), this);
238 connect(myAddBtn, SIGNAL(clicked(bool)), SLOT(onAdd()));
239 aBtnLayout->addWidget(myAddBtn);
241 myInsertBtn = new QPushButton(translate("Insert"), this);
242 connect(myInsertBtn, SIGNAL(clicked(bool)), SLOT(onInsert()));
243 aBtnLayout->addWidget(myInsertBtn);
245 myRemoveBtn = new QPushButton(translate("Remove"), this);
246 connect(myRemoveBtn, SIGNAL(clicked(bool)), SLOT(onRemove()));
247 aBtnLayout->addWidget(myRemoveBtn);
249 aLayout->addLayout(aBtnLayout);
251 onSelectionChanged();
254 void ParametersPlugin_WidgetParamsMgr::setDialogButtons(QDialogButtonBox* theButtons)
256 ModuleBase_ModelDialogWidget::setDialogButtons(theButtons);
258 QWidget* aBtnParentWgt = myOkCancelBtn->parentWidget();
259 QHBoxLayout* aBtnParentLayout = dynamic_cast<QHBoxLayout*>(aBtnParentWgt->layout());
261 QPushButton* aPreviewBtn = new QPushButton(translate("See preview"), aBtnParentWgt);
262 aBtnParentLayout->insertWidget(0, aPreviewBtn);
263 aBtnParentLayout->insertStretch(1, 1);
264 connect(aPreviewBtn, SIGNAL(clicked(bool)), SLOT(onShowPreview()));
268 QList<QWidget*> ParametersPlugin_WidgetParamsMgr::getControls() const
270 QList<QWidget*> aList;
275 void ParametersPlugin_WidgetParamsMgr::selectItemScroll(QTreeWidgetItem* aItem)
277 myTable->clearSelection();
278 QModelIndex aParent = myTable->model()->index(0, 0);
279 int aChildIdx = myParameters->indexOfChild(aItem);
280 QModelIndex aIndex = myTable->model()->index(aChildIdx, Col_Name, aParent);
281 myTable->selectionModel()->select(aIndex,
282 QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
283 myTable->scrollToItem(aItem);
287 bool ParametersPlugin_WidgetParamsMgr::storeValueCustom()
289 ParametersPlugin_ExpressionValidator aValidator;
290 std::list<std::string> aArgs;
291 std::string aAttrId = ParametersPlugin_Parameter::VARIABLE_ID();
292 Events_InfoMessage aErr;
294 foreach(FeaturePtr aFeature, myParametersList) {
295 if (!aValidator.isValid(aFeature->attribute(aAttrId), aArgs, aErr)) {
296 QMessageBox::warning(this, translate("Warning"), aErr.messageString().c_str());
297 selectItemScroll(myParameters->child(aId));
302 // #2813 : make the current feature the latest in the document
303 std::list<FeaturePtr> allFeatures = myFeature->document()->allFeatures();
304 if (!allFeatures.empty()) {
305 myFeature->document()->setCurrentFeature(*(allFeatures.rbegin()), true);
310 bool ParametersPlugin_WidgetParamsMgr::restoreValueCustom()
315 void ParametersPlugin_WidgetParamsMgr::activateCustom()
317 updateParametersFeatures();
318 updateParametersPart();
319 updateFeaturesPart();
321 myFeatures->setExpanded(true);
322 myParameters->setExpanded(true);
325 void ParametersPlugin_WidgetParamsMgr::updateParametersFeatures()
327 myParametersList.clear();
328 FeaturePtr aFeature = feature();
329 DocumentPtr aDoc = aFeature->document();
331 FeaturePtr aParamFeature;
332 int aNbFeatures = aDoc->numInternalFeatures();
333 for (int i = 0; i < aNbFeatures; i++) {
334 aParamFeature = aDoc->internalFeature(i);
335 if (aParamFeature && aParamFeature->getKind() == ParametersPlugin_Parameter::ID()) {
336 myParametersList.append(aParamFeature);
341 void ParametersPlugin_WidgetParamsMgr::updateFeaturesPart()
343 QList<FeaturePtr> aFeatureList;
344 updateItem(myFeatures, featuresItems(myParametersList, aFeatureList));
347 void ParametersPlugin_WidgetParamsMgr::updateParametersPart()
349 updateItem(myParameters, parametersItems(myParametersList));
350 bool aIsValid = isValid();
351 enableButtons(aIsValid);
355 QList<QStringList> ParametersPlugin_WidgetParamsMgr::
356 featuresItems(const QList<FeaturePtr>& theFeatures, QList<FeaturePtr>& theFeatureList) const
358 QList<QStringList> aItemsList;
359 ResultParameterPtr aParam;
360 foreach(FeaturePtr aParameter, theFeatures) {
361 aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aParameter->firstResult());
362 const std::set<std::shared_ptr<ModelAPI_Attribute>>& aRefs = aParam->data()->refsToMe();
363 std::set<std::shared_ptr<ModelAPI_Attribute> >::const_iterator aIt;
364 for(aIt = aRefs.cbegin(); aIt != aRefs.cend(); aIt++) {
365 std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
366 FeaturePtr aReferenced = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
367 if (aReferenced.get() && (aReferenced != aParameter)) {
368 if (aReferenced->getKind() == ParametersPlugin_Parameter::ID()) {
369 // Find referenced feature Recursive
370 QList<FeaturePtr> aList;
371 aList.append(aReferenced);
372 QList<QStringList> aItems = featuresItems(aList, theFeatureList);
373 aItemsList.append(aItems);
375 if (!theFeatureList.contains(aReferenced)) {
376 QStringList aValNames;
377 aValNames << aReferenced->data()->name().c_str();
379 std::string aId = aAttr->attributeType();
380 if (aId == ModelAPI_AttributeDouble::typeId()) {
381 AttributeDoublePtr aDouble =
382 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aAttr);
383 aValNames << aDouble->text().c_str();
384 aValNames << QString::number(aDouble->value());
386 else if (aId == ModelAPI_AttributeInteger::typeId()) {
387 AttributeIntegerPtr aInt =
388 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(aAttr);
389 aValNames << aInt->text().c_str();
390 aValNames << QString::number(aInt->value());
392 else if (aId == GeomDataAPI_Point::typeId()) {
393 std::shared_ptr<GeomDataAPI_Point> aPnt =
394 std::dynamic_pointer_cast<GeomDataAPI_Point>(aAttr);
396 QString aExpr = QString("%1,%2,%3").arg(aPnt->textX().c_str()).
397 arg(aPnt->textY().c_str()).arg(aPnt->textZ().c_str());
400 QString aRes = QString("%1,%2,%3").arg(aPnt->x()).arg(aPnt->y()).arg(aPnt->z());
403 else if (aId == GeomDataAPI_Point2D::typeId()) {
404 std::shared_ptr<GeomDataAPI_Point2D> aPnt =
405 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
407 QString aExpr = QString("%1,%2").arg(aPnt->textX().c_str()).
408 arg(aPnt->textY().c_str());
411 QString aRes = QString("%1,%2").arg(aPnt->x()).arg(aPnt->y());
414 aItemsList.append(aValNames);
415 theFeatureList.append(aReferenced);
425 QList<QStringList> ParametersPlugin_WidgetParamsMgr::
426 parametersItems(const QList<FeaturePtr>& theFeatures) const
428 std::list<std::string> aArgs;
430 QList<QStringList> aItemsList;
431 foreach(FeaturePtr aParameter, theFeatures) {
432 ResultPtr aParam = aParameter->firstResult();
435 std::string aName = aParameter->string(ParametersPlugin_Parameter::VARIABLE_ID())->value();
437 aValues << translate(NoName);
439 aValues << aName.c_str();
441 std::string aExpr = aParameter->string(ParametersPlugin_Parameter::EXPRESSION_ID())->value();
443 aValues << translate(NoValue);
445 aValues << aExpr.c_str();
448 aParameter->data()->string(ParametersPlugin_Parameter::EXPRESSION_ERROR_ID())->value();
450 AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
451 aValues << QString::number(aValueAttribute->value());
453 aValues << aErr.c_str();
455 aValues << aParameter->string(ParametersPlugin_Parameter::COMMENT_ID())->value().c_str();
456 aItemsList.append(aValues);
462 void ParametersPlugin_WidgetParamsMgr::onDoubleClick(const QModelIndex& theIndex)
464 if (myDelegate->isEditable(theIndex)) {
465 myTable->setCurrentIndex(theIndex);
466 myTable->edit(theIndex);
470 void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor,
471 QAbstractItemDelegate::EndEditHint theHint)
473 FeaturePtr aFeature = myParametersList.at(myDelegate->editIndex().row());
474 QTreeWidgetItem* aItem = myParameters->child(myDelegate->editIndex().row());
475 int aColumn = myDelegate->editIndex().column();
476 QString aText = aItem->text(aColumn);
477 bool isModified = false;
482 AttributeStringPtr aStringAttr = aFeature->string(ParametersPlugin_Parameter::VARIABLE_ID());
483 if (!aText.isEmpty()) {
484 while (aText.indexOf(" ") != -1) {
485 aText.replace(" ", "");
487 if (hasName(aText)) {
488 myMessage = translate("Name '%1' already exists.").arg(aText);
489 QTimer::singleShot(50, this, SLOT(sendWarning()));
492 aStringAttr->setValue(aText.toStdString());
499 AttributeStringPtr aStringAttr =
500 aFeature->string(ParametersPlugin_Parameter::EXPRESSION_ID());
501 if (!aText.isEmpty()) {
502 if (aText != aStringAttr->value().c_str()) {
503 aStringAttr->setValue(aText.toStdString());
512 AttributeStringPtr aStringAttr = aFeature->string(ParametersPlugin_Parameter::COMMENT_ID());
513 aStringAttr->setValue(aText.toStdString());
521 Events_Loop* aLoop = Events_Loop::loop();
522 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
523 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
524 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
526 if (aColumn != Col_Comment)
527 updateParametersPart();
528 updateFeaturesPart();
530 onSelectionChanged();
533 void ParametersPlugin_WidgetParamsMgr::updateItem(QTreeWidgetItem* theItem,
534 const QList<QStringList>& theFeaturesList)
536 if (theFeaturesList.count() != theItem->childCount()) {
537 if (theItem->childCount() < theFeaturesList.count()) {
538 while (theItem->childCount() != theFeaturesList.count())
539 theItem->addChild(createNewItem(theItem));
541 while (theItem->childCount() != theFeaturesList.count())
542 theItem->removeChild(theItem->child(theItem->childCount() - 1));
546 foreach(QStringList aFeature, theFeaturesList) {
548 foreach(QString aText, aFeature) {
549 if (aText.length() > 0) {
550 theItem->child(i)->setText(aCol, aText);
551 theItem->child(i)->setToolTip(aCol, aText);
559 FeaturePtr ParametersPlugin_WidgetParamsMgr::createParameter() const
561 SessionPtr aMgr = ModelAPI_Session::get();
562 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
564 FeaturePtr aFeature = aDoc->addFeature(ParametersPlugin_Parameter::ID());
565 if (aFeature.get()) {
566 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
567 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
573 QTreeWidgetItem* ParametersPlugin_WidgetParamsMgr::createNewItem(QTreeWidgetItem* theParent) const
576 aValues << translate(NoName);
577 aValues << translate(NoValue);
579 QTreeWidgetItem* aItem = new QTreeWidgetItem(aValues);
580 if (theParent == myParameters) {
581 aItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
582 aItem->setForeground(2, Qt::darkGray);
584 aItem->setFlags(Qt::NoItemFlags);
589 void ParametersPlugin_WidgetParamsMgr::onAdd()
591 FeaturePtr aFeature = createParameter();
595 myParametersList.append(aFeature);
596 updateParametersPart();
598 QTreeWidgetItem* aItem = myParameters->child(myParameters->childCount() - 1);
600 myTable->scrollToItem(aItem);
601 myTable->setCurrentItem(aItem);
602 myTable->editItem(aItem);
604 enableButtons(false);
607 QTreeWidgetItem* ParametersPlugin_WidgetParamsMgr::selectedItem() const
609 QList<QTreeWidgetItem*> aItemsList = myTable->selectedItems();
610 if (aItemsList.count() == 0)
613 QTreeWidgetItem* aCurrentItem = aItemsList.first();
614 if (aCurrentItem->parent() != myParameters)
621 void ParametersPlugin_WidgetParamsMgr::onInsert()
623 QTreeWidgetItem* aCurrentItem = selectedItem();
627 SessionPtr aMgr = ModelAPI_Session::get();
628 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
630 FeaturePtr aNewFeature = createParameter();
631 if (!aNewFeature.get())
634 int aCurrentPos = myParameters->indexOfChild(aCurrentItem);
635 if (aCurrentPos == 0) {
636 aDoc->moveFeature(aNewFeature, FeaturePtr());
638 FeaturePtr aCurFeature = myParametersList.at(aCurrentPos - 1);
639 aDoc->moveFeature(aNewFeature, aCurFeature);
641 updateParametersFeatures();
642 updateParametersPart();
644 myTable->scrollToItem(aCurrentItem);
645 myTable->setCurrentItem(aCurrentItem);
646 myTable->editItem(aCurrentItem);
649 void ParametersPlugin_WidgetParamsMgr::onRemove()
651 QTreeWidgetItem* aCurrentItem = selectedItem();
655 SessionPtr aMgr = ModelAPI_Session::get();
656 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
658 int aCurrentPos = myParameters->indexOfChild(aCurrentItem);
659 FeaturePtr aCurFeature = myParametersList.at(aCurrentPos);
661 QObjectPtrList anObjects;
662 anObjects.append(aCurFeature);
664 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
665 std::set<FeaturePtr> aFeatures;
666 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
667 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
669 std::set<FeaturePtr> aFeatureRefsToDelete;
670 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, this, aFeatureRefsToDelete)) {
671 if (!aFeatureRefsToDelete.empty())
672 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
673 ModelAPI_Tools::removeFeatures(aFeatures, false);
675 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
676 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
677 updateParametersFeatures();
678 updateFeaturesPart();
679 updateParametersPart();
683 void ParametersPlugin_WidgetParamsMgr::onUp()
685 QTreeWidgetItem* aCurrentItem = selectedItem();
689 int aCurrentPos = myParameters->indexOfChild(aCurrentItem);
690 if (aCurrentPos == 0)
692 FeaturePtr aCurFeature = myParametersList.at(aCurrentPos);
694 SessionPtr aMgr = ModelAPI_Session::get();
695 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
697 if (aCurrentPos == 1)
698 aDoc->moveFeature(aCurFeature, FeaturePtr());
700 aDoc->moveFeature(aCurFeature, myParametersList.at(aCurrentPos - 2));
702 // add the updated also the feature that goes down
703 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
704 static Events_ID EVENT_UPD = Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED);
705 ModelAPI_EventCreator::get()->sendUpdated(myParametersList.at(aCurrentPos - 1), EVENT_UPD);
706 Events_Loop::loop()->flush(EVENT_UPD);
707 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
708 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
709 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
710 updateParametersFeatures();
711 updateParametersPart();
712 updateFeaturesPart();
714 if (aCurrentPos > 0) {
715 aCurrentItem = myParameters->child(aCurrentPos - 1);
716 myTable->setCurrentItem(aCurrentItem);
717 selectItemScroll(aCurrentItem);
721 void ParametersPlugin_WidgetParamsMgr::onDown()
723 QTreeWidgetItem* aCurrentItem = selectedItem();
727 int aCurrentPos = myParameters->indexOfChild(aCurrentItem);
728 if (aCurrentPos == (myParametersList.count() - 1))
730 FeaturePtr aCurFeature = myParametersList.at(aCurrentPos);
732 SessionPtr aMgr = ModelAPI_Session::get();
733 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
734 aDoc->moveFeature(aCurFeature, myParametersList.at(aCurrentPos + 1));
735 // add the updated also the feature that goes up
736 static Events_ID EVENT_UPD = Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED);
737 ModelAPI_EventCreator::get()->sendUpdated(myParametersList.at(aCurrentPos + 1), EVENT_UPD);
739 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
740 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED));
741 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
742 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
743 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
744 updateParametersFeatures();
745 updateParametersPart();
746 updateFeaturesPart();
748 if (aCurrentPos < myParameters->childCount() - 1) {
749 aCurrentItem = myParameters->child(aCurrentPos + 1);
750 myTable->setCurrentItem(aCurrentItem);
751 selectItemScroll(aCurrentItem);
756 bool ParametersPlugin_WidgetParamsMgr::hasName(const QString& theName) const
758 int aCurrent = myDelegate->editIndex().row();
760 foreach(FeaturePtr aFeature, myParametersList) {
761 if ((i != aCurrent) && (aFeature->data()->name() == theName.toStdString()))
768 void ParametersPlugin_WidgetParamsMgr::sendWarning()
770 QMessageBox::warning(this, translate("Warning"), myMessage);
771 QTreeWidgetItem* aItem = myTable->currentItem();
773 myTable->editItem(aItem);
776 void ParametersPlugin_WidgetParamsMgr::onSelectionChanged()
778 QList<QTreeWidgetItem*> aItemsList = myTable->selectedItems();
779 bool aIsValid = isValid();
781 bool isParameter = false;
782 foreach(QTreeWidgetItem* aItem, aItemsList) {
783 if (aItem->parent() == myParameters) {
788 myInsertBtn->setEnabled(isParameter);
789 //myRemoveBtn->setEnabled(isParameter);
790 myUpBtn->setEnabled(isParameter);
791 myDownBtn->setEnabled(isParameter);
793 myInsertBtn->setEnabled(false);
794 //myRemoveBtn->setEnabled(false);
795 myUpBtn->setEnabled(false);
796 myDownBtn->setEnabled(false);
798 myRemoveBtn->setEnabled(!aItemsList.isEmpty());
801 void ParametersPlugin_WidgetParamsMgr::enableButtons(bool theEnable)
803 myAddBtn->setEnabled(theEnable);
805 onSelectionChanged();
807 myInsertBtn->setEnabled(theEnable);
808 //myRemoveBtn->setEnabled(theEnable);
809 myUpBtn->setEnabled(theEnable);
810 myDownBtn->setEnabled(theEnable);
812 myOkCancelBtn->button(QDialogButtonBox::Ok)->setEnabled(theEnable);
815 bool ParametersPlugin_WidgetParamsMgr::isValid()
817 QTreeWidgetItem* aItem;
818 for(int i = 0; i < myParameters->childCount(); i++) {
819 aItem = myParameters->child(i);
820 if ((aItem->text(Col_Name) == NoName) ||
821 (aItem->text(Col_Equation) == translate(NoValue)) ||
822 (!ModelAPI_Expression::isVariable(aItem->text(Col_Name).toStdString())) ) {
829 void ParametersPlugin_WidgetParamsMgr::showEvent(QShowEvent* theEvent)
831 ModuleBase_ModelDialogWidget::showEvent(theEvent);
832 SessionPtr aMgr = ModelAPI_Session::get();
833 isUpplyBlocked = aMgr->isAutoUpdateBlocked();
834 aMgr->blockAutoUpdate(true);
835 Events_Loop* aLoop = Events_Loop::loop();
836 aLoop->flush(aLoop->eventByName(EVENT_AUTOMATIC_RECOMPUTATION_DISABLE));
839 void ParametersPlugin_WidgetParamsMgr::hideEvent(QHideEvent* theEvent)
841 ModuleBase_ModelDialogWidget::hideEvent(theEvent);
842 SessionPtr aMgr = ModelAPI_Session::get();
843 aMgr->blockAutoUpdate(isUpplyBlocked);
846 void ParametersPlugin_WidgetParamsMgr::onShowPreview()
848 SessionPtr aMgr = ModelAPI_Session::get();
849 aMgr->blockAutoUpdate(false);
850 aMgr->blockAutoUpdate(true);