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