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