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