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