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