Salome HOME
Join modifications from V3_2_0_maintainance (V3_2_6pre4 - T32x_16Aug2007_16h00m)
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_SymmetryDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  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 //
24 //  File   : SMESHGUI_SymmetryDlg.cxx
25 //  Author : Michael ZORIN
26 //  Module : SMESH
27 //  $Header:
28
29 #include "SMESHGUI_SymmetryDlg.h"
30
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_SpinBox.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_VTKUtils.h"
35 #include "SMESHGUI_MeshUtils.h"
36 #include "SMESHGUI_IdValidator.h"
37
38 #include "SMESH_Actor.h"
39 #include "SMESH_TypeFilter.hxx"
40 #include "SMESH_LogicalFilter.hxx"
41 #include "SMDS_Mesh.hxx"
42
43 #include "SUIT_Desktop.h"
44 #include "SUIT_ResourceMgr.h"
45 #include "SUIT_Session.h"
46 #include "SUIT_MessageBox.h"
47
48 #include "LightApp_Application.h"
49
50 #include "SVTK_ViewModel.h"
51 #include "SVTK_ViewWindow.h"
52 #include "SVTK_Selector.h"
53 #include "SVTK_Selection.h"
54 #include "SALOME_ListIO.hxx"
55
56 #include "utilities.h"
57
58 // OCCT Includes
59 #include <TColStd_MapOfInteger.hxx>
60 #include <TColStd_IndexedMapOfInteger.hxx>
61
62 // QT Includes
63 #include <qapplication.h>
64 #include <qbuttongroup.h>
65 #include <qgroupbox.h>
66 #include <qlabel.h>
67 #include <qlineedit.h>
68 #include <qpushbutton.h>
69 #include <qradiobutton.h>
70 #include <qcheckbox.h>
71 #include <qlayout.h>
72 #include <qpixmap.h>
73
74 // IDL Headers
75 #include "SALOMEconfig.h"
76 #include CORBA_SERVER_HEADER(SMESH_Group)
77 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
78
79 using namespace std;
80
81 //=================================================================================
82 // class    : SMESHGUI_SymmetryDlg()
83 // purpose  :
84 //=================================================================================
85 SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule, const char* name,
86                                             bool modal, WFlags fl)
87      : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
88                 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
89       mySMESHGUI( theModule ),
90       mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
91 {
92   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_POINT")));
93   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_AXIS")));
94   QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_PLANE")));
95   QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
96
97   if (!name)
98     setName("SMESHGUI_SymmetryDlg");
99   resize(303, 185);
100   setCaption(tr("SMESH_SYMMETRY"));
101   setSizeGripEnabled(TRUE);
102   SMESHGUI_SymmetryDlgLayout = new QGridLayout(this);
103   SMESHGUI_SymmetryDlgLayout->setSpacing(6);
104   SMESHGUI_SymmetryDlgLayout->setMargin(11);
105
106   /***************************************************************/
107   GroupConstructors = new QButtonGroup(this, "GroupConstructors");
108   GroupConstructors->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5,
109                                                (QSizePolicy::SizeType)0, 0, 0,
110                                                GroupConstructors->sizePolicy().hasHeightForWidth()));
111   GroupConstructors->setTitle(tr("SMESH_SYMMETRY" ));
112   GroupConstructors->setExclusive(TRUE);
113   GroupConstructors->setColumnLayout(0, Qt::Vertical);
114   GroupConstructors->layout()->setSpacing(0);
115   GroupConstructors->layout()->setMargin(0);
116   GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
117   GroupConstructorsLayout->setAlignment(Qt::AlignTop);
118   GroupConstructorsLayout->setSpacing(6);
119   GroupConstructorsLayout->setMargin(11);
120   QHBoxLayout* RBLayout = new QHBoxLayout(0, 0, 6, "Layout2");
121   RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
122   RadioButton1->setText(tr("" ));
123   RadioButton1->setPixmap(image0);
124   RBLayout->addWidget(RadioButton1);
125   RadioButton2= new QRadioButton(GroupConstructors, "RadioButton2");
126   RadioButton2->setText(tr("" ));
127   RadioButton2->setPixmap(image1);
128   RBLayout->addWidget(RadioButton2);
129   RadioButton3= new QRadioButton(GroupConstructors, "RadioButton3");
130   RadioButton3->setText(tr("" ));
131   RadioButton3->setPixmap(image2);
132   RBLayout->addWidget(RadioButton3);
133   GroupConstructorsLayout->addLayout(RBLayout, 0, 0);
134   SMESHGUI_SymmetryDlgLayout->addWidget(GroupConstructors, 0, 0);
135
136   /***************************************************************/
137   GroupButtons = new QGroupBox(this, "GroupButtons");
138   GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
139                                           (QSizePolicy::SizeType)0, 0, 0,
140                                           GroupButtons->sizePolicy().hasHeightForWidth()));
141   GroupButtons->setGeometry(QRect(10, 10, 281, 48));
142   GroupButtons->setTitle(tr("" ));
143   GroupButtons->setColumnLayout(0, Qt::Vertical);
144   GroupButtons->layout()->setSpacing(0);
145   GroupButtons->layout()->setMargin(0);
146   GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
147   GroupButtonsLayout->setAlignment(Qt::AlignTop);
148   GroupButtonsLayout->setSpacing(6);
149   GroupButtonsLayout->setMargin(11);
150   buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
151   buttonHelp->setText(tr("SMESH_BUT_HELP" ));
152   buttonHelp->setAutoDefault(TRUE);
153   GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
154   buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
155   buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
156   buttonCancel->setAutoDefault(TRUE);
157   GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
158   buttonApply = new QPushButton(GroupButtons, "buttonApply");
159   buttonApply->setText(tr("SMESH_BUT_APPLY" ));
160   buttonApply->setAutoDefault(TRUE);
161   GroupButtonsLayout->addWidget(buttonApply, 0, 1);
162   QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
163   GroupButtonsLayout->addItem(spacer_9, 0, 2);
164   buttonOk = new QPushButton(GroupButtons, "buttonOk");
165   buttonOk->setText(tr("SMESH_BUT_OK" ));
166   buttonOk->setAutoDefault(TRUE);
167   buttonOk->setDefault(TRUE);
168   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
169   SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons, 2, 0);
170
171   /***************************************************************/
172   GroupArguments = new QGroupBox(this, "GroupArguments");
173   GroupArguments->setTitle(tr("SMESH_ARGUMENTS"));
174   GroupArguments->setColumnLayout(0, Qt::Vertical);
175   GroupArguments->layout()->setSpacing(0);
176   GroupArguments->layout()->setMargin(0);
177   GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
178   GroupArgumentsLayout->setAlignment(Qt::AlignTop);
179   GroupArgumentsLayout->setSpacing(6);
180   GroupArgumentsLayout->setMargin(11);
181
182   // Controls for elements selection
183   TextLabelElements  = new QLabel(GroupArguments, "TextLabelElements");
184   TextLabelElements->setText(tr("SMESH_ID_ELEMENTS" ));
185   TextLabelElements->setFixedWidth(74);
186   GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
187
188   SelectElementsButton  = new QPushButton(GroupArguments, "SelectElementsButton");
189   SelectElementsButton->setText(tr("" ));
190   SelectElementsButton->setPixmap(image3);
191   SelectElementsButton->setToggleButton(FALSE);
192   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
193
194   LineEditElements  = new QLineEdit(GroupArguments, "LineEditElements");
195   LineEditElements->setValidator(new SMESHGUI_IdValidator(this, "validator"));
196   GroupArgumentsLayout->addWidget(LineEditElements, 0, 2);
197
198   // Control for the whole mesh selection
199   CheckBoxMesh = new QCheckBox(GroupArguments, "CheckBoxMesh");
200   CheckBoxMesh->setText(tr("SMESH_SELECT_WHOLE_MESH" ));
201   GroupArgumentsLayout->addMultiCellWidget(CheckBoxMesh, 1, 1, 0, 2);
202
203   // Controls for mirror selection
204   GroupMirror = new QGroupBox(GroupArguments, "GroupMirror");
205   GroupMirror->setColumnLayout(0, Qt::Vertical);
206   GroupMirror->layout()->setSpacing(0);
207   GroupMirror->layout()->setMargin(0);
208   QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror->layout());
209   GroupMirrorLayout->setAlignment(Qt::AlignTop);
210   GroupMirrorLayout->setSpacing(6);
211   GroupMirrorLayout->setMargin(11);
212
213   TextLabelPoint = new QLabel(GroupMirror, "TextLabelPoint");
214   TextLabelPoint->setText(tr("SMESH_POINT"));
215   GroupMirrorLayout->addWidget(TextLabelPoint, 0, 0);
216
217   SelectPointButton  = new QPushButton(GroupMirror, "SelectPointButton");
218   SelectPointButton->setPixmap(image3);
219   GroupMirrorLayout->addWidget(SelectPointButton, 0, 1);
220
221   TextLabelX = new QLabel(GroupMirror, "TextLabelX");
222   TextLabelX->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
223   TextLabelX->setText(tr("SMESH_X"));
224   GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
225
226   SpinBox_X = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_X");
227   GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
228
229   TextLabelY = new QLabel(GroupMirror, "TextLabelY");
230   TextLabelY->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
231   TextLabelY->setText(tr("SMESH_Y"));
232   GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
233
234   SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_Y");
235   GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
236
237   TextLabelZ = new QLabel(GroupMirror, "TextLabelZ");
238   TextLabelZ->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
239   TextLabelZ->setText(tr("SMESH_Z"));
240   GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
241
242   SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_Z");
243   GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
244
245   TextLabelVector = new QLabel(GroupMirror, "TextLabelVector");
246   GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
247
248   SelectVectorButton = new QPushButton(GroupMirror, "SelectVectorButton");
249   SelectVectorButton->setPixmap(image3);
250   GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
251
252   TextLabelDX = new QLabel(GroupMirror, "TextLabelDX");
253   TextLabelDX->setText(tr("SMESH_DX"));
254   GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
255
256   SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_DX");
257   GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
258
259   TextLabelDY = new QLabel(GroupMirror, "TextLabelDY");
260   TextLabelDY->setText(tr("SMESH_DY"));
261   GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
262
263   SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_DY");
264   GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
265
266   TextLabelDZ = new QLabel(GroupMirror, "TextLabelDZ");
267   TextLabelDZ->setText(tr("SMESH_DZ"));
268   GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
269
270   SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_DZ");
271   GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
272
273   GroupArgumentsLayout->addMultiCellWidget(GroupMirror, 2, 2, 0, 2);
274
275   // Controls for "Create a copy" option
276   CheckBoxCopy = new QCheckBox(GroupArguments, "CheckBoxCopy");
277   CheckBoxCopy->setText(tr("SMESH_CREATE_COPY"));
278   GroupArgumentsLayout->addMultiCellWidget(CheckBoxCopy, 3, 3, 0, 2);
279
280
281   SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments, 1, 0);
282
283   /* Initialisations */
284   SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
285   SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
286   SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
287   SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
288   SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
289   SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
290
291   GroupArguments->show();
292   RadioButton1->setChecked(TRUE);
293
294   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
295
296   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
297
298   // Costruction of the logical filter
299   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
300   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
301
302   QPtrList<SUIT_SelectionFilter> aListOfFilters;
303   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
304   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
305
306   myMeshOrSubMeshOrGroupFilter =
307     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
308
309   myHelpFileName = "/files/symmetry.htm";
310
311   Init();
312
313   /* signals and slots connections */
314   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
315   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
316   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
317   connect(buttonHelp, SIGNAL(clicked()),   this, SLOT(ClickOnHelp()));
318   connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
319
320   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
321   connect(SelectPointButton, SIGNAL (clicked()),    this, SLOT(SetEditCurrentArgument()));
322   connect(SelectVectorButton, SIGNAL (clicked()),   this, SLOT(SetEditCurrentArgument()));
323
324   connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
325   connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
326   connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
327
328   connect(mySMESHGUI,     SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
329   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),      this, SLOT(SelectionIntoArgument()));
330   /* to close dialog if study change */
331   connect(mySMESHGUI,       SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
332   connect(LineEditElements, SIGNAL(textChanged(const QString&)),   SLOT(onTextChange(const QString&)));
333   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                 SLOT(onSelectMesh(bool)));
334
335   this->show(); /* displays Dialog */
336
337   ConstructorsClicked(0);
338   SelectionIntoArgument();
339   resize(0,0); // ??
340 }
341
342 //=================================================================================
343 // function : ~SMESHGUI_SymmetryDlg()
344 // purpose  : Destroys the object and frees any allocated resources
345 //=================================================================================
346 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
347 {
348   // no need to delete child widgets, Qt does it all for us
349 }
350
351 //=================================================================================
352 // function : Init()
353 // purpose  :
354 //=================================================================================
355 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
356 {
357   myBusy = false;
358
359   myEditCurrentArgument = 0;
360   LineEditElements->clear();
361   myElementsId = "";
362   myNbOkElements = 0;
363
364   buttonOk->setEnabled(false);
365   buttonApply->setEnabled(false);
366
367   myActor = 0;
368   myMesh = SMESH::SMESH_Mesh::_nil();
369
370   if (ResetControls) {
371     SpinBox_X->SetValue(0.0);
372     SpinBox_Y->SetValue(0.0);
373     SpinBox_Z->SetValue(0.0);
374     SpinBox_DX->SetValue(0.0);
375     SpinBox_DY->SetValue(0.0);
376     SpinBox_DZ->SetValue(0.0);
377
378     CheckBoxCopy->setChecked(false);
379     CheckBoxMesh->setChecked(false);
380     onSelectMesh(false);
381   }
382 }
383
384 //=================================================================================
385 // function : ConstructorsClicked()
386 // purpose  : Radio button management
387 //=================================================================================
388 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
389 {
390   disconnect(mySelectionMgr, 0, this, 0);
391
392   if (constructorId != 0 && !TextLabelVector->isVisible()) {
393     TextLabelVector->show();
394     SelectVectorButton->show();
395     TextLabelDX->show();
396     SpinBox_DX->show();
397     TextLabelDY->show();
398     SpinBox_DY->show();
399     TextLabelDZ->show();
400     SpinBox_DZ->show();
401   }
402
403   switch (constructorId) {
404   case 0:
405     {
406       GroupMirror->setTitle(tr("SMESH_POINT"));
407
408       TextLabelVector->hide();
409       SelectVectorButton->hide();
410       TextLabelDX->hide();
411       SpinBox_DX->hide();
412       TextLabelDY->hide();
413       SpinBox_DY->hide();
414       TextLabelDZ->hide();
415       SpinBox_DZ->hide();
416       break;
417     }
418   case 1:
419     {
420       GroupMirror->setTitle(tr("SMESH_AXIS"));
421       TextLabelVector->setText(tr("SMESH_VECTOR"));
422       break;
423     }
424   case 2:
425     {
426       GroupMirror->setTitle(tr("SMESH_PLANE"));
427       TextLabelVector->setText(tr("SMESH_NORMAL"));
428       break;
429     }
430   }
431
432   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
433     SMESH::SetPointRepresentation(false);
434     if (!CheckBoxMesh->isChecked())
435       {
436         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
437           aViewWindow->SetSelectionMode(CellSelection);
438       }
439   }
440
441   myEditCurrentArgument = (QWidget*)LineEditElements;
442   LineEditElements->setFocus();
443
444   if (CheckBoxMesh->isChecked())
445     onSelectMesh(true);
446
447   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
448 }
449
450 //=================================================================================
451 // function : ClickOnApply()
452 // purpose  :
453 //=================================================================================
454 void SMESHGUI_SymmetryDlg::ClickOnApply()
455 {
456   if (mySMESHGUI->isActiveStudyLocked())
457     return;
458
459   if (myNbOkElements && IsMirrorOk()) {
460     QStringList aListElementsId = QStringList::split(" ", myElementsId, false);
461
462     SMESH::long_array_var anElementsId = new SMESH::long_array;
463
464     anElementsId->length(aListElementsId.count());
465     for (int i = 0; i < aListElementsId.count(); i++)
466       anElementsId[i] = aListElementsId[i].toInt();
467
468     SMESH::AxisStruct aMirror;
469
470     aMirror.x =  SpinBox_X->GetValue();
471     aMirror.y =  SpinBox_Y->GetValue();
472     aMirror.z =  SpinBox_Z->GetValue();
473     if (GetConstructorId() == 0) {
474       aMirror.vx = aMirror.vy = aMirror.vz = 0;
475     } else {
476       aMirror.vx = SpinBox_DX->GetValue();
477       aMirror.vy = SpinBox_DY->GetValue();
478       aMirror.vz = SpinBox_DZ->GetValue();
479     }
480
481     bool toCreateCopy = CheckBoxCopy->isChecked();
482
483     SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
484
485     if (GetConstructorId() == 0)
486       aMirrorType = SMESH::SMESH_MeshEditor::POINT;
487     if (GetConstructorId() == 1)
488       aMirrorType = SMESH::SMESH_MeshEditor::AXIS;
489     if (GetConstructorId() == 2)
490       aMirrorType = SMESH::SMESH_MeshEditor::PLANE;
491
492     try {
493       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
494       QApplication::setOverrideCursor(Qt::waitCursor);
495       aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, toCreateCopy);
496       QApplication::restoreOverrideCursor();
497     } catch (...) {
498     }
499
500     SMESH::UpdateView();
501     Init(false);
502     ConstructorsClicked(GetConstructorId());
503     SelectionIntoArgument();
504   }
505 }
506
507 //=================================================================================
508 // function : ClickOnOk()
509 // purpose  :
510 //=================================================================================
511 void SMESHGUI_SymmetryDlg::ClickOnOk()
512 {
513   ClickOnApply();
514   ClickOnCancel();
515 }
516
517 //=================================================================================
518 // function : ClickOnCancel()
519 // purpose  :
520 //=================================================================================
521 void SMESHGUI_SymmetryDlg::ClickOnCancel()
522 {
523   disconnect(mySelectionMgr, 0, this, 0);
524   mySelectionMgr->clearFilters();
525   //mySelectionMgr->clearSelected();
526   SMESH::SetPointRepresentation(false);
527   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
528     aViewWindow->SetSelectionMode(ActorSelection);
529   mySMESHGUI->ResetState();
530   reject();
531 }
532
533 //=================================================================================
534 // function : ClickOnHelp()
535 // purpose  :
536 //=================================================================================
537 void SMESHGUI_SymmetryDlg::ClickOnHelp()
538 {
539   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
540   if (app) 
541     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
542   else {
543                 QString platform;
544 #ifdef WIN32
545                 platform = "winapplication";
546 #else
547                 platform = "application";
548 #endif
549     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
550                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
551                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
552                            QObject::tr("BUT_OK"));
553   }
554 }
555
556 //=======================================================================
557 // function : onTextChange()
558 // purpose  :
559 //=======================================================================
560 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
561 {
562   QLineEdit* send = (QLineEdit*)sender();
563
564   if (myBusy) return;
565   myBusy = true;
566
567   if (send == LineEditElements)
568     myNbOkElements = 0;
569
570   buttonOk->setEnabled(false);
571   buttonApply->setEnabled(false);
572
573   // hilight entered elements
574   SMDS_Mesh* aMesh = 0;
575   if (myActor)
576     aMesh = myActor->GetObject()->GetMesh();
577
578   if (aMesh) {
579     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
580
581     TColStd_MapOfInteger newIndices;
582     
583     QStringList aListId = QStringList::split(" ", theNewText, false);
584
585     if (send == LineEditElements) {
586       for (int i = 0; i < aListId.count(); i++) {
587         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
588         if (e)
589           newIndices.Add(e->GetID());
590         myNbOkElements++;
591       }
592
593       mySelector->AddOrRemoveIndex( anIO, newIndices, false );
594       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
595         aViewWindow->highlight( anIO, true, true );
596       
597       myElementsId = theNewText;
598     }
599   }
600
601   if (myNbOkElements &&  IsMirrorOk()) {
602     buttonOk->setEnabled(true);
603     buttonApply->setEnabled(true);
604   }
605
606   myBusy = false;
607 }
608
609 //=================================================================================
610 // function : SelectionIntoArgument()
611 // purpose  : Called when selection as changed or other case
612 //=================================================================================
613 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
614 {
615   if (myBusy) return;
616
617   // clear
618   myActor = 0;
619   QString aString = "";
620
621   myBusy = true;
622   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
623     LineEditElements->setText(aString);
624     myNbOkElements = 0;
625     buttonOk->setEnabled(false);
626     buttonApply->setEnabled(false);
627   }
628   myBusy = false;
629
630   if (!GroupButtons->isEnabled()) // inactive
631     return;
632
633   // get selected mesh
634   SALOME_ListIO aList;
635   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
636
637   int nbSel = aList.Extent();
638   if (nbSel != 1)
639     return;
640
641   Handle(SALOME_InteractiveObject) IO = aList.First();
642   myMesh = SMESH::GetMeshByIO(IO);
643   if(myMesh->_is_nil())
644     return;
645
646   myActor = SMESH::FindActorByObject(myMesh);
647   if (!myActor)
648     myActor = SMESH::FindActorByEntry(IO->getEntry());
649   if (!myActor)
650     return;
651
652   int aNbUnits = 0;
653
654   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
655     myElementsId = "";
656
657     if (CheckBoxMesh->isChecked()) {
658       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
659
660       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
661         // get IDs from mesh
662         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
663         if (!aSMDSMesh)
664           return;
665
666         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
667           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
668           if (e) {
669             myElementsId += QString(" %1").arg(i);
670             aNbUnits++;
671           }
672         }
673       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
674         // get submesh
675         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
676
677         // get IDs from submesh
678         SMESH::long_array_var anElementsIds = new SMESH::long_array;
679         anElementsIds = aSubMesh->GetElementsId();
680         for (int i = 0; i < anElementsIds->length(); i++) {
681           myElementsId += QString(" %1").arg(anElementsIds[i]);
682         }
683         aNbUnits = anElementsIds->length();
684       } else { // GROUP
685         // get smesh group
686         SMESH::SMESH_GroupBase_var aGroup =
687           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
688         if (aGroup->_is_nil())
689           return;
690
691         // get IDs from smesh group
692         SMESH::long_array_var anElementsIds = new SMESH::long_array;
693         anElementsIds = aGroup->GetListOfID();
694         for (int i = 0; i < anElementsIds->length(); i++) {
695           myElementsId += QString(" %1").arg(anElementsIds[i]);
696         }
697         aNbUnits = anElementsIds->length();
698       }
699     } else {
700       aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
701       myElementsId = aString;
702     }
703
704     if (aNbUnits < 1)
705       return;
706
707     myNbOkElements = true;
708   } else {
709     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
710     if (aNbUnits != 1)
711       return;
712
713     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
714     if (!aMesh)
715       return;
716
717     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
718     if (!n)
719       return;
720
721     double x = n->X();
722     double y = n->Y();
723     double z = n->Z();
724
725     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
726       SpinBox_X->SetValue(x);
727       SpinBox_Y->SetValue(y);
728       SpinBox_Z->SetValue(z);
729     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
730       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
731       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
732       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
733     }
734   }
735
736   myBusy = true;
737   if (myEditCurrentArgument == (QWidget*)LineEditElements)
738     LineEditElements->setText(aString);
739   myBusy = false;
740
741   // OK
742   if (myNbOkElements && IsMirrorOk()) {
743     buttonOk->setEnabled(true);
744     buttonApply->setEnabled(true);
745   }
746 }
747
748 //=================================================================================
749 // function : SetEditCurrentArgument()
750 // purpose  :
751 //=================================================================================
752 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
753 {
754   QPushButton* send = (QPushButton*)sender();
755
756   disconnect(mySelectionMgr, 0, this, 0);
757   mySelectionMgr->clearSelected();
758   mySelectionMgr->clearFilters();
759
760   if (send == SelectElementsButton) {
761     myEditCurrentArgument = (QWidget*)LineEditElements;
762     SMESH::SetPointRepresentation(false);
763     if (CheckBoxMesh->isChecked()) {
764       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
765         aViewWindow->SetSelectionMode(ActorSelection);
766       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
767     } else {
768       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
769         aViewWindow->SetSelectionMode(CellSelection);
770     }
771   } else if (send == SelectPointButton) {
772     myEditCurrentArgument = (QWidget*)SpinBox_X;
773     SMESH::SetPointRepresentation(true);
774     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
775       aViewWindow->SetSelectionMode(NodeSelection);
776   } else if (send == SelectVectorButton) {
777     myEditCurrentArgument = (QWidget*)SpinBox_DX;
778     SMESH::SetPointRepresentation(true);
779
780     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
781       aViewWindow->SetSelectionMode(NodeSelection);
782   } else {
783   }
784
785   myEditCurrentArgument->setFocus();
786   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
787   SelectionIntoArgument();
788 }
789
790 //=================================================================================
791 // function : DeactivateActiveDialog()
792 // purpose  :
793 //=================================================================================
794 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
795 {
796   if (GroupConstructors->isEnabled()) {
797     GroupConstructors->setEnabled(false);
798     GroupArguments->setEnabled(false);
799     GroupButtons->setEnabled(false);
800     mySMESHGUI->ResetState();
801     mySMESHGUI->SetActiveDialogBox(0);
802   }
803 }
804
805 //=================================================================================
806 // function : ActivateThisDialog()
807 // purpose  :
808 //=================================================================================
809 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
810 {
811   /* Emit a signal to deactivate the active dialog */
812   mySMESHGUI->EmitSignalDeactivateDialog();
813   GroupConstructors->setEnabled(true);
814   GroupArguments->setEnabled(true);
815   GroupButtons->setEnabled(true);
816
817   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
818
819   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
820     aViewWindow->SetSelectionMode(CellSelection);
821   SelectionIntoArgument();
822 }
823
824 //=================================================================================
825 // function : enterEvent()
826 // purpose  :
827 //=================================================================================
828 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
829 {
830   if (!GroupConstructors->isEnabled())
831     ActivateThisDialog();
832 }
833
834 //=================================================================================
835 // function : closeEvent()
836 // purpose  :
837 //=================================================================================
838 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
839 {
840   /* same than click on cancel button */
841   this->ClickOnCancel();
842 }
843
844 //=======================================================================
845 // function : hideEvent()
846 // purpose  : caused by ESC key
847 //=======================================================================
848 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
849 {
850   if (!isMinimized())
851     ClickOnCancel();
852 }
853
854 //=======================================================================
855 //function : onSelectMesh
856 //purpose  :
857 //=======================================================================
858 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
859 {
860   if (toSelectMesh)
861     TextLabelElements->setText(tr("SMESH_NAME"));
862   else
863     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
864
865   if (myEditCurrentArgument != LineEditElements) {
866     LineEditElements->clear();
867     return;
868   }
869
870   mySelectionMgr->clearFilters();
871   SMESH::SetPointRepresentation(false);
872
873   if (toSelectMesh) {
874     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
875       aViewWindow->SetSelectionMode(ActorSelection);
876     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
877     LineEditElements->setReadOnly(true);
878   } else {
879     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
880       aViewWindow->SetSelectionMode(CellSelection);
881     LineEditElements->setReadOnly(false);
882     onTextChange(LineEditElements->text());
883   }
884
885   SelectionIntoArgument();
886 }
887
888 //=================================================================================
889 // function : GetConstructorId()
890 // purpose  :
891 //=================================================================================
892 int SMESHGUI_SymmetryDlg::GetConstructorId()
893 {
894   if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
895     return GroupConstructors->id(GroupConstructors->selected());
896   return -1;
897 }
898
899 //=================================================================================
900 // function : IsMirrorOk()
901 // purpose  :
902 //=================================================================================
903 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
904 {
905   bool isOk = true;
906
907   if (GetConstructorId() != 0)
908     isOk = (SpinBox_DX->GetValue() != 0 ||
909             SpinBox_DY->GetValue() != 0 ||
910             SpinBox_DZ->GetValue() != 0);
911
912   return isOk;
913 }
914
915 //=================================================================================
916 // function : onVectorChanged()
917 // purpose  :
918 //=================================================================================
919 void SMESHGUI_SymmetryDlg::onVectorChanged()
920 {
921   if (IsMirrorOk()) {
922     buttonOk->setEnabled(true);
923     buttonApply->setEnabled(true);
924   } else {
925     buttonOk->setEnabled(false);
926     buttonApply->setEnabled(false);
927   }
928 }
929
930 //=================================================================================
931 // function : keyPressEvent()
932 // purpose  :
933 //=================================================================================
934 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
935 {
936   QDialog::keyPressEvent( e );
937   if ( e->isAccepted() )
938     return;
939
940   if ( e->key() == Key_F1 )
941     {
942       e->accept();
943       ClickOnHelp();
944     }
945 }