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