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