1 // Copyright (C) 2007-2008 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
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_RotationDlg.cxx
24 // Author : Michael ZORIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_RotationDlg.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"
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_LogicalFilter.hxx>
40 #include <SMDS_Mesh.hxx>
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>
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
52 #include <SalomeApp_Notebook.h>
54 #include <SVTK_ViewModel.h>
55 #include <SVTK_ViewWindow.h>
56 #include <SALOME_ListIO.hxx>
58 // SALOME KERNEL includes
59 #include <SALOMEDSClient_SObject.hxx>
62 #include <TColStd_MapOfInteger.hxx>
65 #include <QApplication>
66 #include <QButtonGroup>
70 #include <QPushButton>
71 #include <QRadioButton>
73 #include <QHBoxLayout>
74 #include <QVBoxLayout>
75 #include <QGridLayout>
79 #include <SALOMEconfig.h>
80 #include CORBA_SERVER_HEADER(SMESH_Group)
81 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
83 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
88 //=================================================================================
89 // class : SMESHGUI_RotationDlg()
91 //=================================================================================
92 SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule )
93 : QDialog( SMESH::GetDesktop( theModule ) ),
94 SMESHGUI_Helper( theModule ),
95 mySMESHGUI( theModule ),
96 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
98 mySelectedObject(SMESH::SMESH_IDSource::_nil())
100 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_ROTATION")));
101 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
104 setAttribute(Qt::WA_DeleteOnClose, true);
105 setWindowTitle(tr("SMESH_ROTATION_TITLE"));
106 setSizeGripEnabled(true);
108 QVBoxLayout* SMESHGUI_RotationDlgLayout = new QVBoxLayout(this);
109 SMESHGUI_RotationDlgLayout->setSpacing(SPACING);
110 SMESHGUI_RotationDlgLayout->setMargin(MARGIN);
112 /***************************************************************/
113 GroupConstructors = new QGroupBox(tr("SMESH_ROTATION"), this);
114 QButtonGroup* ButtonGroup = new QButtonGroup(this);
115 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
116 GroupConstructorsLayout->setSpacing(SPACING);
117 GroupConstructorsLayout->setMargin(MARGIN);
119 RadioButton1= new QRadioButton(GroupConstructors);
120 RadioButton1->setIcon(image0);
122 GroupConstructorsLayout->addWidget(RadioButton1);
123 ButtonGroup->addButton(RadioButton1, 0);
125 /***************************************************************/
126 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
127 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
128 GroupArgumentsLayout->setSpacing(SPACING);
129 GroupArgumentsLayout->setMargin(MARGIN);
131 myIdValidator = new SMESHGUI_IdValidator(this);
133 // Controls for elements selection
134 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
135 SelectElementsButton = new QPushButton(GroupArguments);
136 SelectElementsButton->setIcon(image1);
137 LineEditElements = new QLineEdit(GroupArguments);
138 LineEditElements->setValidator(myIdValidator);
139 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
140 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
142 // Control for the whole mesh selection
143 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
145 // Controls for axis defining
146 GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
147 QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
148 GroupAxisLayout->setSpacing(SPACING);
149 GroupAxisLayout->setMargin(MARGIN);
151 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
152 SelectPointButton = new QPushButton(GroupAxis);
153 SelectPointButton->setIcon(image1);
155 TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
156 SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
157 TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
158 SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
159 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
160 SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
162 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
163 SelectVectorButton = new QPushButton(GroupAxis);
164 SelectVectorButton->setIcon(image1);
166 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
167 SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
168 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
169 SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
170 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
171 SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
173 GroupAxisLayout->addWidget(TextLabelPoint, 0, 0);
174 GroupAxisLayout->addWidget(SelectPointButton, 0, 1);
175 GroupAxisLayout->addWidget(TextLabelX, 0, 2);
176 GroupAxisLayout->addWidget(SpinBox_X, 0, 3);
177 GroupAxisLayout->addWidget(TextLabelY, 0, 4);
178 GroupAxisLayout->addWidget(SpinBox_Y, 0, 5);
179 GroupAxisLayout->addWidget(TextLabelZ, 0, 6);
180 GroupAxisLayout->addWidget(SpinBox_Z, 0, 7);
181 GroupAxisLayout->addWidget(TextLabelVector, 1, 0);
182 GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
183 GroupAxisLayout->addWidget(TextLabelDX, 1, 2);
184 GroupAxisLayout->addWidget(SpinBox_DX, 1, 3);
185 GroupAxisLayout->addWidget(TextLabelDY, 1, 4);
186 GroupAxisLayout->addWidget(SpinBox_DY, 1, 5);
187 GroupAxisLayout->addWidget(TextLabelDZ, 1, 6);
188 GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7);
190 // Controls for angle defining
191 TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupArguments);
192 SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments);
195 ActionBox = new QGroupBox(GroupArguments);
196 ActionGroup = new QButtonGroup(GroupArguments);
197 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
198 ActionBoxLayout->setSpacing(SPACING);
199 ActionBoxLayout->setMargin(MARGIN);
201 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
202 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
203 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
205 ActionBoxLayout->addWidget(aMoveElements);
206 ActionBoxLayout->addWidget(aCopyElements);
207 ActionBoxLayout->addWidget(aCreateMesh);
208 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
209 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
210 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
212 // CheckBox for groups generation
213 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
215 // Name of a mesh to create
216 LineEditNewMesh = new QLineEdit(GroupArguments);
218 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
219 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
220 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
221 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
222 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
223 GroupArgumentsLayout->addWidget(GroupAxis, 2, 0, 1, 4);
224 GroupArgumentsLayout->addWidget(TextLabelAngle, 3, 0, 1, 2);
225 GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
226 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 3);
227 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 3);
228 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 3);
230 /***************************************************************/
231 GroupButtons = new QGroupBox(this);
232 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
233 GroupButtonsLayout->setSpacing(SPACING);
234 GroupButtonsLayout->setMargin(MARGIN);
236 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
237 buttonOk->setAutoDefault(true);
238 buttonOk->setDefault(true);
239 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
240 buttonApply->setAutoDefault(true);
241 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
242 buttonCancel->setAutoDefault(true);
243 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
244 buttonHelp->setAutoDefault(true);
246 GroupButtonsLayout->addWidget(buttonOk);
247 GroupButtonsLayout->addSpacing(10);
248 GroupButtonsLayout->addWidget(buttonApply);
249 GroupButtonsLayout->addSpacing(10);
250 GroupButtonsLayout->addStretch();
251 GroupButtonsLayout->addWidget(buttonCancel);
252 GroupButtonsLayout->addWidget(buttonHelp);
254 /***************************************************************/
255 SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors);
256 SMESHGUI_RotationDlgLayout->addWidget(GroupArguments);
257 SMESHGUI_RotationDlgLayout->addWidget(GroupButtons);
259 /* Initialisations */
260 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
261 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
262 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
263 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
264 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
265 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
267 SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, 3);
270 RadioButton1->setChecked(true);
272 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
274 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
276 // Costruction of the logical filter
277 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
278 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
280 QList<SUIT_SelectionFilter*> aListOfFilters;
281 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
282 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
284 myMeshOrSubMeshOrGroupFilter =
285 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
287 myHelpFileName = "rotation_page.html";
291 /* signals and slots connections */
292 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
293 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
294 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
295 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
297 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
298 connect(SelectPointButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
299 connect(SelectVectorButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
301 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
302 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
303 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
305 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
306 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
307 /* to close dialog if study change */
308 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
309 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
310 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
311 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
313 onActionClicked(MOVE_ELEMS_BUTTON);
316 //=================================================================================
317 // function : ~SMESHGUI_RotationDlg()
318 // purpose : Destroys the object and frees any allocated resources
319 //=================================================================================
320 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
323 myFilterDlg->setParent( 0 );
329 //=================================================================================
332 //=================================================================================
333 void SMESHGUI_RotationDlg::Init (bool ResetControls)
337 myEditCurrentArgument = (QWidget*)LineEditElements;
338 LineEditElements->setFocus();
342 buttonOk->setEnabled(false);
343 buttonApply->setEnabled(false);
346 myMesh = SMESH::SMESH_Mesh::_nil();
349 SpinBox_X->SetValue(0.0);
350 SpinBox_Y->SetValue(0.0);
351 SpinBox_Z->SetValue(0.0);
352 SpinBox_DX->SetValue(0.0);
353 SpinBox_DY->SetValue(0.0);
354 SpinBox_DZ->SetValue(0.0);
356 SpinBox_Angle->SetValue(45);
358 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
359 CheckBoxMesh->setChecked(false);
360 // MakeGroupsCheck->setChecked(false);
361 // MakeGroupsCheck->setEnabled(false);
362 // onSelectMesh(false);
365 onSelectMesh(CheckBoxMesh->isChecked());
368 //=================================================================================
369 // function : ClickOnApply()
371 //=================================================================================
372 bool SMESHGUI_RotationDlg::ClickOnApply()
374 if (mySMESHGUI->isActiveStudyLocked())
380 if (myNbOkElements && IsAxisOk()) {
381 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
383 SMESH::long_array_var anElementsId = new SMESH::long_array;
385 anElementsId->length(aListElementsId.count());
386 for (int i = 0; i < aListElementsId.count(); i++)
387 anElementsId[i] = aListElementsId[i].toInt();
389 SMESH::AxisStruct anAxis;
391 anAxis.x = SpinBox_X->GetValue();
392 anAxis.y = SpinBox_Y->GetValue();
393 anAxis.z = SpinBox_Z->GetValue();;
394 anAxis.vx = SpinBox_DX->GetValue();
395 anAxis.vy = SpinBox_DY->GetValue();
396 anAxis.vz = SpinBox_DZ->GetValue();
398 double anAngle = (SpinBox_Angle->GetValue())*PI/180;
400 QStringList aParameters;
401 aParameters << SpinBox_X->text();
402 aParameters << SpinBox_Y->text();
403 aParameters << SpinBox_Z->text();
404 aParameters << SpinBox_DX->text();
405 aParameters << SpinBox_DY->text();
406 aParameters << SpinBox_DZ->text();
407 aParameters << SpinBox_Angle->text();
409 int actionButton = ActionGroup->checkedId();
410 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
412 SUIT_OverrideCursor aWaitCursor;
413 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
414 switch ( actionButton ) {
415 case MOVE_ELEMS_BUTTON:
416 if(CheckBoxMesh->isChecked())
417 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, false);
419 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
420 if( !myMesh->_is_nil())
421 getNotebook()->setParameters( myMesh, aParameters );
423 case COPY_ELEMS_BUTTON:
425 SMESH::ListOfGroups_var groups;
426 if(CheckBoxMesh->isChecked())
427 groups = aMeshEditor->RotateObjectMakeGroups(mySelectedObject, anAxis, anAngle);
429 groups = aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
432 if(CheckBoxMesh->isChecked())
433 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, true);
435 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
437 if( !myMesh->_is_nil())
438 getNotebook()->setParameters( myMesh, aParameters );
440 case MAKE_MESH_BUTTON:
441 SMESH::SMESH_Mesh_var mesh;
442 if(CheckBoxMesh->isChecked())
443 mesh = aMeshEditor->RotateObjectMakeMesh(mySelectedObject, anAxis, anAngle, makeGroups,
444 LineEditNewMesh->text().toLatin1().data());
446 mesh = aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
447 LineEditNewMesh->text().toLatin1().data());
448 if( !mesh->_is_nil())
449 getNotebook()->setParameters( mesh, aParameters );
455 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
456 actionButton == MAKE_MESH_BUTTON )
457 mySMESHGUI->updateObjBrowser(true); // new groups may appear
459 mySelectedObject = SMESH::SMESH_IDSource::_nil();
460 SelectionIntoArgument();
466 //=================================================================================
467 // function : ClickOnOk()
469 //=================================================================================
470 void SMESHGUI_RotationDlg::ClickOnOk()
476 //=================================================================================
477 // function : ClickOnCancel()
479 //=================================================================================
480 void SMESHGUI_RotationDlg::ClickOnCancel()
482 disconnect(mySelectionMgr, 0, this, 0);
483 mySelectionMgr->clearFilters();
484 //mySelectionMgr->clearSelected();
485 if (SMESH::GetCurrentVtkView()) {
486 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
487 SMESH::SetPointRepresentation(false);
489 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
490 aViewWindow->SetSelectionMode(ActorSelection);
491 mySMESHGUI->ResetState();
495 //=================================================================================
496 // function : ClickOnHelp()
498 //=================================================================================
499 void SMESHGUI_RotationDlg::ClickOnHelp()
501 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
503 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
507 platform = "winapplication";
509 platform = "application";
511 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
512 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
513 arg(app->resourceMgr()->stringValue("ExternalBrowser",
515 arg(myHelpFileName));
519 //=======================================================================
520 // function : onTextChange()
522 //=======================================================================
523 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
525 QLineEdit* send = (QLineEdit*)sender();
530 if (send == LineEditElements)
533 buttonOk->setEnabled(false);
534 buttonApply->setEnabled(false);
536 // hilight entered elements
537 SMDS_Mesh* aMesh = 0;
539 aMesh = myActor->GetObject()->GetMesh();
542 if (send == LineEditElements) {
543 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
545 TColStd_MapOfInteger newIndices;
547 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
548 for (int i = 0; i < aListId.count(); i++) {
549 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
551 newIndices.Add(e->GetID());
555 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
556 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
557 aViewWindow->highlight( anIO, true, true );
559 myElementsId = theNewText;
563 if (myNbOkElements && IsAxisOk()) {
564 buttonOk->setEnabled(true);
565 buttonApply->setEnabled(true);
571 //=================================================================================
572 // function : SelectionIntoArgument()
573 // purpose : Called when selection as changed or other case
574 //=================================================================================
575 void SMESHGUI_RotationDlg::SelectionIntoArgument()
581 QString aString = "";
584 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
585 LineEditElements->setText(aString);
587 buttonOk->setEnabled(false);
588 buttonApply->setEnabled(false);
592 if (!GroupButtons->isEnabled()) // inactive
597 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
599 int nbSel = aList.Extent();
603 Handle(SALOME_InteractiveObject) IO = aList.First();
604 myMesh = SMESH::GetMeshByIO(IO);
605 if (myMesh->_is_nil())
608 myActor = SMESH::FindActorByObject(myMesh);
610 myActor = SMESH::FindActorByEntry(IO->getEntry());
616 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
619 // MakeGroups is available if there are groups and "Copy"
620 if ( myMesh->NbGroups() == 0 ) {
621 MakeGroupsCheck->setChecked(false);
622 MakeGroupsCheck->setEnabled(false);
624 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
625 MakeGroupsCheck->setEnabled(true);
627 if (CheckBoxMesh->isChecked()) {
628 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
630 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
631 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
637 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
641 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
642 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
644 myElementsId += QString(" %1").arg(i);
648 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
650 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
652 // get IDs from submesh
653 SMESH::long_array_var anElementsIds = new SMESH::long_array;
654 anElementsIds = aSubMesh->GetElementsId();
655 for (int i = 0; i < anElementsIds->length(); i++) {
656 myElementsId += QString(" %1").arg(anElementsIds[i]);
658 aNbUnits = anElementsIds->length();
661 SMESH::SMESH_GroupBase_var aGroup =
662 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
663 if (aGroup->_is_nil())
666 // get IDs from smesh group
667 SMESH::long_array_var anElementsIds = new SMESH::long_array;
668 anElementsIds = aGroup->GetListOfID();
669 for (int i = 0; i < anElementsIds->length(); i++) {
670 myElementsId += QString(" %1").arg(anElementsIds[i]);
672 aNbUnits = anElementsIds->length();
676 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
677 myElementsId = aString;
682 myNbOkElements = true;
685 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
689 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
693 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
701 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
702 SpinBox_X->SetValue(x);
703 SpinBox_Y->SetValue(y);
704 SpinBox_Z->SetValue(z);
705 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
706 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
707 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
708 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
713 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
714 LineEditElements->setText(aString);
715 LineEditElements->repaint();
716 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
717 LineEditElements->setEnabled(true);
723 if (myNbOkElements && IsAxisOk()) {
724 buttonOk->setEnabled(true);
725 buttonApply->setEnabled(true);
729 //=================================================================================
730 // function : SetEditCurrentArgument()
732 //=================================================================================
733 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
735 QPushButton* send = (QPushButton*)sender();
737 disconnect(mySelectionMgr, 0, this, 0);
738 mySelectionMgr->clearSelected();
739 mySelectionMgr->clearFilters();
741 switch (myConstructorId) {
742 case 0: /* default constructor */
744 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
745 if (send == SelectElementsButton) {
746 myEditCurrentArgument = (QWidget*)LineEditElements;
747 SMESH::SetPointRepresentation(false);
748 if (CheckBoxMesh->isChecked()) {
750 aViewWindow->SetSelectionMode(ActorSelection);
751 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
754 aViewWindow->SetSelectionMode( CellSelection );
756 } else if (send == SelectPointButton) {
757 myEditCurrentArgument = (QWidget*)SpinBox_X;
758 SMESH::SetPointRepresentation(true);
760 aViewWindow->SetSelectionMode( NodeSelection );
761 } else if (send == SelectVectorButton) {
762 myEditCurrentArgument = (QWidget*)SpinBox_DX;
763 SMESH::SetPointRepresentation(true);
765 aViewWindow->SetSelectionMode( NodeSelection );
772 myEditCurrentArgument->setFocus();
773 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
774 SelectionIntoArgument();
777 //=================================================================================
778 // function : DeactivateActiveDialog()
780 //=================================================================================
781 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
783 if (GroupConstructors->isEnabled()) {
784 GroupConstructors->setEnabled(false);
785 GroupArguments->setEnabled(false);
786 GroupButtons->setEnabled(false);
787 mySMESHGUI->ResetState();
788 mySMESHGUI->SetActiveDialogBox(0);
792 //=================================================================================
793 // function : ActivateThisDialog()
795 //=================================================================================
796 void SMESHGUI_RotationDlg::ActivateThisDialog()
798 /* Emit a signal to deactivate the active dialog */
799 mySMESHGUI->EmitSignalDeactivateDialog();
800 GroupConstructors->setEnabled(true);
801 GroupArguments->setEnabled(true);
802 GroupButtons->setEnabled(true);
804 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
806 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
807 aViewWindow->SetSelectionMode( CellSelection );
808 SelectionIntoArgument();
811 //=================================================================================
812 // function : enterEvent()
814 //=================================================================================
815 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
817 if (!GroupConstructors->isEnabled())
818 ActivateThisDialog();
821 //=================================================================================
822 // function : closeEvent()
824 //=================================================================================
825 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
827 /* same than click on cancel button */
831 //=================================================================================
832 // function : hideEvent()
833 // purpose : caused by ESC key
834 //=================================================================================
835 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
841 //=================================================================================
842 // function : onSelectMesh()
844 //=================================================================================
845 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
848 TextLabelElements->setText(tr("SMESH_NAME"));
850 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
851 myFilterBtn->setEnabled(!toSelectMesh);
853 if (myEditCurrentArgument != LineEditElements) {
854 LineEditElements->clear();
858 mySelectionMgr->clearFilters();
859 SMESH::SetPointRepresentation(false);
862 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
863 aViewWindow->SetSelectionMode(ActorSelection);
864 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
865 LineEditElements->setReadOnly(true);
866 LineEditElements->setValidator(0);
868 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
869 aViewWindow->SetSelectionMode( CellSelection );
870 LineEditElements->setReadOnly(false);
871 LineEditElements->setValidator(myIdValidator);
872 onTextChange(LineEditElements->text());
875 SelectionIntoArgument();
878 //=================================================================================
879 // function : IsAxisOk()
881 //=================================================================================
882 bool SMESHGUI_RotationDlg::IsAxisOk()
884 return (SpinBox_DX->GetValue() != 0 ||
885 SpinBox_DY->GetValue() != 0 ||
886 SpinBox_DZ->GetValue() != 0);
889 //=================================================================================
890 // function : onVectorChanged()
892 //=================================================================================
893 void SMESHGUI_RotationDlg::onVectorChanged()
896 buttonOk->setEnabled(true);
897 buttonApply->setEnabled(true);
899 buttonOk->setEnabled(false);
900 buttonApply->setEnabled(false);
905 //=======================================================================
906 //function : onActionClicked
907 //purpose : slot called when an action type changed
908 //=======================================================================
910 void SMESHGUI_RotationDlg::onActionClicked(int button)
913 case MOVE_ELEMS_BUTTON:
914 MakeGroupsCheck->setEnabled(false);
915 LineEditNewMesh->setEnabled(false);
917 case COPY_ELEMS_BUTTON:
918 LineEditNewMesh->setEnabled(false);
919 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
920 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
921 MakeGroupsCheck->setEnabled(true);
923 MakeGroupsCheck->setEnabled(false);
925 case MAKE_MESH_BUTTON:
926 LineEditNewMesh->setEnabled(true);
927 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
928 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
929 MakeGroupsCheck->setEnabled(true);
931 MakeGroupsCheck->setEnabled(false);
937 //=======================================================================
938 //function : setNewMeshName
939 //purpose : update contents of LineEditNewMesh
940 //=======================================================================
942 void SMESHGUI_RotationDlg::setNewMeshName()
944 LineEditNewMesh->setText("");
945 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
947 if ( CheckBoxMesh->isChecked() ) {
948 name = LineEditElements->text();
951 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
952 name = meshSO->GetName().c_str();
954 if ( !name.isEmpty() )
955 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
959 //=================================================================================
960 // function : keyPressEvent()
962 //=================================================================================
963 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
965 QDialog::keyPressEvent( e );
966 if ( e->isAccepted() )
969 if ( e->key() == Qt::Key_F1 ) {
975 //=================================================================================
976 // function : setFilters()
977 // purpose : SLOT. Called when "Filter" button pressed.
978 //=================================================================================
979 void SMESHGUI_RotationDlg::setFilters()
981 if(myMesh->_is_nil()) {
982 SUIT_MessageBox::critical(this,
984 tr("NO_MESH_SELECTED"));
988 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
990 myFilterDlg->SetSelection();
991 myFilterDlg->SetMesh( myMesh );
992 myFilterDlg->SetSourceWg( LineEditElements );
997 //=================================================================================
998 // function : isValid
1000 //=================================================================================
1001 bool SMESHGUI_RotationDlg::isValid()
1003 return checkParameters( true, 7,
1004 SpinBox_X, SpinBox_Y, SpinBox_Z,
1005 SpinBox_DX, SpinBox_DY, SpinBox_DZ,