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