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