Salome HOME
Merging with WPdev
[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                 QString platform;
389 #ifdef WIN32
390                 platform = "winapplication";
391 #else
392                 platform = "application";
393 #endif
394     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
395                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
396                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
397                            QObject::tr("BUT_OK"));
398   }
399 }
400
401 //=================================================================================
402 // function : onEditNodesGroup()
403 // purpose  :
404 //=================================================================================
405 void SMESHGUI_MergeNodesDlg::onEditNodesGroup()
406 {
407   if (ListCoincident->childCount() < 1)
408     return;
409
410   QString aNewIds = "";
411
412   QListBoxItem* anItem;
413   for (anItem = ListEdit->firstItem(); anItem != 0; anItem = anItem->next())
414     aNewIds+=QString(" %1").arg(anItem->text());
415
416   ListCoincident->currentItem()->setText(0, aNewIds);
417 }
418
419 //=================================================================================
420 // function : updateControls()
421 // purpose  :
422 //=================================================================================
423 void SMESHGUI_MergeNodesDlg::updateControls()
424 {
425   if (ListCoincident->childCount() < 1) {
426     SMESH::SetPointRepresentation(false);
427     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
428       aViewWindow->SetSelectionMode(ActorSelection);
429     return;
430   }
431
432   bool hasChecked = false, hasUnchecked = false;
433
434   QListViewItem* item = ListCoincident->firstChild();
435
436   while (item && (!hasChecked || !hasUnchecked)) {
437     if (((QCheckListItem*) item)->isOn())
438       hasChecked = true;
439     else
440       hasUnchecked = true;
441
442     item = item->itemBelow();
443   }
444
445   if (hasUnchecked)
446     SelectAllCB->setChecked(false);
447
448   bool enable = !(myMesh->_is_nil()) && hasChecked;
449
450   buttonOk->setEnabled(enable);
451   buttonApply->setEnabled(enable);
452 }
453
454 //=================================================================================
455 // function : onDetect()
456 // purpose  :
457 //=================================================================================
458 void SMESHGUI_MergeNodesDlg::onDetect()
459 {
460   if (myMesh->_is_nil())
461     return;
462
463   try {
464     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
465
466     QApplication::setOverrideCursor(Qt::waitCursor);
467     ListCoincident->clear();
468     ListEdit->clear();
469
470     SMESH::array_of_long_array_var aNodeGroups;
471     aMeshEditor->FindCoincidentNodes(SpinBoxTolerance->GetValue(), aNodeGroups);
472
473     for (int i = 0; i < aNodeGroups->length(); i++) {
474       SMESH::long_array& aGroup = aNodeGroups[i];
475
476       QString aNodeIds;
477       for (int j = 0; j < aGroup.length(); j++)
478         aNodeIds+=QString(" %1").arg(aGroup[j]);
479
480       new QCheckListItem (ListCoincident, aNodeIds, QCheckListItem::CheckBox);
481     }
482     QApplication::restoreOverrideCursor();
483   } catch(...) {
484   }
485
486   updateControls();
487 }
488
489 //=================================================================================
490 // function : onSelectNodesGroup()
491 // purpose  :
492 //=================================================================================
493 void SMESHGUI_MergeNodesDlg::onSelectNodesGroup()
494 {
495   if (!myActor)
496     return;
497
498   myEditCurrentArgument = (QWidget*)ListCoincident;
499
500   QListViewItem* aSelectedItem = ListCoincident->selectedItem();
501   if (!aSelectedItem)
502     return;
503
504   QStringList aListId = QStringList::split(" ", aSelectedItem->text(0), false);
505
506   ListEdit->clear();
507   ListEdit->insertStringList(aListId);
508
509   //mySelectionMgr->clearSelected();
510   //mySelectionMgr->AddIObject(myActor->getIO());
511   SALOME_ListIO aList;
512   aList.Append(myActor->getIO());
513   mySelectionMgr->setSelectedObjects(aList, false);
514
515   SMESH::SetPointRepresentation(true);
516   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
517     aViewWindow->SetSelectionMode(NodeSelection);
518
519   ListEdit->selectAll(true);
520 }
521
522 //=================================================================================
523 // function : onSelectAll()
524 // purpose  :
525 //=================================================================================
526 void SMESHGUI_MergeNodesDlg::onSelectAll (bool isToggled)
527 {
528   if (isToggled) {
529     int aNbItems = 0;
530     QListViewItem* item = ListCoincident->firstChild();
531     while (item) {
532       aNbItems++;
533       if (!((QCheckListItem*) item)->isOn())
534         ((QCheckListItem*) item)->setOn(true);
535       item = item->itemBelow();
536     }
537
538     if (aNbItems) {
539       buttonOk->setEnabled(true);
540       buttonApply->setEnabled(true);
541     }
542   }
543 }
544
545 //=================================================================================
546 // function : onSelectNodesFromGroup()
547 // purpose  :
548 //=================================================================================
549 void SMESHGUI_MergeNodesDlg::onSelectNodesFromGroup()
550 {
551   if (!myActor)
552     return;
553
554   TColStd_MapOfInteger aIndexes;
555   QListBoxItem* anItem;
556   for (anItem = ListEdit->firstItem(); anItem != 0; anItem = anItem->next()) {
557     if (anItem->isSelected()) {
558       int anId = anItem->text().toInt();
559       aIndexes.Add(anId);
560     }
561   }
562
563   mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
564   SALOME_ListIO aList;
565   aList.Append(myActor->getIO());
566   mySelectionMgr->setSelectedObjects(aList);
567 }
568
569 //=================================================================================
570 // function : onAdd()
571 // purpose  :
572 //=================================================================================
573 void SMESHGUI_MergeNodesDlg::onAdd()
574 {
575   if (!myActor)
576     return;
577
578   QString aListStr = "";
579   int aNbNnodes = 0;
580
581   aNbNnodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
582   if (aNbNnodes < 1)
583     return;
584
585   QStringList aNodes = QStringList::split(" ", aListStr);
586   QListBoxItem* anItem = 0;
587
588   for (QStringList::iterator it = aNodes.begin(); it != aNodes.end(); ++it) {
589     anItem = ListEdit->findItem(*it, Qt::ExactMatch);
590     if (!anItem) {
591       anItem = new QListBoxText(*it);
592       ListEdit->insertItem(anItem);
593     }
594     ListEdit->setSelected(anItem, true);
595   }
596
597   onEditNodesGroup();
598 }
599
600 //=================================================================================
601 // function : onRemove()
602 // purpose  :
603 //=================================================================================
604 void SMESHGUI_MergeNodesDlg::onRemove()
605 {
606   if (myEditCurrentArgument != (QWidget*)ListCoincident)
607     return;
608
609   for (int i = ListEdit->count(); i > 0; i--) {
610     if (ListEdit->isSelected(i-1))
611       ListEdit->removeItem(i-1);
612   }
613   onEditNodesGroup();
614 }
615
616 //=================================================================================
617 // function : SetEditCurrentArgument()
618 // purpose  :
619 //=================================================================================
620 void SMESHGUI_MergeNodesDlg::SetEditCurrentArgument()
621 {
622   QPushButton* send = (QPushButton*)sender();
623
624   disconnect(mySelectionMgr, 0, this, 0);
625   mySelectionMgr->clearSelected();
626   mySelectionMgr->clearFilters();
627
628   if (send == SelectMeshButton) {
629     myEditCurrentArgument = (QWidget*)LineEditMesh;
630     SMESH::SetPointRepresentation(false);
631     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
632       aViewWindow->SetSelectionMode(ActorSelection);
633     mySelectionMgr->installFilter(myMeshOrSubMeshFilter);
634   }
635
636   myEditCurrentArgument->setFocus();
637   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
638   SelectionIntoArgument();
639 }
640
641 //=================================================================================
642 // function : SelectionIntoArgument()
643 // purpose  : Called when selection as changed or other case
644 //=================================================================================
645 void SMESHGUI_MergeNodesDlg::SelectionIntoArgument()
646 {
647   if (myEditCurrentArgument == (QWidget*)LineEditMesh) {
648     QString aString = "";
649     LineEditMesh->setText(aString);
650
651     ListCoincident->clear();
652     ListEdit->clear();
653
654     int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
655     if (nbSel != 1)
656       return;
657
658     SALOME_ListIO aList;
659     mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
660
661     Handle(SALOME_InteractiveObject) IO = aList.First();
662     myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
663     myActor = SMESH::FindActorByEntry(aList.First()->getEntry());
664     if (myMesh->_is_nil() || !myActor)
665       return;
666
667     LineEditMesh->setText(aString);
668   }
669 }
670
671 //=================================================================================
672 // function : DeactivateActiveDialog()
673 // purpose  :
674 //=================================================================================
675 void SMESHGUI_MergeNodesDlg::DeactivateActiveDialog()
676 {
677   if (GroupConstructors->isEnabled()) {
678     GroupConstructors->setEnabled(false);
679     GroupMesh->setEnabled(false);
680     GroupCoincident->setEnabled(false);
681     GroupEdit->setEnabled(false);
682     GroupButtons->setEnabled(false);
683     mySMESHGUI->ResetState();
684     mySMESHGUI->SetActiveDialogBox(0);
685   }
686 }
687
688 //=================================================================================
689 // function : ActivateThisDialog()
690 // purpose  :
691 //=================================================================================
692 void SMESHGUI_MergeNodesDlg::ActivateThisDialog()
693 {
694   /* Emit a signal to deactivate the active dialog */
695   mySMESHGUI->EmitSignalDeactivateDialog();
696   GroupConstructors->setEnabled(true);
697   GroupMesh->setEnabled(true);
698   GroupCoincident->setEnabled(true);
699   GroupEdit->setEnabled(true);
700   GroupButtons->setEnabled(true);
701
702   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
703
704   SelectionIntoArgument();
705 }
706
707 //=================================================================================
708 // function : enterEvent()
709 // purpose  :
710 //=================================================================================
711 void SMESHGUI_MergeNodesDlg::enterEvent (QEvent*)
712 {
713   if (!GroupConstructors->isEnabled())
714     ActivateThisDialog();
715 }
716
717 //=================================================================================
718 // function : closeEvent()
719 // purpose  :
720 //=================================================================================
721 void SMESHGUI_MergeNodesDlg::closeEvent (QCloseEvent*)
722 {
723   /* same than click on cancel button */
724   ClickOnCancel();
725 }
726
727 //=======================================================================
728 //function : hideEvent()
729 //purpose  : caused by ESC key
730 //=======================================================================
731 void SMESHGUI_MergeNodesDlg::hideEvent (QHideEvent*)
732 {
733   if (!isMinimized())
734     ClickOnCancel();
735 }
736
737 //=================================================================================
738 // function : keyPressEvent()
739 // purpose  :
740 //=================================================================================
741 void SMESHGUI_MergeNodesDlg::keyPressEvent( QKeyEvent* e )
742 {
743   QDialog::keyPressEvent( e );
744   if ( e->isAccepted() )
745     return;
746
747   if ( e->key() == Key_F1 )
748     {
749       e->accept();
750       ClickOnHelp();
751     }
752 }