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