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