1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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 // File : SMESHGUI_RotationDlg.cxx
23 // 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"
36 #include <SMESH_Actor.h>
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_LogicalFilter.hxx>
39 #include <SMDS_Mesh.hxx>
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_ResourceMgr.h>
47 #include <LightApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
50 #include <SVTK_ViewModel.h>
51 #include <SVTK_ViewWindow.h>
52 #include <SALOME_ListIO.hxx>
54 // SALOME KERNEL includes
55 #include <SALOMEDSClient_SObject.hxx>
58 #include <TColStd_MapOfInteger.hxx>
61 #include <QApplication>
62 #include <QButtonGroup>
66 #include <QPushButton>
67 #include <QRadioButton>
69 #include <QHBoxLayout>
70 #include <QVBoxLayout>
71 #include <QGridLayout>
75 #include <SALOMEconfig.h>
76 #include CORBA_SERVER_HEADER(SMESH_Group)
77 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
79 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
84 //=================================================================================
85 // class : SMESHGUI_RotationDlg()
87 //=================================================================================
88 SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule )
89 : QDialog( SMESH::GetDesktop( theModule ) ),
90 mySMESHGUI( theModule ),
91 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
93 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_ROTATION")));
94 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
97 setAttribute(Qt::WA_DeleteOnClose, true);
98 setWindowTitle(tr("SMESH_ROTATION_TITLE"));
99 setSizeGripEnabled(true);
101 QVBoxLayout* SMESHGUI_RotationDlgLayout = new QVBoxLayout(this);
102 SMESHGUI_RotationDlgLayout->setSpacing(SPACING);
103 SMESHGUI_RotationDlgLayout->setMargin(MARGIN);
105 /***************************************************************/
106 GroupConstructors = new QGroupBox(tr("SMESH_ROTATION"), this);
107 QButtonGroup* ButtonGroup = new QButtonGroup(this);
108 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
109 GroupConstructorsLayout->setSpacing(SPACING);
110 GroupConstructorsLayout->setMargin(MARGIN);
112 RadioButton1= new QRadioButton(GroupConstructors);
113 RadioButton1->setIcon(image0);
115 GroupConstructorsLayout->addWidget(RadioButton1);
116 ButtonGroup->addButton(RadioButton1, 0);
118 /***************************************************************/
119 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
120 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
121 GroupArgumentsLayout->setSpacing(SPACING);
122 GroupArgumentsLayout->setMargin(MARGIN);
124 // Controls for elements selection
125 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
126 SelectElementsButton = new QPushButton(GroupArguments);
127 SelectElementsButton->setIcon(image1);
128 LineEditElements = new QLineEdit(GroupArguments);
129 LineEditElements->setValidator(new SMESHGUI_IdValidator(this));
131 // Control for the whole mesh selection
132 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
134 // Controls for axis defining
135 GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
136 QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
137 GroupAxisLayout->setSpacing(SPACING);
138 GroupAxisLayout->setMargin(MARGIN);
140 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
141 SelectPointButton = new QPushButton(GroupAxis);
142 SelectPointButton->setIcon(image1);
144 TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
145 SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
146 TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
147 SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
148 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
149 SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
151 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
152 SelectVectorButton = new QPushButton(GroupAxis);
153 SelectVectorButton->setIcon(image1);
155 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
156 SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
157 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
158 SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
159 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
160 SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
162 GroupAxisLayout->addWidget(TextLabelPoint, 0, 0);
163 GroupAxisLayout->addWidget(SelectPointButton, 0, 1);
164 GroupAxisLayout->addWidget(TextLabelX, 0, 2);
165 GroupAxisLayout->addWidget(SpinBox_X, 0, 3);
166 GroupAxisLayout->addWidget(TextLabelY, 0, 4);
167 GroupAxisLayout->addWidget(SpinBox_Y, 0, 5);
168 GroupAxisLayout->addWidget(TextLabelZ, 0, 6);
169 GroupAxisLayout->addWidget(SpinBox_Z, 0, 7);
170 GroupAxisLayout->addWidget(TextLabelVector, 1, 0);
171 GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
172 GroupAxisLayout->addWidget(TextLabelDX, 1, 2);
173 GroupAxisLayout->addWidget(SpinBox_DX, 1, 3);
174 GroupAxisLayout->addWidget(TextLabelDY, 1, 4);
175 GroupAxisLayout->addWidget(SpinBox_DY, 1, 5);
176 GroupAxisLayout->addWidget(TextLabelDZ, 1, 6);
177 GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7);
179 // Controls for angle defining
180 TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupArguments);
181 SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments);
184 ActionBox = new QGroupBox(GroupArguments);
185 ActionGroup = new QButtonGroup(GroupArguments);
186 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
187 ActionBoxLayout->setSpacing(SPACING);
188 ActionBoxLayout->setMargin(MARGIN);
190 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
191 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
192 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
194 ActionBoxLayout->addWidget(aMoveElements);
195 ActionBoxLayout->addWidget(aCopyElements);
196 ActionBoxLayout->addWidget(aCreateMesh);
197 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
198 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
199 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
201 // CheckBox for groups generation
202 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
204 // Name of a mesh to create
205 LineEditNewMesh = new QLineEdit(GroupArguments);
207 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
208 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
209 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 2);
210 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
211 GroupArgumentsLayout->addWidget(GroupAxis, 2, 0, 1, 4);
212 GroupArgumentsLayout->addWidget(TextLabelAngle, 3, 0, 1, 2);
213 GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
214 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 3);
215 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 3);
216 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 3);
218 /***************************************************************/
219 GroupButtons = new QGroupBox(this);
220 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
221 GroupButtonsLayout->setSpacing(SPACING);
222 GroupButtonsLayout->setMargin(MARGIN);
224 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
225 buttonOk->setAutoDefault(true);
226 buttonOk->setDefault(true);
227 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
228 buttonApply->setAutoDefault(true);
229 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
230 buttonCancel->setAutoDefault(true);
231 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
232 buttonHelp->setAutoDefault(true);
234 GroupButtonsLayout->addWidget(buttonOk);
235 GroupButtonsLayout->addSpacing(10);
236 GroupButtonsLayout->addWidget(buttonApply);
237 GroupButtonsLayout->addSpacing(10);
238 GroupButtonsLayout->addStretch();
239 GroupButtonsLayout->addWidget(buttonCancel);
240 GroupButtonsLayout->addWidget(buttonHelp);
242 /***************************************************************/
243 SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors);
244 SMESHGUI_RotationDlgLayout->addWidget(GroupArguments);
245 SMESHGUI_RotationDlgLayout->addWidget(GroupButtons);
247 /* Initialisations */
248 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
249 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
250 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
251 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
252 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
253 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
255 SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, 3);
258 RadioButton1->setChecked(true);
260 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
262 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
264 // Costruction of the logical filter
265 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
266 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
268 QList<SUIT_SelectionFilter*> aListOfFilters;
269 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
270 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
272 myMeshOrSubMeshOrGroupFilter =
273 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
275 myHelpFileName = "rotation_page.html";
279 /* signals and slots connections */
280 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
281 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
282 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
283 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
285 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
286 connect(SelectPointButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
287 connect(SelectVectorButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
289 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
290 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
291 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
293 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
294 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
295 /* to close dialog if study change */
296 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
297 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
298 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
299 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
301 onActionClicked(MOVE_ELEMS_BUTTON);
304 //=================================================================================
305 // function : ~SMESHGUI_RotationDlg()
306 // purpose : Destroys the object and frees any allocated resources
307 //=================================================================================
308 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
312 //=================================================================================
315 //=================================================================================
316 void SMESHGUI_RotationDlg::Init (bool ResetControls)
320 myEditCurrentArgument = (QWidget*)LineEditElements;
321 LineEditElements->setFocus();
325 buttonOk->setEnabled(false);
326 buttonApply->setEnabled(false);
329 myMesh = SMESH::SMESH_Mesh::_nil();
332 SpinBox_X->SetValue(0.0);
333 SpinBox_Y->SetValue(0.0);
334 SpinBox_Z->SetValue(0.0);
335 SpinBox_DX->SetValue(0.0);
336 SpinBox_DY->SetValue(0.0);
337 SpinBox_DZ->SetValue(0.0);
339 SpinBox_Angle->SetValue(45);
341 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
342 CheckBoxMesh->setChecked(false);
343 // MakeGroupsCheck->setChecked(false);
344 // MakeGroupsCheck->setEnabled(false);
345 // onSelectMesh(false);
348 onSelectMesh(CheckBoxMesh->isChecked());
351 //=================================================================================
352 // function : ClickOnApply()
354 //=================================================================================
355 void SMESHGUI_RotationDlg::ClickOnApply()
357 if (mySMESHGUI->isActiveStudyLocked())
360 if (myNbOkElements && IsAxisOk()) {
361 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
363 SMESH::long_array_var anElementsId = new SMESH::long_array;
365 anElementsId->length(aListElementsId.count());
366 for (int i = 0; i < aListElementsId.count(); i++)
367 anElementsId[i] = aListElementsId[i].toInt();
369 SMESH::AxisStruct anAxis;
371 anAxis.x = SpinBox_X->GetValue();
372 anAxis.y = SpinBox_Y->GetValue();
373 anAxis.z = SpinBox_Z->GetValue();;
374 anAxis.vx = SpinBox_DX->GetValue();
375 anAxis.vy = SpinBox_DY->GetValue();
376 anAxis.vz = SpinBox_DZ->GetValue();
378 double anAngle = (SpinBox_Angle->GetValue())*PI/180;
379 int actionButton = ActionGroup->checkedId();
380 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
382 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
383 QApplication::setOverrideCursor(Qt::WaitCursor);
384 switch ( actionButton ) {
385 case MOVE_ELEMS_BUTTON:
386 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
388 case COPY_ELEMS_BUTTON:
390 SMESH::ListOfGroups_var groups =
391 aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
393 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
395 case MAKE_MESH_BUTTON:
396 SMESH::SMESH_Mesh_var mesh =
397 aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
398 LineEditNewMesh->text().toLatin1().data());
400 QApplication::restoreOverrideCursor();
405 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
406 actionButton == MAKE_MESH_BUTTON )
407 mySMESHGUI->updateObjBrowser(true); // new groups may appear
409 SelectionIntoArgument();
413 //=================================================================================
414 // function : ClickOnOk()
416 //=================================================================================
417 void SMESHGUI_RotationDlg::ClickOnOk()
423 //=================================================================================
424 // function : ClickOnCancel()
426 //=================================================================================
427 void SMESHGUI_RotationDlg::ClickOnCancel()
429 disconnect(mySelectionMgr, 0, this, 0);
430 mySelectionMgr->clearFilters();
431 //mySelectionMgr->clearSelected();
432 SMESH::SetPointRepresentation(false);
433 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
434 aViewWindow->SetSelectionMode(ActorSelection);
435 mySMESHGUI->ResetState();
439 //=================================================================================
440 // function : ClickOnHelp()
442 //=================================================================================
443 void SMESHGUI_RotationDlg::ClickOnHelp()
445 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
447 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
451 platform = "winapplication";
453 platform = "application";
455 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
456 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
457 arg(app->resourceMgr()->stringValue("ExternalBrowser",
459 arg(myHelpFileName));
463 //=======================================================================
464 // function : onTextChange()
466 //=======================================================================
467 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
469 QLineEdit* send = (QLineEdit*)sender();
474 if (send == LineEditElements)
477 buttonOk->setEnabled(false);
478 buttonApply->setEnabled(false);
480 // hilight entered elements
481 SMDS_Mesh* aMesh = 0;
483 aMesh = myActor->GetObject()->GetMesh();
486 if (send == LineEditElements) {
487 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
489 TColStd_MapOfInteger newIndices;
491 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
492 for (int i = 0; i < aListId.count(); i++) {
493 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
495 newIndices.Add(e->GetID());
499 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
500 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
501 aViewWindow->highlight( anIO, true, true );
503 myElementsId = theNewText;
507 if (myNbOkElements && IsAxisOk()) {
508 buttonOk->setEnabled(true);
509 buttonApply->setEnabled(true);
515 //=================================================================================
516 // function : SelectionIntoArgument()
517 // purpose : Called when selection as changed or other case
518 //=================================================================================
519 void SMESHGUI_RotationDlg::SelectionIntoArgument()
525 QString aString = "";
528 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
529 LineEditElements->setText(aString);
531 buttonOk->setEnabled(false);
532 buttonApply->setEnabled(false);
536 if (!GroupButtons->isEnabled()) // inactive
541 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
543 int nbSel = aList.Extent();
547 Handle(SALOME_InteractiveObject) IO = aList.First();
548 myMesh = SMESH::GetMeshByIO(IO);
549 if (myMesh->_is_nil())
552 myActor = SMESH::FindActorByObject(myMesh);
554 myActor = SMESH::FindActorByEntry(IO->getEntry());
560 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
563 // MakeGroups is available if there are groups and "Copy"
564 if ( myMesh->NbGroups() == 0 ) {
565 MakeGroupsCheck->setChecked(false);
566 MakeGroupsCheck->setEnabled(false);
568 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
569 MakeGroupsCheck->setEnabled(true);
571 if (CheckBoxMesh->isChecked()) {
572 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
574 if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
576 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
580 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
581 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
583 myElementsId += QString(" %1").arg(i);
587 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
589 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
591 // get IDs from submesh
592 SMESH::long_array_var anElementsIds = new SMESH::long_array;
593 anElementsIds = aSubMesh->GetElementsId();
594 for (int i = 0; i < anElementsIds->length(); i++) {
595 myElementsId += QString(" %1").arg(anElementsIds[i]);
597 aNbUnits = anElementsIds->length();
600 SMESH::SMESH_GroupBase_var aGroup =
601 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
602 if (aGroup->_is_nil())
605 // get IDs from smesh group
606 SMESH::long_array_var anElementsIds = new SMESH::long_array;
607 anElementsIds = aGroup->GetListOfID();
608 for (int i = 0; i < anElementsIds->length(); i++) {
609 myElementsId += QString(" %1").arg(anElementsIds[i]);
611 aNbUnits = anElementsIds->length();
614 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
615 myElementsId = aString;
621 myNbOkElements = true;
623 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
627 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
631 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
639 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
640 SpinBox_X->SetValue(x);
641 SpinBox_Y->SetValue(y);
642 SpinBox_Z->SetValue(z);
643 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
644 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
645 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
646 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
651 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
652 LineEditElements->setText(aString);
658 if (myNbOkElements && IsAxisOk()) {
659 buttonOk->setEnabled(true);
660 buttonApply->setEnabled(true);
664 //=================================================================================
665 // function : SetEditCurrentArgument()
667 //=================================================================================
668 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
670 QPushButton* send = (QPushButton*)sender();
672 disconnect(mySelectionMgr, 0, this, 0);
673 mySelectionMgr->clearSelected();
674 mySelectionMgr->clearFilters();
676 switch (myConstructorId) {
677 case 0: /* default constructor */
679 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
680 if (send == SelectElementsButton) {
681 myEditCurrentArgument = (QWidget*)LineEditElements;
682 SMESH::SetPointRepresentation(false);
683 if (CheckBoxMesh->isChecked()) {
685 aViewWindow->SetSelectionMode(ActorSelection);
686 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
689 aViewWindow->SetSelectionMode( CellSelection );
691 } else if (send == SelectPointButton) {
692 myEditCurrentArgument = (QWidget*)SpinBox_X;
693 SMESH::SetPointRepresentation(true);
695 aViewWindow->SetSelectionMode( NodeSelection );
696 } else if (send == SelectVectorButton) {
697 myEditCurrentArgument = (QWidget*)SpinBox_DX;
698 SMESH::SetPointRepresentation(true);
700 aViewWindow->SetSelectionMode( NodeSelection );
706 myEditCurrentArgument->setFocus();
707 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
708 SelectionIntoArgument();
711 //=================================================================================
712 // function : DeactivateActiveDialog()
714 //=================================================================================
715 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
717 if (GroupConstructors->isEnabled()) {
718 GroupConstructors->setEnabled(false);
719 GroupArguments->setEnabled(false);
720 GroupButtons->setEnabled(false);
721 mySMESHGUI->ResetState();
722 mySMESHGUI->SetActiveDialogBox(0);
726 //=================================================================================
727 // function : ActivateThisDialog()
729 //=================================================================================
730 void SMESHGUI_RotationDlg::ActivateThisDialog()
732 /* Emit a signal to deactivate the active dialog */
733 mySMESHGUI->EmitSignalDeactivateDialog();
734 GroupConstructors->setEnabled(true);
735 GroupArguments->setEnabled(true);
736 GroupButtons->setEnabled(true);
738 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
740 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
741 aViewWindow->SetSelectionMode( CellSelection );
742 SelectionIntoArgument();
745 //=================================================================================
746 // function : enterEvent()
748 //=================================================================================
749 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
751 if (!GroupConstructors->isEnabled())
752 ActivateThisDialog();
755 //=================================================================================
756 // function : closeEvent()
758 //=================================================================================
759 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
761 /* same than click on cancel button */
765 //=================================================================================
766 // function : hideEvent()
767 // purpose : caused by ESC key
768 //=================================================================================
769 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
775 //=================================================================================
776 // function : onSelectMesh()
778 //=================================================================================
779 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
782 TextLabelElements->setText(tr("SMESH_NAME"));
784 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
786 if (myEditCurrentArgument != LineEditElements) {
787 LineEditElements->clear();
791 mySelectionMgr->clearFilters();
792 SMESH::SetPointRepresentation(false);
795 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
796 aViewWindow->SetSelectionMode(ActorSelection);
797 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
798 LineEditElements->setReadOnly(true);
800 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
801 aViewWindow->SetSelectionMode( CellSelection );
802 LineEditElements->setReadOnly(false);
803 onTextChange(LineEditElements->text());
806 SelectionIntoArgument();
809 //=================================================================================
810 // function : IsAxisOk()
812 //=================================================================================
813 bool SMESHGUI_RotationDlg::IsAxisOk()
815 return (SpinBox_DX->GetValue() != 0 ||
816 SpinBox_DY->GetValue() != 0 ||
817 SpinBox_DZ->GetValue() != 0);
820 //=================================================================================
821 // function : onVectorChanged()
823 //=================================================================================
824 void SMESHGUI_RotationDlg::onVectorChanged()
827 buttonOk->setEnabled(true);
828 buttonApply->setEnabled(true);
830 buttonOk->setEnabled(false);
831 buttonApply->setEnabled(false);
836 //=======================================================================
837 //function : onActionClicked
838 //purpose : slot called when an action type changed
839 //=======================================================================
841 void SMESHGUI_RotationDlg::onActionClicked(int button)
844 case MOVE_ELEMS_BUTTON:
845 MakeGroupsCheck->setEnabled(false);
846 LineEditNewMesh->setEnabled(false);
848 case COPY_ELEMS_BUTTON:
849 LineEditNewMesh->setEnabled(false);
850 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
851 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
852 MakeGroupsCheck->setEnabled(true);
854 MakeGroupsCheck->setEnabled(false);
856 case MAKE_MESH_BUTTON:
857 LineEditNewMesh->setEnabled(true);
858 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
859 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
860 MakeGroupsCheck->setEnabled(true);
862 MakeGroupsCheck->setEnabled(false);
868 //=======================================================================
869 //function : setNewMeshName
870 //purpose : update contents of LineEditNewMesh
871 //=======================================================================
873 void SMESHGUI_RotationDlg::setNewMeshName()
875 LineEditNewMesh->setText("");
876 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
878 if ( CheckBoxMesh->isChecked() ) {
879 name = LineEditElements->text();
882 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
883 name = meshSO->GetName().c_str();
885 if ( !name.isEmpty() )
886 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
890 //=================================================================================
891 // function : keyPressEvent()
893 //=================================================================================
894 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
896 QDialog::keyPressEvent( e );
897 if ( e->isAccepted() )
900 if ( e->key() == Qt::Key_F1 ) {