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