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