Salome HOME
The selections of elements corrected.
[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       myViewWindow( SMESH::GetViewWindow( theModule ) ),
87       mySelector( myViewWindow->GetSelector() )
88 {
89   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_POINT")));
90   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_AXIS")));
91   QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_PLANE")));
92   QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
93
94   if (!name)
95     setName("SMESHGUI_SymmetryDlg");
96   resize(303, 185);
97   setCaption(tr("SMESH_SYMMETRY"));
98   setSizeGripEnabled(TRUE);
99   SMESHGUI_SymmetryDlgLayout = new QGridLayout(this);
100   SMESHGUI_SymmetryDlgLayout->setSpacing(6);
101   SMESHGUI_SymmetryDlgLayout->setMargin(11);
102
103   /***************************************************************/
104   GroupConstructors = new QButtonGroup(this, "GroupConstructors");
105   GroupConstructors->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5,
106                                                (QSizePolicy::SizeType)0, 0, 0,
107                                                GroupConstructors->sizePolicy().hasHeightForWidth()));
108   GroupConstructors->setTitle(tr("SMESH_SYMMETRY" ));
109   GroupConstructors->setExclusive(TRUE);
110   GroupConstructors->setColumnLayout(0, Qt::Vertical);
111   GroupConstructors->layout()->setSpacing(0);
112   GroupConstructors->layout()->setMargin(0);
113   GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
114   GroupConstructorsLayout->setAlignment(Qt::AlignTop);
115   GroupConstructorsLayout->setSpacing(6);
116   GroupConstructorsLayout->setMargin(11);
117   QHBoxLayout* RBLayout = new QHBoxLayout(0, 0, 6, "Layout2");
118   RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
119   RadioButton1->setText(tr("" ));
120   RadioButton1->setPixmap(image0);
121   RBLayout->addWidget(RadioButton1);
122   RadioButton2= new QRadioButton(GroupConstructors, "RadioButton2");
123   RadioButton2->setText(tr("" ));
124   RadioButton2->setPixmap(image1);
125   RBLayout->addWidget(RadioButton2);
126   RadioButton3= new QRadioButton(GroupConstructors, "RadioButton3");
127   RadioButton3->setText(tr("" ));
128   RadioButton3->setPixmap(image2);
129   RBLayout->addWidget(RadioButton3);
130   GroupConstructorsLayout->addLayout(RBLayout, 0, 0);
131   SMESHGUI_SymmetryDlgLayout->addWidget(GroupConstructors, 0, 0);
132
133   /***************************************************************/
134   GroupButtons = new QGroupBox(this, "GroupButtons");
135   GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
136                                           (QSizePolicy::SizeType)0, 0, 0,
137                                           GroupButtons->sizePolicy().hasHeightForWidth()));
138   GroupButtons->setGeometry(QRect(10, 10, 281, 48));
139   GroupButtons->setTitle(tr("" ));
140   GroupButtons->setColumnLayout(0, Qt::Vertical);
141   GroupButtons->layout()->setSpacing(0);
142   GroupButtons->layout()->setMargin(0);
143   GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
144   GroupButtonsLayout->setAlignment(Qt::AlignTop);
145   GroupButtonsLayout->setSpacing(6);
146   GroupButtonsLayout->setMargin(11);
147   buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
148   buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
149   buttonCancel->setAutoDefault(TRUE);
150   GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
151   buttonApply = new QPushButton(GroupButtons, "buttonApply");
152   buttonApply->setText(tr("SMESH_BUT_APPLY" ));
153   buttonApply->setAutoDefault(TRUE);
154   GroupButtonsLayout->addWidget(buttonApply, 0, 1);
155   QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
156   GroupButtonsLayout->addItem(spacer_9, 0, 2);
157   buttonOk = new QPushButton(GroupButtons, "buttonOk");
158   buttonOk->setText(tr("SMESH_BUT_OK" ));
159   buttonOk->setAutoDefault(TRUE);
160   buttonOk->setDefault(TRUE);
161   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
162   SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons, 2, 0);
163
164   /***************************************************************/
165   GroupArguments = new QGroupBox(this, "GroupArguments");
166   GroupArguments->setTitle(tr("SMESH_ARGUMENTS"));
167   GroupArguments->setColumnLayout(0, Qt::Vertical);
168   GroupArguments->layout()->setSpacing(0);
169   GroupArguments->layout()->setMargin(0);
170   GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
171   GroupArgumentsLayout->setAlignment(Qt::AlignTop);
172   GroupArgumentsLayout->setSpacing(6);
173   GroupArgumentsLayout->setMargin(11);
174
175   // Controls for elements selection
176   TextLabelElements  = new QLabel(GroupArguments, "TextLabelElements");
177   TextLabelElements->setText(tr("SMESH_ID_ELEMENTS" ));
178   TextLabelElements->setFixedWidth(74);
179   GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
180
181   SelectElementsButton  = new QPushButton(GroupArguments, "SelectElementsButton");
182   SelectElementsButton->setText(tr("" ));
183   SelectElementsButton->setPixmap(image3);
184   SelectElementsButton->setToggleButton(FALSE);
185   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
186
187   LineEditElements  = new QLineEdit(GroupArguments, "LineEditElements");
188   LineEditElements->setValidator(new SMESHGUI_IdValidator(this, "validator"));
189   GroupArgumentsLayout->addWidget(LineEditElements, 0, 2);
190
191   // Control for the whole mesh selection
192   CheckBoxMesh = new QCheckBox(GroupArguments, "CheckBoxMesh");
193   CheckBoxMesh->setText(tr("SMESH_SELECT_WHOLE_MESH" ));
194   GroupArgumentsLayout->addMultiCellWidget(CheckBoxMesh, 1, 1, 0, 2);
195
196   // Controls for mirror selection
197   GroupMirror = new QGroupBox(GroupArguments, "GroupMirror");
198   GroupMirror->setColumnLayout(0, Qt::Vertical);
199   GroupMirror->layout()->setSpacing(0);
200   GroupMirror->layout()->setMargin(0);
201   QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror->layout());
202   GroupMirrorLayout->setAlignment(Qt::AlignTop);
203   GroupMirrorLayout->setSpacing(6);
204   GroupMirrorLayout->setMargin(11);
205
206   TextLabelPoint = new QLabel(GroupMirror, "TextLabelPoint");
207   TextLabelPoint->setText(tr("SMESH_POINT"));
208   GroupMirrorLayout->addWidget(TextLabelPoint, 0, 0);
209
210   SelectPointButton  = new QPushButton(GroupMirror, "SelectPointButton");
211   SelectPointButton->setPixmap(image3);
212   GroupMirrorLayout->addWidget(SelectPointButton, 0, 1);
213
214   TextLabelX = new QLabel(GroupMirror, "TextLabelX");
215   TextLabelX->setText(tr("SMESH_X"));
216   GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
217
218   SpinBox_X = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_X");
219   GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
220
221   TextLabelY = new QLabel(GroupMirror, "TextLabelY");
222   TextLabelY->setText(tr("SMESH_Y"));
223   GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
224
225   SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_Y");
226   GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
227
228   TextLabelZ = new QLabel(GroupMirror, "TextLabelZ");
229   TextLabelZ->setText(tr("SMESH_Z"));
230   GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
231
232   SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_Z");
233   GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
234
235   TextLabelVector = new QLabel(GroupMirror, "TextLabelVector");
236   GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
237
238   SelectVectorButton = new QPushButton(GroupMirror, "SelectVectorButton");
239   SelectVectorButton->setPixmap(image3);
240   GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
241
242   TextLabelDX = new QLabel(GroupMirror, "TextLabelDX");
243   TextLabelDX->setText(tr("SMESH_DX"));
244   GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
245
246   SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_DX");
247   GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
248
249   TextLabelDY = new QLabel(GroupMirror, "TextLabelDY");
250   TextLabelDY->setText(tr("SMESH_DY"));
251   GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
252
253   SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_DY");
254   GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
255
256   TextLabelDZ = new QLabel(GroupMirror, "TextLabelDZ");
257   TextLabelDZ->setText(tr("SMESH_DZ"));
258   GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
259
260   SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_DZ");
261   GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
262
263   GroupArgumentsLayout->addMultiCellWidget(GroupMirror, 2, 2, 0, 2);
264
265   // Controls for "Create a copy" option
266   CheckBoxCopy = new QCheckBox(GroupArguments, "CheckBoxCopy");
267   CheckBoxCopy->setText(tr("SMESH_CREATE_COPY"));
268   GroupArgumentsLayout->addMultiCellWidget(CheckBoxCopy, 3, 3, 0, 2);
269
270
271   SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments, 1, 0);
272
273   /* Initialisations */
274   SpinBox_X->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
275   SpinBox_Y->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
276   SpinBox_Z->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
277   SpinBox_DX->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
278   SpinBox_DY->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
279   SpinBox_DZ->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
280
281   GroupArguments->show();
282   RadioButton1->setChecked(TRUE);
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   /* Move widget on the botton right corner of main widget */
321   int x, y;
322   mySMESHGUI->DefineDlgPosition(this, x, y);
323   this->move(x, y);
324   this->show(); /* displays Dialog */
325
326   ConstructorsClicked(0);
327   resize(0,0); // ??
328 }
329
330 //=================================================================================
331 // function : ~SMESHGUI_SymmetryDlg()
332 // purpose  : Destroys the object and frees any allocated resources
333 //=================================================================================
334 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
335 {
336   // no need to delete child widgets, Qt does it all for us
337 }
338
339 //=================================================================================
340 // function : Init()
341 // purpose  :
342 //=================================================================================
343 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
344 {
345   myBusy = false;
346
347   myEditCurrentArgument = 0;
348   LineEditElements->clear();
349   myElementsId = "";
350   myNbOkElements = 0;
351
352   buttonOk->setEnabled(false);
353   buttonApply->setEnabled(false);
354
355   myActor = 0;
356   myMesh = SMESH::SMESH_Mesh::_nil();
357
358   if (ResetControls) {
359     SpinBox_X->SetValue(0.0);
360     SpinBox_Y->SetValue(0.0);
361     SpinBox_Z->SetValue(0.0);
362     SpinBox_DX->SetValue(0.0);
363     SpinBox_DY->SetValue(0.0);
364     SpinBox_DZ->SetValue(0.0);
365
366     CheckBoxCopy->setChecked(false);
367     CheckBoxMesh->setChecked(false);
368     onSelectMesh(false);
369   }
370 }
371
372 //=================================================================================
373 // function : ConstructorsClicked()
374 // purpose  : Radio button management
375 //=================================================================================
376 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
377 {
378   disconnect(mySelectionMgr, 0, this, 0);
379
380   if (constructorId != 0 && !TextLabelVector->isVisible()) {
381     TextLabelVector->show();
382     SelectVectorButton->show();
383     TextLabelDX->show();
384     SpinBox_DX->show();
385     TextLabelDY->show();
386     SpinBox_DY->show();
387     TextLabelDZ->show();
388     SpinBox_DZ->show();
389   }
390
391   switch (constructorId) {
392   case 0:
393     {
394       GroupMirror->setTitle(tr("SMESH_POINT"));
395
396       TextLabelVector->hide();
397       SelectVectorButton->hide();
398       TextLabelDX->hide();
399       SpinBox_DX->hide();
400       TextLabelDY->hide();
401       SpinBox_DY->hide();
402       TextLabelDZ->hide();
403       SpinBox_DZ->hide();
404       break;
405     }
406   case 1:
407     {
408       GroupMirror->setTitle(tr("SMESH_AXIS"));
409       TextLabelVector->setText(tr("SMESH_VECTOR"));
410       break;
411     }
412   case 2:
413     {
414       GroupMirror->setTitle(tr("SMESH_PLANE"));
415       TextLabelVector->setText(tr("SMESH_NORMAL"));
416       break;
417     }
418   }
419
420   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
421     SMESH::SetPointRepresentation(false);
422     if (!CheckBoxMesh->isChecked())
423       myViewWindow->SetSelectionMode(CellSelection);
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     mySelectionMgr->clearSelected();
486     SMESH::UpdateView();
487     Init(false);
488     ConstructorsClicked(GetConstructorId());
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   myViewWindow->SetSelectionMode(ActorSelection);
513   mySMESHGUI->ResetState();
514   reject();
515 }
516
517 //=======================================================================
518 // function : onTextChange()
519 // purpose  :
520 //=======================================================================
521 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
522 {
523   QLineEdit* send = (QLineEdit*)sender();
524
525   if (myBusy) return;
526   myBusy = true;
527
528   if (send == LineEditElements)
529     myNbOkElements = 0;
530
531   buttonOk->setEnabled(false);
532   buttonApply->setEnabled(false);
533
534   // hilight entered elements
535   SMDS_Mesh* aMesh = 0;
536   if (myActor)
537     aMesh = myActor->GetObject()->GetMesh();
538
539   if (aMesh) {
540     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
541
542     TColStd_MapOfInteger newIndices;
543     
544     QStringList aListId = QStringList::split(" ", theNewText, false);
545
546     if (send == LineEditElements) {
547       for (int i = 0; i < aListId.count(); i++) {
548         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
549         if (e)
550           newIndices.Add(e->GetID());
551         myNbOkElements++;
552       }
553
554       mySelector->AddOrRemoveIndex( anIO, newIndices, false );
555       myViewWindow->highlight( anIO, true, true );
556       
557       myElementsId = theNewText;
558     }
559   }
560
561   if (myNbOkElements &&  IsMirrorOk()) {
562     buttonOk->setEnabled(true);
563     buttonApply->setEnabled(true);
564   }
565
566   myBusy = false;
567 }
568
569 //=================================================================================
570 // function : SelectionIntoArgument()
571 // purpose  : Called when selection as changed or other case
572 //=================================================================================
573 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
574 {
575   if (myBusy) return;
576
577   // clear
578   myActor = 0;
579   QString aString = "";
580
581   myBusy = true;
582   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
583     LineEditElements->setText(aString);
584     myNbOkElements = 0;
585     buttonOk->setEnabled(false);
586     buttonApply->setEnabled(false);
587   }
588   myBusy = false;
589
590   if (!GroupButtons->isEnabled()) // inactive
591     return;
592
593   // get selected mesh
594   SALOME_ListIO aList;
595   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
596
597   int nbSel = aList.Extent();
598   if (nbSel != 1)
599     return;
600
601   Handle(SALOME_InteractiveObject) IO = aList.First();
602   myMesh = SMESH::GetMeshByIO(IO);
603   if(myMesh->_is_nil())
604     return;
605
606   myActor = SMESH::FindActorByObject(myMesh);
607   if (!myActor)
608     myActor = SMESH::FindActorByEntry(IO->getEntry());
609   if (!myActor)
610     return;
611
612   int aNbUnits = 0;
613
614   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
615     myElementsId = "";
616
617     if (CheckBoxMesh->isChecked()) {
618       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
619
620       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
621         // get IDs from mesh
622         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
623         if (!aSMDSMesh)
624           return;
625
626         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
627           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
628           if (e) {
629             myElementsId += QString(" %1").arg(i);
630             aNbUnits++;
631           }
632         }
633       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
634         // get submesh
635         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
636
637         // get IDs from submesh
638         SMESH::long_array_var anElementsIds = new SMESH::long_array;
639         anElementsIds = aSubMesh->GetElementsId();
640         for (int i = 0; i < anElementsIds->length(); i++) {
641           myElementsId += QString(" %1").arg(anElementsIds[i]);
642         }
643         aNbUnits = anElementsIds->length();
644       } else { // GROUP
645         // get smesh group
646         SMESH::SMESH_GroupBase_var aGroup =
647           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
648         if (aGroup->_is_nil())
649           return;
650
651         // get IDs from smesh group
652         SMESH::long_array_var anElementsIds = new SMESH::long_array;
653         anElementsIds = aGroup->GetListOfID();
654         for (int i = 0; i < anElementsIds->length(); i++) {
655           myElementsId += QString(" %1").arg(anElementsIds[i]);
656         }
657         aNbUnits = anElementsIds->length();
658       }
659     } else {
660       aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, myActor->getIO(), aString);
661       myElementsId = aString;
662     }
663
664     if (aNbUnits < 1)
665       return;
666
667     myNbOkElements = true;
668   } else {
669     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
670     if (aNbUnits != 1)
671       return;
672
673     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
674     if (!aMesh)
675       return;
676
677     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
678     if (!n)
679       return;
680
681     double x = n->X();
682     double y = n->Y();
683     double z = n->Z();
684
685     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
686       SpinBox_X->SetValue(x);
687       SpinBox_Y->SetValue(y);
688       SpinBox_Z->SetValue(z);
689     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
690       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
691       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
692       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
693     }
694   }
695
696   myBusy = true;
697   if (myEditCurrentArgument == (QWidget*)LineEditElements)
698     LineEditElements->setText(aString);
699   myBusy = false;
700
701   // OK
702   if (myNbOkElements && IsMirrorOk()) {
703     buttonOk->setEnabled(true);
704     buttonApply->setEnabled(true);
705   }
706 }
707
708 //=================================================================================
709 // function : SetEditCurrentArgument()
710 // purpose  :
711 //=================================================================================
712 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
713 {
714   QPushButton* send = (QPushButton*)sender();
715
716   disconnect(mySelectionMgr, 0, this, 0);
717   mySelectionMgr->clearSelected();
718   mySelectionMgr->clearFilters();
719
720   if (send == SelectElementsButton) {
721     myEditCurrentArgument = (QWidget*)LineEditElements;
722     SMESH::SetPointRepresentation(false);
723     if (CheckBoxMesh->isChecked()) {
724       myViewWindow->SetSelectionMode(ActorSelection);
725       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
726     } else {
727       myViewWindow->SetSelectionMode(CellSelection);
728     }
729   } else if (send == SelectPointButton) {
730     myEditCurrentArgument = (QWidget*)SpinBox_X;
731     SMESH::SetPointRepresentation(true);
732     myViewWindow->SetSelectionMode(NodeSelection);
733   } else if (send == SelectVectorButton) {
734     myEditCurrentArgument = (QWidget*)SpinBox_DX;
735     SMESH::SetPointRepresentation(true);
736
737     myViewWindow->SetSelectionMode(NodeSelection);
738   } else {
739   }
740
741   myEditCurrentArgument->setFocus();
742   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
743   SelectionIntoArgument();
744 }
745
746 //=================================================================================
747 // function : DeactivateActiveDialog()
748 // purpose  :
749 //=================================================================================
750 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
751 {
752   if (GroupConstructors->isEnabled()) {
753     GroupConstructors->setEnabled(false);
754     GroupArguments->setEnabled(false);
755     GroupButtons->setEnabled(false);
756     mySMESHGUI->ResetState();
757     mySMESHGUI->SetActiveDialogBox(0);
758   }
759 }
760
761 //=================================================================================
762 // function : ActivateThisDialog()
763 // purpose  :
764 //=================================================================================
765 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
766 {
767   /* Emit a signal to deactivate the active dialog */
768   mySMESHGUI->EmitSignalDeactivateDialog();
769   GroupConstructors->setEnabled(true);
770   GroupArguments->setEnabled(true);
771   GroupButtons->setEnabled(true);
772
773   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
774
775   myViewWindow->SetSelectionMode(CellSelection);
776   SelectionIntoArgument();
777 }
778
779 //=================================================================================
780 // function : enterEvent()
781 // purpose  :
782 //=================================================================================
783 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
784 {
785   if (!GroupConstructors->isEnabled())
786     ActivateThisDialog();
787 }
788
789 //=================================================================================
790 // function : closeEvent()
791 // purpose  :
792 //=================================================================================
793 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
794 {
795   /* same than click on cancel button */
796   this->ClickOnCancel();
797 }
798
799 //=======================================================================
800 // function : hideEvent()
801 // purpose  : caused by ESC key
802 //=======================================================================
803 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
804 {
805   if (!isMinimized())
806     ClickOnCancel();
807 }
808
809 //=======================================================================
810 //function : onSelectMesh
811 //purpose  :
812 //=======================================================================
813 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
814 {
815   if (toSelectMesh)
816     TextLabelElements->setText(tr("SMESH_NAME"));
817   else
818     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
819
820   if (myEditCurrentArgument != LineEditElements) {
821     LineEditElements->clear();
822     return;
823   }
824
825   mySelectionMgr->clearFilters();
826   SMESH::SetPointRepresentation(false);
827
828   if (toSelectMesh) {
829     myViewWindow->SetSelectionMode(ActorSelection);
830     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
831     LineEditElements->setReadOnly(true);
832   } else {
833     myViewWindow->SetSelectionMode(CellSelection);
834     LineEditElements->setReadOnly(false);
835     onTextChange(LineEditElements->text());
836   }
837
838   SelectionIntoArgument();
839 }
840
841 //=================================================================================
842 // function : GetConstructorId()
843 // purpose  :
844 //=================================================================================
845 int SMESHGUI_SymmetryDlg::GetConstructorId()
846 {
847   if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
848     return GroupConstructors->id(GroupConstructors->selected());
849   return -1;
850 }
851
852 //=================================================================================
853 // function : IsMirrorOk()
854 // purpose  :
855 //=================================================================================
856 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
857 {
858   bool isOk = true;
859
860   if (GetConstructorId() != 0)
861     isOk = (SpinBox_DX->GetValue() != 0 ||
862             SpinBox_DY->GetValue() != 0 ||
863             SpinBox_DZ->GetValue() != 0);
864
865   return isOk;
866 }
867
868 //=================================================================================
869 // function : onVectorChanged()
870 // purpose  :
871 //=================================================================================
872 void SMESHGUI_SymmetryDlg::onVectorChanged()
873 {
874   if (IsMirrorOk()) {
875     buttonOk->setEnabled(true);
876     buttonApply->setEnabled(true);
877   } else {
878     buttonOk->setEnabled(false);
879     buttonApply->setEnabled(false);
880   }
881 }