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>
46 #include <SUIT_OverrideCursor.h>
48 #include <LightApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
51 #include <SVTK_ViewModel.h>
52 #include <SVTK_ViewWindow.h>
53 #include <SALOME_ListIO.hxx>
55 // SALOME KERNEL includes
56 #include <SALOMEDSClient_SObject.hxx>
59 #include <TColStd_MapOfInteger.hxx>
62 #include <QApplication>
63 #include <QButtonGroup>
67 #include <QPushButton>
68 #include <QRadioButton>
70 #include <QHBoxLayout>
71 #include <QVBoxLayout>
72 #include <QGridLayout>
76 #include <SALOMEconfig.h>
77 #include CORBA_SERVER_HEADER(SMESH_Group)
78 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
80 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
85 //=================================================================================
86 // class : SMESHGUI_RotationDlg()
88 //=================================================================================
89 SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule )
90 : QDialog( SMESH::GetDesktop( theModule ) ),
91 mySMESHGUI( theModule ),
92 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
93 mySelectedObject(SMESH::SMESH_IDSource::_nil())
95 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_ROTATION")));
96 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
99 setAttribute(Qt::WA_DeleteOnClose, true);
100 setWindowTitle(tr("SMESH_ROTATION_TITLE"));
101 setSizeGripEnabled(true);
103 QVBoxLayout* SMESHGUI_RotationDlgLayout = new QVBoxLayout(this);
104 SMESHGUI_RotationDlgLayout->setSpacing(SPACING);
105 SMESHGUI_RotationDlgLayout->setMargin(MARGIN);
107 /***************************************************************/
108 GroupConstructors = new QGroupBox(tr("SMESH_ROTATION"), this);
109 QButtonGroup* ButtonGroup = new QButtonGroup(this);
110 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
111 GroupConstructorsLayout->setSpacing(SPACING);
112 GroupConstructorsLayout->setMargin(MARGIN);
114 RadioButton1= new QRadioButton(GroupConstructors);
115 RadioButton1->setIcon(image0);
117 GroupConstructorsLayout->addWidget(RadioButton1);
118 ButtonGroup->addButton(RadioButton1, 0);
120 /***************************************************************/
121 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
122 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
123 GroupArgumentsLayout->setSpacing(SPACING);
124 GroupArgumentsLayout->setMargin(MARGIN);
126 myIdValidator = new SMESHGUI_IdValidator(this);
128 // Controls for elements selection
129 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
130 SelectElementsButton = new QPushButton(GroupArguments);
131 SelectElementsButton->setIcon(image1);
132 LineEditElements = new QLineEdit(GroupArguments);
133 LineEditElements->setValidator(myIdValidator);
135 // Control for the whole mesh selection
136 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
138 // Controls for axis defining
139 GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
140 QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
141 GroupAxisLayout->setSpacing(SPACING);
142 GroupAxisLayout->setMargin(MARGIN);
144 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
145 SelectPointButton = new QPushButton(GroupAxis);
146 SelectPointButton->setIcon(image1);
148 TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
149 SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
150 TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
151 SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
152 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
153 SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
155 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
156 SelectVectorButton = new QPushButton(GroupAxis);
157 SelectVectorButton->setIcon(image1);
159 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
160 SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
161 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
162 SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
163 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
164 SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
166 GroupAxisLayout->addWidget(TextLabelPoint, 0, 0);
167 GroupAxisLayout->addWidget(SelectPointButton, 0, 1);
168 GroupAxisLayout->addWidget(TextLabelX, 0, 2);
169 GroupAxisLayout->addWidget(SpinBox_X, 0, 3);
170 GroupAxisLayout->addWidget(TextLabelY, 0, 4);
171 GroupAxisLayout->addWidget(SpinBox_Y, 0, 5);
172 GroupAxisLayout->addWidget(TextLabelZ, 0, 6);
173 GroupAxisLayout->addWidget(SpinBox_Z, 0, 7);
174 GroupAxisLayout->addWidget(TextLabelVector, 1, 0);
175 GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
176 GroupAxisLayout->addWidget(TextLabelDX, 1, 2);
177 GroupAxisLayout->addWidget(SpinBox_DX, 1, 3);
178 GroupAxisLayout->addWidget(TextLabelDY, 1, 4);
179 GroupAxisLayout->addWidget(SpinBox_DY, 1, 5);
180 GroupAxisLayout->addWidget(TextLabelDZ, 1, 6);
181 GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7);
183 // Controls for angle defining
184 TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupArguments);
185 SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments);
188 ActionBox = new QGroupBox(GroupArguments);
189 ActionGroup = new QButtonGroup(GroupArguments);
190 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
191 ActionBoxLayout->setSpacing(SPACING);
192 ActionBoxLayout->setMargin(MARGIN);
194 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
195 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
196 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
198 ActionBoxLayout->addWidget(aMoveElements);
199 ActionBoxLayout->addWidget(aCopyElements);
200 ActionBoxLayout->addWidget(aCreateMesh);
201 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
202 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
203 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
205 // CheckBox for groups generation
206 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
208 // Name of a mesh to create
209 LineEditNewMesh = new QLineEdit(GroupArguments);
211 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
212 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
213 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 2);
214 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
215 GroupArgumentsLayout->addWidget(GroupAxis, 2, 0, 1, 4);
216 GroupArgumentsLayout->addWidget(TextLabelAngle, 3, 0, 1, 2);
217 GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
218 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 3);
219 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 3);
220 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 3);
222 /***************************************************************/
223 GroupButtons = new QGroupBox(this);
224 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
225 GroupButtonsLayout->setSpacing(SPACING);
226 GroupButtonsLayout->setMargin(MARGIN);
228 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
229 buttonOk->setAutoDefault(true);
230 buttonOk->setDefault(true);
231 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
232 buttonApply->setAutoDefault(true);
233 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
234 buttonCancel->setAutoDefault(true);
235 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
236 buttonHelp->setAutoDefault(true);
238 GroupButtonsLayout->addWidget(buttonOk);
239 GroupButtonsLayout->addSpacing(10);
240 GroupButtonsLayout->addWidget(buttonApply);
241 GroupButtonsLayout->addSpacing(10);
242 GroupButtonsLayout->addStretch();
243 GroupButtonsLayout->addWidget(buttonCancel);
244 GroupButtonsLayout->addWidget(buttonHelp);
246 /***************************************************************/
247 SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors);
248 SMESHGUI_RotationDlgLayout->addWidget(GroupArguments);
249 SMESHGUI_RotationDlgLayout->addWidget(GroupButtons);
251 /* Initialisations */
252 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
253 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
254 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
255 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
256 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
257 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
259 SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, 3);
262 RadioButton1->setChecked(true);
264 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
266 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
268 // Costruction of the logical filter
269 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
270 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
272 QList<SUIT_SelectionFilter*> aListOfFilters;
273 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
274 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
276 myMeshOrSubMeshOrGroupFilter =
277 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
279 myHelpFileName = "rotation_page.html";
283 /* signals and slots connections */
284 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
285 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
286 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
287 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
289 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
290 connect(SelectPointButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
291 connect(SelectVectorButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
293 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
294 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
295 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
297 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
298 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
299 /* to close dialog if study change */
300 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
301 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
302 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
303 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
305 onActionClicked(MOVE_ELEMS_BUTTON);
308 //=================================================================================
309 // function : ~SMESHGUI_RotationDlg()
310 // purpose : Destroys the object and frees any allocated resources
311 //=================================================================================
312 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
316 //=================================================================================
319 //=================================================================================
320 void SMESHGUI_RotationDlg::Init (bool ResetControls)
324 myEditCurrentArgument = (QWidget*)LineEditElements;
325 LineEditElements->setFocus();
329 buttonOk->setEnabled(false);
330 buttonApply->setEnabled(false);
333 myMesh = SMESH::SMESH_Mesh::_nil();
336 SpinBox_X->SetValue(0.0);
337 SpinBox_Y->SetValue(0.0);
338 SpinBox_Z->SetValue(0.0);
339 SpinBox_DX->SetValue(0.0);
340 SpinBox_DY->SetValue(0.0);
341 SpinBox_DZ->SetValue(0.0);
343 SpinBox_Angle->SetValue(45);
345 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
346 CheckBoxMesh->setChecked(false);
347 // MakeGroupsCheck->setChecked(false);
348 // MakeGroupsCheck->setEnabled(false);
349 // onSelectMesh(false);
352 onSelectMesh(CheckBoxMesh->isChecked());
355 //=================================================================================
356 // function : ClickOnApply()
358 //=================================================================================
359 bool SMESHGUI_RotationDlg::ClickOnApply()
361 if (mySMESHGUI->isActiveStudyLocked())
367 if (myNbOkElements && IsAxisOk()) {
368 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
370 SMESH::long_array_var anElementsId = new SMESH::long_array;
372 anElementsId->length(aListElementsId.count());
373 for (int i = 0; i < aListElementsId.count(); i++)
374 anElementsId[i] = aListElementsId[i].toInt();
376 SMESH::AxisStruct anAxis;
378 anAxis.x = SpinBox_X->GetValue();
379 anAxis.y = SpinBox_Y->GetValue();
380 anAxis.z = SpinBox_Z->GetValue();;
381 anAxis.vx = SpinBox_DX->GetValue();
382 anAxis.vy = SpinBox_DY->GetValue();
383 anAxis.vz = SpinBox_DZ->GetValue();
385 double anAngle = (SpinBox_Angle->GetValue())*PI/180;
387 QStringList aParameters;
388 aParameters << SpinBox_X->text();
389 aParameters << SpinBox_Y->text();
390 aParameters << SpinBox_Z->text();
391 aParameters << SpinBox_DX->text();
392 aParameters << SpinBox_DY->text();
393 aParameters << SpinBox_DZ->text();
394 aParameters << SpinBox_Angle->text();
396 int actionButton = ActionGroup->checkedId();
397 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
399 SUIT_OverrideCursor aWaitCursor;
400 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
401 switch ( actionButton ) {
402 case MOVE_ELEMS_BUTTON:
403 if(CheckBoxMesh->isChecked())
404 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, false);
406 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
407 if( !myMesh->_is_nil())
408 myMesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
410 case COPY_ELEMS_BUTTON:
412 SMESH::ListOfGroups_var groups;
413 if(CheckBoxMesh->isChecked())
414 groups = aMeshEditor->RotateObjectMakeGroups(mySelectedObject, anAxis, anAngle);
416 groups = aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
419 if(CheckBoxMesh->isChecked())
420 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, true);
422 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
424 if( !myMesh->_is_nil())
425 myMesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
427 case MAKE_MESH_BUTTON:
428 SMESH::SMESH_Mesh_var mesh;
429 if(CheckBoxMesh->isChecked())
430 mesh = aMeshEditor->RotateObjectMakeMesh(mySelectedObject, anAxis, anAngle, makeGroups,
431 LineEditNewMesh->text().toLatin1().data());
433 mesh = aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
434 LineEditNewMesh->text().toLatin1().data());
435 if( !mesh->_is_nil())
436 mesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
442 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
443 actionButton == MAKE_MESH_BUTTON )
444 mySMESHGUI->updateObjBrowser(true); // new groups may appear
446 mySelectedObject = SMESH::SMESH_IDSource::_nil();
447 SelectionIntoArgument();
453 //=================================================================================
454 // function : ClickOnOk()
456 //=================================================================================
457 void SMESHGUI_RotationDlg::ClickOnOk()
463 //=================================================================================
464 // function : ClickOnCancel()
466 //=================================================================================
467 void SMESHGUI_RotationDlg::ClickOnCancel()
469 disconnect(mySelectionMgr, 0, this, 0);
470 mySelectionMgr->clearFilters();
471 //mySelectionMgr->clearSelected();
472 SMESH::SetPointRepresentation(false);
473 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
474 aViewWindow->SetSelectionMode(ActorSelection);
475 mySMESHGUI->ResetState();
479 //=================================================================================
480 // function : ClickOnHelp()
482 //=================================================================================
483 void SMESHGUI_RotationDlg::ClickOnHelp()
485 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
487 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
491 platform = "winapplication";
493 platform = "application";
495 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
496 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
497 arg(app->resourceMgr()->stringValue("ExternalBrowser",
499 arg(myHelpFileName));
503 //=======================================================================
504 // function : onTextChange()
506 //=======================================================================
507 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
509 QLineEdit* send = (QLineEdit*)sender();
514 if (send == LineEditElements)
517 buttonOk->setEnabled(false);
518 buttonApply->setEnabled(false);
520 // hilight entered elements
521 SMDS_Mesh* aMesh = 0;
523 aMesh = myActor->GetObject()->GetMesh();
526 if (send == LineEditElements) {
527 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
529 TColStd_MapOfInteger newIndices;
531 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
532 for (int i = 0; i < aListId.count(); i++) {
533 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
535 newIndices.Add(e->GetID());
539 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
540 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
541 aViewWindow->highlight( anIO, true, true );
543 myElementsId = theNewText;
547 if (myNbOkElements && IsAxisOk()) {
548 buttonOk->setEnabled(true);
549 buttonApply->setEnabled(true);
555 //=================================================================================
556 // function : SelectionIntoArgument()
557 // purpose : Called when selection as changed or other case
558 //=================================================================================
559 void SMESHGUI_RotationDlg::SelectionIntoArgument()
565 QString aString = "";
568 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
569 LineEditElements->setText(aString);
571 buttonOk->setEnabled(false);
572 buttonApply->setEnabled(false);
576 if (!GroupButtons->isEnabled()) // inactive
581 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
583 int nbSel = aList.Extent();
587 Handle(SALOME_InteractiveObject) IO = aList.First();
588 myMesh = SMESH::GetMeshByIO(IO);
589 if (myMesh->_is_nil())
592 myActor = SMESH::FindActorByObject(myMesh);
594 myActor = SMESH::FindActorByEntry(IO->getEntry());
600 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
603 // MakeGroups is available if there are groups and "Copy"
604 if ( myMesh->NbGroups() == 0 ) {
605 MakeGroupsCheck->setChecked(false);
606 MakeGroupsCheck->setEnabled(false);
608 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
609 MakeGroupsCheck->setEnabled(true);
611 if (CheckBoxMesh->isChecked()) {
612 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
614 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
615 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
621 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
625 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
626 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
628 myElementsId += QString(" %1").arg(i);
632 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
634 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
636 // get IDs from submesh
637 SMESH::long_array_var anElementsIds = new SMESH::long_array;
638 anElementsIds = aSubMesh->GetElementsId();
639 for (int i = 0; i < anElementsIds->length(); i++) {
640 myElementsId += QString(" %1").arg(anElementsIds[i]);
642 aNbUnits = anElementsIds->length();
645 SMESH::SMESH_GroupBase_var aGroup =
646 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
647 if (aGroup->_is_nil())
650 // get IDs from smesh group
651 SMESH::long_array_var anElementsIds = new SMESH::long_array;
652 anElementsIds = aGroup->GetListOfID();
653 for (int i = 0; i < anElementsIds->length(); i++) {
654 myElementsId += QString(" %1").arg(anElementsIds[i]);
656 aNbUnits = anElementsIds->length();
660 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
661 myElementsId = aString;
666 myNbOkElements = true;
669 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
673 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
677 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
685 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
686 SpinBox_X->SetValue(x);
687 SpinBox_Y->SetValue(y);
688 SpinBox_Z->SetValue(z);
689 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
690 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
691 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
692 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
697 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
698 LineEditElements->setText(aString);
704 if (myNbOkElements && IsAxisOk()) {
705 buttonOk->setEnabled(true);
706 buttonApply->setEnabled(true);
710 //=================================================================================
711 // function : SetEditCurrentArgument()
713 //=================================================================================
714 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
716 QPushButton* send = (QPushButton*)sender();
718 disconnect(mySelectionMgr, 0, this, 0);
719 mySelectionMgr->clearSelected();
720 mySelectionMgr->clearFilters();
722 switch (myConstructorId) {
723 case 0: /* default constructor */
725 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
726 if (send == SelectElementsButton) {
727 myEditCurrentArgument = (QWidget*)LineEditElements;
728 SMESH::SetPointRepresentation(false);
729 if (CheckBoxMesh->isChecked()) {
731 aViewWindow->SetSelectionMode(ActorSelection);
732 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
735 aViewWindow->SetSelectionMode( CellSelection );
737 } else if (send == SelectPointButton) {
738 myEditCurrentArgument = (QWidget*)SpinBox_X;
739 SMESH::SetPointRepresentation(true);
741 aViewWindow->SetSelectionMode( NodeSelection );
742 } else if (send == SelectVectorButton) {
743 myEditCurrentArgument = (QWidget*)SpinBox_DX;
744 SMESH::SetPointRepresentation(true);
746 aViewWindow->SetSelectionMode( NodeSelection );
753 myEditCurrentArgument->setFocus();
754 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
755 SelectionIntoArgument();
758 //=================================================================================
759 // function : DeactivateActiveDialog()
761 //=================================================================================
762 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
764 if (GroupConstructors->isEnabled()) {
765 GroupConstructors->setEnabled(false);
766 GroupArguments->setEnabled(false);
767 GroupButtons->setEnabled(false);
768 mySMESHGUI->ResetState();
769 mySMESHGUI->SetActiveDialogBox(0);
773 //=================================================================================
774 // function : ActivateThisDialog()
776 //=================================================================================
777 void SMESHGUI_RotationDlg::ActivateThisDialog()
779 /* Emit a signal to deactivate the active dialog */
780 mySMESHGUI->EmitSignalDeactivateDialog();
781 GroupConstructors->setEnabled(true);
782 GroupArguments->setEnabled(true);
783 GroupButtons->setEnabled(true);
785 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
787 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
788 aViewWindow->SetSelectionMode( CellSelection );
789 SelectionIntoArgument();
792 //=================================================================================
793 // function : enterEvent()
795 //=================================================================================
796 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
798 if (!GroupConstructors->isEnabled())
799 ActivateThisDialog();
802 //=================================================================================
803 // function : closeEvent()
805 //=================================================================================
806 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
808 /* same than click on cancel button */
812 //=================================================================================
813 // function : hideEvent()
814 // purpose : caused by ESC key
815 //=================================================================================
816 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
822 //=================================================================================
823 // function : onSelectMesh()
825 //=================================================================================
826 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
829 TextLabelElements->setText(tr("SMESH_NAME"));
831 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
833 if (myEditCurrentArgument != LineEditElements) {
834 LineEditElements->clear();
838 mySelectionMgr->clearFilters();
839 SMESH::SetPointRepresentation(false);
842 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
843 aViewWindow->SetSelectionMode(ActorSelection);
844 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
845 LineEditElements->setReadOnly(true);
846 LineEditElements->setValidator(0);
848 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
849 aViewWindow->SetSelectionMode( CellSelection );
850 LineEditElements->setReadOnly(false);
851 LineEditElements->setValidator(myIdValidator);
852 onTextChange(LineEditElements->text());
855 SelectionIntoArgument();
858 //=================================================================================
859 // function : IsAxisOk()
861 //=================================================================================
862 bool SMESHGUI_RotationDlg::IsAxisOk()
864 return (SpinBox_DX->GetValue() != 0 ||
865 SpinBox_DY->GetValue() != 0 ||
866 SpinBox_DZ->GetValue() != 0);
869 //=================================================================================
870 // function : onVectorChanged()
872 //=================================================================================
873 void SMESHGUI_RotationDlg::onVectorChanged()
876 buttonOk->setEnabled(true);
877 buttonApply->setEnabled(true);
879 buttonOk->setEnabled(false);
880 buttonApply->setEnabled(false);
885 //=======================================================================
886 //function : onActionClicked
887 //purpose : slot called when an action type changed
888 //=======================================================================
890 void SMESHGUI_RotationDlg::onActionClicked(int button)
893 case MOVE_ELEMS_BUTTON:
894 MakeGroupsCheck->setEnabled(false);
895 LineEditNewMesh->setEnabled(false);
897 case COPY_ELEMS_BUTTON:
898 LineEditNewMesh->setEnabled(false);
899 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
900 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
901 MakeGroupsCheck->setEnabled(true);
903 MakeGroupsCheck->setEnabled(false);
905 case MAKE_MESH_BUTTON:
906 LineEditNewMesh->setEnabled(true);
907 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
908 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
909 MakeGroupsCheck->setEnabled(true);
911 MakeGroupsCheck->setEnabled(false);
917 //=======================================================================
918 //function : setNewMeshName
919 //purpose : update contents of LineEditNewMesh
920 //=======================================================================
922 void SMESHGUI_RotationDlg::setNewMeshName()
924 LineEditNewMesh->setText("");
925 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
927 if ( CheckBoxMesh->isChecked() ) {
928 name = LineEditElements->text();
931 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
932 name = meshSO->GetName().c_str();
934 if ( !name.isEmpty() )
935 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
939 //=================================================================================
940 // function : keyPressEvent()
942 //=================================================================================
943 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
945 QDialog::keyPressEvent( e );
946 if ( e->isAccepted() )
949 if ( e->key() == Qt::Key_F1 ) {
955 //=================================================================================
956 // function : isValid
958 //=================================================================================
959 bool SMESHGUI_RotationDlg::isValid()
964 ok = SpinBox_X->isValid( msg, true ) && ok;
965 ok = SpinBox_Y->isValid( msg, true ) && ok;
966 ok = SpinBox_Z->isValid( msg, true ) && ok;
967 ok = SpinBox_DX->isValid( msg, true ) && ok;
968 ok = SpinBox_DY->isValid( msg, true ) && ok;
969 ok = SpinBox_DZ->isValid( msg, true ) && ok;
970 ok = SpinBox_Angle->isValid( msg, true ) && ok;
973 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
974 if ( !msg.isEmpty() )
976 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );