Salome HOME
74c5720df39e27bcd90b615da976d2539968665c
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_TranslationDlg.cxx
1 //  Copyright (C) 2007-2008  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 // SMESH SMESHGUI : GUI for SMESH component
23 // File   : SMESHGUI_TranslationDlg.cxx
24 // Author : Michael ZORIN, Open CASCADE S.A.S.
25 // SMESH includes
26 //
27 #include "SMESHGUI_TranslationDlg.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESHGUI_FilterDlg.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 //=================================================================================
105 // class    : SMESHGUI_TranslationDlg()
106 // purpose  :
107 //=================================================================================
108 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule )
109   : QDialog( SMESH::GetDesktop( theModule ) ),
110     SMESHGUI_Helper( theModule ),
111     mySMESHGUI( theModule ),
112     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
113     myFilterDlg(0),
114     mySelectedObject(SMESH::SMESH_IDSource::_nil())
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   myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
161   connect(myFilterBtn,   SIGNAL(clicked()), this, SLOT(setFilters()));
162
163   // Control for the whole mesh selection
164   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
165
166   // Controls for vector and points selection
167   TextLabel1 = new QLabel(GroupArguments);
168   SelectButton1 = new QPushButton(GroupArguments);
169   SelectButton1->setIcon(image2);
170
171   TextLabel1_1 = new QLabel(GroupArguments);
172   SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
173   TextLabel1_2 = new QLabel(GroupArguments);
174   SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
175   TextLabel1_3 = new QLabel(GroupArguments);
176   SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
177
178   TextLabel2 = new QLabel(tr("SMESH_POINT_2"), GroupArguments);
179   SelectButton2  = new QPushButton(GroupArguments);
180   SelectButton2->setIcon(image2);
181
182   TextLabel2_1 = new QLabel(tr("SMESH_X"), GroupArguments);
183   SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments);
184   TextLabel2_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
185   SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments);
186   TextLabel2_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
187   SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments);
188
189   // switch of action type
190   ActionBox = new QGroupBox(GroupArguments);
191   ActionGroup = new QButtonGroup(GroupArguments);
192   QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
193   ActionBoxLayout->addSpacing(SPACING);
194   ActionBoxLayout->setMargin(MARGIN);
195
196   QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
197   QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
198   QRadioButton* aCreateMesh   = new QRadioButton(tr("SMESH_CREATE_MESH"),   ActionBox);
199
200   ActionBoxLayout->addWidget(aMoveElements);
201   ActionBoxLayout->addWidget(aCopyElements);
202   ActionBoxLayout->addWidget(aCreateMesh);
203   ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
204   ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
205   ActionGroup->addButton(aCreateMesh,   MAKE_MESH_BUTTON);
206
207   // CheckBox for groups generation
208   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
209   MakeGroupsCheck->setChecked(false);
210
211   // Name of a mesh to create
212   LineEditNewMesh = new QLineEdit(GroupArguments);
213
214   // layout
215   GroupArgumentsLayout->addWidget(TextLabelElements,    0, 0);
216   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
217   GroupArgumentsLayout->addWidget(LineEditElements,     0, 2, 1, 5);
218   GroupArgumentsLayout->addWidget(myFilterBtn,          0, 7);
219   GroupArgumentsLayout->addWidget(CheckBoxMesh,         1, 0, 1, 8);
220   GroupArgumentsLayout->addWidget(TextLabel1,           2, 0);
221   GroupArgumentsLayout->addWidget(SelectButton1,        2, 1);
222   GroupArgumentsLayout->addWidget(TextLabel1_1,         2, 2);
223   GroupArgumentsLayout->addWidget(SpinBox1_1,           2, 3);
224   GroupArgumentsLayout->addWidget(TextLabel1_2,         2, 4);
225   GroupArgumentsLayout->addWidget(SpinBox1_2,           2, 5);
226   GroupArgumentsLayout->addWidget(TextLabel1_3,         2, 6);
227   GroupArgumentsLayout->addWidget(SpinBox1_3,           2, 7);
228   GroupArgumentsLayout->addWidget(TextLabel2,           3, 0);
229   GroupArgumentsLayout->addWidget(SelectButton2,        3, 1);
230   GroupArgumentsLayout->addWidget(TextLabel2_1,         3, 2);
231   GroupArgumentsLayout->addWidget(SpinBox2_1,           3, 3);
232   GroupArgumentsLayout->addWidget(TextLabel2_2,         3, 4);
233   GroupArgumentsLayout->addWidget(SpinBox2_2,           3, 5);
234   GroupArgumentsLayout->addWidget(TextLabel2_3,         3, 6);
235   GroupArgumentsLayout->addWidget(SpinBox2_3,           3, 7);
236   GroupArgumentsLayout->addWidget(ActionBox,            4, 0, 3, 4);
237   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      5, 5, 1, 4);
238   GroupArgumentsLayout->addWidget(LineEditNewMesh,      6, 5, 1, 4);
239
240   /***************************************************************/
241   GroupButtons = new QGroupBox(this);
242   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
243   GroupButtonsLayout->setSpacing(SPACING);
244   GroupButtonsLayout->setMargin(MARGIN);
245
246   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
247   buttonOk->setAutoDefault(true);
248   buttonOk->setDefault(true);
249   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
250   buttonApply->setAutoDefault(true);
251   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
252   buttonCancel->setAutoDefault(true);
253   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
254   buttonHelp->setAutoDefault(true);
255
256   GroupButtonsLayout->addWidget(buttonOk);
257   GroupButtonsLayout->addSpacing(10);
258   GroupButtonsLayout->addWidget(buttonApply);
259   GroupButtonsLayout->addSpacing(10);
260   GroupButtonsLayout->addStretch();
261   GroupButtonsLayout->addWidget(buttonCancel);
262   GroupButtonsLayout->addWidget(buttonHelp);
263
264   /***************************************************************/
265   SMESHGUI_TranslationDlgLayout->addWidget(ConstructorsBox);
266   SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments);
267   SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons);
268
269   /* Initialisations */
270   SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
271   SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
272   SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
273   SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
274   SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
275   SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
276
277   RadioButton1->setChecked(true);
278
279   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
280
281   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
282
283   // Costruction of the logical filter
284   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
285   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
286
287   QList<SUIT_SelectionFilter*> aListOfFilters;
288   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
289   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
290
291   myMeshOrSubMeshOrGroupFilter =
292     new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
293
294   myHelpFileName = "translation_page.html";
295
296   Init();
297
298   /* signals and slots connections */
299   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
300   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
301   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
302   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
303   connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
304
305   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
306   connect(SelectButton1,        SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
307   connect(SelectButton2,        SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
308
309   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
310   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),   this, SLOT(SelectionIntoArgument()));
311   /* to close dialog if study change */
312   connect(mySMESHGUI,       SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
313   connect(LineEditElements, SIGNAL(textChanged(const QString&)),    SLOT(onTextChange(const QString&)));
314   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                  SLOT(onSelectMesh(bool)));
315   connect(ActionGroup,      SIGNAL(buttonClicked(int)),             SLOT(onActionClicked(int)));
316
317   ConstructorsClicked(0);
318   SelectionIntoArgument();
319   onActionClicked(MOVE_ELEMS_BUTTON);
320 }
321
322 //=================================================================================
323 // function : ~SMESHGUI_TranslationDlg()
324 // purpose  : Destroys the object and frees any allocated resources
325 //=================================================================================
326 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
327 {
328   if ( myFilterDlg ) {
329     myFilterDlg->setParent( 0 );
330     delete myFilterDlg;
331     myFilterDlg = 0;
332   }
333 }
334
335 //=================================================================================
336 // function : Init()
337 // purpose  :
338 //=================================================================================
339 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
340 {
341   myBusy = false;
342
343   myEditCurrentArgument = 0;
344   LineEditElements->clear();
345   myElementsId = "";
346   myNbOkElements = 0;
347
348   buttonOk->setEnabled(false);
349   buttonApply->setEnabled(false);
350
351   myActor = 0;
352   myMesh = SMESH::SMESH_Mesh::_nil();
353
354   if (ResetControls) {
355     SpinBox1_1->SetValue(0.0);
356     SpinBox1_2->SetValue(0.0);
357     SpinBox1_3->SetValue(0.0);
358     SpinBox2_1->SetValue(0.0);
359     SpinBox2_2->SetValue(0.0);
360     SpinBox2_3->SetValue(0.0);
361
362     ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
363     CheckBoxMesh->setChecked(false);
364 //     MakeGroupsCheck->setChecked(false);
365 //     MakeGroupsCheck->setEnabled(false);
366     onSelectMesh(false);
367   }
368 }
369
370 //=================================================================================
371 // function : ConstructorsClicked()
372 // purpose  : Radio button management
373 //=================================================================================
374 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
375 {
376   disconnect(mySelectionMgr, 0, this, 0);
377
378   switch (constructorId) {
379   case 0:
380     {
381       TextLabel1->setText(tr("SMESH_POINT_1"));
382       TextLabel1_1->setText(tr("SMESH_X"));
383       TextLabel1_2->setText(tr("SMESH_Y"));
384       TextLabel1_3->setText(tr("SMESH_Z"));
385
386       SelectButton1->show();
387       TextLabel2->show();
388       SelectButton2->show();
389       TextLabel2_1->show();
390       SpinBox2_1->show();
391       TextLabel2_2->show();
392       SpinBox2_2->show();
393       TextLabel2_3->show();
394       SpinBox2_3->show();
395       break;
396     }
397   case 1:
398     {
399       TextLabel1->setText(tr("SMESH_VECTOR"));
400       TextLabel1_1->setText(tr("SMESH_DX"));
401       TextLabel1_2->setText(tr("SMESH_DY"));
402       TextLabel1_3->setText(tr("SMESH_DZ"));
403
404       SelectButton1->hide();
405       TextLabel2->hide();
406       SelectButton2->hide();
407       TextLabel2_1->hide();
408       SpinBox2_1->hide();
409       TextLabel2_2->hide();
410       SpinBox2_2->hide();
411       TextLabel2_3->hide();
412       SpinBox2_3->hide();
413       break;
414     }
415   }
416
417   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
418     SMESH::SetPointRepresentation(false);
419     if (!CheckBoxMesh->isChecked())
420       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
421         aViewWindow->SetSelectionMode( CellSelection );
422   }
423
424   myEditCurrentArgument = (QWidget*)LineEditElements;
425   LineEditElements->setFocus();
426
427   if (CheckBoxMesh->isChecked())
428     onSelectMesh(true);
429
430   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
431
432   QApplication::instance()->processEvents();
433   updateGeometry();
434   resize(100,100);
435 }
436
437 //=================================================================================
438 // function : ClickOnApply()
439 // purpose  :
440 //=================================================================================
441 bool SMESHGUI_TranslationDlg::ClickOnApply()
442 {
443   if (mySMESHGUI->isActiveStudyLocked())
444     return false;
445
446   if( !isValid() )
447     return false;
448
449   if (myNbOkElements) {
450     QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
451
452     SMESH::long_array_var anElementsId = new SMESH::long_array;
453
454     anElementsId->length(aListElementsId.count());
455     for (int i = 0; i < aListElementsId.count(); i++)
456       anElementsId[i] = aListElementsId[i].toInt();
457
458     SMESH::DirStruct aVector;
459     if (GetConstructorId() == 0) {
460       aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
461       aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
462       aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
463     } else if (GetConstructorId() == 1) {
464       aVector.PS.x = SpinBox1_1->GetValue();
465       aVector.PS.y = SpinBox1_2->GetValue();
466       aVector.PS.z = SpinBox1_3->GetValue();
467     }
468
469     QStringList aParameters;
470     aParameters << SpinBox1_1->text();
471     if (GetConstructorId() == 0)
472       aParameters << SpinBox2_1->text();
473     aParameters << SpinBox1_2->text();
474     if (GetConstructorId() == 0)
475       aParameters << SpinBox2_2->text();
476     aParameters << SpinBox1_3->text();
477     if (GetConstructorId() == 0)
478       aParameters << SpinBox2_3->text();
479
480     int actionButton = ActionGroup->checkedId();
481     bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
482     try {
483       SUIT_OverrideCursor aWaitCursor;
484       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
485       switch ( actionButton ) {
486       case MOVE_ELEMS_BUTTON:
487         if(CheckBoxMesh->isChecked())
488           aMeshEditor->TranslateObject(mySelectedObject, aVector, false);
489         else
490           aMeshEditor->Translate(anElementsId, aVector, false);
491         //asl: if( !myMesh->_is_nil())
492           //asl: myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
493         break;
494       case COPY_ELEMS_BUTTON:
495         if ( makeGroups ) {
496           SMESH::ListOfGroups_var groups; 
497           if(CheckBoxMesh->isChecked())
498             groups = aMeshEditor->TranslateObjectMakeGroups(mySelectedObject,aVector);
499           else
500             groups = aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
501         }
502         else {
503           if(CheckBoxMesh->isChecked())
504             aMeshEditor->TranslateObject(mySelectedObject, aVector, true);
505           else
506             aMeshEditor->Translate(anElementsId, aVector, true);
507         }
508         //asl: if( !myMesh->_is_nil())
509           //asl: myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
510         break;
511       case MAKE_MESH_BUTTON:
512         SMESH::SMESH_Mesh_var mesh; 
513         if(CheckBoxMesh->isChecked())
514           mesh = aMeshEditor->TranslateObjectMakeMesh(mySelectedObject, aVector, makeGroups,
515                                                       LineEditNewMesh->text().toLatin1().data());
516         else
517           mesh = aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
518                                                 LineEditNewMesh->text().toLatin1().data());
519         //asl: if( !mesh->_is_nil())
520           //asl: mesh->SetParameters( aParameters.join(":").toLatin1().constData() );
521       }
522     } catch (...) {
523     }
524     
525     SMESH::UpdateView();
526     if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
527          actionButton == MAKE_MESH_BUTTON )
528       mySMESHGUI->updateObjBrowser(true); // new groups may appear
529     Init(false);
530     ConstructorsClicked(GetConstructorId());
531     mySelectedObject = SMESH::SMESH_IDSource::_nil();
532     SelectionIntoArgument();
533   }
534   
535   return true;
536 }
537
538 //=================================================================================
539 // function : ClickOnOk()
540 // purpose  :
541 //=================================================================================
542 void SMESHGUI_TranslationDlg::ClickOnOk()
543 {
544   if( ClickOnApply() )
545     ClickOnCancel();
546 }
547
548 //=================================================================================
549 // function : ClickOnCancel()
550 // purpose  :
551 //=================================================================================
552 void SMESHGUI_TranslationDlg::ClickOnCancel()
553 {
554   disconnect(mySelectionMgr, 0, this, 0);
555   mySelectionMgr->clearFilters();
556   //mySelectionMgr->clearSelected();
557   if (SMESH::GetCurrentVtkView()) {
558     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
559     SMESH::SetPointRepresentation(false);
560   }
561   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
562     aViewWindow->SetSelectionMode( ActorSelection );
563   mySMESHGUI->ResetState();
564   reject();
565 }
566
567 //=================================================================================
568 // function : ClickOnHelp()
569 // purpose  :
570 //=================================================================================
571 void SMESHGUI_TranslationDlg::ClickOnHelp()
572 {
573   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
574   if (app) 
575     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
576   else {
577     QString platform;
578 #ifdef WIN32
579     platform = "winapplication";
580 #else
581     platform = "application";
582 #endif
583     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
584                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
585                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
586                                                                  platform)).
587                              arg(myHelpFileName));
588   }
589 }
590
591 //=======================================================================
592 // function : onTextChange()
593 // purpose  :
594 //=======================================================================
595 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
596 {
597   QLineEdit* send = (QLineEdit*)sender();
598
599   if (myBusy) return;
600   BusyLocker lock( myBusy );
601
602   if (send == LineEditElements)
603     myNbOkElements = 0;
604
605   buttonOk->setEnabled(false);
606   buttonApply->setEnabled(false);
607
608   // hilight entered elements
609   SMDS_Mesh* aMesh = 0;
610   if (myActor)
611     aMesh = myActor->GetObject()->GetMesh();
612
613   if (aMesh) {
614     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
615     
616     TColStd_MapOfInteger newIndices;
617
618     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
619
620     if (send == LineEditElements) {
621       for (int i = 0; i < aListId.count(); i++) {
622         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
623         if (e)
624           newIndices.Add(e->GetID());
625         myNbOkElements++;
626       }
627     }
628
629     mySelector->AddOrRemoveIndex( anIO, newIndices, false );
630     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
631       aViewWindow->highlight( anIO, true, true );
632     
633     myElementsId = theNewText;
634   }
635
636   if (myNbOkElements) {
637     buttonOk->setEnabled(true);
638     buttonApply->setEnabled(true);
639   }
640 }
641
642 //=================================================================================
643 // function : SelectionIntoArgument()
644 // purpose  : Called when selection as changed or other case
645 //=================================================================================
646 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
647 {
648   if (myBusy) return;
649   BusyLocker lock( myBusy );
650   // clear
651   myActor = 0;
652   QString aString = "";
653
654   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
655     LineEditElements->setText(aString);
656     myNbOkElements = 0;
657     buttonOk->setEnabled(false);
658     buttonApply->setEnabled(false);
659   }
660
661   if (!GroupButtons->isEnabled()) // inactive
662     return;
663
664   // get selected mesh
665   SALOME_ListIO aList;
666   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
667
668   int nbSel = aList.Extent();
669   if (nbSel != 1)
670     return;
671
672   Handle(SALOME_InteractiveObject) IO = aList.First();
673   myMesh = SMESH::GetMeshByIO(IO);
674   if (myMesh->_is_nil())
675     return;
676
677   myActor = SMESH::FindActorByObject(myMesh);
678   if (!myActor)
679     myActor = SMESH::FindActorByEntry(IO->getEntry());
680   if (!myActor)
681     return;
682
683   int aNbUnits = 0;
684
685   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
686     myElementsId = "";
687
688     // MakeGroups is available if there are groups and "Copy"
689     if ( myMesh->NbGroups() == 0 ) {
690       MakeGroupsCheck->setChecked(false);
691       MakeGroupsCheck->setEnabled(false);
692     }
693     else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
694       MakeGroupsCheck->setEnabled(true);
695     }
696
697     if (CheckBoxMesh->isChecked()) {
698       SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
699
700       if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
701         mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
702       }
703       else
704         return;
705         // get IDs from mesh
706         /*
707         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
708         if (!aSMDSMesh)
709           return;
710
711         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
712           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
713           if (e) {
714             myElementsId += QString(" %1").arg(i);
715             aNbUnits++;
716           }
717         }
718       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
719         // get submesh
720         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
721
722         // get IDs from submesh
723         SMESH::long_array_var anElementsIds = new SMESH::long_array;
724         anElementsIds = aSubMesh->GetElementsId();
725         for (int i = 0; i < anElementsIds->length(); i++) {
726           myElementsId += QString(" %1").arg(anElementsIds[i]);
727         }
728         aNbUnits = anElementsIds->length();
729       } else { // GROUP
730         // get smesh group
731         SMESH::SMESH_GroupBase_var aGroup =
732           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
733         if (aGroup->_is_nil())
734           return;
735
736         // get IDs from smesh group
737         SMESH::long_array_var anElementsIds = new SMESH::long_array;
738         anElementsIds = aGroup->GetListOfID();
739         for (int i = 0; i < anElementsIds->length(); i++) {
740           myElementsId += QString(" %1").arg(anElementsIds[i]);
741         }
742         aNbUnits = anElementsIds->length();
743       }
744         */
745     } else {
746       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
747       myElementsId = aString;
748       if (aNbUnits < 1)
749         return;  
750     }
751
752     myNbOkElements = true;
753   } else {
754     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
755     if (aNbUnits != 1)
756       return;
757
758     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
759     if (!aMesh)
760       return;
761
762     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
763     if (!n)
764       return;
765
766     double x = n->X();
767     double y = n->Y();
768     double z = n->Z();
769
770     if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
771       SpinBox1_1->SetValue(x);
772       SpinBox1_2->SetValue(y);
773       SpinBox1_3->SetValue(z);
774     } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
775       SpinBox2_1->SetValue(x);
776       SpinBox2_2->SetValue(y);
777       SpinBox2_3->SetValue(z);
778     }
779   }
780
781   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
782     LineEditElements->setText(aString);
783     LineEditElements->repaint();
784     LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
785     LineEditElements->setEnabled(true); 
786     setNewMeshName();
787   }
788
789   // OK
790   if (myNbOkElements) {
791     buttonOk->setEnabled(true);
792     buttonApply->setEnabled(true);
793   }
794 }
795
796 //=================================================================================
797 // function : SetEditCurrentArgument()
798 // purpose  :
799 //=================================================================================
800 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
801 {
802   QPushButton* send = (QPushButton*)sender();
803
804   disconnect(mySelectionMgr, 0, this, 0);
805   mySelectionMgr->clearSelected();
806   mySelectionMgr->clearFilters();
807
808   if (send == SelectElementsButton) {
809     myEditCurrentArgument = (QWidget*)LineEditElements;
810     SMESH::SetPointRepresentation(false);
811     if (CheckBoxMesh->isChecked()) {
812       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
813         aViewWindow->SetSelectionMode( ActorSelection );
814       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
815     } else {
816
817       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
818         aViewWindow->SetSelectionMode( CellSelection );
819     }
820   } else if (send == SelectButton1) {
821     myEditCurrentArgument = (QWidget*)SpinBox1_1;
822     SMESH::SetPointRepresentation(true);
823
824     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
825       aViewWindow->SetSelectionMode( NodeSelection );
826   } else if (send == SelectButton2) {
827     myEditCurrentArgument = (QWidget*)SpinBox2_1;
828     SMESH::SetPointRepresentation(true);
829
830     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
831       aViewWindow->SetSelectionMode( NodeSelection );
832   }
833
834   myEditCurrentArgument->setFocus();
835   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
836   SelectionIntoArgument();
837 }
838
839 //=================================================================================
840 // function : DeactivateActiveDialog()
841 // purpose  :
842 //=================================================================================
843 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
844 {
845   if (ConstructorsBox->isEnabled()) {
846     ConstructorsBox->setEnabled(false);
847     GroupArguments->setEnabled(false);
848     GroupButtons->setEnabled(false);
849     mySMESHGUI->ResetState();
850     mySMESHGUI->SetActiveDialogBox(0);
851   }
852 }
853
854 //=================================================================================
855 // function : ActivateThisDialog()
856 // purpose  :
857 //=================================================================================
858 void SMESHGUI_TranslationDlg::ActivateThisDialog()
859 {
860   /* Emit a signal to deactivate the active dialog */
861   mySMESHGUI->EmitSignalDeactivateDialog();
862   ConstructorsBox->setEnabled(true);
863   GroupArguments->setEnabled(true);
864   GroupButtons->setEnabled(true);
865
866   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
867
868   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
869     aViewWindow->SetSelectionMode( CellSelection );
870
871   SelectionIntoArgument();
872 }
873
874 //=================================================================================
875 // function : enterEvent()
876 // purpose  :
877 //=================================================================================
878 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
879 {
880   if (!ConstructorsBox->isEnabled())
881     ActivateThisDialog();
882 }
883
884 //=================================================================================
885 // function : closeEvent()
886 // purpose  :
887 //=================================================================================
888 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
889 {
890   /* same than click on cancel button */
891   ClickOnCancel();
892 }
893
894 //=======================================================================
895 //function : hideEvent
896 //purpose  : caused by ESC key
897 //=======================================================================
898 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
899 {
900   if (!isMinimized())
901     ClickOnCancel();
902 }
903
904 //=======================================================================
905 //function : onSelectMesh
906 //purpose  :
907 //=======================================================================
908 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
909 {
910   if (toSelectMesh)
911     TextLabelElements->setText(tr("SMESH_NAME"));
912   else
913     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
914   myFilterBtn->setEnabled(!toSelectMesh);
915
916   if (myEditCurrentArgument != LineEditElements) {
917     LineEditElements->clear();
918     return;
919   }
920
921   mySelectionMgr->clearFilters();
922   SMESH::SetPointRepresentation(false);
923
924   if (toSelectMesh) {
925     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
926       aViewWindow->SetSelectionMode( ActorSelection );
927     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
928     LineEditElements->setReadOnly(true);
929     LineEditElements->setValidator(0);
930   } else {
931     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
932       aViewWindow->SetSelectionMode( CellSelection );
933     LineEditElements->setReadOnly(false);
934     LineEditElements->setValidator(myIdValidator);
935     onTextChange(LineEditElements->text());
936   }
937
938   SelectionIntoArgument();
939 }
940
941 //=======================================================================
942 //function : onActionClicked
943 //purpose  : slot called when an action type changed
944 //=======================================================================
945
946 void SMESHGUI_TranslationDlg::onActionClicked(int button)
947 {
948   switch ( button ) {
949   case MOVE_ELEMS_BUTTON:
950     MakeGroupsCheck->setEnabled(false);
951     LineEditNewMesh->setEnabled(false);
952     break;
953   case COPY_ELEMS_BUTTON:
954     LineEditNewMesh->setEnabled(false);
955     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
956     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
957       MakeGroupsCheck->setEnabled(true);
958     else
959       MakeGroupsCheck->setEnabled(false);
960     break;
961   case MAKE_MESH_BUTTON:
962     LineEditNewMesh->setEnabled(true);
963     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
964     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
965       MakeGroupsCheck->setEnabled(true);
966     else
967       MakeGroupsCheck->setEnabled(false);
968     break;
969   }
970   setNewMeshName();
971 }
972
973 //=======================================================================
974 //function : setNewMeshName
975 //purpose  : update contents of LineEditNewMesh
976 //=======================================================================
977
978 void SMESHGUI_TranslationDlg::setNewMeshName()
979 {
980   LineEditNewMesh->setText("");
981   if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
982     QString name;
983     if ( CheckBoxMesh->isChecked() ) {
984       name = LineEditElements->text();
985     }
986     else {
987       _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
988       name = meshSO->GetName().c_str();
989     }
990     if ( !name.isEmpty() )
991       LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
992   }
993 }
994
995 //=================================================================================
996 // function : GetConstructorId()
997 // purpose  :
998 //=================================================================================
999 int SMESHGUI_TranslationDlg::GetConstructorId()
1000 {
1001   return GroupConstructors->checkedId();
1002 }
1003
1004 //=================================================================================
1005 // function : keyPressEvent()
1006 // purpose  :
1007 //=================================================================================
1008 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1009 {
1010   QDialog::keyPressEvent( e );
1011   if ( e->isAccepted() )
1012     return;
1013
1014   if ( e->key() == Qt::Key_F1 ) {
1015     e->accept();
1016     ClickOnHelp();
1017   }
1018 }
1019
1020 //=================================================================================
1021 // function : setFilters()
1022 // purpose  : SLOT. Called when "Filter" button pressed.
1023 //=================================================================================
1024 void SMESHGUI_TranslationDlg::setFilters()
1025 {
1026   if(myMesh->_is_nil()) {
1027     SUIT_MessageBox::critical(this,
1028                               tr("SMESH_ERROR"),
1029                               tr("NO_MESH_SELECTED"));
1030    return;
1031   }
1032   if ( !myFilterDlg )
1033     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1034
1035   myFilterDlg->SetSelection();
1036   myFilterDlg->SetMesh( myMesh );
1037   myFilterDlg->SetSourceWg( LineEditElements );
1038
1039   myFilterDlg->show();
1040 }
1041
1042 //=================================================================================
1043 // function : isValid
1044 // purpose  :
1045 //=================================================================================
1046 bool SMESHGUI_TranslationDlg::isValid()
1047 {
1048   QList<QAbstractSpinBox*> aSpinBoxList;
1049   aSpinBoxList << SpinBox1_1 << SpinBox1_2 << SpinBox1_3;
1050   if( GetConstructorId() == 0 )
1051     aSpinBoxList << SpinBox2_1 << SpinBox2_2 << SpinBox2_3;
1052   return checkParameters( true, aSpinBoxList );
1053 }