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