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