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