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 myIdValidator = new SMESHGUI_IdValidator(this);
126 // Controls for elements selection
127 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
128 SelectElementsButton = new QPushButton(GroupArguments);
129 SelectElementsButton->setIcon(image1);
130 LineEditElements = new QLineEdit(GroupArguments);
131 LineEditElements->setValidator(myIdValidator);
133 // Control for the whole mesh selection
134 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
136 // Controls for axis defining
137 GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
138 QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
139 GroupAxisLayout->setSpacing(SPACING);
140 GroupAxisLayout->setMargin(MARGIN);
142 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
143 SelectPointButton = new QPushButton(GroupAxis);
144 SelectPointButton->setIcon(image1);
146 TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
147 SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
148 TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
149 SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
150 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
151 SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
153 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
154 SelectVectorButton = new QPushButton(GroupAxis);
155 SelectVectorButton->setIcon(image1);
157 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
158 SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
159 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
160 SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
161 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
162 SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
164 GroupAxisLayout->addWidget(TextLabelPoint, 0, 0);
165 GroupAxisLayout->addWidget(SelectPointButton, 0, 1);
166 GroupAxisLayout->addWidget(TextLabelX, 0, 2);
167 GroupAxisLayout->addWidget(SpinBox_X, 0, 3);
168 GroupAxisLayout->addWidget(TextLabelY, 0, 4);
169 GroupAxisLayout->addWidget(SpinBox_Y, 0, 5);
170 GroupAxisLayout->addWidget(TextLabelZ, 0, 6);
171 GroupAxisLayout->addWidget(SpinBox_Z, 0, 7);
172 GroupAxisLayout->addWidget(TextLabelVector, 1, 0);
173 GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
174 GroupAxisLayout->addWidget(TextLabelDX, 1, 2);
175 GroupAxisLayout->addWidget(SpinBox_DX, 1, 3);
176 GroupAxisLayout->addWidget(TextLabelDY, 1, 4);
177 GroupAxisLayout->addWidget(SpinBox_DY, 1, 5);
178 GroupAxisLayout->addWidget(TextLabelDZ, 1, 6);
179 GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7);
181 // Controls for angle defining
182 TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupArguments);
183 SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments);
186 ActionBox = new QGroupBox(GroupArguments);
187 ActionGroup = new QButtonGroup(GroupArguments);
188 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
189 ActionBoxLayout->setSpacing(SPACING);
190 ActionBoxLayout->setMargin(MARGIN);
192 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
193 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
194 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
196 ActionBoxLayout->addWidget(aMoveElements);
197 ActionBoxLayout->addWidget(aCopyElements);
198 ActionBoxLayout->addWidget(aCreateMesh);
199 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
200 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
201 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
203 // CheckBox for groups generation
204 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
206 // Name of a mesh to create
207 LineEditNewMesh = new QLineEdit(GroupArguments);
209 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
210 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
211 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 2);
212 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
213 GroupArgumentsLayout->addWidget(GroupAxis, 2, 0, 1, 4);
214 GroupArgumentsLayout->addWidget(TextLabelAngle, 3, 0, 1, 2);
215 GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
216 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 3);
217 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 3);
218 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 3);
220 /***************************************************************/
221 GroupButtons = new QGroupBox(this);
222 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
223 GroupButtonsLayout->setSpacing(SPACING);
224 GroupButtonsLayout->setMargin(MARGIN);
226 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
227 buttonOk->setAutoDefault(true);
228 buttonOk->setDefault(true);
229 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
230 buttonApply->setAutoDefault(true);
231 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
232 buttonCancel->setAutoDefault(true);
233 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
234 buttonHelp->setAutoDefault(true);
236 GroupButtonsLayout->addWidget(buttonOk);
237 GroupButtonsLayout->addSpacing(10);
238 GroupButtonsLayout->addWidget(buttonApply);
239 GroupButtonsLayout->addSpacing(10);
240 GroupButtonsLayout->addStretch();
241 GroupButtonsLayout->addWidget(buttonCancel);
242 GroupButtonsLayout->addWidget(buttonHelp);
244 /***************************************************************/
245 SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors);
246 SMESHGUI_RotationDlgLayout->addWidget(GroupArguments);
247 SMESHGUI_RotationDlgLayout->addWidget(GroupButtons);
249 /* Initialisations */
250 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
251 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
252 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
253 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
254 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
255 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
257 SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, 3);
260 RadioButton1->setChecked(true);
262 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
264 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
266 // Costruction of the logical filter
267 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
268 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
270 QList<SUIT_SelectionFilter*> aListOfFilters;
271 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
272 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
274 myMeshOrSubMeshOrGroupFilter =
275 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
277 myHelpFileName = "rotation_page.html";
281 /* signals and slots connections */
282 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
283 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
284 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
285 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
287 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
288 connect(SelectPointButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
289 connect(SelectVectorButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
291 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
292 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
293 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
295 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
296 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
297 /* to close dialog if study change */
298 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
299 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
300 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
301 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
303 onActionClicked(MOVE_ELEMS_BUTTON);
306 //=================================================================================
307 // function : ~SMESHGUI_RotationDlg()
308 // purpose : Destroys the object and frees any allocated resources
309 //=================================================================================
310 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
314 //=================================================================================
317 //=================================================================================
318 void SMESHGUI_RotationDlg::Init (bool ResetControls)
322 myEditCurrentArgument = (QWidget*)LineEditElements;
323 LineEditElements->setFocus();
327 buttonOk->setEnabled(false);
328 buttonApply->setEnabled(false);
331 myMesh = SMESH::SMESH_Mesh::_nil();
334 SpinBox_X->SetValue(0.0);
335 SpinBox_Y->SetValue(0.0);
336 SpinBox_Z->SetValue(0.0);
337 SpinBox_DX->SetValue(0.0);
338 SpinBox_DY->SetValue(0.0);
339 SpinBox_DZ->SetValue(0.0);
341 SpinBox_Angle->SetValue(45);
343 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
344 CheckBoxMesh->setChecked(false);
345 // MakeGroupsCheck->setChecked(false);
346 // MakeGroupsCheck->setEnabled(false);
347 // onSelectMesh(false);
350 onSelectMesh(CheckBoxMesh->isChecked());
353 //=================================================================================
354 // function : ClickOnApply()
356 //=================================================================================
357 void SMESHGUI_RotationDlg::ClickOnApply()
359 if (mySMESHGUI->isActiveStudyLocked())
362 if (myNbOkElements && IsAxisOk()) {
363 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
365 SMESH::long_array_var anElementsId = new SMESH::long_array;
367 anElementsId->length(aListElementsId.count());
368 for (int i = 0; i < aListElementsId.count(); i++)
369 anElementsId[i] = aListElementsId[i].toInt();
371 SMESH::AxisStruct anAxis;
373 anAxis.x = SpinBox_X->GetValue();
374 anAxis.y = SpinBox_Y->GetValue();
375 anAxis.z = SpinBox_Z->GetValue();;
376 anAxis.vx = SpinBox_DX->GetValue();
377 anAxis.vy = SpinBox_DY->GetValue();
378 anAxis.vz = SpinBox_DZ->GetValue();
380 double anAngle = (SpinBox_Angle->GetValue())*PI/180;
381 int actionButton = ActionGroup->checkedId();
382 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
384 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
385 QApplication::setOverrideCursor(Qt::WaitCursor);
386 switch ( actionButton ) {
387 case MOVE_ELEMS_BUTTON:
388 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
390 case COPY_ELEMS_BUTTON:
392 SMESH::ListOfGroups_var groups =
393 aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
395 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
397 case MAKE_MESH_BUTTON:
398 SMESH::SMESH_Mesh_var mesh =
399 aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
400 LineEditNewMesh->text().toLatin1().data());
402 QApplication::restoreOverrideCursor();
407 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
408 actionButton == MAKE_MESH_BUTTON )
409 mySMESHGUI->updateObjBrowser(true); // new groups may appear
411 SelectionIntoArgument();
415 //=================================================================================
416 // function : ClickOnOk()
418 //=================================================================================
419 void SMESHGUI_RotationDlg::ClickOnOk()
425 //=================================================================================
426 // function : ClickOnCancel()
428 //=================================================================================
429 void SMESHGUI_RotationDlg::ClickOnCancel()
431 disconnect(mySelectionMgr, 0, this, 0);
432 mySelectionMgr->clearFilters();
433 //mySelectionMgr->clearSelected();
434 SMESH::SetPointRepresentation(false);
435 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
436 aViewWindow->SetSelectionMode(ActorSelection);
437 mySMESHGUI->ResetState();
441 //=================================================================================
442 // function : ClickOnHelp()
444 //=================================================================================
445 void SMESHGUI_RotationDlg::ClickOnHelp()
447 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
449 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
453 platform = "winapplication";
455 platform = "application";
457 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
458 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
459 arg(app->resourceMgr()->stringValue("ExternalBrowser",
461 arg(myHelpFileName));
465 //=======================================================================
466 // function : onTextChange()
468 //=======================================================================
469 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
471 QLineEdit* send = (QLineEdit*)sender();
476 if (send == LineEditElements)
479 buttonOk->setEnabled(false);
480 buttonApply->setEnabled(false);
482 // hilight entered elements
483 SMDS_Mesh* aMesh = 0;
485 aMesh = myActor->GetObject()->GetMesh();
488 if (send == LineEditElements) {
489 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
491 TColStd_MapOfInteger newIndices;
493 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
494 for (int i = 0; i < aListId.count(); i++) {
495 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
497 newIndices.Add(e->GetID());
501 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
502 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
503 aViewWindow->highlight( anIO, true, true );
505 myElementsId = theNewText;
509 if (myNbOkElements && IsAxisOk()) {
510 buttonOk->setEnabled(true);
511 buttonApply->setEnabled(true);
517 //=================================================================================
518 // function : SelectionIntoArgument()
519 // purpose : Called when selection as changed or other case
520 //=================================================================================
521 void SMESHGUI_RotationDlg::SelectionIntoArgument()
527 QString aString = "";
530 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
531 LineEditElements->setText(aString);
533 buttonOk->setEnabled(false);
534 buttonApply->setEnabled(false);
538 if (!GroupButtons->isEnabled()) // inactive
543 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
545 int nbSel = aList.Extent();
549 Handle(SALOME_InteractiveObject) IO = aList.First();
550 myMesh = SMESH::GetMeshByIO(IO);
551 if (myMesh->_is_nil())
554 myActor = SMESH::FindActorByObject(myMesh);
556 myActor = SMESH::FindActorByEntry(IO->getEntry());
562 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
565 // MakeGroups is available if there are groups and "Copy"
566 if ( myMesh->NbGroups() == 0 ) {
567 MakeGroupsCheck->setChecked(false);
568 MakeGroupsCheck->setEnabled(false);
570 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
571 MakeGroupsCheck->setEnabled(true);
573 if (CheckBoxMesh->isChecked()) {
574 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
576 if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
578 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
582 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
583 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
585 myElementsId += QString(" %1").arg(i);
589 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
591 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
593 // get IDs from submesh
594 SMESH::long_array_var anElementsIds = new SMESH::long_array;
595 anElementsIds = aSubMesh->GetElementsId();
596 for (int i = 0; i < anElementsIds->length(); i++) {
597 myElementsId += QString(" %1").arg(anElementsIds[i]);
599 aNbUnits = anElementsIds->length();
602 SMESH::SMESH_GroupBase_var aGroup =
603 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
604 if (aGroup->_is_nil())
607 // get IDs from smesh group
608 SMESH::long_array_var anElementsIds = new SMESH::long_array;
609 anElementsIds = aGroup->GetListOfID();
610 for (int i = 0; i < anElementsIds->length(); i++) {
611 myElementsId += QString(" %1").arg(anElementsIds[i]);
613 aNbUnits = anElementsIds->length();
616 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
617 myElementsId = aString;
623 myNbOkElements = true;
625 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
629 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
633 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
641 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
642 SpinBox_X->SetValue(x);
643 SpinBox_Y->SetValue(y);
644 SpinBox_Z->SetValue(z);
645 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
646 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
647 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
648 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
653 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
654 LineEditElements->setText(aString);
660 if (myNbOkElements && IsAxisOk()) {
661 buttonOk->setEnabled(true);
662 buttonApply->setEnabled(true);
666 //=================================================================================
667 // function : SetEditCurrentArgument()
669 //=================================================================================
670 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
672 QPushButton* send = (QPushButton*)sender();
674 disconnect(mySelectionMgr, 0, this, 0);
675 mySelectionMgr->clearSelected();
676 mySelectionMgr->clearFilters();
678 switch (myConstructorId) {
679 case 0: /* default constructor */
681 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
682 if (send == SelectElementsButton) {
683 myEditCurrentArgument = (QWidget*)LineEditElements;
684 SMESH::SetPointRepresentation(false);
685 if (CheckBoxMesh->isChecked()) {
687 aViewWindow->SetSelectionMode(ActorSelection);
688 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
691 aViewWindow->SetSelectionMode( CellSelection );
693 } else if (send == SelectPointButton) {
694 myEditCurrentArgument = (QWidget*)SpinBox_X;
695 SMESH::SetPointRepresentation(true);
697 aViewWindow->SetSelectionMode( NodeSelection );
698 } else if (send == SelectVectorButton) {
699 myEditCurrentArgument = (QWidget*)SpinBox_DX;
700 SMESH::SetPointRepresentation(true);
702 aViewWindow->SetSelectionMode( NodeSelection );
708 myEditCurrentArgument->setFocus();
709 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
710 SelectionIntoArgument();
713 //=================================================================================
714 // function : DeactivateActiveDialog()
716 //=================================================================================
717 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
719 if (GroupConstructors->isEnabled()) {
720 GroupConstructors->setEnabled(false);
721 GroupArguments->setEnabled(false);
722 GroupButtons->setEnabled(false);
723 mySMESHGUI->ResetState();
724 mySMESHGUI->SetActiveDialogBox(0);
728 //=================================================================================
729 // function : ActivateThisDialog()
731 //=================================================================================
732 void SMESHGUI_RotationDlg::ActivateThisDialog()
734 /* Emit a signal to deactivate the active dialog */
735 mySMESHGUI->EmitSignalDeactivateDialog();
736 GroupConstructors->setEnabled(true);
737 GroupArguments->setEnabled(true);
738 GroupButtons->setEnabled(true);
740 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
742 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
743 aViewWindow->SetSelectionMode( CellSelection );
744 SelectionIntoArgument();
747 //=================================================================================
748 // function : enterEvent()
750 //=================================================================================
751 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
753 if (!GroupConstructors->isEnabled())
754 ActivateThisDialog();
757 //=================================================================================
758 // function : closeEvent()
760 //=================================================================================
761 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
763 /* same than click on cancel button */
767 //=================================================================================
768 // function : hideEvent()
769 // purpose : caused by ESC key
770 //=================================================================================
771 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
777 //=================================================================================
778 // function : onSelectMesh()
780 //=================================================================================
781 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
784 TextLabelElements->setText(tr("SMESH_NAME"));
786 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
788 if (myEditCurrentArgument != LineEditElements) {
789 LineEditElements->clear();
793 mySelectionMgr->clearFilters();
794 SMESH::SetPointRepresentation(false);
797 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
798 aViewWindow->SetSelectionMode(ActorSelection);
799 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
800 LineEditElements->setReadOnly(true);
801 LineEditElements->setValidator(0);
803 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
804 aViewWindow->SetSelectionMode( CellSelection );
805 LineEditElements->setReadOnly(false);
806 LineEditElements->setValidator(myIdValidator);
807 onTextChange(LineEditElements->text());
810 SelectionIntoArgument();
813 //=================================================================================
814 // function : IsAxisOk()
816 //=================================================================================
817 bool SMESHGUI_RotationDlg::IsAxisOk()
819 return (SpinBox_DX->GetValue() != 0 ||
820 SpinBox_DY->GetValue() != 0 ||
821 SpinBox_DZ->GetValue() != 0);
824 //=================================================================================
825 // function : onVectorChanged()
827 //=================================================================================
828 void SMESHGUI_RotationDlg::onVectorChanged()
831 buttonOk->setEnabled(true);
832 buttonApply->setEnabled(true);
834 buttonOk->setEnabled(false);
835 buttonApply->setEnabled(false);
840 //=======================================================================
841 //function : onActionClicked
842 //purpose : slot called when an action type changed
843 //=======================================================================
845 void SMESHGUI_RotationDlg::onActionClicked(int button)
848 case MOVE_ELEMS_BUTTON:
849 MakeGroupsCheck->setEnabled(false);
850 LineEditNewMesh->setEnabled(false);
852 case COPY_ELEMS_BUTTON:
853 LineEditNewMesh->setEnabled(false);
854 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
855 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
856 MakeGroupsCheck->setEnabled(true);
858 MakeGroupsCheck->setEnabled(false);
860 case MAKE_MESH_BUTTON:
861 LineEditNewMesh->setEnabled(true);
862 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
863 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
864 MakeGroupsCheck->setEnabled(true);
866 MakeGroupsCheck->setEnabled(false);
872 //=======================================================================
873 //function : setNewMeshName
874 //purpose : update contents of LineEditNewMesh
875 //=======================================================================
877 void SMESHGUI_RotationDlg::setNewMeshName()
879 LineEditNewMesh->setText("");
880 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
882 if ( CheckBoxMesh->isChecked() ) {
883 name = LineEditElements->text();
886 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
887 name = meshSO->GetName().c_str();
889 if ( !name.isEmpty() )
890 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
894 //=================================================================================
895 // function : keyPressEvent()
897 //=================================================================================
898 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
900 QDialog::keyPressEvent( e );
901 if ( e->isAccepted() )
904 if ( e->key() == Qt::Key_F1 ) {