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