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