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