]> SALOME platform Git repositories - modules/smesh.git/blob - src/SMESHGUI/SMESHGUI_SymmetryDlg.cxx
Salome HOME
Dump Puthon extension
[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         }
505         else {
506           if(CheckBoxMesh->isChecked())
507             aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, true);
508           else
509             aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
510         }
511         if( !myMesh->_is_nil())
512           myMesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
513         break;
514         }
515       case MAKE_MESH_BUTTON: {
516         SMESH::SMESH_Mesh_var mesh;
517         if(CheckBoxMesh->isChecked())
518           mesh = aMeshEditor->MirrorObjectMakeMesh(mySelectedObject, aMirror, aMirrorType, makeGroups,
519                                                    LineEditNewMesh->text().toLatin1().data());
520         else
521           mesh = aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
522                                              LineEditNewMesh->text().toLatin1().data());
523         if( !mesh->_is_nil())
524           mesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
525         break;
526       }
527       }
528     } catch (...) {
529     }
530     
531     SMESH::UpdateView();
532     if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
533          actionButton == MAKE_MESH_BUTTON )
534       mySMESHGUI->updateObjBrowser(true); // new groups may appear
535     Init(false);
536     ConstructorsClicked(GetConstructorId());
537     mySelectedObject = SMESH::SMESH_IDSource::_nil();
538     SelectionIntoArgument();
539   }
540   return true;
541 }
542
543 //=================================================================================
544 // function : ClickOnOk()
545 // purpose  :
546 //=================================================================================
547 void SMESHGUI_SymmetryDlg::ClickOnOk()
548 {
549   if( ClickOnApply() )
550     ClickOnCancel();
551 }
552
553 //=================================================================================
554 // function : ClickOnCancel()
555 // purpose  :
556 //=================================================================================
557 void SMESHGUI_SymmetryDlg::ClickOnCancel()
558 {
559   disconnect(mySelectionMgr, 0, this, 0);
560   mySelectionMgr->clearFilters();
561   //mySelectionMgr->clearSelected();
562   SMESH::SetPointRepresentation(false);
563   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
564     aViewWindow->SetSelectionMode(ActorSelection);
565   mySMESHGUI->ResetState();
566   reject();
567 }
568
569 //=================================================================================
570 // function : ClickOnHelp()
571 // purpose  :
572 //=================================================================================
573 void SMESHGUI_SymmetryDlg::ClickOnHelp()
574 {
575   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
576   if (app) 
577     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
578   else {
579     QString platform;
580 #ifdef WIN32
581     platform = "winapplication";
582 #else
583     platform = "application";
584 #endif
585     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
586                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
587                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
588                                                                  platform)).
589                              arg(myHelpFileName));
590   }
591 }
592
593 //=======================================================================
594 // function : onTextChange()
595 // purpose  :
596 //=======================================================================
597 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
598 {
599   QLineEdit* send = (QLineEdit*)sender();
600
601   if (myBusy) return;
602   myBusy = true;
603
604   if (send == LineEditElements)
605     myNbOkElements = 0;
606
607   buttonOk->setEnabled(false);
608   buttonApply->setEnabled(false);
609
610   // hilight entered elements
611   SMDS_Mesh* aMesh = 0;
612   if (myActor)
613     aMesh = myActor->GetObject()->GetMesh();
614
615   if (aMesh) {
616     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
617
618     TColStd_MapOfInteger newIndices;
619     
620     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
621
622     if (send == LineEditElements) {
623       for (int i = 0; i < aListId.count(); i++) {
624         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
625         if (e)
626           newIndices.Add(e->GetID());
627         myNbOkElements++;
628       }
629
630       mySelector->AddOrRemoveIndex( anIO, newIndices, false );
631       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
632         aViewWindow->highlight( anIO, true, true );
633       
634       myElementsId = theNewText;
635     }
636   }
637
638   if (myNbOkElements &&  IsMirrorOk()) {
639     buttonOk->setEnabled(true);
640     buttonApply->setEnabled(true);
641   }
642
643   myBusy = false;
644 }
645
646 //=================================================================================
647 // function : SelectionIntoArgument()
648 // purpose  : Called when selection as changed or other case
649 //=================================================================================
650 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
651 {
652   if (myBusy) return;
653
654   // clear
655   myActor = 0;
656   QString aString = "";
657
658   myBusy = true;
659   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
660     LineEditElements->setText(aString);
661     myNbOkElements = 0;
662     buttonOk->setEnabled(false);
663     buttonApply->setEnabled(false);
664   }
665   myBusy = false;
666
667   if (!GroupButtons->isEnabled()) // inactive
668     return;
669
670   // get selected mesh
671   SALOME_ListIO aList;
672   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
673
674   int nbSel = aList.Extent();
675   if (nbSel != 1)
676     return;
677
678   Handle(SALOME_InteractiveObject) IO = aList.First();
679   myMesh = SMESH::GetMeshByIO(IO);
680   if(myMesh->_is_nil())
681     return;
682
683   myActor = SMESH::FindActorByObject(myMesh);
684   if (!myActor)
685     myActor = SMESH::FindActorByEntry(IO->getEntry());
686   if (!myActor)
687     return;
688
689   int aNbUnits = 0;
690
691   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
692     myElementsId = "";
693
694     // MakeGroups is available if there are groups and "Copy"
695     if ( myMesh->NbGroups() == 0 ) {
696       MakeGroupsCheck->setChecked(false);
697       MakeGroupsCheck->setEnabled(false);
698     }
699     else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
700       MakeGroupsCheck->setEnabled(true);
701     }
702     if (CheckBoxMesh->isChecked()) {
703       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
704
705       if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
706         mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
707       }
708       else
709         return;
710       // get IDs from mesh
711       /*
712         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
713         if (!aSMDSMesh)
714           return;
715
716         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
717           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
718           if (e) {
719             myElementsId += QString(" %1").arg(i);
720             aNbUnits++;
721           }
722         }
723         
724       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
725         // get submesh
726         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
727
728         // get IDs from submesh
729         /*
730         SMESH::long_array_var anElementsIds = new SMESH::long_array;
731         anElementsIds = aSubMesh->GetElementsId();
732         for (int i = 0; i < anElementsIds->length(); i++) {
733           myElementsId += QString(" %1").arg(anElementsIds[i]);
734         }
735         aNbUnits = anElementsIds->length();
736         
737       } else { // GROUP
738         // get smesh group
739         SMESH::SMESH_GroupBase_var aGroup =
740           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
741         if (aGroup->_is_nil())
742           return;
743
744         // get IDs from smesh group
745         SMESH::long_array_var anElementsIds = new SMESH::long_array;
746         anElementsIds = aGroup->GetListOfID();
747         for (int i = 0; i < anElementsIds->length(); i++) {
748           myElementsId += QString(" %1").arg(anElementsIds[i]);
749         }
750         aNbUnits = anElementsIds->length();
751       }
752       */
753     } else {
754       aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
755       myElementsId = aString;
756       if (aNbUnits < 1)
757         return;
758     }
759     
760     myNbOkElements = true;
761   } else {
762     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
763     if (aNbUnits != 1)
764       return;
765
766     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
767     if (!aMesh)
768       return;
769
770     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
771     if (!n)
772       return;
773
774     double x = n->X();
775     double y = n->Y();
776     double z = n->Z();
777
778     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
779       SpinBox_X->SetValue(x);
780       SpinBox_Y->SetValue(y);
781       SpinBox_Z->SetValue(z);
782     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
783       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
784       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
785       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
786     }
787   }
788
789   myBusy = true;
790   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
791     LineEditElements->setText(aString);
792     setNewMeshName();
793   }
794   myBusy = false;
795
796   // OK
797   if (myNbOkElements && IsMirrorOk()) {
798     buttonOk->setEnabled(true);
799     buttonApply->setEnabled(true);
800   }
801 }
802
803 //=================================================================================
804 // function : SetEditCurrentArgument()
805 // purpose  :
806 //=================================================================================
807 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
808 {
809   QPushButton* send = (QPushButton*)sender();
810
811   disconnect(mySelectionMgr, 0, this, 0);
812   mySelectionMgr->clearSelected();
813   mySelectionMgr->clearFilters();
814
815   if (send == SelectElementsButton) {
816     myEditCurrentArgument = (QWidget*)LineEditElements;
817     SMESH::SetPointRepresentation(false);
818     if (CheckBoxMesh->isChecked()) {
819       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
820         aViewWindow->SetSelectionMode(ActorSelection);
821       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
822     } else {
823       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
824         aViewWindow->SetSelectionMode(CellSelection);
825     }
826   } else if (send == SelectPointButton) {
827     myEditCurrentArgument = (QWidget*)SpinBox_X;
828     SMESH::SetPointRepresentation(true);
829     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
830       aViewWindow->SetSelectionMode(NodeSelection);
831   } else if (send == SelectVectorButton) {
832     myEditCurrentArgument = (QWidget*)SpinBox_DX;
833     SMESH::SetPointRepresentation(true);
834
835     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
836       aViewWindow->SetSelectionMode(NodeSelection);
837   } else {
838   }
839
840   myEditCurrentArgument->setFocus();
841   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
842   SelectionIntoArgument();
843 }
844
845 //=================================================================================
846 // function : DeactivateActiveDialog()
847 // purpose  :
848 //=================================================================================
849 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
850 {
851   if (ConstructorsBox->isEnabled()) {
852     ConstructorsBox->setEnabled(false);
853     GroupArguments->setEnabled(false);
854     GroupButtons->setEnabled(false);
855     mySMESHGUI->ResetState();
856     mySMESHGUI->SetActiveDialogBox(0);
857   }
858 }
859
860 //=================================================================================
861 // function : ActivateThisDialog()
862 // purpose  :
863 //=================================================================================
864 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
865 {
866   /* Emit a signal to deactivate the active dialog */
867   mySMESHGUI->EmitSignalDeactivateDialog();
868   ConstructorsBox->setEnabled(true);
869   GroupArguments->setEnabled(true);
870   GroupButtons->setEnabled(true);
871
872   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
873
874   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
875     aViewWindow->SetSelectionMode(CellSelection);
876   SelectionIntoArgument();
877 }
878
879 //=================================================================================
880 // function : enterEvent()
881 // purpose  :
882 //=================================================================================
883 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
884 {
885   if (!ConstructorsBox->isEnabled())
886     ActivateThisDialog();
887 }
888
889 //=================================================================================
890 // function : closeEvent()
891 // purpose  :
892 //=================================================================================
893 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
894 {
895   /* same than click on cancel button */
896   ClickOnCancel();
897 }
898
899 //=======================================================================
900 // function : hideEvent()
901 // purpose  : caused by ESC key
902 //=======================================================================
903 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
904 {
905   if (!isMinimized())
906     ClickOnCancel();
907 }
908
909 //=======================================================================
910 //function : onSelectMesh
911 //purpose  :
912 //=======================================================================
913 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
914 {
915   if (toSelectMesh)
916     TextLabelElements->setText(tr("SMESH_NAME"));
917   else
918     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
919
920   if (myEditCurrentArgument != LineEditElements) {
921     LineEditElements->clear();
922     return;
923   }
924
925   mySelectionMgr->clearFilters();
926   SMESH::SetPointRepresentation(false);
927
928   if (toSelectMesh) {
929     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
930       aViewWindow->SetSelectionMode(ActorSelection);
931     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
932     LineEditElements->setReadOnly(true);
933     LineEditElements->setValidator(0);
934   } else {
935     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
936       aViewWindow->SetSelectionMode(CellSelection);
937     LineEditElements->setReadOnly(false);
938     LineEditElements->setValidator(myIdValidator);
939     onTextChange(LineEditElements->text());
940   }
941
942   SelectionIntoArgument();
943 }
944
945 //=================================================================================
946 // function : GetConstructorId()
947 // purpose  :
948 //=================================================================================
949 int SMESHGUI_SymmetryDlg::GetConstructorId()
950 {
951   return GroupConstructors->checkedId();
952 }
953
954 //=================================================================================
955 // function : IsMirrorOk()
956 // purpose  :
957 //=================================================================================
958 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
959 {
960   bool isOk = true;
961
962   if (GetConstructorId() != 0)
963     isOk = (SpinBox_DX->GetValue() != 0 ||
964             SpinBox_DY->GetValue() != 0 ||
965             SpinBox_DZ->GetValue() != 0);
966
967   return isOk;
968 }
969
970 //=================================================================================
971 // function : onVectorChanged()
972 // purpose  :
973 //=================================================================================
974 void SMESHGUI_SymmetryDlg::onVectorChanged()
975 {
976   if (IsMirrorOk()) {
977     buttonOk->setEnabled(true);
978     buttonApply->setEnabled(true);
979   } else {
980     buttonOk->setEnabled(false);
981     buttonApply->setEnabled(false);
982   }
983 }
984
985 //=======================================================================
986 //function : onActionClicked
987 //purpose  : slot called when an action type changed
988 //=======================================================================
989
990 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
991 {
992   switch ( button ) {
993   case MOVE_ELEMS_BUTTON:
994     MakeGroupsCheck->setEnabled(false);
995     LineEditNewMesh->setEnabled(false);
996     break;
997   case COPY_ELEMS_BUTTON:
998     LineEditNewMesh->setEnabled(false);
999     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1000     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1001       MakeGroupsCheck->setEnabled(true);
1002     else
1003       MakeGroupsCheck->setEnabled(false);
1004     break;
1005   case MAKE_MESH_BUTTON:
1006     LineEditNewMesh->setEnabled(true);
1007     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1008     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1009       MakeGroupsCheck->setEnabled(true);
1010     else
1011       MakeGroupsCheck->setEnabled(false);
1012     break;
1013   }
1014   setNewMeshName();
1015 }
1016
1017 //=======================================================================
1018 //function : setNewMeshName
1019 //purpose  : update contents of LineEditNewMesh
1020 //=======================================================================
1021
1022 void SMESHGUI_SymmetryDlg::setNewMeshName()
1023 {
1024   LineEditNewMesh->setText("");
1025   if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
1026     QString name;
1027     if ( CheckBoxMesh->isChecked() ) {
1028       name = LineEditElements->text();
1029     }
1030     else {
1031       _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1032       name = meshSO->GetName().c_str();
1033     }
1034     if ( !name.isEmpty() )
1035       LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
1036   }
1037 }
1038
1039 //=================================================================================
1040 // function : keyPressEvent()
1041 // purpose  :
1042 //=================================================================================
1043 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1044 {
1045   QDialog::keyPressEvent( e );
1046   if ( e->isAccepted() )
1047     return;
1048
1049   if ( e->key() == Qt::Key_F1 ) {
1050     e->accept();
1051     ClickOnHelp();
1052   }
1053 }
1054
1055 //=================================================================================
1056 // function : isValid
1057 // purpose  :
1058 //=================================================================================
1059 bool SMESHGUI_SymmetryDlg::isValid()
1060 {
1061   bool ok = true;
1062   QString msg;
1063
1064   ok = SpinBox_X->isValid( msg, true ) && ok;
1065   ok = SpinBox_Y->isValid( msg, true ) && ok;
1066   ok = SpinBox_Z->isValid( msg, true ) && ok;
1067   if (GetConstructorId() != 0) {
1068     ok = SpinBox_DX->isValid( msg, true ) && ok;
1069     ok = SpinBox_DY->isValid( msg, true ) && ok;
1070     ok = SpinBox_DZ->isValid( msg, true ) && ok;
1071   }
1072
1073   if( !ok ) {
1074     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1075     if ( !msg.isEmpty() )
1076       str += "\n" + msg;
1077     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1078     return false;
1079   }
1080   return true;
1081 }