1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_RotationDlg.cxx
25 // Author : Michael ZORIN, Open CASCADE S.A.S.
28 #include "SMESHGUI_RotationDlg.h"
31 #include "SMESHGUI_SpinBox.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_IdValidator.h"
36 #include "SMESHGUI_FilterDlg.h"
38 #include <SMESH_Actor.h>
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESH_LogicalFilter.hxx>
41 #include <SMDS_Mesh.hxx>
43 // SALOME GUI includes
44 #include <SUIT_Desktop.h>
45 #include <SUIT_Session.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_ResourceMgr.h>
48 #include <SUIT_OverrideCursor.h>
50 #include <LightApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
53 #include <SVTK_ViewModel.h>
54 #include <SVTK_ViewWindow.h>
55 #include <SALOME_ListIO.hxx>
57 // SALOME KERNEL includes
58 #include <SALOMEDSClient_SObject.hxx>
61 #include <TColStd_MapOfInteger.hxx>
64 #include <QApplication>
65 #include <QButtonGroup>
69 #include <QPushButton>
70 #include <QRadioButton>
72 #include <QHBoxLayout>
73 #include <QVBoxLayout>
74 #include <QGridLayout>
78 #include <SALOMEconfig.h>
79 #include CORBA_SERVER_HEADER(SMESH_Group)
80 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
82 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
87 //=================================================================================
88 // class : SMESHGUI_RotationDlg()
90 //=================================================================================
91 SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule )
92 : QDialog( SMESH::GetDesktop( theModule ) ),
93 mySMESHGUI( theModule ),
94 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
96 mySelectedObject(SMESH::SMESH_IDSource::_nil())
98 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_ROTATION")));
99 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
102 setAttribute(Qt::WA_DeleteOnClose, true);
103 setWindowTitle(tr("SMESH_ROTATION_TITLE"));
104 setSizeGripEnabled(true);
106 QVBoxLayout* SMESHGUI_RotationDlgLayout = new QVBoxLayout(this);
107 SMESHGUI_RotationDlgLayout->setSpacing(SPACING);
108 SMESHGUI_RotationDlgLayout->setMargin(MARGIN);
110 /***************************************************************/
111 GroupConstructors = new QGroupBox(tr("SMESH_ROTATION"), this);
112 QButtonGroup* ButtonGroup = new QButtonGroup(this);
113 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
114 GroupConstructorsLayout->setSpacing(SPACING);
115 GroupConstructorsLayout->setMargin(MARGIN);
117 RadioButton1= new QRadioButton(GroupConstructors);
118 RadioButton1->setIcon(image0);
120 GroupConstructorsLayout->addWidget(RadioButton1);
121 ButtonGroup->addButton(RadioButton1, 0);
123 /***************************************************************/
124 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
125 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
126 GroupArgumentsLayout->setSpacing(SPACING);
127 GroupArgumentsLayout->setMargin(MARGIN);
129 myIdValidator = new SMESHGUI_IdValidator(this);
131 // Controls for elements selection
132 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
133 SelectElementsButton = new QPushButton(GroupArguments);
134 SelectElementsButton->setIcon(image1);
135 LineEditElements = new QLineEdit(GroupArguments);
136 LineEditElements->setValidator(myIdValidator);
137 LineEditElements->setMaxLength(-1);
138 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
139 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
141 // Control for the whole mesh selection
142 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
144 // Controls for axis defining
145 GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
146 QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
147 GroupAxisLayout->setSpacing(SPACING);
148 GroupAxisLayout->setMargin(MARGIN);
150 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
151 SelectPointButton = new QPushButton(GroupAxis);
152 SelectPointButton->setIcon(image1);
154 TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
155 SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
156 TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
157 SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
158 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
159 SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
161 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
162 SelectVectorButton = new QPushButton(GroupAxis);
163 SelectVectorButton->setIcon(image1);
165 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
166 SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
167 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
168 SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
169 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
170 SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
172 GroupAxisLayout->addWidget(TextLabelPoint, 0, 0);
173 GroupAxisLayout->addWidget(SelectPointButton, 0, 1);
174 GroupAxisLayout->addWidget(TextLabelX, 0, 2);
175 GroupAxisLayout->addWidget(SpinBox_X, 0, 3);
176 GroupAxisLayout->addWidget(TextLabelY, 0, 4);
177 GroupAxisLayout->addWidget(SpinBox_Y, 0, 5);
178 GroupAxisLayout->addWidget(TextLabelZ, 0, 6);
179 GroupAxisLayout->addWidget(SpinBox_Z, 0, 7);
180 GroupAxisLayout->addWidget(TextLabelVector, 1, 0);
181 GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
182 GroupAxisLayout->addWidget(TextLabelDX, 1, 2);
183 GroupAxisLayout->addWidget(SpinBox_DX, 1, 3);
184 GroupAxisLayout->addWidget(TextLabelDY, 1, 4);
185 GroupAxisLayout->addWidget(SpinBox_DY, 1, 5);
186 GroupAxisLayout->addWidget(TextLabelDZ, 1, 6);
187 GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7);
189 // Controls for angle defining
190 TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupArguments);
191 SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments);
194 ActionBox = new QGroupBox(GroupArguments);
195 ActionGroup = new QButtonGroup(GroupArguments);
196 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
197 ActionBoxLayout->setSpacing(SPACING);
198 ActionBoxLayout->setMargin(MARGIN);
200 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
201 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
202 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
204 ActionBoxLayout->addWidget(aMoveElements);
205 ActionBoxLayout->addWidget(aCopyElements);
206 ActionBoxLayout->addWidget(aCreateMesh);
207 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
208 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
209 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
211 // CheckBox for groups generation
212 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
214 // Name of a mesh to create
215 LineEditNewMesh = new QLineEdit(GroupArguments);
217 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
218 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
219 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
220 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
221 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
222 GroupArgumentsLayout->addWidget(GroupAxis, 2, 0, 1, 4);
223 GroupArgumentsLayout->addWidget(TextLabelAngle, 3, 0, 1, 2);
224 GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
225 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 3);
226 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 3);
227 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 3);
229 /***************************************************************/
230 GroupButtons = new QGroupBox(this);
231 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
232 GroupButtonsLayout->setSpacing(SPACING);
233 GroupButtonsLayout->setMargin(MARGIN);
235 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
236 buttonOk->setAutoDefault(true);
237 buttonOk->setDefault(true);
238 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
239 buttonApply->setAutoDefault(true);
240 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
241 buttonCancel->setAutoDefault(true);
242 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
243 buttonHelp->setAutoDefault(true);
245 GroupButtonsLayout->addWidget(buttonOk);
246 GroupButtonsLayout->addSpacing(10);
247 GroupButtonsLayout->addWidget(buttonApply);
248 GroupButtonsLayout->addSpacing(10);
249 GroupButtonsLayout->addStretch();
250 GroupButtonsLayout->addWidget(buttonCancel);
251 GroupButtonsLayout->addWidget(buttonHelp);
253 /***************************************************************/
254 SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors);
255 SMESHGUI_RotationDlgLayout->addWidget(GroupArguments);
256 SMESHGUI_RotationDlgLayout->addWidget(GroupButtons);
258 /* Initialisations */
259 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
260 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
261 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
262 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
263 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
264 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
266 SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, "angle_precision");
269 RadioButton1->setChecked(true);
271 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
273 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
275 // Costruction of the logical filter
276 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
277 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
279 QList<SUIT_SelectionFilter*> aListOfFilters;
280 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
281 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
283 myMeshOrSubMeshOrGroupFilter =
284 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
286 myHelpFileName = "rotation_page.html";
290 /* signals and slots connections */
291 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
292 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
293 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
294 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
296 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
297 connect(SelectPointButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
298 connect(SelectVectorButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
300 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
301 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
302 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
304 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
305 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
306 /* to close dialog if study change */
307 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
308 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
309 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
310 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
312 onActionClicked(MOVE_ELEMS_BUTTON);
315 //=================================================================================
316 // function : ~SMESHGUI_RotationDlg()
317 // purpose : Destroys the object and frees any allocated resources
318 //=================================================================================
319 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
322 myFilterDlg->setParent( 0 );
328 //=================================================================================
331 //=================================================================================
332 void SMESHGUI_RotationDlg::Init (bool ResetControls)
336 myEditCurrentArgument = (QWidget*)LineEditElements;
337 LineEditElements->setFocus();
341 buttonOk->setEnabled(false);
342 buttonApply->setEnabled(false);
345 myMesh = SMESH::SMESH_Mesh::_nil();
348 SpinBox_X->SetValue(0.0);
349 SpinBox_Y->SetValue(0.0);
350 SpinBox_Z->SetValue(0.0);
351 SpinBox_DX->SetValue(0.0);
352 SpinBox_DY->SetValue(0.0);
353 SpinBox_DZ->SetValue(0.0);
355 SpinBox_Angle->SetValue(45);
357 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
358 CheckBoxMesh->setChecked(false);
359 // MakeGroupsCheck->setChecked(false);
360 // MakeGroupsCheck->setEnabled(false);
361 // onSelectMesh(false);
364 onSelectMesh(CheckBoxMesh->isChecked());
367 //=================================================================================
368 // function : ClickOnApply()
370 //=================================================================================
371 bool SMESHGUI_RotationDlg::ClickOnApply()
373 if (mySMESHGUI->isActiveStudyLocked())
379 if (myNbOkElements && IsAxisOk()) {
380 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
382 SMESH::long_array_var anElementsId = new SMESH::long_array;
384 anElementsId->length(aListElementsId.count());
385 for (int i = 0; i < aListElementsId.count(); i++)
386 anElementsId[i] = aListElementsId[i].toInt();
388 SMESH::AxisStruct anAxis;
390 anAxis.x = SpinBox_X->GetValue();
391 anAxis.y = SpinBox_Y->GetValue();
392 anAxis.z = SpinBox_Z->GetValue();;
393 anAxis.vx = SpinBox_DX->GetValue();
394 anAxis.vy = SpinBox_DY->GetValue();
395 anAxis.vz = SpinBox_DZ->GetValue();
397 double anAngle = (SpinBox_Angle->GetValue())*PI/180;
399 QStringList aParameters;
400 aParameters << SpinBox_X->text();
401 aParameters << SpinBox_Y->text();
402 aParameters << SpinBox_Z->text();
403 aParameters << SpinBox_DX->text();
404 aParameters << SpinBox_DY->text();
405 aParameters << SpinBox_DZ->text();
406 aParameters << SpinBox_Angle->text();
408 int actionButton = ActionGroup->checkedId();
409 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
411 SUIT_OverrideCursor aWaitCursor;
412 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
413 switch ( actionButton ) {
414 case MOVE_ELEMS_BUTTON:
415 if(CheckBoxMesh->isChecked())
416 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, false);
418 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
419 if( !myMesh->_is_nil())
420 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
422 case COPY_ELEMS_BUTTON:
424 SMESH::ListOfGroups_var groups;
425 if(CheckBoxMesh->isChecked())
426 groups = aMeshEditor->RotateObjectMakeGroups(mySelectedObject, anAxis, anAngle);
428 groups = aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
431 if(CheckBoxMesh->isChecked())
432 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, true);
434 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
436 if( !myMesh->_is_nil())
437 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
439 case MAKE_MESH_BUTTON:
440 SMESH::SMESH_Mesh_var mesh;
441 if(CheckBoxMesh->isChecked())
442 mesh = aMeshEditor->RotateObjectMakeMesh(mySelectedObject, anAxis, anAngle, makeGroups,
443 LineEditNewMesh->text().toLatin1().data());
445 mesh = aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
446 LineEditNewMesh->text().toLatin1().data());
447 if( !mesh->_is_nil())
448 mesh->SetParameters( aParameters.join(":").toLatin1().constData() );
454 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
455 actionButton == MAKE_MESH_BUTTON )
456 mySMESHGUI->updateObjBrowser(true); // new groups may appear
458 mySelectedObject = SMESH::SMESH_IDSource::_nil();
459 SelectionIntoArgument();
461 SMESHGUI::Modified();
467 //=================================================================================
468 // function : ClickOnOk()
470 //=================================================================================
471 void SMESHGUI_RotationDlg::ClickOnOk()
477 //=================================================================================
478 // function : ClickOnCancel()
480 //=================================================================================
481 void SMESHGUI_RotationDlg::ClickOnCancel()
483 disconnect(mySelectionMgr, 0, this, 0);
484 mySelectionMgr->clearFilters();
485 //mySelectionMgr->clearSelected();
486 if (SMESH::GetCurrentVtkView()) {
487 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
488 SMESH::SetPointRepresentation(false);
490 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
491 aViewWindow->SetSelectionMode(ActorSelection);
492 mySMESHGUI->ResetState();
496 //=================================================================================
497 // function : ClickOnHelp()
499 //=================================================================================
500 void SMESHGUI_RotationDlg::ClickOnHelp()
502 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
504 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
508 platform = "winapplication";
510 platform = "application";
512 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
513 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
514 arg(app->resourceMgr()->stringValue("ExternalBrowser",
516 arg(myHelpFileName));
520 //=======================================================================
521 // function : onTextChange()
523 //=======================================================================
524 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
526 QLineEdit* send = (QLineEdit*)sender();
531 if (send == LineEditElements)
534 buttonOk->setEnabled(false);
535 buttonApply->setEnabled(false);
537 // hilight entered elements
538 SMDS_Mesh* aMesh = 0;
540 aMesh = myActor->GetObject()->GetMesh();
543 if (send == LineEditElements) {
544 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
546 TColStd_MapOfInteger newIndices;
548 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
549 for (int i = 0; i < aListId.count(); i++) {
550 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
552 newIndices.Add(e->GetID());
556 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
557 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
558 aViewWindow->highlight( anIO, true, true );
560 myElementsId = theNewText;
564 if (myNbOkElements && IsAxisOk()) {
565 buttonOk->setEnabled(true);
566 buttonApply->setEnabled(true);
572 //=================================================================================
573 // function : SelectionIntoArgument()
574 // purpose : Called when selection as changed or other case
575 //=================================================================================
576 void SMESHGUI_RotationDlg::SelectionIntoArgument()
582 QString aString = "";
585 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
586 LineEditElements->setText(aString);
588 buttonOk->setEnabled(false);
589 buttonApply->setEnabled(false);
593 if (!GroupButtons->isEnabled()) // inactive
598 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
600 int nbSel = aList.Extent();
604 Handle(SALOME_InteractiveObject) IO = aList.First();
605 myMesh = SMESH::GetMeshByIO(IO);
606 if (myMesh->_is_nil())
609 myActor = SMESH::FindActorByObject(myMesh);
611 myActor = SMESH::FindActorByEntry(IO->getEntry());
612 if (!myActor && !CheckBoxMesh->isChecked())
617 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
620 // MakeGroups is available if there are groups and "Copy"
621 if ( myMesh->NbGroups() == 0 ) {
622 MakeGroupsCheck->setChecked(false);
623 MakeGroupsCheck->setEnabled(false);
625 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
626 MakeGroupsCheck->setEnabled(true);
628 if (CheckBoxMesh->isChecked()) {
629 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
631 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
632 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
638 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
642 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
643 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
645 myElementsId += QString(" %1").arg(i);
649 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
651 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
653 // get IDs from submesh
654 SMESH::long_array_var anElementsIds = new SMESH::long_array;
655 anElementsIds = aSubMesh->GetElementsId();
656 for (int i = 0; i < anElementsIds->length(); i++) {
657 myElementsId += QString(" %1").arg(anElementsIds[i]);
659 aNbUnits = anElementsIds->length();
662 SMESH::SMESH_GroupBase_var aGroup =
663 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
664 if (aGroup->_is_nil())
667 // get IDs from smesh group
668 SMESH::long_array_var anElementsIds = new SMESH::long_array;
669 anElementsIds = aGroup->GetListOfID();
670 for (int i = 0; i < anElementsIds->length(); i++) {
671 myElementsId += QString(" %1").arg(anElementsIds[i]);
673 aNbUnits = anElementsIds->length();
677 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
678 myElementsId = aString;
683 myNbOkElements = true;
686 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
690 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
694 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
702 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
703 SpinBox_X->SetValue(x);
704 SpinBox_Y->SetValue(y);
705 SpinBox_Z->SetValue(z);
706 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
707 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
708 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
709 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
714 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
715 LineEditElements->setText(aString);
716 LineEditElements->repaint();
717 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
718 LineEditElements->setEnabled(true);
724 if (myNbOkElements && IsAxisOk()) {
725 buttonOk->setEnabled(true);
726 buttonApply->setEnabled(true);
730 //=================================================================================
731 // function : SetEditCurrentArgument()
733 //=================================================================================
734 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
736 QPushButton* send = (QPushButton*)sender();
738 disconnect(mySelectionMgr, 0, this, 0);
739 mySelectionMgr->clearSelected();
740 mySelectionMgr->clearFilters();
742 switch (myConstructorId) {
743 case 0: /* default constructor */
745 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
746 if (send == SelectElementsButton) {
747 myEditCurrentArgument = (QWidget*)LineEditElements;
748 SMESH::SetPointRepresentation(false);
749 if (CheckBoxMesh->isChecked()) {
751 aViewWindow->SetSelectionMode(ActorSelection);
752 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
755 aViewWindow->SetSelectionMode( CellSelection );
757 } else if (send == SelectPointButton) {
758 myEditCurrentArgument = (QWidget*)SpinBox_X;
759 SMESH::SetPointRepresentation(true);
761 aViewWindow->SetSelectionMode( NodeSelection );
762 } else if (send == SelectVectorButton) {
763 myEditCurrentArgument = (QWidget*)SpinBox_DX;
764 SMESH::SetPointRepresentation(true);
766 aViewWindow->SetSelectionMode( NodeSelection );
773 myEditCurrentArgument->setFocus();
774 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
775 SelectionIntoArgument();
778 //=================================================================================
779 // function : DeactivateActiveDialog()
781 //=================================================================================
782 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
784 if (GroupConstructors->isEnabled()) {
785 GroupConstructors->setEnabled(false);
786 GroupArguments->setEnabled(false);
787 GroupButtons->setEnabled(false);
788 mySMESHGUI->ResetState();
789 mySMESHGUI->SetActiveDialogBox(0);
793 //=================================================================================
794 // function : ActivateThisDialog()
796 //=================================================================================
797 void SMESHGUI_RotationDlg::ActivateThisDialog()
799 /* Emit a signal to deactivate the active dialog */
800 mySMESHGUI->EmitSignalDeactivateDialog();
801 GroupConstructors->setEnabled(true);
802 GroupArguments->setEnabled(true);
803 GroupButtons->setEnabled(true);
805 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
807 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
808 aViewWindow->SetSelectionMode( CellSelection );
809 SelectionIntoArgument();
812 //=================================================================================
813 // function : enterEvent()
815 //=================================================================================
816 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
818 if (!GroupConstructors->isEnabled())
819 ActivateThisDialog();
822 //=================================================================================
823 // function : closeEvent()
825 //=================================================================================
826 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
828 /* same than click on cancel button */
832 //=================================================================================
833 // function : hideEvent()
834 // purpose : caused by ESC key
835 //=================================================================================
836 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
842 //=================================================================================
843 // function : onSelectMesh()
845 //=================================================================================
846 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
849 TextLabelElements->setText(tr("SMESH_NAME"));
851 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
852 myFilterBtn->setEnabled(!toSelectMesh);
854 if (myEditCurrentArgument != LineEditElements) {
855 LineEditElements->clear();
859 mySelectionMgr->clearFilters();
860 SMESH::SetPointRepresentation(false);
863 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
864 aViewWindow->SetSelectionMode(ActorSelection);
865 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
866 LineEditElements->setReadOnly(true);
867 LineEditElements->setValidator(0);
869 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
870 aViewWindow->SetSelectionMode( CellSelection );
871 LineEditElements->setReadOnly(false);
872 LineEditElements->setValidator(myIdValidator);
873 onTextChange(LineEditElements->text());
876 SelectionIntoArgument();
879 //=================================================================================
880 // function : IsAxisOk()
882 //=================================================================================
883 bool SMESHGUI_RotationDlg::IsAxisOk()
885 return (SpinBox_DX->GetValue() != 0 ||
886 SpinBox_DY->GetValue() != 0 ||
887 SpinBox_DZ->GetValue() != 0);
890 //=================================================================================
891 // function : onVectorChanged()
893 //=================================================================================
894 void SMESHGUI_RotationDlg::onVectorChanged()
897 buttonOk->setEnabled(true);
898 buttonApply->setEnabled(true);
900 buttonOk->setEnabled(false);
901 buttonApply->setEnabled(false);
906 //=======================================================================
907 //function : onActionClicked
908 //purpose : slot called when an action type changed
909 //=======================================================================
911 void SMESHGUI_RotationDlg::onActionClicked(int button)
914 case MOVE_ELEMS_BUTTON:
915 MakeGroupsCheck->setEnabled(false);
916 LineEditNewMesh->setEnabled(false);
918 case COPY_ELEMS_BUTTON:
919 LineEditNewMesh->setEnabled(false);
920 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
921 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
922 MakeGroupsCheck->setEnabled(true);
924 MakeGroupsCheck->setEnabled(false);
926 case MAKE_MESH_BUTTON:
927 LineEditNewMesh->setEnabled(true);
928 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
929 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
930 MakeGroupsCheck->setEnabled(true);
932 MakeGroupsCheck->setEnabled(false);
938 //=======================================================================
939 //function : setNewMeshName
940 //purpose : update contents of LineEditNewMesh
941 //=======================================================================
943 void SMESHGUI_RotationDlg::setNewMeshName()
945 LineEditNewMesh->setText("");
946 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
948 if ( CheckBoxMesh->isChecked() ) {
949 name = LineEditElements->text();
952 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
953 name = meshSO->GetName().c_str();
955 if ( !name.isEmpty() )
956 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
960 //=================================================================================
961 // function : keyPressEvent()
963 //=================================================================================
964 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
966 QDialog::keyPressEvent( e );
967 if ( e->isAccepted() )
970 if ( e->key() == Qt::Key_F1 ) {
976 //=================================================================================
977 // function : setFilters()
978 // purpose : SLOT. Called when "Filter" button pressed.
979 //=================================================================================
980 void SMESHGUI_RotationDlg::setFilters()
982 if(myMesh->_is_nil()) {
983 SUIT_MessageBox::critical(this,
985 tr("NO_MESH_SELECTED"));
989 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
991 myFilterDlg->SetSelection();
992 myFilterDlg->SetMesh( myMesh );
993 myFilterDlg->SetSourceWg( LineEditElements );
998 //=================================================================================
999 // function : isValid
1001 //=================================================================================
1002 bool SMESHGUI_RotationDlg::isValid()
1007 ok = SpinBox_X->isValid( msg, true ) && ok;
1008 ok = SpinBox_Y->isValid( msg, true ) && ok;
1009 ok = SpinBox_Z->isValid( msg, true ) && ok;
1010 ok = SpinBox_DX->isValid( msg, true ) && ok;
1011 ok = SpinBox_DY->isValid( msg, true ) && ok;
1012 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1013 ok = SpinBox_Angle->isValid( msg, true ) && ok;
1016 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1017 if ( !msg.isEmpty() )
1019 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );