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