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