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