Salome HOME
0020746: EDF 1274 SMESH : MergeAllNodesButNodesFromGroup feature
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MergeDlg.cxx
1 //  Copyright (C) 2007-2010  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->SetInput( 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->SetInput(myPointsNumDataSet);
144       myPtsMaskPoints->SetOnRatio(1);
145
146       myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
147       myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
148       myPtsSelectVisiblePoints->SelectInvisibleOff();
149       myPtsSelectVisiblePoints->SetTolerance(0.1);
150     
151       myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
152       myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
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->SetInput( 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(ClickOnCancel()));
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(ClickOnCancel()));
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   SMESH::UpdateView();
686   SMESHGUI::Modified();
687   
688   return true;
689 }
690
691 //=================================================================================
692 // function : ClickOnOk()
693 // purpose  :
694 //=================================================================================
695 void SMESHGUI_MergeDlg::ClickOnOk()
696 {
697   if (ClickOnApply())
698     ClickOnCancel();
699 }
700
701 //=================================================================================
702 // function : ClickOnCancel()
703 // purpose  :
704 //=================================================================================
705 void SMESHGUI_MergeDlg::ClickOnCancel()
706 {
707   myIdPreview->SetPointsLabeled(false);
708   SMESH::SetPointRepresentation(false);
709   disconnect(mySelectionMgr, 0, this, 0);
710   disconnect(mySMESHGUI, 0, this, 0);
711   mySMESHGUI->ResetState();
712
713   mySelectionMgr->clearFilters();
714   //mySelectionMgr->clearSelected();
715
716   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
717     aViewWindow->SetSelectionMode(ActorSelection);
718
719   reject();
720 }
721
722 //=================================================================================
723 // function : ClickOnHelp()
724 // purpose  :
725 //=================================================================================
726 void SMESHGUI_MergeDlg::ClickOnHelp()
727 {
728   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
729   if (app) 
730     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
731   else {
732     QString platform;
733 #ifdef WIN32
734     platform = "winapplication";
735 #else
736     platform = "application";
737 #endif
738     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
739                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
740                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
741                                                                  platform)).
742                              arg(myHelpFileName));
743   }
744 }
745
746 //=================================================================================
747 // function : onEditGroup()
748 // purpose  :
749 //=================================================================================
750 void SMESHGUI_MergeDlg::onEditGroup()
751 {
752   QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
753   if ( selItems.count() != 1 ) {
754     ListEdit->clear();
755     return;
756   }
757
758   QStringList aNewIds;
759
760   for (int i = 0; i < ListEdit->count(); i++ )
761     aNewIds.append(ListEdit->item(i)->text());
762
763   ListCoincident->clearSelection();
764   selItems.first()->setText(aNewIds.join(" "));
765   selItems.first()->setSelected(true);
766 }
767
768 //=================================================================================
769 // function : updateControls()
770 // purpose  :
771 //=================================================================================
772 void SMESHGUI_MergeDlg::updateControls()
773 {
774   if (ListEdit->count() == 0)
775     SetFirstButton->setEnabled(false);
776   bool enable = !(myMesh->_is_nil()) && (ListCoincident->count() || (myTypeId == 0));
777   buttonOk->setEnabled(enable);
778   buttonApply->setEnabled(enable);
779 }
780
781 //=================================================================================
782 // function : onDetect()
783 // purpose  :
784 //=================================================================================
785 void SMESHGUI_MergeDlg::onDetect()
786 {
787   if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
788     return;
789
790   try {
791     SUIT_OverrideCursor aWaitCursor;
792     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
793
794     ListCoincident->clear();
795     ListEdit->clear();
796
797     SMESH::array_of_long_array_var aGroupsArray;
798     SMESH::ListOfIDSources_var aExcludeGroups = new SMESH::ListOfIDSources;
799
800     SMESH::SMESH_IDSource_var src;
801     if ( mySubMeshOrGroup->_is_nil() ) src = SMESH::SMESH_IDSource::_duplicate( myMesh );
802     else src = SMESH::SMESH_IDSource::_duplicate( mySubMeshOrGroup );
803
804     switch (myAction) {
805     case 0 :
806       for ( int i = 0; GroupExclude->isChecked() && i < ListExclude->count(); i++ ) {
807         if ( ListExclude->item( i )->checkState() == Qt::Checked ) {
808           aExcludeGroups->length( aExcludeGroups->length()+1 );
809           aExcludeGroups[ aExcludeGroups->length()-1 ] = SMESH::SMESH_IDSource::_duplicate( myGroups[i] );
810         }
811       }
812       aMeshEditor->FindCoincidentNodesOnPartBut(src.in(),
813                                                 SpinBoxTolerance->GetValue(), 
814                                                 aGroupsArray.out(),
815                                                 aExcludeGroups.in());
816       break;
817     case 1 :
818       aMeshEditor->FindEqualElements(src.in(), aGroupsArray.out());
819       break;
820     }
821     
822     for (int i = 0; i < aGroupsArray->length(); i++) {
823       SMESH::long_array& aGroup = aGroupsArray[i];
824
825       QStringList anIDs;
826       for (int j = 0; j < aGroup.length(); j++)
827         anIDs.append(QString::number(aGroup[j]));
828
829       ListCoincident->addItem(anIDs.join(" "));
830     }
831    } catch(...) {
832   }
833
834   ListCoincident->selectAll();
835   updateControls();
836 }
837
838 //=================================================================================
839 // function : onSelectGroup()
840 // purpose  :
841 //=================================================================================
842 void SMESHGUI_MergeDlg::onSelectGroup()
843 {
844   if (myIsBusy || !myActor)
845     return;
846   myEditCurrentArgument = (QWidget*)ListCoincident;
847
848   ListEdit->clear();
849   
850   TColStd_MapOfInteger anIndices;
851   QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
852   QListWidgetItem* anItem;
853   QStringList aListIds;
854
855   ListEdit->clear();
856
857   foreach(anItem, selItems) {
858     aListIds = anItem->text().split(" ", QString::SkipEmptyParts);
859     for (int i = 0; i < aListIds.count(); i++)
860       anIndices.Add(aListIds[i].toInt());
861   }
862   
863   if (selItems.count() == 1) {
864     ListEdit->addItems(aListIds);
865     ListEdit->selectAll();
866   }
867
868   mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
869   SALOME_ListIO aList;
870   aList.Append(myActor->getIO());
871   mySelectionMgr->setSelectedObjects(aList,false);
872   
873   if (myAction == 0) {
874     myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
875     myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
876   }
877   else {
878     std::list< gp_XYZ > aGrCentersXYZ;
879     FindGravityCenter(anIndices, aGrCentersXYZ);
880     myIdPreview->SetElemsData( anIndices, aGrCentersXYZ);
881     myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
882   }
883
884   updateControls();
885 }
886
887 //=================================================================================
888 // function : onSelectAll()
889 // purpose  :
890 //=================================================================================
891 void SMESHGUI_MergeDlg::onSelectAll (bool isToggled)
892 {
893   if ( isToggled )
894     ListCoincident->selectAll();
895   else
896     ListCoincident->clearSelection();
897 }
898
899 //=================================================================================
900 // function : onSelectElementFromGroup()
901 // purpose  :
902 //=================================================================================
903 void SMESHGUI_MergeDlg::onSelectElementFromGroup()
904 {
905   if (myIsBusy || !myActor)
906     return;
907
908   TColStd_MapOfInteger anIndices;
909   QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
910   QListWidgetItem* anItem;
911
912   foreach(anItem, selItems)
913     anIndices.Add(anItem->text().toInt());
914
915   SetFirstButton->setEnabled(selItems.count() == 1);
916
917   mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
918   SALOME_ListIO aList;
919   aList.Append(myActor->getIO());
920   mySelectionMgr->setSelectedObjects(aList);
921
922   if (myAction == 0) {
923     myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
924     myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
925   }
926   else {
927     std::list< gp_XYZ > aGrCentersXYZ;
928     FindGravityCenter(anIndices, aGrCentersXYZ);
929     myIdPreview->SetElemsData(anIndices, aGrCentersXYZ);
930     myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
931   }
932 }
933
934 //=================================================================================
935 // function : onAddGroup()
936 // purpose  :
937 //=================================================================================
938 void SMESHGUI_MergeDlg::onAddGroup()
939 {
940   if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
941     return;
942
943   QString anIDs = "";
944   int aNbElements = 0;
945   aNbElements = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
946
947   if (aNbElements < 1)
948     return;
949   
950   ListCoincident->clearSelection();
951   ListCoincident->addItem(anIDs);
952   int nbGroups = ListCoincident->count();
953   if (nbGroups) {
954     ListCoincident->setCurrentRow(nbGroups-1);
955     ListCoincident->item(nbGroups-1)->setSelected(true);
956   }
957   else {
958     // VSR ? this code seems to be never executed!!!
959     ListCoincident->setCurrentRow(0);
960     //ListCoincident->setSelected(0, true); // VSR: no items - no selection
961   }
962
963   updateControls();
964 }
965
966 //=================================================================================
967 // function : onRemoveGroup()
968 // purpose  :
969 //=================================================================================
970 void SMESHGUI_MergeDlg::onRemoveGroup()
971 {
972   if (myEditCurrentArgument != (QWidget*)ListCoincident)
973     return;
974   myIsBusy = true;
975
976   QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
977   QListWidgetItem* anItem;
978
979   foreach(anItem, selItems)
980     delete anItem;
981
982   ListEdit->clear();
983   updateControls();
984
985   myIsBusy = false;
986 }
987
988 //=================================================================================
989 // function : onAddElement()
990 // purpose  :
991 //=================================================================================
992 void SMESHGUI_MergeDlg::onAddElement()
993 {
994   if (!myActor)
995     return;
996   myIsBusy = true;
997
998   QString aListStr = "";
999   int aNbNnodes = 0;
1000
1001   aNbNnodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1002   if (aNbNnodes < 1)
1003     return;
1004
1005   QStringList aNodes = aListStr.split(" ", QString::SkipEmptyParts);
1006
1007   for (QStringList::iterator it = aNodes.begin(); it != aNodes.end(); ++it) {
1008     QList<QListWidgetItem*> found = ListEdit->findItems(*it, Qt::MatchExactly);
1009     if ( found.count() == 0 ) {
1010       QListWidgetItem* anItem = new QListWidgetItem(*it);
1011       ListEdit->addItem(anItem);
1012       anItem->setSelected(true);
1013     }
1014     else {
1015       QListWidgetItem* anItem;
1016       foreach(anItem, found) anItem->setSelected(true);
1017     }
1018   }
1019
1020   myIsBusy = false;
1021   onEditGroup();
1022 }
1023
1024 //=================================================================================
1025 // function : onRemoveElement()
1026 // purpose  :
1027 //=================================================================================
1028 void SMESHGUI_MergeDlg::onRemoveElement()
1029 {
1030   if (myEditCurrentArgument != (QWidget*)ListCoincident)
1031     return;
1032   myIsBusy = true;
1033
1034   QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
1035   QListWidgetItem* anItem;
1036
1037   foreach(anItem, selItems)
1038     delete anItem;
1039   
1040   myIsBusy = false;
1041   onEditGroup();
1042 }
1043
1044 //=================================================================================
1045 // function : onSetFirst()
1046 // purpose  :
1047 //=================================================================================
1048 void SMESHGUI_MergeDlg::onSetFirst()
1049 {
1050   if (myEditCurrentArgument != (QWidget*)ListCoincident)
1051     return;
1052   myIsBusy = true;
1053   
1054   QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
1055   QListWidgetItem* anItem;
1056   
1057   foreach(anItem, selItems) {
1058     ListEdit->takeItem(ListEdit->row(anItem));
1059     ListEdit->insertItem(0, anItem);
1060   }
1061
1062   myIsBusy = false;
1063   onEditGroup();
1064 }
1065
1066 //=================================================================================
1067 // function : SetEditCurrentArgument()
1068 // purpose  :
1069 //=================================================================================
1070 void SMESHGUI_MergeDlg::SetEditCurrentArgument()
1071 {
1072   QPushButton* send = (QPushButton*)sender();
1073
1074   disconnect(mySelectionMgr, 0, this, 0);
1075   mySelectionMgr->clearSelected();
1076   mySelectionMgr->clearFilters();
1077
1078   if (send == SelectMeshButton) {
1079     myEditCurrentArgument = (QWidget*)LineEditMesh;
1080     SMESH::SetPointRepresentation(false);
1081     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1082       aViewWindow->SetSelectionMode(ActorSelection);
1083     if (myTypeId == 1)
1084       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1085   }
1086
1087   myEditCurrentArgument->setFocus();
1088   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1089   SelectionIntoArgument();
1090 }
1091
1092 //=================================================================================
1093 // function : SelectionIntoArgument()
1094 // purpose  : Called when selection as changed or other case
1095 //=================================================================================
1096 void SMESHGUI_MergeDlg::SelectionIntoArgument()
1097 {
1098   if (myEditCurrentArgument == (QWidget*)LineEditMesh) {
1099     QString aString = "";
1100     LineEditMesh->setText(aString);
1101     
1102     ListCoincident->clear();
1103     ListEdit->clear();
1104     myActor = 0;
1105     QString aCurrentEntry = myEntry;
1106     
1107     int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
1108     if (nbSel != 1) {
1109       myIdPreview->SetPointsLabeled(false);
1110       SMESH::SetPointRepresentation(false);
1111       mySelectionMgr->clearFilters();
1112       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1113         aViewWindow->SetSelectionMode(ActorSelection);
1114       return;
1115     }
1116
1117     SALOME_ListIO aList;
1118     mySelectionMgr->selectedObjects(aList);
1119     
1120     Handle(SALOME_InteractiveObject) IO = aList.First();
1121     myEntry = IO->getEntry();
1122     myMesh = SMESH::GetMeshByIO(IO);
1123     
1124     if (myMesh->_is_nil())
1125       return;
1126
1127     LineEditMesh->setText(aString);
1128     
1129     myActor = SMESH::FindActorByEntry(IO->getEntry());
1130     if (!myActor)
1131       myActor = SMESH::FindActorByObject(myMesh);
1132     
1133     if ( myActor && myTypeId ==1 ) {
1134       mySubMeshOrGroup = SMESH::SMESH_IDSource::_nil();
1135       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1136       
1137       if ((!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil() || //SUBMESH OR GROUP
1138            !SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) &&
1139           !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
1140         mySubMeshOrGroup = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
1141       
1142       if (myAction == 0) {
1143         SMESH::SetPointRepresentation(true);
1144         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1145           aViewWindow->SetSelectionMode(NodeSelection);
1146       }
1147       else
1148         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1149           aViewWindow->SetSelectionMode(CellSelection);
1150     }
1151
1152     // process groups
1153     if ( myAction == 0 && !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
1154       myGroups.clear();
1155       ListExclude->clear();
1156       SMESH::ListOfGroups_var aListOfGroups = myMesh->GetGroups();
1157       for( int i = 0, n = aListOfGroups->length(); i < n; i++ ) {
1158         SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
1159         if ( !aGroup->_is_nil() ) { // && aGroup->GetType() == SMESH::NODE
1160           QString aGroupName( aGroup->GetName() );
1161           if ( !aGroupName.isEmpty() ) {
1162             myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
1163             QListWidgetItem* item = new QListWidgetItem( aGroupName );
1164             item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
1165             item->setCheckState( Qt::Unchecked );
1166             ListExclude->addItem( item );
1167           }
1168         }
1169       }
1170     }
1171
1172     updateControls();
1173   }
1174 }
1175
1176 //=================================================================================
1177 // function : DeactivateActiveDialog()
1178 // purpose  :
1179 //=================================================================================
1180 void SMESHGUI_MergeDlg::DeactivateActiveDialog()
1181 {
1182   if (GroupConstructors->isEnabled()) {
1183     GroupConstructors->setEnabled(false);
1184     TypeBox->setEnabled(false);
1185     GroupMesh->setEnabled(false);
1186     GroupCoincident->setEnabled(false);
1187     GroupEdit->setEnabled(false);
1188     GroupButtons->setEnabled(false);
1189     mySMESHGUI->ResetState();
1190     mySMESHGUI->SetActiveDialogBox(0);
1191   }
1192
1193   mySelectionMgr->clearSelected();
1194   disconnect(mySelectionMgr, 0, this, 0);
1195 }
1196
1197 //=================================================================================
1198 // function : ActivateThisDialog()
1199 // purpose  :
1200 //=================================================================================
1201 void SMESHGUI_MergeDlg::ActivateThisDialog()
1202 {
1203   /* Emit a signal to deactivate the active dialog */
1204   mySMESHGUI->EmitSignalDeactivateDialog();
1205   GroupConstructors->setEnabled(true);
1206   TypeBox->setEnabled(true);
1207   GroupMesh->setEnabled(true);
1208   GroupCoincident->setEnabled(true);
1209   GroupEdit->setEnabled(true);
1210   GroupButtons->setEnabled(true);
1211
1212   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1213   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1214   SelectionIntoArgument();
1215 }
1216
1217 //=================================================================================
1218 // function : enterEvent()
1219 // purpose  :
1220 //=================================================================================
1221 void SMESHGUI_MergeDlg::enterEvent(QEvent*)
1222 {
1223   if (!GroupConstructors->isEnabled())
1224     ActivateThisDialog();
1225 }
1226
1227 //=================================================================================
1228 // function : closeEvent()
1229 // purpose  :
1230 //=================================================================================
1231 void SMESHGUI_MergeDlg::closeEvent(QCloseEvent*)
1232 {
1233   /* same than click on cancel button */
1234   ClickOnCancel();
1235 }
1236
1237 //=======================================================================
1238 //function : hideEvent
1239 //purpose  : caused by ESC key
1240 //=======================================================================
1241 void SMESHGUI_MergeDlg::hideEvent (QHideEvent *)
1242 {
1243   if (!isMinimized())
1244     ClickOnCancel();
1245 }
1246
1247 //=================================================================================
1248 // function : keyPressEvent()
1249 // purpose  :
1250 //=================================================================================
1251 void SMESHGUI_MergeDlg::keyPressEvent( QKeyEvent* e)
1252 {
1253   QDialog::keyPressEvent( e );
1254   if ( e->isAccepted() )
1255     return;
1256
1257   if ( e->key() == Qt::Key_F1 ) {
1258     e->accept();
1259     ClickOnHelp();
1260   }
1261 }
1262
1263 //=================================================================================
1264 // function : onTypeChanged()
1265 // purpose  : the type radio button management
1266 //=================================================================================
1267 void SMESHGUI_MergeDlg::onTypeChanged (int id)
1268 {
1269   if (myTypeId == id)
1270     return;
1271
1272   myTypeId = id;
1273   switch (id)
1274   {
1275   case 0: // automatic
1276     myIdPreview->SetPointsLabeled(false);
1277     SMESH::SetPointRepresentation(false);
1278     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1279       aViewWindow->SetSelectionMode(ActorSelection);
1280     mySelectionMgr->clearFilters();
1281     if (myAction == 0)
1282       GroupCoincidentWidget->hide();
1283     else
1284       GroupCoincident->hide();
1285     GroupEdit->hide();
1286     break;
1287
1288   case 1: // manual
1289     SMESH::UpdateView();
1290
1291     // Costruction of the logical filter
1292     SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
1293     SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
1294     
1295     QList<SUIT_SelectionFilter*> aListOfFilters;
1296     if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
1297     if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
1298     
1299     myMeshOrSubMeshOrGroupFilter =
1300       new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
1301
1302     if (myAction == 0) {
1303       GroupCoincidentWidget->show();
1304       SMESH::SetPointRepresentation(true);
1305       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1306         aViewWindow->SetSelectionMode(NodeSelection);
1307     }
1308     else {
1309       GroupCoincident->show();
1310       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1311         aViewWindow->SetSelectionMode(CellSelection);
1312     }
1313     GroupEdit->show();
1314     break;
1315   }
1316   updateControls();
1317
1318   qApp->processEvents();
1319   updateGeometry();
1320   resize(10,10);
1321
1322   SelectionIntoArgument();
1323 }