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