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