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