Salome HOME
64d335709298e9442f21d230357b2d4b4a4c1ab5
[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 < myMeshes.count(); i++ )
587       SMESH::Update( (SMESH::FindActorByObject( myMeshes[i] ))->getIO(), true );
588
589     if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
590          actionButton == MAKE_MESH_BUTTON ) {
591       mySMESHGUI->updateObjBrowser(true); // new groups may appear
592       if( LightApp_Application* anApp =
593           dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
594         anApp->browseObjects( anEntryList, isApplyAndClose() );
595     }
596     Init(false);
597     ConstructorsClicked(GetConstructorId());
598     SelectionIntoArgument();
599
600     SMESHGUI::Modified();
601   }
602   return true;
603 }
604
605 //=================================================================================
606 // function : ClickOnOk()
607 // purpose  :
608 //=================================================================================
609 void SMESHGUI_SymmetryDlg::ClickOnOk()
610 {
611   setIsApplyAndClose( true );
612   if( ClickOnApply() )
613     reject();
614 }
615
616 //=================================================================================
617 // function : reject()
618 // purpose  :
619 //=================================================================================
620 void SMESHGUI_SymmetryDlg::reject()
621 {
622   disconnect(mySelectionMgr, 0, this, 0);
623   mySelectionMgr->clearFilters();
624   //mySelectionMgr->clearSelected();
625   if (SMESH::GetCurrentVtkView()) {
626     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
627     SMESH::SetPointRepresentation(false);
628   }
629   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
630     aViewWindow->SetSelectionMode(ActorSelection);
631   mySMESHGUI->ResetState();
632   QDialog::reject();
633 }
634
635 //=================================================================================
636 // function : ClickOnHelp()
637 // purpose  :
638 //=================================================================================
639 void SMESHGUI_SymmetryDlg::ClickOnHelp()
640 {
641   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
642   if (app)
643     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
644   else {
645     QString platform;
646 #ifdef WIN32
647     platform = "winapplication";
648 #else
649     platform = "application";
650 #endif
651     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
652                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
653                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
654                                                                  platform)).
655                              arg(myHelpFileName));
656   }
657 }
658
659 //=======================================================================
660 // function : onTextChange()
661 // purpose  :
662 //=======================================================================
663 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
664 {
665   QLineEdit* send = (QLineEdit*)sender();
666
667   if (myBusy) return;
668   myBusy = true;
669
670   if (send == LineEditElements)
671     myNbOkElements = 0;
672
673   buttonOk->setEnabled(false);
674   buttonApply->setEnabled(false);
675
676   // hilight entered elements
677   SMDS_Mesh* aMesh = 0;
678   if (myActor)
679     aMesh = myActor->GetObject()->GetMesh();
680
681   if (aMesh) {
682     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
683
684     TColStd_MapOfInteger newIndices;
685
686     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
687
688     if (send == LineEditElements) {
689       for (int i = 0; i < aListId.count(); i++) {
690         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
691         if (e)
692           newIndices.Add(e->GetID());
693         myNbOkElements++;
694       }
695
696       mySelector->AddOrRemoveIndex( anIO, newIndices, false );
697       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
698         aViewWindow->highlight( anIO, true, true );
699
700       myElementsId = theNewText;
701     }
702   }
703
704   if (myNbOkElements &&  IsMirrorOk()) {
705     buttonOk->setEnabled(true);
706     buttonApply->setEnabled(true);
707   }
708
709   myBusy = false;
710 }
711
712 //=================================================================================
713 // function : SelectionIntoArgument()
714 // purpose  : Called when selection as changed or other case
715 //=================================================================================
716 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
717 {
718   if (myBusy) return;
719
720   // clear
721   myActor = 0;
722   QString aString = "";
723   onDisplaySimulation(false);
724
725   myBusy = true;
726   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
727     LineEditElements->setText(aString);
728     myNbOkElements = 0;
729     buttonOk->setEnabled(false);
730     buttonApply->setEnabled(false);
731   }
732   myBusy = false;
733
734   if (!GroupButtons->isEnabled()) // inactive
735     return;
736
737   // get selected mesh
738   SALOME_ListIO aList;
739   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
740
741   int nbSel = aList.Extent();
742   if (nbSel < 1)
743     return;
744
745   int aNbUnits = 0;
746
747   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
748     myElementsId = "";
749     myObjects.clear();
750     myObjectsNames.clear();
751     myMeshes.clear();
752
753     for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
754       Handle(SALOME_InteractiveObject) IO = it.Value();
755       
756       SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
757       if( aMesh->_is_nil() )
758         return;
759
760       myActor = SMESH::FindActorByObject( aMesh );
761       if ( !myActor )
762         myActor = SMESH::FindActorByEntry( IO->getEntry() );
763       if ( !myActor && !CheckBoxMesh->isChecked() )
764         return;
765
766       if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
767         if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
768           _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
769           _PTR(GenericAttribute) anAttr;
770           if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
771             _PTR(AttributeName) aNameAttr( anAttr );
772             myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
773             myObjectsNames << aNameAttr->Value().c_str();
774             myMeshes << aMesh;
775           }
776         }
777       }
778     }
779
780     // MakeGroups is available if there are groups and "Copy"
781       int aNbGroups = 0;
782       for ( int i = 0; i < myMeshes.count(); i++ )
783         aNbGroups += myMeshes[i]->NbGroups();
784       
785     if ( aNbGroups == 0 ) {
786       MakeGroupsCheck->setChecked(false);
787       MakeGroupsCheck->setEnabled(false);
788     }
789     else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
790       MakeGroupsCheck->setEnabled(true);
791     }
792     if (CheckBoxMesh->isChecked()) {
793       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
794
795       if ( myObjects.isEmpty() ) 
796         return;
797       // get IDs from mesh
798       /*
799         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
800         if (!aSMDSMesh)
801           return;
802
803         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
804           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
805           if (e) {
806             myElementsId += QString(" %1").arg(i);
807             aNbUnits++;
808           }
809         }
810       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
811         // get submesh
812         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
813
814         // get IDs from submesh
815         /*
816         SMESH::long_array_var anElementsIds = new SMESH::long_array;
817         anElementsIds = aSubMesh->GetElementsId();
818         for (int i = 0; i < anElementsIds->length(); i++) {
819           myElementsId += QString(" %1").arg(anElementsIds[i]);
820         }
821         aNbUnits = anElementsIds->length();
822       } else { // GROUP
823         // get smesh group
824         SMESH::SMESH_GroupBase_var aGroup =
825           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
826         if (aGroup->_is_nil())
827           return;
828
829         // get IDs from smesh group
830         SMESH::long_array_var anElementsIds = new SMESH::long_array;
831         anElementsIds = aGroup->GetListOfID();
832         for (int i = 0; i < anElementsIds->length(); i++) {
833           myElementsId += QString(" %1").arg(anElementsIds[i]);
834         }
835         aNbUnits = anElementsIds->length();
836       }
837       */
838     } else {
839       aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, aList.First(), aString);
840       myElementsId = aString;
841       if (aNbUnits < 1)
842         return;
843     }
844
845     myNbOkElements = true;
846   } else {
847     Handle(SALOME_InteractiveObject) IO = aList.First();
848     if ((SMESH::GetMeshByIO(IO))->_is_nil())
849       return;
850
851     SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
852     if (!anActor)
853       anActor = SMESH::FindActorByEntry(IO->getEntry());
854     if (!anActor && !CheckBoxMesh->isChecked())
855       return;
856
857     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
858     if (aNbUnits != 1)
859       return;
860
861     SMDS_Mesh* aMesh =  anActor->GetObject()->GetMesh();
862     if (!aMesh)
863       return;
864
865     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
866     if (!n)
867       return;
868
869     double x = n->X();
870     double y = n->Y();
871     double z = n->Z();
872
873     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
874       SpinBox_X->SetValue(x);
875       SpinBox_Y->SetValue(y);
876       SpinBox_Z->SetValue(z);
877     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
878       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
879       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
880       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
881     }
882   }
883
884   myBusy = true;
885   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
886     LineEditElements->setText(aString);
887     LineEditElements->repaint();
888     LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
889     LineEditElements->setEnabled(true);
890     setNewMeshName();
891   }
892   myBusy = false;
893
894   // OK
895   if (myNbOkElements && IsMirrorOk()) {
896     buttonOk->setEnabled(true);
897     buttonApply->setEnabled(true);
898   }
899   onDisplaySimulation(true);
900 }
901
902 //=================================================================================
903 // function : SetEditCurrentArgument()
904 // purpose  :
905 //=================================================================================
906 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
907 {
908   QPushButton* send = (QPushButton*)sender();
909
910   disconnect(mySelectionMgr, 0, this, 0);
911   mySelectionMgr->clearSelected();
912   mySelectionMgr->clearFilters();
913
914   if (send == SelectElementsButton) {
915     myEditCurrentArgument = (QWidget*)LineEditElements;
916     SMESH::SetPointRepresentation(false);
917     if (CheckBoxMesh->isChecked()) {
918       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
919         aViewWindow->SetSelectionMode(ActorSelection);
920       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
921     } else {
922       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
923         aViewWindow->SetSelectionMode(CellSelection);
924     }
925   } else if (send == SelectPointButton) {
926     myEditCurrentArgument = (QWidget*)SpinBox_X;
927     SMESH::SetPointRepresentation(true);
928     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
929       aViewWindow->SetSelectionMode(NodeSelection);
930   } else if (send == SelectVectorButton) {
931     myEditCurrentArgument = (QWidget*)SpinBox_DX;
932     SMESH::SetPointRepresentation(true);
933
934     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
935       aViewWindow->SetSelectionMode(NodeSelection);
936   } else {
937   }
938
939   myEditCurrentArgument->setFocus();
940   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
941   SelectionIntoArgument();
942 }
943
944 //=================================================================================
945 // function : DeactivateActiveDialog()
946 // purpose  :
947 //=================================================================================
948 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
949 {
950   if (ConstructorsBox->isEnabled()) {
951     ConstructorsBox->setEnabled(false);
952     GroupArguments->setEnabled(false);
953     GroupButtons->setEnabled(false);
954     mySMESHGUI->ResetState();
955     mySMESHGUI->SetActiveDialogBox(0);
956   }
957 }
958
959 //=================================================================================
960 // function : ActivateThisDialog()
961 // purpose  :
962 //=================================================================================
963 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
964 {
965   /* Emit a signal to deactivate the active dialog */
966   mySMESHGUI->EmitSignalDeactivateDialog();
967   ConstructorsBox->setEnabled(true);
968   GroupArguments->setEnabled(true);
969   GroupButtons->setEnabled(true);
970
971   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
972
973   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
974     aViewWindow->SetSelectionMode(CellSelection);
975   SelectionIntoArgument();
976 }
977
978 //=================================================================================
979 // function : enterEvent()
980 // purpose  :
981 //=================================================================================
982 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
983 {
984   if (!ConstructorsBox->isEnabled())
985     ActivateThisDialog();
986 }
987
988 //=======================================================================
989 //function : onSelectMesh
990 //purpose  :
991 //=======================================================================
992 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
993 {
994   if (toSelectMesh)
995     TextLabelElements->setText(tr("SMESH_NAME"));
996   else
997     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
998   myFilterBtn->setEnabled(!toSelectMesh);
999
1000   if (myEditCurrentArgument != LineEditElements) {
1001     LineEditElements->clear();
1002     return;
1003   }
1004
1005   mySelectionMgr->clearFilters();
1006   SMESH::SetPointRepresentation(false);
1007
1008   if (toSelectMesh) {
1009     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1010       aViewWindow->SetSelectionMode(ActorSelection);
1011     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1012     LineEditElements->setReadOnly(true);
1013     LineEditElements->setValidator(0);
1014   } else {
1015     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1016       aViewWindow->SetSelectionMode(CellSelection);
1017     LineEditElements->setReadOnly(false);
1018     LineEditElements->setValidator(myIdValidator);
1019     onTextChange(LineEditElements->text());
1020     hidePreview();
1021   }
1022
1023   SelectionIntoArgument();
1024 }
1025
1026 //=================================================================================
1027 // function : GetConstructorId()
1028 // purpose  :
1029 //=================================================================================
1030 int SMESHGUI_SymmetryDlg::GetConstructorId()
1031 {
1032   return GroupConstructors->checkedId();
1033 }
1034
1035 //=================================================================================
1036 // function : IsMirrorOk()
1037 // purpose  :
1038 //=================================================================================
1039 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
1040 {
1041   bool isOk = true;
1042
1043   if (GetConstructorId() != 0)
1044     isOk = (SpinBox_DX->GetValue() != 0 ||
1045             SpinBox_DY->GetValue() != 0 ||
1046             SpinBox_DZ->GetValue() != 0);
1047
1048   return isOk;
1049 }
1050
1051 //=================================================================================
1052 // function : onVectorChanged()
1053 // purpose  :
1054 //=================================================================================
1055 void SMESHGUI_SymmetryDlg::onVectorChanged()
1056 {
1057   if (IsMirrorOk()) {
1058     buttonOk->setEnabled(true);
1059     buttonApply->setEnabled(true);
1060   } else {
1061     buttonOk->setEnabled(false);
1062     buttonApply->setEnabled(false);
1063   }
1064 }
1065
1066 //=======================================================================
1067 //function : onActionClicked
1068 //purpose  : slot called when an action type changed
1069 //=======================================================================
1070
1071 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
1072 {
1073   int aNbGroups = 0;
1074   for ( int i = 0; i < myMeshes.count(); i++ )
1075     aNbGroups += myMeshes[i]->NbGroups();
1076
1077   switch ( button ) {
1078   case MOVE_ELEMS_BUTTON:
1079     MakeGroupsCheck->setEnabled(false);
1080     LineEditNewMesh->setEnabled(false);
1081     break;
1082   case COPY_ELEMS_BUTTON:
1083     LineEditNewMesh->setEnabled(false);
1084     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1085     MakeGroupsCheck->setEnabled(myMeshes.isEmpty() || aNbGroups > 0);
1086     break;
1087   case MAKE_MESH_BUTTON:
1088     LineEditNewMesh->setEnabled(true);
1089     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1090     MakeGroupsCheck->setEnabled(myMeshes.isEmpty() || aNbGroups > 0);
1091     break;
1092   }
1093   setNewMeshName();
1094   toDisplaySimulation();
1095 }
1096
1097 //=======================================================================
1098 //function : setNewMeshName
1099 //purpose  : update contents of LineEditNewMesh
1100 //=======================================================================
1101
1102 void SMESHGUI_SymmetryDlg::setNewMeshName()
1103 {
1104   LineEditNewMesh->setText("");
1105   if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1106     QString name;
1107     if ( CheckBoxMesh->isChecked() ) {
1108       name = myObjects.count() > 1 ? "*" : LineEditElements->text();
1109     }
1110     else {
1111       _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1112       name = meshSO->GetName().c_str();
1113     }
1114     if ( !name.isEmpty() )
1115       LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
1116   }
1117 }
1118
1119 //=================================================================================
1120 // function : keyPressEvent()
1121 // purpose  :
1122 //=================================================================================
1123 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1124 {
1125   QDialog::keyPressEvent( e );
1126   if ( e->isAccepted() )
1127     return;
1128
1129   if ( e->key() == Qt::Key_F1 ) {
1130     e->accept();
1131     ClickOnHelp();
1132   }
1133 }
1134
1135 //=================================================================================
1136 // function : setFilters()
1137 // purpose  : SLOT. Called when "Filter" button pressed.
1138 //=================================================================================
1139 void SMESHGUI_SymmetryDlg::setFilters()
1140 {
1141   if(myMeshes.isEmpty()) {
1142     SUIT_MessageBox::critical(this,
1143                               tr("SMESH_ERROR"),
1144                               tr("NO_MESH_SELECTED"));
1145    return;
1146   }
1147   if ( !myFilterDlg )
1148     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1149
1150   myFilterDlg->SetSelection();
1151   myFilterDlg->SetMesh( myMeshes[0] );
1152   myFilterDlg->SetSourceWg( LineEditElements );
1153
1154   myFilterDlg->show();
1155 }
1156
1157 //=================================================================================
1158 // function : isValid
1159 // purpose  :
1160 //=================================================================================
1161 bool SMESHGUI_SymmetryDlg::isValid()
1162 {
1163   bool ok = true;
1164   QString msg;
1165
1166   ok = SpinBox_X->isValid( msg, true ) && ok;
1167   ok = SpinBox_Y->isValid( msg, true ) && ok;
1168   ok = SpinBox_Z->isValid( msg, true ) && ok;
1169   if (GetConstructorId() != 0) {
1170     ok = SpinBox_DX->isValid( msg, true ) && ok;
1171     ok = SpinBox_DY->isValid( msg, true ) && ok;
1172     ok = SpinBox_DZ->isValid( msg, true ) && ok;
1173   }
1174
1175   if( !ok ) {
1176     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1177     if ( !msg.isEmpty() )
1178       str += "\n" + msg;
1179     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1180     return false;
1181   }
1182   return true;
1183 }
1184
1185 //=================================================================================
1186 // function : onDisplaySimulation
1187 // purpose  : Show/Hide preview
1188 //=================================================================================
1189 void SMESHGUI_SymmetryDlg::onDisplaySimulation( bool toDisplayPreview ) {
1190   if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1191     if ( myNbOkElements && isValid() && IsMirrorOk() ) {
1192       QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);      
1193       SMESH::long_array_var anElementsId = new SMESH::long_array;
1194
1195       anElementsId->length(aListElementsId.count());
1196       for (int i = 0; i < aListElementsId.count(); i++)
1197         anElementsId[i] = aListElementsId[i].toInt();
1198
1199       SMESH::AxisStruct aMirror;
1200       SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
1201       
1202       getMirror(aMirror,aMirrorType);
1203
1204       try {
1205         bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1206                       ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1207         SUIT_OverrideCursor aWaitCursor;
1208         QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1209         if(CheckBoxMesh->isChecked())
1210           for ( int i = 0; i < myMeshes.count(); i++ ) {
1211             SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1212             aMeshEditor->MirrorObject(myObjects[i], aMirror, aMirrorType, copy );
1213             aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1214           }
1215         else {
1216           SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1217           aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, copy );        
1218           aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1219         }
1220         setSimulationPreview(aMeshPreviewStruct);
1221       } catch (...) {
1222         hidePreview();
1223       }
1224     } else {
1225       hidePreview();
1226     } 
1227   } else {
1228     hidePreview();
1229   }
1230 }
1231
1232 //=================================================================================
1233 // function : getMirror
1234 // purpose  : return mirror parameters
1235 //=================================================================================
1236 void SMESHGUI_SymmetryDlg::getMirror(SMESH::AxisStruct& theMirror, SMESH::SMESH_MeshEditor::MirrorType& theMirrorType) {
1237   theMirror.x =  SpinBox_X->GetValue();
1238   theMirror.y =  SpinBox_Y->GetValue();
1239   theMirror.z =  SpinBox_Z->GetValue();
1240   if (GetConstructorId() == 0) {
1241     theMirror.vx = theMirror.vy = theMirror.vz = 0;
1242   } else {
1243     theMirror.vx = SpinBox_DX->GetValue();
1244     theMirror.vy = SpinBox_DY->GetValue();
1245     theMirror.vz = SpinBox_DZ->GetValue();
1246   }
1247   if (GetConstructorId() == 0)
1248     theMirrorType = SMESH::SMESH_MeshEditor::POINT;
1249   if (GetConstructorId() == 1)
1250     theMirrorType = SMESH::SMESH_MeshEditor::AXIS;
1251   if (GetConstructorId() == 2)
1252     theMirrorType = SMESH::SMESH_MeshEditor::PLANE;
1253 }