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