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