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