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