Salome HOME
Porting SMESH module to Qt 4
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_TranslationDlg.cxx
1 // SMESH SMESHGUI : GUI for SMESH component
2 //
3 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 //
6 // This library is free software; you can redistribute it and/or 
7 // modify it under the terms of the GNU Lesser General Public 
8 // License as published by the Free Software Foundation; either 
9 // version 2.1 of the License. 
10 //
11 // This library is distributed in the hope that it will be useful, 
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 // Lesser General Public License for more details. 
15 //
16 // You should have received a copy of the GNU Lesser General Public 
17 // License along with this library; if not, write to the Free Software 
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : SMESHGUI_TranslationDlg.cxx
23 // Author : Michael ZORIN, Open CASCADE S.A.S.
24 //
25
26 // SMESH includes
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
36 #include <SMESH_Actor.h>
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_LogicalFilter.hxx>
39 #include <SMDS_Mesh.hxx>
40
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46
47 #include <LightApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
49
50 #include <SVTK_ViewModel.h>
51 #include <SVTK_ViewWindow.h>
52 #include <SALOME_ListIO.hxx>
53
54 // SALOME KERNEL includes
55 #include <SALOMEDSClient_SObject.hxx>
56
57 // OCCT includes
58 #include <TColStd_MapOfInteger.hxx>
59
60 // Qt includes
61 #include <QApplication>
62 #include <QButtonGroup>
63 #include <QGroupBox>
64 #include <QLabel>
65 #include <QLineEdit>
66 #include <QPushButton>
67 #include <QRadioButton>
68 #include <QCheckBox>
69 #include <QHBoxLayout>
70 #include <QVBoxLayout>
71 #include <QGridLayout>
72 #include <QSpinBox>
73 #include <QKeyEvent>
74
75 // IDL includes
76 #include <SALOMEconfig.h>
77 #include CORBA_SERVER_HEADER(SMESH_Group)
78 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
79
80 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
81
82 #define SPACING 6
83 #define MARGIN  11
84
85 //=================================================================================
86 // class    : SMESHGUI_TranslationDlg()
87 // purpose  :
88 //=================================================================================
89 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule )
90   : QDialog( SMESH::GetDesktop( theModule ) ),
91     mySMESHGUI( theModule ),
92     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
93 {
94   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
95   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
96   QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
97
98   setModal(false);
99   setAttribute(Qt::WA_DeleteOnClose, true);
100   setWindowTitle(tr("SMESH_TRANSLATION"));
101   setSizeGripEnabled(true);
102
103   QVBoxLayout* SMESHGUI_TranslationDlgLayout = new QVBoxLayout(this);
104   SMESHGUI_TranslationDlgLayout->setSpacing(SPACING);
105   SMESHGUI_TranslationDlgLayout->setMargin(MARGIN);
106
107   /***************************************************************/
108   ConstructorsBox = new QGroupBox(tr("SMESH_TRANSLATION"), this);
109   GroupConstructors = new QButtonGroup(this);
110   QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
111   ConstructorsBoxLayout->setSpacing(SPACING);
112   ConstructorsBoxLayout->setMargin(MARGIN);
113
114   RadioButton1= new QRadioButton(ConstructorsBox);
115   RadioButton1->setIcon(image0);
116   RadioButton2= new QRadioButton(ConstructorsBox);
117   RadioButton2->setIcon(image1);
118
119   ConstructorsBoxLayout->addWidget(RadioButton1);
120   ConstructorsBoxLayout->addWidget(RadioButton2);
121   GroupConstructors->addButton(RadioButton1, 0);
122   GroupConstructors->addButton(RadioButton2, 1);
123
124   /***************************************************************/
125   GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
126   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
127   GroupArgumentsLayout->setSpacing(SPACING);
128   GroupArgumentsLayout->setMargin(MARGIN);
129
130   // Controls for elements selection
131   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
132   SelectElementsButton = new QPushButton(GroupArguments);
133   SelectElementsButton->setIcon(image2);
134   LineEditElements = new QLineEdit(GroupArguments);
135   LineEditElements->setValidator(new SMESHGUI_IdValidator(this));
136
137   // Control for the whole mesh selection
138   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
139
140   // Controls for vector and points selection
141   TextLabel1 = new QLabel(GroupArguments);
142   SelectButton1 = new QPushButton(GroupArguments);
143   SelectButton1->setIcon(image2);
144
145   TextLabel1_1 = new QLabel(GroupArguments);
146   SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
147   TextLabel1_2 = new QLabel(GroupArguments);
148   SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
149   TextLabel1_3 = new QLabel(GroupArguments);
150   SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
151
152   TextLabel2 = new QLabel(tr("SMESH_POINT_2"), GroupArguments);
153   SelectButton2  = new QPushButton(GroupArguments);
154   SelectButton2->setIcon(image2);
155
156   TextLabel2_1 = new QLabel(tr("SMESH_X"), GroupArguments);
157   SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments);
158   TextLabel2_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
159   SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments);
160   TextLabel2_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
161   SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments);
162
163   // switch of action type
164   ActionBox = new QGroupBox(tr("ACTION"), GroupArguments);
165   ActionGroup = new QButtonGroup(GroupArguments);
166   QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
167   ActionBoxLayout->addSpacing(SPACING);
168   ActionBoxLayout->setMargin(MARGIN);
169
170   QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
171   QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
172   QRadioButton* aCreateMesh   = new QRadioButton(tr("SMESH_CREATE_MESH"),   ActionBox);
173
174   ActionBoxLayout->addWidget(aMoveElements);
175   ActionBoxLayout->addWidget(aCopyElements);
176   ActionBoxLayout->addWidget(aCreateMesh);
177   ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
178   ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
179   ActionGroup->addButton(aCreateMesh,   MAKE_MESH_BUTTON);
180
181   // CheckBox for groups generation
182   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
183   MakeGroupsCheck->setChecked(false);
184
185   // Name of a mesh to create
186   LineEditNewMesh = new QLineEdit(GroupArguments);
187
188   // layout
189   GroupArgumentsLayout->addWidget(TextLabelElements,    0, 0);
190   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
191   GroupArgumentsLayout->addWidget(LineEditElements,     0, 2, 1, 6);
192   GroupArgumentsLayout->addWidget(CheckBoxMesh,         1, 0, 1, 8);
193   GroupArgumentsLayout->addWidget(TextLabel1,           2, 0);
194   GroupArgumentsLayout->addWidget(SelectButton1,        2, 1);
195   GroupArgumentsLayout->addWidget(TextLabel1_1,         2, 2);
196   GroupArgumentsLayout->addWidget(SpinBox1_1,           2, 3);
197   GroupArgumentsLayout->addWidget(TextLabel1_2,         2, 4);
198   GroupArgumentsLayout->addWidget(SpinBox1_2,           2, 5);
199   GroupArgumentsLayout->addWidget(TextLabel1_3,         2, 6);
200   GroupArgumentsLayout->addWidget(SpinBox1_3,           2, 7);
201   GroupArgumentsLayout->addWidget(TextLabel2,           3, 0);
202   GroupArgumentsLayout->addWidget(SelectButton2,        3, 1);
203   GroupArgumentsLayout->addWidget(TextLabel2_1,         3, 2);
204   GroupArgumentsLayout->addWidget(SpinBox2_1,           3, 3);
205   GroupArgumentsLayout->addWidget(TextLabel2_2,         3, 4);
206   GroupArgumentsLayout->addWidget(SpinBox2_2,           3, 5);
207   GroupArgumentsLayout->addWidget(TextLabel2_3,         3, 6);
208   GroupArgumentsLayout->addWidget(SpinBox2_3,           3, 7);
209   GroupArgumentsLayout->addWidget(ActionBox,            4, 0, 3, 4);
210   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      5, 5, 1, 4);
211   GroupArgumentsLayout->addWidget(LineEditNewMesh,      6, 5, 1, 4);
212
213   /***************************************************************/
214   GroupButtons = new QGroupBox(this);
215   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
216   GroupButtonsLayout->setSpacing(SPACING);
217   GroupButtonsLayout->setMargin(MARGIN);
218
219   buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
220   buttonOk->setAutoDefault(true);
221   buttonOk->setDefault(true);
222   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
223   buttonApply->setAutoDefault(true);
224   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
225   buttonCancel->setAutoDefault(true);
226   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
227   buttonHelp->setAutoDefault(true);
228
229   GroupButtonsLayout->addWidget(buttonOk);
230   GroupButtonsLayout->addSpacing(10);
231   GroupButtonsLayout->addWidget(buttonApply);
232   GroupButtonsLayout->addSpacing(10);
233   GroupButtonsLayout->addStretch();
234   GroupButtonsLayout->addWidget(buttonCancel);
235   GroupButtonsLayout->addWidget(buttonHelp);
236
237   /***************************************************************/
238   SMESHGUI_TranslationDlgLayout->addWidget(ConstructorsBox);
239   SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments);
240   SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons);
241
242   /* Initialisations */
243   SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
244   SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
245   SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
246   SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
247   SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
248   SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
249
250   RadioButton1->setChecked(true);
251
252   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
253
254   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
255
256   // Costruction of the logical filter
257   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
258   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
259
260   QList<SUIT_SelectionFilter*> aListOfFilters;
261   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
262   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
263
264   myMeshOrSubMeshOrGroupFilter =
265     new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
266
267   myHelpFileName = "translation_page.html";
268
269   Init();
270
271   /* signals and slots connections */
272   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
273   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
274   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
275   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
276   connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
277
278   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
279   connect(SelectButton1,        SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
280   connect(SelectButton2,        SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
281
282   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
283   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),   this, SLOT(SelectionIntoArgument()));
284   /* to close dialog if study change */
285   connect(mySMESHGUI,       SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
286   connect(LineEditElements, SIGNAL(textChanged(const QString&)),    SLOT(onTextChange(const QString&)));
287   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                  SLOT(onSelectMesh(bool)));
288   connect(ActionGroup,      SIGNAL(buttonClicked(int)),             SLOT(onActionClicked(int)));
289
290   ConstructorsClicked(0);
291   SelectionIntoArgument();
292   onActionClicked(MOVE_ELEMS_BUTTON);
293 }
294
295 //=================================================================================
296 // function : ~SMESHGUI_TranslationDlg()
297 // purpose  : Destroys the object and frees any allocated resources
298 //=================================================================================
299 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
300 {
301 }
302
303 //=================================================================================
304 // function : Init()
305 // purpose  :
306 //=================================================================================
307 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
308 {
309   myBusy = false;
310
311   myEditCurrentArgument = 0;
312   LineEditElements->clear();
313   myElementsId = "";
314   myNbOkElements = 0;
315
316   buttonOk->setEnabled(false);
317   buttonApply->setEnabled(false);
318
319   myActor = 0;
320   myMesh = SMESH::SMESH_Mesh::_nil();
321
322   if (ResetControls) {
323     SpinBox1_1->SetValue(0.0);
324     SpinBox1_2->SetValue(0.0);
325     SpinBox1_3->SetValue(0.0);
326     SpinBox2_1->SetValue(0.0);
327     SpinBox2_2->SetValue(0.0);
328     SpinBox2_3->SetValue(0.0);
329
330     ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
331     CheckBoxMesh->setChecked(false);
332 //     MakeGroupsCheck->setChecked(false);
333 //     MakeGroupsCheck->setEnabled(false);
334     onSelectMesh(false);
335   }
336 }
337
338 //=================================================================================
339 // function : ConstructorsClicked()
340 // purpose  : Radio button management
341 //=================================================================================
342 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
343 {
344   disconnect(mySelectionMgr, 0, this, 0);
345
346   switch (constructorId) {
347   case 0:
348     {
349       TextLabel1->setText(tr("SMESH_POINT_1"));
350       TextLabel1_1->setText(tr("SMESH_X"));
351       TextLabel1_2->setText(tr("SMESH_Y"));
352       TextLabel1_3->setText(tr("SMESH_Z"));
353
354       SelectButton1->show();
355       TextLabel2->show();
356       SelectButton2->show();
357       TextLabel2_1->show();
358       SpinBox2_1->show();
359       TextLabel2_2->show();
360       SpinBox2_2->show();
361       TextLabel2_3->show();
362       SpinBox2_3->show();
363       break;
364     }
365   case 1:
366     {
367       TextLabel1->setText(tr("SMESH_VECTOR"));
368       TextLabel1_1->setText(tr("SMESH_DX"));
369       TextLabel1_2->setText(tr("SMESH_DY"));
370       TextLabel1_3->setText(tr("SMESH_DZ"));
371
372       SelectButton1->hide();
373       TextLabel2->hide();
374       SelectButton2->hide();
375       TextLabel2_1->hide();
376       SpinBox2_1->hide();
377       TextLabel2_2->hide();
378       SpinBox2_2->hide();
379       TextLabel2_3->hide();
380       SpinBox2_3->hide();
381       break;
382     }
383   }
384
385   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
386     SMESH::SetPointRepresentation(false);
387     if (!CheckBoxMesh->isChecked())
388       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
389         aViewWindow->SetSelectionMode( CellSelection );
390   }
391
392   myEditCurrentArgument = (QWidget*)LineEditElements;
393   LineEditElements->setFocus();
394
395   if (CheckBoxMesh->isChecked())
396     onSelectMesh(true);
397
398   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
399
400   QApplication::instance()->processEvents();
401   updateGeometry();
402   resize( minimumSize() );
403 }
404
405 //=================================================================================
406 // function : ClickOnApply()
407 // purpose  :
408 //=================================================================================
409 void SMESHGUI_TranslationDlg::ClickOnApply()
410 {
411   if (mySMESHGUI->isActiveStudyLocked())
412     return;
413
414   if (myNbOkElements) {
415     QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
416
417     SMESH::long_array_var anElementsId = new SMESH::long_array;
418
419     anElementsId->length(aListElementsId.count());
420     for (int i = 0; i < aListElementsId.count(); i++)
421       anElementsId[i] = aListElementsId[i].toInt();
422
423     SMESH::DirStruct aVector;
424     if (GetConstructorId() == 0) {
425       aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
426       aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
427       aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
428     } else if (GetConstructorId() == 1) {
429       aVector.PS.x = SpinBox1_1->GetValue();
430       aVector.PS.y = SpinBox1_2->GetValue();
431       aVector.PS.z = SpinBox1_3->GetValue();
432     }
433
434     int actionButton = ActionGroup->checkedId();
435     bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
436     try {
437       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
438       QApplication::setOverrideCursor(Qt::WaitCursor);
439       switch ( actionButton ) {
440       case MOVE_ELEMS_BUTTON:
441         aMeshEditor->Translate(anElementsId, aVector, false);
442         break;
443       case COPY_ELEMS_BUTTON:
444         if ( makeGroups )
445           SMESH::ListOfGroups_var groups = 
446             aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
447         else
448           aMeshEditor->Translate(anElementsId, aVector, true);
449         break;
450       case MAKE_MESH_BUTTON:
451         SMESH::SMESH_Mesh_var mesh = 
452           aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
453                                          LineEditNewMesh->text().toLatin1().data());
454       }
455       QApplication::restoreOverrideCursor();
456     } catch (...) {
457     }
458
459     SMESH::UpdateView();
460     if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
461          actionButton == MAKE_MESH_BUTTON )
462       mySMESHGUI->updateObjBrowser(true); // new groups may appear
463     Init(false);
464     ConstructorsClicked(GetConstructorId());
465     SelectionIntoArgument();
466   }
467 }
468
469 //=================================================================================
470 // function : ClickOnOk()
471 // purpose  :
472 //=================================================================================
473 void SMESHGUI_TranslationDlg::ClickOnOk()
474 {
475   ClickOnApply();
476   ClickOnCancel();
477 }
478
479 //=================================================================================
480 // function : ClickOnCancel()
481 // purpose  :
482 //=================================================================================
483 void SMESHGUI_TranslationDlg::ClickOnCancel()
484 {
485   disconnect(mySelectionMgr, 0, this, 0);
486   mySelectionMgr->clearFilters();
487   //mySelectionMgr->clearSelected();
488   SMESH::SetPointRepresentation(false);
489   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
490     aViewWindow->SetSelectionMode( ActorSelection );
491   mySMESHGUI->ResetState();
492   reject();
493 }
494
495 //=================================================================================
496 // function : ClickOnHelp()
497 // purpose  :
498 //=================================================================================
499 void SMESHGUI_TranslationDlg::ClickOnHelp()
500 {
501   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
502   if (app) 
503     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
504   else {
505     QString platform;
506 #ifdef WIN32
507     platform = "winapplication";
508 #else
509     platform = "application";
510 #endif
511     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
512                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
513                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
514                                                                  platform)).
515                              arg(myHelpFileName));
516   }
517 }
518
519 //=======================================================================
520 // function : onTextChange()
521 // purpose  :
522 //=======================================================================
523 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
524 {
525   QLineEdit* send = (QLineEdit*)sender();
526
527   if (myBusy) return;
528   myBusy = true;
529
530   if (send == LineEditElements)
531     myNbOkElements = 0;
532
533   buttonOk->setEnabled(false);
534   buttonApply->setEnabled(false);
535
536   // hilight entered elements
537   SMDS_Mesh* aMesh = 0;
538   if (myActor)
539     aMesh = myActor->GetObject()->GetMesh();
540
541   if (aMesh) {
542     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
543     
544     TColStd_MapOfInteger newIndices;
545
546     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
547
548     if (send == LineEditElements) {
549       for (int i = 0; i < aListId.count(); i++) {
550         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
551         if (e)
552           newIndices.Add(e->GetID());
553         myNbOkElements++;
554       }
555     }
556
557     mySelector->AddOrRemoveIndex( anIO, newIndices, false );
558     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
559       aViewWindow->highlight( anIO, true, true );
560     
561     myElementsId = theNewText;
562   }
563
564   if (myNbOkElements) {
565     buttonOk->setEnabled(true);
566     buttonApply->setEnabled(true);
567   }
568
569   myBusy = false;
570 }
571
572 //=================================================================================
573 // function : SelectionIntoArgument()
574 // purpose  : Called when selection as changed or other case
575 //=================================================================================
576 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
577 {
578   if (myBusy) return;
579
580   // clear
581   myActor = 0;
582   QString aString = "";
583
584   myBusy = true;
585   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
586     LineEditElements->setText(aString);
587     myNbOkElements = 0;
588     buttonOk->setEnabled(false);
589     buttonApply->setEnabled(false);
590   }
591   myBusy = false;
592
593   if (!GroupButtons->isEnabled()) // inactive
594     return;
595
596   // get selected mesh
597   SALOME_ListIO aList;
598   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
599
600   int nbSel = aList.Extent();
601   if (nbSel != 1)
602     return;
603
604   Handle(SALOME_InteractiveObject) IO = aList.First();
605   myMesh = SMESH::GetMeshByIO(IO);
606   if (myMesh->_is_nil())
607     return;
608
609   myActor = SMESH::FindActorByObject(myMesh);
610   if (!myActor)
611     myActor = SMESH::FindActorByEntry(IO->getEntry());
612   if (!myActor)
613     return;
614
615   int aNbUnits = 0;
616
617   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
618     myElementsId = "";
619
620     // MakeGroups is available if there are groups and "Copy"
621     if ( myMesh->NbGroups() == 0 ) {
622       MakeGroupsCheck->setChecked(false);
623       MakeGroupsCheck->setEnabled(false);
624     }
625     else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
626       MakeGroupsCheck->setEnabled(true);
627     }
628
629     if (CheckBoxMesh->isChecked()) {
630       SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
631
632       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
633         // get IDs from mesh
634         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
635         if (!aSMDSMesh)
636           return;
637
638         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
639           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
640           if (e) {
641             myElementsId += QString(" %1").arg(i);
642             aNbUnits++;
643           }
644         }
645       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
646         // get submesh
647         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
648
649         // get IDs from submesh
650         SMESH::long_array_var anElementsIds = new SMESH::long_array;
651         anElementsIds = aSubMesh->GetElementsId();
652         for (int i = 0; i < anElementsIds->length(); i++) {
653           myElementsId += QString(" %1").arg(anElementsIds[i]);
654         }
655         aNbUnits = anElementsIds->length();
656       } else { // GROUP
657         // get smesh group
658         SMESH::SMESH_GroupBase_var aGroup =
659           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
660         if (aGroup->_is_nil())
661           return;
662
663         // get IDs from smesh group
664         SMESH::long_array_var anElementsIds = new SMESH::long_array;
665         anElementsIds = aGroup->GetListOfID();
666         for (int i = 0; i < anElementsIds->length(); i++) {
667           myElementsId += QString(" %1").arg(anElementsIds[i]);
668         }
669         aNbUnits = anElementsIds->length();
670       }
671     } else {
672       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
673       myElementsId = aString;
674     }
675
676     if (aNbUnits < 1)
677       return;
678
679     myNbOkElements = true;
680   } else {
681     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
682     if (aNbUnits != 1)
683       return;
684
685     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
686     if (!aMesh)
687       return;
688
689     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
690     if (!n)
691       return;
692
693     double x = n->X();
694     double y = n->Y();
695     double z = n->Z();
696
697     if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
698       SpinBox1_1->SetValue(x);
699       SpinBox1_2->SetValue(y);
700       SpinBox1_3->SetValue(z);
701     } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
702       SpinBox2_1->SetValue(x);
703       SpinBox2_2->SetValue(y);
704       SpinBox2_3->SetValue(z);
705     }
706   }
707
708   myBusy = true;
709   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
710     LineEditElements->setText(aString);
711     setNewMeshName();
712   }
713   myBusy = false;
714
715   // OK
716   if (myNbOkElements) {
717     buttonOk->setEnabled(true);
718     buttonApply->setEnabled(true);
719   }
720 }
721
722 //=================================================================================
723 // function : SetEditCurrentArgument()
724 // purpose  :
725 //=================================================================================
726 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
727 {
728   QPushButton* send = (QPushButton*)sender();
729
730   disconnect(mySelectionMgr, 0, this, 0);
731   mySelectionMgr->clearSelected();
732   mySelectionMgr->clearFilters();
733
734   if (send == SelectElementsButton) {
735     myEditCurrentArgument = (QWidget*)LineEditElements;
736     SMESH::SetPointRepresentation(false);
737     if (CheckBoxMesh->isChecked()) {
738       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
739         aViewWindow->SetSelectionMode( ActorSelection );
740       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
741     } else {
742
743       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
744         aViewWindow->SetSelectionMode( CellSelection );
745     }
746   } else if (send == SelectButton1) {
747     myEditCurrentArgument = (QWidget*)SpinBox1_1;
748     SMESH::SetPointRepresentation(true);
749
750     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
751       aViewWindow->SetSelectionMode( NodeSelection );
752   } else if (send == SelectButton2) {
753     myEditCurrentArgument = (QWidget*)SpinBox2_1;
754     SMESH::SetPointRepresentation(true);
755
756     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
757       aViewWindow->SetSelectionMode( NodeSelection );
758   }
759
760   myEditCurrentArgument->setFocus();
761   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
762   SelectionIntoArgument();
763 }
764
765 //=================================================================================
766 // function : DeactivateActiveDialog()
767 // purpose  :
768 //=================================================================================
769 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
770 {
771   if (ConstructorsBox->isEnabled()) {
772     ConstructorsBox->setEnabled(false);
773     GroupArguments->setEnabled(false);
774     GroupButtons->setEnabled(false);
775     mySMESHGUI->ResetState();
776     mySMESHGUI->SetActiveDialogBox(0);
777   }
778 }
779
780 //=================================================================================
781 // function : ActivateThisDialog()
782 // purpose  :
783 //=================================================================================
784 void SMESHGUI_TranslationDlg::ActivateThisDialog()
785 {
786   /* Emit a signal to deactivate the active dialog */
787   mySMESHGUI->EmitSignalDeactivateDialog();
788   ConstructorsBox->setEnabled(true);
789   GroupArguments->setEnabled(true);
790   GroupButtons->setEnabled(true);
791
792   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
793
794   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
795     aViewWindow->SetSelectionMode( CellSelection );
796
797   SelectionIntoArgument();
798 }
799
800 //=================================================================================
801 // function : enterEvent()
802 // purpose  :
803 //=================================================================================
804 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
805 {
806   if (!ConstructorsBox->isEnabled())
807     ActivateThisDialog();
808 }
809
810 //=================================================================================
811 // function : closeEvent()
812 // purpose  :
813 //=================================================================================
814 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
815 {
816   /* same than click on cancel button */
817   ClickOnCancel();
818 }
819
820 //=======================================================================
821 //function : hideEvent
822 //purpose  : caused by ESC key
823 //=======================================================================
824 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
825 {
826   if (!isMinimized())
827     ClickOnCancel();
828 }
829
830 //=======================================================================
831 //function : onSelectMesh
832 //purpose  :
833 //=======================================================================
834 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
835 {
836   if (toSelectMesh)
837     TextLabelElements->setText(tr("SMESH_NAME"));
838   else
839     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
840
841   if (myEditCurrentArgument != LineEditElements) {
842     LineEditElements->clear();
843     return;
844   }
845
846   mySelectionMgr->clearFilters();
847   SMESH::SetPointRepresentation(false);
848
849   if (toSelectMesh) {
850     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
851       aViewWindow->SetSelectionMode( ActorSelection );
852     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
853     LineEditElements->setReadOnly(true);
854   } else {
855     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
856       aViewWindow->SetSelectionMode( CellSelection );
857     LineEditElements->setReadOnly(false);
858     onTextChange(LineEditElements->text());
859   }
860
861   SelectionIntoArgument();
862 }
863
864 //=======================================================================
865 //function : onActionClicked
866 //purpose  : slot called when an action type changed
867 //=======================================================================
868
869 void SMESHGUI_TranslationDlg::onActionClicked(int button)
870 {
871   switch ( button ) {
872   case MOVE_ELEMS_BUTTON:
873     MakeGroupsCheck->setEnabled(false);
874     LineEditNewMesh->setEnabled(false);
875     break;
876   case COPY_ELEMS_BUTTON:
877     LineEditNewMesh->setEnabled(false);
878     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
879     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
880       MakeGroupsCheck->setEnabled(true);
881     else
882       MakeGroupsCheck->setEnabled(false);
883     break;
884   case MAKE_MESH_BUTTON:
885     LineEditNewMesh->setEnabled(true);
886     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
887     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
888       MakeGroupsCheck->setEnabled(true);
889     else
890       MakeGroupsCheck->setEnabled(false);
891     break;
892   }
893   setNewMeshName();
894 }
895
896 //=======================================================================
897 //function : setNewMeshName
898 //purpose  : update contents of LineEditNewMesh
899 //=======================================================================
900
901 void SMESHGUI_TranslationDlg::setNewMeshName()
902 {
903   LineEditNewMesh->setText("");
904   if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
905     QString name;
906     if ( CheckBoxMesh->isChecked() ) {
907       name = LineEditElements->text();
908     }
909     else {
910       _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
911       name = meshSO->GetName().c_str();
912     }
913     if ( !name.isEmpty() )
914       LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
915   }
916 }
917
918 //=================================================================================
919 // function : GetConstructorId()
920 // purpose  :
921 //=================================================================================
922 int SMESHGUI_TranslationDlg::GetConstructorId()
923 {
924   return GroupConstructors->checkedId();
925 }
926
927 //=================================================================================
928 // function : keyPressEvent()
929 // purpose  :
930 //=================================================================================
931 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
932 {
933   QDialog::keyPressEvent( e );
934   if ( e->isAccepted() )
935     return;
936
937   if ( e->key() == Qt::Key_F1 ) {
938     e->accept();
939     ClickOnHelp();
940   }
941 }