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