Salome HOME
Merging with WPdev
[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                 QString platform;
502 #ifdef WIN32
503                 platform = "winapplication";
504 #else
505                 platform = "application";
506 #endif
507     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
508                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
509                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
510                            QObject::tr("BUT_OK"));
511   }
512 }
513
514 //=======================================================================
515 // function : onTextChange()
516 // purpose  :
517 //=======================================================================
518 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
519 {
520   QLineEdit* send = (QLineEdit*)sender();
521
522   if (myBusy) return;
523   myBusy = true;
524
525   if (send == LineEditElements)
526     myNbOkElements = 0;
527
528   buttonOk->setEnabled(false);
529   buttonApply->setEnabled(false);
530
531   // hilight entered elements
532   SMDS_Mesh* aMesh = 0;
533   if (myActor)
534     aMesh = myActor->GetObject()->GetMesh();
535
536   if (aMesh) {
537     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
538     
539     TColStd_MapOfInteger newIndices;
540
541     QStringList aListId = QStringList::split(" ", theNewText, false);
542
543     if (send == LineEditElements) {
544       for (int i = 0; i < aListId.count(); i++) {
545         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
546         if (e)
547           newIndices.Add(e->GetID());
548         myNbOkElements++;
549       }
550     }
551
552     mySelector->AddOrRemoveIndex( anIO, newIndices, false );
553     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
554       aViewWindow->highlight( anIO, true, true );
555     
556     myElementsId = theNewText;
557   }
558
559   if (myNbOkElements) {
560     buttonOk->setEnabled(true);
561     buttonApply->setEnabled(true);
562   }
563
564   myBusy = false;
565 }
566
567 //=================================================================================
568 // function : SelectionIntoArgument()
569 // purpose  : Called when selection as changed or other case
570 //=================================================================================
571 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
572 {
573   if (myBusy) return;
574
575   // clear
576   myActor = 0;
577   QString aString = "";
578
579   myBusy = true;
580   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
581     LineEditElements->setText(aString);
582     myNbOkElements = 0;
583     buttonOk->setEnabled(false);
584     buttonApply->setEnabled(false);
585   }
586   myBusy = false;
587
588   if (!GroupButtons->isEnabled()) // inactive
589     return;
590
591   // get selected mesh
592   SALOME_ListIO aList;
593   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
594
595   int nbSel = aList.Extent();
596   if (nbSel != 1)
597     return;
598
599   Handle(SALOME_InteractiveObject) IO = aList.First();
600   myMesh = SMESH::GetMeshByIO(IO);
601   if (myMesh->_is_nil())
602     return;
603
604   myActor = SMESH::FindActorByObject(myMesh);
605   if (!myActor)
606     myActor = SMESH::FindActorByEntry(IO->getEntry());
607   if (!myActor)
608     return;
609
610   int aNbUnits = 0;
611
612   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
613     myElementsId = "";
614
615     if (CheckBoxMesh->isChecked()) {
616       SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
617
618       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
619         // get IDs from mesh
620         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
621         if (!aSMDSMesh)
622           return;
623
624         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
625           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
626           if (e) {
627             myElementsId += QString(" %1").arg(i);
628             aNbUnits++;
629           }
630         }
631       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
632         // get submesh
633         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
634
635         // get IDs from submesh
636         SMESH::long_array_var anElementsIds = new SMESH::long_array;
637         anElementsIds = aSubMesh->GetElementsId();
638         for (int i = 0; i < anElementsIds->length(); i++) {
639           myElementsId += QString(" %1").arg(anElementsIds[i]);
640         }
641         aNbUnits = anElementsIds->length();
642       } else { // GROUP
643         // get smesh group
644         SMESH::SMESH_GroupBase_var aGroup =
645           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
646         if (aGroup->_is_nil())
647           return;
648
649         // get IDs from smesh group
650         SMESH::long_array_var anElementsIds = new SMESH::long_array;
651         anElementsIds = aGroup->GetListOfID();
652         for (int i = 0; i < anElementsIds->length(); i++) {
653           myElementsId += QString(" %1").arg(anElementsIds[i]);
654         }
655         aNbUnits = anElementsIds->length();
656       }
657     } else {
658       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
659       myElementsId = aString;
660     }
661
662     if (aNbUnits < 1)
663       return;
664
665     myNbOkElements = true;
666   } else {
667     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
668     if (aNbUnits != 1)
669       return;
670
671     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
672     if (!aMesh)
673       return;
674
675     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
676     if (!n)
677       return;
678
679     double x = n->X();
680     double y = n->Y();
681     double z = n->Z();
682
683     if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
684       SpinBox1_1->SetValue(x);
685       SpinBox1_2->SetValue(y);
686       SpinBox1_3->SetValue(z);
687     } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
688       SpinBox2_1->SetValue(x);
689       SpinBox2_2->SetValue(y);
690       SpinBox2_3->SetValue(z);
691     }
692   }
693
694   myBusy = true;
695   if (myEditCurrentArgument == (QWidget*)LineEditElements)
696     LineEditElements->setText(aString);
697   myBusy = false;
698
699   // OK
700   if (myNbOkElements) {
701     buttonOk->setEnabled(true);
702     buttonApply->setEnabled(true);
703   }
704 }
705
706 //=================================================================================
707 // function : SetEditCurrentArgument()
708 // purpose  :
709 //=================================================================================
710 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
711 {
712   QPushButton* send = (QPushButton*)sender();
713
714   disconnect(mySelectionMgr, 0, this, 0);
715   mySelectionMgr->clearSelected();
716   mySelectionMgr->clearFilters();
717
718   if (send == SelectElementsButton) {
719     myEditCurrentArgument = (QWidget*)LineEditElements;
720     SMESH::SetPointRepresentation(false);
721     if (CheckBoxMesh->isChecked()) {
722       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
723         aViewWindow->SetSelectionMode( ActorSelection );
724       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
725     } else {
726
727       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
728         aViewWindow->SetSelectionMode( CellSelection );
729     }
730   } else if (send == SelectButton1) {
731     myEditCurrentArgument = (QWidget*)SpinBox1_1;
732     SMESH::SetPointRepresentation(true);
733
734     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
735       aViewWindow->SetSelectionMode( NodeSelection );
736   } else if (send == SelectButton2) {
737     myEditCurrentArgument = (QWidget*)SpinBox2_1;
738     SMESH::SetPointRepresentation(true);
739
740     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
741       aViewWindow->SetSelectionMode( NodeSelection );
742   }
743
744   myEditCurrentArgument->setFocus();
745   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
746   SelectionIntoArgument();
747 }
748
749 //=================================================================================
750 // function : DeactivateActiveDialog()
751 // purpose  :
752 //=================================================================================
753 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
754 {
755   if (GroupConstructors->isEnabled()) {
756     GroupConstructors->setEnabled(false);
757     GroupArguments->setEnabled(false);
758     GroupButtons->setEnabled(false);
759     mySMESHGUI->ResetState();
760     mySMESHGUI->SetActiveDialogBox(0);
761   }
762 }
763
764 //=================================================================================
765 // function : ActivateThisDialog()
766 // purpose  :
767 //=================================================================================
768 void SMESHGUI_TranslationDlg::ActivateThisDialog()
769 {
770   /* Emit a signal to deactivate the active dialog */
771   mySMESHGUI->EmitSignalDeactivateDialog();
772   GroupConstructors->setEnabled(true);
773   GroupArguments->setEnabled(true);
774   GroupButtons->setEnabled(true);
775
776   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
777
778   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
779     aViewWindow->SetSelectionMode( CellSelection );
780
781   SelectionIntoArgument();
782 }
783
784 //=================================================================================
785 // function : enterEvent()
786 // purpose  :
787 //=================================================================================
788 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
789 {
790   if (!GroupConstructors->isEnabled())
791     ActivateThisDialog();
792 }
793
794 //=================================================================================
795 // function : closeEvent()
796 // purpose  :
797 //=================================================================================
798 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
799 {
800   /* same than click on cancel button */
801   this->ClickOnCancel();
802 }
803
804 //=======================================================================
805 //function : hideEvent
806 //purpose  : caused by ESC key
807 //=======================================================================
808 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
809 {
810   if (!isMinimized())
811     ClickOnCancel();
812 }
813
814 //=======================================================================
815 //function : onSelectMesh
816 //purpose  :
817 //=======================================================================
818 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
819 {
820   if (toSelectMesh)
821     TextLabelElements->setText(tr("SMESH_NAME"));
822   else
823     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
824
825   if (myEditCurrentArgument != LineEditElements) {
826     LineEditElements->clear();
827     return;
828   }
829
830   mySelectionMgr->clearFilters();
831   SMESH::SetPointRepresentation(false);
832
833   if (toSelectMesh) {
834     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
835       aViewWindow->SetSelectionMode( ActorSelection );
836     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
837     LineEditElements->setReadOnly(true);
838   } else {
839     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
840       aViewWindow->SetSelectionMode( CellSelection );
841     LineEditElements->setReadOnly(false);
842     onTextChange(LineEditElements->text());
843   }
844
845   SelectionIntoArgument();
846 }
847
848 //=================================================================================
849 // function : GetConstructorId()
850 // purpose  :
851 //=================================================================================
852 int SMESHGUI_TranslationDlg::GetConstructorId()
853 {
854   if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
855     return GroupConstructors->id(GroupConstructors->selected());
856   return -1;
857 }
858
859 //=================================================================================
860 // function : keyPressEvent()
861 // purpose  :
862 //=================================================================================
863 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
864 {
865   QDialog::keyPressEvent( e );
866   if ( e->isAccepted() )
867     return;
868
869   if ( e->key() == Key_F1 )
870     {
871       e->accept();
872       ClickOnHelp();
873     }
874 }