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