Salome HOME
Additional fix for bug IPAL9834(selection in transformation does not work for group...
[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
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->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
222   TextLabelX->setText(tr("SMESH_X"));
223   GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
224
225   SpinBox_X = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_X");
226   GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
227
228   TextLabelY = new QLabel(GroupMirror, "TextLabelY");
229   TextLabelY->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
230   TextLabelY->setText(tr("SMESH_Y"));
231   GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
232
233   SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_Y");
234   GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
235
236   TextLabelZ = new QLabel(GroupMirror, "TextLabelZ");
237   TextLabelZ->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
238   TextLabelZ->setText(tr("SMESH_Z"));
239   GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
240
241   SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_Z");
242   GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
243
244   TextLabelVector = new QLabel(GroupMirror, "TextLabelVector");
245   GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
246
247   SelectVectorButton = new QPushButton(GroupMirror, "SelectVectorButton");
248   SelectVectorButton->setPixmap(image3);
249   GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
250
251   TextLabelDX = new QLabel(GroupMirror, "TextLabelDX");
252   TextLabelDX->setText(tr("SMESH_DX"));
253   GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
254
255   SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_DX");
256   GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
257
258   TextLabelDY = new QLabel(GroupMirror, "TextLabelDY");
259   TextLabelDY->setText(tr("SMESH_DY"));
260   GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
261
262   SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_DY");
263   GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
264
265   TextLabelDZ = new QLabel(GroupMirror, "TextLabelDZ");
266   TextLabelDZ->setText(tr("SMESH_DZ"));
267   GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
268
269   SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_DZ");
270   GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
271
272   GroupArgumentsLayout->addMultiCellWidget(GroupMirror, 2, 2, 0, 2);
273
274   // Controls for "Create a copy" option
275   CheckBoxCopy = new QCheckBox(GroupArguments, "CheckBoxCopy");
276   CheckBoxCopy->setText(tr("SMESH_CREATE_COPY"));
277   GroupArgumentsLayout->addMultiCellWidget(CheckBoxCopy, 3, 3, 0, 2);
278
279
280   SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments, 1, 0);
281
282   /* Initialisations */
283   SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
284   SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
285   SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
286   SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
287   SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
288   SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
289
290   GroupArguments->show();
291   RadioButton1->setChecked(TRUE);
292
293   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
294
295   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
296
297   // Costruction of the logical filter
298   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
299   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
300
301   QPtrList<SUIT_SelectionFilter> aListOfFilters;
302   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
303   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
304
305   myMeshOrSubMeshOrGroupFilter =
306     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
307
308   myHelpFileName = "/files/symmetry.htm";
309
310   Init();
311
312   /* signals and slots connections */
313   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
314   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
315   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
316   connect(buttonHelp, SIGNAL(clicked()),   this, SLOT(ClickOnHelp()));
317   connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
318
319   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
320   connect(SelectPointButton, SIGNAL (clicked()),    this, SLOT(SetEditCurrentArgument()));
321   connect(SelectVectorButton, SIGNAL (clicked()),   this, SLOT(SetEditCurrentArgument()));
322
323   connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
324   connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
325   connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
326
327   connect(mySMESHGUI,     SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
328   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),      this, SLOT(SelectionIntoArgument()));
329   /* to close dialog if study change */
330   connect(mySMESHGUI,       SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
331   connect(LineEditElements, SIGNAL(textChanged(const QString&)),   SLOT(onTextChange(const QString&)));
332   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                 SLOT(onSelectMesh(bool)));
333
334   this->show(); /* displays Dialog */
335
336   ConstructorsClicked(0);
337   SelectionIntoArgument();
338   resize(0,0); // ??
339 }
340
341 //=================================================================================
342 // function : ~SMESHGUI_SymmetryDlg()
343 // purpose  : Destroys the object and frees any allocated resources
344 //=================================================================================
345 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
346 {
347   // no need to delete child widgets, Qt does it all for us
348 }
349
350 //=================================================================================
351 // function : Init()
352 // purpose  :
353 //=================================================================================
354 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
355 {
356   myBusy = false;
357
358   myEditCurrentArgument = 0;
359   LineEditElements->clear();
360   myElementsId = "";
361   myNbOkElements = 0;
362
363   buttonOk->setEnabled(false);
364   buttonApply->setEnabled(false);
365
366   myActor = 0;
367   myMesh = SMESH::SMESH_Mesh::_nil();
368
369   if (ResetControls) {
370     SpinBox_X->SetValue(0.0);
371     SpinBox_Y->SetValue(0.0);
372     SpinBox_Z->SetValue(0.0);
373     SpinBox_DX->SetValue(0.0);
374     SpinBox_DY->SetValue(0.0);
375     SpinBox_DZ->SetValue(0.0);
376
377     CheckBoxCopy->setChecked(false);
378     CheckBoxMesh->setChecked(false);
379     onSelectMesh(false);
380   }
381 }
382
383 //=================================================================================
384 // function : ConstructorsClicked()
385 // purpose  : Radio button management
386 //=================================================================================
387 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
388 {
389   disconnect(mySelectionMgr, 0, this, 0);
390
391   if (constructorId != 0 && !TextLabelVector->isVisible()) {
392     TextLabelVector->show();
393     SelectVectorButton->show();
394     TextLabelDX->show();
395     SpinBox_DX->show();
396     TextLabelDY->show();
397     SpinBox_DY->show();
398     TextLabelDZ->show();
399     SpinBox_DZ->show();
400   }
401
402   switch (constructorId) {
403   case 0:
404     {
405       GroupMirror->setTitle(tr("SMESH_POINT"));
406
407       TextLabelVector->hide();
408       SelectVectorButton->hide();
409       TextLabelDX->hide();
410       SpinBox_DX->hide();
411       TextLabelDY->hide();
412       SpinBox_DY->hide();
413       TextLabelDZ->hide();
414       SpinBox_DZ->hide();
415       break;
416     }
417   case 1:
418     {
419       GroupMirror->setTitle(tr("SMESH_AXIS"));
420       TextLabelVector->setText(tr("SMESH_VECTOR"));
421       break;
422     }
423   case 2:
424     {
425       GroupMirror->setTitle(tr("SMESH_PLANE"));
426       TextLabelVector->setText(tr("SMESH_NORMAL"));
427       break;
428     }
429   }
430
431   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
432     SMESH::SetPointRepresentation(false);
433     if (!CheckBoxMesh->isChecked())
434       {
435         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
436           aViewWindow->SetSelectionMode(CellSelection);
437       }
438   }
439
440   myEditCurrentArgument = (QWidget*)LineEditElements;
441   LineEditElements->setFocus();
442
443   if (CheckBoxMesh->isChecked())
444     onSelectMesh(true);
445
446   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
447 }
448
449 //=================================================================================
450 // function : ClickOnApply()
451 // purpose  :
452 //=================================================================================
453 void SMESHGUI_SymmetryDlg::ClickOnApply()
454 {
455   if (mySMESHGUI->isActiveStudyLocked())
456     return;
457
458   if (myNbOkElements && IsMirrorOk()) {
459     QStringList aListElementsId = QStringList::split(" ", myElementsId, false);
460
461     SMESH::long_array_var anElementsId = new SMESH::long_array;
462
463     anElementsId->length(aListElementsId.count());
464     for (int i = 0; i < aListElementsId.count(); i++)
465       anElementsId[i] = aListElementsId[i].toInt();
466
467     SMESH::AxisStruct aMirror;
468
469     aMirror.x =  SpinBox_X->GetValue();
470     aMirror.y =  SpinBox_Y->GetValue();
471     aMirror.z =  SpinBox_Z->GetValue();
472     if (GetConstructorId() == 0) {
473       aMirror.vx = aMirror.vy = aMirror.vz = 0;
474     } else {
475       aMirror.vx = SpinBox_DX->GetValue();
476       aMirror.vy = SpinBox_DY->GetValue();
477       aMirror.vz = SpinBox_DZ->GetValue();
478     }
479
480     bool toCreateCopy = CheckBoxCopy->isChecked();
481
482     SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
483
484     if (GetConstructorId() == 0)
485       aMirrorType = SMESH::SMESH_MeshEditor::POINT;
486     if (GetConstructorId() == 1)
487       aMirrorType = SMESH::SMESH_MeshEditor::AXIS;
488     if (GetConstructorId() == 2)
489       aMirrorType = SMESH::SMESH_MeshEditor::PLANE;
490
491     try {
492       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
493       QApplication::setOverrideCursor(Qt::waitCursor);
494       aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, toCreateCopy);
495       QApplication::restoreOverrideCursor();
496     } catch (...) {
497     }
498
499     SMESH::UpdateView();
500     Init(false);
501     ConstructorsClicked(GetConstructorId());
502     SelectionIntoArgument();
503   }
504 }
505
506 //=================================================================================
507 // function : ClickOnOk()
508 // purpose  :
509 //=================================================================================
510 void SMESHGUI_SymmetryDlg::ClickOnOk()
511 {
512   ClickOnApply();
513   ClickOnCancel();
514 }
515
516 //=================================================================================
517 // function : ClickOnCancel()
518 // purpose  :
519 //=================================================================================
520 void SMESHGUI_SymmetryDlg::ClickOnCancel()
521 {
522   disconnect(mySelectionMgr, 0, this, 0);
523   mySelectionMgr->clearFilters();
524   //mySelectionMgr->clearSelected();
525   SMESH::SetPointRepresentation(false);
526   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
527     aViewWindow->SetSelectionMode(ActorSelection);
528   mySMESHGUI->ResetState();
529   reject();
530 }
531
532 //=================================================================================
533 // function : ClickOnHelp()
534 // purpose  :
535 //=================================================================================
536 void SMESHGUI_SymmetryDlg::ClickOnHelp()
537 {
538   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
539   if (app) 
540     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
541   else {
542     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
543                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
544                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
545                            QObject::tr("BUT_OK"));
546   }
547 }
548
549 //=======================================================================
550 // function : onTextChange()
551 // purpose  :
552 //=======================================================================
553 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
554 {
555   QLineEdit* send = (QLineEdit*)sender();
556
557   if (myBusy) return;
558   myBusy = true;
559
560   if (send == LineEditElements)
561     myNbOkElements = 0;
562
563   buttonOk->setEnabled(false);
564   buttonApply->setEnabled(false);
565
566   // hilight entered elements
567   SMDS_Mesh* aMesh = 0;
568   if (myActor)
569     aMesh = myActor->GetObject()->GetMesh();
570
571   if (aMesh) {
572     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
573
574     TColStd_MapOfInteger newIndices;
575     
576     QStringList aListId = QStringList::split(" ", theNewText, false);
577
578     if (send == LineEditElements) {
579       for (int i = 0; i < aListId.count(); i++) {
580         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
581         if (e)
582           newIndices.Add(e->GetID());
583         myNbOkElements++;
584       }
585
586       mySelector->AddOrRemoveIndex( anIO, newIndices, false );
587       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
588         aViewWindow->highlight( anIO, true, true );
589       
590       myElementsId = theNewText;
591     }
592   }
593
594   if (myNbOkElements &&  IsMirrorOk()) {
595     buttonOk->setEnabled(true);
596     buttonApply->setEnabled(true);
597   }
598
599   myBusy = false;
600 }
601
602 //=================================================================================
603 // function : SelectionIntoArgument()
604 // purpose  : Called when selection as changed or other case
605 //=================================================================================
606 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
607 {
608   if (myBusy) return;
609
610   // clear
611   myActor = 0;
612   QString aString = "";
613
614   myBusy = true;
615   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
616     LineEditElements->setText(aString);
617     myNbOkElements = 0;
618     buttonOk->setEnabled(false);
619     buttonApply->setEnabled(false);
620   }
621   myBusy = false;
622
623   if (!GroupButtons->isEnabled()) // inactive
624     return;
625
626   // get selected mesh
627   SALOME_ListIO aList;
628   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
629
630   int nbSel = aList.Extent();
631   if (nbSel != 1)
632     return;
633
634   Handle(SALOME_InteractiveObject) IO = aList.First();
635   myMesh = SMESH::GetMeshByIO(IO);
636   if(myMesh->_is_nil())
637     return;
638
639   myActor = SMESH::FindActorByObject(myMesh);
640   if (!myActor)
641     myActor = SMESH::FindActorByEntry(IO->getEntry());
642   if (!myActor)
643     return;
644
645   int aNbUnits = 0;
646
647   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
648     myElementsId = "";
649
650     if (CheckBoxMesh->isChecked()) {
651       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
652
653       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
654         // get IDs from mesh
655         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
656         if (!aSMDSMesh)
657           return;
658
659         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
660           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
661           if (e) {
662             myElementsId += QString(" %1").arg(i);
663             aNbUnits++;
664           }
665         }
666       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
667         // get submesh
668         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
669
670         // get IDs from submesh
671         SMESH::long_array_var anElementsIds = new SMESH::long_array;
672         anElementsIds = aSubMesh->GetElementsId();
673         for (int i = 0; i < anElementsIds->length(); i++) {
674           myElementsId += QString(" %1").arg(anElementsIds[i]);
675         }
676         aNbUnits = anElementsIds->length();
677       } else { // GROUP
678         // get smesh group
679         SMESH::SMESH_GroupBase_var aGroup =
680           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
681         if (aGroup->_is_nil())
682           return;
683
684         // get IDs from smesh group
685         SMESH::long_array_var anElementsIds = new SMESH::long_array;
686         anElementsIds = aGroup->GetListOfID();
687         for (int i = 0; i < anElementsIds->length(); i++) {
688           myElementsId += QString(" %1").arg(anElementsIds[i]);
689         }
690         aNbUnits = anElementsIds->length();
691       }
692     } else {
693       aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
694       myElementsId = aString;
695     }
696
697     if (aNbUnits < 1)
698       return;
699
700     myNbOkElements = true;
701   } else {
702     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
703     if (aNbUnits != 1)
704       return;
705
706     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
707     if (!aMesh)
708       return;
709
710     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
711     if (!n)
712       return;
713
714     double x = n->X();
715     double y = n->Y();
716     double z = n->Z();
717
718     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
719       SpinBox_X->SetValue(x);
720       SpinBox_Y->SetValue(y);
721       SpinBox_Z->SetValue(z);
722     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
723       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
724       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
725       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
726     }
727   }
728
729   myBusy = true;
730   if (myEditCurrentArgument == (QWidget*)LineEditElements)
731     LineEditElements->setText(aString);
732   myBusy = false;
733
734   // OK
735   if (myNbOkElements && IsMirrorOk()) {
736     buttonOk->setEnabled(true);
737     buttonApply->setEnabled(true);
738   }
739 }
740
741 //=================================================================================
742 // function : SetEditCurrentArgument()
743 // purpose  :
744 //=================================================================================
745 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
746 {
747   QPushButton* send = (QPushButton*)sender();
748
749   disconnect(mySelectionMgr, 0, this, 0);
750   mySelectionMgr->clearSelected();
751   mySelectionMgr->clearFilters();
752
753   if (send == SelectElementsButton) {
754     myEditCurrentArgument = (QWidget*)LineEditElements;
755     SMESH::SetPointRepresentation(false);
756     if (CheckBoxMesh->isChecked()) {
757       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
758         aViewWindow->SetSelectionMode(ActorSelection);
759       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
760     } else {
761       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
762         aViewWindow->SetSelectionMode(CellSelection);
763     }
764   } else if (send == SelectPointButton) {
765     myEditCurrentArgument = (QWidget*)SpinBox_X;
766     SMESH::SetPointRepresentation(true);
767     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
768       aViewWindow->SetSelectionMode(NodeSelection);
769   } else if (send == SelectVectorButton) {
770     myEditCurrentArgument = (QWidget*)SpinBox_DX;
771     SMESH::SetPointRepresentation(true);
772
773     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
774       aViewWindow->SetSelectionMode(NodeSelection);
775   } else {
776   }
777
778   myEditCurrentArgument->setFocus();
779   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
780   SelectionIntoArgument();
781 }
782
783 //=================================================================================
784 // function : DeactivateActiveDialog()
785 // purpose  :
786 //=================================================================================
787 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
788 {
789   if (GroupConstructors->isEnabled()) {
790     GroupConstructors->setEnabled(false);
791     GroupArguments->setEnabled(false);
792     GroupButtons->setEnabled(false);
793     mySMESHGUI->ResetState();
794     mySMESHGUI->SetActiveDialogBox(0);
795   }
796 }
797
798 //=================================================================================
799 // function : ActivateThisDialog()
800 // purpose  :
801 //=================================================================================
802 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
803 {
804   /* Emit a signal to deactivate the active dialog */
805   mySMESHGUI->EmitSignalDeactivateDialog();
806   GroupConstructors->setEnabled(true);
807   GroupArguments->setEnabled(true);
808   GroupButtons->setEnabled(true);
809
810   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
811
812   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
813     aViewWindow->SetSelectionMode(CellSelection);
814   SelectionIntoArgument();
815 }
816
817 //=================================================================================
818 // function : enterEvent()
819 // purpose  :
820 //=================================================================================
821 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
822 {
823   if (!GroupConstructors->isEnabled())
824     ActivateThisDialog();
825 }
826
827 //=================================================================================
828 // function : closeEvent()
829 // purpose  :
830 //=================================================================================
831 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
832 {
833   /* same than click on cancel button */
834   this->ClickOnCancel();
835 }
836
837 //=======================================================================
838 // function : hideEvent()
839 // purpose  : caused by ESC key
840 //=======================================================================
841 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
842 {
843   if (!isMinimized())
844     ClickOnCancel();
845 }
846
847 //=======================================================================
848 //function : onSelectMesh
849 //purpose  :
850 //=======================================================================
851 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
852 {
853   if (toSelectMesh)
854     TextLabelElements->setText(tr("SMESH_NAME"));
855   else
856     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
857
858   if (myEditCurrentArgument != LineEditElements) {
859     LineEditElements->clear();
860     return;
861   }
862
863   mySelectionMgr->clearFilters();
864   SMESH::SetPointRepresentation(false);
865
866   if (toSelectMesh) {
867     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
868       aViewWindow->SetSelectionMode(ActorSelection);
869     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
870     LineEditElements->setReadOnly(true);
871   } else {
872     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
873       aViewWindow->SetSelectionMode(CellSelection);
874     LineEditElements->setReadOnly(false);
875     onTextChange(LineEditElements->text());
876   }
877
878   SelectionIntoArgument();
879 }
880
881 //=================================================================================
882 // function : GetConstructorId()
883 // purpose  :
884 //=================================================================================
885 int SMESHGUI_SymmetryDlg::GetConstructorId()
886 {
887   if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
888     return GroupConstructors->id(GroupConstructors->selected());
889   return -1;
890 }
891
892 //=================================================================================
893 // function : IsMirrorOk()
894 // purpose  :
895 //=================================================================================
896 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
897 {
898   bool isOk = true;
899
900   if (GetConstructorId() != 0)
901     isOk = (SpinBox_DX->GetValue() != 0 ||
902             SpinBox_DY->GetValue() != 0 ||
903             SpinBox_DZ->GetValue() != 0);
904
905   return isOk;
906 }
907
908 //=================================================================================
909 // function : onVectorChanged()
910 // purpose  :
911 //=================================================================================
912 void SMESHGUI_SymmetryDlg::onVectorChanged()
913 {
914   if (IsMirrorOk()) {
915     buttonOk->setEnabled(true);
916     buttonApply->setEnabled(true);
917   } else {
918     buttonOk->setEnabled(false);
919     buttonApply->setEnabled(false);
920   }
921 }
922
923 //=================================================================================
924 // function : keyPressEvent()
925 // purpose  :
926 //=================================================================================
927 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
928 {
929   QDialog::keyPressEvent( e );
930   if ( e->isAccepted() )
931     return;
932
933   if ( e->key() == Key_F1 )
934     {
935       e->accept();
936       ClickOnHelp();
937     }
938 }