Salome HOME
1df8f02eba9b88eabb6d127dd1b4b5215b99ac63
[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   /* Move widget on the botton right corner of main widget */
297   int x, y;
298   mySMESHGUI->DefineDlgPosition(this, x, y);
299   this->move(x, y);
300   this->show(); /* displays Dialog */
301
302   ConstructorsClicked(0);
303   resize(0,0); // ??
304 }
305
306 //=================================================================================
307 // function : ~SMESHGUI_TranslationDlg()
308 // purpose  : Destroys the object and frees any allocated resources
309 //=================================================================================
310 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
311 {
312   // no need to delete child widgets, Qt does it all for us
313 }
314
315 //=================================================================================
316 // function : Init()
317 // purpose  :
318 //=================================================================================
319 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
320 {
321   myBusy = false;
322
323   myEditCurrentArgument = 0;
324   LineEditElements->clear();
325   myElementsId = "";
326   myNbOkElements = 0;
327
328   buttonOk->setEnabled(false);
329   buttonApply->setEnabled(false);
330
331   myActor = 0;
332   myMesh = SMESH::SMESH_Mesh::_nil();
333
334   if (ResetControls) {
335     SpinBox1_1->SetValue(0.0);
336     SpinBox1_2->SetValue(0.0);
337     SpinBox1_3->SetValue(0.0);
338     SpinBox2_1->SetValue(0.0);
339     SpinBox2_2->SetValue(0.0);
340     SpinBox2_3->SetValue(0.0);
341
342     CheckBoxCopy->setChecked(false);
343     CheckBoxMesh->setChecked(false);
344     onSelectMesh(false);
345   }
346 }
347
348 //=================================================================================
349 // function : ConstructorsClicked()
350 // purpose  : Radio button management
351 //=================================================================================
352 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
353 {
354   disconnect(mySelectionMgr, 0, this, 0);
355
356   switch (constructorId) {
357   case 0:
358     {
359       TextLabel1->setText(tr("SMESH_POINT_1"));
360       TextLabel1_1->setText(tr("SMESH_X"));
361       TextLabel1_2->setText(tr("SMESH_Y"));
362       TextLabel1_3->setText(tr("SMESH_Z"));
363
364       SelectButton1->show();
365       TextLabel2->show();
366       SelectButton2->show();
367       TextLabel2_1->show();
368       SpinBox2_1->show();
369       TextLabel2_2->show();
370       SpinBox2_2->show();
371       TextLabel2_3->show();
372       SpinBox2_3->show();
373       break;
374     }
375   case 1:
376     {
377       TextLabel1->setText(tr("SMESH_VECTOR"));
378       TextLabel1_1->setText(tr("SMESH_DX"));
379       TextLabel1_2->setText(tr("SMESH_DY"));
380       TextLabel1_3->setText(tr("SMESH_DZ"));
381
382       SelectButton1->hide();
383       TextLabel2->hide();
384       SelectButton2->hide();
385       TextLabel2_1->hide();
386       SpinBox2_1->hide();
387       TextLabel2_2->hide();
388       SpinBox2_2->hide();
389       TextLabel2_3->hide();
390       SpinBox2_3->hide();
391       break;
392     }
393   }
394
395   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
396     SMESH::SetPointRepresentation(false);
397     if (!CheckBoxMesh->isChecked())
398       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
399         aViewWindow->SetSelectionMode( CellSelection );
400   }
401
402   myEditCurrentArgument = (QWidget*)LineEditElements;
403   LineEditElements->setFocus();
404
405   if (CheckBoxMesh->isChecked())
406     onSelectMesh(true);
407
408   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
409 }
410
411 //=================================================================================
412 // function : ClickOnApply()
413 // purpose  :
414 //=================================================================================
415 void SMESHGUI_TranslationDlg::ClickOnApply()
416 {
417   if (mySMESHGUI->isActiveStudyLocked())
418     return;
419
420   if (myNbOkElements) {
421     QStringList aListElementsId = QStringList::split(" ", myElementsId, false);
422
423     SMESH::long_array_var anElementsId = new SMESH::long_array;
424
425     anElementsId->length(aListElementsId.count());
426     for (int i = 0; i < aListElementsId.count(); i++)
427       anElementsId[i] = aListElementsId[i].toInt();
428
429     SMESH::DirStruct aVector;
430     if (GetConstructorId() == 0) {
431       aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
432       aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
433       aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
434     } else if (GetConstructorId() == 1) {
435       aVector.PS.x = SpinBox1_1->GetValue();
436       aVector.PS.y = SpinBox1_2->GetValue();
437       aVector.PS.z = SpinBox1_3->GetValue();
438     }
439
440     bool toCreateCopy = CheckBoxCopy->isChecked();
441
442     try {
443       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
444       QApplication::setOverrideCursor(Qt::waitCursor);
445       aMeshEditor->Translate(anElementsId.inout(), aVector, toCreateCopy);
446       QApplication::restoreOverrideCursor();
447     } catch (...) {
448     }
449
450     SMESH::UpdateView();
451     Init(false);
452     ConstructorsClicked(GetConstructorId());
453     SelectionIntoArgument();
454   }
455 }
456
457 //=================================================================================
458 // function : ClickOnOk()
459 // purpose  :
460 //=================================================================================
461 void SMESHGUI_TranslationDlg::ClickOnOk()
462 {
463   ClickOnApply();
464   ClickOnCancel();
465 }
466
467 //=================================================================================
468 // function : ClickOnCancel()
469 // purpose  :
470 //=================================================================================
471 void SMESHGUI_TranslationDlg::ClickOnCancel()
472 {
473   disconnect(mySelectionMgr, 0, this, 0);
474   mySelectionMgr->clearFilters();
475   mySelectionMgr->clearSelected();
476   SMESH::SetPointRepresentation(false);
477   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
478     aViewWindow->SetSelectionMode( ActorSelection );
479   mySMESHGUI->ResetState();
480   reject();
481 }
482
483 //=======================================================================
484 // function : onTextChange()
485 // purpose  :
486 //=======================================================================
487 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
488 {
489   QLineEdit* send = (QLineEdit*)sender();
490
491   if (myBusy) return;
492   myBusy = true;
493
494   if (send == LineEditElements)
495     myNbOkElements = 0;
496
497   buttonOk->setEnabled(false);
498   buttonApply->setEnabled(false);
499
500   // hilight entered elements
501   SMDS_Mesh* aMesh = 0;
502   if (myActor)
503     aMesh = myActor->GetObject()->GetMesh();
504
505   if (aMesh) {
506     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
507     
508     TColStd_MapOfInteger newIndices;
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           newIndices.Add(e->GetID());
517         myNbOkElements++;
518       }
519     }
520
521     mySelector->AddOrRemoveIndex( anIO, newIndices, false );
522     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
523       aViewWindow->highlight( anIO, true, true );
524     
525     myElementsId = theNewText;
526   }
527
528   if (myNbOkElements) {
529     buttonOk->setEnabled(true);
530     buttonApply->setEnabled(true);
531   }
532
533   myBusy = false;
534 }
535
536 //=================================================================================
537 // function : SelectionIntoArgument()
538 // purpose  : Called when selection as changed or other case
539 //=================================================================================
540 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
541 {
542   if (myBusy) return;
543
544   // clear
545   myActor = 0;
546   QString aString = "";
547
548   myBusy = true;
549   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
550     LineEditElements->setText(aString);
551     myNbOkElements = 0;
552     buttonOk->setEnabled(false);
553     buttonApply->setEnabled(false);
554   }
555   myBusy = false;
556
557   if (!GroupButtons->isEnabled()) // inactive
558     return;
559
560   // get selected mesh
561   SALOME_ListIO aList;
562   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
563
564   int nbSel = aList.Extent();
565   if (nbSel != 1)
566     return;
567
568   Handle(SALOME_InteractiveObject) IO = aList.First();
569   myMesh = SMESH::GetMeshByIO(IO);
570   if (myMesh->_is_nil())
571     return;
572
573   myActor = SMESH::FindActorByObject(myMesh);
574   if (!myActor)
575     myActor = SMESH::FindActorByEntry(IO->getEntry());
576   if (!myActor)
577     return;
578
579   int aNbUnits = 0;
580
581   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
582     myElementsId = "";
583
584     if (CheckBoxMesh->isChecked()) {
585       SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
586
587       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
588         // get IDs from mesh
589         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
590         if (!aSMDSMesh)
591           return;
592
593         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
594           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
595           if (e) {
596             myElementsId += QString(" %1").arg(i);
597             aNbUnits++;
598           }
599         }
600       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
601         // get submesh
602         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
603
604         // get IDs from submesh
605         SMESH::long_array_var anElementsIds = new SMESH::long_array;
606         anElementsIds = aSubMesh->GetElementsId();
607         for (int i = 0; i < anElementsIds->length(); i++) {
608           myElementsId += QString(" %1").arg(anElementsIds[i]);
609         }
610         aNbUnits = anElementsIds->length();
611       } else { // GROUP
612         // get smesh group
613         SMESH::SMESH_GroupBase_var aGroup =
614           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
615         if (aGroup->_is_nil())
616           return;
617
618         // get IDs from smesh group
619         SMESH::long_array_var anElementsIds = new SMESH::long_array;
620         anElementsIds = aGroup->GetListOfID();
621         for (int i = 0; i < anElementsIds->length(); i++) {
622           myElementsId += QString(" %1").arg(anElementsIds[i]);
623         }
624         aNbUnits = anElementsIds->length();
625       }
626     } else {
627       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
628       myElementsId = aString;
629     }
630
631     if (aNbUnits < 1)
632       return;
633
634     myNbOkElements = true;
635   } else {
636     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
637     if (aNbUnits != 1)
638       return;
639
640     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
641     if (!aMesh)
642       return;
643
644     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
645     if (!n)
646       return;
647
648     double x = n->X();
649     double y = n->Y();
650     double z = n->Z();
651
652     if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
653       SpinBox1_1->SetValue(x);
654       SpinBox1_2->SetValue(y);
655       SpinBox2_3->SetValue(z);
656     } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
657       SpinBox2_1->SetValue(x);
658       SpinBox2_2->SetValue(y);
659       SpinBox2_3->SetValue(z);
660     }
661   }
662
663   myBusy = true;
664   if (myEditCurrentArgument == (QWidget*)LineEditElements)
665     LineEditElements->setText(aString);
666   myBusy = false;
667
668   // OK
669   if (myNbOkElements) {
670     buttonOk->setEnabled(true);
671     buttonApply->setEnabled(true);
672   }
673 }
674
675 //=================================================================================
676 // function : SetEditCurrentArgument()
677 // purpose  :
678 //=================================================================================
679 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
680 {
681   QPushButton* send = (QPushButton*)sender();
682
683   disconnect(mySelectionMgr, 0, this, 0);
684   mySelectionMgr->clearSelected();
685   mySelectionMgr->clearFilters();
686
687   if (send == SelectElementsButton) {
688     myEditCurrentArgument = (QWidget*)LineEditElements;
689     SMESH::SetPointRepresentation(false);
690     if (CheckBoxMesh->isChecked()) {
691       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
692         aViewWindow->SetSelectionMode( ActorSelection );
693       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
694     } else {
695
696       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
697         aViewWindow->SetSelectionMode( CellSelection );
698     }
699   } else if (send == SelectButton1) {
700     myEditCurrentArgument = (QWidget*)SpinBox1_1;
701     SMESH::SetPointRepresentation(true);
702
703     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
704       aViewWindow->SetSelectionMode( NodeSelection );
705   } else if (send == SelectButton2) {
706     myEditCurrentArgument = (QWidget*)SpinBox2_1;
707     SMESH::SetPointRepresentation(true);
708
709     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
710       aViewWindow->SetSelectionMode( NodeSelection );
711   }
712
713   myEditCurrentArgument->setFocus();
714   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
715   SelectionIntoArgument();
716 }
717
718 //=================================================================================
719 // function : DeactivateActiveDialog()
720 // purpose  :
721 //=================================================================================
722 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
723 {
724   if (GroupConstructors->isEnabled()) {
725     GroupConstructors->setEnabled(false);
726     GroupArguments->setEnabled(false);
727     GroupButtons->setEnabled(false);
728     mySMESHGUI->ResetState();
729     mySMESHGUI->SetActiveDialogBox(0);
730   }
731 }
732
733 //=================================================================================
734 // function : ActivateThisDialog()
735 // purpose  :
736 //=================================================================================
737 void SMESHGUI_TranslationDlg::ActivateThisDialog()
738 {
739   /* Emit a signal to deactivate the active dialog */
740   mySMESHGUI->EmitSignalDeactivateDialog();
741   GroupConstructors->setEnabled(true);
742   GroupArguments->setEnabled(true);
743   GroupButtons->setEnabled(true);
744
745   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
746
747   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
748     aViewWindow->SetSelectionMode( CellSelection );
749
750   SelectionIntoArgument();
751 }
752
753 //=================================================================================
754 // function : enterEvent()
755 // purpose  :
756 //=================================================================================
757 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
758 {
759   if (!GroupConstructors->isEnabled())
760     ActivateThisDialog();
761 }
762
763 //=================================================================================
764 // function : closeEvent()
765 // purpose  :
766 //=================================================================================
767 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
768 {
769   /* same than click on cancel button */
770   this->ClickOnCancel();
771 }
772
773 //=======================================================================
774 //function : hideEvent
775 //purpose  : caused by ESC key
776 //=======================================================================
777 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
778 {
779   if (!isMinimized())
780     ClickOnCancel();
781 }
782
783 //=======================================================================
784 //function : onSelectMesh
785 //purpose  :
786 //=======================================================================
787 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
788 {
789   if (toSelectMesh)
790     TextLabelElements->setText(tr("SMESH_NAME"));
791   else
792     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
793
794   if (myEditCurrentArgument != LineEditElements) {
795     LineEditElements->clear();
796     return;
797   }
798
799   mySelectionMgr->clearFilters();
800   SMESH::SetPointRepresentation(false);
801
802   if (toSelectMesh) {
803     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
804       aViewWindow->SetSelectionMode( ActorSelection );
805     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
806     LineEditElements->setReadOnly(true);
807   } else {
808     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
809       aViewWindow->SetSelectionMode( CellSelection );
810     LineEditElements->setReadOnly(false);
811     onTextChange(LineEditElements->text());
812   }
813
814   SelectionIntoArgument();
815 }
816
817 //=================================================================================
818 // function : GetConstructorId()
819 // purpose  :
820 //=================================================================================
821 int SMESHGUI_TranslationDlg::GetConstructorId()
822 {
823   if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
824     return GroupConstructors->id(GroupConstructors->selected());
825   return -1;
826 }