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