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