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