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