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