Salome HOME
3dd0cadc17b3d22f34d884be9ecda80fb1402252
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_SymmetryDlg.cxx
1 // Copyright (C) 2007-2013  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 //  File   : SMESHGUI_SymmetryDlg.cxx
23 //  Author : Michael ZORIN, Open CASCADE S.A.S.
24 //  SMESH includes
25
26 #include "SMESHGUI_SymmetryDlg.h"
27
28 #include "SMESHGUI.h"
29 #include "SMESHGUI_SpinBox.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_IdValidator.h"
34 #include "SMESHGUI_FilterDlg.h"
35 #include "SMESHGUI_MeshEditPreview.h"
36
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_LogicalFilter.hxx>
40 #include <SMDS_Mesh.hxx>
41
42 // SALOME GUI includes
43 #include <SUIT_Desktop.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Session.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_OverrideCursor.h>
48
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
51
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <SALOME_ListIO.hxx>
55 #include <SALOME_ListIteratorOfListIO.hxx>
56
57 // SALOME KERNEL includes
58 #include <SALOMEDSClient.hxx>
59 #include <SALOMEDSClient_SObject.hxx>
60
61 // OCCT includes
62 #include <TColStd_MapOfInteger.hxx>
63
64 // Qt includes
65 #include <QApplication>
66 #include <QButtonGroup>
67 #include <QGroupBox>
68 #include <QLabel>
69 #include <QLineEdit>
70 #include <QPushButton>
71 #include <QRadioButton>
72 #include <QCheckBox>
73 #include <QHBoxLayout>
74 #include <QVBoxLayout>
75 #include <QGridLayout>
76 #include <QKeyEvent>
77
78 // IDL includes
79 #include <SALOMEconfig.h>
80 #include CORBA_SERVER_HEADER(SMESH_Group)
81 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
82
83 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
84
85 #define SPACING 6
86 #define MARGIN  11
87
88 //To disable automatic genericobj management, the following line should be commented.
89 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
90 #define WITHGENERICOBJ
91
92 //=================================================================================
93 // class    : SMESHGUI_SymmetryDlg()
94 // purpose  :
95 //=================================================================================
96
97 SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule )
98   : SMESHGUI_MultiPreviewDlg( theModule ),
99     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
100     myFilterDlg(0)
101 {
102   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_POINT")));
103   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_AXIS")));
104   QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_PLANE")));
105   QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
106
107   setModal(false);
108   setAttribute(Qt::WA_DeleteOnClose, true);
109   setWindowTitle(tr("SMESH_SYMMETRY"));
110   setSizeGripEnabled(true);
111
112   QVBoxLayout* SMESHGUI_SymmetryDlgLayout = new QVBoxLayout(this);
113   SMESHGUI_SymmetryDlgLayout->setSpacing(SPACING);
114   SMESHGUI_SymmetryDlgLayout->setMargin(MARGIN);
115
116   /***************************************************************/
117   ConstructorsBox = new QGroupBox(tr("SMESH_SYMMETRY"), this);
118   GroupConstructors = new QButtonGroup(this);
119   QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
120   ConstructorsBoxLayout->setSpacing(SPACING);
121   ConstructorsBoxLayout->setMargin(MARGIN);
122
123   RadioButton1 = new QRadioButton(ConstructorsBox);
124   RadioButton1->setIcon(image0);
125   RadioButton2 = new QRadioButton(ConstructorsBox);
126   RadioButton2->setIcon(image1);
127   RadioButton3 = new QRadioButton(ConstructorsBox);
128   RadioButton3->setIcon(image2);
129
130   ConstructorsBoxLayout->addWidget(RadioButton1);
131   ConstructorsBoxLayout->addWidget(RadioButton2);
132   ConstructorsBoxLayout->addWidget(RadioButton3);
133   GroupConstructors->addButton(RadioButton1, 0);
134   GroupConstructors->addButton(RadioButton2, 1);
135   GroupConstructors->addButton(RadioButton3, 2);
136
137   /***************************************************************/
138   GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
139   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
140   GroupArgumentsLayout->setSpacing(SPACING);
141   GroupArgumentsLayout->setMargin(MARGIN);
142
143   myIdValidator = new SMESHGUI_IdValidator(this);
144
145   // Controls for elements selection
146   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
147   SelectElementsButton  = new QPushButton(GroupArguments);
148   SelectElementsButton->setIcon(image3);
149   LineEditElements = new QLineEdit(GroupArguments);
150   LineEditElements->setValidator(myIdValidator);
151   LineEditElements->setMaxLength(-1);
152   myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
153   connect(myFilterBtn,   SIGNAL(clicked()), this, SLOT(setFilters()));
154
155   // Control for the whole mesh selection
156   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
157
158   // Controls for mirror selection
159   GroupMirror = new QGroupBox(GroupArguments);
160   QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror);
161   GroupMirrorLayout->setSpacing(SPACING);
162   GroupMirrorLayout->setMargin(MARGIN);
163
164   TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupMirror);
165   SelectPointButton  = new QPushButton(GroupMirror);
166   SelectPointButton->setIcon(image3);
167
168   TextLabelX = new QLabel(tr("SMESH_X"), GroupMirror);
169   SpinBox_X = new SMESHGUI_SpinBox(GroupMirror);
170   TextLabelY = new QLabel(tr("SMESH_Y"), GroupMirror);
171   SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror);
172   TextLabelZ = new QLabel(tr("SMESH_Z"), GroupMirror);
173   SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror);
174
175   TextLabelVector = new QLabel(GroupMirror);
176   SelectVectorButton = new QPushButton(GroupMirror);
177   SelectVectorButton->setIcon(image3);
178
179   TextLabelDX = new QLabel(tr("SMESH_DX"), GroupMirror);
180   SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror);
181   TextLabelDY = new QLabel(tr("SMESH_DY"), GroupMirror);
182   SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror);
183   TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupMirror);
184   SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror);
185
186   GroupMirrorLayout->addWidget(TextLabelPoint,     0, 0);
187   GroupMirrorLayout->addWidget(SelectPointButton,  0, 1);
188   GroupMirrorLayout->addWidget(TextLabelX,         0, 2);
189   GroupMirrorLayout->addWidget(SpinBox_X,          0, 3);
190   GroupMirrorLayout->addWidget(TextLabelY,         0, 4);
191   GroupMirrorLayout->addWidget(SpinBox_Y,          0, 5);
192   GroupMirrorLayout->addWidget(TextLabelZ,         0, 6);
193   GroupMirrorLayout->addWidget(SpinBox_Z,          0, 7);
194   GroupMirrorLayout->addWidget(TextLabelVector,    1, 0);
195   GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
196   GroupMirrorLayout->addWidget(TextLabelDX,        1, 2);
197   GroupMirrorLayout->addWidget(SpinBox_DX,         1, 3);
198   GroupMirrorLayout->addWidget(TextLabelDY,        1, 4);
199   GroupMirrorLayout->addWidget(SpinBox_DY,         1, 5);
200   GroupMirrorLayout->addWidget(TextLabelDZ,        1, 6);
201   GroupMirrorLayout->addWidget(SpinBox_DZ,         1, 7);
202
203   // switch of action type
204   ActionBox = new QGroupBox(GroupArguments);
205   ActionGroup = new QButtonGroup(GroupArguments);
206   QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
207   ActionBoxLayout->addSpacing(SPACING);
208   ActionBoxLayout->setMargin(MARGIN);
209
210   QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
211   QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
212   QRadioButton* aCreateMesh   = new QRadioButton(tr("SMESH_CREATE_MESH"),   ActionBox);
213
214   ActionBoxLayout->addWidget(aMoveElements);
215   ActionBoxLayout->addWidget(aCopyElements);
216   ActionBoxLayout->addWidget(aCreateMesh);
217   ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
218   ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
219   ActionGroup->addButton(aCreateMesh,   MAKE_MESH_BUTTON);
220
221   // CheckBox for groups generation
222   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
223   MakeGroupsCheck->setChecked(false);
224
225   // Name of a mesh to create
226   LineEditNewMesh = new QLineEdit(GroupArguments);
227
228
229   //Preview check box
230   myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
231
232   // layout
233   GroupArgumentsLayout->addWidget(TextLabelElements,    0, 0);
234   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
235   GroupArgumentsLayout->addWidget(LineEditElements,     0, 2, 1, 1);
236   GroupArgumentsLayout->addWidget(myFilterBtn,          0, 3);
237   GroupArgumentsLayout->addWidget(CheckBoxMesh,         1, 0, 1, 4);
238   GroupArgumentsLayout->addWidget(GroupMirror,          2, 0, 1, 4);
239   GroupArgumentsLayout->addWidget(ActionBox,            3, 0, 3, 3);
240   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      4, 3);
241   GroupArgumentsLayout->addWidget(LineEditNewMesh,      5, 3);
242   GroupArgumentsLayout->addWidget(myPreviewCheckBox,    6, 0);
243
244   /***************************************************************/
245   GroupButtons = new QGroupBox(this);
246   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
247   GroupButtonsLayout->setSpacing(SPACING);
248   GroupButtonsLayout->setMargin(MARGIN);
249
250   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
251   buttonOk->setAutoDefault(true);
252   buttonOk->setDefault(true);
253   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
254   buttonApply->setAutoDefault(true);
255   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
256   buttonCancel->setAutoDefault(true);
257   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
258   buttonHelp->setAutoDefault(true);
259
260   GroupButtonsLayout->addWidget(buttonOk);
261   GroupButtonsLayout->addSpacing(10);
262   GroupButtonsLayout->addWidget(buttonApply);
263   GroupButtonsLayout->addSpacing(10);
264   GroupButtonsLayout->addStretch();
265   GroupButtonsLayout->addWidget(buttonCancel);
266   GroupButtonsLayout->addWidget(buttonHelp);
267
268   /***************************************************************/
269   SMESHGUI_SymmetryDlgLayout->addWidget(ConstructorsBox);
270   SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments);
271   SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons);
272
273   /* Initialisations */
274   SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
275   SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
276   SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
277   SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
278   SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
279   SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
280
281   RadioButton1->setChecked(true);
282
283   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
284
285   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
286
287   // Costruction of the logical filter
288   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
289   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (SMESH::GROUP);
290
291   QList<SUIT_SelectionFilter*> aListOfFilters;
292   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
293   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
294
295   myMeshOrSubMeshOrGroupFilter =
296     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
297
298   myHelpFileName = "symmetry_page.html";
299
300   Init();
301
302   /* signals and slots connections */
303   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
304   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
305   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
306   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
307   connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
308
309   connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
310   connect(SelectPointButton,    SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
311   connect(SelectVectorButton,   SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
312
313   connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
314   connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
315   connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
316
317   connect(mySMESHGUI,     SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
318   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),      this, SLOT(SelectionIntoArgument()));
319   /* to close dialog if study change */
320   connect(mySMESHGUI,       SIGNAL(SignalCloseAllDialogs()), this, SLOT(reject()));
321   connect(LineEditElements, SIGNAL(textChanged(const QString&)),   SLOT(onTextChange(const QString&)));
322   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                 SLOT(onSelectMesh(bool)));
323   connect(ActionGroup,      SIGNAL(buttonClicked(int)),            SLOT(onActionClicked(int)));
324
325   connect(SpinBox_X,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326   connect(SpinBox_Y,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
327   connect(SpinBox_Z,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
328   connect(SpinBox_DX,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
329   connect(SpinBox_DY,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
330   connect(SpinBox_DZ,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
331
332   //To Connect preview check box
333   connectPreviewControl();
334
335   ConstructorsClicked(0);
336   SelectionIntoArgument();
337   onActionClicked(MOVE_ELEMS_BUTTON);
338 }
339
340 //=================================================================================
341 // function : ~SMESHGUI_SymmetryDlg()
342 // purpose  : Destroys the object and frees any allocated resources
343 //=================================================================================
344 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
345 {
346   if ( myFilterDlg != 0 ) {
347     myFilterDlg->setParent( 0 );
348     delete myFilterDlg;
349   }
350 }
351
352 //=================================================================================
353 // function : Init()
354 // purpose  :
355 //=================================================================================
356 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
357 {
358   myBusy = false;
359   myMeshes.clear();
360   myObjects.clear();
361   myObjectsNames.clear();
362
363   myEditCurrentArgument = 0;
364   LineEditElements->clear();
365   myElementsId = "";
366   myNbOkElements = 0;
367
368   buttonOk->setEnabled(false);
369   buttonApply->setEnabled(false);
370
371   myActor = 0;
372
373   if (ResetControls) {
374     SpinBox_X->SetValue(0.0);
375     SpinBox_Y->SetValue(0.0);
376     SpinBox_Z->SetValue(0.0);
377     SpinBox_DX->SetValue(0.0);
378     SpinBox_DY->SetValue(0.0);
379     SpinBox_DZ->SetValue(0.0);
380
381     ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
382     CheckBoxMesh->setChecked(false);
383     myPreviewCheckBox->setChecked(false);
384     onDisplaySimulation(false);
385
386 //     MakeGroupsCheck->setChecked(false);
387 //     MakeGroupsCheck->setEnabled(false);
388     onSelectMesh(false);
389   }
390 }
391
392 //=================================================================================
393 // function : ConstructorsClicked()
394 // purpose  : Radio button management
395 //=================================================================================
396 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
397 {
398   disconnect(mySelectionMgr, 0, this, 0);
399
400   if (constructorId != 0 && !TextLabelVector->isVisible()) {
401     TextLabelVector->show();
402     SelectVectorButton->show();
403     TextLabelDX->show();
404     SpinBox_DX->show();
405     TextLabelDY->show();
406     SpinBox_DY->show();
407     TextLabelDZ->show();
408     SpinBox_DZ->show();
409   }
410
411   switch (constructorId) {
412   case 0:
413     {
414       GroupMirror->setTitle(tr("SMESH_POINT"));
415
416       TextLabelVector->hide();
417       SelectVectorButton->hide();
418       TextLabelDX->hide();
419       SpinBox_DX->hide();
420       TextLabelDY->hide();
421       SpinBox_DY->hide();
422       TextLabelDZ->hide();
423       SpinBox_DZ->hide();
424       break;
425     }
426   case 1:
427     {
428       GroupMirror->setTitle(tr("SMESH_AXIS"));
429       TextLabelVector->setText(tr("SMESH_VECTOR"));
430       break;
431     }
432   case 2:
433     {
434       GroupMirror->setTitle(tr("SMESH_PLANE"));
435       TextLabelVector->setText(tr("SMESH_NORMAL"));
436       break;
437     }
438   }
439
440   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
441     SMESH::SetPointRepresentation(false);
442     if (!CheckBoxMesh->isChecked())
443       {
444         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
445           aViewWindow->SetSelectionMode(CellSelection);
446       }
447   }
448
449   myEditCurrentArgument = (QWidget*)LineEditElements;
450   LineEditElements->setFocus();
451
452   if (CheckBoxMesh->isChecked())
453     onSelectMesh(true);
454
455   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
456
457   onDisplaySimulation(true);
458
459   QApplication::instance()->processEvents();
460   updateGeometry();
461   resize(100,100);
462 }
463
464 //=================================================================================
465 // function : ClickOnApply()
466 // purpose  :
467 //=================================================================================
468 bool SMESHGUI_SymmetryDlg::ClickOnApply()
469 {
470   if (mySMESHGUI->isActiveStudyLocked())
471     return false;
472
473   if( !isValid() )
474     return false;
475
476   if (myNbOkElements && IsMirrorOk()) {
477     QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
478
479     SMESH::long_array_var anElementsId = new SMESH::long_array;
480
481     anElementsId->length(aListElementsId.count());
482     for (int i = 0; i < aListElementsId.count(); i++)
483       anElementsId[i] = aListElementsId[i].toInt();
484
485     SMESH::AxisStruct aMirror;
486     SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
487     getMirror(aMirror,aMirrorType);
488
489     QStringList aParameters;
490     aParameters << SpinBox_X->text();
491     aParameters << SpinBox_Y->text();
492     aParameters << SpinBox_Z->text();
493     aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DX->text() );
494     aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DY->text() );
495     aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DZ->text() );
496
497     int actionButton = ActionGroup->checkedId();
498     bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
499     QStringList anEntryList;
500     try {
501       SUIT_OverrideCursor aWaitCursor;
502
503       switch ( actionButton ) {
504       case MOVE_ELEMS_BUTTON: {
505         if(CheckBoxMesh->isChecked())
506           for ( int i = 0; i < myObjects.count(); i++ ) {
507             SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
508             myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
509             aMeshEditor->MirrorObject(myObjects[i], aMirror, aMirrorType, false );
510           }
511         else {
512           SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
513           myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
514           aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
515         }
516         break;
517       }
518       case COPY_ELEMS_BUTTON: {
519         SMESH::ListOfGroups_var groups;
520         if ( makeGroups ) {
521           if(CheckBoxMesh->isChecked())
522             for ( int i = 0; i < myObjects.count(); i++ ) {
523               SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
524               myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
525               groups = aMeshEditor->MirrorObjectMakeGroups(myObjects[i], aMirror, aMirrorType);
526             }
527           else {
528             SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
529             myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
530             groups = aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
531           }
532         }
533         else {
534           if(CheckBoxMesh->isChecked())
535             for ( int i = 0; i < myObjects.count(); i++ ) {
536               SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
537               myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
538               aMeshEditor->MirrorObject(myObjects[i], aMirror, aMirrorType, true);
539             }
540           else {
541             SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
542             myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
543             aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
544           }
545         }
546         break;
547         }
548       case MAKE_MESH_BUTTON: {
549         SMESH::SMESH_Mesh_var mesh;
550         if (CheckBoxMesh->isChecked())
551           for ( int i = 0; i < myObjects.count(); i++ ) {
552             QString aName = SMESH::UniqueMeshName( LineEditNewMesh->text().replace( "*", myObjectsNames[i] ) );
553             SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
554             myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
555             mesh = aMeshEditor->MirrorObjectMakeMesh(myObjects[i], aMirror, aMirrorType, makeGroups,
556                                                      aName.toLatin1().data());
557             if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
558               anEntryList.append( aSObject->GetID().c_str() );
559 #ifdef WITHGENERICOBJ
560             // obj has been published in study. Its refcount has been incremented.
561             // It is safe to decrement its refcount
562             // so that it will be destroyed when the entry in study will be removed
563             mesh->UnRegister();
564 #endif
565           }
566         else {
567           SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
568           myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
569           mesh = aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
570                                              LineEditNewMesh->text().toLatin1().data());
571           if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
572             anEntryList.append( aSObject->GetID().c_str() );
573 #ifdef WITHGENERICOBJ
574           // obj has been published in study. Its refcount has been incremented.
575           // It is safe to decrement its refcount
576           // so that it will be destroyed when the entry in study will be removed
577           mesh->UnRegister();
578 #endif
579         }
580         }
581         break;
582       }
583     } catch (...) {
584     }
585
586     for ( int i = 0; i < myObjects.count(); i++ ) {
587       SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
588       if ( actor ) SMESH::Update( actor->getIO(), true );
589     }
590
591     if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
592          actionButton == MAKE_MESH_BUTTON ) {
593       mySMESHGUI->updateObjBrowser(true); // new groups may appear
594       if( LightApp_Application* anApp =
595           dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
596         anApp->browseObjects( anEntryList, isApplyAndClose() );
597     }
598     Init(false);
599     ConstructorsClicked(GetConstructorId());
600     SelectionIntoArgument();
601
602     SMESHGUI::Modified();
603   }
604   return true;
605 }
606
607 //=================================================================================
608 // function : ClickOnOk()
609 // purpose  :
610 //=================================================================================
611 void SMESHGUI_SymmetryDlg::ClickOnOk()
612 {
613   setIsApplyAndClose( true );
614   if( ClickOnApply() )
615     reject();
616 }
617
618 //=================================================================================
619 // function : reject()
620 // purpose  :
621 //=================================================================================
622 void SMESHGUI_SymmetryDlg::reject()
623 {
624   disconnect(mySelectionMgr, 0, this, 0);
625   mySelectionMgr->clearFilters();
626   //mySelectionMgr->clearSelected();
627   if (SMESH::GetCurrentVtkView()) {
628     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
629     SMESH::SetPointRepresentation(false);
630   }
631   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
632     aViewWindow->SetSelectionMode(ActorSelection);
633   mySMESHGUI->ResetState();
634   QDialog::reject();
635 }
636
637 //=================================================================================
638 // function : ClickOnHelp()
639 // purpose  :
640 //=================================================================================
641 void SMESHGUI_SymmetryDlg::ClickOnHelp()
642 {
643   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
644   if (app)
645     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
646   else {
647     QString platform;
648 #ifdef WIN32
649     platform = "winapplication";
650 #else
651     platform = "application";
652 #endif
653     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
654                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
655                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
656                                                                  platform)).
657                              arg(myHelpFileName));
658   }
659 }
660
661 //=======================================================================
662 // function : onTextChange()
663 // purpose  :
664 //=======================================================================
665 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
666 {
667   QLineEdit* send = (QLineEdit*)sender();
668
669   if (myBusy) return;
670   myBusy = true;
671
672   if (send == LineEditElements)
673     myNbOkElements = 0;
674
675   buttonOk->setEnabled(false);
676   buttonApply->setEnabled(false);
677
678   // hilight entered elements
679   SMDS_Mesh* aMesh = 0;
680   if (myActor)
681     aMesh = myActor->GetObject()->GetMesh();
682
683   if (aMesh) {
684     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
685
686     TColStd_MapOfInteger newIndices;
687
688     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
689
690     if (send == LineEditElements) {
691       for (int i = 0; i < aListId.count(); i++) {
692         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
693         if (e)
694           newIndices.Add(e->GetID());
695         myNbOkElements++;
696       }
697
698       mySelector->AddOrRemoveIndex( anIO, newIndices, false );
699       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
700         aViewWindow->highlight( anIO, true, true );
701
702       myElementsId = theNewText;
703     }
704   }
705
706   if (myNbOkElements &&  IsMirrorOk()) {
707     buttonOk->setEnabled(true);
708     buttonApply->setEnabled(true);
709   }
710
711   myBusy = false;
712 }
713
714 //=================================================================================
715 // function : SelectionIntoArgument()
716 // purpose  : Called when selection as changed or other case
717 //=================================================================================
718 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
719 {
720   if (myBusy) return;
721
722   // clear
723   myActor = 0;
724   QString aString = "";
725   onDisplaySimulation(false);
726
727   myBusy = true;
728   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
729     LineEditElements->setText(aString);
730     myNbOkElements = 0;
731     buttonOk->setEnabled(false);
732     buttonApply->setEnabled(false);
733   }
734   myBusy = false;
735
736   if (!GroupButtons->isEnabled()) // inactive
737     return;
738
739   // get selected mesh
740   SALOME_ListIO aList;
741   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
742
743   int nbSel = aList.Extent();
744   if (nbSel < 1)
745     return;
746
747   int aNbUnits = 0;
748
749   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
750     myElementsId = "";
751     myObjects.clear();
752     myObjectsNames.clear();
753     myMeshes.clear();
754
755     for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
756       Handle(SALOME_InteractiveObject) IO = it.Value();
757       
758       SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
759       if( aMesh->_is_nil() )
760         return;
761
762       myActor = SMESH::FindActorByObject( aMesh );
763       if ( !myActor )
764         myActor = SMESH::FindActorByEntry( IO->getEntry() );
765       if ( !myActor && !CheckBoxMesh->isChecked() )
766         return;
767
768       if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
769         if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
770           _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
771           _PTR(GenericAttribute) anAttr;
772           if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
773             _PTR(AttributeName) aNameAttr( anAttr );
774             myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
775             myObjectsNames << aNameAttr->Value().c_str();
776             myMeshes << aMesh;
777           }
778         }
779       }
780     }
781
782     // MakeGroups is available if there are groups and "Copy"
783       int aNbGroups = 0;
784       for ( int i = 0; i < myMeshes.count(); i++ )
785         aNbGroups += myMeshes[i]->NbGroups();
786       
787     if ( aNbGroups == 0 ) {
788       MakeGroupsCheck->setChecked(false);
789       MakeGroupsCheck->setEnabled(false);
790     }
791     else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
792       MakeGroupsCheck->setEnabled(true);
793     }
794     if (CheckBoxMesh->isChecked()) {
795       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
796
797       if ( myObjects.isEmpty() ) 
798         return;
799       // get IDs from mesh
800       /*
801         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
802         if (!aSMDSMesh)
803           return;
804
805         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
806           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
807           if (e) {
808             myElementsId += QString(" %1").arg(i);
809             aNbUnits++;
810           }
811         }
812       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
813         // get submesh
814         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
815
816         // get IDs from submesh
817         /*
818         SMESH::long_array_var anElementsIds = new SMESH::long_array;
819         anElementsIds = aSubMesh->GetElementsId();
820         for (int i = 0; i < anElementsIds->length(); i++) {
821           myElementsId += QString(" %1").arg(anElementsIds[i]);
822         }
823         aNbUnits = anElementsIds->length();
824       } else { // GROUP
825         // get smesh group
826         SMESH::SMESH_GroupBase_var aGroup =
827           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
828         if (aGroup->_is_nil())
829           return;
830
831         // get IDs from smesh group
832         SMESH::long_array_var anElementsIds = new SMESH::long_array;
833         anElementsIds = aGroup->GetListOfID();
834         for (int i = 0; i < anElementsIds->length(); i++) {
835           myElementsId += QString(" %1").arg(anElementsIds[i]);
836         }
837         aNbUnits = anElementsIds->length();
838       }
839       */
840     } else {
841       aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, aList.First(), aString);
842       myElementsId = aString;
843       if (aNbUnits < 1)
844         return;
845     }
846
847     myNbOkElements = true;
848   } else {
849     Handle(SALOME_InteractiveObject) IO = aList.First();
850     if ((SMESH::GetMeshByIO(IO))->_is_nil())
851       return;
852
853     SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
854     if (!anActor)
855       anActor = SMESH::FindActorByEntry(IO->getEntry());
856     if (!anActor && !CheckBoxMesh->isChecked())
857       return;
858
859     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
860     if (aNbUnits != 1)
861       return;
862
863     SMDS_Mesh* aMesh =  anActor->GetObject()->GetMesh();
864     if (!aMesh)
865       return;
866
867     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
868     if (!n)
869       return;
870
871     double x = n->X();
872     double y = n->Y();
873     double z = n->Z();
874
875     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
876       SpinBox_X->SetValue(x);
877       SpinBox_Y->SetValue(y);
878       SpinBox_Z->SetValue(z);
879     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
880       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
881       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
882       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
883     }
884   }
885
886   myBusy = true;
887   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
888     LineEditElements->setText(aString);
889     LineEditElements->repaint();
890     LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
891     LineEditElements->setEnabled(true);
892     setNewMeshName();
893   }
894   myBusy = false;
895
896   // OK
897   if (myNbOkElements && IsMirrorOk()) {
898     buttonOk->setEnabled(true);
899     buttonApply->setEnabled(true);
900   }
901   onDisplaySimulation(true);
902 }
903
904 //=================================================================================
905 // function : SetEditCurrentArgument()
906 // purpose  :
907 //=================================================================================
908 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
909 {
910   QPushButton* send = (QPushButton*)sender();
911
912   disconnect(mySelectionMgr, 0, this, 0);
913   mySelectionMgr->clearSelected();
914   mySelectionMgr->clearFilters();
915
916   if (send == SelectElementsButton) {
917     myEditCurrentArgument = (QWidget*)LineEditElements;
918     SMESH::SetPointRepresentation(false);
919     if (CheckBoxMesh->isChecked()) {
920       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
921         aViewWindow->SetSelectionMode(ActorSelection);
922       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
923     } else {
924       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
925         aViewWindow->SetSelectionMode(CellSelection);
926     }
927   } else if (send == SelectPointButton) {
928     myEditCurrentArgument = (QWidget*)SpinBox_X;
929     SMESH::SetPointRepresentation(true);
930     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
931       aViewWindow->SetSelectionMode(NodeSelection);
932   } else if (send == SelectVectorButton) {
933     myEditCurrentArgument = (QWidget*)SpinBox_DX;
934     SMESH::SetPointRepresentation(true);
935
936     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
937       aViewWindow->SetSelectionMode(NodeSelection);
938   } else {
939   }
940
941   myEditCurrentArgument->setFocus();
942   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
943   SelectionIntoArgument();
944 }
945
946 //=================================================================================
947 // function : DeactivateActiveDialog()
948 // purpose  :
949 //=================================================================================
950 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
951 {
952   if (ConstructorsBox->isEnabled()) {
953     ConstructorsBox->setEnabled(false);
954     GroupArguments->setEnabled(false);
955     GroupButtons->setEnabled(false);
956     mySMESHGUI->ResetState();
957     mySMESHGUI->SetActiveDialogBox(0);
958   }
959 }
960
961 //=================================================================================
962 // function : ActivateThisDialog()
963 // purpose  :
964 //=================================================================================
965 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
966 {
967   /* Emit a signal to deactivate the active dialog */
968   mySMESHGUI->EmitSignalDeactivateDialog();
969   ConstructorsBox->setEnabled(true);
970   GroupArguments->setEnabled(true);
971   GroupButtons->setEnabled(true);
972
973   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
974
975   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
976     aViewWindow->SetSelectionMode(CellSelection);
977   SelectionIntoArgument();
978 }
979
980 //=================================================================================
981 // function : enterEvent()
982 // purpose  :
983 //=================================================================================
984 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
985 {
986   if (!ConstructorsBox->isEnabled())
987     ActivateThisDialog();
988 }
989
990 //=======================================================================
991 //function : onSelectMesh
992 //purpose  :
993 //=======================================================================
994 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
995 {
996   if (toSelectMesh)
997     TextLabelElements->setText(tr("SMESH_NAME"));
998   else
999     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
1000   myFilterBtn->setEnabled(!toSelectMesh);
1001
1002   if (myEditCurrentArgument != LineEditElements) {
1003     LineEditElements->clear();
1004     return;
1005   }
1006
1007   mySelectionMgr->clearFilters();
1008   SMESH::SetPointRepresentation(false);
1009
1010   if (toSelectMesh) {
1011     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1012       aViewWindow->SetSelectionMode(ActorSelection);
1013     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1014     LineEditElements->setReadOnly(true);
1015     LineEditElements->setValidator(0);
1016   } else {
1017     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1018       aViewWindow->SetSelectionMode(CellSelection);
1019     LineEditElements->setReadOnly(false);
1020     LineEditElements->setValidator(myIdValidator);
1021     onTextChange(LineEditElements->text());
1022     hidePreview();
1023   }
1024
1025   SelectionIntoArgument();
1026 }
1027
1028 //=================================================================================
1029 // function : GetConstructorId()
1030 // purpose  :
1031 //=================================================================================
1032 int SMESHGUI_SymmetryDlg::GetConstructorId()
1033 {
1034   return GroupConstructors->checkedId();
1035 }
1036
1037 //=================================================================================
1038 // function : IsMirrorOk()
1039 // purpose  :
1040 //=================================================================================
1041 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
1042 {
1043   bool isOk = true;
1044
1045   if (GetConstructorId() != 0)
1046     isOk = (SpinBox_DX->GetValue() != 0 ||
1047             SpinBox_DY->GetValue() != 0 ||
1048             SpinBox_DZ->GetValue() != 0);
1049
1050   return isOk;
1051 }
1052
1053 //=================================================================================
1054 // function : onVectorChanged()
1055 // purpose  :
1056 //=================================================================================
1057 void SMESHGUI_SymmetryDlg::onVectorChanged()
1058 {
1059   if (IsMirrorOk()) {
1060     buttonOk->setEnabled(true);
1061     buttonApply->setEnabled(true);
1062   } else {
1063     buttonOk->setEnabled(false);
1064     buttonApply->setEnabled(false);
1065   }
1066 }
1067
1068 //=======================================================================
1069 //function : onActionClicked
1070 //purpose  : slot called when an action type changed
1071 //=======================================================================
1072
1073 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
1074 {
1075   int aNbGroups = 0;
1076   for ( int i = 0; i < myMeshes.count(); i++ )
1077     aNbGroups += myMeshes[i]->NbGroups();
1078
1079   switch ( button ) {
1080   case MOVE_ELEMS_BUTTON:
1081     MakeGroupsCheck->setEnabled(false);
1082     LineEditNewMesh->setEnabled(false);
1083     break;
1084   case COPY_ELEMS_BUTTON:
1085     LineEditNewMesh->setEnabled(false);
1086     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1087     MakeGroupsCheck->setEnabled(myMeshes.isEmpty() || aNbGroups > 0);
1088     break;
1089   case MAKE_MESH_BUTTON:
1090     LineEditNewMesh->setEnabled(true);
1091     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1092     MakeGroupsCheck->setEnabled(myMeshes.isEmpty() || aNbGroups > 0);
1093     break;
1094   }
1095   setNewMeshName();
1096   toDisplaySimulation();
1097 }
1098
1099 //=======================================================================
1100 //function : setNewMeshName
1101 //purpose  : update contents of LineEditNewMesh
1102 //=======================================================================
1103
1104 void SMESHGUI_SymmetryDlg::setNewMeshName()
1105 {
1106   LineEditNewMesh->setText("");
1107   if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1108     QString name;
1109     if ( CheckBoxMesh->isChecked() ) {
1110       name = myObjects.count() > 1 ? "*" : LineEditElements->text();
1111     }
1112     else {
1113       _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1114       name = meshSO->GetName().c_str();
1115     }
1116     if ( !name.isEmpty() )
1117       LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
1118   }
1119 }
1120
1121 //=================================================================================
1122 // function : keyPressEvent()
1123 // purpose  :
1124 //=================================================================================
1125 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1126 {
1127   QDialog::keyPressEvent( e );
1128   if ( e->isAccepted() )
1129     return;
1130
1131   if ( e->key() == Qt::Key_F1 ) {
1132     e->accept();
1133     ClickOnHelp();
1134   }
1135 }
1136
1137 //=================================================================================
1138 // function : setFilters()
1139 // purpose  : SLOT. Called when "Filter" button pressed.
1140 //=================================================================================
1141 void SMESHGUI_SymmetryDlg::setFilters()
1142 {
1143   if(myMeshes.isEmpty()) {
1144     SUIT_MessageBox::critical(this,
1145                               tr("SMESH_ERROR"),
1146                               tr("NO_MESH_SELECTED"));
1147    return;
1148   }
1149   if ( !myFilterDlg )
1150     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1151
1152   myFilterDlg->SetSelection();
1153   myFilterDlg->SetMesh( myMeshes[0] );
1154   myFilterDlg->SetSourceWg( LineEditElements );
1155
1156   myFilterDlg->show();
1157 }
1158
1159 //=================================================================================
1160 // function : isValid
1161 // purpose  :
1162 //=================================================================================
1163 bool SMESHGUI_SymmetryDlg::isValid()
1164 {
1165   bool ok = true;
1166   QString msg;
1167
1168   ok = SpinBox_X->isValid( msg, true ) && ok;
1169   ok = SpinBox_Y->isValid( msg, true ) && ok;
1170   ok = SpinBox_Z->isValid( msg, true ) && ok;
1171   if (GetConstructorId() != 0) {
1172     ok = SpinBox_DX->isValid( msg, true ) && ok;
1173     ok = SpinBox_DY->isValid( msg, true ) && ok;
1174     ok = SpinBox_DZ->isValid( msg, true ) && ok;
1175   }
1176
1177   if( !ok ) {
1178     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1179     if ( !msg.isEmpty() )
1180       str += "\n" + msg;
1181     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1182     return false;
1183   }
1184   return true;
1185 }
1186
1187 //=================================================================================
1188 // function : onDisplaySimulation
1189 // purpose  : Show/Hide preview
1190 //=================================================================================
1191 void SMESHGUI_SymmetryDlg::onDisplaySimulation( bool toDisplayPreview ) {
1192   if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1193     if ( myNbOkElements && isValid() && IsMirrorOk() ) {
1194       QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);      
1195       SMESH::long_array_var anElementsId = new SMESH::long_array;
1196
1197       anElementsId->length(aListElementsId.count());
1198       for (int i = 0; i < aListElementsId.count(); i++)
1199         anElementsId[i] = aListElementsId[i].toInt();
1200
1201       SMESH::AxisStruct aMirror;
1202       SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
1203       
1204       getMirror(aMirror,aMirrorType);
1205
1206       try {
1207         bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1208                       ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1209         SUIT_OverrideCursor aWaitCursor;
1210         QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1211         if(CheckBoxMesh->isChecked())
1212           for ( int i = 0; i < myMeshes.count(); i++ ) {
1213             SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1214             aMeshEditor->MirrorObject(myObjects[i], aMirror, aMirrorType, copy );
1215             aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1216           }
1217         else {
1218           SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1219           aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, copy );        
1220           aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1221         }
1222         setSimulationPreview(aMeshPreviewStruct);
1223       } catch (...) {
1224         hidePreview();
1225       }
1226     } else {
1227       hidePreview();
1228     } 
1229   } else {
1230     hidePreview();
1231   }
1232 }
1233
1234 //=================================================================================
1235 // function : getMirror
1236 // purpose  : return mirror parameters
1237 //=================================================================================
1238 void SMESHGUI_SymmetryDlg::getMirror(SMESH::AxisStruct& theMirror, SMESH::SMESH_MeshEditor::MirrorType& theMirrorType) {
1239   theMirror.x =  SpinBox_X->GetValue();
1240   theMirror.y =  SpinBox_Y->GetValue();
1241   theMirror.z =  SpinBox_Z->GetValue();
1242   if (GetConstructorId() == 0) {
1243     theMirror.vx = theMirror.vy = theMirror.vz = 0;
1244   } else {
1245     theMirror.vx = SpinBox_DX->GetValue();
1246     theMirror.vy = SpinBox_DY->GetValue();
1247     theMirror.vz = SpinBox_DZ->GetValue();
1248   }
1249   if (GetConstructorId() == 0)
1250     theMirrorType = SMESH::SMESH_MeshEditor::POINT;
1251   if (GetConstructorId() == 1)
1252     theMirrorType = SMESH::SMESH_MeshEditor::AXIS;
1253   if (GetConstructorId() == 2)
1254     theMirrorType = SMESH::SMESH_MeshEditor::PLANE;
1255 }