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