Salome HOME
The selections of elements corrected.
[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      myViewWindow( SMESH::GetViewWindow( theModule ) ),
88      mySelector( myViewWindow->GetSelector() )
89 {
90   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
91   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
92   QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
93
94   if (!name)
95     setName("SMESHGUI_TranslationDlg");
96   resize(303, 185);
97   setCaption(tr("SMESH_TRANSLATION"));
98   setSizeGripEnabled(TRUE);
99   SMESHGUI_TranslationDlgLayout = new QGridLayout(this);
100   SMESHGUI_TranslationDlgLayout->setSpacing(6);
101   SMESHGUI_TranslationDlgLayout->setMargin(11);
102
103   /***************************************************************/
104   GroupConstructors = new QButtonGroup(this, "GroupConstructors");
105   GroupConstructors->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupConstructors->sizePolicy().hasHeightForWidth()));
106   GroupConstructors->setTitle(tr("SMESH_TRANSLATION" ));
107   GroupConstructors->setExclusive(TRUE);
108   GroupConstructors->setColumnLayout(0, Qt::Vertical);
109   GroupConstructors->layout()->setSpacing(0);
110   GroupConstructors->layout()->setMargin(0);
111   GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
112   GroupConstructorsLayout->setAlignment(Qt::AlignTop);
113   GroupConstructorsLayout->setSpacing(6);
114   GroupConstructorsLayout->setMargin(11);
115   RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
116   RadioButton1->setText(tr("" ));
117   RadioButton1->setPixmap(image0);
118   GroupConstructorsLayout->addWidget(RadioButton1, 0, 0);
119   RadioButton2= new QRadioButton(GroupConstructors, "RadioButton2");
120   RadioButton2->setText(tr("" ));
121   RadioButton2->setPixmap(image1);
122   GroupConstructorsLayout->addWidget(RadioButton2, 0, 2 );
123   SMESHGUI_TranslationDlgLayout->addWidget(GroupConstructors, 0, 0);
124
125   /***************************************************************/
126   GroupButtons = new QGroupBox(this, "GroupButtons");
127   GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth()));
128   GroupButtons->setGeometry(QRect(10, 10, 281, 48));
129   GroupButtons->setTitle(tr("" ));
130   GroupButtons->setColumnLayout(0, Qt::Vertical);
131   GroupButtons->layout()->setSpacing(0);
132   GroupButtons->layout()->setMargin(0);
133   GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
134   GroupButtonsLayout->setAlignment(Qt::AlignTop);
135   GroupButtonsLayout->setSpacing(6);
136   GroupButtonsLayout->setMargin(11);
137   buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
138   buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
139   buttonCancel->setAutoDefault(TRUE);
140   GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
141   buttonApply = new QPushButton(GroupButtons, "buttonApply");
142   buttonApply->setText(tr("SMESH_BUT_APPLY" ));
143   buttonApply->setAutoDefault(TRUE);
144   GroupButtonsLayout->addWidget(buttonApply, 0, 1);
145   QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
146   GroupButtonsLayout->addItem(spacer_9, 0, 2);
147   buttonOk = new QPushButton(GroupButtons, "buttonOk");
148   buttonOk->setText(tr("SMESH_BUT_OK" ));
149   buttonOk->setAutoDefault(TRUE);
150   buttonOk->setDefault(TRUE);
151   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
152   SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons, 2, 0);
153
154   /***************************************************************/
155   GroupArguments = new QGroupBox(this, "GroupArguments");
156   GroupArguments->setTitle(tr("SMESH_ARGUMENTS"));
157   GroupArguments->setColumnLayout(0, Qt::Vertical);
158   GroupArguments->layout()->setSpacing(0);
159   GroupArguments->layout()->setMargin(0);
160   GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
161   GroupArgumentsLayout->setAlignment(Qt::AlignTop);
162   GroupArgumentsLayout->setSpacing(6);
163   GroupArgumentsLayout->setMargin(11);
164
165   // Controls for elements selection
166   TextLabelElements  = new QLabel(GroupArguments, "TextLabelElements");
167   TextLabelElements->setText(tr("SMESH_ID_ELEMENTS" ));
168   TextLabelElements->setFixedWidth(74);
169   GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
170
171   SelectElementsButton  = new QPushButton(GroupArguments, "SelectElementsButton");
172   SelectElementsButton->setText(tr("" ));
173   SelectElementsButton->setPixmap(image2);
174   SelectElementsButton->setToggleButton(FALSE);
175   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
176
177   LineEditElements  = new QLineEdit(GroupArguments, "LineEditElements");
178   LineEditElements->setValidator(new SMESHGUI_IdValidator(this, "validator"));
179   GroupArgumentsLayout->addMultiCellWidget(LineEditElements, 0, 0, 2, 7);
180
181   // Control for the whole mesh selection
182   CheckBoxMesh = new QCheckBox(GroupArguments, "CheckBoxMesh");
183   CheckBoxMesh->setText(tr("SMESH_SELECT_WHOLE_MESH" ));
184   GroupArgumentsLayout->addMultiCellWidget(CheckBoxMesh, 1, 1, 0, 7);
185
186   // Controls for vector and points selection
187   TextLabel1 = new QLabel(GroupArguments, "TextLabel1");
188   GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
189
190   SelectButton1  = new QPushButton(GroupArguments, "SelectButton1");
191   SelectButton1->setText(tr("" ));
192   SelectButton1->setPixmap(image2);
193   SelectButton1->setToggleButton(FALSE);
194   GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
195
196   TextLabel1_1 = new QLabel(GroupArguments, "TextLabel1_1");
197   GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
198
199   SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox1_1");
200   GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
201
202   TextLabel1_2 = new QLabel(GroupArguments, "TextLabel1_2");
203   GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
204
205   SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox1_2");
206   GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
207
208   TextLabel1_3 = new QLabel(GroupArguments, "TextLabel1_3");
209   GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
210
211   SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox1_3");
212   GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
213
214   TextLabel2 = new QLabel(GroupArguments, "TextLabel2");
215   TextLabel2->setText(tr("SMESH_POINT_2" ));
216   GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
217
218   SelectButton2  = new QPushButton(GroupArguments, "SelectButton2");
219   SelectButton2->setText(tr("" ));
220   SelectButton2->setPixmap(image2);
221   SelectButton2->setToggleButton(FALSE);
222   GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
223
224   TextLabel2_1 = new QLabel(GroupArguments, "TextLabel2_1");
225   TextLabel2_1->setText(tr("SMESH_X" ));
226   GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
227
228   SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox2_1");
229   GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
230
231   TextLabel2_2 = new QLabel(GroupArguments, "TextLabel2_2");
232   TextLabel2_2->setText(tr("SMESH_Y" ));
233   GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
234
235   SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox2_2");
236   GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
237
238   TextLabel2_3 = new QLabel(GroupArguments, "TextLabel2_3");
239   TextLabel2_3->setText(tr("SMESH_Z"));
240   GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
241
242   SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox2_3");
243   GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
244
245   // Controls for "Create a copy" option
246   CheckBoxCopy = new QCheckBox(GroupArguments, "CheckBoxCopy");
247   CheckBoxCopy->setText(tr("SMESH_CREATE_COPY"));
248   GroupArgumentsLayout->addMultiCellWidget(CheckBoxCopy, 4, 4, 0, 2);
249
250
251   SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments, 1, 0);
252
253   /* Initialisations */
254   SpinBox1_1->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
255   SpinBox1_2->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
256   SpinBox1_3->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
257   SpinBox2_1->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
258   SpinBox2_2->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
259   SpinBox2_3->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
260
261   GroupArguments->show();
262   RadioButton1->setChecked(TRUE);
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
399       myViewWindow->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     mySelectionMgr->clearSelected();
451     SMESH::UpdateView();
452     Init(false);
453     ConstructorsClicked(GetConstructorId());
454   }
455 }
456
457 //=================================================================================
458 // function : ClickOnOk()
459 // purpose  :
460 //=================================================================================
461 void SMESHGUI_TranslationDlg::ClickOnOk()
462 {
463   ClickOnApply();
464   ClickOnCancel();
465 }
466
467 //=================================================================================
468 // 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   myViewWindow->SetSelectionMode( ActorSelection );
478   mySMESHGUI->ResetState();
479   reject();
480 }
481
482 //=======================================================================
483 // function : onTextChange()
484 // purpose  :
485 //=======================================================================
486 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
487 {
488   QLineEdit* send = (QLineEdit*)sender();
489
490   if (myBusy) return;
491   myBusy = true;
492
493   if (send == LineEditElements)
494     myNbOkElements = 0;
495
496   buttonOk->setEnabled(false);
497   buttonApply->setEnabled(false);
498
499   // hilight entered elements
500   SMDS_Mesh* aMesh = 0;
501   if (myActor)
502     aMesh = myActor->GetObject()->GetMesh();
503
504   if (aMesh) {
505     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
506     
507     TColStd_MapOfInteger newIndices;
508
509     QStringList aListId = QStringList::split(" ", theNewText, false);
510
511     if (send == LineEditElements) {
512       for (int i = 0; i < aListId.count(); i++) {
513         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
514         if (e)
515           newIndices.Add(e->GetID());
516         myNbOkElements++;
517       }
518     }
519
520     mySelector->AddOrRemoveIndex( anIO, newIndices, false );
521     myViewWindow->highlight( anIO, true, true );
522     
523     myElementsId = theNewText;
524   }
525
526   if (myNbOkElements) {
527     buttonOk->setEnabled(true);
528     buttonApply->setEnabled(true);
529   }
530
531   myBusy = false;
532 }
533
534 //=================================================================================
535 // function : SelectionIntoArgument()
536 // purpose  : Called when selection as changed or other case
537 //=================================================================================
538 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
539 {
540   if (myBusy) return;
541
542   // clear
543   myActor = 0;
544   QString aString = "";
545
546   myBusy = true;
547   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
548     LineEditElements->setText(aString);
549     myNbOkElements = 0;
550     buttonOk->setEnabled(false);
551     buttonApply->setEnabled(false);
552   }
553   myBusy = false;
554
555   if (!GroupButtons->isEnabled()) // inactive
556     return;
557
558   // get selected mesh
559   SALOME_ListIO aList;
560   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
561
562   int nbSel = aList.Extent();
563   if (nbSel != 1)
564     return;
565
566   Handle(SALOME_InteractiveObject) IO = aList.First();
567   myMesh = SMESH::GetMeshByIO(IO);
568   if (myMesh->_is_nil())
569     return;
570
571   myActor = SMESH::FindActorByObject(myMesh);
572   if (!myActor)
573     myActor = SMESH::FindActorByEntry(IO->getEntry());
574   if (!myActor)
575     return;
576
577   int aNbUnits = 0;
578
579   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
580     myElementsId = "";
581
582     if (CheckBoxMesh->isChecked()) {
583       SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
584
585       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
586         // get IDs from mesh
587         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
588         if (!aSMDSMesh)
589           return;
590
591         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
592           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
593           if (e) {
594             myElementsId += QString(" %1").arg(i);
595             aNbUnits++;
596           }
597         }
598       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
599         // get submesh
600         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
601
602         // get IDs from submesh
603         SMESH::long_array_var anElementsIds = new SMESH::long_array;
604         anElementsIds = aSubMesh->GetElementsId();
605         for (int i = 0; i < anElementsIds->length(); i++) {
606           myElementsId += QString(" %1").arg(anElementsIds[i]);
607         }
608         aNbUnits = anElementsIds->length();
609       } else { // GROUP
610         // get smesh group
611         SMESH::SMESH_GroupBase_var aGroup =
612           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
613         if (aGroup->_is_nil())
614           return;
615
616         // get IDs from smesh group
617         SMESH::long_array_var anElementsIds = new SMESH::long_array;
618         anElementsIds = aGroup->GetListOfID();
619         for (int i = 0; i < anElementsIds->length(); i++) {
620           myElementsId += QString(" %1").arg(anElementsIds[i]);
621         }
622         aNbUnits = anElementsIds->length();
623       }
624     } else {
625       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
626       myElementsId = aString;
627     }
628
629     if (aNbUnits < 1)
630       return;
631
632     myNbOkElements = true;
633   } else {
634     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
635     if (aNbUnits != 1)
636       return;
637
638     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
639     if (!aMesh)
640       return;
641
642     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
643     if (!n)
644       return;
645
646     double x = n->X();
647     double y = n->Y();
648     double z = n->Z();
649
650     if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
651       SpinBox1_1->SetValue(x);
652       SpinBox1_2->SetValue(y);
653       SpinBox2_3->SetValue(z);
654     } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
655       SpinBox2_1->SetValue(x);
656       SpinBox2_2->SetValue(y);
657       SpinBox2_3->SetValue(z);
658     }
659   }
660
661   myBusy = true;
662   if (myEditCurrentArgument == (QWidget*)LineEditElements)
663     LineEditElements->setText(aString);
664   myBusy = false;
665
666   // OK
667   if (myNbOkElements) {
668     buttonOk->setEnabled(true);
669     buttonApply->setEnabled(true);
670   }
671 }
672
673 //=================================================================================
674 // function : SetEditCurrentArgument()
675 // purpose  :
676 //=================================================================================
677 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
678 {
679   QPushButton* send = (QPushButton*)sender();
680
681   disconnect(mySelectionMgr, 0, this, 0);
682   mySelectionMgr->clearSelected();
683   mySelectionMgr->clearFilters();
684
685   if (send == SelectElementsButton) {
686     myEditCurrentArgument = (QWidget*)LineEditElements;
687     SMESH::SetPointRepresentation(false);
688     if (CheckBoxMesh->isChecked()) {
689       myViewWindow->SetSelectionMode( ActorSelection );
690       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
691     } else {
692
693       myViewWindow->SetSelectionMode( CellSelection );
694     }
695   } else if (send == SelectButton1) {
696     myEditCurrentArgument = (QWidget*)SpinBox1_1;
697     SMESH::SetPointRepresentation(true);
698
699     myViewWindow->SetSelectionMode( NodeSelection );
700   } else if (send == SelectButton2) {
701     myEditCurrentArgument = (QWidget*)SpinBox2_1;
702     SMESH::SetPointRepresentation(true);
703
704     myViewWindow->SetSelectionMode( NodeSelection );
705   }
706
707   myEditCurrentArgument->setFocus();
708   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
709   SelectionIntoArgument();
710 }
711
712 //=================================================================================
713 // function : DeactivateActiveDialog()
714 // purpose  :
715 //=================================================================================
716 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
717 {
718   if (GroupConstructors->isEnabled()) {
719     GroupConstructors->setEnabled(false);
720     GroupArguments->setEnabled(false);
721     GroupButtons->setEnabled(false);
722     mySMESHGUI->ResetState();
723     mySMESHGUI->SetActiveDialogBox(0);
724   }
725 }
726
727 //=================================================================================
728 // function : ActivateThisDialog()
729 // purpose  :
730 //=================================================================================
731 void SMESHGUI_TranslationDlg::ActivateThisDialog()
732 {
733   /* Emit a signal to deactivate the active dialog */
734   mySMESHGUI->EmitSignalDeactivateDialog();
735   GroupConstructors->setEnabled(true);
736   GroupArguments->setEnabled(true);
737   GroupButtons->setEnabled(true);
738
739   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
740
741   myViewWindow->SetSelectionMode( CellSelection );
742
743   SelectionIntoArgument();
744 }
745
746 //=================================================================================
747 // function : enterEvent()
748 // purpose  :
749 //=================================================================================
750 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
751 {
752   if (!GroupConstructors->isEnabled())
753     ActivateThisDialog();
754 }
755
756 //=================================================================================
757 // function : closeEvent()
758 // purpose  :
759 //=================================================================================
760 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
761 {
762   /* same than click on cancel button */
763   this->ClickOnCancel();
764 }
765
766 //=======================================================================
767 //function : hideEvent
768 //purpose  : caused by ESC key
769 //=======================================================================
770 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
771 {
772   if (!isMinimized())
773     ClickOnCancel();
774 }
775
776 //=======================================================================
777 //function : onSelectMesh
778 //purpose  :
779 //=======================================================================
780 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
781 {
782   if (toSelectMesh)
783     TextLabelElements->setText(tr("SMESH_NAME"));
784   else
785     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
786
787   if (myEditCurrentArgument != LineEditElements) {
788     LineEditElements->clear();
789     return;
790   }
791
792   mySelectionMgr->clearFilters();
793   SMESH::SetPointRepresentation(false);
794
795   if (toSelectMesh) {
796     myViewWindow->SetSelectionMode( ActorSelection );
797     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
798     LineEditElements->setReadOnly(true);
799   } else {
800     myViewWindow->SetSelectionMode( CellSelection );
801     LineEditElements->setReadOnly(false);
802     onTextChange(LineEditElements->text());
803   }
804
805   SelectionIntoArgument();
806 }
807
808 //=================================================================================
809 // function : GetConstructorId()
810 // purpose  :
811 //=================================================================================
812 int SMESHGUI_TranslationDlg::GetConstructorId()
813 {
814   if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
815     return GroupConstructors->id(GroupConstructors->selected());
816   return -1;
817 }