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