Salome HOME
Merge with version on tag OCC-V2_1_0d
[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   myActor = SMESH::FindActorByObject(myMesh);
596   if (!myActor)
597     return;
598   
599   int aNbUnits = 0;
600
601   if (myEditCurrentArgument == (QWidget*)LineEditElements)
602     {
603       myElementsId = "";
604       
605       if (CheckBoxMesh->isChecked())
606         {
607           SMESH::GetNameOfSelectedIObjects(mySelection, aString);
608           
609           if(!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) //MESH
610             {
611               // get IDs from mesh
612               SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
613               if (!aSMDSMesh)
614                 return;
615               
616               for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++  )
617                 {
618                   const SMDS_MeshElement * e = aSMDSMesh->FindElement( i );
619                   if ( e ) {
620                     myElementsId += QString(" %1").arg(i);
621                     aNbUnits++;
622                   }
623                 }
624             }
625           else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) //SUBMESH
626             {
627               // get submesh
628               SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO) ;
629               
630               // get IDs from submesh
631               SMESH::long_array_var anElementsIds = new SMESH::long_array;
632               anElementsIds = aSubMesh->GetElementsId();
633               for ( int i = 0; i < anElementsIds->length(); i++ )
634                 myElementsId += QString(" %1").arg(anElementsIds[i]);
635               aNbUnits = anElementsIds->length();
636             }
637           else // GROUP
638             {
639               // get smesh group
640               SMESH::SMESH_GroupBase_var aGroup
641                 = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
642               if (aGroup->_is_nil())
643                 return;
644               
645               // get IDs from smesh group
646               SMESH::long_array_var anElementsIds = new SMESH::long_array;
647               anElementsIds = aGroup->GetListOfID();
648               for ( int i = 0; i < anElementsIds->length(); i++ )
649                 myElementsId += QString(" %1").arg(anElementsIds[i]);
650               aNbUnits = anElementsIds->length();
651             }
652         }
653       else
654         {
655           aNbUnits = SMESH::GetNameOfSelectedElements(mySelection, aString) ;
656           myElementsId = aString;
657         }
658       
659       if(aNbUnits < 1)
660         return ;
661       
662       myNbOkElements = true;
663     }
664   else
665     {
666       aNbUnits = SMESH::GetNameOfSelectedNodes(mySelection, aString);
667       if(aNbUnits != 1)
668         return;
669       
670       SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
671       if (!aMesh)
672         return;
673       
674       const SMDS_MeshNode * n = aMesh->FindNode( aString.toInt() );
675       if ( !n )
676         return;
677       
678       double x = n->X();
679       double y = n->Y();
680       double z = n->Z();
681       
682       if (myEditCurrentArgument == (QWidget*)SpinBox_X)
683         {
684           SpinBox_X->SetValue(x);
685           SpinBox_Y->SetValue(y);
686           SpinBox_Z->SetValue(z);
687         }
688       else if (myEditCurrentArgument == (QWidget*)SpinBox_DX)
689         {
690           SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
691           SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
692           SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
693         }
694     }
695   
696   myBusy = true;
697   if (myEditCurrentArgument == (QWidget*)LineEditElements)
698     LineEditElements->setText( aString );
699   myBusy = false;
700   
701   // OK
702   if(myNbOkElements && IsMirrorOk())
703     {
704       buttonOk->setEnabled( true );
705       buttonApply->setEnabled( true );
706     }
707 }
708
709
710 //=================================================================================
711 // function : SetEditCurrentArgument()
712 // purpose  :
713 //=================================================================================
714 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
715 {
716   QPushButton* send = (QPushButton*)sender();
717   
718   disconnect( mySelection, 0, this, 0 );
719   mySelection->ClearIObjects();
720   mySelection->ClearFilters();
721   
722   if(send == SelectElementsButton) {
723     myEditCurrentArgument = (QWidget*)LineEditElements;
724     SMESH::SetPointRepresentation(false);
725     if (CheckBoxMesh->isChecked())
726       {
727         QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
728         mySelection->AddFilter(myMeshOrSubMeshOrGroupFilter);
729       }
730     else
731       QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
732   }
733   else if (send == SelectPointButton)
734     {
735       myEditCurrentArgument = (QWidget*)SpinBox_X;
736       SMESH::SetPointRepresentation(true);
737       QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
738     }
739   else if (send == SelectVectorButton)
740     {
741       myEditCurrentArgument = (QWidget*)SpinBox_DX;
742       SMESH::SetPointRepresentation(true);
743       QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
744     }
745   
746   myEditCurrentArgument->setFocus();
747   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
748   SelectionIntoArgument() ;
749 }
750
751 //=================================================================================
752 // function : DeactivateActiveDialog()
753 // purpose  :
754 //=================================================================================
755 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
756 {
757   if ( GroupConstructors->isEnabled() ) {
758     GroupConstructors->setEnabled(false) ;
759     GroupArguments->setEnabled(false) ;
760     GroupButtons->setEnabled(false) ;
761     mySMESHGUI->ResetState() ;    
762     mySMESHGUI->SetActiveDialogBox(0) ;
763   }
764 }
765
766
767 //=================================================================================
768 // function : ActivateThisDialog()
769 // purpose  :
770 //=================================================================================
771 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
772 {
773   /* Emit a signal to deactivate the active dialog */
774   mySMESHGUI->EmitSignalDeactivateDialog() ;   
775   GroupConstructors->setEnabled(true) ;
776   GroupArguments->setEnabled(true) ;
777   GroupButtons->setEnabled(true) ;
778   
779   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
780
781   QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
782   SelectionIntoArgument();
783 }
784
785
786 //=================================================================================
787 // function : enterEvent()
788 // purpose  :
789 //=================================================================================
790 void SMESHGUI_SymmetryDlg::enterEvent(QEvent* e)
791 {
792   if ( GroupConstructors->isEnabled() )
793     return ;  
794   ActivateThisDialog() ;
795 }
796
797
798 //=================================================================================
799 // function : closeEvent()
800 // purpose  :
801 //=================================================================================
802 void SMESHGUI_SymmetryDlg::closeEvent( QCloseEvent* e )
803 {
804   /* same than click on cancel button */
805   this->ClickOnCancel() ;
806 }
807
808
809 //=======================================================================
810 //function : hideEvent
811 //purpose  : caused by ESC key
812 //=======================================================================
813
814 void SMESHGUI_SymmetryDlg::hideEvent ( QHideEvent * e )
815 {
816   if ( !isMinimized() )
817     ClickOnCancel();
818 }
819
820
821 //=======================================================================
822 //function : onSelectMesh
823 //purpose  :
824 //=======================================================================
825 void SMESHGUI_SymmetryDlg::onSelectMesh ( bool toSelectMesh )
826 {
827   if (toSelectMesh)
828     TextLabelElements->setText( tr( "SMESH_NAME" ) );
829   else
830     TextLabelElements->setText( tr( "SMESH_ID_ELEMENTS" ) );
831   
832   if (myEditCurrentArgument != LineEditElements)
833     {
834       LineEditElements->clear();
835       return;
836     }
837   
838   mySelection->ClearFilters() ;
839   SMESH::SetPointRepresentation(false);
840   
841   if (toSelectMesh)
842     {
843       QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
844       mySelection->AddFilter(myMeshOrSubMeshOrGroupFilter);
845       LineEditElements->setReadOnly(true);
846     }
847   else
848     {
849       QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
850       LineEditElements->setReadOnly(false);
851       onTextChange(LineEditElements->text());
852     }
853   
854   SelectionIntoArgument();
855 }
856
857
858 //=================================================================================
859 // function : GetConstructorId()
860 // purpose  : 
861 //=================================================================================
862 int SMESHGUI_SymmetryDlg::GetConstructorId()
863
864   if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
865     return GroupConstructors->id( GroupConstructors->selected() );
866   return -1;
867 }
868
869
870 //=================================================================================
871 // function : IsAxisOk()
872 // purpose  : 
873 //=================================================================================
874 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
875 {
876   bool isOk = true;
877
878   if (GetConstructorId() != 0)
879     isOk = SpinBox_DX->GetValue() != 0 || SpinBox_DY->GetValue() != 0 || SpinBox_DZ->GetValue() != 0; 
880
881   return isOk;
882 }
883
884
885 //=================================================================================
886 // function : onVectorChanged()
887 // purpose  : 
888 //=================================================================================
889 void SMESHGUI_SymmetryDlg::onVectorChanged()
890 {
891   if (IsMirrorOk())
892     {
893       buttonOk->setEnabled( true );
894       buttonApply->setEnabled( true );
895     }
896   else
897     {
898       buttonOk->setEnabled( false );
899       buttonApply->setEnabled( false );
900     }
901 }