]> SALOME platform Git repositories - modules/smesh.git/blob - src/SMESHGUI/SMESHGUI_SymmetryDlg.cxx
Salome HOME
Improve dump python.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_SymmetryDlg.cxx
1 // SMESH SMESHGUI : GUI for SMESH component
2 //
3 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 //
6 // This library is free software; you can redistribute it and/or 
7 // modify it under the terms of the GNU Lesser General Public 
8 // License as published by the Free Software Foundation; either 
9 // version 2.1 of the License. 
10 //
11 // This library is distributed in the hope that it will be useful, 
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 // Lesser General Public License for more details. 
15 //
16 // You should have received a copy of the GNU Lesser General Public 
17 // License along with this library; if not, write to the Free Software 
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : SMESHGUI_SymmetryDlg.cxx
23 // Author : Michael ZORIN, Open CASCADE S.A.S.
24 //
25
26 // SMESH includes
27 #include "SMESHGUI_SymmetryDlg.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_IdValidator.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_SObject.hxx>
57
58 // OCCT includes
59 #include <TColStd_MapOfInteger.hxx>
60
61 // Qt includes
62 #include <QApplication>
63 #include <QButtonGroup>
64 #include <QGroupBox>
65 #include <QLabel>
66 #include <QLineEdit>
67 #include <QPushButton>
68 #include <QRadioButton>
69 #include <QCheckBox>
70 #include <QHBoxLayout>
71 #include <QVBoxLayout>
72 #include <QGridLayout>
73 #include <QKeyEvent>
74
75 // IDL includes
76 #include <SALOMEconfig.h>
77 #include CORBA_SERVER_HEADER(SMESH_Group)
78 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
79
80 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
81
82 #define SPACING 6
83 #define MARGIN  11
84
85 //=================================================================================
86 // class    : SMESHGUI_SymmetryDlg()
87 // purpose  :
88 //=================================================================================
89
90 SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule )
91   : QDialog( SMESH::GetDesktop( theModule ) ),
92     mySMESHGUI( theModule ),
93     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
94     mySelectedObject(SMESH::SMESH_IDSource::_nil())
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
146   // Control for the whole mesh selection
147   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
148
149   // Controls for mirror selection
150   GroupMirror = new QGroupBox(GroupArguments);
151   QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror);
152   GroupMirrorLayout->setSpacing(SPACING);
153   GroupMirrorLayout->setMargin(MARGIN);
154
155   TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupMirror);
156   SelectPointButton  = new QPushButton(GroupMirror);
157   SelectPointButton->setIcon(image3);
158
159   TextLabelX = new QLabel(tr("SMESH_X"), GroupMirror);
160   SpinBox_X = new SMESHGUI_SpinBox(GroupMirror);
161   TextLabelY = new QLabel(tr("SMESH_Y"), GroupMirror);
162   SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror);
163   TextLabelZ = new QLabel(tr("SMESH_Z"), GroupMirror);
164   SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror);
165
166   TextLabelVector = new QLabel(GroupMirror);
167   SelectVectorButton = new QPushButton(GroupMirror);
168   SelectVectorButton->setIcon(image3);
169
170   TextLabelDX = new QLabel(tr("SMESH_DX"), GroupMirror);
171   SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror);
172   TextLabelDY = new QLabel(tr("SMESH_DY"), GroupMirror);
173   SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror);
174   TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupMirror);
175   SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror);
176
177   GroupMirrorLayout->addWidget(TextLabelPoint,     0, 0);
178   GroupMirrorLayout->addWidget(SelectPointButton,  0, 1);
179   GroupMirrorLayout->addWidget(TextLabelX,         0, 2);
180   GroupMirrorLayout->addWidget(SpinBox_X,          0, 3);
181   GroupMirrorLayout->addWidget(TextLabelY,         0, 4);
182   GroupMirrorLayout->addWidget(SpinBox_Y,          0, 5);
183   GroupMirrorLayout->addWidget(TextLabelZ,         0, 6);
184   GroupMirrorLayout->addWidget(SpinBox_Z,          0, 7);
185   GroupMirrorLayout->addWidget(TextLabelVector,    1, 0);
186   GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
187   GroupMirrorLayout->addWidget(TextLabelDX,        1, 2);
188   GroupMirrorLayout->addWidget(SpinBox_DX,         1, 3);
189   GroupMirrorLayout->addWidget(TextLabelDY,        1, 4);
190   GroupMirrorLayout->addWidget(SpinBox_DY,         1, 5);
191   GroupMirrorLayout->addWidget(TextLabelDZ,        1, 6);
192   GroupMirrorLayout->addWidget(SpinBox_DZ,         1, 7);
193
194   // switch of action type
195   ActionBox = new QGroupBox(GroupArguments);
196   ActionGroup = new QButtonGroup(GroupArguments);
197   QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
198   ActionBoxLayout->addSpacing(SPACING);
199   ActionBoxLayout->setMargin(MARGIN);
200
201   QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
202   QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
203   QRadioButton* aCreateMesh   = new QRadioButton(tr("SMESH_CREATE_MESH"),   ActionBox);
204
205   ActionBoxLayout->addWidget(aMoveElements);
206   ActionBoxLayout->addWidget(aCopyElements);
207   ActionBoxLayout->addWidget(aCreateMesh);
208   ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
209   ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
210   ActionGroup->addButton(aCreateMesh,   MAKE_MESH_BUTTON);
211
212   // CheckBox for groups generation
213   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
214   MakeGroupsCheck->setChecked(false);
215
216   // Name of a mesh to create
217   LineEditNewMesh = new QLineEdit(GroupArguments);
218
219   // layout
220   GroupArgumentsLayout->addWidget(TextLabelElements,    0, 0);
221   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
222   GroupArgumentsLayout->addWidget(LineEditElements,     0, 2, 1, 2);
223   GroupArgumentsLayout->addWidget(CheckBoxMesh,         1, 0, 1, 4);
224   GroupArgumentsLayout->addWidget(GroupMirror,          2, 0, 1, 4);
225   GroupArgumentsLayout->addWidget(ActionBox,            3, 0, 3, 3);
226   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      4, 3);
227   GroupArgumentsLayout->addWidget(LineEditNewMesh,      5, 3);
228
229   /***************************************************************/
230   GroupButtons = new QGroupBox(this);
231   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
232   GroupButtonsLayout->setSpacing(SPACING);
233   GroupButtonsLayout->setMargin(MARGIN);
234
235   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
236   buttonOk->setAutoDefault(true);
237   buttonOk->setDefault(true);
238   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
239   buttonApply->setAutoDefault(true);
240   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
241   buttonCancel->setAutoDefault(true);
242   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
243   buttonHelp->setAutoDefault(true);
244
245   GroupButtonsLayout->addWidget(buttonOk);
246   GroupButtonsLayout->addSpacing(10);
247   GroupButtonsLayout->addWidget(buttonApply);
248   GroupButtonsLayout->addSpacing(10);
249   GroupButtonsLayout->addStretch();
250   GroupButtonsLayout->addWidget(buttonCancel);
251   GroupButtonsLayout->addWidget(buttonHelp);
252
253   /***************************************************************/
254   SMESHGUI_SymmetryDlgLayout->addWidget(ConstructorsBox);
255   SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments);
256   SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons);
257
258   /* Initialisations */
259   SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
260   SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
261   SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
262   SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
263   SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
264   SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
265
266   RadioButton1->setChecked(true);
267
268   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
269
270   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
271
272   // Costruction of the logical filter
273   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
274   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
275
276   QList<SUIT_SelectionFilter*> aListOfFilters;
277   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
278   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
279
280   myMeshOrSubMeshOrGroupFilter =
281     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
282
283   myHelpFileName = "symmetry_page.html";
284
285   Init();
286
287   /* signals and slots connections */
288   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
289   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
290   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
291   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
292   connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
293
294   connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
295   connect(SelectPointButton,    SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
296   connect(SelectVectorButton,   SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
297
298   connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
299   connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
300   connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
301
302   connect(mySMESHGUI,     SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
303   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),      this, SLOT(SelectionIntoArgument()));
304   /* to close dialog if study change */
305   connect(mySMESHGUI,       SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
306   connect(LineEditElements, SIGNAL(textChanged(const QString&)),   SLOT(onTextChange(const QString&)));
307   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                 SLOT(onSelectMesh(bool)));
308   connect(ActionGroup,      SIGNAL(buttonClicked(int)),            SLOT(onActionClicked(int)));
309
310   ConstructorsClicked(0);
311   SelectionIntoArgument();
312   onActionClicked(MOVE_ELEMS_BUTTON);
313 }
314
315 //=================================================================================
316 // function : ~SMESHGUI_SymmetryDlg()
317 // purpose  : Destroys the object and frees any allocated resources
318 //=================================================================================
319 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
320 {
321 }
322
323 //=================================================================================
324 // function : Init()
325 // purpose  :
326 //=================================================================================
327 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
328 {
329   myBusy = false;
330
331   myEditCurrentArgument = 0;
332   LineEditElements->clear();
333   myElementsId = "";
334   myNbOkElements = 0;
335
336   buttonOk->setEnabled(false);
337   buttonApply->setEnabled(false);
338
339   myActor = 0;
340   myMesh = SMESH::SMESH_Mesh::_nil();
341
342   if (ResetControls) {
343     SpinBox_X->SetValue(0.0);
344     SpinBox_Y->SetValue(0.0);
345     SpinBox_Z->SetValue(0.0);
346     SpinBox_DX->SetValue(0.0);
347     SpinBox_DY->SetValue(0.0);
348     SpinBox_DZ->SetValue(0.0);
349
350     ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
351     CheckBoxMesh->setChecked(false);
352 //     MakeGroupsCheck->setChecked(false);
353 //     MakeGroupsCheck->setEnabled(false);
354     onSelectMesh(false);
355   }
356 }
357
358 //=================================================================================
359 // function : ConstructorsClicked()
360 // purpose  : Radio button management
361 //=================================================================================
362 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
363 {
364   disconnect(mySelectionMgr, 0, this, 0);
365
366   if (constructorId != 0 && !TextLabelVector->isVisible()) {
367     TextLabelVector->show();
368     SelectVectorButton->show();
369     TextLabelDX->show();
370     SpinBox_DX->show();
371     TextLabelDY->show();
372     SpinBox_DY->show();
373     TextLabelDZ->show();
374     SpinBox_DZ->show();
375   }
376
377   switch (constructorId) {
378   case 0:
379     {
380       GroupMirror->setTitle(tr("SMESH_POINT"));
381
382       TextLabelVector->hide();
383       SelectVectorButton->hide();
384       TextLabelDX->hide();
385       SpinBox_DX->hide();
386       TextLabelDY->hide();
387       SpinBox_DY->hide();
388       TextLabelDZ->hide();
389       SpinBox_DZ->hide();
390       break;
391     }
392   case 1:
393     {
394       GroupMirror->setTitle(tr("SMESH_AXIS"));
395       TextLabelVector->setText(tr("SMESH_VECTOR"));
396       break;
397     }
398   case 2:
399     {
400       GroupMirror->setTitle(tr("SMESH_PLANE"));
401       TextLabelVector->setText(tr("SMESH_NORMAL"));
402       break;
403     }
404   }
405
406   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
407     SMESH::SetPointRepresentation(false);
408     if (!CheckBoxMesh->isChecked())
409       {
410         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
411           aViewWindow->SetSelectionMode(CellSelection);
412       }
413   }
414
415   myEditCurrentArgument = (QWidget*)LineEditElements;
416   LineEditElements->setFocus();
417
418   if (CheckBoxMesh->isChecked())
419     onSelectMesh(true);
420
421   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
422
423   QApplication::instance()->processEvents();
424   updateGeometry();
425   resize( minimumSize() );
426 }
427
428 //=================================================================================
429 // function : ClickOnApply()
430 // purpose  :
431 //=================================================================================
432 bool SMESHGUI_SymmetryDlg::ClickOnApply()
433 {
434   if (mySMESHGUI->isActiveStudyLocked())
435     return false;
436
437   if( !isValid() )
438     return false;
439
440   if (myNbOkElements && IsMirrorOk()) {
441     QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
442
443     SMESH::long_array_var anElementsId = new SMESH::long_array;
444
445     anElementsId->length(aListElementsId.count());
446     for (int i = 0; i < aListElementsId.count(); i++)
447       anElementsId[i] = aListElementsId[i].toInt();
448
449     SMESH::AxisStruct aMirror;
450
451     aMirror.x =  SpinBox_X->GetValue();
452     aMirror.y =  SpinBox_Y->GetValue();
453     aMirror.z =  SpinBox_Z->GetValue();
454     if (GetConstructorId() == 0) {
455       aMirror.vx = aMirror.vy = aMirror.vz = 0;
456     } else {
457       aMirror.vx = SpinBox_DX->GetValue();
458       aMirror.vy = SpinBox_DY->GetValue();
459       aMirror.vz = SpinBox_DZ->GetValue();
460     }
461
462     QStringList aParameters;
463     aParameters << SpinBox_X->text();
464     aParameters << SpinBox_Y->text();
465     aParameters << SpinBox_Z->text();
466     aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DX->text() );
467     aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DY->text() );
468     aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DZ->text() );
469
470     SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
471
472     if (GetConstructorId() == 0)
473       aMirrorType = SMESH::SMESH_MeshEditor::POINT;
474     if (GetConstructorId() == 1)
475       aMirrorType = SMESH::SMESH_MeshEditor::AXIS;
476     if (GetConstructorId() == 2)
477       aMirrorType = SMESH::SMESH_MeshEditor::PLANE;
478
479     int actionButton = ActionGroup->checkedId();
480     bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
481
482     try {
483       SUIT_OverrideCursor aWaitCursor;
484       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
485
486       switch ( actionButton ) {
487       case MOVE_ELEMS_BUTTON: {
488         if(CheckBoxMesh->isChecked())
489           aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, false );
490         else
491           aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
492         
493         if( !myMesh->_is_nil())
494           myMesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
495         break;
496       }
497       case COPY_ELEMS_BUTTON: {
498         SMESH::ListOfGroups_var groups;
499         if ( makeGroups )
500           if(CheckBoxMesh->isChecked())
501             groups = aMeshEditor->MirrorObjectMakeGroups(mySelectedObject, aMirror, aMirrorType);
502           else
503             groups = aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
504         else
505           if(CheckBoxMesh->isChecked())
506             aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, true);
507           else
508             aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
509         if( !myMesh->_is_nil())
510           myMesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
511         break;
512         }
513       case MAKE_MESH_BUTTON: {
514         SMESH::SMESH_Mesh_var mesh;
515         if(CheckBoxMesh->isChecked())
516           mesh = aMeshEditor->MirrorObjectMakeMesh(mySelectedObject, aMirror, aMirrorType, makeGroups,
517                                                    LineEditNewMesh->text().toLatin1().data());
518         else
519           mesh = aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
520                                              LineEditNewMesh->text().toLatin1().data());
521         if( !mesh->_is_nil())
522           mesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
523         break;
524       }
525       }
526     } catch (...) {
527     }
528     
529     SMESH::UpdateView();
530     if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
531          actionButton == MAKE_MESH_BUTTON )
532       mySMESHGUI->updateObjBrowser(true); // new groups may appear
533     Init(false);
534     ConstructorsClicked(GetConstructorId());
535     mySelectedObject = SMESH::SMESH_IDSource::_nil();
536     SelectionIntoArgument();
537   }
538   return true;
539 }
540
541 //=================================================================================
542 // function : ClickOnOk()
543 // purpose  :
544 //=================================================================================
545 void SMESHGUI_SymmetryDlg::ClickOnOk()
546 {
547   if( ClickOnApply() )
548     ClickOnCancel();
549 }
550
551 //=================================================================================
552 // function : ClickOnCancel()
553 // purpose  :
554 //=================================================================================
555 void SMESHGUI_SymmetryDlg::ClickOnCancel()
556 {
557   disconnect(mySelectionMgr, 0, this, 0);
558   mySelectionMgr->clearFilters();
559   //mySelectionMgr->clearSelected();
560   SMESH::SetPointRepresentation(false);
561   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
562     aViewWindow->SetSelectionMode(ActorSelection);
563   mySMESHGUI->ResetState();
564   reject();
565 }
566
567 //=================================================================================
568 // function : ClickOnHelp()
569 // purpose  :
570 //=================================================================================
571 void SMESHGUI_SymmetryDlg::ClickOnHelp()
572 {
573   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
574   if (app) 
575     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
576   else {
577     QString platform;
578 #ifdef WIN32
579     platform = "winapplication";
580 #else
581     platform = "application";
582 #endif
583     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
584                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
585                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
586                                                                  platform)).
587                              arg(myHelpFileName));
588   }
589 }
590
591 //=======================================================================
592 // function : onTextChange()
593 // purpose  :
594 //=======================================================================
595 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
596 {
597   QLineEdit* send = (QLineEdit*)sender();
598
599   if (myBusy) return;
600   myBusy = true;
601
602   if (send == LineEditElements)
603     myNbOkElements = 0;
604
605   buttonOk->setEnabled(false);
606   buttonApply->setEnabled(false);
607
608   // hilight entered elements
609   SMDS_Mesh* aMesh = 0;
610   if (myActor)
611     aMesh = myActor->GetObject()->GetMesh();
612
613   if (aMesh) {
614     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
615
616     TColStd_MapOfInteger newIndices;
617     
618     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
619
620     if (send == LineEditElements) {
621       for (int i = 0; i < aListId.count(); i++) {
622         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
623         if (e)
624           newIndices.Add(e->GetID());
625         myNbOkElements++;
626       }
627
628       mySelector->AddOrRemoveIndex( anIO, newIndices, false );
629       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
630         aViewWindow->highlight( anIO, true, true );
631       
632       myElementsId = theNewText;
633     }
634   }
635
636   if (myNbOkElements &&  IsMirrorOk()) {
637     buttonOk->setEnabled(true);
638     buttonApply->setEnabled(true);
639   }
640
641   myBusy = false;
642 }
643
644 //=================================================================================
645 // function : SelectionIntoArgument()
646 // purpose  : Called when selection as changed or other case
647 //=================================================================================
648 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
649 {
650   if (myBusy) return;
651
652   // clear
653   myActor = 0;
654   QString aString = "";
655
656   myBusy = true;
657   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
658     LineEditElements->setText(aString);
659     myNbOkElements = 0;
660     buttonOk->setEnabled(false);
661     buttonApply->setEnabled(false);
662   }
663   myBusy = false;
664
665   if (!GroupButtons->isEnabled()) // inactive
666     return;
667
668   // get selected mesh
669   SALOME_ListIO aList;
670   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
671
672   int nbSel = aList.Extent();
673   if (nbSel != 1)
674     return;
675
676   Handle(SALOME_InteractiveObject) IO = aList.First();
677   myMesh = SMESH::GetMeshByIO(IO);
678   if(myMesh->_is_nil())
679     return;
680
681   myActor = SMESH::FindActorByObject(myMesh);
682   if (!myActor)
683     myActor = SMESH::FindActorByEntry(IO->getEntry());
684   if (!myActor)
685     return;
686
687   int aNbUnits = 0;
688
689   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
690     myElementsId = "";
691
692     // MakeGroups is available if there are groups and "Copy"
693     if ( myMesh->NbGroups() == 0 ) {
694       MakeGroupsCheck->setChecked(false);
695       MakeGroupsCheck->setEnabled(false);
696     }
697     else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
698       MakeGroupsCheck->setEnabled(true);
699     }
700     if (CheckBoxMesh->isChecked()) {
701       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
702
703       if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
704         mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
705       }
706       else
707         return;
708       // get IDs from mesh
709       /*
710         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
711         if (!aSMDSMesh)
712           return;
713
714         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
715           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
716           if (e) {
717             myElementsId += QString(" %1").arg(i);
718             aNbUnits++;
719           }
720         }
721         
722       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
723         // get submesh
724         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
725
726         // get IDs from submesh
727         /*
728         SMESH::long_array_var anElementsIds = new SMESH::long_array;
729         anElementsIds = aSubMesh->GetElementsId();
730         for (int i = 0; i < anElementsIds->length(); i++) {
731           myElementsId += QString(" %1").arg(anElementsIds[i]);
732         }
733         aNbUnits = anElementsIds->length();
734         
735       } else { // GROUP
736         // get smesh group
737         SMESH::SMESH_GroupBase_var aGroup =
738           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
739         if (aGroup->_is_nil())
740           return;
741
742         // get IDs from smesh group
743         SMESH::long_array_var anElementsIds = new SMESH::long_array;
744         anElementsIds = aGroup->GetListOfID();
745         for (int i = 0; i < anElementsIds->length(); i++) {
746           myElementsId += QString(" %1").arg(anElementsIds[i]);
747         }
748         aNbUnits = anElementsIds->length();
749       }
750       */
751     } else {
752       aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
753       myElementsId = aString;
754       if (aNbUnits < 1)
755         return;
756     }
757     
758     myNbOkElements = true;
759   } else {
760     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
761     if (aNbUnits != 1)
762       return;
763
764     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
765     if (!aMesh)
766       return;
767
768     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
769     if (!n)
770       return;
771
772     double x = n->X();
773     double y = n->Y();
774     double z = n->Z();
775
776     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
777       SpinBox_X->SetValue(x);
778       SpinBox_Y->SetValue(y);
779       SpinBox_Z->SetValue(z);
780     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
781       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
782       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
783       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
784     }
785   }
786
787   myBusy = true;
788   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
789     LineEditElements->setText(aString);
790     setNewMeshName();
791   }
792   myBusy = false;
793
794   // OK
795   if (myNbOkElements && IsMirrorOk()) {
796     buttonOk->setEnabled(true);
797     buttonApply->setEnabled(true);
798   }
799 }
800
801 //=================================================================================
802 // function : SetEditCurrentArgument()
803 // purpose  :
804 //=================================================================================
805 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
806 {
807   QPushButton* send = (QPushButton*)sender();
808
809   disconnect(mySelectionMgr, 0, this, 0);
810   mySelectionMgr->clearSelected();
811   mySelectionMgr->clearFilters();
812
813   if (send == SelectElementsButton) {
814     myEditCurrentArgument = (QWidget*)LineEditElements;
815     SMESH::SetPointRepresentation(false);
816     if (CheckBoxMesh->isChecked()) {
817       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
818         aViewWindow->SetSelectionMode(ActorSelection);
819       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
820     } else {
821       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
822         aViewWindow->SetSelectionMode(CellSelection);
823     }
824   } else if (send == SelectPointButton) {
825     myEditCurrentArgument = (QWidget*)SpinBox_X;
826     SMESH::SetPointRepresentation(true);
827     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
828       aViewWindow->SetSelectionMode(NodeSelection);
829   } else if (send == SelectVectorButton) {
830     myEditCurrentArgument = (QWidget*)SpinBox_DX;
831     SMESH::SetPointRepresentation(true);
832
833     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
834       aViewWindow->SetSelectionMode(NodeSelection);
835   } else {
836   }
837
838   myEditCurrentArgument->setFocus();
839   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
840   SelectionIntoArgument();
841 }
842
843 //=================================================================================
844 // function : DeactivateActiveDialog()
845 // purpose  :
846 //=================================================================================
847 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
848 {
849   if (ConstructorsBox->isEnabled()) {
850     ConstructorsBox->setEnabled(false);
851     GroupArguments->setEnabled(false);
852     GroupButtons->setEnabled(false);
853     mySMESHGUI->ResetState();
854     mySMESHGUI->SetActiveDialogBox(0);
855   }
856 }
857
858 //=================================================================================
859 // function : ActivateThisDialog()
860 // purpose  :
861 //=================================================================================
862 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
863 {
864   /* Emit a signal to deactivate the active dialog */
865   mySMESHGUI->EmitSignalDeactivateDialog();
866   ConstructorsBox->setEnabled(true);
867   GroupArguments->setEnabled(true);
868   GroupButtons->setEnabled(true);
869
870   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
871
872   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
873     aViewWindow->SetSelectionMode(CellSelection);
874   SelectionIntoArgument();
875 }
876
877 //=================================================================================
878 // function : enterEvent()
879 // purpose  :
880 //=================================================================================
881 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
882 {
883   if (!ConstructorsBox->isEnabled())
884     ActivateThisDialog();
885 }
886
887 //=================================================================================
888 // function : closeEvent()
889 // purpose  :
890 //=================================================================================
891 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
892 {
893   /* same than click on cancel button */
894   ClickOnCancel();
895 }
896
897 //=======================================================================
898 // function : hideEvent()
899 // purpose  : caused by ESC key
900 //=======================================================================
901 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
902 {
903   if (!isMinimized())
904     ClickOnCancel();
905 }
906
907 //=======================================================================
908 //function : onSelectMesh
909 //purpose  :
910 //=======================================================================
911 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
912 {
913   if (toSelectMesh)
914     TextLabelElements->setText(tr("SMESH_NAME"));
915   else
916     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
917
918   if (myEditCurrentArgument != LineEditElements) {
919     LineEditElements->clear();
920     return;
921   }
922
923   mySelectionMgr->clearFilters();
924   SMESH::SetPointRepresentation(false);
925
926   if (toSelectMesh) {
927     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
928       aViewWindow->SetSelectionMode(ActorSelection);
929     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
930     LineEditElements->setReadOnly(true);
931     LineEditElements->setValidator(0);
932   } else {
933     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
934       aViewWindow->SetSelectionMode(CellSelection);
935     LineEditElements->setReadOnly(false);
936     LineEditElements->setValidator(myIdValidator);
937     onTextChange(LineEditElements->text());
938   }
939
940   SelectionIntoArgument();
941 }
942
943 //=================================================================================
944 // function : GetConstructorId()
945 // purpose  :
946 //=================================================================================
947 int SMESHGUI_SymmetryDlg::GetConstructorId()
948 {
949   return GroupConstructors->checkedId();
950 }
951
952 //=================================================================================
953 // function : IsMirrorOk()
954 // purpose  :
955 //=================================================================================
956 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
957 {
958   bool isOk = true;
959
960   if (GetConstructorId() != 0)
961     isOk = (SpinBox_DX->GetValue() != 0 ||
962             SpinBox_DY->GetValue() != 0 ||
963             SpinBox_DZ->GetValue() != 0);
964
965   return isOk;
966 }
967
968 //=================================================================================
969 // function : onVectorChanged()
970 // purpose  :
971 //=================================================================================
972 void SMESHGUI_SymmetryDlg::onVectorChanged()
973 {
974   if (IsMirrorOk()) {
975     buttonOk->setEnabled(true);
976     buttonApply->setEnabled(true);
977   } else {
978     buttonOk->setEnabled(false);
979     buttonApply->setEnabled(false);
980   }
981 }
982
983 //=======================================================================
984 //function : onActionClicked
985 //purpose  : slot called when an action type changed
986 //=======================================================================
987
988 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
989 {
990   switch ( button ) {
991   case MOVE_ELEMS_BUTTON:
992     MakeGroupsCheck->setEnabled(false);
993     LineEditNewMesh->setEnabled(false);
994     break;
995   case COPY_ELEMS_BUTTON:
996     LineEditNewMesh->setEnabled(false);
997     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
998     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
999       MakeGroupsCheck->setEnabled(true);
1000     else
1001       MakeGroupsCheck->setEnabled(false);
1002     break;
1003   case MAKE_MESH_BUTTON:
1004     LineEditNewMesh->setEnabled(true);
1005     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1006     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1007       MakeGroupsCheck->setEnabled(true);
1008     else
1009       MakeGroupsCheck->setEnabled(false);
1010     break;
1011   }
1012   setNewMeshName();
1013 }
1014
1015 //=======================================================================
1016 //function : setNewMeshName
1017 //purpose  : update contents of LineEditNewMesh
1018 //=======================================================================
1019
1020 void SMESHGUI_SymmetryDlg::setNewMeshName()
1021 {
1022   LineEditNewMesh->setText("");
1023   if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
1024     QString name;
1025     if ( CheckBoxMesh->isChecked() ) {
1026       name = LineEditElements->text();
1027     }
1028     else {
1029       _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1030       name = meshSO->GetName().c_str();
1031     }
1032     if ( !name.isEmpty() )
1033       LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
1034   }
1035 }
1036
1037 //=================================================================================
1038 // function : keyPressEvent()
1039 // purpose  :
1040 //=================================================================================
1041 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1042 {
1043   QDialog::keyPressEvent( e );
1044   if ( e->isAccepted() )
1045     return;
1046
1047   if ( e->key() == Qt::Key_F1 ) {
1048     e->accept();
1049     ClickOnHelp();
1050   }
1051 }
1052
1053 //=================================================================================
1054 // function : isValid
1055 // purpose  :
1056 //=================================================================================
1057 bool SMESHGUI_SymmetryDlg::isValid()
1058 {
1059   bool ok = true;
1060   QString msg;
1061
1062   ok = SpinBox_X->isValid( msg, true ) && ok;
1063   ok = SpinBox_Y->isValid( msg, true ) && ok;
1064   ok = SpinBox_Z->isValid( msg, true ) && ok;
1065   if (GetConstructorId() != 0) {
1066     ok = SpinBox_DX->isValid( msg, true ) && ok;
1067     ok = SpinBox_DY->isValid( msg, true ) && ok;
1068     ok = SpinBox_DZ->isValid( msg, true ) && ok;
1069   }
1070
1071   if( !ok ) {
1072     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1073     if ( !msg.isEmpty() )
1074       str += "\n" + msg;
1075     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1076     return false;
1077   }
1078   return true;
1079 }