+
+//=======================================================================
+//function : isKeepNodesIDsSelection
+//purpose : Return true of Nodes to keep are selected by IDs
+//=======================================================================
+
+bool SMESHGUI_MergeDlg::isKeepNodesIDsSelection()
+{
+ return KeepFromButGroup && KeepFromButGroup->checkedId() == 0;
+}
+
+//=======================================================================
+//function : isNewKeepNodesGroup
+//purpose : Return true if an object with given entry is NOT present in KeepList
+//=======================================================================
+
+bool SMESHGUI_MergeDlg::isNewKeepNodesGroup( const char* entry )
+{
+ if ( !entry || isKeepNodesIDsSelection() )
+ return false;
+
+ for ( int i = 0; i < KeepList->count(); i++ )
+ if ( KeepList->item( i )->data( Qt::UserRole ).toString() == entry )
+ return false;
+
+ return true;
+}
+
+//=======================================================================
+//function : onAddKeepNode
+//purpose : SLOT called when [Add] of Nodes To Keep group is pressed
+//=======================================================================
+
+void SMESHGUI_MergeDlg::onAddKeepNode()
+{
+ if ( myIsBusy )
+ return;
+ myIsBusy = true;
+
+ if ( isKeepNodesIDsSelection() )
+ {
+ //KeepList->clearSelection();
+ QString anIDs = "";
+ int aNbNodes = 0;
+ if ( myActor )
+ aNbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
+ if (aNbNodes > 0)
+ {
+ QStringList anNodes = anIDs.split( " ", QString::SkipEmptyParts);
+ QList<QListWidgetItem*> listItemsToSel;
+ QListWidgetItem* anItem;
+ for (QStringList::iterator it = anNodes.begin(); it != anNodes.end(); ++it)
+ {
+ QList<QListWidgetItem*> found = KeepList->findItems(*it, Qt::MatchExactly);
+ if (found.count() == 0) {
+ anItem = new QListWidgetItem(*it);
+ KeepList->addItem(anItem);
+ if (!anItem->isSelected())
+ listItemsToSel.push_back(anItem);
+ }
+ else {
+ foreach(anItem, found)
+ if (!anItem->isSelected())
+ listItemsToSel.push_back(anItem);
+ }
+ }
+ bool blocked = KeepList->signalsBlocked();
+ KeepList->blockSignals(true);
+ foreach(anItem, listItemsToSel) anItem->setSelected(true);
+ KeepList->blockSignals(blocked);
+ //onSelectKeepNode();
+ }
+ RemoveKeepNodesButton->setEnabled( aNbNodes > 0 );
+ }
+ else
+ {
+ SALOME_ListIO aList;
+ mySelectionMgr->selectedObjects(aList);
+ SALOME_ListIteratorOfListIO anIt (aList);
+ for ( ; anIt.More(); anIt.Next()) {
+ Handle(SALOME_InteractiveObject) anIO = anIt.Value();
+ if ( isNewKeepNodesGroup( anIO->getEntry() ))
+ {
+ QListWidgetItem* anItem = new QListWidgetItem( anIO->getName() );
+ anItem->setData( Qt::UserRole, QString( anIO->getEntry() ));
+ KeepList->addItem(anItem);
+ }
+ }
+ //RemoveKeepNodesButton->setEnabled( KeepList->selectedItems().count() );
+ }
+
+ AddKeepNodesButton->setEnabled( false );
+
+ myIsBusy = false;
+}
+
+//=======================================================================
+//function : onRemoveKeepNode
+//purpose : SLOT called when [Remove] of Nodes To Keep group is pressed
+//=======================================================================
+
+void SMESHGUI_MergeDlg::onRemoveKeepNode()
+{
+ // if ( isKeepNodesIDsSelection() )
+ // {
+ // }
+ // else
+ {
+ QList<QListWidgetItem*> selItems = KeepList->selectedItems();
+ QListWidgetItem* item;
+ foreach(item, selItems) delete item;
+ }
+ if ( isKeepNodesIDsSelection() )
+ {
+ AddKeepNodesButton->setEnabled( false );
+ }
+ RemoveKeepNodesButton->setEnabled( false );
+}
+
+//=======================================================================
+//function : onSelectKeepNode
+//purpose : SLOT called when selection in KeepList changes
+//=======================================================================
+
+void SMESHGUI_MergeDlg::onSelectKeepNode()
+{
+ if ( myIsBusy || !isEnabled() ) return;
+ myIsBusy = true;
+
+ if ( isKeepNodesIDsSelection() )
+ {
+ if ( myActor )
+ {
+ mySelectionMgr->clearSelected();
+ TColStd_MapOfInteger aIndexes;
+ QList<QListWidgetItem*> selItems = KeepList->selectedItems();
+ QListWidgetItem* anItem;
+ foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
+ mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
+ SALOME_ListIO aList;
+ aList.Append(myActor->getIO());
+ mySelectionMgr->setSelectedObjects(aList,false);
+
+ AddKeepNodesButton->setEnabled( false );
+ RemoveKeepNodesButton->setEnabled( aIndexes.Extent() > 0 );
+ }
+ }
+ else
+ {
+ RemoveKeepNodesButton->setEnabled( KeepList->selectedItems().count() );
+ }
+ myIsBusy = false;
+}
+
+//=======================================================================
+//function : onKeepNodeSourceChanged
+//purpose : SLOT called when type of source of Nodes To Keep change from
+// IDs to groups or vice versa
+//=======================================================================
+
+void SMESHGUI_MergeDlg::onKeepNodeSourceChanged(int isGroup)
+{
+ KeepList->clear();
+ SelectKeepNodesButton->click();
+}