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