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 <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <SALOME_ListIO.hxx>
56 // SALOME KERNEL includes
57 #include <SALOMEDSClient_SObject.hxx>
60 #include <TColStd_MapOfInteger.hxx>
63 #include <QApplication>
64 #include <QButtonGroup>
68 #include <QPushButton>
69 #include <QRadioButton>
71 #include <QHBoxLayout>
72 #include <QVBoxLayout>
73 #include <QGridLayout>
77 #include <SALOMEconfig.h>
78 #include CORBA_SERVER_HEADER(SMESH_Group)
79 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
81 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
86 //=================================================================================
87 // class : SMESHGUI_RotationDlg()
89 //=================================================================================
90 SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule )
91 : QDialog( SMESH::GetDesktop( theModule ) ),
92 mySMESHGUI( theModule ),
93 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
95 mySelectedObject(SMESH::SMESH_IDSource::_nil())
97 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_ROTATION")));
98 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
101 setAttribute(Qt::WA_DeleteOnClose, true);
102 setWindowTitle(tr("SMESH_ROTATION_TITLE"));
103 setSizeGripEnabled(true);
105 QVBoxLayout* SMESHGUI_RotationDlgLayout = new QVBoxLayout(this);
106 SMESHGUI_RotationDlgLayout->setSpacing(SPACING);
107 SMESHGUI_RotationDlgLayout->setMargin(MARGIN);
109 /***************************************************************/
110 GroupConstructors = new QGroupBox(tr("SMESH_ROTATION"), this);
111 QButtonGroup* ButtonGroup = new QButtonGroup(this);
112 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
113 GroupConstructorsLayout->setSpacing(SPACING);
114 GroupConstructorsLayout->setMargin(MARGIN);
116 RadioButton1= new QRadioButton(GroupConstructors);
117 RadioButton1->setIcon(image0);
119 GroupConstructorsLayout->addWidget(RadioButton1);
120 ButtonGroup->addButton(RadioButton1, 0);
122 /***************************************************************/
123 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
124 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
125 GroupArgumentsLayout->setSpacing(SPACING);
126 GroupArgumentsLayout->setMargin(MARGIN);
128 myIdValidator = new SMESHGUI_IdValidator(this);
130 // Controls for elements selection
131 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
132 SelectElementsButton = new QPushButton(GroupArguments);
133 SelectElementsButton->setIcon(image1);
134 LineEditElements = new QLineEdit(GroupArguments);
135 LineEditElements->setValidator(myIdValidator);
136 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
137 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
139 // Control for the whole mesh selection
140 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
142 // Controls for axis defining
143 GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
144 QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
145 GroupAxisLayout->setSpacing(SPACING);
146 GroupAxisLayout->setMargin(MARGIN);
148 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
149 SelectPointButton = new QPushButton(GroupAxis);
150 SelectPointButton->setIcon(image1);
152 TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
153 SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
154 TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
155 SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
156 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
157 SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
159 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
160 SelectVectorButton = new QPushButton(GroupAxis);
161 SelectVectorButton->setIcon(image1);
163 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
164 SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
165 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
166 SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
167 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
168 SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
170 GroupAxisLayout->addWidget(TextLabelPoint, 0, 0);
171 GroupAxisLayout->addWidget(SelectPointButton, 0, 1);
172 GroupAxisLayout->addWidget(TextLabelX, 0, 2);
173 GroupAxisLayout->addWidget(SpinBox_X, 0, 3);
174 GroupAxisLayout->addWidget(TextLabelY, 0, 4);
175 GroupAxisLayout->addWidget(SpinBox_Y, 0, 5);
176 GroupAxisLayout->addWidget(TextLabelZ, 0, 6);
177 GroupAxisLayout->addWidget(SpinBox_Z, 0, 7);
178 GroupAxisLayout->addWidget(TextLabelVector, 1, 0);
179 GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
180 GroupAxisLayout->addWidget(TextLabelDX, 1, 2);
181 GroupAxisLayout->addWidget(SpinBox_DX, 1, 3);
182 GroupAxisLayout->addWidget(TextLabelDY, 1, 4);
183 GroupAxisLayout->addWidget(SpinBox_DY, 1, 5);
184 GroupAxisLayout->addWidget(TextLabelDZ, 1, 6);
185 GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7);
187 // Controls for angle defining
188 TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupArguments);
189 SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments);
192 ActionBox = new QGroupBox(GroupArguments);
193 ActionGroup = new QButtonGroup(GroupArguments);
194 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
195 ActionBoxLayout->setSpacing(SPACING);
196 ActionBoxLayout->setMargin(MARGIN);
198 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
199 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
200 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
202 ActionBoxLayout->addWidget(aMoveElements);
203 ActionBoxLayout->addWidget(aCopyElements);
204 ActionBoxLayout->addWidget(aCreateMesh);
205 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
206 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
207 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
209 // CheckBox for groups generation
210 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
212 // Name of a mesh to create
213 LineEditNewMesh = new QLineEdit(GroupArguments);
215 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
216 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
217 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
218 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
219 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
220 GroupArgumentsLayout->addWidget(GroupAxis, 2, 0, 1, 4);
221 GroupArgumentsLayout->addWidget(TextLabelAngle, 3, 0, 1, 2);
222 GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
223 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 3);
224 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 3);
225 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 3);
227 /***************************************************************/
228 GroupButtons = new QGroupBox(this);
229 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
230 GroupButtonsLayout->setSpacing(SPACING);
231 GroupButtonsLayout->setMargin(MARGIN);
233 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
234 buttonOk->setAutoDefault(true);
235 buttonOk->setDefault(true);
236 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
237 buttonApply->setAutoDefault(true);
238 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
239 buttonCancel->setAutoDefault(true);
240 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
241 buttonHelp->setAutoDefault(true);
243 GroupButtonsLayout->addWidget(buttonOk);
244 GroupButtonsLayout->addSpacing(10);
245 GroupButtonsLayout->addWidget(buttonApply);
246 GroupButtonsLayout->addSpacing(10);
247 GroupButtonsLayout->addStretch();
248 GroupButtonsLayout->addWidget(buttonCancel);
249 GroupButtonsLayout->addWidget(buttonHelp);
251 /***************************************************************/
252 SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors);
253 SMESHGUI_RotationDlgLayout->addWidget(GroupArguments);
254 SMESHGUI_RotationDlgLayout->addWidget(GroupButtons);
256 /* Initialisations */
257 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
258 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
259 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
260 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
261 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
262 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
264 SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, 3);
267 RadioButton1->setChecked(true);
269 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
271 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
273 // Costruction of the logical filter
274 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
275 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
277 QList<SUIT_SelectionFilter*> aListOfFilters;
278 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
279 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
281 myMeshOrSubMeshOrGroupFilter =
282 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
284 myHelpFileName = "rotation_page.html";
288 /* signals and slots connections */
289 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
290 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
291 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
292 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
294 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
295 connect(SelectPointButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
296 connect(SelectVectorButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
298 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
299 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
300 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
302 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
303 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
304 /* to close dialog if study change */
305 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
306 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
307 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
308 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
310 onActionClicked(MOVE_ELEMS_BUTTON);
313 //=================================================================================
314 // function : ~SMESHGUI_RotationDlg()
315 // purpose : Destroys the object and frees any allocated resources
316 //=================================================================================
317 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
320 myFilterDlg->setParent( 0 );
326 //=================================================================================
329 //=================================================================================
330 void SMESHGUI_RotationDlg::Init (bool ResetControls)
334 myEditCurrentArgument = (QWidget*)LineEditElements;
335 LineEditElements->setFocus();
339 buttonOk->setEnabled(false);
340 buttonApply->setEnabled(false);
343 myMesh = SMESH::SMESH_Mesh::_nil();
346 SpinBox_X->SetValue(0.0);
347 SpinBox_Y->SetValue(0.0);
348 SpinBox_Z->SetValue(0.0);
349 SpinBox_DX->SetValue(0.0);
350 SpinBox_DY->SetValue(0.0);
351 SpinBox_DZ->SetValue(0.0);
353 SpinBox_Angle->SetValue(45);
355 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
356 CheckBoxMesh->setChecked(false);
357 // MakeGroupsCheck->setChecked(false);
358 // MakeGroupsCheck->setEnabled(false);
359 // onSelectMesh(false);
362 onSelectMesh(CheckBoxMesh->isChecked());
365 //=================================================================================
366 // function : ClickOnApply()
368 //=================================================================================
369 bool SMESHGUI_RotationDlg::ClickOnApply()
371 if (mySMESHGUI->isActiveStudyLocked())
377 if (myNbOkElements && IsAxisOk()) {
378 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
380 SMESH::long_array_var anElementsId = new SMESH::long_array;
382 anElementsId->length(aListElementsId.count());
383 for (int i = 0; i < aListElementsId.count(); i++)
384 anElementsId[i] = aListElementsId[i].toInt();
386 SMESH::AxisStruct anAxis;
388 anAxis.x = SpinBox_X->GetValue();
389 anAxis.y = SpinBox_Y->GetValue();
390 anAxis.z = SpinBox_Z->GetValue();;
391 anAxis.vx = SpinBox_DX->GetValue();
392 anAxis.vy = SpinBox_DY->GetValue();
393 anAxis.vz = SpinBox_DZ->GetValue();
395 double anAngle = (SpinBox_Angle->GetValue())*PI/180;
397 QStringList aParameters;
398 aParameters << SpinBox_X->text();
399 aParameters << SpinBox_Y->text();
400 aParameters << SpinBox_Z->text();
401 aParameters << SpinBox_DX->text();
402 aParameters << SpinBox_DY->text();
403 aParameters << SpinBox_DZ->text();
404 aParameters << SpinBox_Angle->text();
406 int actionButton = ActionGroup->checkedId();
407 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
409 SUIT_OverrideCursor aWaitCursor;
410 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
411 switch ( actionButton ) {
412 case MOVE_ELEMS_BUTTON:
413 if(CheckBoxMesh->isChecked())
414 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, false);
416 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
417 if( !myMesh->_is_nil())
418 myMesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
420 case COPY_ELEMS_BUTTON:
422 SMESH::ListOfGroups_var groups;
423 if(CheckBoxMesh->isChecked())
424 groups = aMeshEditor->RotateObjectMakeGroups(mySelectedObject, anAxis, anAngle);
426 groups = aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
429 if(CheckBoxMesh->isChecked())
430 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, true);
432 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
434 if( !myMesh->_is_nil())
435 myMesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
437 case MAKE_MESH_BUTTON:
438 SMESH::SMESH_Mesh_var mesh;
439 if(CheckBoxMesh->isChecked())
440 mesh = aMeshEditor->RotateObjectMakeMesh(mySelectedObject, anAxis, anAngle, makeGroups,
441 LineEditNewMesh->text().toLatin1().data());
443 mesh = aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
444 LineEditNewMesh->text().toLatin1().data());
445 if( !mesh->_is_nil())
446 mesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
452 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
453 actionButton == MAKE_MESH_BUTTON )
454 mySMESHGUI->updateObjBrowser(true); // new groups may appear
456 mySelectedObject = SMESH::SMESH_IDSource::_nil();
457 SelectionIntoArgument();
463 //=================================================================================
464 // function : ClickOnOk()
466 //=================================================================================
467 void SMESHGUI_RotationDlg::ClickOnOk()
473 //=================================================================================
474 // function : ClickOnCancel()
476 //=================================================================================
477 void SMESHGUI_RotationDlg::ClickOnCancel()
479 disconnect(mySelectionMgr, 0, this, 0);
480 mySelectionMgr->clearFilters();
481 //mySelectionMgr->clearSelected();
482 if (SMESH::GetCurrentVtkView()) {
483 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
484 SMESH::SetPointRepresentation(false);
486 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
487 aViewWindow->SetSelectionMode(ActorSelection);
488 mySMESHGUI->ResetState();
492 //=================================================================================
493 // function : ClickOnHelp()
495 //=================================================================================
496 void SMESHGUI_RotationDlg::ClickOnHelp()
498 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
500 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
504 platform = "winapplication";
506 platform = "application";
508 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
509 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
510 arg(app->resourceMgr()->stringValue("ExternalBrowser",
512 arg(myHelpFileName));
516 //=======================================================================
517 // function : onTextChange()
519 //=======================================================================
520 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
522 QLineEdit* send = (QLineEdit*)sender();
527 if (send == LineEditElements)
530 buttonOk->setEnabled(false);
531 buttonApply->setEnabled(false);
533 // hilight entered elements
534 SMDS_Mesh* aMesh = 0;
536 aMesh = myActor->GetObject()->GetMesh();
539 if (send == LineEditElements) {
540 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
542 TColStd_MapOfInteger newIndices;
544 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
545 for (int i = 0; i < aListId.count(); i++) {
546 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
548 newIndices.Add(e->GetID());
552 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
553 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
554 aViewWindow->highlight( anIO, true, true );
556 myElementsId = theNewText;
560 if (myNbOkElements && IsAxisOk()) {
561 buttonOk->setEnabled(true);
562 buttonApply->setEnabled(true);
568 //=================================================================================
569 // function : SelectionIntoArgument()
570 // purpose : Called when selection as changed or other case
571 //=================================================================================
572 void SMESHGUI_RotationDlg::SelectionIntoArgument()
578 QString aString = "";
581 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
582 LineEditElements->setText(aString);
584 buttonOk->setEnabled(false);
585 buttonApply->setEnabled(false);
589 if (!GroupButtons->isEnabled()) // inactive
594 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
596 int nbSel = aList.Extent();
600 Handle(SALOME_InteractiveObject) IO = aList.First();
601 myMesh = SMESH::GetMeshByIO(IO);
602 if (myMesh->_is_nil())
605 myActor = SMESH::FindActorByObject(myMesh);
607 myActor = SMESH::FindActorByEntry(IO->getEntry());
613 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
616 // MakeGroups is available if there are groups and "Copy"
617 if ( myMesh->NbGroups() == 0 ) {
618 MakeGroupsCheck->setChecked(false);
619 MakeGroupsCheck->setEnabled(false);
621 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
622 MakeGroupsCheck->setEnabled(true);
624 if (CheckBoxMesh->isChecked()) {
625 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
627 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
628 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
634 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
638 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
639 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
641 myElementsId += QString(" %1").arg(i);
645 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
647 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
649 // get IDs from submesh
650 SMESH::long_array_var anElementsIds = new SMESH::long_array;
651 anElementsIds = aSubMesh->GetElementsId();
652 for (int i = 0; i < anElementsIds->length(); i++) {
653 myElementsId += QString(" %1").arg(anElementsIds[i]);
655 aNbUnits = anElementsIds->length();
658 SMESH::SMESH_GroupBase_var aGroup =
659 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
660 if (aGroup->_is_nil())
663 // get IDs from smesh group
664 SMESH::long_array_var anElementsIds = new SMESH::long_array;
665 anElementsIds = aGroup->GetListOfID();
666 for (int i = 0; i < anElementsIds->length(); i++) {
667 myElementsId += QString(" %1").arg(anElementsIds[i]);
669 aNbUnits = anElementsIds->length();
673 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
674 myElementsId = aString;
679 myNbOkElements = true;
682 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
686 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
690 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
698 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
699 SpinBox_X->SetValue(x);
700 SpinBox_Y->SetValue(y);
701 SpinBox_Z->SetValue(z);
702 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
703 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
704 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
705 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
710 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
711 LineEditElements->setText(aString);
712 LineEditElements->repaint();
713 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
714 LineEditElements->setEnabled(true);
720 if (myNbOkElements && IsAxisOk()) {
721 buttonOk->setEnabled(true);
722 buttonApply->setEnabled(true);
726 //=================================================================================
727 // function : SetEditCurrentArgument()
729 //=================================================================================
730 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
732 QPushButton* send = (QPushButton*)sender();
734 disconnect(mySelectionMgr, 0, this, 0);
735 mySelectionMgr->clearSelected();
736 mySelectionMgr->clearFilters();
738 switch (myConstructorId) {
739 case 0: /* default constructor */
741 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
742 if (send == SelectElementsButton) {
743 myEditCurrentArgument = (QWidget*)LineEditElements;
744 SMESH::SetPointRepresentation(false);
745 if (CheckBoxMesh->isChecked()) {
747 aViewWindow->SetSelectionMode(ActorSelection);
748 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
751 aViewWindow->SetSelectionMode( CellSelection );
753 } else if (send == SelectPointButton) {
754 myEditCurrentArgument = (QWidget*)SpinBox_X;
755 SMESH::SetPointRepresentation(true);
757 aViewWindow->SetSelectionMode( NodeSelection );
758 } else if (send == SelectVectorButton) {
759 myEditCurrentArgument = (QWidget*)SpinBox_DX;
760 SMESH::SetPointRepresentation(true);
762 aViewWindow->SetSelectionMode( NodeSelection );
769 myEditCurrentArgument->setFocus();
770 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
771 SelectionIntoArgument();
774 //=================================================================================
775 // function : DeactivateActiveDialog()
777 //=================================================================================
778 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
780 if (GroupConstructors->isEnabled()) {
781 GroupConstructors->setEnabled(false);
782 GroupArguments->setEnabled(false);
783 GroupButtons->setEnabled(false);
784 mySMESHGUI->ResetState();
785 mySMESHGUI->SetActiveDialogBox(0);
789 //=================================================================================
790 // function : ActivateThisDialog()
792 //=================================================================================
793 void SMESHGUI_RotationDlg::ActivateThisDialog()
795 /* Emit a signal to deactivate the active dialog */
796 mySMESHGUI->EmitSignalDeactivateDialog();
797 GroupConstructors->setEnabled(true);
798 GroupArguments->setEnabled(true);
799 GroupButtons->setEnabled(true);
801 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
803 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
804 aViewWindow->SetSelectionMode( CellSelection );
805 SelectionIntoArgument();
808 //=================================================================================
809 // function : enterEvent()
811 //=================================================================================
812 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
814 if (!GroupConstructors->isEnabled())
815 ActivateThisDialog();
818 //=================================================================================
819 // function : closeEvent()
821 //=================================================================================
822 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
824 /* same than click on cancel button */
828 //=================================================================================
829 // function : hideEvent()
830 // purpose : caused by ESC key
831 //=================================================================================
832 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
838 //=================================================================================
839 // function : onSelectMesh()
841 //=================================================================================
842 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
845 TextLabelElements->setText(tr("SMESH_NAME"));
847 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
848 myFilterBtn->setEnabled(!toSelectMesh);
850 if (myEditCurrentArgument != LineEditElements) {
851 LineEditElements->clear();
855 mySelectionMgr->clearFilters();
856 SMESH::SetPointRepresentation(false);
859 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
860 aViewWindow->SetSelectionMode(ActorSelection);
861 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
862 LineEditElements->setReadOnly(true);
863 LineEditElements->setValidator(0);
865 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
866 aViewWindow->SetSelectionMode( CellSelection );
867 LineEditElements->setReadOnly(false);
868 LineEditElements->setValidator(myIdValidator);
869 onTextChange(LineEditElements->text());
872 SelectionIntoArgument();
875 //=================================================================================
876 // function : IsAxisOk()
878 //=================================================================================
879 bool SMESHGUI_RotationDlg::IsAxisOk()
881 return (SpinBox_DX->GetValue() != 0 ||
882 SpinBox_DY->GetValue() != 0 ||
883 SpinBox_DZ->GetValue() != 0);
886 //=================================================================================
887 // function : onVectorChanged()
889 //=================================================================================
890 void SMESHGUI_RotationDlg::onVectorChanged()
893 buttonOk->setEnabled(true);
894 buttonApply->setEnabled(true);
896 buttonOk->setEnabled(false);
897 buttonApply->setEnabled(false);
902 //=======================================================================
903 //function : onActionClicked
904 //purpose : slot called when an action type changed
905 //=======================================================================
907 void SMESHGUI_RotationDlg::onActionClicked(int button)
910 case MOVE_ELEMS_BUTTON:
911 MakeGroupsCheck->setEnabled(false);
912 LineEditNewMesh->setEnabled(false);
914 case COPY_ELEMS_BUTTON:
915 LineEditNewMesh->setEnabled(false);
916 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
917 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
918 MakeGroupsCheck->setEnabled(true);
920 MakeGroupsCheck->setEnabled(false);
922 case MAKE_MESH_BUTTON:
923 LineEditNewMesh->setEnabled(true);
924 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
925 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
926 MakeGroupsCheck->setEnabled(true);
928 MakeGroupsCheck->setEnabled(false);
934 //=======================================================================
935 //function : setNewMeshName
936 //purpose : update contents of LineEditNewMesh
937 //=======================================================================
939 void SMESHGUI_RotationDlg::setNewMeshName()
941 LineEditNewMesh->setText("");
942 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
944 if ( CheckBoxMesh->isChecked() ) {
945 name = LineEditElements->text();
948 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
949 name = meshSO->GetName().c_str();
951 if ( !name.isEmpty() )
952 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
956 //=================================================================================
957 // function : keyPressEvent()
959 //=================================================================================
960 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
962 QDialog::keyPressEvent( e );
963 if ( e->isAccepted() )
966 if ( e->key() == Qt::Key_F1 ) {
972 //=================================================================================
973 // function : setFilters()
974 // purpose : SLOT. Called when "Filter" button pressed.
975 //=================================================================================
976 void SMESHGUI_RotationDlg::setFilters()
978 if(myMesh->_is_nil()) {
979 SUIT_MessageBox::critical(this,
981 tr("NO_MESH_SELECTED"));
985 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
987 myFilterDlg->SetSelection();
988 myFilterDlg->SetMesh( myMesh );
989 myFilterDlg->SetSourceWg( LineEditElements );
994 //=================================================================================
995 // function : isValid
997 //=================================================================================
998 bool SMESHGUI_RotationDlg::isValid()
1003 ok = SpinBox_X->isValid( msg, true ) && ok;
1004 ok = SpinBox_Y->isValid( msg, true ) && ok;
1005 ok = SpinBox_Z->isValid( msg, true ) && ok;
1006 ok = SpinBox_DX->isValid( msg, true ) && ok;
1007 ok = SpinBox_DY->isValid( msg, true ) && ok;
1008 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1009 ok = SpinBox_Angle->isValid( msg, true ) && ok;
1012 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1013 if ( !msg.isEmpty() )
1015 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );