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