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