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