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 #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 = "/files/symmetry.htm";
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     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
588                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
589                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
590                            QObject::tr("BUT_OK"));
591   }
592 }
593
594 //=======================================================================
595 // function : onTextChange()
596 // purpose  :
597 //=======================================================================
598 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
599 {
600   QLineEdit* send = (QLineEdit*)sender();
601
602   if (myBusy) return;
603   myBusy = true;
604
605   if (send == LineEditElements)
606     myNbOkElements = 0;
607
608   buttonOk->setEnabled(false);
609   buttonApply->setEnabled(false);
610
611   // hilight entered elements
612   SMDS_Mesh* aMesh = 0;
613   if (myActor)
614     aMesh = myActor->GetObject()->GetMesh();
615
616   if (aMesh) {
617     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
618
619     TColStd_MapOfInteger newIndices;
620     
621     QStringList aListId = QStringList::split(" ", theNewText, false);
622
623     if (send == LineEditElements) {
624       for (int i = 0; i < aListId.count(); i++) {
625         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
626         if (e)
627           newIndices.Add(e->GetID());
628         myNbOkElements++;
629       }
630
631       mySelector->AddOrRemoveIndex( anIO, newIndices, false );
632       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
633         aViewWindow->highlight( anIO, true, true );
634       
635       myElementsId = theNewText;
636     }
637   }
638
639   if (myNbOkElements &&  IsMirrorOk()) {
640     buttonOk->setEnabled(true);
641     buttonApply->setEnabled(true);
642   }
643
644   myBusy = false;
645 }
646
647 //=================================================================================
648 // function : SelectionIntoArgument()
649 // purpose  : Called when selection as changed or other case
650 //=================================================================================
651 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
652 {
653   if (myBusy) return;
654
655   // clear
656   myActor = 0;
657   QString aString = "";
658
659   myBusy = true;
660   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
661     LineEditElements->setText(aString);
662     myNbOkElements = 0;
663     buttonOk->setEnabled(false);
664     buttonApply->setEnabled(false);
665   }
666   myBusy = false;
667
668   if (!GroupButtons->isEnabled()) // inactive
669     return;
670
671   // get selected mesh
672   SALOME_ListIO aList;
673   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
674
675   int nbSel = aList.Extent();
676   if (nbSel != 1)
677     return;
678
679   Handle(SALOME_InteractiveObject) IO = aList.First();
680   myMesh = SMESH::GetMeshByIO(IO);
681   if(myMesh->_is_nil())
682     return;
683
684   myActor = SMESH::FindActorByObject(myMesh);
685   if (!myActor)
686     myActor = SMESH::FindActorByEntry(IO->getEntry());
687   if (!myActor)
688     return;
689
690   int aNbUnits = 0;
691
692   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
693     myElementsId = "";
694
695     // MakeGroups is available if there are groups and "Copy"
696     if ( myMesh->NbGroups() == 0 ) {
697       MakeGroupsCheck->setChecked(false);
698       MakeGroupsCheck->setEnabled(false);
699     }
700     else if ( ActionGroup->id( ActionGroup->selected() ) != MOVE_ELEMS_BUTTON ) {
701       MakeGroupsCheck->setEnabled(true);
702     }
703     if (CheckBoxMesh->isChecked()) {
704       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
705
706       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
707         // get IDs from mesh
708         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
709         if (!aSMDSMesh)
710           return;
711
712         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
713           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
714           if (e) {
715             myElementsId += QString(" %1").arg(i);
716             aNbUnits++;
717           }
718         }
719       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
720         // get submesh
721         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
722
723         // get IDs from submesh
724         SMESH::long_array_var anElementsIds = new SMESH::long_array;
725         anElementsIds = aSubMesh->GetElementsId();
726         for (int i = 0; i < anElementsIds->length(); i++) {
727           myElementsId += QString(" %1").arg(anElementsIds[i]);
728         }
729         aNbUnits = anElementsIds->length();
730       } else { // GROUP
731         // get smesh group
732         SMESH::SMESH_GroupBase_var aGroup =
733           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
734         if (aGroup->_is_nil())
735           return;
736
737         // get IDs from smesh group
738         SMESH::long_array_var anElementsIds = new SMESH::long_array;
739         anElementsIds = aGroup->GetListOfID();
740         for (int i = 0; i < anElementsIds->length(); i++) {
741           myElementsId += QString(" %1").arg(anElementsIds[i]);
742         }
743         aNbUnits = anElementsIds->length();
744       }
745     } else {
746       aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
747       myElementsId = aString;
748     }
749
750     if (aNbUnits < 1)
751       return;
752
753     myNbOkElements = true;
754   } else {
755     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
756     if (aNbUnits != 1)
757       return;
758
759     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
760     if (!aMesh)
761       return;
762
763     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
764     if (!n)
765       return;
766
767     double x = n->X();
768     double y = n->Y();
769     double z = n->Z();
770
771     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
772       SpinBox_X->SetValue(x);
773       SpinBox_Y->SetValue(y);
774       SpinBox_Z->SetValue(z);
775     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
776       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
777       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
778       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
779     }
780   }
781
782   myBusy = true;
783   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
784     LineEditElements->setText(aString);
785     setNewMeshName();
786   }
787   myBusy = false;
788
789   // OK
790   if (myNbOkElements && IsMirrorOk()) {
791     buttonOk->setEnabled(true);
792     buttonApply->setEnabled(true);
793   }
794 }
795
796 //=================================================================================
797 // function : SetEditCurrentArgument()
798 // purpose  :
799 //=================================================================================
800 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
801 {
802   QPushButton* send = (QPushButton*)sender();
803
804   disconnect(mySelectionMgr, 0, this, 0);
805   mySelectionMgr->clearSelected();
806   mySelectionMgr->clearFilters();
807
808   if (send == SelectElementsButton) {
809     myEditCurrentArgument = (QWidget*)LineEditElements;
810     SMESH::SetPointRepresentation(false);
811     if (CheckBoxMesh->isChecked()) {
812       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
813         aViewWindow->SetSelectionMode(ActorSelection);
814       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
815     } else {
816       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
817         aViewWindow->SetSelectionMode(CellSelection);
818     }
819   } else if (send == SelectPointButton) {
820     myEditCurrentArgument = (QWidget*)SpinBox_X;
821     SMESH::SetPointRepresentation(true);
822     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
823       aViewWindow->SetSelectionMode(NodeSelection);
824   } else if (send == SelectVectorButton) {
825     myEditCurrentArgument = (QWidget*)SpinBox_DX;
826     SMESH::SetPointRepresentation(true);
827
828     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
829       aViewWindow->SetSelectionMode(NodeSelection);
830   } else {
831   }
832
833   myEditCurrentArgument->setFocus();
834   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
835   SelectionIntoArgument();
836 }
837
838 //=================================================================================
839 // function : DeactivateActiveDialog()
840 // purpose  :
841 //=================================================================================
842 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
843 {
844   if (GroupConstructors->isEnabled()) {
845     GroupConstructors->setEnabled(false);
846     GroupArguments->setEnabled(false);
847     GroupButtons->setEnabled(false);
848     mySMESHGUI->ResetState();
849     mySMESHGUI->SetActiveDialogBox(0);
850   }
851 }
852
853 //=================================================================================
854 // function : ActivateThisDialog()
855 // purpose  :
856 //=================================================================================
857 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
858 {
859   /* Emit a signal to deactivate the active dialog */
860   mySMESHGUI->EmitSignalDeactivateDialog();
861   GroupConstructors->setEnabled(true);
862   GroupArguments->setEnabled(true);
863   GroupButtons->setEnabled(true);
864
865   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
866
867   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
868     aViewWindow->SetSelectionMode(CellSelection);
869   SelectionIntoArgument();
870 }
871
872 //=================================================================================
873 // function : enterEvent()
874 // purpose  :
875 //=================================================================================
876 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
877 {
878   if (!GroupConstructors->isEnabled())
879     ActivateThisDialog();
880 }
881
882 //=================================================================================
883 // function : closeEvent()
884 // purpose  :
885 //=================================================================================
886 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
887 {
888   /* same than click on cancel button */
889   this->ClickOnCancel();
890 }
891
892 //=======================================================================
893 // function : hideEvent()
894 // purpose  : caused by ESC key
895 //=======================================================================
896 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
897 {
898   if (!isMinimized())
899     ClickOnCancel();
900 }
901
902 //=======================================================================
903 //function : onSelectMesh
904 //purpose  :
905 //=======================================================================
906 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
907 {
908   if (toSelectMesh)
909     TextLabelElements->setText(tr("SMESH_NAME"));
910   else
911     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
912
913   if (myEditCurrentArgument != LineEditElements) {
914     LineEditElements->clear();
915     return;
916   }
917
918   mySelectionMgr->clearFilters();
919   SMESH::SetPointRepresentation(false);
920
921   if (toSelectMesh) {
922     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
923       aViewWindow->SetSelectionMode(ActorSelection);
924     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
925     LineEditElements->setReadOnly(true);
926   } else {
927     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
928       aViewWindow->SetSelectionMode(CellSelection);
929     LineEditElements->setReadOnly(false);
930     onTextChange(LineEditElements->text());
931   }
932
933   SelectionIntoArgument();
934 }
935
936 //=================================================================================
937 // function : GetConstructorId()
938 // purpose  :
939 //=================================================================================
940 int SMESHGUI_SymmetryDlg::GetConstructorId()
941 {
942   if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
943     return GroupConstructors->id(GroupConstructors->selected());
944   return -1;
945 }
946
947 //=================================================================================
948 // function : IsMirrorOk()
949 // purpose  :
950 //=================================================================================
951 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
952 {
953   bool isOk = true;
954
955   if (GetConstructorId() != 0)
956     isOk = (SpinBox_DX->GetValue() != 0 ||
957             SpinBox_DY->GetValue() != 0 ||
958             SpinBox_DZ->GetValue() != 0);
959
960   return isOk;
961 }
962
963 //=================================================================================
964 // function : onVectorChanged()
965 // purpose  :
966 //=================================================================================
967 void SMESHGUI_SymmetryDlg::onVectorChanged()
968 {
969   if (IsMirrorOk()) {
970     buttonOk->setEnabled(true);
971     buttonApply->setEnabled(true);
972   } else {
973     buttonOk->setEnabled(false);
974     buttonApply->setEnabled(false);
975   }
976 }
977
978 //=======================================================================
979 //function : onActionClicked
980 //purpose  : slot called when an action type changed
981 //=======================================================================
982
983 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
984 {
985   switch ( button ) {
986   case MOVE_ELEMS_BUTTON:
987     MakeGroupsCheck->setEnabled(false);
988     LineEditNewMesh->setEnabled(false);
989     break;
990   case COPY_ELEMS_BUTTON:
991     LineEditNewMesh->setEnabled(false);
992     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
993     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
994       MakeGroupsCheck->setEnabled(true);
995     else
996       MakeGroupsCheck->setEnabled(false);
997     break;
998   case MAKE_MESH_BUTTON:
999     LineEditNewMesh->setEnabled(true);
1000     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1001     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1002       MakeGroupsCheck->setEnabled(true);
1003     else
1004       MakeGroupsCheck->setEnabled(false);
1005     break;
1006   }
1007   setNewMeshName();
1008 }
1009
1010 //=======================================================================
1011 //function : setNewMeshName
1012 //purpose  : update contents of LineEditNewMesh
1013 //=======================================================================
1014
1015 void SMESHGUI_SymmetryDlg::setNewMeshName()
1016 {
1017   LineEditNewMesh->setText("");
1018   if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
1019     QString name;
1020     if ( CheckBoxMesh->isChecked() ) {
1021       name = LineEditElements->text();
1022     }
1023     else {
1024       _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1025       name = meshSO->GetName();
1026     }
1027     if ( !name.isEmpty() )
1028       LineEditNewMesh->setText( SMESH::UniqueMeshName( name.latin1(), "mirrored"));
1029   }
1030 }
1031
1032 //=================================================================================
1033 // function : keyPressEvent()
1034 // purpose  :
1035 //=================================================================================
1036 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1037 {
1038   QDialog::keyPressEvent( e );
1039   if ( e->isAccepted() )
1040     return;
1041
1042   if ( e->key() == Key_F1 )
1043     {
1044       e->accept();
1045       ClickOnHelp();
1046     }
1047 }