Salome HOME
Fix bug 12796: Warning missed for the bad file 'test18.med'
[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 //
23 //
24 //  File   : SMESHGUI_TranslationDlg.cxx
25 //  Author : Michael ZORIN
26 //  Module : SMESH
27 //  $Header:
28
29 #include "SMESHGUI_TranslationDlg.h"
30
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_SpinBox.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_VTKUtils.h"
35 #include "SMESHGUI_MeshUtils.h"
36 #include "SMESHGUI_IdValidator.h"
37
38 #include "SMESH_Actor.h"
39 #include "SMESH_TypeFilter.hxx"
40 #include "SMESH_LogicalFilter.hxx"
41 #include "SMDS_Mesh.hxx"
42
43 #include "SUIT_Desktop.h"
44 #include "SUIT_ResourceMgr.h"
45 #include "SUIT_Session.h"
46 #include "SUIT_MessageBox.h"
47
48 #include "LightApp_Application.h"
49
50 #include "SVTK_ViewModel.h"
51 #include "SVTK_Selection.h"
52 #include "SVTK_ViewWindow.h"
53 #include "SVTK_Selector.h"
54 #include "SALOME_ListIO.hxx"
55
56 #include "utilities.h"
57
58 // OCCT Includes
59 #include <TColStd_MapOfInteger.hxx>
60 #include <TColStd_IndexedMapOfInteger.hxx>
61
62 // QT Includes
63 #include <qapplication.h>
64 #include <qbuttongroup.h>
65 #include <qgroupbox.h>
66 #include <qlabel.h>
67 #include <qlineedit.h>
68 #include <qpushbutton.h>
69 #include <qradiobutton.h>
70 #include <qcheckbox.h>
71 #include <qlayout.h>
72 #include <qspinbox.h>
73 #include <qpixmap.h>
74
75 // IDL Headers
76 #include "SALOMEconfig.h"
77 #include CORBA_SERVER_HEADER(SMESH_Group)
78
79 using namespace std;
80
81 //=================================================================================
82 // class    : SMESHGUI_TranslationDlg()
83 // purpose  :
84 //=================================================================================
85 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule, const char* name,
86                                                   bool modal, WFlags fl)
87      : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
88                 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
89      mySMESHGUI( theModule ),
90      mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
91 {
92   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
93   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
94   QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
95
96   if (!name)
97     setName("SMESHGUI_TranslationDlg");
98   resize(303, 185);
99   setCaption(tr("SMESH_TRANSLATION"));
100   setSizeGripEnabled(TRUE);
101   SMESHGUI_TranslationDlgLayout = new QGridLayout(this);
102   SMESHGUI_TranslationDlgLayout->setSpacing(6);
103   SMESHGUI_TranslationDlgLayout->setMargin(11);
104
105   /***************************************************************/
106   GroupConstructors = new QButtonGroup(this, "GroupConstructors");
107   GroupConstructors->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupConstructors->sizePolicy().hasHeightForWidth()));
108   GroupConstructors->setTitle(tr("SMESH_TRANSLATION" ));
109   GroupConstructors->setExclusive(TRUE);
110   GroupConstructors->setColumnLayout(0, Qt::Vertical);
111   GroupConstructors->layout()->setSpacing(0);
112   GroupConstructors->layout()->setMargin(0);
113   GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
114   GroupConstructorsLayout->setAlignment(Qt::AlignTop);
115   GroupConstructorsLayout->setSpacing(6);
116   GroupConstructorsLayout->setMargin(11);
117   RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
118   RadioButton1->setText(tr("" ));
119   RadioButton1->setPixmap(image0);
120   GroupConstructorsLayout->addWidget(RadioButton1, 0, 0);
121   RadioButton2= new QRadioButton(GroupConstructors, "RadioButton2");
122   RadioButton2->setText(tr("" ));
123   RadioButton2->setPixmap(image1);
124   GroupConstructorsLayout->addWidget(RadioButton2, 0, 2 );
125   SMESHGUI_TranslationDlgLayout->addWidget(GroupConstructors, 0, 0);
126
127   /***************************************************************/
128   GroupButtons = new QGroupBox(this, "GroupButtons");
129   GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth()));
130   GroupButtons->setGeometry(QRect(10, 10, 281, 48));
131   GroupButtons->setTitle(tr("" ));
132   GroupButtons->setColumnLayout(0, Qt::Vertical);
133   GroupButtons->layout()->setSpacing(0);
134   GroupButtons->layout()->setMargin(0);
135   GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
136   GroupButtonsLayout->setAlignment(Qt::AlignTop);
137   GroupButtonsLayout->setSpacing(6);
138   GroupButtonsLayout->setMargin(11);
139   buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
140   buttonHelp->setText(tr("SMESH_BUT_HELP" ));
141   buttonHelp->setAutoDefault(TRUE);
142   GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
143   buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
144   buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
145   buttonCancel->setAutoDefault(TRUE);
146   GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
147   buttonApply = new QPushButton(GroupButtons, "buttonApply");
148   buttonApply->setText(tr("SMESH_BUT_APPLY" ));
149   buttonApply->setAutoDefault(TRUE);
150   GroupButtonsLayout->addWidget(buttonApply, 0, 1);
151   QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
152   GroupButtonsLayout->addItem(spacer_9, 0, 2);
153   buttonOk = new QPushButton(GroupButtons, "buttonOk");
154   buttonOk->setText(tr("SMESH_BUT_OK" ));
155   buttonOk->setAutoDefault(TRUE);
156   buttonOk->setDefault(TRUE);
157   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
158   SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons, 2, 0);
159
160   /***************************************************************/
161   GroupArguments = new QGroupBox(this, "GroupArguments");
162   GroupArguments->setTitle(tr("SMESH_ARGUMENTS"));
163   GroupArguments->setColumnLayout(0, Qt::Vertical);
164   GroupArguments->layout()->setSpacing(0);
165   GroupArguments->layout()->setMargin(0);
166   GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
167   GroupArgumentsLayout->setAlignment(Qt::AlignTop);
168   GroupArgumentsLayout->setSpacing(6);
169   GroupArgumentsLayout->setMargin(11);
170
171   // Controls for elements selection
172   TextLabelElements  = new QLabel(GroupArguments, "TextLabelElements");
173   TextLabelElements->setText(tr("SMESH_ID_ELEMENTS" ));
174   TextLabelElements->setFixedWidth(74);
175   GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
176
177   SelectElementsButton  = new QPushButton(GroupArguments, "SelectElementsButton");
178   SelectElementsButton->setText(tr("" ));
179   SelectElementsButton->setPixmap(image2);
180   SelectElementsButton->setToggleButton(FALSE);
181   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
182
183   LineEditElements  = new QLineEdit(GroupArguments, "LineEditElements");
184   LineEditElements->setValidator(new SMESHGUI_IdValidator(this, "validator"));
185   GroupArgumentsLayout->addMultiCellWidget(LineEditElements, 0, 0, 2, 7);
186
187   // Control for the whole mesh selection
188   CheckBoxMesh = new QCheckBox(GroupArguments, "CheckBoxMesh");
189   CheckBoxMesh->setText(tr("SMESH_SELECT_WHOLE_MESH" ));
190   GroupArgumentsLayout->addMultiCellWidget(CheckBoxMesh, 1, 1, 0, 7);
191
192   // Controls for vector and points selection
193   TextLabel1 = new QLabel(GroupArguments, "TextLabel1");
194   GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
195
196   SelectButton1  = new QPushButton(GroupArguments, "SelectButton1");
197   SelectButton1->setText(tr("" ));
198   SelectButton1->setPixmap(image2);
199   SelectButton1->setToggleButton(FALSE);
200   GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
201
202   TextLabel1_1 = new QLabel(GroupArguments, "TextLabel1_1");
203   GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
204
205   SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox1_1");
206   GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
207
208   TextLabel1_2 = new QLabel(GroupArguments, "TextLabel1_2");
209   GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
210
211   SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox1_2");
212   GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
213
214   TextLabel1_3 = new QLabel(GroupArguments, "TextLabel1_3");
215   GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
216
217   SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox1_3");
218   GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
219
220   TextLabel2 = new QLabel(GroupArguments, "TextLabel2");
221   TextLabel2->setText(tr("SMESH_POINT_2" ));
222   GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
223
224   SelectButton2  = new QPushButton(GroupArguments, "SelectButton2");
225   SelectButton2->setText(tr("" ));
226   SelectButton2->setPixmap(image2);
227   SelectButton2->setToggleButton(FALSE);
228   GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
229
230   TextLabel2_1 = new QLabel(GroupArguments, "TextLabel2_1");
231   TextLabel2_1->setText(tr("SMESH_X" ));
232   GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
233
234   SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox2_1");
235   GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
236
237   TextLabel2_2 = new QLabel(GroupArguments, "TextLabel2_2");
238   TextLabel2_2->setText(tr("SMESH_Y" ));
239   GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
240
241   SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox2_2");
242   GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
243
244   TextLabel2_3 = new QLabel(GroupArguments, "TextLabel2_3");
245   TextLabel2_3->setText(tr("SMESH_Z"));
246   GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
247
248   SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox2_3");
249   GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
250
251   // Controls for "Create a copy" option
252   CheckBoxCopy = new QCheckBox(GroupArguments, "CheckBoxCopy");
253   CheckBoxCopy->setText(tr("SMESH_CREATE_COPY"));
254   GroupArgumentsLayout->addMultiCellWidget(CheckBoxCopy, 4, 4, 0, 2);
255
256
257   SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments, 1, 0);
258
259   /* Initialisations */
260   SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
261   SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
262   SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
263   SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
264   SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
265   SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
266
267   GroupArguments->show();
268   RadioButton1->setChecked(TRUE);
269
270   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
271
272   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
273
274   // Costruction of the logical filter
275   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
276   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
277
278   QPtrList<SUIT_SelectionFilter> aListOfFilters;
279   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
280   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
281
282   myMeshOrSubMeshOrGroupFilter =
283     new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
284
285   myHelpFileName = "/files/translation.htm";
286
287   Init();
288
289   /* signals and slots connections */
290   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
291   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
292   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
293   connect(buttonHelp, SIGNAL(clicked()),   this, SLOT(ClickOnHelp()));
294   connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
295
296   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
297   connect(SelectButton1,        SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
298   connect(SelectButton2,        SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
299
300   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
301   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),   this, SLOT(SelectionIntoArgument()));
302   /* to close dialog if study change */
303   connect(mySMESHGUI,       SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
304   connect(LineEditElements, SIGNAL(textChanged(const QString&)),    SLOT(onTextChange(const QString&)));
305   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                  SLOT(onSelectMesh(bool)));
306
307   this->show(); /* displays Dialog */
308
309   ConstructorsClicked(0);
310   SelectionIntoArgument();
311   resize(0,0); // ??
312 }
313
314 //=================================================================================
315 // function : ~SMESHGUI_TranslationDlg()
316 // purpose  : Destroys the object and frees any allocated resources
317 //=================================================================================
318 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
319 {
320   // no need to delete child widgets, Qt does it all for us
321 }
322
323 //=================================================================================
324 // function : Init()
325 // purpose  :
326 //=================================================================================
327 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
328 {
329   myBusy = false;
330
331   myEditCurrentArgument = 0;
332   LineEditElements->clear();
333   myElementsId = "";
334   myNbOkElements = 0;
335
336   buttonOk->setEnabled(false);
337   buttonApply->setEnabled(false);
338
339   myActor = 0;
340   myMesh = SMESH::SMESH_Mesh::_nil();
341
342   if (ResetControls) {
343     SpinBox1_1->SetValue(0.0);
344     SpinBox1_2->SetValue(0.0);
345     SpinBox1_3->SetValue(0.0);
346     SpinBox2_1->SetValue(0.0);
347     SpinBox2_2->SetValue(0.0);
348     SpinBox2_3->SetValue(0.0);
349
350     CheckBoxCopy->setChecked(false);
351     CheckBoxMesh->setChecked(false);
352     onSelectMesh(false);
353   }
354 }
355
356 //=================================================================================
357 // function : ConstructorsClicked()
358 // purpose  : Radio button management
359 //=================================================================================
360 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
361 {
362   disconnect(mySelectionMgr, 0, this, 0);
363
364   switch (constructorId) {
365   case 0:
366     {
367       TextLabel1->setText(tr("SMESH_POINT_1"));
368       TextLabel1_1->setText(tr("SMESH_X"));
369       TextLabel1_2->setText(tr("SMESH_Y"));
370       TextLabel1_3->setText(tr("SMESH_Z"));
371
372       SelectButton1->show();
373       TextLabel2->show();
374       SelectButton2->show();
375       TextLabel2_1->show();
376       SpinBox2_1->show();
377       TextLabel2_2->show();
378       SpinBox2_2->show();
379       TextLabel2_3->show();
380       SpinBox2_3->show();
381       break;
382     }
383   case 1:
384     {
385       TextLabel1->setText(tr("SMESH_VECTOR"));
386       TextLabel1_1->setText(tr("SMESH_DX"));
387       TextLabel1_2->setText(tr("SMESH_DY"));
388       TextLabel1_3->setText(tr("SMESH_DZ"));
389
390       SelectButton1->hide();
391       TextLabel2->hide();
392       SelectButton2->hide();
393       TextLabel2_1->hide();
394       SpinBox2_1->hide();
395       TextLabel2_2->hide();
396       SpinBox2_2->hide();
397       TextLabel2_3->hide();
398       SpinBox2_3->hide();
399       break;
400     }
401   }
402
403   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
404     SMESH::SetPointRepresentation(false);
405     if (!CheckBoxMesh->isChecked())
406       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
407         aViewWindow->SetSelectionMode( CellSelection );
408   }
409
410   myEditCurrentArgument = (QWidget*)LineEditElements;
411   LineEditElements->setFocus();
412
413   if (CheckBoxMesh->isChecked())
414     onSelectMesh(true);
415
416   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
417 }
418
419 //=================================================================================
420 // function : ClickOnApply()
421 // purpose  :
422 //=================================================================================
423 void SMESHGUI_TranslationDlg::ClickOnApply()
424 {
425   if (mySMESHGUI->isActiveStudyLocked())
426     return;
427
428   if (myNbOkElements) {
429     QStringList aListElementsId = QStringList::split(" ", myElementsId, false);
430
431     SMESH::long_array_var anElementsId = new SMESH::long_array;
432
433     anElementsId->length(aListElementsId.count());
434     for (int i = 0; i < aListElementsId.count(); i++)
435       anElementsId[i] = aListElementsId[i].toInt();
436
437     SMESH::DirStruct aVector;
438     if (GetConstructorId() == 0) {
439       aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
440       aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
441       aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
442     } else if (GetConstructorId() == 1) {
443       aVector.PS.x = SpinBox1_1->GetValue();
444       aVector.PS.y = SpinBox1_2->GetValue();
445       aVector.PS.z = SpinBox1_3->GetValue();
446     }
447
448     bool toCreateCopy = CheckBoxCopy->isChecked();
449
450     try {
451       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
452       QApplication::setOverrideCursor(Qt::waitCursor);
453       aMeshEditor->Translate(anElementsId.inout(), aVector, toCreateCopy);
454       QApplication::restoreOverrideCursor();
455     } catch (...) {
456     }
457
458     SMESH::UpdateView();
459     Init(false);
460     ConstructorsClicked(GetConstructorId());
461     SelectionIntoArgument();
462   }
463 }
464
465 //=================================================================================
466 // function : ClickOnOk()
467 // purpose  :
468 //=================================================================================
469 void SMESHGUI_TranslationDlg::ClickOnOk()
470 {
471   ClickOnApply();
472   ClickOnCancel();
473 }
474
475 //=================================================================================
476 // function : ClickOnCancel()
477 // purpose  :
478 //=================================================================================
479 void SMESHGUI_TranslationDlg::ClickOnCancel()
480 {
481   disconnect(mySelectionMgr, 0, this, 0);
482   mySelectionMgr->clearFilters();
483   //mySelectionMgr->clearSelected();
484   SMESH::SetPointRepresentation(false);
485   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
486     aViewWindow->SetSelectionMode( ActorSelection );
487   mySMESHGUI->ResetState();
488   reject();
489 }
490
491 //=================================================================================
492 // function : ClickOnHelp()
493 // purpose  :
494 //=================================================================================
495 void SMESHGUI_TranslationDlg::ClickOnHelp()
496 {
497   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
498   if (app) 
499     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
500   else {
501     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
502                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
503                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
504                            QObject::tr("BUT_OK"));
505   }
506 }
507
508 //=======================================================================
509 // function : onTextChange()
510 // purpose  :
511 //=======================================================================
512 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
513 {
514   QLineEdit* send = (QLineEdit*)sender();
515
516   if (myBusy) return;
517   myBusy = true;
518
519   if (send == LineEditElements)
520     myNbOkElements = 0;
521
522   buttonOk->setEnabled(false);
523   buttonApply->setEnabled(false);
524
525   // hilight entered elements
526   SMDS_Mesh* aMesh = 0;
527   if (myActor)
528     aMesh = myActor->GetObject()->GetMesh();
529
530   if (aMesh) {
531     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
532     
533     TColStd_MapOfInteger newIndices;
534
535     QStringList aListId = QStringList::split(" ", theNewText, false);
536
537     if (send == LineEditElements) {
538       for (int i = 0; i < aListId.count(); i++) {
539         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
540         if (e)
541           newIndices.Add(e->GetID());
542         myNbOkElements++;
543       }
544     }
545
546     mySelector->AddOrRemoveIndex( anIO, newIndices, false );
547     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
548       aViewWindow->highlight( anIO, true, true );
549     
550     myElementsId = theNewText;
551   }
552
553   if (myNbOkElements) {
554     buttonOk->setEnabled(true);
555     buttonApply->setEnabled(true);
556   }
557
558   myBusy = false;
559 }
560
561 //=================================================================================
562 // function : SelectionIntoArgument()
563 // purpose  : Called when selection as changed or other case
564 //=================================================================================
565 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
566 {
567   if (myBusy) return;
568
569   // clear
570   myActor = 0;
571   QString aString = "";
572
573   myBusy = true;
574   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
575     LineEditElements->setText(aString);
576     myNbOkElements = 0;
577     buttonOk->setEnabled(false);
578     buttonApply->setEnabled(false);
579   }
580   myBusy = false;
581
582   if (!GroupButtons->isEnabled()) // inactive
583     return;
584
585   // get selected mesh
586   SALOME_ListIO aList;
587   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
588
589   int nbSel = aList.Extent();
590   if (nbSel != 1)
591     return;
592
593   Handle(SALOME_InteractiveObject) IO = aList.First();
594   myMesh = SMESH::GetMeshByIO(IO);
595   if (myMesh->_is_nil())
596     return;
597
598   myActor = SMESH::FindActorByObject(myMesh);
599   if (!myActor)
600     myActor = SMESH::FindActorByEntry(IO->getEntry());
601   if (!myActor)
602     return;
603
604   int aNbUnits = 0;
605
606   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
607     myElementsId = "";
608
609     if (CheckBoxMesh->isChecked()) {
610       SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
611
612       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
613         // get IDs from mesh
614         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
615         if (!aSMDSMesh)
616           return;
617
618         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
619           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
620           if (e) {
621             myElementsId += QString(" %1").arg(i);
622             aNbUnits++;
623           }
624         }
625       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
626         // get submesh
627         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
628
629         // get IDs from submesh
630         SMESH::long_array_var anElementsIds = new SMESH::long_array;
631         anElementsIds = aSubMesh->GetElementsId();
632         for (int i = 0; i < anElementsIds->length(); i++) {
633           myElementsId += QString(" %1").arg(anElementsIds[i]);
634         }
635         aNbUnits = anElementsIds->length();
636       } else { // GROUP
637         // get smesh group
638         SMESH::SMESH_GroupBase_var aGroup =
639           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
640         if (aGroup->_is_nil())
641           return;
642
643         // get IDs from smesh group
644         SMESH::long_array_var anElementsIds = new SMESH::long_array;
645         anElementsIds = aGroup->GetListOfID();
646         for (int i = 0; i < anElementsIds->length(); i++) {
647           myElementsId += QString(" %1").arg(anElementsIds[i]);
648         }
649         aNbUnits = anElementsIds->length();
650       }
651     } else {
652       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
653       myElementsId = aString;
654     }
655
656     if (aNbUnits < 1)
657       return;
658
659     myNbOkElements = true;
660   } else {
661     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
662     if (aNbUnits != 1)
663       return;
664
665     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
666     if (!aMesh)
667       return;
668
669     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
670     if (!n)
671       return;
672
673     double x = n->X();
674     double y = n->Y();
675     double z = n->Z();
676
677     if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
678       SpinBox1_1->SetValue(x);
679       SpinBox1_2->SetValue(y);
680       SpinBox1_3->SetValue(z);
681     } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
682       SpinBox2_1->SetValue(x);
683       SpinBox2_2->SetValue(y);
684       SpinBox2_3->SetValue(z);
685     }
686   }
687
688   myBusy = true;
689   if (myEditCurrentArgument == (QWidget*)LineEditElements)
690     LineEditElements->setText(aString);
691   myBusy = false;
692
693   // OK
694   if (myNbOkElements) {
695     buttonOk->setEnabled(true);
696     buttonApply->setEnabled(true);
697   }
698 }
699
700 //=================================================================================
701 // function : SetEditCurrentArgument()
702 // purpose  :
703 //=================================================================================
704 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
705 {
706   QPushButton* send = (QPushButton*)sender();
707
708   disconnect(mySelectionMgr, 0, this, 0);
709   mySelectionMgr->clearSelected();
710   mySelectionMgr->clearFilters();
711
712   if (send == SelectElementsButton) {
713     myEditCurrentArgument = (QWidget*)LineEditElements;
714     SMESH::SetPointRepresentation(false);
715     if (CheckBoxMesh->isChecked()) {
716       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
717         aViewWindow->SetSelectionMode( ActorSelection );
718       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
719     } else {
720
721       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
722         aViewWindow->SetSelectionMode( CellSelection );
723     }
724   } else if (send == SelectButton1) {
725     myEditCurrentArgument = (QWidget*)SpinBox1_1;
726     SMESH::SetPointRepresentation(true);
727
728     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
729       aViewWindow->SetSelectionMode( NodeSelection );
730   } else if (send == SelectButton2) {
731     myEditCurrentArgument = (QWidget*)SpinBox2_1;
732     SMESH::SetPointRepresentation(true);
733
734     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
735       aViewWindow->SetSelectionMode( NodeSelection );
736   }
737
738   myEditCurrentArgument->setFocus();
739   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
740   SelectionIntoArgument();
741 }
742
743 //=================================================================================
744 // function : DeactivateActiveDialog()
745 // purpose  :
746 //=================================================================================
747 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
748 {
749   if (GroupConstructors->isEnabled()) {
750     GroupConstructors->setEnabled(false);
751     GroupArguments->setEnabled(false);
752     GroupButtons->setEnabled(false);
753     mySMESHGUI->ResetState();
754     mySMESHGUI->SetActiveDialogBox(0);
755   }
756 }
757
758 //=================================================================================
759 // function : ActivateThisDialog()
760 // purpose  :
761 //=================================================================================
762 void SMESHGUI_TranslationDlg::ActivateThisDialog()
763 {
764   /* Emit a signal to deactivate the active dialog */
765   mySMESHGUI->EmitSignalDeactivateDialog();
766   GroupConstructors->setEnabled(true);
767   GroupArguments->setEnabled(true);
768   GroupButtons->setEnabled(true);
769
770   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
771
772   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
773     aViewWindow->SetSelectionMode( CellSelection );
774
775   SelectionIntoArgument();
776 }
777
778 //=================================================================================
779 // function : enterEvent()
780 // purpose  :
781 //=================================================================================
782 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
783 {
784   if (!GroupConstructors->isEnabled())
785     ActivateThisDialog();
786 }
787
788 //=================================================================================
789 // function : closeEvent()
790 // purpose  :
791 //=================================================================================
792 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
793 {
794   /* same than click on cancel button */
795   this->ClickOnCancel();
796 }
797
798 //=======================================================================
799 //function : hideEvent
800 //purpose  : caused by ESC key
801 //=======================================================================
802 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
803 {
804   if (!isMinimized())
805     ClickOnCancel();
806 }
807
808 //=======================================================================
809 //function : onSelectMesh
810 //purpose  :
811 //=======================================================================
812 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
813 {
814   if (toSelectMesh)
815     TextLabelElements->setText(tr("SMESH_NAME"));
816   else
817     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
818
819   if (myEditCurrentArgument != LineEditElements) {
820     LineEditElements->clear();
821     return;
822   }
823
824   mySelectionMgr->clearFilters();
825   SMESH::SetPointRepresentation(false);
826
827   if (toSelectMesh) {
828     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
829       aViewWindow->SetSelectionMode( ActorSelection );
830     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
831     LineEditElements->setReadOnly(true);
832   } else {
833     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
834       aViewWindow->SetSelectionMode( CellSelection );
835     LineEditElements->setReadOnly(false);
836     onTextChange(LineEditElements->text());
837   }
838
839   SelectionIntoArgument();
840 }
841
842 //=================================================================================
843 // function : GetConstructorId()
844 // purpose  :
845 //=================================================================================
846 int SMESHGUI_TranslationDlg::GetConstructorId()
847 {
848   if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
849     return GroupConstructors->id(GroupConstructors->selected());
850   return -1;
851 }
852
853 //=================================================================================
854 // function : keyPressEvent()
855 // purpose  :
856 //=================================================================================
857 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
858 {
859   QDialog::keyPressEvent( e );
860   if ( e->isAccepted() )
861     return;
862
863   if ( e->key() == Key_F1 )
864     {
865       e->accept();
866       ClickOnHelp();
867     }
868 }