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