Salome HOME
Merge from BR_PORTING_VTK6 01/03/2013
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MergeDlg.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_MergeDlg.cxx
25 // Author : Open CASCADE S.A.S.
26 // SMESH includes
27 //
28 #include "SMESHGUI_MergeDlg.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_SpinBox.h"
35
36 #include <SMESH_Actor.h>
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_LogicalFilter.hxx>
39 #include <SMDS_Mesh.hxx>
40
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_OverrideCursor.h>
47
48 #include <LightApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
50
51 #include <SVTK_ViewModel.h>
52 #include <SVTK_ViewWindow.h>
53 #include <SALOME_ListIO.hxx>
54
55 // OCCT includes
56 #include <TColStd_MapOfInteger.hxx>
57 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
58
59 // IDL includes
60 #include <SALOMEconfig.h>
61 #include CORBA_SERVER_HEADER(SMESH_Group)
62 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
63
64 // VTK includes
65 #include <vtkUnstructuredGrid.h>
66 #include <vtkRenderer.h>
67 #include <vtkActor2D.h>
68 #include <vtkPoints.h>
69 #include <vtkDataSetMapper.h>
70 #include <vtkMaskPoints.h>
71 #include <vtkSelectVisiblePoints.h>
72 #include <vtkLabeledDataMapper.h>
73 #include <vtkTextProperty.h>
74 #include <vtkIntArray.h>
75 #include <vtkProperty2D.h>
76 #include <vtkPointData.h>
77 #include <vtkConfigure.h>
78 #if !defined(VTK_XVERSION)
79 #define VTK_XVERSION (VTK_MAJOR_VERSION<<16)+(VTK_MINOR_VERSION<<8)+(VTK_BUILD_VERSION)
80 #endif
81
82 // Qt includes
83 #include <QApplication>
84 #include <QGroupBox>
85 #include <QLabel>
86 #include <QLineEdit>
87 #include <QListWidget>
88 #include <QPushButton>
89 #include <QRadioButton>
90 #include <QCheckBox>
91 #include <QHBoxLayout>
92 #include <QVBoxLayout>
93 #include <QGridLayout>
94 #include <QKeyEvent>
95 #include <QButtonGroup>
96
97 #define SPACING 6
98 #define MARGIN  11
99
100 namespace SMESH
101 {
102   class TIdPreview
103   { // to display in the viewer IDs of the selected elements
104     SVTK_ViewWindow* myViewWindow;
105
106     vtkUnstructuredGrid* myIdGrid;
107     SALOME_Actor* myIdActor;
108
109     vtkUnstructuredGrid* myPointsNumDataSet;
110     vtkMaskPoints* myPtsMaskPoints;
111     vtkSelectVisiblePoints* myPtsSelectVisiblePoints;
112     vtkLabeledDataMapper* myPtsLabeledDataMapper;
113     vtkTextProperty* aPtsTextProp;
114     bool myIsPointsLabeled;
115     vtkActor2D* myPointLabels;
116
117     std::vector<int> myIDs;
118
119   public:
120     TIdPreview(SVTK_ViewWindow* theViewWindow):
121       myViewWindow(theViewWindow)
122     {
123       myIdGrid = vtkUnstructuredGrid::New();
124
125       // Create and display actor
126       vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
127       aMapper->SetInputData( myIdGrid );
128
129       myIdActor = SALOME_Actor::New();
130       myIdActor->SetInfinitive(true);
131       myIdActor->VisibilityOff();
132       myIdActor->PickableOff();
133
134       myIdActor->SetMapper( aMapper );
135       aMapper->Delete();
136
137       myViewWindow->AddActor(myIdActor);
138
139       //Definition of points numbering pipeline
140       myPointsNumDataSet = vtkUnstructuredGrid::New();
141
142       myPtsMaskPoints = vtkMaskPoints::New();
143       myPtsMaskPoints->SetInputData(myPointsNumDataSet);
144       myPtsMaskPoints->SetOnRatio(1);
145
146       myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
147       myPtsSelectVisiblePoints->SetInputConnection(myPtsMaskPoints->GetOutputPort());
148       myPtsSelectVisiblePoints->SelectInvisibleOff();
149       myPtsSelectVisiblePoints->SetTolerance(0.1);
150     
151       myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
152       myPtsLabeledDataMapper->SetInputConnection(myPtsSelectVisiblePoints->GetOutputPort());
153 #if (VTK_XVERSION < 0x050200)
154       myPtsLabeledDataMapper->SetLabelFormat("%g");
155 #endif
156       myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
157     
158       vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
159       aPtsTextProp->SetFontFamilyToTimes();
160       static int aPointsFontSize = 12;
161       aPtsTextProp->SetFontSize(aPointsFontSize);
162       aPtsTextProp->SetBold(1);
163       aPtsTextProp->SetItalic(0);
164       aPtsTextProp->SetShadow(0);
165       myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
166       aPtsTextProp->Delete();
167   
168       myIsPointsLabeled = false;
169
170       myPointLabels = vtkActor2D::New();
171       myPointLabels->SetMapper(myPtsLabeledDataMapper);
172       myPointLabels->GetProperty()->SetColor(1,1,1);
173       myPointLabels->SetVisibility(myIsPointsLabeled);
174
175       AddToRender(myViewWindow->getRenderer());
176     }
177
178     void SetPointsData ( SMDS_Mesh* theMesh, 
179                          TColStd_MapOfInteger & theNodesIdMap )
180     {
181       vtkPoints* aPoints = vtkPoints::New();
182       aPoints->SetNumberOfPoints(theNodesIdMap.Extent());
183       myIDs.clear();
184       
185       TColStd_MapIteratorOfMapOfInteger idIter( theNodesIdMap );
186       for( int i = 0; idIter.More(); idIter.Next(), i++ ) {
187         const SMDS_MeshNode* aNode = theMesh->FindNode(idIter.Key());
188         aPoints->SetPoint( i, aNode->X(), aNode->Y(), aNode->Z() );
189         myIDs.push_back(idIter.Key());
190       }
191
192       myIdGrid->SetPoints(aPoints);
193
194       aPoints->Delete();
195
196       myIdActor->GetMapper()->Update();
197     }
198
199     void SetElemsData( TColStd_MapOfInteger & theElemsIdMap, 
200                        std::list<gp_XYZ> & aGrCentersXYZ )
201     {
202       vtkPoints* aPoints = vtkPoints::New();
203       aPoints->SetNumberOfPoints(theElemsIdMap.Extent());
204       myIDs.clear();
205       
206       TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
207       for( ; idIter.More(); idIter.Next() ) {
208         myIDs.push_back(idIter.Key());
209       }
210
211       gp_XYZ aXYZ;
212       std::list<gp_XYZ>::iterator coordIt = aGrCentersXYZ.begin();
213       for( int i = 0; coordIt != aGrCentersXYZ.end(); coordIt++, i++ ) {
214         aXYZ = *coordIt;
215         aPoints->SetPoint( i, aXYZ.X(), aXYZ.Y(), aXYZ.Z() );
216       }
217       myIdGrid->SetPoints(aPoints);
218       aPoints->Delete();
219       
220       myIdActor->GetMapper()->Update();
221     }
222
223     void AddToRender(vtkRenderer* theRenderer)
224     {
225       myIdActor->AddToRender(theRenderer);
226
227       myPtsSelectVisiblePoints->SetRenderer(theRenderer);
228       theRenderer->AddActor2D(myPointLabels);
229     }
230
231     void RemoveFromRender(vtkRenderer* theRenderer)
232     {
233       myIdActor->RemoveFromRender(theRenderer);
234
235       myPtsSelectVisiblePoints->SetRenderer(theRenderer);
236       theRenderer->RemoveActor(myPointLabels);
237     }
238
239     void SetPointsLabeled( bool theIsPointsLabeled, bool theIsActorVisible = true )
240     {
241       myIsPointsLabeled = theIsPointsLabeled && myIdGrid->GetNumberOfPoints();
242       
243       if ( myIsPointsLabeled ) {
244         myPointsNumDataSet->ShallowCopy(myIdGrid);
245         vtkDataSet *aDataSet = myPointsNumDataSet;
246         int aNbElem = myIDs.size();
247         vtkIntArray *anArray = vtkIntArray::New();
248         anArray->SetNumberOfValues( aNbElem );
249         for ( int i = 0; i < aNbElem; i++ )
250           anArray->SetValue( i, myIDs[i] );
251         aDataSet->GetPointData()->SetScalars( anArray );
252         anArray->Delete();
253         myPtsMaskPoints->SetInputData( aDataSet );
254         myPointLabels->SetVisibility( theIsActorVisible );
255       }
256       else {
257         myPointLabels->SetVisibility( false );
258       }
259     }
260     
261     ~TIdPreview()
262     {
263       RemoveFromRender(myViewWindow->getRenderer());
264
265       myIdGrid->Delete();
266
267       myViewWindow->RemoveActor(myIdActor);
268       myIdActor->Delete();
269
270       //Deleting of points numbering pipeline
271       //---------------------------------------
272       myPointsNumDataSet->Delete();
273       
274       //myPtsLabeledDataMapper->RemoveAllInputs();        //vtk 5.0 porting
275       myPtsLabeledDataMapper->Delete();
276
277       //myPtsSelectVisiblePoints->UnRegisterAllOutputs(); //vtk 5.0 porting
278       myPtsSelectVisiblePoints->Delete();
279
280       //myPtsMaskPoints->UnRegisterAllOutputs();          //vtk 5.0 porting
281       myPtsMaskPoints->Delete();
282
283       myPointLabels->Delete();
284
285 //       myTimeStamp->Delete();
286     }
287   };
288 }
289
290 static const char * IconFirst[] = {
291 "18 10 2 1",
292 "       g None",
293 ".      g #000000",
294 "         .     .  ",
295 "  ..    ..    ..  ",
296 "  ..   ...   ...  ",
297 "  ..  ....  ....  ",
298 "  .. ..... .....  ",
299 "  .. ..... .....  ",
300 "  ..  ....  ....  ",
301 "  ..   ...   ...  ",
302 "  ..    ..    ..  ",
303 "         .     .  "};
304
305 //=================================================================================
306 // class    : SMESHGUI_MergeDlg()
307 // purpose  :
308 //=================================================================================
309 SMESHGUI_MergeDlg::SMESHGUI_MergeDlg (SMESHGUI* theModule, int theAction)
310   : QDialog(SMESH::GetDesktop(theModule)),
311     mySMESHGUI(theModule),
312     mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
313     myAction(theAction)
314 {
315   setModal(false);
316   setAttribute(Qt::WA_DeleteOnClose, true);
317   setWindowTitle(myAction == 1 ? tr("SMESH_MERGE_ELEMENTS") : tr("SMESH_MERGE_NODES"));
318
319   myIdPreview = new SMESH::TIdPreview(SMESH::GetViewWindow( mySMESHGUI ));
320
321   SUIT_ResourceMgr* aResMgr = SMESH::GetResourceMgr( mySMESHGUI );
322   QPixmap IconMergeNodes (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_MERGE_NODES")));
323   QPixmap IconMergeElems (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_MERGE_ELEMENTS")));
324   QPixmap IconSelect     (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
325   QPixmap IconAdd        (aResMgr->loadPixmap("SMESH", tr("ICON_APPEND")));
326   QPixmap IconRemove     (aResMgr->loadPixmap("SMESH", tr("ICON_REMOVE")));
327
328   setSizeGripEnabled(true);
329
330   QVBoxLayout* DlgLayout = new QVBoxLayout(this);
331   DlgLayout->setSpacing(SPACING);
332   DlgLayout->setMargin(MARGIN);
333
334   /***************************************************************/
335   GroupConstructors = new QGroupBox(myAction == 1 ? 
336                                     tr("SMESH_MERGE_ELEMENTS") : 
337                                     tr("SMESH_MERGE_NODES"), 
338                                     this);
339
340   QButtonGroup* ButtonGroup = new QButtonGroup(this);
341   QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
342   GroupConstructorsLayout->setSpacing(SPACING);
343   GroupConstructorsLayout->setMargin(MARGIN);
344
345   RadioButton = new QRadioButton(GroupConstructors);
346   RadioButton->setIcon(myAction == 1 ? IconMergeElems : IconMergeNodes);
347   RadioButton->setChecked(true);
348   GroupConstructorsLayout->addWidget(RadioButton);
349   ButtonGroup->addButton(RadioButton, 0);
350
351   /***************************************************************/
352   // Controls for mesh defining
353   GroupMesh = new QGroupBox(tr("SMESH_SELECT_WHOLE_MESH"), this);
354   QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
355   GroupMeshLayout->setSpacing(SPACING);
356   GroupMeshLayout->setMargin(MARGIN);
357
358   TextLabelName = new QLabel(tr("SMESH_NAME"), GroupMesh);
359   SelectMeshButton = new QPushButton(GroupMesh);
360   SelectMeshButton->setIcon(IconSelect);
361   LineEditMesh = new QLineEdit(GroupMesh);
362   LineEditMesh->setReadOnly(true);
363
364   GroupMeshLayout->addWidget(TextLabelName);
365   GroupMeshLayout->addWidget(SelectMeshButton);
366   GroupMeshLayout->addWidget(LineEditMesh);
367
368   /***************************************************************/
369   // Controls for switch dialog behaviour
370
371   TypeBox = new QGroupBox( tr( "SMESH_MODE" ), this );
372   GroupType = new QButtonGroup( this );
373   QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( TypeBox );
374   aTypeBoxLayout->setMargin( MARGIN );
375   aTypeBoxLayout->setSpacing( SPACING );
376
377   QRadioButton* rb1 = new QRadioButton( tr( "SMESH_AUTOMATIC" ), TypeBox );
378   QRadioButton* rb2 = new QRadioButton( tr( "SMESH_MANUAL" ),   TypeBox );
379   GroupType->addButton( rb1, 0 );
380   GroupType->addButton( rb2, 1 );
381   aTypeBoxLayout->addWidget( rb1 );
382   aTypeBoxLayout->addWidget( rb2 );
383
384   myTypeId = 0;
385
386   /***************************************************************/
387   // Controls for coincident elements detecting
388   GroupCoincident = new QGroupBox(myAction == 1 ? 
389                                   tr("COINCIDENT_ELEMENTS") : 
390                                   tr("COINCIDENT_NODES"), 
391                                   this);
392
393   QVBoxLayout* aCoincidentLayout = new QVBoxLayout(GroupCoincident);
394   aCoincidentLayout->setSpacing(SPACING);
395   aCoincidentLayout->setMargin(MARGIN);
396
397   if (myAction == 0) { // case merge nodes
398     QWidget* foo = new QWidget(GroupCoincident);
399     TextLabelTolerance = new QLabel(tr("SMESH_TOLERANCE"), foo);
400     SpinBoxTolerance = new SMESHGUI_SpinBox(foo);
401     SpinBoxTolerance->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
402
403     GroupExclude = new QGroupBox(tr("EXCLUDE_GROUPS"), foo);
404     GroupExclude->setCheckable( true );
405     GroupExclude->setChecked( false );
406     ListExclude = new QListWidget( GroupExclude );
407     QVBoxLayout* GroupExcludeLayout = new QVBoxLayout(GroupExclude);
408     GroupExcludeLayout->setSpacing(SPACING);
409     GroupExcludeLayout->setMargin(MARGIN);
410     GroupExcludeLayout->addWidget(ListExclude);
411
412     QGridLayout* fooLayout = new QGridLayout( foo );
413     fooLayout->setSpacing(SPACING);
414     fooLayout->setMargin(0);
415     fooLayout->addWidget(TextLabelTolerance, 0, 0 );
416     fooLayout->addWidget(SpinBoxTolerance,   0, 1 );
417     fooLayout->addWidget(GroupExclude,       1, 0, 1, 2 );
418     aCoincidentLayout->addWidget(foo);
419   }
420   else {
421     TextLabelTolerance = 0;
422     SpinBoxTolerance = 0;
423     GroupExclude = 0;
424     ListExclude = 0;
425   }
426
427   GroupCoincidentWidget = new QWidget(GroupCoincident);
428   QGridLayout* GroupCoincidentLayout = new QGridLayout(GroupCoincidentWidget);
429   GroupCoincidentLayout->setSpacing(SPACING);
430   GroupCoincidentLayout->setMargin(0);
431
432   ListCoincident = new QListWidget(GroupCoincidentWidget);
433   ListCoincident->setSelectionMode(QListWidget::ExtendedSelection);
434
435   DetectButton      = new QPushButton(tr("DETECT"),           GroupCoincidentWidget);
436   AddGroupButton    = new QPushButton(tr("SMESH_BUT_ADD"),    GroupCoincidentWidget);
437   RemoveGroupButton = new QPushButton(tr("SMESH_BUT_REMOVE"), GroupCoincidentWidget);
438
439   SelectAllCB = new QCheckBox(tr("SELECT_ALL"), GroupCoincidentWidget);
440
441   GroupCoincidentLayout->addWidget(ListCoincident,    0,   0, 4, 2);
442   GroupCoincidentLayout->addWidget(DetectButton,      0,   2);
443   GroupCoincidentLayout->addWidget(AddGroupButton,    2, 2);
444   GroupCoincidentLayout->addWidget(RemoveGroupButton, 3, 2);
445   GroupCoincidentLayout->addWidget(SelectAllCB,       4, 0, 1, 3);
446   GroupCoincidentLayout->setRowMinimumHeight(1, 10);
447   GroupCoincidentLayout->setRowStretch(1, 5);
448
449   aCoincidentLayout->addWidget(GroupCoincidentWidget);
450
451   /***************************************************************/
452   // Controls for editing the selected group
453   GroupEdit = new QGroupBox(tr("EDIT_SELECTED_GROUP"), this);
454   QGridLayout* GroupEditLayout = new QGridLayout(GroupEdit);
455   GroupEditLayout->setSpacing(SPACING);
456   GroupEditLayout->setMargin(MARGIN);
457
458   ListEdit = new QListWidget(GroupEdit);
459   //ListEdit->setRowMode(QListBox::FixedNumber);
460   //ListEdit->setHScrollBarMode(QScrollView::AlwaysOn);
461   //ListEdit->setVScrollBarMode(QScrollView::AlwaysOff);
462   ListEdit->setFlow( QListView::LeftToRight );
463   ListEdit->setSelectionMode(QListWidget::ExtendedSelection);
464
465   AddElemButton = new QPushButton(GroupEdit);
466   AddElemButton->setIcon(IconAdd);
467   RemoveElemButton = new QPushButton(GroupEdit);
468   RemoveElemButton->setIcon(IconRemove);
469   SetFirstButton = new QPushButton(GroupEdit);
470   SetFirstButton->setIcon(QPixmap(IconFirst));
471
472   GroupEditLayout->addWidget(ListEdit,         0, 0, 2, 1);
473   GroupEditLayout->addWidget(AddElemButton,    0, 1);
474   GroupEditLayout->addWidget(RemoveElemButton, 0, 2);
475   GroupEditLayout->addWidget(SetFirstButton,   1, 1, 1, 2);
476
477   /***************************************************************/
478   GroupButtons = new QGroupBox(this);
479   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
480   GroupButtonsLayout->setSpacing(SPACING);
481   GroupButtonsLayout->setMargin(MARGIN);
482
483   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
484   buttonOk->setAutoDefault(true);
485   buttonOk->setDefault(true);
486   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
487   buttonApply->setAutoDefault(true);
488   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
489   buttonCancel->setAutoDefault(true);
490   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
491   buttonHelp->setAutoDefault(true);
492
493   GroupButtonsLayout->addWidget(buttonOk);
494   GroupButtonsLayout->addSpacing(10);
495   GroupButtonsLayout->addWidget(buttonApply);
496   GroupButtonsLayout->addSpacing(10);
497   GroupButtonsLayout->addStretch();
498   GroupButtonsLayout->addWidget(buttonCancel);
499   GroupButtonsLayout->addWidget(buttonHelp);
500
501   /***************************************************************/
502   DlgLayout->addWidget(GroupConstructors);
503   DlgLayout->addWidget(GroupMesh);
504   DlgLayout->addWidget(TypeBox);
505   DlgLayout->addWidget(GroupCoincident);
506   DlgLayout->addWidget(GroupEdit);
507   DlgLayout->addWidget(GroupButtons);
508
509   GroupCoincidentWidget->setVisible( myAction != 0 );
510   GroupCoincident->setVisible( myAction == 0 );
511   //if GroupExclude->setVisible( myAction == 0 );
512   GroupEdit->hide();
513
514   this->resize(10,10);
515
516   Init(); // Initialisations
517 }
518
519 //=================================================================================
520 // function : ~SMESHGUI_MergeDlg()
521 // purpose  : Destroys the object and frees any allocated resources
522 //=================================================================================
523 SMESHGUI_MergeDlg::~SMESHGUI_MergeDlg()
524 {
525   delete myIdPreview;
526 }
527
528 //=================================================================================
529 // function : Init()
530 // purpose  :
531 //=================================================================================
532 void SMESHGUI_MergeDlg::Init()
533 {
534   if (myAction == 0) {
535     SpinBoxTolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, "len_tol_precision");
536     SpinBoxTolerance->SetValue(1e-05);
537   }
538
539   RadioButton->setChecked(true);
540
541   GroupType->button(0)->setChecked(true);
542
543   myEditCurrentArgument = (QWidget*)LineEditMesh; 
544
545   myActor = 0;
546   mySubMeshOrGroup = SMESH::SMESH_subMesh::_nil();
547
548   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
549
550   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
551   myIsBusy = false;
552   
553   /* signals and slots connections */
554   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
555   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
556   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
557   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
558
559   connect(SelectMeshButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
560   connect(DetectButton, SIGNAL (clicked()), this, SLOT(onDetect()));
561   connect(ListCoincident, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectGroup()));
562   connect(AddGroupButton, SIGNAL (clicked()), this, SLOT(onAddGroup()));
563   connect(RemoveGroupButton, SIGNAL (clicked()), this, SLOT(onRemoveGroup()));
564   connect(SelectAllCB, SIGNAL(toggled(bool)), this, SLOT(onSelectAll(bool)));
565   connect(ListEdit, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectElementFromGroup()));
566   connect(AddElemButton, SIGNAL (clicked()), this, SLOT(onAddElement()));
567   connect(RemoveElemButton, SIGNAL (clicked()), this, SLOT(onRemoveElement()));
568   connect(SetFirstButton, SIGNAL( clicked() ), this, SLOT( onSetFirst() ) );
569   connect(GroupType, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
570
571   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
572   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
573   /* to close dialog if study change */
574   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
575
576   // Init Mesh field from selection
577   SelectionIntoArgument();
578
579   // Update Buttons
580   updateControls();
581   
582   if (myAction == 0)
583     myHelpFileName = "merging_nodes_page.html";
584   else
585     myHelpFileName = "merging_elements_page.html";
586 }
587
588 //=================================================================================
589 // function : FindGravityCenter()
590 // purpose  :
591 //=================================================================================
592 void SMESHGUI_MergeDlg::FindGravityCenter(TColStd_MapOfInteger & theElemsIdMap, 
593                                           std::list< gp_XYZ > & theGrCentersXYZ)
594 {
595   if (!myActor)
596     return;
597
598   SMDS_Mesh* aMesh = 0;
599   aMesh = myActor->GetObject()->GetMesh();
600   if (!aMesh)
601     return;
602
603   int nbNodes;
604
605   TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
606   for( ; idIter.More(); idIter.Next() ) {
607     const SMDS_MeshElement* anElem = aMesh->FindElement(idIter.Key());
608     if ( !anElem )
609       continue;
610
611     gp_XYZ anXYZ(0., 0., 0.);
612     SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
613     for ( nbNodes = 0; nodeIt->more(); nbNodes++ ) {
614       const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
615       anXYZ.Add( gp_XYZ( node->X(), node->Y(), node->Z() ) );
616     }
617     anXYZ.Divide( nbNodes );
618     
619     theGrCentersXYZ.push_back( anXYZ );
620   }
621 }
622
623 //=================================================================================
624 // function : ClickOnApply()
625 // purpose  :
626 //=================================================================================
627 bool SMESHGUI_MergeDlg::ClickOnApply()
628 {
629   if (mySMESHGUI->isActiveStudyLocked() || myMesh->_is_nil())
630     return false;
631
632   try {
633     if (myTypeId == 0)
634       onDetect();
635
636     SUIT_OverrideCursor aWaitCursor;
637     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
638
639     SMESH::long_array_var anIds = new SMESH::long_array;
640     SMESH::array_of_long_array_var aGroupsOfElements = new SMESH::array_of_long_array;
641
642     if ( ListCoincident->count() == 0) {
643       if (myAction == 0)
644         SUIT_MessageBox::warning(this,
645                                  tr("SMESH_WARNING"),
646                                  tr("SMESH_NO_NODES_DETECTED"));
647       else
648         SUIT_MessageBox::warning(this,
649                                  tr("SMESH_WARNING"),
650                                  tr("SMESH_NO_ELEMENTS_DETECTED"));
651       return false;
652     }
653
654     aGroupsOfElements->length(ListCoincident->count());
655
656     int anArrayNum = 0;
657     for (int i = 0; i < ListCoincident->count(); i++) {
658       QStringList aListIds = ListCoincident->item(i)->text().split(" ", QString::SkipEmptyParts);
659
660       anIds->length(aListIds.count());
661       for (int i = 0; i < aListIds.count(); i++)
662         anIds[i] = aListIds[i].toInt();
663
664       aGroupsOfElements[anArrayNum++] = anIds.inout();
665     }
666
667     if( myAction == 0 )
668       aMeshEditor->MergeNodes (aGroupsOfElements.inout());
669     else
670       aMeshEditor->MergeElements (aGroupsOfElements.inout());
671
672     if ( myTypeId == 0 ) {
673       if (myAction == 0 )
674         SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
675                                      tr("SMESH_MERGED_NODES").arg(QString::number(ListCoincident->count()).toLatin1().data()));
676       else
677         SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
678                                      tr("SMESH_MERGED_ELEMENTS").arg(QString::number(ListCoincident->count()).toLatin1().data()));
679     }
680       
681
682   } catch(...) {
683   }
684   
685   ListCoincident->clear();
686   
687   SMESH::UpdateView();
688   SMESHGUI::Modified();
689   
690   return true;
691 }
692
693 //=================================================================================
694 // function : ClickOnOk()
695 // purpose  :
696 //=================================================================================
697 void SMESHGUI_MergeDlg::ClickOnOk()
698 {
699   if (ClickOnApply())
700     reject();
701 }
702
703 //=================================================================================
704 // function : reject()
705 // purpose  :
706 //=================================================================================
707 void SMESHGUI_MergeDlg::reject()
708 {
709   myIdPreview->SetPointsLabeled(false);
710   SMESH::SetPointRepresentation(false);
711   disconnect(mySelectionMgr, 0, this, 0);
712   disconnect(mySMESHGUI, 0, this, 0);
713   mySMESHGUI->ResetState();
714
715   mySelectionMgr->clearFilters();
716   //mySelectionMgr->clearSelected();
717
718   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
719     aViewWindow->SetSelectionMode(ActorSelection);
720
721   QDialog::reject();
722 }
723
724 //=================================================================================
725 // function : ClickOnHelp()
726 // purpose  :
727 //=================================================================================
728 void SMESHGUI_MergeDlg::ClickOnHelp()
729 {
730   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
731   if (app) 
732     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
733   else {
734     QString platform;
735 #ifdef WIN32
736     platform = "winapplication";
737 #else
738     platform = "application";
739 #endif
740     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
741                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
742                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
743                                                                  platform)).
744                              arg(myHelpFileName));
745   }
746 }
747
748 //=================================================================================
749 // function : onEditGroup()
750 // purpose  :
751 //=================================================================================
752 void SMESHGUI_MergeDlg::onEditGroup()
753 {
754   QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
755   if ( selItems.count() != 1 ) {
756     ListEdit->clear();
757     return;
758   }
759
760   QStringList aNewIds;
761
762   for (int i = 0; i < ListEdit->count(); i++ )
763     aNewIds.append(ListEdit->item(i)->text());
764
765   ListCoincident->clearSelection();
766   selItems.first()->setText(aNewIds.join(" "));
767   selItems.first()->setSelected(true);
768 }
769
770 //=================================================================================
771 // function : updateControls()
772 // purpose  :
773 //=================================================================================
774 void SMESHGUI_MergeDlg::updateControls()
775 {
776   if (ListEdit->count() == 0)
777     SetFirstButton->setEnabled(false);
778   bool enable = !(myMesh->_is_nil()) && (ListCoincident->count() || (myTypeId == 0));
779   buttonOk->setEnabled(enable);
780   buttonApply->setEnabled(enable);
781 }
782
783 //=================================================================================
784 // function : onDetect()
785 // purpose  :
786 //=================================================================================
787 void SMESHGUI_MergeDlg::onDetect()
788 {
789   if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
790     return;
791
792   try {
793     SUIT_OverrideCursor aWaitCursor;
794     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
795
796     ListCoincident->clear();
797     ListEdit->clear();
798
799     SMESH::array_of_long_array_var aGroupsArray;
800     SMESH::ListOfIDSources_var aExcludeGroups = new SMESH::ListOfIDSources;
801
802     SMESH::SMESH_IDSource_var src;
803     if ( mySubMeshOrGroup->_is_nil() ) src = SMESH::SMESH_IDSource::_duplicate( myMesh );
804     else src = SMESH::SMESH_IDSource::_duplicate( mySubMeshOrGroup );
805
806     switch (myAction) {
807     case 0 :
808       for ( int i = 0; GroupExclude->isChecked() && i < ListExclude->count(); i++ ) {
809         if ( ListExclude->item( i )->checkState() == Qt::Checked ) {
810           aExcludeGroups->length( aExcludeGroups->length()+1 );
811           aExcludeGroups[ aExcludeGroups->length()-1 ] = SMESH::SMESH_IDSource::_duplicate( myGroups[i] );
812         }
813       }
814       aMeshEditor->FindCoincidentNodesOnPartBut(src.in(),
815                                                 SpinBoxTolerance->GetValue(), 
816                                                 aGroupsArray.out(),
817                                                 aExcludeGroups.in());
818       break;
819     case 1 :
820       aMeshEditor->FindEqualElements(src.in(), aGroupsArray.out());
821       break;
822     }
823     
824     for (int i = 0; i < aGroupsArray->length(); i++) {
825       SMESH::long_array& aGroup = aGroupsArray[i];
826
827       QStringList anIDs;
828       for (int j = 0; j < aGroup.length(); j++)
829         anIDs.append(QString::number(aGroup[j]));
830
831       ListCoincident->addItem(anIDs.join(" "));
832     }
833    } catch(...) {
834   }
835
836   ListCoincident->selectAll();
837   updateControls();
838 }
839
840 //=================================================================================
841 // function : onSelectGroup()
842 // purpose  :
843 //=================================================================================
844 void SMESHGUI_MergeDlg::onSelectGroup()
845 {
846   if (myIsBusy || !myActor)
847     return;
848   myEditCurrentArgument = (QWidget*)ListCoincident;
849
850   ListEdit->clear();
851   
852   TColStd_MapOfInteger anIndices;
853   QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
854   QListWidgetItem* anItem;
855   QStringList aListIds;
856
857   ListEdit->clear();
858
859   foreach(anItem, selItems) {
860     aListIds = anItem->text().split(" ", QString::SkipEmptyParts);
861     for (int i = 0; i < aListIds.count(); i++)
862       anIndices.Add(aListIds[i].toInt());
863   }
864   
865   if (selItems.count() == 1) {
866     ListEdit->addItems(aListIds);
867     ListEdit->selectAll();
868   }
869
870   mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
871   SALOME_ListIO aList;
872   aList.Append(myActor->getIO());
873   mySelectionMgr->setSelectedObjects(aList,false);
874   
875   if (myAction == 0) {
876     myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
877     myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
878   }
879   else {
880     std::list< gp_XYZ > aGrCentersXYZ;
881     FindGravityCenter(anIndices, aGrCentersXYZ);
882     myIdPreview->SetElemsData( anIndices, aGrCentersXYZ);
883     myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
884   }
885
886   updateControls();
887 }
888
889 //=================================================================================
890 // function : onSelectAll()
891 // purpose  :
892 //=================================================================================
893 void SMESHGUI_MergeDlg::onSelectAll (bool isToggled)
894 {
895   if ( isToggled )
896     ListCoincident->selectAll();
897   else
898     ListCoincident->clearSelection();
899 }
900
901 //=================================================================================
902 // function : onSelectElementFromGroup()
903 // purpose  :
904 //=================================================================================
905 void SMESHGUI_MergeDlg::onSelectElementFromGroup()
906 {
907   if (myIsBusy || !myActor)
908     return;
909
910   TColStd_MapOfInteger anIndices;
911   QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
912   QListWidgetItem* anItem;
913
914   foreach(anItem, selItems)
915     anIndices.Add(anItem->text().toInt());
916
917   SetFirstButton->setEnabled(selItems.count() == 1);
918
919   mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
920   SALOME_ListIO aList;
921   aList.Append(myActor->getIO());
922   mySelectionMgr->setSelectedObjects(aList);
923
924   if (myAction == 0) {
925     myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
926     myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
927   }
928   else {
929     std::list< gp_XYZ > aGrCentersXYZ;
930     FindGravityCenter(anIndices, aGrCentersXYZ);
931     myIdPreview->SetElemsData(anIndices, aGrCentersXYZ);
932     myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
933   }
934 }
935
936 //=================================================================================
937 // function : onAddGroup()
938 // purpose  :
939 //=================================================================================
940 void SMESHGUI_MergeDlg::onAddGroup()
941 {
942   if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
943     return;
944
945   QString anIDs = "";
946   int aNbElements = 0;
947   aNbElements = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
948
949   if (aNbElements < 1)
950     return;
951   
952   ListCoincident->clearSelection();
953   ListCoincident->addItem(anIDs);
954   int nbGroups = ListCoincident->count();
955   if (nbGroups) {
956     ListCoincident->setCurrentRow(nbGroups-1);
957     ListCoincident->item(nbGroups-1)->setSelected(true);
958   }
959   else {
960     // VSR ? this code seems to be never executed!!!
961     ListCoincident->setCurrentRow(0);
962     //ListCoincident->setSelected(0, true); // VSR: no items - no selection
963   }
964
965   updateControls();
966 }
967
968 //=================================================================================
969 // function : onRemoveGroup()
970 // purpose  :
971 //=================================================================================
972 void SMESHGUI_MergeDlg::onRemoveGroup()
973 {
974   if (myEditCurrentArgument != (QWidget*)ListCoincident)
975     return;
976   myIsBusy = true;
977
978   QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
979   QListWidgetItem* anItem;
980
981   foreach(anItem, selItems)
982     delete anItem;
983
984   ListEdit->clear();
985   updateControls();
986
987   myIsBusy = false;
988 }
989
990 //=================================================================================
991 // function : onAddElement()
992 // purpose  :
993 //=================================================================================
994 void SMESHGUI_MergeDlg::onAddElement()
995 {
996   if (!myActor)
997     return;
998   myIsBusy = true;
999
1000   QString aListStr = "";
1001   int aNbNnodes = 0;
1002
1003   aNbNnodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1004   if (aNbNnodes < 1)
1005     return;
1006
1007   QStringList aNodes = aListStr.split(" ", QString::SkipEmptyParts);
1008
1009   for (QStringList::iterator it = aNodes.begin(); it != aNodes.end(); ++it) {
1010     QList<QListWidgetItem*> found = ListEdit->findItems(*it, Qt::MatchExactly);
1011     if ( found.count() == 0 ) {
1012       QListWidgetItem* anItem = new QListWidgetItem(*it);
1013       ListEdit->addItem(anItem);
1014       anItem->setSelected(true);
1015     }
1016     else {
1017       QListWidgetItem* anItem;
1018       foreach(anItem, found) anItem->setSelected(true);
1019     }
1020   }
1021
1022   myIsBusy = false;
1023   onEditGroup();
1024 }
1025
1026 //=================================================================================
1027 // function : onRemoveElement()
1028 // purpose  :
1029 //=================================================================================
1030 void SMESHGUI_MergeDlg::onRemoveElement()
1031 {
1032   if (myEditCurrentArgument != (QWidget*)ListCoincident)
1033     return;
1034   myIsBusy = true;
1035
1036   QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
1037   QListWidgetItem* anItem;
1038
1039   foreach(anItem, selItems)
1040     delete anItem;
1041   
1042   myIsBusy = false;
1043   onEditGroup();
1044 }
1045
1046 //=================================================================================
1047 // function : onSetFirst()
1048 // purpose  :
1049 //=================================================================================
1050 void SMESHGUI_MergeDlg::onSetFirst()
1051 {
1052   if (myEditCurrentArgument != (QWidget*)ListCoincident)
1053     return;
1054   myIsBusy = true;
1055   
1056   QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
1057   QListWidgetItem* anItem;
1058   
1059   foreach(anItem, selItems) {
1060     ListEdit->takeItem(ListEdit->row(anItem));
1061     ListEdit->insertItem(0, anItem);
1062   }
1063
1064   myIsBusy = false;
1065   onEditGroup();
1066 }
1067
1068 //=================================================================================
1069 // function : SetEditCurrentArgument()
1070 // purpose  :
1071 //=================================================================================
1072 void SMESHGUI_MergeDlg::SetEditCurrentArgument()
1073 {
1074   QPushButton* send = (QPushButton*)sender();
1075
1076   disconnect(mySelectionMgr, 0, this, 0);
1077   mySelectionMgr->clearSelected();
1078   mySelectionMgr->clearFilters();
1079
1080   if (send == SelectMeshButton) {
1081     myEditCurrentArgument = (QWidget*)LineEditMesh;
1082     SMESH::SetPointRepresentation(false);
1083     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1084       aViewWindow->SetSelectionMode(ActorSelection);
1085     if (myTypeId == 1)
1086       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1087   }
1088
1089   myEditCurrentArgument->setFocus();
1090   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1091   SelectionIntoArgument();
1092 }
1093
1094 //=================================================================================
1095 // function : SelectionIntoArgument()
1096 // purpose  : Called when selection as changed or other case
1097 //=================================================================================
1098 void SMESHGUI_MergeDlg::SelectionIntoArgument()
1099 {
1100   if (myEditCurrentArgument == (QWidget*)LineEditMesh) {
1101     QString aString = "";
1102     LineEditMesh->setText(aString);
1103     
1104     ListCoincident->clear();
1105     ListEdit->clear();
1106     myActor = 0;
1107     QString aCurrentEntry = myEntry;
1108     
1109     int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
1110     if (nbSel != 1) {
1111       myIdPreview->SetPointsLabeled(false);
1112       SMESH::SetPointRepresentation(false);
1113       mySelectionMgr->clearFilters();
1114       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1115         aViewWindow->SetSelectionMode(ActorSelection);
1116       return;
1117     }
1118
1119     SALOME_ListIO aList;
1120     mySelectionMgr->selectedObjects(aList);
1121     
1122     Handle(SALOME_InteractiveObject) IO = aList.First();
1123     myEntry = IO->getEntry();
1124     myMesh = SMESH::GetMeshByIO(IO);
1125     
1126     if (myMesh->_is_nil())
1127       return;
1128
1129     LineEditMesh->setText(aString);
1130     
1131     myActor = SMESH::FindActorByEntry(IO->getEntry());
1132     if (!myActor)
1133       myActor = SMESH::FindActorByObject(myMesh);
1134     
1135     if ( myActor && myTypeId ==1 ) {
1136       mySubMeshOrGroup = SMESH::SMESH_IDSource::_nil();
1137       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1138       
1139       if ((!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil() || //SUBMESH OR GROUP
1140            !SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) &&
1141           !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
1142         mySubMeshOrGroup = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
1143       
1144       if (myAction == 0) {
1145         SMESH::SetPointRepresentation(true);
1146         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1147           aViewWindow->SetSelectionMode(NodeSelection);
1148       }
1149       else
1150         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1151           aViewWindow->SetSelectionMode(CellSelection);
1152     }
1153
1154     // process groups
1155     if ( myAction == 0 && !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
1156       myGroups.clear();
1157       ListExclude->clear();
1158       SMESH::ListOfGroups_var aListOfGroups = myMesh->GetGroups();
1159       for( int i = 0, n = aListOfGroups->length(); i < n; i++ ) {
1160         SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
1161         if ( !aGroup->_is_nil() ) { // && aGroup->GetType() == SMESH::NODE
1162           QString aGroupName( aGroup->GetName() );
1163           if ( !aGroupName.isEmpty() ) {
1164             myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
1165             QListWidgetItem* item = new QListWidgetItem( aGroupName );
1166             item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
1167             item->setCheckState( Qt::Unchecked );
1168             ListExclude->addItem( item );
1169           }
1170         }
1171       }
1172     }
1173
1174     updateControls();
1175   }
1176 }
1177
1178 //=================================================================================
1179 // function : DeactivateActiveDialog()
1180 // purpose  :
1181 //=================================================================================
1182 void SMESHGUI_MergeDlg::DeactivateActiveDialog()
1183 {
1184   if (GroupConstructors->isEnabled()) {
1185     GroupConstructors->setEnabled(false);
1186     TypeBox->setEnabled(false);
1187     GroupMesh->setEnabled(false);
1188     GroupCoincident->setEnabled(false);
1189     GroupEdit->setEnabled(false);
1190     GroupButtons->setEnabled(false);
1191     mySMESHGUI->ResetState();
1192     mySMESHGUI->SetActiveDialogBox(0);
1193   }
1194
1195   mySelectionMgr->clearSelected();
1196   disconnect(mySelectionMgr, 0, this, 0);
1197 }
1198
1199 //=================================================================================
1200 // function : ActivateThisDialog()
1201 // purpose  :
1202 //=================================================================================
1203 void SMESHGUI_MergeDlg::ActivateThisDialog()
1204 {
1205   /* Emit a signal to deactivate the active dialog */
1206   mySMESHGUI->EmitSignalDeactivateDialog();
1207   GroupConstructors->setEnabled(true);
1208   TypeBox->setEnabled(true);
1209   GroupMesh->setEnabled(true);
1210   GroupCoincident->setEnabled(true);
1211   GroupEdit->setEnabled(true);
1212   GroupButtons->setEnabled(true);
1213
1214   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1215   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1216   SelectionIntoArgument();
1217 }
1218
1219 //=================================================================================
1220 // function : enterEvent()
1221 // purpose  :
1222 //=================================================================================
1223 void SMESHGUI_MergeDlg::enterEvent(QEvent*)
1224 {
1225   if (!GroupConstructors->isEnabled())
1226     ActivateThisDialog();
1227 }
1228
1229 //=================================================================================
1230 // function : keyPressEvent()
1231 // purpose  :
1232 //=================================================================================
1233 void SMESHGUI_MergeDlg::keyPressEvent( QKeyEvent* e)
1234 {
1235   QDialog::keyPressEvent( e );
1236   if ( e->isAccepted() )
1237     return;
1238
1239   if ( e->key() == Qt::Key_F1 ) {
1240     e->accept();
1241     ClickOnHelp();
1242   }
1243 }
1244
1245 //=================================================================================
1246 // function : onTypeChanged()
1247 // purpose  : the type radio button management
1248 //=================================================================================
1249 void SMESHGUI_MergeDlg::onTypeChanged (int id)
1250 {
1251   if (myTypeId == id)
1252     return;
1253
1254   myTypeId = id;
1255   switch (id)
1256   {
1257   case 0: // automatic
1258     myIdPreview->SetPointsLabeled(false);
1259     SMESH::SetPointRepresentation(false);
1260     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1261       aViewWindow->SetSelectionMode(ActorSelection);
1262     mySelectionMgr->clearFilters();
1263     if (myAction == 0)
1264       GroupCoincidentWidget->hide();
1265     else
1266       GroupCoincident->hide();
1267     GroupEdit->hide();
1268     break;
1269
1270   case 1: // manual
1271     SMESH::UpdateView();
1272
1273     // Costruction of the logical filter
1274     SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
1275     SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (SMESH::GROUP);
1276     
1277     QList<SUIT_SelectionFilter*> aListOfFilters;
1278     if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
1279     if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
1280     
1281     myMeshOrSubMeshOrGroupFilter =
1282       new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
1283
1284     if (myAction == 0) {
1285       GroupCoincidentWidget->show();
1286       SMESH::SetPointRepresentation(true);
1287       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1288         aViewWindow->SetSelectionMode(NodeSelection);
1289     }
1290     else {
1291       GroupCoincident->show();
1292       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1293         aViewWindow->SetSelectionMode(CellSelection);
1294     }
1295     GroupEdit->show();
1296     break;
1297   }
1298   updateControls();
1299
1300   qApp->processEvents();
1301   updateGeometry();
1302   resize(10,10);
1303
1304   SelectionIntoArgument();
1305 }