Salome HOME
Fix bug 12796: Warning missed for the bad file 'test18.med'
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MergeNodesDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : SMESHGUI_MergeNodesDlg.cxx
25 //  Author : Michael ZORIN
26 //  Module : SMESH
27 //  $Header:
28
29 #include "SMESHGUI_MergeNodesDlg.h"
30
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESHGUI_SpinBox.h"
36
37 #include "SMESH_Actor.h"
38 #include "SMESH_TypeFilter.hxx"
39 #include "SMDS_Mesh.hxx"
40
41 #include "GEOMBase.h"
42
43 #include "SUIT_ResourceMgr.h"
44 #include "SUIT_Session.h"
45 #include "SUIT_MessageBox.h"
46
47 #include "LightApp_Application.h"
48
49 #include "SVTK_ViewModel.h"
50 #include "SVTK_ViewWindow.h"
51 #include "SVTK_Selector.h"
52 #include "SVTK_Selection.h"
53 #include "SALOME_ListIO.hxx"
54
55 #include "utilities.h"
56
57 // OCCT Includes
58 #include <TColStd_MapOfInteger.hxx>
59
60 // QT Includes
61 #include <qapplication.h>
62 #include <qbuttongroup.h>
63 #include <qgroupbox.h>
64 #include <qlabel.h>
65 #include <qlineedit.h>
66 #include <qlistbox.h>
67 #include <qlistview.h>
68 #include <qpushbutton.h>
69 #include <qradiobutton.h>
70 #include <qcheckbox.h>
71 #include <qlayout.h>
72 #include <qpixmap.h>
73 #include <qheader.h>
74
75 using namespace std;
76
77 //=================================================================================
78 // class    : SMESHGUI_MergeNodesDlg()
79 // purpose  :
80 //=================================================================================
81 SMESHGUI_MergeNodesDlg::SMESHGUI_MergeNodesDlg( SMESHGUI* theModule, const char* name,
82                                                 bool modal, WFlags fl)
83      : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
84                 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
85      mySMESHGUI( theModule ),
86      mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
87 {
88   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_MERGE_NODES")));
89   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
90
91   if (!name)
92     setName("SMESHGUI_MergeNodesDlg");
93   resize(303, 185);
94   setCaption(tr("SMESH_MERGE_NODES"));
95   setSizeGripEnabled(TRUE);
96   SMESHGUI_MergeNodesDlgLayout = new QGridLayout(this);
97   SMESHGUI_MergeNodesDlgLayout->setSpacing(6);
98   SMESHGUI_MergeNodesDlgLayout->setMargin(11);
99
100   /***************************************************************/
101   GroupConstructors = new QButtonGroup(this, "GroupConstructors");
102   GroupConstructors->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5,
103                                                (QSizePolicy::SizeType)0, 0, 0,
104                                                GroupConstructors->sizePolicy().hasHeightForWidth()));
105   GroupConstructors->setTitle(tr("SMESH_MERGE_NODES" ));
106   GroupConstructors->setExclusive(TRUE);
107   GroupConstructors->setColumnLayout(0, Qt::Vertical);
108   GroupConstructors->layout()->setSpacing(0);
109   GroupConstructors->layout()->setMargin(0);
110   GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
111   GroupConstructorsLayout->setAlignment(Qt::AlignTop);
112   GroupConstructorsLayout->setSpacing(6);
113   GroupConstructorsLayout->setMargin(11);
114   QHBoxLayout* RBLayout = new QHBoxLayout(0, 0, 6, "Layout2");
115   RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
116   RadioButton1->setText(tr("" ));
117   RadioButton1->setPixmap(image0);
118   RBLayout->addWidget(RadioButton1);
119   GroupConstructorsLayout->addLayout(RBLayout, 0, 0);
120   SMESHGUI_MergeNodesDlgLayout->addWidget(GroupConstructors, 0, 0);
121
122   /***************************************************************/
123   GroupButtons = new QGroupBox(this, "GroupButtons");
124   GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
125                                           (QSizePolicy::SizeType)0, 0, 0,
126                                           GroupButtons->sizePolicy().hasHeightForWidth()));
127   GroupButtons->setGeometry(QRect(10, 10, 281, 48));
128   GroupButtons->setTitle(tr("" ));
129   GroupButtons->setColumnLayout(0, Qt::Vertical);
130   GroupButtons->layout()->setSpacing(0);
131   GroupButtons->layout()->setMargin(0);
132   GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
133   GroupButtonsLayout->setAlignment(Qt::AlignTop);
134   GroupButtonsLayout->setSpacing(6);
135   GroupButtonsLayout->setMargin(11);
136   buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
137   buttonHelp->setText(tr("SMESH_BUT_HELP" ));
138   buttonHelp->setAutoDefault(TRUE);
139   GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
140   buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
141   buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
142   buttonCancel->setAutoDefault(TRUE);
143   GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
144   buttonApply = new QPushButton(GroupButtons, "buttonApply");
145   buttonApply->setText(tr("SMESH_BUT_APPLY" ));
146   buttonApply->setAutoDefault(TRUE);
147   GroupButtonsLayout->addWidget(buttonApply, 0, 1);
148   QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
149   GroupButtonsLayout->addItem(spacer_9, 0, 2);
150   buttonOk = new QPushButton(GroupButtons, "buttonOk");
151   buttonOk->setText(tr("SMESH_BUT_OK" ));
152   buttonOk->setAutoDefault(TRUE);
153   buttonOk->setDefault(TRUE);
154   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
155   SMESHGUI_MergeNodesDlgLayout->addWidget(GroupButtons, 4, 0);
156
157   /***************************************************************/
158
159   // Controls for mesh defining
160   GroupMesh = new QGroupBox(this, "GroupMesh");
161   GroupMesh->setTitle(tr("SMESH_MESH"));
162   GroupMesh->setColumnLayout(0, Qt::Vertical);
163   GroupMesh->layout()->setSpacing(0);
164   GroupMesh->layout()->setMargin(0);
165   GroupMeshLayout = new QGridLayout(GroupMesh->layout());
166   GroupMeshLayout->setAlignment(Qt::AlignTop);
167   GroupMeshLayout->setSpacing(6);
168   GroupMeshLayout->setMargin(11);
169
170   TextLabelName = new QLabel(GroupMesh, "TextLabelName");
171   TextLabelName->setText(tr("SMESH_NAME"));
172   GroupMeshLayout->addWidget(TextLabelName, 0, 0);
173
174   SelectMeshButton = new QPushButton(GroupMesh, "SelectMeshButton");
175   SelectMeshButton->setPixmap(image1);
176   GroupMeshLayout->addWidget(SelectMeshButton, 0, 1);
177
178   LineEditMesh = new QLineEdit(GroupMesh, "LineEditMesh");
179   LineEditMesh->setReadOnly(true);
180   GroupMeshLayout->addWidget(LineEditMesh, 0, 2);
181
182   SMESHGUI_MergeNodesDlgLayout->addWidget(GroupMesh, 1, 0);
183
184   // Controls for coincident nodes detecting
185   GroupCoincident = new QGroupBox(this, "GroupCoincident");
186   GroupCoincident->setTitle(tr("COINCIDENT_NODES"));
187   GroupCoincident->setColumnLayout(0, Qt::Vertical);
188   GroupCoincident->layout()->setSpacing(0);
189   GroupCoincident->layout()->setMargin(0);
190   QGridLayout* GroupCoincidentLayout = new QGridLayout(GroupCoincident->layout());
191   GroupCoincidentLayout->setAlignment(Qt::AlignTop);
192   GroupCoincidentLayout->setSpacing(6);
193   GroupCoincidentLayout->setMargin(11);
194
195   TextLabelTolerance = new QLabel(GroupCoincident, "TextLabelTolerance");
196   TextLabelTolerance->setText(tr("SMESH_TOLERANCE"));
197   GroupCoincidentLayout->addWidget(TextLabelTolerance, 0, 0);
198
199   SpinBoxTolerance = new SMESHGUI_SpinBox(GroupCoincident, "SpinBoxTolerance");
200   GroupCoincidentLayout->addWidget(SpinBoxTolerance, 0, 1);
201
202   QPushButton* DetectButton = new QPushButton(GroupCoincident, "DetectButton");
203   DetectButton->setText(tr("DETECT"));
204   GroupCoincidentLayout->addWidget(DetectButton, 0, 2);
205
206   ListCoincident = new QListView(GroupCoincident);
207   ListCoincident->setSorting(-1);
208   ListCoincident->addColumn("Nodes");
209   ListCoincident->header()->hide();
210
211   GroupCoincidentLayout->addMultiCellWidget(ListCoincident, 1, 1, 0, 1);
212
213   SelectAllCB = new QCheckBox(GroupCoincident, "SelectAllCB");
214   SelectAllCB->setText(tr("SELECT_ALL"));
215   GroupCoincidentLayout->addWidget(SelectAllCB, 2, 0);
216
217   SMESHGUI_MergeNodesDlgLayout->addWidget(GroupCoincident, 2, 0);
218
219   // Controls for editing group of nodes
220   GroupEdit = new QGroupBox(this, "GroupEdit");
221   GroupEdit->setTitle(tr("EDIT_GROUP_OF_NODES"));
222   GroupEdit->setColumnLayout(0, Qt::Vertical);
223   GroupEdit->layout()->setSpacing(0);
224   GroupEdit->layout()->setMargin(0);
225   QGridLayout* GroupEditLayout = new QGridLayout(GroupEdit->layout());
226   GroupEditLayout->setAlignment(Qt::AlignTop);
227   GroupEditLayout->setSpacing(6);
228   GroupEditLayout->setMargin(11);
229
230   ListEdit = new QListBox(GroupEdit, "ListEdit");
231   ListEdit->setColumnMode(QListBox::FitToHeight);
232   ListEdit->setSelectionMode(QListBox::Extended);
233   GroupEditLayout->addMultiCellWidget(ListEdit, 0, 2, 0, 0);
234
235   QPushButton* AddButton = new QPushButton(GroupEdit, "AddButton");
236   AddButton->setText(tr("SMESH_BUT_ADD"));
237   GroupEditLayout->addWidget(AddButton, 0, 1);
238
239   QPushButton* RemoveButton = new QPushButton(GroupEdit, "RemoveButton");
240   RemoveButton->setText(tr("SMESH_BUT_REMOVE"));
241   GroupEditLayout->addWidget(RemoveButton, 1, 1);
242
243   QSpacerItem* spacer = new QSpacerItem(20, 200, QSizePolicy::Minimum, QSizePolicy::Expanding);
244   GroupEditLayout->addItem(spacer, 2, 1);
245
246   SMESHGUI_MergeNodesDlgLayout->addWidget(GroupEdit, 3, 0);
247
248   /* Initialisations */
249   SpinBoxTolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.1, 3);
250   SpinBoxTolerance->SetValue(1e-05);
251
252   RadioButton1->setChecked(TRUE);
253
254   myEditCurrentArgument = (QWidget*)LineEditMesh; 
255
256   myActor = 0;
257
258   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
259
260   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
261
262   myMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
263
264   /* signals and slots connections */
265   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
266   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
267   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
268   connect(buttonHelp, SIGNAL(clicked()),   this, SLOT(ClickOnHelp()));
269
270   connect(SelectMeshButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
271   connect(DetectButton, SIGNAL (clicked()), this, SLOT(onDetect()));
272   connect(ListCoincident, SIGNAL (selectionChanged()), this, SLOT(onSelectNodesGroup()));
273   connect(ListCoincident, SIGNAL (pressed(QListViewItem*)), this, SLOT(updateControls()));
274   connect(ListCoincident, SIGNAL (currentChanged(QListViewItem*)), this, SLOT(updateControls()));
275   connect(SelectAllCB, SIGNAL(toggled(bool)), this, SLOT(onSelectAll(bool)));
276   connect(ListEdit, SIGNAL (selectionChanged()), this, SLOT(onSelectNodesFromGroup()));
277   connect(AddButton, SIGNAL (clicked()), this, SLOT(onAdd()));
278   connect(RemoveButton, SIGNAL (clicked()), this, SLOT(onRemove()));
279
280   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
281   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
282   /* to close dialog if study change */
283   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
284
285   this->show(); /* displays Dialog */
286
287   resize(0,0);
288   buttonOk->setEnabled(false);
289   buttonApply->setEnabled(false);
290
291   // Init Mesh field from selection
292   SelectionIntoArgument();
293
294   myHelpFileName = "/files/merging_nodes.htm";
295 }
296
297 //=================================================================================
298 // function : ~SMESHGUI_MergeNodesDlg()
299 // purpose  : Destroys the object and frees any allocated resources
300 //=================================================================================
301 SMESHGUI_MergeNodesDlg::~SMESHGUI_MergeNodesDlg()
302 {
303   // no need to delete child widgets, Qt does it all for us
304 }
305
306 //=================================================================================
307 // function : ClickOnApply()
308 // purpose  :
309 //=================================================================================
310 bool SMESHGUI_MergeNodesDlg::ClickOnApply()
311 {
312   if (mySMESHGUI->isActiveStudyLocked() || myMesh->_is_nil())
313     return false;
314
315   try {
316     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
317
318     QApplication::setOverrideCursor(Qt::waitCursor);
319     SMESH::array_of_long_array_var aGroupsOfNodes = new SMESH::array_of_long_array;
320     aGroupsOfNodes->length(ListCoincident->childCount());
321     QListViewItem* item = ListCoincident->firstChild();
322
323     int anArrayNum = 0;
324     while (item) {
325       QStringList aListIds = QStringList("");
326       if (((QCheckListItem*) item)->isOn())
327         aListIds = QStringList::split(" ", item->text(0), false);
328
329       SMESH::long_array_var anIds = new SMESH::long_array;
330       anIds->length(aListIds.count());
331
332       for (int i = 0; i < aListIds.count(); i++)
333         anIds[i] = aListIds[i].toInt();
334
335       aGroupsOfNodes[anArrayNum++] = anIds.inout();
336
337       item = item->itemBelow();
338     }
339
340     aMeshEditor->MergeNodes (aGroupsOfNodes.inout());
341     QApplication::restoreOverrideCursor();
342   } catch(...) {
343   }
344
345   //mySelectionMgr->clearSelected();
346   SMESH::UpdateView();
347
348   onDetect();
349   return true;
350 }
351
352 //=================================================================================
353 // function : ClickOnOk()
354 // purpose  :
355 //=================================================================================
356 void SMESHGUI_MergeNodesDlg::ClickOnOk()
357 {
358   if (ClickOnApply())
359     ClickOnCancel();
360 }
361
362 //=================================================================================
363 // function : ClickOnCancel()
364 // purpose  :
365 //=================================================================================
366 void SMESHGUI_MergeNodesDlg::ClickOnCancel()
367 {
368   mySelectionMgr->clearFilters();
369   //mySelectionMgr->clearSelected();
370   SMESH::SetPointRepresentation(false);
371   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
372     aViewWindow->SetSelectionMode(ActorSelection);
373   disconnect(mySelectionMgr, 0, this, 0);
374   mySMESHGUI->ResetState();
375   reject();
376 }
377
378 //=================================================================================
379 // function : ClickOnHelp()
380 // purpose  :
381 //=================================================================================
382 void SMESHGUI_MergeNodesDlg::ClickOnHelp()
383 {
384   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
385   if (app) 
386     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
387   else {
388     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
389                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
390                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
391                            QObject::tr("BUT_OK"));
392   }
393 }
394
395 //=================================================================================
396 // function : onEditNodesGroup()
397 // purpose  :
398 //=================================================================================
399 void SMESHGUI_MergeNodesDlg::onEditNodesGroup()
400 {
401   if (ListCoincident->childCount() < 1)
402     return;
403
404   QString aNewIds = "";
405
406   QListBoxItem* anItem;
407   for (anItem = ListEdit->firstItem(); anItem != 0; anItem = anItem->next())
408     aNewIds+=QString(" %1").arg(anItem->text());
409
410   ListCoincident->currentItem()->setText(0, aNewIds);
411 }
412
413 //=================================================================================
414 // function : updateControls()
415 // purpose  :
416 //=================================================================================
417 void SMESHGUI_MergeNodesDlg::updateControls()
418 {
419   if (ListCoincident->childCount() < 1) {
420     SMESH::SetPointRepresentation(false);
421     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
422       aViewWindow->SetSelectionMode(ActorSelection);
423     return;
424   }
425
426   bool hasChecked = false, hasUnchecked = false;
427
428   QListViewItem* item = ListCoincident->firstChild();
429
430   while (item && (!hasChecked || !hasUnchecked)) {
431     if (((QCheckListItem*) item)->isOn())
432       hasChecked = true;
433     else
434       hasUnchecked = true;
435
436     item = item->itemBelow();
437   }
438
439   if (hasUnchecked)
440     SelectAllCB->setChecked(false);
441
442   bool enable = !(myMesh->_is_nil()) && hasChecked;
443
444   buttonOk->setEnabled(enable);
445   buttonApply->setEnabled(enable);
446 }
447
448 //=================================================================================
449 // function : onDetect()
450 // purpose  :
451 //=================================================================================
452 void SMESHGUI_MergeNodesDlg::onDetect()
453 {
454   if (myMesh->_is_nil())
455     return;
456
457   try {
458     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
459
460     QApplication::setOverrideCursor(Qt::waitCursor);
461     ListCoincident->clear();
462     ListEdit->clear();
463
464     SMESH::array_of_long_array_var aNodeGroups;
465     aMeshEditor->FindCoincidentNodes(SpinBoxTolerance->GetValue(), aNodeGroups);
466
467     for (int i = 0; i < aNodeGroups->length(); i++) {
468       SMESH::long_array& aGroup = aNodeGroups[i];
469
470       QString aNodeIds;
471       for (int j = 0; j < aGroup.length(); j++)
472         aNodeIds+=QString(" %1").arg(aGroup[j]);
473
474       new QCheckListItem (ListCoincident, aNodeIds, QCheckListItem::CheckBox);
475     }
476     QApplication::restoreOverrideCursor();
477   } catch(...) {
478   }
479
480   updateControls();
481 }
482
483 //=================================================================================
484 // function : onSelectNodesGroup()
485 // purpose  :
486 //=================================================================================
487 void SMESHGUI_MergeNodesDlg::onSelectNodesGroup()
488 {
489   if (!myActor)
490     return;
491
492   myEditCurrentArgument = (QWidget*)ListCoincident;
493
494   QListViewItem* aSelectedItem = ListCoincident->selectedItem();
495   if (!aSelectedItem)
496     return;
497
498   QStringList aListId = QStringList::split(" ", aSelectedItem->text(0), false);
499
500   ListEdit->clear();
501   ListEdit->insertStringList(aListId);
502
503   //mySelectionMgr->clearSelected();
504   //mySelectionMgr->AddIObject(myActor->getIO());
505   SALOME_ListIO aList;
506   aList.Append(myActor->getIO());
507   mySelectionMgr->setSelectedObjects(aList, false);
508
509   SMESH::SetPointRepresentation(true);
510   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
511     aViewWindow->SetSelectionMode(NodeSelection);
512
513   ListEdit->selectAll(true);
514 }
515
516 //=================================================================================
517 // function : onSelectAll()
518 // purpose  :
519 //=================================================================================
520 void SMESHGUI_MergeNodesDlg::onSelectAll (bool isToggled)
521 {
522   if (isToggled) {
523     int aNbItems = 0;
524     QListViewItem* item = ListCoincident->firstChild();
525     while (item) {
526       aNbItems++;
527       if (!((QCheckListItem*) item)->isOn())
528         ((QCheckListItem*) item)->setOn(true);
529       item = item->itemBelow();
530     }
531
532     if (aNbItems) {
533       buttonOk->setEnabled(true);
534       buttonApply->setEnabled(true);
535     }
536   }
537 }
538
539 //=================================================================================
540 // function : onSelectNodesFromGroup()
541 // purpose  :
542 //=================================================================================
543 void SMESHGUI_MergeNodesDlg::onSelectNodesFromGroup()
544 {
545   if (!myActor)
546     return;
547
548   TColStd_MapOfInteger aIndexes;
549   QListBoxItem* anItem;
550   for (anItem = ListEdit->firstItem(); anItem != 0; anItem = anItem->next()) {
551     if (anItem->isSelected()) {
552       int anId = anItem->text().toInt();
553       aIndexes.Add(anId);
554     }
555   }
556
557   mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
558   SALOME_ListIO aList;
559   aList.Append(myActor->getIO());
560   mySelectionMgr->setSelectedObjects(aList);
561 }
562
563 //=================================================================================
564 // function : onAdd()
565 // purpose  :
566 //=================================================================================
567 void SMESHGUI_MergeNodesDlg::onAdd()
568 {
569   if (!myActor)
570     return;
571
572   QString aListStr = "";
573   int aNbNnodes = 0;
574
575   aNbNnodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
576   if (aNbNnodes < 1)
577     return;
578
579   QStringList aNodes = QStringList::split(" ", aListStr);
580   QListBoxItem* anItem = 0;
581
582   for (QStringList::iterator it = aNodes.begin(); it != aNodes.end(); ++it) {
583     anItem = ListEdit->findItem(*it, Qt::ExactMatch);
584     if (!anItem) {
585       anItem = new QListBoxText(*it);
586       ListEdit->insertItem(anItem);
587     }
588     ListEdit->setSelected(anItem, true);
589   }
590
591   onEditNodesGroup();
592 }
593
594 //=================================================================================
595 // function : onRemove()
596 // purpose  :
597 //=================================================================================
598 void SMESHGUI_MergeNodesDlg::onRemove()
599 {
600   if (myEditCurrentArgument != (QWidget*)ListCoincident)
601     return;
602
603   for (int i = ListEdit->count(); i > 0; i--) {
604     if (ListEdit->isSelected(i-1))
605       ListEdit->removeItem(i-1);
606   }
607   onEditNodesGroup();
608 }
609
610 //=================================================================================
611 // function : SetEditCurrentArgument()
612 // purpose  :
613 //=================================================================================
614 void SMESHGUI_MergeNodesDlg::SetEditCurrentArgument()
615 {
616   QPushButton* send = (QPushButton*)sender();
617
618   disconnect(mySelectionMgr, 0, this, 0);
619   mySelectionMgr->clearSelected();
620   mySelectionMgr->clearFilters();
621
622   if (send == SelectMeshButton) {
623     myEditCurrentArgument = (QWidget*)LineEditMesh;
624     SMESH::SetPointRepresentation(false);
625     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
626       aViewWindow->SetSelectionMode(ActorSelection);
627     mySelectionMgr->installFilter(myMeshOrSubMeshFilter);
628   }
629
630   myEditCurrentArgument->setFocus();
631   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
632   SelectionIntoArgument();
633 }
634
635 //=================================================================================
636 // function : SelectionIntoArgument()
637 // purpose  : Called when selection as changed or other case
638 //=================================================================================
639 void SMESHGUI_MergeNodesDlg::SelectionIntoArgument()
640 {
641   if (myEditCurrentArgument == (QWidget*)LineEditMesh) {
642     QString aString = "";
643     LineEditMesh->setText(aString);
644
645     ListCoincident->clear();
646     ListEdit->clear();
647
648     int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
649     if (nbSel != 1)
650       return;
651
652     SALOME_ListIO aList;
653     mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
654
655     Handle(SALOME_InteractiveObject) IO = aList.First();
656     myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
657     myActor = SMESH::FindActorByEntry(aList.First()->getEntry());
658     if (myMesh->_is_nil() || !myActor)
659       return;
660
661     LineEditMesh->setText(aString);
662   }
663 }
664
665 //=================================================================================
666 // function : DeactivateActiveDialog()
667 // purpose  :
668 //=================================================================================
669 void SMESHGUI_MergeNodesDlg::DeactivateActiveDialog()
670 {
671   if (GroupConstructors->isEnabled()) {
672     GroupConstructors->setEnabled(false);
673     GroupMesh->setEnabled(false);
674     GroupCoincident->setEnabled(false);
675     GroupEdit->setEnabled(false);
676     GroupButtons->setEnabled(false);
677     mySMESHGUI->ResetState();
678     mySMESHGUI->SetActiveDialogBox(0);
679   }
680 }
681
682 //=================================================================================
683 // function : ActivateThisDialog()
684 // purpose  :
685 //=================================================================================
686 void SMESHGUI_MergeNodesDlg::ActivateThisDialog()
687 {
688   /* Emit a signal to deactivate the active dialog */
689   mySMESHGUI->EmitSignalDeactivateDialog();
690   GroupConstructors->setEnabled(true);
691   GroupMesh->setEnabled(true);
692   GroupCoincident->setEnabled(true);
693   GroupEdit->setEnabled(true);
694   GroupButtons->setEnabled(true);
695
696   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
697
698   SelectionIntoArgument();
699 }
700
701 //=================================================================================
702 // function : enterEvent()
703 // purpose  :
704 //=================================================================================
705 void SMESHGUI_MergeNodesDlg::enterEvent (QEvent*)
706 {
707   if (!GroupConstructors->isEnabled())
708     ActivateThisDialog();
709 }
710
711 //=================================================================================
712 // function : closeEvent()
713 // purpose  :
714 //=================================================================================
715 void SMESHGUI_MergeNodesDlg::closeEvent (QCloseEvent*)
716 {
717   /* same than click on cancel button */
718   ClickOnCancel();
719 }
720
721 //=======================================================================
722 //function : hideEvent()
723 //purpose  : caused by ESC key
724 //=======================================================================
725 void SMESHGUI_MergeNodesDlg::hideEvent (QHideEvent*)
726 {
727   if (!isMinimized())
728     ClickOnCancel();
729 }
730
731 //=================================================================================
732 // function : keyPressEvent()
733 // purpose  :
734 //=================================================================================
735 void SMESHGUI_MergeNodesDlg::keyPressEvent( QKeyEvent* e )
736 {
737   QDialog::keyPressEvent( e );
738   if ( e->isAccepted() )
739     return;
740
741   if ( e->key() == Key_F1 )
742     {
743       e->accept();
744       ClickOnHelp();
745     }
746 }