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