Salome HOME
*** empty log message ***
[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     //mySelectionMgr->clearSelected();
541     //mySelectionMgr->AddIObject(myActor->getIO());
542     SALOME_ListIO aList;
543     aList.Append(myActor->getIO());
544     mySelectionMgr->setSelectedObjects(aList, false);
545
546     TColStd_IndexedMapOfInteger selectedIndices;
547     TColStd_MapOfInteger newIndices;
548     mySelector->GetIndex(myActor->getIO(), selectedIndices);
549
550     QStringList aListId = QStringList::split(" ", theNewText, false);
551
552     if (send == LineEditElements) {
553       for (int i = 0; i < aListId.count(); i++) {
554         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
555         if (e) {
556           //if (!mySelectionMgr->IsIndexSelected(myActor->getIO(), e->GetID())) {
557           if (selectedIndices.Add(e->GetID())) {
558             //mySelectionMgr->AddOrRemoveIndex (myActor->getIO(), e->GetID(), true);
559             newIndices.Add(e->GetID());
560           }
561           myNbOkElements++;
562         }
563       }
564
565       if (newIndices.Extent() > 0){
566         mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, true );
567         myViewWindow->highlight( myActor->getIO(), true, true );
568       }
569
570       myElementsId = theNewText;
571     }
572   }
573
574   if (myNbOkElements &&  IsMirrorOk()) {
575     buttonOk->setEnabled(true);
576     buttonApply->setEnabled(true);
577   }
578
579   myBusy = false;
580 }
581
582 //=================================================================================
583 // function : SelectionIntoArgument()
584 // purpose  : Called when selection as changed or other case
585 //=================================================================================
586 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
587 {
588   if (myBusy) return;
589
590   // clear
591   myActor = 0;
592   QString aString = "";
593
594   myBusy = true;
595   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
596     LineEditElements->setText(aString);
597     myNbOkElements = 0;
598     buttonOk->setEnabled(false);
599     buttonApply->setEnabled(false);
600   }
601   myBusy = false;
602
603   if (!GroupButtons->isEnabled()) // inactive
604     return;
605
606   // get selected mesh
607   SALOME_ListIO aList;
608   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
609
610   int nbSel = aList.Extent();
611   if (nbSel != 1)
612     return;
613
614   Handle(SALOME_InteractiveObject) IO = aList.First();
615   myMesh = SMESH::GetMeshByIO(IO);
616   if(myMesh->_is_nil())
617     return;
618
619   myActor = SMESH::FindActorByObject(myMesh);
620   if (!myActor)
621     myActor = SMESH::FindActorByEntry(IO->getEntry());
622   if (!myActor)
623     return;
624
625   int aNbUnits = 0;
626
627   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
628     myElementsId = "";
629
630     if (CheckBoxMesh->isChecked()) {
631       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
632
633       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
634         // get IDs from mesh
635         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
636         if (!aSMDSMesh)
637           return;
638
639         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
640           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
641           if (e) {
642             myElementsId += QString(" %1").arg(i);
643             aNbUnits++;
644           }
645         }
646       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
647         // get submesh
648         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
649
650         // get IDs from submesh
651         SMESH::long_array_var anElementsIds = new SMESH::long_array;
652         anElementsIds = aSubMesh->GetElementsId();
653         for (int i = 0; i < anElementsIds->length(); i++) {
654           myElementsId += QString(" %1").arg(anElementsIds[i]);
655         }
656         aNbUnits = anElementsIds->length();
657       } else { // GROUP
658         // get smesh group
659         SMESH::SMESH_GroupBase_var aGroup =
660           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
661         if (aGroup->_is_nil())
662           return;
663
664         // get IDs from smesh group
665         SMESH::long_array_var anElementsIds = new SMESH::long_array;
666         anElementsIds = aGroup->GetListOfID();
667         for (int i = 0; i < anElementsIds->length(); i++) {
668           myElementsId += QString(" %1").arg(anElementsIds[i]);
669         }
670         aNbUnits = anElementsIds->length();
671       }
672     } else {
673       aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, myActor->getIO(), aString);
674       myElementsId = aString;
675     }
676
677     if (aNbUnits < 1)
678       return;
679
680     myNbOkElements = true;
681   } else {
682     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
683     if (aNbUnits != 1)
684       return;
685
686     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
687     if (!aMesh)
688       return;
689
690     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
691     if (!n)
692       return;
693
694     double x = n->X();
695     double y = n->Y();
696     double z = n->Z();
697
698     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
699       SpinBox_X->SetValue(x);
700       SpinBox_Y->SetValue(y);
701       SpinBox_Z->SetValue(z);
702     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
703       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
704       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
705       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
706     }
707   }
708
709   myBusy = true;
710   if (myEditCurrentArgument == (QWidget*)LineEditElements)
711     LineEditElements->setText(aString);
712   myBusy = false;
713
714   // OK
715   if (myNbOkElements && IsMirrorOk()) {
716     buttonOk->setEnabled(true);
717     buttonApply->setEnabled(true);
718   }
719 }
720
721 //=================================================================================
722 // function : SetEditCurrentArgument()
723 // purpose  :
724 //=================================================================================
725 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
726 {
727   QPushButton* send = (QPushButton*)sender();
728
729   disconnect(mySelectionMgr, 0, this, 0);
730   mySelectionMgr->clearSelected();
731   mySelectionMgr->clearFilters();
732
733   if (send == SelectElementsButton) {
734     myEditCurrentArgument = (QWidget*)LineEditElements;
735     SMESH::SetPointRepresentation(false);
736     if (CheckBoxMesh->isChecked()) {
737       myViewWindow->SetSelectionMode(ActorSelection);
738       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
739     } else {
740       myViewWindow->SetSelectionMode(CellSelection);
741     }
742   } else if (send == SelectPointButton) {
743     myEditCurrentArgument = (QWidget*)SpinBox_X;
744     SMESH::SetPointRepresentation(true);
745     myViewWindow->SetSelectionMode(NodeSelection);
746   } else if (send == SelectVectorButton) {
747     myEditCurrentArgument = (QWidget*)SpinBox_DX;
748     SMESH::SetPointRepresentation(true);
749
750     myViewWindow->SetSelectionMode(NodeSelection);
751   } else {
752   }
753
754   myEditCurrentArgument->setFocus();
755   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
756   SelectionIntoArgument();
757 }
758
759 //=================================================================================
760 // function : DeactivateActiveDialog()
761 // purpose  :
762 //=================================================================================
763 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
764 {
765   if (GroupConstructors->isEnabled()) {
766     GroupConstructors->setEnabled(false);
767     GroupArguments->setEnabled(false);
768     GroupButtons->setEnabled(false);
769     mySMESHGUI->ResetState();
770     mySMESHGUI->SetActiveDialogBox(0);
771   }
772 }
773
774 //=================================================================================
775 // function : ActivateThisDialog()
776 // purpose  :
777 //=================================================================================
778 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
779 {
780   /* Emit a signal to deactivate the active dialog */
781   mySMESHGUI->EmitSignalDeactivateDialog();
782   GroupConstructors->setEnabled(true);
783   GroupArguments->setEnabled(true);
784   GroupButtons->setEnabled(true);
785
786   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
787
788   myViewWindow->SetSelectionMode(CellSelection);
789   SelectionIntoArgument();
790 }
791
792 //=================================================================================
793 // function : enterEvent()
794 // purpose  :
795 //=================================================================================
796 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
797 {
798   if (!GroupConstructors->isEnabled())
799     ActivateThisDialog();
800 }
801
802 //=================================================================================
803 // function : closeEvent()
804 // purpose  :
805 //=================================================================================
806 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
807 {
808   /* same than click on cancel button */
809   this->ClickOnCancel();
810 }
811
812 //=======================================================================
813 // function : hideEvent()
814 // purpose  : caused by ESC key
815 //=======================================================================
816 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
817 {
818   if (!isMinimized())
819     ClickOnCancel();
820 }
821
822 //=======================================================================
823 //function : onSelectMesh
824 //purpose  :
825 //=======================================================================
826 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
827 {
828   if (toSelectMesh)
829     TextLabelElements->setText(tr("SMESH_NAME"));
830   else
831     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
832
833   if (myEditCurrentArgument != LineEditElements) {
834     LineEditElements->clear();
835     return;
836   }
837
838   mySelectionMgr->clearFilters();
839   SMESH::SetPointRepresentation(false);
840
841   if (toSelectMesh) {
842     myViewWindow->SetSelectionMode(ActorSelection);
843     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
844     LineEditElements->setReadOnly(true);
845   } else {
846     myViewWindow->SetSelectionMode(CellSelection);
847     LineEditElements->setReadOnly(false);
848     onTextChange(LineEditElements->text());
849   }
850
851   SelectionIntoArgument();
852 }
853
854 //=================================================================================
855 // function : GetConstructorId()
856 // purpose  :
857 //=================================================================================
858 int SMESHGUI_SymmetryDlg::GetConstructorId()
859 {
860   if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
861     return GroupConstructors->id(GroupConstructors->selected());
862   return -1;
863 }
864
865 //=================================================================================
866 // function : IsMirrorOk()
867 // purpose  :
868 //=================================================================================
869 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
870 {
871   bool isOk = true;
872
873   if (GetConstructorId() != 0)
874     isOk = (SpinBox_DX->GetValue() != 0 ||
875             SpinBox_DY->GetValue() != 0 ||
876             SpinBox_DZ->GetValue() != 0);
877
878   return isOk;
879 }
880
881 //=================================================================================
882 // function : onVectorChanged()
883 // purpose  :
884 //=================================================================================
885 void SMESHGUI_SymmetryDlg::onVectorChanged()
886 {
887   if (IsMirrorOk()) {
888     buttonOk->setEnabled(true);
889     buttonApply->setEnabled(true);
890   } else {
891     buttonOk->setEnabled(false);
892     buttonApply->setEnabled(false);
893   }
894 }