Salome HOME
bb6d11167296b3d6302130150c4718efeeaca6ed
[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     SMESHGUI::Modified();
535   }
536   
537   return true;
538 }
539
540 //=================================================================================
541 // function : ClickOnOk()
542 // purpose  :
543 //=================================================================================
544 void SMESHGUI_TranslationDlg::ClickOnOk()
545 {
546   if( ClickOnApply() )
547     ClickOnCancel();
548 }
549
550 //=================================================================================
551 // function : ClickOnCancel()
552 // purpose  :
553 //=================================================================================
554 void SMESHGUI_TranslationDlg::ClickOnCancel()
555 {
556   disconnect(mySelectionMgr, 0, this, 0);
557   mySelectionMgr->clearFilters();
558   //mySelectionMgr->clearSelected();
559   if (SMESH::GetCurrentVtkView()) {
560     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
561     SMESH::SetPointRepresentation(false);
562   }
563   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
564     aViewWindow->SetSelectionMode( ActorSelection );
565   mySMESHGUI->ResetState();
566   reject();
567 }
568
569 //=================================================================================
570 // function : ClickOnHelp()
571 // purpose  :
572 //=================================================================================
573 void SMESHGUI_TranslationDlg::ClickOnHelp()
574 {
575   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
576   if (app) 
577     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
578   else {
579     QString platform;
580 #ifdef WIN32
581     platform = "winapplication";
582 #else
583     platform = "application";
584 #endif
585     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
586                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
587                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
588                                                                  platform)).
589                              arg(myHelpFileName));
590   }
591 }
592
593 //=======================================================================
594 // function : onTextChange()
595 // purpose  :
596 //=======================================================================
597 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
598 {
599   QLineEdit* send = (QLineEdit*)sender();
600
601   if (myBusy) return;
602   BusyLocker lock( myBusy );
603
604   if (send == LineEditElements)
605     myNbOkElements = 0;
606
607   buttonOk->setEnabled(false);
608   buttonApply->setEnabled(false);
609
610   // hilight entered elements
611   SMDS_Mesh* aMesh = 0;
612   if (myActor)
613     aMesh = myActor->GetObject()->GetMesh();
614
615   if (aMesh) {
616     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
617     
618     TColStd_MapOfInteger newIndices;
619
620     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
621
622     if (send == LineEditElements) {
623       for (int i = 0; i < aListId.count(); i++) {
624         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
625         if (e)
626           newIndices.Add(e->GetID());
627         myNbOkElements++;
628       }
629     }
630
631     mySelector->AddOrRemoveIndex( anIO, newIndices, false );
632     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
633       aViewWindow->highlight( anIO, true, true );
634     
635     myElementsId = theNewText;
636   }
637
638   if (myNbOkElements) {
639     buttonOk->setEnabled(true);
640     buttonApply->setEnabled(true);
641   }
642 }
643
644 //=================================================================================
645 // function : SelectionIntoArgument()
646 // purpose  : Called when selection as changed or other case
647 //=================================================================================
648 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
649 {
650   if (myBusy) return;
651   BusyLocker lock( myBusy );
652   // clear
653   myActor = 0;
654   QString aString = "";
655
656   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
657     LineEditElements->setText(aString);
658     myNbOkElements = 0;
659     buttonOk->setEnabled(false);
660     buttonApply->setEnabled(false);
661   }
662
663   if (!GroupButtons->isEnabled()) // inactive
664     return;
665
666   // get selected mesh
667   SALOME_ListIO aList;
668   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
669
670   int nbSel = aList.Extent();
671   if (nbSel != 1)
672     return;
673
674   Handle(SALOME_InteractiveObject) IO = aList.First();
675   myMesh = SMESH::GetMeshByIO(IO);
676   if (myMesh->_is_nil())
677     return;
678
679   myActor = SMESH::FindActorByObject(myMesh);
680   if (!myActor)
681     myActor = SMESH::FindActorByEntry(IO->getEntry());
682
683   if (!myActor && !CheckBoxMesh->isChecked())
684       return;
685
686   int aNbUnits = 0;
687
688   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
689     myElementsId = "";
690
691     // MakeGroups is available if there are groups and "Copy"
692     if ( myMesh->NbGroups() == 0 ) {
693       MakeGroupsCheck->setChecked(false);
694       MakeGroupsCheck->setEnabled(false);
695     }
696     else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
697       MakeGroupsCheck->setEnabled(true);
698     }
699
700     if (CheckBoxMesh->isChecked()) {
701       SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
702
703       if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
704         mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
705       }
706       else
707         return;
708         // get IDs from mesh
709         /*
710         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
711         if (!aSMDSMesh)
712           return;
713
714         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
715           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
716           if (e) {
717             myElementsId += QString(" %1").arg(i);
718             aNbUnits++;
719           }
720         }
721       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
722         // get submesh
723         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
724
725         // get IDs from submesh
726         SMESH::long_array_var anElementsIds = new SMESH::long_array;
727         anElementsIds = aSubMesh->GetElementsId();
728         for (int i = 0; i < anElementsIds->length(); i++) {
729           myElementsId += QString(" %1").arg(anElementsIds[i]);
730         }
731         aNbUnits = anElementsIds->length();
732       } else { // GROUP
733         // get smesh group
734         SMESH::SMESH_GroupBase_var aGroup =
735           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
736         if (aGroup->_is_nil())
737           return;
738
739         // get IDs from smesh group
740         SMESH::long_array_var anElementsIds = new SMESH::long_array;
741         anElementsIds = aGroup->GetListOfID();
742         for (int i = 0; i < anElementsIds->length(); i++) {
743           myElementsId += QString(" %1").arg(anElementsIds[i]);
744         }
745         aNbUnits = anElementsIds->length();
746       }
747         */
748     } else {
749       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
750       myElementsId = aString;
751       if (aNbUnits < 1)
752         return;  
753     }
754
755     myNbOkElements = true;
756   } else {
757     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
758     if (aNbUnits != 1)
759       return;
760
761     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
762     if (!aMesh)
763       return;
764
765     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
766     if (!n)
767       return;
768
769     double x = n->X();
770     double y = n->Y();
771     double z = n->Z();
772
773     if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
774       SpinBox1_1->SetValue(x);
775       SpinBox1_2->SetValue(y);
776       SpinBox1_3->SetValue(z);
777     } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
778       SpinBox2_1->SetValue(x);
779       SpinBox2_2->SetValue(y);
780       SpinBox2_3->SetValue(z);
781     }
782   }
783
784   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
785     LineEditElements->setText(aString);
786     LineEditElements->repaint();
787     LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
788     LineEditElements->setEnabled(true); 
789     setNewMeshName();
790   }
791
792   // OK
793   if (myNbOkElements) {
794     buttonOk->setEnabled(true);
795     buttonApply->setEnabled(true);
796   }
797 }
798
799 //=================================================================================
800 // function : SetEditCurrentArgument()
801 // purpose  :
802 //=================================================================================
803 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
804 {
805   QPushButton* send = (QPushButton*)sender();
806
807   disconnect(mySelectionMgr, 0, this, 0);
808   mySelectionMgr->clearSelected();
809   mySelectionMgr->clearFilters();
810
811   if (send == SelectElementsButton) {
812     myEditCurrentArgument = (QWidget*)LineEditElements;
813     SMESH::SetPointRepresentation(false);
814     if (CheckBoxMesh->isChecked()) {
815       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
816         aViewWindow->SetSelectionMode( ActorSelection );
817       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
818     } else {
819
820       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
821         aViewWindow->SetSelectionMode( CellSelection );
822     }
823   } else if (send == SelectButton1) {
824     myEditCurrentArgument = (QWidget*)SpinBox1_1;
825     SMESH::SetPointRepresentation(true);
826
827     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
828       aViewWindow->SetSelectionMode( NodeSelection );
829   } else if (send == SelectButton2) {
830     myEditCurrentArgument = (QWidget*)SpinBox2_1;
831     SMESH::SetPointRepresentation(true);
832
833     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
834       aViewWindow->SetSelectionMode( NodeSelection );
835   }
836
837   myEditCurrentArgument->setFocus();
838   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
839   SelectionIntoArgument();
840 }
841
842 //=================================================================================
843 // function : DeactivateActiveDialog()
844 // purpose  :
845 //=================================================================================
846 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
847 {
848   if (ConstructorsBox->isEnabled()) {
849     ConstructorsBox->setEnabled(false);
850     GroupArguments->setEnabled(false);
851     GroupButtons->setEnabled(false);
852     mySMESHGUI->ResetState();
853     mySMESHGUI->SetActiveDialogBox(0);
854   }
855 }
856
857 //=================================================================================
858 // function : ActivateThisDialog()
859 // purpose  :
860 //=================================================================================
861 void SMESHGUI_TranslationDlg::ActivateThisDialog()
862 {
863   /* Emit a signal to deactivate the active dialog */
864   mySMESHGUI->EmitSignalDeactivateDialog();
865   ConstructorsBox->setEnabled(true);
866   GroupArguments->setEnabled(true);
867   GroupButtons->setEnabled(true);
868
869   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
870
871   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
872     aViewWindow->SetSelectionMode( CellSelection );
873
874   SelectionIntoArgument();
875 }
876
877 //=================================================================================
878 // function : enterEvent()
879 // purpose  :
880 //=================================================================================
881 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
882 {
883   if (!ConstructorsBox->isEnabled())
884     ActivateThisDialog();
885 }
886
887 //=================================================================================
888 // function : closeEvent()
889 // purpose  :
890 //=================================================================================
891 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
892 {
893   /* same than click on cancel button */
894   ClickOnCancel();
895 }
896
897 //=======================================================================
898 //function : hideEvent
899 //purpose  : caused by ESC key
900 //=======================================================================
901 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
902 {
903   if (!isMinimized())
904     ClickOnCancel();
905 }
906
907 //=======================================================================
908 //function : onSelectMesh
909 //purpose  :
910 //=======================================================================
911 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
912 {
913   if (toSelectMesh)
914     TextLabelElements->setText(tr("SMESH_NAME"));
915   else
916     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
917   myFilterBtn->setEnabled(!toSelectMesh);
918
919   if (myEditCurrentArgument != LineEditElements) {
920     LineEditElements->clear();
921     return;
922   }
923
924   mySelectionMgr->clearFilters();
925   SMESH::SetPointRepresentation(false);
926
927   if (toSelectMesh) {
928     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
929       aViewWindow->SetSelectionMode( ActorSelection );
930     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
931     LineEditElements->setReadOnly(true);
932     LineEditElements->setValidator(0);
933   } else {
934     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
935       aViewWindow->SetSelectionMode( CellSelection );
936     LineEditElements->setReadOnly(false);
937     LineEditElements->setValidator(myIdValidator);
938     onTextChange(LineEditElements->text());
939   }
940
941   SelectionIntoArgument();
942 }
943
944 //=======================================================================
945 //function : onActionClicked
946 //purpose  : slot called when an action type changed
947 //=======================================================================
948
949 void SMESHGUI_TranslationDlg::onActionClicked(int button)
950 {
951   switch ( button ) {
952   case MOVE_ELEMS_BUTTON:
953     MakeGroupsCheck->setEnabled(false);
954     LineEditNewMesh->setEnabled(false);
955     break;
956   case COPY_ELEMS_BUTTON:
957     LineEditNewMesh->setEnabled(false);
958     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
959     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
960       MakeGroupsCheck->setEnabled(true);
961     else
962       MakeGroupsCheck->setEnabled(false);
963     break;
964   case MAKE_MESH_BUTTON:
965     LineEditNewMesh->setEnabled(true);
966     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
967     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
968       MakeGroupsCheck->setEnabled(true);
969     else
970       MakeGroupsCheck->setEnabled(false);
971     break;
972   }
973   setNewMeshName();
974 }
975
976 //=======================================================================
977 //function : setNewMeshName
978 //purpose  : update contents of LineEditNewMesh
979 //=======================================================================
980
981 void SMESHGUI_TranslationDlg::setNewMeshName()
982 {
983   LineEditNewMesh->setText("");
984   if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
985     QString name;
986     if ( CheckBoxMesh->isChecked() ) {
987       name = LineEditElements->text();
988     }
989     else {
990       _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
991       name = meshSO->GetName().c_str();
992     }
993     if ( !name.isEmpty() )
994       LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
995   }
996 }
997
998 //=================================================================================
999 // function : GetConstructorId()
1000 // purpose  :
1001 //=================================================================================
1002 int SMESHGUI_TranslationDlg::GetConstructorId()
1003 {
1004   return GroupConstructors->checkedId();
1005 }
1006
1007 //=================================================================================
1008 // function : keyPressEvent()
1009 // purpose  :
1010 //=================================================================================
1011 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1012 {
1013   QDialog::keyPressEvent( e );
1014   if ( e->isAccepted() )
1015     return;
1016
1017   if ( e->key() == Qt::Key_F1 ) {
1018     e->accept();
1019     ClickOnHelp();
1020   }
1021 }
1022
1023 //=================================================================================
1024 // function : setFilters()
1025 // purpose  : SLOT. Called when "Filter" button pressed.
1026 //=================================================================================
1027 void SMESHGUI_TranslationDlg::setFilters()
1028 {
1029   if(myMesh->_is_nil()) {
1030     SUIT_MessageBox::critical(this,
1031                               tr("SMESH_ERROR"),
1032                               tr("NO_MESH_SELECTED"));
1033    return;
1034   }
1035   if ( !myFilterDlg )
1036     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1037
1038   myFilterDlg->SetSelection();
1039   myFilterDlg->SetMesh( myMesh );
1040   myFilterDlg->SetSourceWg( LineEditElements );
1041
1042   myFilterDlg->show();
1043 }
1044
1045 //=================================================================================
1046 // function : isValid
1047 // purpose  :
1048 //=================================================================================
1049 bool SMESHGUI_TranslationDlg::isValid()
1050 {
1051   bool ok = true;
1052   QString msg;
1053
1054   ok = SpinBox1_1->isValid( msg, true ) && ok;
1055   ok = SpinBox1_2->isValid( msg, true ) && ok;
1056   ok = SpinBox1_3->isValid( msg, true ) && ok;
1057   if (GetConstructorId() == 0) {
1058     ok = SpinBox2_1->isValid( msg, true ) && ok;
1059     ok = SpinBox2_2->isValid( msg, true ) && ok;
1060     ok = SpinBox2_3->isValid( msg, true ) && ok;
1061   }
1062
1063   if( !ok ) {
1064     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1065     if ( !msg.isEmpty() )
1066       str += "\n" + msg;
1067     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1068     return false;
1069   }
1070   return true;
1071 }