Salome HOME
Fix regression (SIGSEGV) caused by improvement 0022099
[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 < myObjects.count(); i++ ) {
596       SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
597       if ( actor ) SMESH::Update( actor->getIO(), true );
598     }
599
600     if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
601          actionButton == MAKE_MESH_BUTTON ) {
602       mySMESHGUI->updateObjBrowser(true); // new groups may appear
603       if( LightApp_Application* anApp =
604           dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
605         anApp->browseObjects( anEntryList, isApplyAndClose() );
606     }
607       
608     Init(false);
609     ConstructorsClicked(GetConstructorId());
610     SelectionIntoArgument();
611
612     SMESHGUI::Modified();
613   }
614
615   return true;
616 }
617
618 //=================================================================================
619 // function : ClickOnOk()
620 // purpose  :
621 //=================================================================================
622 void SMESHGUI_TranslationDlg::ClickOnOk()
623 {
624   setIsApplyAndClose( true );
625   if( ClickOnApply() )
626     reject();
627 }
628
629 //=================================================================================
630 // function : reject()
631 // purpose  :
632 //=================================================================================
633 void SMESHGUI_TranslationDlg::reject()
634 {
635   disconnect(mySelectionMgr, 0, this, 0);
636   mySelectionMgr->clearFilters();
637   //mySelectionMgr->clearSelected();
638   if (SMESH::GetCurrentVtkView()) {
639     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
640     SMESH::SetPointRepresentation(false);
641   }
642   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
643     aViewWindow->SetSelectionMode( ActorSelection );
644   mySMESHGUI->ResetState();
645   QDialog::reject();
646 }
647
648 //=================================================================================
649 // function : ClickOnHelp()
650 // purpose  :
651 //=================================================================================
652 void SMESHGUI_TranslationDlg::ClickOnHelp()
653 {
654   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
655   if (app)
656     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
657   else {
658     QString platform;
659 #ifdef WIN32
660     platform = "winapplication";
661 #else
662     platform = "application";
663 #endif
664     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
665                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
666                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
667                                                                  platform)).
668                              arg(myHelpFileName));
669   }
670 }
671
672 //=======================================================================
673 // function : onTextChange()
674 // purpose  :
675 //=======================================================================
676 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
677 {
678   QLineEdit* send = (QLineEdit*)sender();
679
680   if (myBusy) return;
681   BusyLocker lock( myBusy );
682
683   if (send == LineEditElements)
684     myNbOkElements = 0;
685
686   buttonOk->setEnabled(false);
687   buttonApply->setEnabled(false);
688
689   // hilight entered elements
690   SMDS_Mesh* aMesh = 0;
691   if (myActor)
692     aMesh = myActor->GetObject()->GetMesh();
693
694   if (aMesh) {
695     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
696
697     TColStd_MapOfInteger newIndices;
698
699     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
700
701     if (send == LineEditElements) {
702       for (int i = 0; i < aListId.count(); i++) {
703         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
704         if (e)
705           newIndices.Add(e->GetID());
706         myNbOkElements++;
707       }
708     }
709
710     mySelector->AddOrRemoveIndex( anIO, newIndices, false );
711     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
712       aViewWindow->highlight( anIO, true, true );
713
714     myElementsId = theNewText;
715   }
716
717   if (myNbOkElements) {
718     buttonOk->setEnabled(true);
719     buttonApply->setEnabled(true);
720   }
721 }
722
723 //=================================================================================
724 // function : SelectionIntoArgument()
725 // purpose  : Called when selection as changed or other case
726 //=================================================================================
727 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
728 {
729   if (myBusy) return;
730   BusyLocker lock( myBusy );
731   // clear
732   myActor = 0;
733   QString aString = "";
734   onDisplaySimulation(false);
735
736   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
737     LineEditElements->setText(aString);
738     myNbOkElements = 0;
739     buttonOk->setEnabled(false);
740     buttonApply->setEnabled(false);
741   }
742
743   if (!GroupButtons->isEnabled()) // inactive
744     return;
745
746   // get selected mesh
747   SALOME_ListIO aList;
748   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
749
750   int nbSel = aList.Extent();
751   if (nbSel < 1)
752     return;
753
754   int aNbUnits = 0;
755   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
756     myElementsId = "";
757     myObjects.clear();
758     myObjectsNames.clear();
759     myMeshes.clear();
760
761     for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
762       Handle(SALOME_InteractiveObject) IO = it.Value();
763       SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
764       if ( aMesh->_is_nil() )
765         return;
766
767       SMESH_Actor* anActor = SMESH::FindActorByObject( aMesh );
768       if ( !anActor )
769         anActor = SMESH::FindActorByEntry( IO->getEntry() );
770
771       if ( !anActor && !CheckBoxMesh->isChecked() )
772         return;
773
774       if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
775         if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
776           _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
777           _PTR(GenericAttribute) anAttr;
778           if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
779             _PTR(AttributeName) aNameAttr( anAttr );
780             myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
781             myObjectsNames << aNameAttr->Value().c_str();
782             myMeshes << aMesh;
783           }
784         }
785       }
786
787       myActor = anActor;
788     }
789     
790     // MakeGroups is available if there are groups and "Copy"
791     int aNbGroups = 0;
792     for ( int i = 0; i < myMeshes.count(); i++ )
793       aNbGroups += myMeshes[i]->NbGroups();
794
795     if ( aNbGroups == 0 ) {
796       MakeGroupsCheck->setChecked(false);
797       MakeGroupsCheck->setEnabled(false);
798     }
799     else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
800       MakeGroupsCheck->setEnabled(true);
801     }
802
803     if (CheckBoxMesh->isChecked()) {
804       SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
805       if (myMeshes.isEmpty())
806         return;
807     } else {
808       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
809       myElementsId = aString;
810       if (aNbUnits < 1)
811         return;
812     }
813
814     myNbOkElements = true;
815   } else {
816     Handle(SALOME_InteractiveObject) IO = aList.First();
817     if ((SMESH::GetMeshByIO(IO))->_is_nil())
818       return;
819
820     SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
821     if (!anActor)
822       anActor = SMESH::FindActorByEntry(IO->getEntry());
823     if (!anActor && !CheckBoxMesh->isChecked())
824       return;
825
826     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
827     if (aNbUnits != 1)
828       return;
829
830     SMDS_Mesh* aMesh =  anActor->GetObject()->GetMesh();
831     if (!aMesh)
832       return;
833
834     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
835     if (!n)
836       return;
837
838     double x = n->X();
839     double y = n->Y();
840     double z = n->Z();
841
842     if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
843       SpinBox1_1->SetValue(x);
844       SpinBox1_2->SetValue(y);
845       SpinBox1_3->SetValue(z);
846     } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
847       SpinBox2_1->SetValue(x);
848       SpinBox2_2->SetValue(y);
849       SpinBox2_3->SetValue(z);
850     }
851   }
852
853   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
854     LineEditElements->setText(aString);
855     LineEditElements->repaint();
856     LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
857     LineEditElements->setEnabled(true);
858     setNewMeshName();
859   }
860
861   // OK
862   if (myNbOkElements) {
863     buttonOk->setEnabled(true);
864     buttonApply->setEnabled(true);
865   }
866   onDisplaySimulation(true);
867 }
868
869 //=================================================================================
870 // function : SetEditCurrentArgument()
871 // purpose  :
872 //=================================================================================
873 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
874 {
875   QPushButton* send = (QPushButton*)sender();
876
877   disconnect(mySelectionMgr, 0, this, 0);
878   mySelectionMgr->clearSelected();
879   mySelectionMgr->clearFilters();
880   
881   if (send == SelectElementsButton) {
882     myEditCurrentArgument = (QWidget*)LineEditElements;
883     SMESH::SetPointRepresentation(false);
884     if (CheckBoxMesh->isChecked()) {
885       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
886         aViewWindow->SetSelectionMode( ActorSelection );
887       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
888     } else {
889
890       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
891         aViewWindow->SetSelectionMode( CellSelection );
892     }
893   } else if (send == SelectButton1) {
894     myEditCurrentArgument = (QWidget*)SpinBox1_1;
895     SMESH::SetPointRepresentation(true);
896
897     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
898       aViewWindow->SetSelectionMode( NodeSelection );
899   } else if (send == SelectButton2) {
900     myEditCurrentArgument = (QWidget*)SpinBox2_1;
901     SMESH::SetPointRepresentation(true);
902
903     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
904       aViewWindow->SetSelectionMode( NodeSelection );
905   }
906
907   myEditCurrentArgument->setFocus();
908   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
909   SelectionIntoArgument();
910 }
911
912 //=================================================================================
913 // function : DeactivateActiveDialog()
914 // purpose  :
915 //=================================================================================
916 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
917 {
918   if (ConstructorsBox->isEnabled()) {
919     ConstructorsBox->setEnabled(false);
920     GroupArguments->setEnabled(false);
921     GroupButtons->setEnabled(false);
922     mySMESHGUI->ResetState();
923     mySMESHGUI->SetActiveDialogBox(0);
924   }
925 }
926
927 //=================================================================================
928 // function : ActivateThisDialog()
929 // purpose  :
930 //=================================================================================
931 void SMESHGUI_TranslationDlg::ActivateThisDialog()
932 {
933   /* Emit a signal to deactivate the active dialog */
934   mySMESHGUI->EmitSignalDeactivateDialog();
935   ConstructorsBox->setEnabled(true);
936   GroupArguments->setEnabled(true);
937   GroupButtons->setEnabled(true);
938
939   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
940
941   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
942     aViewWindow->SetSelectionMode( CellSelection );
943
944   SelectionIntoArgument();
945 }
946
947 //=================================================================================
948 // function : enterEvent()
949 // purpose  :
950 //=================================================================================
951 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
952 {
953   if (!ConstructorsBox->isEnabled())
954     ActivateThisDialog();
955 }
956
957 //=======================================================================
958 //function : onSelectMesh
959 //purpose  :
960 //=======================================================================
961 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
962 {
963   if (toSelectMesh)
964     TextLabelElements->setText(tr("SMESH_NAME"));
965   else
966     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
967   myFilterBtn->setEnabled(!toSelectMesh);
968
969   if (myEditCurrentArgument != LineEditElements) {
970     LineEditElements->clear();
971     return;
972   }
973
974   mySelectionMgr->clearFilters();
975   SMESH::SetPointRepresentation(false);
976
977   if (toSelectMesh) {
978     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
979       aViewWindow->SetSelectionMode( ActorSelection );
980     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
981     LineEditElements->setReadOnly(true);
982     LineEditElements->setValidator(0);
983   } else {
984     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
985       aViewWindow->SetSelectionMode( CellSelection );
986     LineEditElements->setReadOnly(false);
987     LineEditElements->setValidator(myIdValidator);
988     onTextChange(LineEditElements->text());
989     hidePreview();
990   }
991
992   SelectionIntoArgument();
993 }
994
995 //=======================================================================
996 //function : onActionClicked
997 //purpose  : slot called when an action type changed
998 //=======================================================================
999
1000 void SMESHGUI_TranslationDlg::onActionClicked(int button)
1001 {
1002   int aNbGroups = 0;
1003   for ( int i = 0; i < myMeshes.count(); i++ )
1004     aNbGroups += myMeshes[i]->NbGroups();
1005
1006   switch ( button ) {
1007   case MOVE_ELEMS_BUTTON:
1008     MakeGroupsCheck->setEnabled(false);
1009     LineEditNewMesh->setEnabled(false);
1010     break;
1011   case COPY_ELEMS_BUTTON:
1012     LineEditNewMesh->setEnabled(false);
1013     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1014     MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1015     break;
1016   case MAKE_MESH_BUTTON:
1017     LineEditNewMesh->setEnabled(true);
1018     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1019     MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1020     break;
1021   }
1022   setNewMeshName();
1023   toDisplaySimulation();
1024 }
1025
1026 //=======================================================================
1027 //function : setNewMeshName
1028 //purpose  : update contents of LineEditNewMesh
1029 //=======================================================================
1030
1031 void SMESHGUI_TranslationDlg::setNewMeshName()
1032 {
1033   LineEditNewMesh->setText("");
1034   if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1035     QString name;
1036     if ( CheckBoxMesh->isChecked() ) {
1037       name = myObjects.count() > 1 ? "*" : LineEditElements->text();
1038     }
1039     else {
1040       _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1041       name = meshSO->GetName().c_str();
1042     }
1043     if ( !name.isEmpty() )
1044       LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
1045   }
1046 }
1047
1048 //=================================================================================
1049 // function : GetConstructorId()
1050 // purpose  :
1051 //=================================================================================
1052 int SMESHGUI_TranslationDlg::GetConstructorId()
1053 {
1054   return GroupConstructors->checkedId();
1055 }
1056
1057 //=================================================================================
1058 // function : keyPressEvent()
1059 // purpose  :
1060 //=================================================================================
1061 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1062 {
1063   QDialog::keyPressEvent( e );
1064   if ( e->isAccepted() )
1065     return;
1066
1067   if ( e->key() == Qt::Key_F1 ) {
1068     e->accept();
1069     ClickOnHelp();
1070   }
1071 }
1072
1073 //=================================================================================
1074 // function : setFilters()
1075 // purpose  : SLOT. Called when "Filter" button pressed.
1076 //=================================================================================
1077 void SMESHGUI_TranslationDlg::setFilters()
1078 {
1079   if(myMeshes.isEmpty()) {
1080     SUIT_MessageBox::critical(this,
1081                               tr("SMESH_ERROR"),
1082                               tr("NO_MESH_SELECTED"));
1083    return;
1084   }
1085   if ( !myFilterDlg )
1086     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1087
1088   myFilterDlg->SetSelection();
1089   myFilterDlg->SetMesh( myMeshes[0] );
1090   myFilterDlg->SetSourceWg( LineEditElements );
1091
1092   myFilterDlg->show();
1093 }
1094
1095 //=================================================================================
1096 // function : isValid
1097 // purpose  :
1098 //=================================================================================
1099 bool SMESHGUI_TranslationDlg::isValid()
1100 {
1101   bool ok = true;
1102   QString msg;
1103
1104   ok = SpinBox1_1->isValid( msg, true ) && ok;
1105   ok = SpinBox1_2->isValid( msg, true ) && ok;
1106   ok = SpinBox1_3->isValid( msg, true ) && ok;
1107   if (GetConstructorId() == 0) {
1108     ok = SpinBox2_1->isValid( msg, true ) && ok;
1109     ok = SpinBox2_2->isValid( msg, true ) && ok;
1110     ok = SpinBox2_3->isValid( msg, true ) && ok;
1111   }
1112
1113   if( !ok ) {
1114     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1115     if ( !msg.isEmpty() )
1116       str += "\n" + msg;
1117     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1118     return false;
1119   }
1120   return true;
1121 }
1122
1123 //=================================================================================
1124 // function : onDisplaySimulation
1125 // purpose  : Show/Hide preview
1126 //=================================================================================
1127 void SMESHGUI_TranslationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1128   if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1129     
1130     if (isValid() && myNbOkElements) {
1131       QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1132       
1133       SMESH::long_array_var anElementsId = new SMESH::long_array;
1134
1135       anElementsId->length(aListElementsId.count());
1136       for (int i = 0; i < aListElementsId.count(); i++)
1137         anElementsId[i] = aListElementsId[i].toInt();
1138
1139       SMESH::DirStruct aVector;
1140       if (GetConstructorId() == 0) {
1141         aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
1142         aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
1143         aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
1144       } else if (GetConstructorId() == 1) {
1145         aVector.PS.x = SpinBox1_1->GetValue();
1146         aVector.PS.y = SpinBox1_2->GetValue();
1147         aVector.PS.z = SpinBox1_3->GetValue();
1148       }
1149
1150       try {
1151         bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1152                       ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1153         SUIT_OverrideCursor aWaitCursor;
1154         QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1155         if(CheckBoxMesh->isChecked())
1156           for ( int i = 0; i < myObjects.count(); i++ ) {
1157             SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1158             aMeshEditor->TranslateObject(myObjects[i], aVector, copy);
1159             aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1160           }
1161         else {
1162           SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1163           aMeshEditor->Translate(anElementsId, aVector, copy);
1164           aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1165         }
1166         setSimulationPreview( aMeshPreviewStruct );
1167       } catch (...) {
1168         
1169       }
1170     }
1171     else {
1172       hidePreview();
1173     }
1174   } else {
1175     hidePreview();
1176   }
1177 }