Salome HOME
[Bug PAL7444] display mesh takes a lot of more memory in 2.1.0 than in 2.0.0.
[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   myActor = 0;
231
232   mySelection = Sel;  
233   
234   mySMESHGUI  = SMESHGUI::GetSMESHGUI() ;
235   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
236   
237   myMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
238
239   /* signals and slots connections */
240   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
241   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
242   connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
243   
244   connect( SelectMeshButton, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) );
245   connect( DetectButton, SIGNAL ( clicked() ), this, SLOT( onDetect() ) );
246   connect( ListCoincident, SIGNAL ( selectionChanged() ), this, SLOT( onSelectNodesGroup() ) );
247   connect( ListCoincident, SIGNAL ( pressed( QListViewItem* ) ), this, SLOT( updateControls() ) );
248   connect( ListCoincident, SIGNAL ( currentChanged( QListViewItem* ) ), this, SLOT( updateControls() ) );
249   connect( SelectAllCB, SIGNAL( toggled(bool) ), this, SLOT(onSelectAll(bool) ) );
250   connect( ListEdit, SIGNAL ( selectionChanged() ), this, SLOT( onSelectNodesFromGroup() ) );
251   connect( AddButton, SIGNAL ( clicked() ), this, SLOT( onAdd() ) );
252   connect( RemoveButton, SIGNAL ( clicked() ), this, SLOT( onRemove() ) );
253
254   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
255   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
256   /* to close dialog if study change */
257   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
258   
259   /* Move widget on the botton right corner of main widget */
260   int x, y ;
261   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
262   this->move( x, y ) ;
263   this->show() ; /* displays Dialog */
264   
265   resize(0,0);
266   buttonOk->setEnabled(false);
267   buttonApply->setEnabled(false);
268 }
269
270 //=================================================================================
271 // function : ~SMESHGUI_MergeNodesDlg()
272 // purpose  : Destroys the object and frees any allocated resources
273 //=================================================================================
274 SMESHGUI_MergeNodesDlg::~SMESHGUI_MergeNodesDlg()
275 {
276   // no need to delete child widgets, Qt does it all for us
277 }
278
279
280 //=================================================================================
281 // function : ClickOnApply()
282 // purpose  :
283 //=================================================================================
284 bool SMESHGUI_MergeNodesDlg::ClickOnApply()
285 {
286   if (mySMESHGUI->ActiveStudyLocked() || myMesh->_is_nil())
287     return false;
288
289   try
290     {
291       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
292
293       QApplication::setOverrideCursor(Qt::waitCursor);
294       SMESH::array_of_long_array_var aGroupsOfNodes = new SMESH::array_of_long_array;
295       aGroupsOfNodes->length(ListCoincident->childCount());
296       QListViewItem* item = ListCoincident->firstChild();
297
298       int anArrayNum = 0;
299       while (item)
300         {
301           QStringList aListIds = QStringList("");
302           if (((QCheckListItem*) item)->isOn())
303             aListIds = QStringList::split( " ", item->text(0), false);
304           
305           SMESH::long_array_var anIds = new SMESH::long_array;
306           anIds->length(aListIds.count());
307           
308           for ( int i = 0; i < aListIds.count(); i++ )
309             anIds[i] = aListIds[i].toInt();
310           
311           aGroupsOfNodes[anArrayNum++] = anIds.inout();
312           
313           item = item->itemBelow();
314         }
315
316       aMeshEditor->MergeNodes (aGroupsOfNodes.inout());
317       QApplication::restoreOverrideCursor();
318     }
319   catch( ... )
320     {
321     }
322
323   mySelection->ClearIObjects();
324   SMESH::UpdateView();
325
326   onDetect();
327   return true;
328 }
329
330 //=================================================================================
331 // function : ClickOnOk()
332 // purpose  :
333 //=================================================================================
334 void SMESHGUI_MergeNodesDlg::ClickOnOk()
335 {
336   if( ClickOnApply())
337     ClickOnCancel() ;
338 }
339
340         
341 //=================================================================================
342 // function : ClickOnCancel()
343 // purpose  :
344 //=================================================================================
345 void SMESHGUI_MergeNodesDlg::ClickOnCancel()
346 {
347   mySelection->ClearFilters();
348   mySelection->ClearIObjects();
349   SMESH::SetPointRepresentation(false);
350   QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
351   disconnect( mySelection, 0, this, 0 );
352   mySMESHGUI->ResetState() ;
353   reject() ;
354 }
355
356
357 //=================================================================================
358 // function : onEditNodesGroup()
359 // purpose  :
360 //=================================================================================
361 void SMESHGUI_MergeNodesDlg::onEditNodesGroup()
362 {
363   if ( ListCoincident->childCount() < 1 )
364     return;
365
366   QString aNewIds = "";
367   
368   QListBoxItem* anItem;
369   for (anItem = ListEdit->firstItem(); anItem != 0; anItem = anItem->next())
370     aNewIds+=QString(" %1").arg(anItem->text());
371   
372   ListCoincident->currentItem()->setText(0, aNewIds);
373 }
374
375
376 //=================================================================================
377 // function : updateControls()
378 // purpose  : 
379 //=================================================================================
380 void SMESHGUI_MergeNodesDlg::updateControls()
381 {
382   if ( ListCoincident->childCount() < 1 )
383     {
384       SMESH::SetPointRepresentation(false);
385       QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
386       return;
387     }
388   
389   bool hasChecked = false, hasUnchecked = false;
390   
391   QListViewItem* item = ListCoincident->firstChild();
392   
393   while (item && (!hasChecked || !hasUnchecked))
394     {
395       if (((QCheckListItem*) item)->isOn())
396         hasChecked = true;
397       else
398         hasUnchecked = true;
399       
400       item = item->itemBelow();
401     }
402   
403   if (hasUnchecked)
404     SelectAllCB->setChecked(false);
405   
406   bool enable = !(myMesh->_is_nil()) && hasChecked;
407   
408   buttonOk->setEnabled(enable);
409   buttonApply->setEnabled(enable);
410 }
411
412
413 //=================================================================================
414 // function : onDetect()
415 // purpose  : 
416 //=================================================================================
417 void SMESHGUI_MergeNodesDlg::onDetect()
418 {
419   if(myMesh->_is_nil())
420     return;
421
422   try
423     {
424       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
425       
426       QApplication::setOverrideCursor(Qt::waitCursor);
427       ListCoincident->clear();
428       ListEdit->clear();
429       
430       SMESH::array_of_long_array_var aNodeGroups;
431       aMeshEditor->FindCoincidentNodes(SpinBoxTolerance->GetValue(), aNodeGroups);
432       
433       for ( int i = 0; i < aNodeGroups->length(); i++ )
434         {
435           SMESH::long_array& aGroup = aNodeGroups[i];
436           
437           QString aNodeIds;
438           for ( int j = 0; j < aGroup.length(); j++ )
439             aNodeIds+=QString(" %1").arg(aGroup[j]);
440           
441           new QCheckListItem ( ListCoincident, aNodeIds, QCheckListItem::CheckBox );
442         }
443       QApplication::restoreOverrideCursor();
444     }
445   catch( ... )
446     {
447     }
448   
449   updateControls();
450 }
451
452
453 //=================================================================================
454 // function : onSelectNodesGroup()
455 // purpose  : 
456 //=================================================================================
457 void SMESHGUI_MergeNodesDlg::onSelectNodesGroup()
458 {
459   if(!myActor)
460     return;
461   
462   myEditCurrentArgument = (QWidget*)ListCoincident;
463   
464   QListViewItem* aSelectedItem = ListCoincident->selectedItem();
465   if (!aSelectedItem)
466     return;
467   
468   QStringList aListId = QStringList::split( " ", aSelectedItem->text(0), false);
469   
470   ListEdit->clear();
471   ListEdit->insertStringList(aListId);
472   
473   mySelection->ClearIObjects();
474   mySelection->AddIObject( myActor->getIO() );
475   
476   SMESH::SetPointRepresentation(true);
477   QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
478     
479   ListEdit->selectAll(true);
480 }
481
482
483 //=================================================================================
484 // function : onSelectAll()
485 // purpose  : 
486 //=================================================================================
487 void SMESHGUI_MergeNodesDlg::onSelectAll(bool isToggled)
488 {
489   if (isToggled)
490     {
491       int aNbItems = 0;
492       QListViewItem* item = ListCoincident->firstChild();
493       while (item)
494         {
495           aNbItems++;
496           if (!((QCheckListItem*) item)->isOn())
497             ((QCheckListItem*) item)->setOn(true);
498           item = item->itemBelow();
499         }
500       
501       if (aNbItems)
502         {
503           buttonOk->setEnabled(true);
504           buttonApply->setEnabled(true);
505         }
506     }
507 }
508
509
510 //=================================================================================
511 // function : onSelectNodesFromGroup()
512 // purpose  : 
513 //=================================================================================
514 void SMESHGUI_MergeNodesDlg::onSelectNodesFromGroup()
515 {
516   if (!myActor) 
517     return;
518   
519   mySelection->ClearIObjects();
520   
521   TColStd_MapOfInteger aIndexes;
522   QListBoxItem* anItem;
523   for (anItem = ListEdit->firstItem(); anItem != 0; anItem = anItem->next()) {
524     if (anItem->isSelected()) {
525       int anId = anItem->text().toInt();
526       aIndexes.Add(anId);
527     }
528   }
529   mySelection->AddOrRemoveIndex(myActor->getIO(), aIndexes, false, false);
530   mySelection->AddIObject(myActor->getIO());
531 }
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(mySelection, 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 //=================================================================================
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     {
577       if (ListEdit->isSelected(i-1))
578         ListEdit->removeItem(i-1);
579     }
580   onEditNodesGroup();
581 }
582
583
584 //=================================================================================
585 // function : SetEditCurrentArgument()
586 // purpose  : 
587 //=================================================================================
588 void SMESHGUI_MergeNodesDlg::SetEditCurrentArgument()
589 {
590   QPushButton* send = (QPushButton*)sender();
591   
592   disconnect( mySelection, 0, this, 0 );
593   mySelection->ClearIObjects();
594   mySelection->ClearFilters();
595   
596   if(send == SelectMeshButton) 
597     {
598       myEditCurrentArgument = (QWidget*)LineEditMesh;
599       SMESH::SetPointRepresentation(false);
600       QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
601       mySelection->AddFilter(myMeshOrSubMeshFilter) ;
602     }
603   
604   myEditCurrentArgument->setFocus();
605   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
606   SelectionIntoArgument() ;
607 }
608
609
610 //=================================================================================
611 // function : SelectionIntoArgument()
612 // purpose  : Called when selection as changed or other case
613 //=================================================================================
614 void SMESHGUI_MergeNodesDlg::SelectionIntoArgument()
615 {
616   if (myEditCurrentArgument == (QWidget*)LineEditMesh)
617     {
618       QString aString = "";
619       LineEditMesh->setText( aString );
620       
621       ListCoincident->clear();
622       ListEdit->clear();
623
624       int nbSel = SMESH::GetNameOfSelectedIObjects(mySelection, aString);
625       if(nbSel != 1)
626         return;
627       
628       Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
629       myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO) ;
630       myActor = SMESH::FindActorByEntry( mySelection->firstIObject()->getEntry() );
631       if(myMesh->_is_nil() || !myActor)
632         return;
633       
634       LineEditMesh->setText( aString );
635     }
636 }
637
638
639 //=================================================================================
640 // function : DeactivateActiveDialog()
641 // purpose  :
642 //=================================================================================
643 void SMESHGUI_MergeNodesDlg::DeactivateActiveDialog()
644 {
645   if ( GroupConstructors->isEnabled() ) {
646     GroupConstructors->setEnabled(false) ;
647     GroupMesh->setEnabled(false);
648     GroupCoincident->setEnabled(false);
649     GroupEdit->setEnabled(false);
650     GroupButtons->setEnabled(false) ;
651     mySMESHGUI->ResetState() ;    
652     mySMESHGUI->SetActiveDialogBox(0) ;
653   }
654 }
655
656
657 //=================================================================================
658 // function : ActivateThisDialog()
659 // purpose  :
660 //=================================================================================
661 void SMESHGUI_MergeNodesDlg::ActivateThisDialog()
662 {
663   /* Emit a signal to deactivate the active dialog */
664   mySMESHGUI->EmitSignalDeactivateDialog() ;   
665   GroupConstructors->setEnabled(true) ;
666   GroupMesh->setEnabled(true);
667   GroupCoincident->setEnabled(true);
668   GroupEdit->setEnabled(true);
669   GroupButtons->setEnabled(true) ;
670   
671   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
672   
673   SelectionIntoArgument();
674 }
675
676
677 //=================================================================================
678 // function : enterEvent()
679 // purpose  :
680 //=================================================================================
681 void SMESHGUI_MergeNodesDlg::enterEvent(QEvent* e)
682 {
683   if ( GroupConstructors->isEnabled() )
684     return ;  
685   ActivateThisDialog() ;
686 }
687
688
689 //=================================================================================
690 // function : closeEvent()
691 // purpose  :
692 //=================================================================================
693 void SMESHGUI_MergeNodesDlg::closeEvent( QCloseEvent* e )
694 {
695   /* same than click on cancel button */
696   ClickOnCancel() ;
697 }
698
699
700 //=======================================================================
701 //function : hideEvent
702 //purpose  : caused by ESC key
703 //=======================================================================
704
705 void SMESHGUI_MergeNodesDlg::hideEvent ( QHideEvent * e )
706 {
707   if ( !isMinimized() )
708     ClickOnCancel();
709 }