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