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