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