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