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