Salome HOME
Integration of PAL/SALOME V2.1.0c from OCC
[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_IdValidator.h"
35 #include "SMESHGUI_SpinBox.h"
36 #include "SMESH_Actor.h"
37 #include "SMDS_Mesh.hxx"
38
39 #include "QAD_Application.h"
40 #include "QAD_Desktop.h"
41 #include "QAD_MessageBox.h"
42 #include "utilities.h"
43
44 // QT Includes
45 #include <qapplication.h>
46 #include <qbuttongroup.h>
47 #include <qgroupbox.h>
48 #include <qlabel.h>
49 #include <qlineedit.h>
50 #include <qpushbutton.h>
51 #include <qradiobutton.h>
52 #include <qcheckbox.h>
53 #include <qlayout.h>
54 #include <qspinbox.h> 
55 #include <qpixmap.h>
56
57 using namespace std;
58
59 //=================================================================================
60 // class    : SMESHGUI_TranslationDlg()
61 // purpose  : 
62 //=================================================================================
63 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
64                                               bool modal, WFlags fl )
65   : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu |
66              Qt::WDestructiveClose)
67 {
68   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SMESH_TRANSLATION_POINTS")));
69   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SMESH_TRANSLATION_VECTOR")));
70   QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
71
72   if ( !name )
73     setName( "SMESHGUI_TranslationDlg" );
74   resize( 303, 185 ); 
75   setCaption( tr( "SMESH_TRANSLATION" ) );
76   setSizeGripEnabled( TRUE );
77   SMESHGUI_TranslationDlgLayout = new QGridLayout( this ); 
78   SMESHGUI_TranslationDlgLayout->setSpacing( 6 );
79   SMESHGUI_TranslationDlgLayout->setMargin( 11 );
80
81   /***************************************************************/
82   GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
83   GroupConstructors->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupConstructors->sizePolicy().hasHeightForWidth() ) );
84   GroupConstructors->setTitle( tr( "SMESH_TRANSLATION"  ) );
85   GroupConstructors->setExclusive( TRUE );
86   GroupConstructors->setColumnLayout(0, Qt::Vertical );
87   GroupConstructors->layout()->setSpacing( 0 );
88   GroupConstructors->layout()->setMargin( 0 );
89   GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
90   GroupConstructorsLayout->setAlignment( Qt::AlignTop );
91   GroupConstructorsLayout->setSpacing( 6 );
92   GroupConstructorsLayout->setMargin( 11 );
93   RadioButton1= new QRadioButton( GroupConstructors, "RadioButton1" );
94   RadioButton1->setText( tr( ""  ) );
95   RadioButton1->setPixmap( image0 );
96   GroupConstructorsLayout->addWidget( RadioButton1, 0, 0 );
97   RadioButton2= new QRadioButton( GroupConstructors, "RadioButton2" );
98   RadioButton2->setText( tr( ""  ) );
99   RadioButton2->setPixmap( image1 );
100   GroupConstructorsLayout->addWidget( RadioButton2, 0, 2  );
101   SMESHGUI_TranslationDlgLayout->addWidget( GroupConstructors, 0, 0 );
102   
103   /***************************************************************/
104   GroupButtons = new QGroupBox( this, "GroupButtons" );
105   GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth() ) );
106   GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
107   GroupButtons->setTitle( tr( ""  ) );
108   GroupButtons->setColumnLayout(0, Qt::Vertical );
109   GroupButtons->layout()->setSpacing( 0 );
110   GroupButtons->layout()->setMargin( 0 );
111   GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
112   GroupButtonsLayout->setAlignment( Qt::AlignTop );
113   GroupButtonsLayout->setSpacing( 6 );
114   GroupButtonsLayout->setMargin( 11 );
115   buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
116   buttonCancel->setText( tr( "SMESH_BUT_CLOSE"  ) );
117   buttonCancel->setAutoDefault( TRUE );
118   GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
119   buttonApply = new QPushButton( GroupButtons, "buttonApply" );
120   buttonApply->setText( tr( "SMESH_BUT_APPLY"  ) );
121   buttonApply->setAutoDefault( TRUE );
122   GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
123   QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
124   GroupButtonsLayout->addItem( spacer_9, 0, 2 );
125   buttonOk = new QPushButton( GroupButtons, "buttonOk" );
126   buttonOk->setText( tr( "SMESH_BUT_OK"  ) );
127   buttonOk->setAutoDefault( TRUE );
128   buttonOk->setDefault( TRUE );
129   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
130   SMESHGUI_TranslationDlgLayout->addWidget( GroupButtons, 2, 0 );
131
132   /***************************************************************/
133   GroupArguments = new QGroupBox( this, "GroupArguments" );
134   GroupArguments->setTitle( tr( "SMESH_ARGUMENTS" ) );
135   GroupArguments->setColumnLayout(0, Qt::Vertical );
136   GroupArguments->layout()->setSpacing( 0 );
137   GroupArguments->layout()->setMargin( 0 );
138   GroupArgumentsLayout = new QGridLayout( GroupArguments->layout() );
139   GroupArgumentsLayout->setAlignment( Qt::AlignTop );
140   GroupArgumentsLayout->setSpacing( 6 );
141   GroupArgumentsLayout->setMargin( 11 );
142
143   // Controls for elements selection
144   TextLabelElements  = new QLabel( GroupArguments, "TextLabelElements" );
145   TextLabelElements->setText( tr( "SMESH_ID_ELEMENTS"  ) );
146   TextLabelElements->setFixedWidth(74);
147   GroupArgumentsLayout->addWidget( TextLabelElements, 0, 0 );
148
149   SelectElementsButton  = new QPushButton( GroupArguments, "SelectElementsButton" );
150   SelectElementsButton->setText( tr( ""  ) );
151   SelectElementsButton->setPixmap( image2 );
152   SelectElementsButton->setToggleButton( FALSE );
153   GroupArgumentsLayout->addWidget( SelectElementsButton, 0, 1 );
154
155   LineEditElements  = new QLineEdit( GroupArguments, "LineEditElements" );
156   LineEditElements->setValidator( new SMESHGUI_IdValidator( this, "validator" ));
157   GroupArgumentsLayout->addMultiCellWidget( LineEditElements, 0, 0, 2, 7 );
158
159   // Control for the whole mesh selection
160   CheckBoxMesh = new QCheckBox( GroupArguments, "CheckBoxMesh" );
161   CheckBoxMesh->setText( tr( "SMESH_SELECT_WHOLE_MESH"  ) );
162   GroupArgumentsLayout->addMultiCellWidget( CheckBoxMesh, 1, 1, 0, 7 );
163   
164   // Controls for vector and points selection
165   TextLabel1 = new QLabel( GroupArguments, "TextLabel1" );
166   GroupArgumentsLayout->addWidget( TextLabel1, 2, 0 );
167
168   SelectButton1  = new QPushButton( GroupArguments, "SelectButton1" );
169   SelectButton1->setText( tr( ""  ) );
170   SelectButton1->setPixmap( image2 );
171   SelectButton1->setToggleButton( FALSE );
172   GroupArgumentsLayout->addWidget( SelectButton1, 2, 1 );
173
174   TextLabel1_1 = new QLabel( GroupArguments, "TextLabel1_1" );
175   GroupArgumentsLayout->addWidget( TextLabel1_1, 2, 2 );
176
177   SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox1_1");
178   GroupArgumentsLayout->addWidget( SpinBox1_1, 2, 3 );
179
180   TextLabel1_2 = new QLabel( GroupArguments, "TextLabel1_2" );
181   GroupArgumentsLayout->addWidget( TextLabel1_2, 2, 4 );
182
183   SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox1_2");
184   GroupArgumentsLayout->addWidget( SpinBox1_2, 2, 5 );
185
186   TextLabel1_3 = new QLabel( GroupArguments, "TextLabel1_3" );
187   GroupArgumentsLayout->addWidget( TextLabel1_3, 2, 6 );
188   
189   SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox1_3");
190   GroupArgumentsLayout->addWidget( SpinBox1_3, 2, 7 );
191   
192   TextLabel2 = new QLabel( GroupArguments, "TextLabel2" );
193   TextLabel2->setText( tr( "SMESH_POINT_2"  ) );
194   GroupArgumentsLayout->addWidget( TextLabel2, 3, 0 );
195
196   SelectButton2  = new QPushButton( GroupArguments, "SelectButton2" );
197   SelectButton2->setText( tr( ""  ) );
198   SelectButton2->setPixmap( image2 );
199   SelectButton2->setToggleButton( FALSE );
200   GroupArgumentsLayout->addWidget( SelectButton2, 3, 1 );
201
202   TextLabel2_1 = new QLabel( GroupArguments, "TextLabel2_1" );
203   TextLabel2_1->setText( tr( "SMESH_X"  ) );
204   GroupArgumentsLayout->addWidget( TextLabel2_1, 3, 2 );
205   
206   SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox2_1");
207   GroupArgumentsLayout->addWidget( SpinBox2_1, 3, 3 );
208   
209   TextLabel2_2 = new QLabel( GroupArguments, "TextLabel2_2" );
210   TextLabel2_2->setText( tr( "SMESH_Y"  ) );
211   GroupArgumentsLayout->addWidget( TextLabel2_2, 3, 4 );
212
213   SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox2_2");
214   GroupArgumentsLayout->addWidget( SpinBox2_2, 3, 5 );
215
216   TextLabel2_3 = new QLabel( GroupArguments, "TextLabel2_3" );
217   TextLabel2_3->setText( tr( "SMESH_Z" ) );
218   GroupArgumentsLayout->addWidget( TextLabel2_3, 3, 6 );
219   
220   SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox2_3");
221   GroupArgumentsLayout->addWidget( SpinBox2_3, 3, 7 );
222   
223   // Controls for "Create a copy" option
224   CheckBoxCopy = new QCheckBox( GroupArguments, "CheckBoxCopy" );
225   CheckBoxCopy->setText( tr( "SMESH_CREATE_COPY" ) );
226   GroupArgumentsLayout->addMultiCellWidget( CheckBoxCopy, 4, 4, 0, 2 );
227   
228
229   SMESHGUI_TranslationDlgLayout->addWidget( GroupArguments, 1, 0 );
230   
231   /* Initialisations */
232   SpinBox1_1->RangeStepAndValidator( -999999.999, +999999.999, 10.0, 3 );
233   SpinBox1_2->RangeStepAndValidator( -999999.999, +999999.999, 10.0, 3 );
234   SpinBox1_3->RangeStepAndValidator( -999999.999, +999999.999, 10.0, 3 );
235   SpinBox2_1->RangeStepAndValidator( -999999.999, +999999.999, 10.0, 3 );
236   SpinBox2_2->RangeStepAndValidator( -999999.999, +999999.999, 10.0, 3 );
237   SpinBox2_3->RangeStepAndValidator( -999999.999, +999999.999, 10.0, 3 );
238
239   GroupArguments->show();
240   RadioButton1->setChecked( TRUE );
241   mySelection = Sel;  
242   
243   mySMESHGUI  = SMESHGUI::GetSMESHGUI() ;
244   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
245
246   myMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
247
248   Init();
249
250   /* signals and slots connections */
251   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
252   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
253   connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
254   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
255   
256   connect( SelectElementsButton, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
257   connect( SelectButton1, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
258   connect( SelectButton2, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
259
260   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
261   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
262   /* to close dialog if study change */
263   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
264   connect( LineEditElements, SIGNAL( textChanged( const QString& )),
265            SLOT( onTextChange( const QString& )));
266   connect( CheckBoxMesh, SIGNAL( toggled( bool )),
267            SLOT( onSelectMesh( bool )));
268   
269   /* Move widget on the botton right corner of main widget */
270   int x, y ;
271   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
272   this->move( x, y ) ;
273   this->show() ; /* displays Dialog */
274
275   ConstructorsClicked(0);
276 }
277
278 //=================================================================================
279 // function : ~SMESHGUI_TranslationDlg()
280 // purpose  : Destroys the object and frees any allocated resources
281 //=================================================================================
282 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
283 {
284   // no need to delete child widgets, Qt does it all for us
285 }
286
287
288 //=================================================================================
289 // function : Init()
290 // purpose  :
291 //=================================================================================
292 void SMESHGUI_TranslationDlg::Init( bool ResetControls )
293 {
294   myBusy = false;
295   
296   myEditCurrentArgument = 0;
297   LineEditElements->clear();
298   myElementsId = "";
299   myNbOkElements = 0;
300
301   buttonOk->setEnabled( false );
302   buttonApply->setEnabled( false );
303   
304   myActor     = 0;
305   myMesh = SMESH::SMESH_Mesh::_nil();
306
307   if( ResetControls )
308     {
309       SpinBox1_1->SetValue(0.0);
310       SpinBox1_2->SetValue(0.0);
311       SpinBox1_3->SetValue(0.0);
312       SpinBox2_1->SetValue(0.0);
313       SpinBox2_2->SetValue(0.0);
314       SpinBox2_3->SetValue(0.0);
315       
316       CheckBoxCopy->setChecked(false);
317       CheckBoxMesh->setChecked(false);
318       onSelectMesh( false );
319     }
320 }
321
322
323 //=================================================================================
324 // function : ConstructorsClicked()
325 // purpose  : Radio button management
326 //=================================================================================
327 void SMESHGUI_TranslationDlg::ConstructorsClicked(int constructorId)
328 {
329   disconnect(mySelection, 0, this, 0);
330   
331   switch(constructorId)
332     {
333     case 0 :
334       { 
335         TextLabel1->setText( tr( "SMESH_POINT_1" ) );
336         TextLabel1_1->setText( tr( "SMESH_X" ) );
337         TextLabel1_2->setText( tr( "SMESH_Y" ) );
338         TextLabel1_3->setText( tr( "SMESH_Z" ) );
339
340         SelectButton1->show();
341         TextLabel2->show();
342         SelectButton2->show();
343         TextLabel2_1->show();
344         SpinBox2_1->show();
345         TextLabel2_2->show();
346         SpinBox2_2->show();
347         TextLabel2_3->show();
348         SpinBox2_3->show();
349         break;
350       }
351     case 1 :
352       {
353         TextLabel1->setText( tr( "SMESH_VECTOR" ) );
354         TextLabel1_1->setText( tr( "SMESH_DX" ) );
355         TextLabel1_2->setText( tr( "SMESH_DY" ) );
356         TextLabel1_3->setText( tr( "SMESH_DZ" ) );
357
358         SelectButton1->hide();
359         TextLabel2->hide();
360         SelectButton2->hide();
361         TextLabel2_1->hide();
362         SpinBox2_1->hide();
363         TextLabel2_2->hide();
364         SpinBox2_2->hide();
365         TextLabel2_3->hide();
366         SpinBox2_3->hide();
367         break;
368       }
369     }
370   
371   if (myEditCurrentArgument != (QWidget*)LineEditElements)
372     {
373       SMESH::SetPointRepresentation(false);
374       if (!CheckBoxMesh->isChecked())
375         QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
376     }
377   
378   myEditCurrentArgument = (QWidget*)LineEditElements;
379   LineEditElements->setFocus();
380   
381   if (CheckBoxMesh->isChecked())
382     onSelectMesh(true);
383   
384   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
385 }
386
387
388 //=================================================================================
389 // function : ClickOnApply()
390 // purpose  :
391 //=================================================================================
392 void SMESHGUI_TranslationDlg::ClickOnApply()
393 {
394   if (mySMESHGUI->ActiveStudyLocked())
395     return;
396   
397   if ( myNbOkElements)
398     {
399       QStringList aListElementsId = QStringList::split( " ", myElementsId, false);
400       
401       SMESH::long_array_var anElementsId = new SMESH::long_array;
402       
403       anElementsId->length( aListElementsId.count() );
404       for ( int i = 0; i < aListElementsId.count(); i++ )
405         anElementsId[i] = aListElementsId[i].toInt();
406
407       SMESH::DirStruct aVector;
408       if(GetConstructorId() == 0)
409         {
410           aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
411           aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
412           aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
413         }
414       else if(GetConstructorId() == 1)
415         {
416           aVector.PS.x = SpinBox1_1->GetValue();
417           aVector.PS.y = SpinBox1_2->GetValue();
418           aVector.PS.z = SpinBox1_3->GetValue();
419         }
420       
421       bool toCreateCopy = CheckBoxCopy->isChecked();
422       
423       try
424         {
425           SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
426           QApplication::setOverrideCursor(Qt::waitCursor);
427           aMeshEditor->Translate(anElementsId.inout(), aVector, toCreateCopy);
428           QApplication::restoreOverrideCursor();
429         }
430       catch( ... )
431         {
432         }
433       
434       mySelection->ClearIObjects();
435       SMESH::UpdateView();
436       Init( false );
437       ConstructorsClicked( GetConstructorId() );
438     }
439 }
440
441 //=================================================================================
442 // function : ClickOnOk()
443 // purpose  :
444 //=================================================================================
445 void SMESHGUI_TranslationDlg::ClickOnOk()
446 {
447   ClickOnApply() ;
448   ClickOnCancel() ;
449 }
450
451         
452 //=================================================================================
453 // function : ClickOnCancel()
454 // purpose  :
455 //=================================================================================
456 void SMESHGUI_TranslationDlg::ClickOnCancel()
457 {
458   mySelection->ClearFilters();
459   mySelection->ClearIObjects();
460   SMESH::SetPointRepresentation(false);
461   QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
462   disconnect( mySelection, 0, this, 0 );
463   mySMESHGUI->ResetState() ;
464   reject() ;
465 }
466
467 //=======================================================================
468 //function : onTextChange
469 //purpose  : 
470 //=======================================================================
471
472 void SMESHGUI_TranslationDlg::onTextChange(const QString& theNewText)
473 {
474   QLineEdit* send = (QLineEdit*)sender();
475
476   if ( myBusy ) return;
477   myBusy = true;
478   
479   if (send == LineEditElements)
480     myNbOkElements = 0;
481   
482   buttonOk->setEnabled( false );
483   buttonApply->setEnabled( false );
484   
485   // hilight entered elements
486   SMDS_Mesh* aMesh = 0;
487   if ( myActor )
488     aMesh = myActor->GetObject()->GetMesh();
489   
490   if ( aMesh ) {
491     
492     mySelection->ClearIObjects();
493     mySelection->AddIObject( myActor->getIO() );
494     
495     QStringList aListId = QStringList::split( " ", theNewText, false);
496     
497     if (send == LineEditElements) {
498       for ( int i = 0; i < aListId.count(); i++ ) {
499         const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
500         if ( e ) {
501           if ( !mySelection->IsIndexSelected( myActor->getIO(), e->GetID() ))
502             mySelection->AddOrRemoveIndex (myActor->getIO(), e->GetID(), true);
503           myNbOkElements++;
504         }
505       }
506       myElementsId = theNewText;
507     }
508   }
509   
510   if ( myNbOkElements ) {
511     buttonOk->setEnabled( true );
512     buttonApply->setEnabled( true );
513   }
514   
515   myBusy = false;
516 }
517
518 //=================================================================================
519 // function : SelectionIntoArgument()
520 // purpose  : Called when selection as changed or other case
521 //=================================================================================
522 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
523 {
524   if ( myBusy ) return;
525   
526   // clear
527   myActor = 0;
528   QString aString = "";
529
530   myBusy = true;
531   if (myEditCurrentArgument == (QWidget*)LineEditElements)
532     {
533       LineEditElements->setText( aString );
534       myNbOkElements = 0;
535       buttonOk->setEnabled( false );
536       buttonApply->setEnabled( false );
537     }
538   myBusy = false;
539   
540   if ( !GroupButtons->isEnabled() ) // inactive
541     return;
542    
543   // get selected mesh
544   
545   int nbSel = mySelection->IObjectCount();
546   if(nbSel != 1)
547     return;
548   
549   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
550   myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO) ;
551   myActor = SMESH::FindActorByEntry( mySelection->firstIObject()->getEntry() );
552   
553   int aNbUnits = 0;
554   
555   if (myEditCurrentArgument == (QWidget*)LineEditElements)
556     {
557       myElementsId = "";
558       
559       if (CheckBoxMesh->isChecked())
560         {
561           SMESH::GetNameOfSelectedIObjects(mySelection, aString);
562           if(!myMesh->_is_nil())
563             {
564               if (!myActor)
565                 return;
566               
567               // get IDs from mesh
568               SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
569               if (!aSMDSMesh)
570                 return;
571               
572               for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++  )
573                 {
574                   const SMDS_MeshElement * e = aSMDSMesh->FindElement( i );
575                   if ( e ) {
576                     myElementsId += QString(" %1").arg(i);
577                     aNbUnits++;
578                   }
579                 }
580             }
581           else
582             {
583               // get submesh
584               SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO) ;
585               if(aSubMesh->_is_nil())
586                 return;
587               
588               myMesh = aSubMesh->GetFather();
589               if(myMesh->_is_nil())
590                 return;
591               
592               myActor = SMESH::FindActorByObject(myMesh);
593               if (!myActor)
594                 return;
595
596               // get IDs from submesh
597               SMESH::long_array_var anElementsIds = new SMESH::long_array;
598               anElementsIds = aSubMesh->GetElementsId();
599               for ( int i = 0; i < anElementsIds->length(); i++ )
600                 myElementsId += QString(" %1").arg(anElementsIds[i]);
601               aNbUnits = anElementsIds->length();
602             }
603         }
604       else
605         {
606           if(myMesh->_is_nil())
607             {
608               // get submesh
609               SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO) ;
610               if(!aSubMesh->_is_nil())
611                 myMesh = aSubMesh->GetFather();  // get mesh from submesh
612               else
613                 {
614                   // get group
615                   SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(IO);
616                   if ( !aGroup->_is_nil() )
617                     myMesh = aGroup->GetMesh(); // get mesh from group
618                 }
619               
620               if(myMesh->_is_nil())
621                 return;
622               
623               // get mesh actor
624               myActor = SMESH::FindActorByObject(myMesh);
625             }
626           
627           if (!myActor)
628             return;
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   
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(myMeshOrSubMeshFilter) ;
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(myMeshOrSubMeshFilter);
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 }