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