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