Salome HOME
Merge from V5_1_main 14/05/2010
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_EditMeshDlg.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_EditMeshDlg.cxx
25 // Author : Open CASCADE S.A.S.
26 // SMESH includes
27 //
28 #include "SMESHGUI_EditMeshDlg.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_SpinBox.h"
35
36 #include <SMESH_Actor.h>
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_LogicalFilter.hxx>
39 #include <SMDS_Mesh.hxx>
40
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_OverrideCursor.h>
47
48 #include <LightApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
50
51 #include <SVTK_ViewModel.h>
52 #include <SVTK_ViewWindow.h>
53 #include <SALOME_ListIO.hxx>
54
55 // OCCT includes
56 #include <TColStd_MapOfInteger.hxx>
57 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
58
59 // IDL includes
60 #include <SALOMEconfig.h>
61 #include CORBA_SERVER_HEADER(SMESH_Group)
62 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
63
64 // VTK includes
65 #include <vtkUnstructuredGrid.h>
66 #include <vtkRenderer.h>
67 #include <vtkActor2D.h>
68 #include <vtkPoints.h>
69 #include <vtkDataSetMapper.h>
70 #include <vtkMaskPoints.h>
71 #include <vtkSelectVisiblePoints.h>
72 #include <vtkLabeledDataMapper.h>
73 #include <vtkTextProperty.h>
74 #include <vtkIntArray.h>
75 #include <vtkProperty2D.h>
76 #include <vtkPointData.h>
77 #include <vtkConfigure.h>
78 #if !defined(VTK_XVERSION)
79 #define VTK_XVERSION (VTK_MAJOR_VERSION<<16)+(VTK_MINOR_VERSION<<8)+(VTK_BUILD_VERSION)
80 #endif
81
82 // Qt includes
83 #include <QApplication>
84 #include <QGroupBox>
85 #include <QLabel>
86 #include <QLineEdit>
87 #include <QListWidget>
88 #include <QPushButton>
89 #include <QRadioButton>
90 #include <QCheckBox>
91 #include <QHBoxLayout>
92 #include <QVBoxLayout>
93 #include <QGridLayout>
94 #include <QKeyEvent>
95 #include <QButtonGroup>
96
97 #define SPACING 6
98 #define MARGIN  11
99
100 namespace SMESH
101 {
102   class TIdPreview
103   { // to display in the viewer IDs of the selected elements
104     SVTK_ViewWindow* myViewWindow;
105
106     vtkUnstructuredGrid* myIdGrid;
107     SALOME_Actor* myIdActor;
108
109     vtkUnstructuredGrid* myPointsNumDataSet;
110     vtkMaskPoints* myPtsMaskPoints;
111     vtkSelectVisiblePoints* myPtsSelectVisiblePoints;
112     vtkLabeledDataMapper* myPtsLabeledDataMapper;
113     vtkTextProperty* aPtsTextProp;
114     bool myIsPointsLabeled;
115     vtkActor2D* myPointLabels;
116
117     std::vector<int> myIDs;
118
119   public:
120     TIdPreview(SVTK_ViewWindow* theViewWindow):
121       myViewWindow(theViewWindow)
122     {
123       myIdGrid = vtkUnstructuredGrid::New();
124
125       // Create and display actor
126       vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
127       aMapper->SetInput( myIdGrid );
128
129       myIdActor = SALOME_Actor::New();
130       myIdActor->SetInfinitive(true);
131       myIdActor->VisibilityOff();
132       myIdActor->PickableOff();
133
134       myIdActor->SetMapper( aMapper );
135       aMapper->Delete();
136
137       myViewWindow->AddActor(myIdActor);
138
139       //Definition of points numbering pipeline
140       myPointsNumDataSet = vtkUnstructuredGrid::New();
141
142       myPtsMaskPoints = vtkMaskPoints::New();
143       myPtsMaskPoints->SetInput(myPointsNumDataSet);
144       myPtsMaskPoints->SetOnRatio(1);
145
146       myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
147       myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
148       myPtsSelectVisiblePoints->SelectInvisibleOff();
149       myPtsSelectVisiblePoints->SetTolerance(0.1);
150     
151       myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
152       myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
153 #if (VTK_XVERSION < 0x050200)
154       myPtsLabeledDataMapper->SetLabelFormat("%g");
155 #endif
156       myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
157     
158       vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
159       aPtsTextProp->SetFontFamilyToTimes();
160       static int aPointsFontSize = 12;
161       aPtsTextProp->SetFontSize(aPointsFontSize);
162       aPtsTextProp->SetBold(1);
163       aPtsTextProp->SetItalic(0);
164       aPtsTextProp->SetShadow(0);
165       myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
166       aPtsTextProp->Delete();
167   
168       myIsPointsLabeled = false;
169
170       myPointLabels = vtkActor2D::New();
171       myPointLabels->SetMapper(myPtsLabeledDataMapper);
172       myPointLabels->GetProperty()->SetColor(1,1,1);
173       myPointLabels->SetVisibility(myIsPointsLabeled);
174
175       AddToRender(myViewWindow->getRenderer());
176     }
177
178     void SetPointsData ( SMDS_Mesh* theMesh, 
179                          TColStd_MapOfInteger & theNodesIdMap )
180     {
181       vtkPoints* aPoints = vtkPoints::New();
182       aPoints->SetNumberOfPoints(theNodesIdMap.Extent());
183       myIDs.clear();
184       
185       TColStd_MapIteratorOfMapOfInteger idIter( theNodesIdMap );
186       for( int i = 0; idIter.More(); idIter.Next(), i++ ) {
187         const SMDS_MeshNode* aNode = theMesh->FindNode(idIter.Key());
188         aPoints->SetPoint( i, aNode->X(), aNode->Y(), aNode->Z() );
189         myIDs.push_back(idIter.Key());
190       }
191
192       myIdGrid->SetPoints(aPoints);
193
194       aPoints->Delete();
195
196       myIdActor->GetMapper()->Update();
197     }
198
199     void SetElemsData( TColStd_MapOfInteger & theElemsIdMap, 
200                        std::list<gp_XYZ> & aGrCentersXYZ )
201     {
202       vtkPoints* aPoints = vtkPoints::New();
203       aPoints->SetNumberOfPoints(theElemsIdMap.Extent());
204       myIDs.clear();
205       
206       TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
207       for( ; idIter.More(); idIter.Next() ) {
208         myIDs.push_back(idIter.Key());
209       }
210
211       gp_XYZ aXYZ;
212       std::list<gp_XYZ>::iterator coordIt = aGrCentersXYZ.begin();
213       for( int i = 0; coordIt != aGrCentersXYZ.end(); coordIt++, i++ ) {
214         aXYZ = *coordIt;
215         aPoints->SetPoint( i, aXYZ.X(), aXYZ.Y(), aXYZ.Z() );
216       }
217       myIdGrid->SetPoints(aPoints);
218       aPoints->Delete();
219       
220       myIdActor->GetMapper()->Update();
221     }
222
223     void AddToRender(vtkRenderer* theRenderer)
224     {
225       myIdActor->AddToRender(theRenderer);
226
227       myPtsSelectVisiblePoints->SetRenderer(theRenderer);
228       theRenderer->AddActor2D(myPointLabels);
229     }
230
231     void RemoveFromRender(vtkRenderer* theRenderer)
232     {
233       myIdActor->RemoveFromRender(theRenderer);
234
235       myPtsSelectVisiblePoints->SetRenderer(theRenderer);
236       theRenderer->RemoveActor(myPointLabels);
237     }
238
239     void SetPointsLabeled( bool theIsPointsLabeled, bool theIsActorVisible = true )
240     {
241       myIsPointsLabeled = theIsPointsLabeled && myIdGrid->GetNumberOfPoints();
242       
243       if ( myIsPointsLabeled ) {
244         myPointsNumDataSet->ShallowCopy(myIdGrid);
245         vtkDataSet *aDataSet = myPointsNumDataSet;
246         int aNbElem = myIDs.size();
247         vtkIntArray *anArray = vtkIntArray::New();
248         anArray->SetNumberOfValues( aNbElem );
249         for ( int i = 0; i < aNbElem; i++ )
250           anArray->SetValue( i, myIDs[i] );
251         aDataSet->GetPointData()->SetScalars( anArray );
252         anArray->Delete();
253         myPtsMaskPoints->SetInput( aDataSet );
254         myPointLabels->SetVisibility( theIsActorVisible );
255       }
256       else {
257         myPointLabels->SetVisibility( false );
258       }
259     }
260     
261     ~TIdPreview()
262     {
263       RemoveFromRender(myViewWindow->getRenderer());
264
265       myIdGrid->Delete();
266
267       myViewWindow->RemoveActor(myIdActor);
268       myIdActor->Delete();
269
270       //Deleting of points numbering pipeline
271       //---------------------------------------
272       myPointsNumDataSet->Delete();
273       
274       //myPtsLabeledDataMapper->RemoveAllInputs();        //vtk 5.0 porting
275       myPtsLabeledDataMapper->Delete();
276
277       //myPtsSelectVisiblePoints->UnRegisterAllOutputs(); //vtk 5.0 porting
278       myPtsSelectVisiblePoints->Delete();
279
280       //myPtsMaskPoints->UnRegisterAllOutputs();          //vtk 5.0 porting
281       myPtsMaskPoints->Delete();
282
283       myPointLabels->Delete();
284
285 //       myTimeStamp->Delete();
286     }
287   };
288 }
289
290 static const char * IconFirst[] = {
291 "18 10 2 1",
292 "       g None",
293 ".      g #000000",
294 "         .     .  ",
295 "  ..    ..    ..  ",
296 "  ..   ...   ...  ",
297 "  ..  ....  ....  ",
298 "  .. ..... .....  ",
299 "  .. ..... .....  ",
300 "  ..  ....  ....  ",
301 "  ..   ...   ...  ",
302 "  ..    ..    ..  ",
303 "         .     .  "};
304
305 //=================================================================================
306 // class    : SMESHGUI_EditMeshDlg()
307 // purpose  :
308 //=================================================================================
309 SMESHGUI_EditMeshDlg::SMESHGUI_EditMeshDlg (SMESHGUI* theModule, 
310                                             int theAction)
311   : QDialog(SMESH::GetDesktop(theModule)),
312     mySMESHGUI(theModule),
313     mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
314     myAction(theAction)
315 {
316   setModal(false);
317   setAttribute(Qt::WA_DeleteOnClose, true);
318   setWindowTitle(myAction == 1 ? tr("SMESH_MERGE_ELEMENTS") : tr("SMESH_MERGE_NODES"));
319
320   myIdPreview = new SMESH::TIdPreview(SMESH::GetViewWindow( mySMESHGUI ));
321
322   SUIT_ResourceMgr* aResMgr = SMESH::GetResourceMgr( mySMESHGUI );
323   QPixmap IconMergeNodes (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_MERGE_NODES")));
324   QPixmap IconMergeElems (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_MERGE_ELEMENTS")));
325   QPixmap IconSelect     (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
326   QPixmap IconAdd        (aResMgr->loadPixmap("SMESH", tr("ICON_APPEND")));
327   QPixmap IconRemove     (aResMgr->loadPixmap("SMESH", tr("ICON_REMOVE")));
328
329   setSizeGripEnabled(true);
330
331   QVBoxLayout* DlgLayout = new QVBoxLayout(this);
332   DlgLayout->setSpacing(SPACING);
333   DlgLayout->setMargin(MARGIN);
334
335   /***************************************************************/
336   GroupConstructors = new QGroupBox(myAction == 1 ? 
337                                     tr("SMESH_MERGE_ELEMENTS") : 
338                                     tr("SMESH_MERGE_NODES"), 
339                                     this);
340
341   QButtonGroup* ButtonGroup = new QButtonGroup(this);
342   QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
343   GroupConstructorsLayout->setSpacing(SPACING);
344   GroupConstructorsLayout->setMargin(MARGIN);
345
346   RadioButton = new QRadioButton(GroupConstructors);
347   RadioButton->setIcon(myAction == 1 ? IconMergeElems : IconMergeNodes);
348   RadioButton->setChecked(true);
349   GroupConstructorsLayout->addWidget(RadioButton);
350   ButtonGroup->addButton(RadioButton, 0);
351
352   /***************************************************************/
353   // Controls for mesh defining
354   GroupMesh = new QGroupBox(tr("SMESH_SELECT_WHOLE_MESH"), this);
355   QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
356   GroupMeshLayout->setSpacing(SPACING);
357   GroupMeshLayout->setMargin(MARGIN);
358
359   TextLabelName = new QLabel(tr("SMESH_NAME"), GroupMesh);
360   SelectMeshButton = new QPushButton(GroupMesh);
361   SelectMeshButton->setIcon(IconSelect);
362   LineEditMesh = new QLineEdit(GroupMesh);
363   LineEditMesh->setReadOnly(true);
364
365   GroupMeshLayout->addWidget(TextLabelName);
366   GroupMeshLayout->addWidget(SelectMeshButton);
367   GroupMeshLayout->addWidget(LineEditMesh);
368
369   /***************************************************************/
370   // Controls for switch dialog behaviour
371
372   TypeBox = new QGroupBox( tr( "SMESH_MODE" ), this );
373   GroupType = new QButtonGroup( this );
374   QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( TypeBox );
375   aTypeBoxLayout->setMargin( MARGIN );
376   aTypeBoxLayout->setSpacing( SPACING );
377
378   QRadioButton* rb1 = new QRadioButton( tr( "SMESH_AUTOMATIC" ), TypeBox );
379   QRadioButton* rb2 = new QRadioButton( tr( "SMESH_MANUAL" ),   TypeBox );
380   GroupType->addButton( rb1, 0 );
381   GroupType->addButton( rb2, 1 );
382   aTypeBoxLayout->addWidget( rb1 );
383   aTypeBoxLayout->addWidget( rb2 );
384
385   myTypeId = 0;
386
387   /***************************************************************/
388   // Controls for coincident elements detecting
389   GroupCoincident = new QGroupBox(myAction == 1 ? 
390                                   tr("COINCIDENT_ELEMENTS") : 
391                                   tr("COINCIDENT_NODES"), 
392                                   this);
393
394   QVBoxLayout* aCoincidentLayout = new QVBoxLayout(GroupCoincident);
395
396   GroupCoincident->setLayout(aCoincidentLayout);
397
398   QHBoxLayout* aSpinBoxLayout = new QHBoxLayout( GroupCoincident );
399   
400   if (myAction == 0) { // case merge nodes
401     TextLabelTolerance = new QLabel(tr("SMESH_TOLERANCE"), GroupCoincident);
402     SpinBoxTolerance = new SMESHGUI_SpinBox(GroupCoincident);
403     SpinBoxTolerance->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
404
405     aSpinBoxLayout->addWidget(TextLabelTolerance);
406     aSpinBoxLayout->addWidget(SpinBoxTolerance);
407     aCoincidentLayout->addLayout(aSpinBoxLayout);
408   }
409   else {
410     TextLabelTolerance = 0;
411     SpinBoxTolerance = 0;
412   }
413
414   GroupCoincidentWidget = new QWidget(GroupCoincident);
415   QGridLayout* GroupCoincidentLayout = new QGridLayout(GroupCoincidentWidget);
416   GroupCoincidentLayout->setSpacing(SPACING);
417   GroupCoincidentLayout->setMargin(MARGIN);
418
419   ListCoincident = new QListWidget(GroupCoincidentWidget);
420   ListCoincident->setSelectionMode(QListWidget::ExtendedSelection);
421
422   DetectButton      = new QPushButton(tr("DETECT"),           GroupCoincidentWidget);
423   AddGroupButton    = new QPushButton(tr("SMESH_BUT_ADD"),    GroupCoincidentWidget);
424   RemoveGroupButton = new QPushButton(tr("SMESH_BUT_REMOVE"), GroupCoincidentWidget);
425
426   SelectAllCB = new QCheckBox(tr("SELECT_ALL"), GroupCoincidentWidget);
427
428   if (myAction == 0)
429     GroupCoincidentWidget->hide();
430   else
431     GroupCoincident->hide();
432
433   GroupCoincidentLayout->addWidget(ListCoincident,    0,   0, 4, 2);
434   GroupCoincidentLayout->addWidget(DetectButton,      0,   2);
435   GroupCoincidentLayout->addWidget(AddGroupButton,    2, 2);
436   GroupCoincidentLayout->addWidget(RemoveGroupButton, 3, 2);
437   GroupCoincidentLayout->addWidget(SelectAllCB,       4, 0, 1, 3);
438   GroupCoincidentLayout->setRowMinimumHeight(1, 10);
439   GroupCoincidentLayout->setRowStretch(1, 5);
440
441   aCoincidentLayout->addWidget(GroupCoincidentWidget);
442
443   /***************************************************************/
444   // Controls for editing the selected group
445   GroupEdit = new QGroupBox(tr("EDIT_SELECTED_GROUP"), this);
446   QGridLayout* GroupEditLayout = new QGridLayout(GroupEdit);
447   GroupEditLayout->setSpacing(SPACING);
448   GroupEditLayout->setMargin(MARGIN);
449
450   ListEdit = new QListWidget(GroupEdit);
451   //ListEdit->setRowMode(QListBox::FixedNumber);
452   //ListEdit->setHScrollBarMode(QScrollView::AlwaysOn);
453   //ListEdit->setVScrollBarMode(QScrollView::AlwaysOff);
454   ListEdit->setFlow( QListView::LeftToRight );
455   ListEdit->setSelectionMode(QListWidget::ExtendedSelection);
456
457   AddElemButton = new QPushButton(GroupEdit);
458   AddElemButton->setIcon(IconAdd);
459   RemoveElemButton = new QPushButton(GroupEdit);
460   RemoveElemButton->setIcon(IconRemove);
461   SetFirstButton = new QPushButton(GroupEdit);
462   SetFirstButton->setIcon(QPixmap(IconFirst));
463
464   GroupEditLayout->addWidget(ListEdit,         0, 0, 2, 1);
465   GroupEditLayout->addWidget(AddElemButton,    0, 1);
466   GroupEditLayout->addWidget(RemoveElemButton, 0, 2);
467   GroupEditLayout->addWidget(SetFirstButton,   1, 1, 1, 2);
468
469   GroupEdit->hide();
470
471   /***************************************************************/
472   GroupButtons = new QGroupBox(this);
473   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
474   GroupButtonsLayout->setSpacing(SPACING);
475   GroupButtonsLayout->setMargin(MARGIN);
476
477   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
478   buttonOk->setAutoDefault(true);
479   buttonOk->setDefault(true);
480   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
481   buttonApply->setAutoDefault(true);
482   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
483   buttonCancel->setAutoDefault(true);
484   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
485   buttonHelp->setAutoDefault(true);
486
487   GroupButtonsLayout->addWidget(buttonOk);
488   GroupButtonsLayout->addSpacing(10);
489   GroupButtonsLayout->addWidget(buttonApply);
490   GroupButtonsLayout->addSpacing(10);
491   GroupButtonsLayout->addStretch();
492   GroupButtonsLayout->addWidget(buttonCancel);
493   GroupButtonsLayout->addWidget(buttonHelp);
494
495   /***************************************************************/
496   DlgLayout->addWidget(GroupConstructors);
497   DlgLayout->addWidget(GroupMesh);
498   DlgLayout->addWidget(TypeBox);
499   DlgLayout->addWidget(GroupCoincident);
500   DlgLayout->addWidget(GroupEdit);
501   DlgLayout->addWidget(GroupButtons);
502
503   this->resize(10,10);
504
505   Init(); // Initialisations
506 }
507
508 //=================================================================================
509 // function : ~SMESHGUI_EditMeshDlg()
510 // purpose  : Destroys the object and frees any allocated resources
511 //=================================================================================
512 SMESHGUI_EditMeshDlg::~SMESHGUI_EditMeshDlg()
513 {
514   delete myIdPreview;
515 }
516
517 //=================================================================================
518 // function : Init()
519 // purpose  :
520 //=================================================================================
521 void SMESHGUI_EditMeshDlg::Init()
522 {
523   if (myAction == 0) {
524     SpinBoxTolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, "len_tol_precision");
525     SpinBoxTolerance->SetValue(1e-05);
526   }
527
528   RadioButton->setChecked(true);
529
530   GroupType->button(0)->setChecked(true);
531
532   myEditCurrentArgument = (QWidget*)LineEditMesh; 
533
534   myActor = 0;
535   mySubMeshOrGroup = SMESH::SMESH_subMesh::_nil();
536
537   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
538
539   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
540   myIsBusy = false;
541   
542   /* signals and slots connections */
543   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
544   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
545   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
546   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
547
548   connect(SelectMeshButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
549   connect(DetectButton, SIGNAL (clicked()), this, SLOT(onDetect()));
550   connect(ListCoincident, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectGroup()));
551   connect(AddGroupButton, SIGNAL (clicked()), this, SLOT(onAddGroup()));
552   connect(RemoveGroupButton, SIGNAL (clicked()), this, SLOT(onRemoveGroup()));
553   connect(SelectAllCB, SIGNAL(toggled(bool)), this, SLOT(onSelectAll(bool)));
554   connect(ListEdit, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectElementFromGroup()));
555   connect(AddElemButton, SIGNAL (clicked()), this, SLOT(onAddElement()));
556   connect(RemoveElemButton, SIGNAL (clicked()), this, SLOT(onRemoveElement()));
557   connect(SetFirstButton, SIGNAL( clicked() ), this, SLOT( onSetFirst() ) );
558   connect(GroupType, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
559
560   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
561   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
562   /* to close dialog if study change */
563   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
564
565   // Init Mesh field from selection
566   SelectionIntoArgument();
567
568   // Update Buttons
569   updateControls();
570   
571   if (myAction == 0)
572     myHelpFileName = "merging_nodes_page.html";
573   else
574     myHelpFileName = "merging_elements_page.html";
575 }
576
577 //=================================================================================
578 // function : FindGravityCenter()
579 // purpose  :
580 //=================================================================================
581 void SMESHGUI_EditMeshDlg::FindGravityCenter(TColStd_MapOfInteger & theElemsIdMap, 
582                                              std::list< gp_XYZ > & theGrCentersXYZ)
583 {
584   if (!myActor)
585     return;
586
587   SMDS_Mesh* aMesh = 0;
588   aMesh = myActor->GetObject()->GetMesh();
589   if (!aMesh)
590     return;
591
592   int nbNodes;
593
594   TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
595   for( ; idIter.More(); idIter.Next() ) {
596     const SMDS_MeshElement* anElem = aMesh->FindElement(idIter.Key());
597     if ( !anElem )
598       continue;
599
600     gp_XYZ anXYZ(0., 0., 0.);
601     SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
602     for ( nbNodes = 0; nodeIt->more(); nbNodes++ ) {
603       const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
604       anXYZ.Add( gp_XYZ( node->X(), node->Y(), node->Z() ) );
605     }
606     anXYZ.Divide( nbNodes );
607     
608     theGrCentersXYZ.push_back( anXYZ );
609   }
610 }
611
612 //=================================================================================
613 // function : ClickOnApply()
614 // purpose  :
615 //=================================================================================
616 bool SMESHGUI_EditMeshDlg::ClickOnApply()
617 {
618   if (mySMESHGUI->isActiveStudyLocked() || myMesh->_is_nil())
619     return false;
620
621   try {
622     if (myTypeId == 0)
623       onDetect();
624
625     SUIT_OverrideCursor aWaitCursor;
626     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
627
628     SMESH::long_array_var anIds = new SMESH::long_array;
629     SMESH::array_of_long_array_var aGroupsOfElements = new SMESH::array_of_long_array;
630
631     if ( ListCoincident->count() == 0) {
632       if (myAction == 0)
633         SUIT_MessageBox::warning(this,
634                                  tr("SMESH_WARNING"),
635                                  tr("SMESH_NO_NODES_DETECTED"));
636       else
637         SUIT_MessageBox::warning(this,
638                                  tr("SMESH_WARNING"),
639                                  tr("SMESH_NO_ELEMENTS_DETECTED"));
640       return false;
641     }
642
643     aGroupsOfElements->length(ListCoincident->count());
644
645     int anArrayNum = 0;
646     for (int i = 0; i < ListCoincident->count(); i++) {
647       QStringList aListIds = ListCoincident->item(i)->text().split(" ", QString::SkipEmptyParts);
648
649       anIds->length(aListIds.count());
650       for (int i = 0; i < aListIds.count(); i++)
651         anIds[i] = aListIds[i].toInt();
652
653       aGroupsOfElements[anArrayNum++] = anIds.inout();
654     }
655
656     if( myAction == 0 )
657       aMeshEditor->MergeNodes (aGroupsOfElements.inout());
658     else
659       aMeshEditor->MergeElements (aGroupsOfElements.inout());
660
661     if ( myTypeId == 0 ) {
662       if (myAction ==0)
663         SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
664                                      tr("SMESH_MERGED_NODES").arg(QString::number(ListCoincident->count()).toLatin1().data()));
665       else
666         SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
667                                      tr("SMESH_MERGED_ELEMENTS").arg(QString::number(ListCoincident->count()).toLatin1().data()));
668     }
669       
670
671   } catch(...) {
672   }
673   
674   SMESH::UpdateView();
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 }