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