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