Salome HOME
merge V5_1_4
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_TranslationDlg.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_TranslationDlg.cxx
25 // Author : Michael ZORIN, Open CASCADE S.A.S.
26 // SMESH includes
27 //
28 #include "SMESHGUI_TranslationDlg.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_SpinBox.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_IdValidator.h"
36 #include "SMESHGUI_FilterDlg.h"
37
38 #include <SMESH_Actor.h>
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESH_LogicalFilter.hxx>
41 #include <SMDS_Mesh.hxx>
42
43 // SALOME GUI includes
44 #include <SUIT_Desktop.h>
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_Session.h>
47 #include <SUIT_MessageBox.h>
48 #include <SUIT_OverrideCursor.h>
49
50 #include <LightApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
52
53 #include <SVTK_ViewModel.h>
54 #include <SVTK_ViewWindow.h>
55 #include <SALOME_ListIO.hxx>
56
57 // SALOME KERNEL includes
58 #include <SALOMEDSClient_SObject.hxx>
59
60 // OCCT includes
61 #include <TColStd_MapOfInteger.hxx>
62
63 // Qt includes
64 #include <QApplication>
65 #include <QButtonGroup>
66 #include <QGroupBox>
67 #include <QLabel>
68 #include <QLineEdit>
69 #include <QPushButton>
70 #include <QRadioButton>
71 #include <QCheckBox>
72 #include <QHBoxLayout>
73 #include <QVBoxLayout>
74 #include <QGridLayout>
75 #include <QSpinBox>
76 #include <QKeyEvent>
77
78 // IDL includes
79 #include <SALOMEconfig.h>
80 #include CORBA_SERVER_HEADER(SMESH_Group)
81 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
82
83 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
84
85 /*!
86   \class BusyLocker
87   \brief Simple 'busy state' flag locker.
88   \internal
89 */
90
91 class BusyLocker
92 {
93 public:
94   //! Constructor. Sets passed boolean flag to \c true.
95   BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
96   //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
97   ~BusyLocker() { myBusy = false; }
98 private:
99   bool& myBusy; //! External 'busy state' boolean flag
100 };
101
102 #define SPACING 6
103 #define MARGIN  11
104
105 //=================================================================================
106 // class    : SMESHGUI_TranslationDlg()
107 // purpose  :
108 //=================================================================================
109 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule )
110   : QDialog( SMESH::GetDesktop( theModule ) ),
111     mySMESHGUI( theModule ),
112     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
113     myFilterDlg(0),
114     mySelectedObject(SMESH::SMESH_IDSource::_nil())
115 {
116   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
117   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
118   QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
119
120   setModal(false);
121   setAttribute(Qt::WA_DeleteOnClose, true);
122   setWindowTitle(tr("SMESH_TRANSLATION"));
123   setSizeGripEnabled(true);
124
125   QVBoxLayout* SMESHGUI_TranslationDlgLayout = new QVBoxLayout(this);
126   SMESHGUI_TranslationDlgLayout->setSpacing(SPACING);
127   SMESHGUI_TranslationDlgLayout->setMargin(MARGIN);
128
129   /***************************************************************/
130   ConstructorsBox = new QGroupBox(tr("SMESH_TRANSLATION"), this);
131   GroupConstructors = new QButtonGroup(this);
132   QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
133   ConstructorsBoxLayout->setSpacing(SPACING);
134   ConstructorsBoxLayout->setMargin(MARGIN);
135
136   RadioButton1= new QRadioButton(ConstructorsBox);
137   RadioButton1->setIcon(image0);
138   RadioButton2= new QRadioButton(ConstructorsBox);
139   RadioButton2->setIcon(image1);
140
141   ConstructorsBoxLayout->addWidget(RadioButton1);
142   ConstructorsBoxLayout->addWidget(RadioButton2);
143   GroupConstructors->addButton(RadioButton1, 0);
144   GroupConstructors->addButton(RadioButton2, 1);
145
146   /***************************************************************/
147   GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
148   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
149   GroupArgumentsLayout->setSpacing(SPACING);
150   GroupArgumentsLayout->setMargin(MARGIN);
151
152   myIdValidator = new SMESHGUI_IdValidator(this);
153
154   // Controls for elements selection
155   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
156   SelectElementsButton = new QPushButton(GroupArguments);
157   SelectElementsButton->setIcon(image2);
158   LineEditElements = new QLineEdit(GroupArguments);
159   LineEditElements->setValidator(myIdValidator);
160   LineEditElements->setMaxLength(-1);
161   myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
162   connect(myFilterBtn,   SIGNAL(clicked()), this, SLOT(setFilters()));
163
164   // Control for the whole mesh selection
165   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
166
167   // Controls for vector and points selection
168   TextLabel1 = new QLabel(GroupArguments);
169   SelectButton1 = new QPushButton(GroupArguments);
170   SelectButton1->setIcon(image2);
171
172   TextLabel1_1 = new QLabel(GroupArguments);
173   SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
174   TextLabel1_2 = new QLabel(GroupArguments);
175   SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
176   TextLabel1_3 = new QLabel(GroupArguments);
177   SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
178
179   TextLabel2 = new QLabel(tr("SMESH_POINT_2"), GroupArguments);
180   SelectButton2  = new QPushButton(GroupArguments);
181   SelectButton2->setIcon(image2);
182
183   TextLabel2_1 = new QLabel(tr("SMESH_X"), GroupArguments);
184   SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments);
185   TextLabel2_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
186   SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments);
187   TextLabel2_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
188   SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments);
189
190   // switch of action type
191   ActionBox = new QGroupBox(GroupArguments);
192   ActionGroup = new QButtonGroup(GroupArguments);
193   QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
194   ActionBoxLayout->addSpacing(SPACING);
195   ActionBoxLayout->setMargin(MARGIN);
196
197   QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
198   QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
199   QRadioButton* aCreateMesh   = new QRadioButton(tr("SMESH_CREATE_MESH"),   ActionBox);
200
201   ActionBoxLayout->addWidget(aMoveElements);
202   ActionBoxLayout->addWidget(aCopyElements);
203   ActionBoxLayout->addWidget(aCreateMesh);
204   ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
205   ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
206   ActionGroup->addButton(aCreateMesh,   MAKE_MESH_BUTTON);
207
208   // CheckBox for groups generation
209   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
210   MakeGroupsCheck->setChecked(false);
211
212   // Name of a mesh to create
213   LineEditNewMesh = new QLineEdit(GroupArguments);
214
215   // layout
216   GroupArgumentsLayout->addWidget(TextLabelElements,    0, 0);
217   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
218   GroupArgumentsLayout->addWidget(LineEditElements,     0, 2, 1, 5);
219   GroupArgumentsLayout->addWidget(myFilterBtn,          0, 7);
220   GroupArgumentsLayout->addWidget(CheckBoxMesh,         1, 0, 1, 8);
221   GroupArgumentsLayout->addWidget(TextLabel1,           2, 0);
222   GroupArgumentsLayout->addWidget(SelectButton1,        2, 1);
223   GroupArgumentsLayout->addWidget(TextLabel1_1,         2, 2);
224   GroupArgumentsLayout->addWidget(SpinBox1_1,           2, 3);
225   GroupArgumentsLayout->addWidget(TextLabel1_2,         2, 4);
226   GroupArgumentsLayout->addWidget(SpinBox1_2,           2, 5);
227   GroupArgumentsLayout->addWidget(TextLabel1_3,         2, 6);
228   GroupArgumentsLayout->addWidget(SpinBox1_3,           2, 7);
229   GroupArgumentsLayout->addWidget(TextLabel2,           3, 0);
230   GroupArgumentsLayout->addWidget(SelectButton2,        3, 1);
231   GroupArgumentsLayout->addWidget(TextLabel2_1,         3, 2);
232   GroupArgumentsLayout->addWidget(SpinBox2_1,           3, 3);
233   GroupArgumentsLayout->addWidget(TextLabel2_2,         3, 4);
234   GroupArgumentsLayout->addWidget(SpinBox2_2,           3, 5);
235   GroupArgumentsLayout->addWidget(TextLabel2_3,         3, 6);
236   GroupArgumentsLayout->addWidget(SpinBox2_3,           3, 7);
237   GroupArgumentsLayout->addWidget(ActionBox,            4, 0, 3, 4);
238   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      5, 5, 1, 4);
239   GroupArgumentsLayout->addWidget(LineEditNewMesh,      6, 5, 1, 4);
240
241   /***************************************************************/
242   GroupButtons = new QGroupBox(this);
243   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
244   GroupButtonsLayout->setSpacing(SPACING);
245   GroupButtonsLayout->setMargin(MARGIN);
246
247   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
248   buttonOk->setAutoDefault(true);
249   buttonOk->setDefault(true);
250   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
251   buttonApply->setAutoDefault(true);
252   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
253   buttonCancel->setAutoDefault(true);
254   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
255   buttonHelp->setAutoDefault(true);
256
257   GroupButtonsLayout->addWidget(buttonOk);
258   GroupButtonsLayout->addSpacing(10);
259   GroupButtonsLayout->addWidget(buttonApply);
260   GroupButtonsLayout->addSpacing(10);
261   GroupButtonsLayout->addStretch();
262   GroupButtonsLayout->addWidget(buttonCancel);
263   GroupButtonsLayout->addWidget(buttonHelp);
264
265   /***************************************************************/
266   SMESHGUI_TranslationDlgLayout->addWidget(ConstructorsBox);
267   SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments);
268   SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons);
269
270   /* Initialisations */
271   SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
272   SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
273   SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
274   SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
275   SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
276   SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
277
278   RadioButton1->setChecked(true);
279
280   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
281
282   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
283
284   // Costruction of the logical filter
285   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
286   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
287
288   QList<SUIT_SelectionFilter*> aListOfFilters;
289   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
290   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
291
292   myMeshOrSubMeshOrGroupFilter =
293     new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
294
295   myHelpFileName = "translation_page.html";
296
297   Init();
298
299   /* signals and slots connections */
300   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
301   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
302   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
303   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
304   connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
305
306   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
307   connect(SelectButton1,        SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
308   connect(SelectButton2,        SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
309
310   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
311   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),   this, SLOT(SelectionIntoArgument()));
312   /* to close dialog if study change */
313   connect(mySMESHGUI,       SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
314   connect(LineEditElements, SIGNAL(textChanged(const QString&)),    SLOT(onTextChange(const QString&)));
315   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                  SLOT(onSelectMesh(bool)));
316   connect(ActionGroup,      SIGNAL(buttonClicked(int)),             SLOT(onActionClicked(int)));
317
318   ConstructorsClicked(0);
319   SelectionIntoArgument();
320   onActionClicked(MOVE_ELEMS_BUTTON);
321 }
322
323 //=================================================================================
324 // function : ~SMESHGUI_TranslationDlg()
325 // purpose  : Destroys the object and frees any allocated resources
326 //=================================================================================
327 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
328 {
329   if ( myFilterDlg ) {
330     myFilterDlg->setParent( 0 );
331     delete myFilterDlg;
332     myFilterDlg = 0;
333   }
334 }
335
336 //=================================================================================
337 // function : Init()
338 // purpose  :
339 //=================================================================================
340 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
341 {
342   myBusy = false;
343
344   myEditCurrentArgument = 0;
345   LineEditElements->clear();
346   myElementsId = "";
347   myNbOkElements = 0;
348
349   buttonOk->setEnabled(false);
350   buttonApply->setEnabled(false);
351
352   myActor = 0;
353   myMesh = SMESH::SMESH_Mesh::_nil();
354
355   if (ResetControls) {
356     SpinBox1_1->SetValue(0.0);
357     SpinBox1_2->SetValue(0.0);
358     SpinBox1_3->SetValue(0.0);
359     SpinBox2_1->SetValue(0.0);
360     SpinBox2_2->SetValue(0.0);
361     SpinBox2_3->SetValue(0.0);
362
363     ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
364     CheckBoxMesh->setChecked(false);
365 //     MakeGroupsCheck->setChecked(false);
366 //     MakeGroupsCheck->setEnabled(false);
367     onSelectMesh(false);
368   }
369 }
370
371 //=================================================================================
372 // function : ConstructorsClicked()
373 // purpose  : Radio button management
374 //=================================================================================
375 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
376 {
377   disconnect(mySelectionMgr, 0, this, 0);
378
379   switch (constructorId) {
380   case 0:
381     {
382       TextLabel1->setText(tr("SMESH_POINT_1"));
383       TextLabel1_1->setText(tr("SMESH_X"));
384       TextLabel1_2->setText(tr("SMESH_Y"));
385       TextLabel1_3->setText(tr("SMESH_Z"));
386
387       SelectButton1->show();
388       TextLabel2->show();
389       SelectButton2->show();
390       TextLabel2_1->show();
391       SpinBox2_1->show();
392       TextLabel2_2->show();
393       SpinBox2_2->show();
394       TextLabel2_3->show();
395       SpinBox2_3->show();
396       break;
397     }
398   case 1:
399     {
400       TextLabel1->setText(tr("SMESH_VECTOR"));
401       TextLabel1_1->setText(tr("SMESH_DX"));
402       TextLabel1_2->setText(tr("SMESH_DY"));
403       TextLabel1_3->setText(tr("SMESH_DZ"));
404
405       SelectButton1->hide();
406       TextLabel2->hide();
407       SelectButton2->hide();
408       TextLabel2_1->hide();
409       SpinBox2_1->hide();
410       TextLabel2_2->hide();
411       SpinBox2_2->hide();
412       TextLabel2_3->hide();
413       SpinBox2_3->hide();
414       break;
415     }
416   }
417
418   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
419     SMESH::SetPointRepresentation(false);
420     if (!CheckBoxMesh->isChecked())
421       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
422         aViewWindow->SetSelectionMode( CellSelection );
423   }
424
425   myEditCurrentArgument = (QWidget*)LineEditElements;
426   LineEditElements->setFocus();
427
428   if (CheckBoxMesh->isChecked())
429     onSelectMesh(true);
430
431   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
432
433   QApplication::instance()->processEvents();
434   updateGeometry();
435   resize(100,100);
436 }
437
438 //=================================================================================
439 // function : ClickOnApply()
440 // purpose  :
441 //=================================================================================
442 bool SMESHGUI_TranslationDlg::ClickOnApply()
443 {
444   if (mySMESHGUI->isActiveStudyLocked())
445     return false;
446
447   if( !isValid() )
448     return false;
449
450   if (myNbOkElements) {
451     QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
452
453     SMESH::long_array_var anElementsId = new SMESH::long_array;
454
455     anElementsId->length(aListElementsId.count());
456     for (int i = 0; i < aListElementsId.count(); i++)
457       anElementsId[i] = aListElementsId[i].toInt();
458
459     SMESH::DirStruct aVector;
460     if (GetConstructorId() == 0) {
461       aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
462       aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
463       aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
464     } else if (GetConstructorId() == 1) {
465       aVector.PS.x = SpinBox1_1->GetValue();
466       aVector.PS.y = SpinBox1_2->GetValue();
467       aVector.PS.z = SpinBox1_3->GetValue();
468     }
469
470     QStringList aParameters;
471     aParameters << SpinBox1_1->text();
472     if (GetConstructorId() == 0)
473       aParameters << SpinBox2_1->text();
474     aParameters << SpinBox1_2->text();
475     if (GetConstructorId() == 0)
476       aParameters << SpinBox2_2->text();
477     aParameters << SpinBox1_3->text();
478     if (GetConstructorId() == 0)
479       aParameters << SpinBox2_3->text();
480
481     int actionButton = ActionGroup->checkedId();
482     bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
483     try {
484       SUIT_OverrideCursor aWaitCursor;
485       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
486       switch ( actionButton ) {
487       case MOVE_ELEMS_BUTTON:
488         if(CheckBoxMesh->isChecked())
489           aMeshEditor->TranslateObject(mySelectedObject, aVector, false);
490         else
491           aMeshEditor->Translate(anElementsId, aVector, false);
492         if( !myMesh->_is_nil())
493           myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
494         break;
495       case COPY_ELEMS_BUTTON:
496         if ( makeGroups ) {
497           SMESH::ListOfGroups_var groups; 
498           if(CheckBoxMesh->isChecked())
499             groups = aMeshEditor->TranslateObjectMakeGroups(mySelectedObject,aVector);
500           else
501             groups = aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
502         }
503         else {
504           if(CheckBoxMesh->isChecked())
505             aMeshEditor->TranslateObject(mySelectedObject, aVector, true);
506           else
507             aMeshEditor->Translate(anElementsId, aVector, true);
508         }
509         if( !myMesh->_is_nil())
510           myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
511         break;
512       case MAKE_MESH_BUTTON:
513         SMESH::SMESH_Mesh_var mesh; 
514         if(CheckBoxMesh->isChecked())
515           mesh = aMeshEditor->TranslateObjectMakeMesh(mySelectedObject, aVector, makeGroups,
516                                                       LineEditNewMesh->text().toLatin1().data());
517         else
518           mesh = aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
519                                                 LineEditNewMesh->text().toLatin1().data());
520         if( !mesh->_is_nil())
521           mesh->SetParameters( aParameters.join(":").toLatin1().constData() );
522       }
523     } catch (...) {
524     }
525     
526     SMESH::UpdateView();
527     if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
528          actionButton == MAKE_MESH_BUTTON )
529       mySMESHGUI->updateObjBrowser(true); // new groups may appear
530     Init(false);
531     ConstructorsClicked(GetConstructorId());
532     mySelectedObject = SMESH::SMESH_IDSource::_nil();
533     SelectionIntoArgument();
534
535     SMESHGUI::Modified();
536   }
537   
538   return true;
539 }
540
541 //=================================================================================
542 // function : ClickOnOk()
543 // purpose  :
544 //=================================================================================
545 void SMESHGUI_TranslationDlg::ClickOnOk()
546 {
547   if( ClickOnApply() )
548     ClickOnCancel();
549 }
550
551 //=================================================================================
552 // function : ClickOnCancel()
553 // purpose  :
554 //=================================================================================
555 void SMESHGUI_TranslationDlg::ClickOnCancel()
556 {
557   disconnect(mySelectionMgr, 0, this, 0);
558   mySelectionMgr->clearFilters();
559   //mySelectionMgr->clearSelected();
560   if (SMESH::GetCurrentVtkView()) {
561     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
562     SMESH::SetPointRepresentation(false);
563   }
564   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
565     aViewWindow->SetSelectionMode( ActorSelection );
566   mySMESHGUI->ResetState();
567   reject();
568 }
569
570 //=================================================================================
571 // function : ClickOnHelp()
572 // purpose  :
573 //=================================================================================
574 void SMESHGUI_TranslationDlg::ClickOnHelp()
575 {
576   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
577   if (app) 
578     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
579   else {
580     QString platform;
581 #ifdef WIN32
582     platform = "winapplication";
583 #else
584     platform = "application";
585 #endif
586     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
587                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
588                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
589                                                                  platform)).
590                              arg(myHelpFileName));
591   }
592 }
593
594 //=======================================================================
595 // function : onTextChange()
596 // purpose  :
597 //=======================================================================
598 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
599 {
600   QLineEdit* send = (QLineEdit*)sender();
601
602   if (myBusy) return;
603   BusyLocker lock( myBusy );
604
605   if (send == LineEditElements)
606     myNbOkElements = 0;
607
608   buttonOk->setEnabled(false);
609   buttonApply->setEnabled(false);
610
611   // hilight entered elements
612   SMDS_Mesh* aMesh = 0;
613   if (myActor)
614     aMesh = myActor->GetObject()->GetMesh();
615
616   if (aMesh) {
617     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
618     
619     TColStd_MapOfInteger newIndices;
620
621     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
622
623     if (send == LineEditElements) {
624       for (int i = 0; i < aListId.count(); i++) {
625         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
626         if (e)
627           newIndices.Add(e->GetID());
628         myNbOkElements++;
629       }
630     }
631
632     mySelector->AddOrRemoveIndex( anIO, newIndices, false );
633     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
634       aViewWindow->highlight( anIO, true, true );
635     
636     myElementsId = theNewText;
637   }
638
639   if (myNbOkElements) {
640     buttonOk->setEnabled(true);
641     buttonApply->setEnabled(true);
642   }
643 }
644
645 //=================================================================================
646 // function : SelectionIntoArgument()
647 // purpose  : Called when selection as changed or other case
648 //=================================================================================
649 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
650 {
651   if (myBusy) return;
652   BusyLocker lock( myBusy );
653   // clear
654   myActor = 0;
655   QString aString = "";
656
657   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
658     LineEditElements->setText(aString);
659     myNbOkElements = 0;
660     buttonOk->setEnabled(false);
661     buttonApply->setEnabled(false);
662   }
663
664   if (!GroupButtons->isEnabled()) // inactive
665     return;
666
667   // get selected mesh
668   SALOME_ListIO aList;
669   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
670
671   int nbSel = aList.Extent();
672   if (nbSel != 1)
673     return;
674
675   Handle(SALOME_InteractiveObject) IO = aList.First();
676   myMesh = SMESH::GetMeshByIO(IO);
677   if (myMesh->_is_nil())
678     return;
679
680   myActor = SMESH::FindActorByObject(myMesh);
681   if (!myActor)
682     myActor = SMESH::FindActorByEntry(IO->getEntry());
683
684   if (!myActor && !CheckBoxMesh->isChecked())
685       return;
686
687   int aNbUnits = 0;
688
689   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
690     myElementsId = "";
691
692     // MakeGroups is available if there are groups and "Copy"
693     if ( myMesh->NbGroups() == 0 ) {
694       MakeGroupsCheck->setChecked(false);
695       MakeGroupsCheck->setEnabled(false);
696     }
697     else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
698       MakeGroupsCheck->setEnabled(true);
699     }
700
701     if (CheckBoxMesh->isChecked()) {
702       SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
703
704       if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
705         mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
706       }
707       else
708         return;
709         // get IDs from mesh
710         /*
711         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
712         if (!aSMDSMesh)
713           return;
714
715         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
716           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
717           if (e) {
718             myElementsId += QString(" %1").arg(i);
719             aNbUnits++;
720           }
721         }
722       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
723         // get submesh
724         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
725
726         // get IDs from submesh
727         SMESH::long_array_var anElementsIds = new SMESH::long_array;
728         anElementsIds = aSubMesh->GetElementsId();
729         for (int i = 0; i < anElementsIds->length(); i++) {
730           myElementsId += QString(" %1").arg(anElementsIds[i]);
731         }
732         aNbUnits = anElementsIds->length();
733       } else { // GROUP
734         // get smesh group
735         SMESH::SMESH_GroupBase_var aGroup =
736           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
737         if (aGroup->_is_nil())
738           return;
739
740         // get IDs from smesh group
741         SMESH::long_array_var anElementsIds = new SMESH::long_array;
742         anElementsIds = aGroup->GetListOfID();
743         for (int i = 0; i < anElementsIds->length(); i++) {
744           myElementsId += QString(" %1").arg(anElementsIds[i]);
745         }
746         aNbUnits = anElementsIds->length();
747       }
748         */
749     } else {
750       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
751       myElementsId = aString;
752       if (aNbUnits < 1)
753         return;  
754     }
755
756     myNbOkElements = true;
757   } else {
758     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
759     if (aNbUnits != 1)
760       return;
761
762     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
763     if (!aMesh)
764       return;
765
766     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
767     if (!n)
768       return;
769
770     double x = n->X();
771     double y = n->Y();
772     double z = n->Z();
773
774     if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
775       SpinBox1_1->SetValue(x);
776       SpinBox1_2->SetValue(y);
777       SpinBox1_3->SetValue(z);
778     } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
779       SpinBox2_1->SetValue(x);
780       SpinBox2_2->SetValue(y);
781       SpinBox2_3->SetValue(z);
782     }
783   }
784
785   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
786     LineEditElements->setText(aString);
787     LineEditElements->repaint();
788     LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
789     LineEditElements->setEnabled(true); 
790     setNewMeshName();
791   }
792
793   // OK
794   if (myNbOkElements) {
795     buttonOk->setEnabled(true);
796     buttonApply->setEnabled(true);
797   }
798 }
799
800 //=================================================================================
801 // function : SetEditCurrentArgument()
802 // purpose  :
803 //=================================================================================
804 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
805 {
806   QPushButton* send = (QPushButton*)sender();
807
808   disconnect(mySelectionMgr, 0, this, 0);
809   mySelectionMgr->clearSelected();
810   mySelectionMgr->clearFilters();
811
812   if (send == SelectElementsButton) {
813     myEditCurrentArgument = (QWidget*)LineEditElements;
814     SMESH::SetPointRepresentation(false);
815     if (CheckBoxMesh->isChecked()) {
816       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
817         aViewWindow->SetSelectionMode( ActorSelection );
818       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
819     } else {
820
821       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
822         aViewWindow->SetSelectionMode( CellSelection );
823     }
824   } else if (send == SelectButton1) {
825     myEditCurrentArgument = (QWidget*)SpinBox1_1;
826     SMESH::SetPointRepresentation(true);
827
828     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
829       aViewWindow->SetSelectionMode( NodeSelection );
830   } else if (send == SelectButton2) {
831     myEditCurrentArgument = (QWidget*)SpinBox2_1;
832     SMESH::SetPointRepresentation(true);
833
834     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
835       aViewWindow->SetSelectionMode( NodeSelection );
836   }
837
838   myEditCurrentArgument->setFocus();
839   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
840   SelectionIntoArgument();
841 }
842
843 //=================================================================================
844 // function : DeactivateActiveDialog()
845 // purpose  :
846 //=================================================================================
847 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
848 {
849   if (ConstructorsBox->isEnabled()) {
850     ConstructorsBox->setEnabled(false);
851     GroupArguments->setEnabled(false);
852     GroupButtons->setEnabled(false);
853     mySMESHGUI->ResetState();
854     mySMESHGUI->SetActiveDialogBox(0);
855   }
856 }
857
858 //=================================================================================
859 // function : ActivateThisDialog()
860 // purpose  :
861 //=================================================================================
862 void SMESHGUI_TranslationDlg::ActivateThisDialog()
863 {
864   /* Emit a signal to deactivate the active dialog */
865   mySMESHGUI->EmitSignalDeactivateDialog();
866   ConstructorsBox->setEnabled(true);
867   GroupArguments->setEnabled(true);
868   GroupButtons->setEnabled(true);
869
870   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
871
872   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
873     aViewWindow->SetSelectionMode( CellSelection );
874
875   SelectionIntoArgument();
876 }
877
878 //=================================================================================
879 // function : enterEvent()
880 // purpose  :
881 //=================================================================================
882 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
883 {
884   if (!ConstructorsBox->isEnabled())
885     ActivateThisDialog();
886 }
887
888 //=================================================================================
889 // function : closeEvent()
890 // purpose  :
891 //=================================================================================
892 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
893 {
894   /* same than click on cancel button */
895   ClickOnCancel();
896 }
897
898 //=======================================================================
899 //function : hideEvent
900 //purpose  : caused by ESC key
901 //=======================================================================
902 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
903 {
904   if (!isMinimized())
905     ClickOnCancel();
906 }
907
908 //=======================================================================
909 //function : onSelectMesh
910 //purpose  :
911 //=======================================================================
912 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
913 {
914   if (toSelectMesh)
915     TextLabelElements->setText(tr("SMESH_NAME"));
916   else
917     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
918   myFilterBtn->setEnabled(!toSelectMesh);
919
920   if (myEditCurrentArgument != LineEditElements) {
921     LineEditElements->clear();
922     return;
923   }
924
925   mySelectionMgr->clearFilters();
926   SMESH::SetPointRepresentation(false);
927
928   if (toSelectMesh) {
929     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
930       aViewWindow->SetSelectionMode( ActorSelection );
931     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
932     LineEditElements->setReadOnly(true);
933     LineEditElements->setValidator(0);
934   } else {
935     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
936       aViewWindow->SetSelectionMode( CellSelection );
937     LineEditElements->setReadOnly(false);
938     LineEditElements->setValidator(myIdValidator);
939     onTextChange(LineEditElements->text());
940   }
941
942   SelectionIntoArgument();
943 }
944
945 //=======================================================================
946 //function : onActionClicked
947 //purpose  : slot called when an action type changed
948 //=======================================================================
949
950 void SMESHGUI_TranslationDlg::onActionClicked(int button)
951 {
952   switch ( button ) {
953   case MOVE_ELEMS_BUTTON:
954     MakeGroupsCheck->setEnabled(false);
955     LineEditNewMesh->setEnabled(false);
956     break;
957   case COPY_ELEMS_BUTTON:
958     LineEditNewMesh->setEnabled(false);
959     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
960     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
961       MakeGroupsCheck->setEnabled(true);
962     else
963       MakeGroupsCheck->setEnabled(false);
964     break;
965   case MAKE_MESH_BUTTON:
966     LineEditNewMesh->setEnabled(true);
967     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
968     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
969       MakeGroupsCheck->setEnabled(true);
970     else
971       MakeGroupsCheck->setEnabled(false);
972     break;
973   }
974   setNewMeshName();
975 }
976
977 //=======================================================================
978 //function : setNewMeshName
979 //purpose  : update contents of LineEditNewMesh
980 //=======================================================================
981
982 void SMESHGUI_TranslationDlg::setNewMeshName()
983 {
984   LineEditNewMesh->setText("");
985   if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
986     QString name;
987     if ( CheckBoxMesh->isChecked() ) {
988       name = LineEditElements->text();
989     }
990     else {
991       _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
992       name = meshSO->GetName().c_str();
993     }
994     if ( !name.isEmpty() )
995       LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
996   }
997 }
998
999 //=================================================================================
1000 // function : GetConstructorId()
1001 // purpose  :
1002 //=================================================================================
1003 int SMESHGUI_TranslationDlg::GetConstructorId()
1004 {
1005   return GroupConstructors->checkedId();
1006 }
1007
1008 //=================================================================================
1009 // function : keyPressEvent()
1010 // purpose  :
1011 //=================================================================================
1012 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1013 {
1014   QDialog::keyPressEvent( e );
1015   if ( e->isAccepted() )
1016     return;
1017
1018   if ( e->key() == Qt::Key_F1 ) {
1019     e->accept();
1020     ClickOnHelp();
1021   }
1022 }
1023
1024 //=================================================================================
1025 // function : setFilters()
1026 // purpose  : SLOT. Called when "Filter" button pressed.
1027 //=================================================================================
1028 void SMESHGUI_TranslationDlg::setFilters()
1029 {
1030   if(myMesh->_is_nil()) {
1031     SUIT_MessageBox::critical(this,
1032                               tr("SMESH_ERROR"),
1033                               tr("NO_MESH_SELECTED"));
1034    return;
1035   }
1036   if ( !myFilterDlg )
1037     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1038
1039   myFilterDlg->SetSelection();
1040   myFilterDlg->SetMesh( myMesh );
1041   myFilterDlg->SetSourceWg( LineEditElements );
1042
1043   myFilterDlg->show();
1044 }
1045
1046 //=================================================================================
1047 // function : isValid
1048 // purpose  :
1049 //=================================================================================
1050 bool SMESHGUI_TranslationDlg::isValid()
1051 {
1052   bool ok = true;
1053   QString msg;
1054
1055   ok = SpinBox1_1->isValid( msg, true ) && ok;
1056   ok = SpinBox1_2->isValid( msg, true ) && ok;
1057   ok = SpinBox1_3->isValid( msg, true ) && ok;
1058   if (GetConstructorId() == 0) {
1059     ok = SpinBox2_1->isValid( msg, true ) && ok;
1060     ok = SpinBox2_2->isValid( msg, true ) && ok;
1061     ok = SpinBox2_3->isValid( msg, true ) && ok;
1062   }
1063
1064   if( !ok ) {
1065     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1066     if ( !msg.isEmpty() )
1067       str += "\n" + msg;
1068     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1069     return false;
1070   }
1071   return true;
1072 }