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