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