1 // Copyright (C) 2007-2010 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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_RotationDlg.cxx
25 // Author : Michael ZORIN, Open CASCADE S.A.S.
28 #include "SMESHGUI_RotationDlg.h"
31 #include "SMESHGUI_SpinBox.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_IdValidator.h"
36 #include "SMESHGUI_FilterDlg.h"
38 #include <SMESH_Actor.h>
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESH_LogicalFilter.hxx>
41 #include <SMDS_Mesh.hxx>
43 // SALOME GUI includes
44 #include <SUIT_Desktop.h>
45 #include <SUIT_Session.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_ResourceMgr.h>
48 #include <SUIT_OverrideCursor.h>
50 #include <LightApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
53 #include <SVTK_ViewModel.h>
54 #include <SVTK_ViewWindow.h>
55 #include <SALOME_ListIO.hxx>
57 // SALOME KERNEL includes
58 #include <SALOMEDSClient_SObject.hxx>
61 #include <TColStd_MapOfInteger.hxx>
64 #include <QApplication>
65 #include <QButtonGroup>
69 #include <QPushButton>
70 #include <QRadioButton>
72 #include <QHBoxLayout>
73 #include <QVBoxLayout>
74 #include <QGridLayout>
78 #include <SALOMEconfig.h>
79 #include CORBA_SERVER_HEADER(SMESH_Group)
80 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
82 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
87 //=================================================================================
88 // class : SMESHGUI_RotationDlg()
90 //=================================================================================
91 SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule )
92 : QDialog( SMESH::GetDesktop( theModule ) ),
93 mySMESHGUI( theModule ),
94 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
96 mySelectedObject(SMESH::SMESH_IDSource::_nil())
98 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_ROTATION")));
99 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
102 setAttribute(Qt::WA_DeleteOnClose, true);
103 setWindowTitle(tr("SMESH_ROTATION_TITLE"));
104 setSizeGripEnabled(true);
106 QVBoxLayout* SMESHGUI_RotationDlgLayout = new QVBoxLayout(this);
107 SMESHGUI_RotationDlgLayout->setSpacing(SPACING);
108 SMESHGUI_RotationDlgLayout->setMargin(MARGIN);
110 /***************************************************************/
111 GroupConstructors = new QGroupBox(tr("SMESH_ROTATION"), this);
112 QButtonGroup* ButtonGroup = new QButtonGroup(this);
113 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
114 GroupConstructorsLayout->setSpacing(SPACING);
115 GroupConstructorsLayout->setMargin(MARGIN);
117 RadioButton1= new QRadioButton(GroupConstructors);
118 RadioButton1->setIcon(image0);
120 GroupConstructorsLayout->addWidget(RadioButton1);
121 ButtonGroup->addButton(RadioButton1, 0);
123 /***************************************************************/
124 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
125 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
126 GroupArgumentsLayout->setSpacing(SPACING);
127 GroupArgumentsLayout->setMargin(MARGIN);
129 myIdValidator = new SMESHGUI_IdValidator(this);
131 // Controls for elements selection
132 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
133 SelectElementsButton = new QPushButton(GroupArguments);
134 SelectElementsButton->setIcon(image1);
135 LineEditElements = new QLineEdit(GroupArguments);
136 LineEditElements->setValidator(myIdValidator);
137 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
138 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
140 // Control for the whole mesh selection
141 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
143 // Controls for axis defining
144 GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
145 QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
146 GroupAxisLayout->setSpacing(SPACING);
147 GroupAxisLayout->setMargin(MARGIN);
149 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
150 SelectPointButton = new QPushButton(GroupAxis);
151 SelectPointButton->setIcon(image1);
153 TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
154 SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
155 TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
156 SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
157 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
158 SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
160 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
161 SelectVectorButton = new QPushButton(GroupAxis);
162 SelectVectorButton->setIcon(image1);
164 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
165 SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
166 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
167 SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
168 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
169 SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
171 GroupAxisLayout->addWidget(TextLabelPoint, 0, 0);
172 GroupAxisLayout->addWidget(SelectPointButton, 0, 1);
173 GroupAxisLayout->addWidget(TextLabelX, 0, 2);
174 GroupAxisLayout->addWidget(SpinBox_X, 0, 3);
175 GroupAxisLayout->addWidget(TextLabelY, 0, 4);
176 GroupAxisLayout->addWidget(SpinBox_Y, 0, 5);
177 GroupAxisLayout->addWidget(TextLabelZ, 0, 6);
178 GroupAxisLayout->addWidget(SpinBox_Z, 0, 7);
179 GroupAxisLayout->addWidget(TextLabelVector, 1, 0);
180 GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
181 GroupAxisLayout->addWidget(TextLabelDX, 1, 2);
182 GroupAxisLayout->addWidget(SpinBox_DX, 1, 3);
183 GroupAxisLayout->addWidget(TextLabelDY, 1, 4);
184 GroupAxisLayout->addWidget(SpinBox_DY, 1, 5);
185 GroupAxisLayout->addWidget(TextLabelDZ, 1, 6);
186 GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7);
188 // Controls for angle defining
189 TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupArguments);
190 SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments);
193 ActionBox = new QGroupBox(GroupArguments);
194 ActionGroup = new QButtonGroup(GroupArguments);
195 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
196 ActionBoxLayout->setSpacing(SPACING);
197 ActionBoxLayout->setMargin(MARGIN);
199 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
200 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
201 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
203 ActionBoxLayout->addWidget(aMoveElements);
204 ActionBoxLayout->addWidget(aCopyElements);
205 ActionBoxLayout->addWidget(aCreateMesh);
206 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
207 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
208 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
210 // CheckBox for groups generation
211 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
213 // Name of a mesh to create
214 LineEditNewMesh = new QLineEdit(GroupArguments);
216 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
217 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
218 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
219 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
220 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
221 GroupArgumentsLayout->addWidget(GroupAxis, 2, 0, 1, 4);
222 GroupArgumentsLayout->addWidget(TextLabelAngle, 3, 0, 1, 2);
223 GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
224 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 3);
225 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 3);
226 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 3);
228 /***************************************************************/
229 GroupButtons = new QGroupBox(this);
230 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
231 GroupButtonsLayout->setSpacing(SPACING);
232 GroupButtonsLayout->setMargin(MARGIN);
234 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
235 buttonOk->setAutoDefault(true);
236 buttonOk->setDefault(true);
237 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
238 buttonApply->setAutoDefault(true);
239 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
240 buttonCancel->setAutoDefault(true);
241 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
242 buttonHelp->setAutoDefault(true);
244 GroupButtonsLayout->addWidget(buttonOk);
245 GroupButtonsLayout->addSpacing(10);
246 GroupButtonsLayout->addWidget(buttonApply);
247 GroupButtonsLayout->addSpacing(10);
248 GroupButtonsLayout->addStretch();
249 GroupButtonsLayout->addWidget(buttonCancel);
250 GroupButtonsLayout->addWidget(buttonHelp);
252 /***************************************************************/
253 SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors);
254 SMESHGUI_RotationDlgLayout->addWidget(GroupArguments);
255 SMESHGUI_RotationDlgLayout->addWidget(GroupButtons);
257 /* Initialisations */
258 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
259 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
260 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
261 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
262 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
263 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
265 SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, "angle_precision");
268 RadioButton1->setChecked(true);
270 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
272 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
274 // Costruction of the logical filter
275 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
276 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
278 QList<SUIT_SelectionFilter*> aListOfFilters;
279 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
280 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
282 myMeshOrSubMeshOrGroupFilter =
283 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
285 myHelpFileName = "rotation_page.html";
289 /* signals and slots connections */
290 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
291 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
292 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
293 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
295 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
296 connect(SelectPointButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
297 connect(SelectVectorButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
299 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
300 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
301 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
303 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
304 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
305 /* to close dialog if study change */
306 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
307 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
308 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
309 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
311 onActionClicked(MOVE_ELEMS_BUTTON);
314 //=================================================================================
315 // function : ~SMESHGUI_RotationDlg()
316 // purpose : Destroys the object and frees any allocated resources
317 //=================================================================================
318 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
321 myFilterDlg->setParent( 0 );
327 //=================================================================================
330 //=================================================================================
331 void SMESHGUI_RotationDlg::Init (bool ResetControls)
335 myEditCurrentArgument = (QWidget*)LineEditElements;
336 LineEditElements->setFocus();
340 buttonOk->setEnabled(false);
341 buttonApply->setEnabled(false);
344 myMesh = SMESH::SMESH_Mesh::_nil();
347 SpinBox_X->SetValue(0.0);
348 SpinBox_Y->SetValue(0.0);
349 SpinBox_Z->SetValue(0.0);
350 SpinBox_DX->SetValue(0.0);
351 SpinBox_DY->SetValue(0.0);
352 SpinBox_DZ->SetValue(0.0);
354 SpinBox_Angle->SetValue(45);
356 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
357 CheckBoxMesh->setChecked(false);
358 // MakeGroupsCheck->setChecked(false);
359 // MakeGroupsCheck->setEnabled(false);
360 // onSelectMesh(false);
363 onSelectMesh(CheckBoxMesh->isChecked());
366 //=================================================================================
367 // function : ClickOnApply()
369 //=================================================================================
370 bool SMESHGUI_RotationDlg::ClickOnApply()
372 if (mySMESHGUI->isActiveStudyLocked())
378 if (myNbOkElements && IsAxisOk()) {
379 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
381 SMESH::long_array_var anElementsId = new SMESH::long_array;
383 anElementsId->length(aListElementsId.count());
384 for (int i = 0; i < aListElementsId.count(); i++)
385 anElementsId[i] = aListElementsId[i].toInt();
387 SMESH::AxisStruct anAxis;
389 anAxis.x = SpinBox_X->GetValue();
390 anAxis.y = SpinBox_Y->GetValue();
391 anAxis.z = SpinBox_Z->GetValue();;
392 anAxis.vx = SpinBox_DX->GetValue();
393 anAxis.vy = SpinBox_DY->GetValue();
394 anAxis.vz = SpinBox_DZ->GetValue();
396 double anAngle = (SpinBox_Angle->GetValue())*PI/180;
398 QStringList aParameters;
399 aParameters << SpinBox_X->text();
400 aParameters << SpinBox_Y->text();
401 aParameters << SpinBox_Z->text();
402 aParameters << SpinBox_DX->text();
403 aParameters << SpinBox_DY->text();
404 aParameters << SpinBox_DZ->text();
405 aParameters << SpinBox_Angle->text();
407 int actionButton = ActionGroup->checkedId();
408 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
410 SUIT_OverrideCursor aWaitCursor;
411 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
412 switch ( actionButton ) {
413 case MOVE_ELEMS_BUTTON:
414 if(CheckBoxMesh->isChecked())
415 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, false);
417 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
418 if( !myMesh->_is_nil())
419 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
421 case COPY_ELEMS_BUTTON:
423 SMESH::ListOfGroups_var groups;
424 if(CheckBoxMesh->isChecked())
425 groups = aMeshEditor->RotateObjectMakeGroups(mySelectedObject, anAxis, anAngle);
427 groups = aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
430 if(CheckBoxMesh->isChecked())
431 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, true);
433 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
435 if( !myMesh->_is_nil())
436 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
438 case MAKE_MESH_BUTTON:
439 SMESH::SMESH_Mesh_var mesh;
440 if(CheckBoxMesh->isChecked())
441 mesh = aMeshEditor->RotateObjectMakeMesh(mySelectedObject, anAxis, anAngle, makeGroups,
442 LineEditNewMesh->text().toLatin1().data());
444 mesh = aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
445 LineEditNewMesh->text().toLatin1().data());
446 if( !mesh->_is_nil())
447 mesh->SetParameters( aParameters.join(":").toLatin1().constData() );
453 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
454 actionButton == MAKE_MESH_BUTTON )
455 mySMESHGUI->updateObjBrowser(true); // new groups may appear
457 mySelectedObject = SMESH::SMESH_IDSource::_nil();
458 SelectionIntoArgument();
464 //=================================================================================
465 // function : ClickOnOk()
467 //=================================================================================
468 void SMESHGUI_RotationDlg::ClickOnOk()
474 //=================================================================================
475 // function : ClickOnCancel()
477 //=================================================================================
478 void SMESHGUI_RotationDlg::ClickOnCancel()
480 disconnect(mySelectionMgr, 0, this, 0);
481 mySelectionMgr->clearFilters();
482 //mySelectionMgr->clearSelected();
483 if (SMESH::GetCurrentVtkView()) {
484 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
485 SMESH::SetPointRepresentation(false);
487 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
488 aViewWindow->SetSelectionMode(ActorSelection);
489 mySMESHGUI->ResetState();
493 //=================================================================================
494 // function : ClickOnHelp()
496 //=================================================================================
497 void SMESHGUI_RotationDlg::ClickOnHelp()
499 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
501 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
505 platform = "winapplication";
507 platform = "application";
509 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
510 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
511 arg(app->resourceMgr()->stringValue("ExternalBrowser",
513 arg(myHelpFileName));
517 //=======================================================================
518 // function : onTextChange()
520 //=======================================================================
521 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
523 QLineEdit* send = (QLineEdit*)sender();
528 if (send == LineEditElements)
531 buttonOk->setEnabled(false);
532 buttonApply->setEnabled(false);
534 // hilight entered elements
535 SMDS_Mesh* aMesh = 0;
537 aMesh = myActor->GetObject()->GetMesh();
540 if (send == LineEditElements) {
541 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
543 TColStd_MapOfInteger newIndices;
545 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
546 for (int i = 0; i < aListId.count(); i++) {
547 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
549 newIndices.Add(e->GetID());
553 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
554 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
555 aViewWindow->highlight( anIO, true, true );
557 myElementsId = theNewText;
561 if (myNbOkElements && IsAxisOk()) {
562 buttonOk->setEnabled(true);
563 buttonApply->setEnabled(true);
569 //=================================================================================
570 // function : SelectionIntoArgument()
571 // purpose : Called when selection as changed or other case
572 //=================================================================================
573 void SMESHGUI_RotationDlg::SelectionIntoArgument()
579 QString aString = "";
582 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
583 LineEditElements->setText(aString);
585 buttonOk->setEnabled(false);
586 buttonApply->setEnabled(false);
590 if (!GroupButtons->isEnabled()) // inactive
595 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
597 int nbSel = aList.Extent();
601 Handle(SALOME_InteractiveObject) IO = aList.First();
602 myMesh = SMESH::GetMeshByIO(IO);
603 if (myMesh->_is_nil())
606 myActor = SMESH::FindActorByObject(myMesh);
608 myActor = SMESH::FindActorByEntry(IO->getEntry());
609 if (!myActor && !CheckBoxMesh->isChecked())
614 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
617 // MakeGroups is available if there are groups and "Copy"
618 if ( myMesh->NbGroups() == 0 ) {
619 MakeGroupsCheck->setChecked(false);
620 MakeGroupsCheck->setEnabled(false);
622 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
623 MakeGroupsCheck->setEnabled(true);
625 if (CheckBoxMesh->isChecked()) {
626 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
628 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
629 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
635 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
639 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
640 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
642 myElementsId += QString(" %1").arg(i);
646 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
648 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
650 // get IDs from submesh
651 SMESH::long_array_var anElementsIds = new SMESH::long_array;
652 anElementsIds = aSubMesh->GetElementsId();
653 for (int i = 0; i < anElementsIds->length(); i++) {
654 myElementsId += QString(" %1").arg(anElementsIds[i]);
656 aNbUnits = anElementsIds->length();
659 SMESH::SMESH_GroupBase_var aGroup =
660 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
661 if (aGroup->_is_nil())
664 // get IDs from smesh group
665 SMESH::long_array_var anElementsIds = new SMESH::long_array;
666 anElementsIds = aGroup->GetListOfID();
667 for (int i = 0; i < anElementsIds->length(); i++) {
668 myElementsId += QString(" %1").arg(anElementsIds[i]);
670 aNbUnits = anElementsIds->length();
674 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
675 myElementsId = aString;
680 myNbOkElements = true;
683 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
687 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
691 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
699 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
700 SpinBox_X->SetValue(x);
701 SpinBox_Y->SetValue(y);
702 SpinBox_Z->SetValue(z);
703 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
704 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
705 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
706 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
711 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
712 LineEditElements->setText(aString);
713 LineEditElements->repaint();
714 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
715 LineEditElements->setEnabled(true);
721 if (myNbOkElements && IsAxisOk()) {
722 buttonOk->setEnabled(true);
723 buttonApply->setEnabled(true);
727 //=================================================================================
728 // function : SetEditCurrentArgument()
730 //=================================================================================
731 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
733 QPushButton* send = (QPushButton*)sender();
735 disconnect(mySelectionMgr, 0, this, 0);
736 mySelectionMgr->clearSelected();
737 mySelectionMgr->clearFilters();
739 switch (myConstructorId) {
740 case 0: /* default constructor */
742 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
743 if (send == SelectElementsButton) {
744 myEditCurrentArgument = (QWidget*)LineEditElements;
745 SMESH::SetPointRepresentation(false);
746 if (CheckBoxMesh->isChecked()) {
748 aViewWindow->SetSelectionMode(ActorSelection);
749 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
752 aViewWindow->SetSelectionMode( CellSelection );
754 } else if (send == SelectPointButton) {
755 myEditCurrentArgument = (QWidget*)SpinBox_X;
756 SMESH::SetPointRepresentation(true);
758 aViewWindow->SetSelectionMode( NodeSelection );
759 } else if (send == SelectVectorButton) {
760 myEditCurrentArgument = (QWidget*)SpinBox_DX;
761 SMESH::SetPointRepresentation(true);
763 aViewWindow->SetSelectionMode( NodeSelection );
770 myEditCurrentArgument->setFocus();
771 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
772 SelectionIntoArgument();
775 //=================================================================================
776 // function : DeactivateActiveDialog()
778 //=================================================================================
779 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
781 if (GroupConstructors->isEnabled()) {
782 GroupConstructors->setEnabled(false);
783 GroupArguments->setEnabled(false);
784 GroupButtons->setEnabled(false);
785 mySMESHGUI->ResetState();
786 mySMESHGUI->SetActiveDialogBox(0);
790 //=================================================================================
791 // function : ActivateThisDialog()
793 //=================================================================================
794 void SMESHGUI_RotationDlg::ActivateThisDialog()
796 /* Emit a signal to deactivate the active dialog */
797 mySMESHGUI->EmitSignalDeactivateDialog();
798 GroupConstructors->setEnabled(true);
799 GroupArguments->setEnabled(true);
800 GroupButtons->setEnabled(true);
802 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
804 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
805 aViewWindow->SetSelectionMode( CellSelection );
806 SelectionIntoArgument();
809 //=================================================================================
810 // function : enterEvent()
812 //=================================================================================
813 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
815 if (!GroupConstructors->isEnabled())
816 ActivateThisDialog();
819 //=================================================================================
820 // function : closeEvent()
822 //=================================================================================
823 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
825 /* same than click on cancel button */
829 //=================================================================================
830 // function : hideEvent()
831 // purpose : caused by ESC key
832 //=================================================================================
833 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
839 //=================================================================================
840 // function : onSelectMesh()
842 //=================================================================================
843 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
846 TextLabelElements->setText(tr("SMESH_NAME"));
848 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
849 myFilterBtn->setEnabled(!toSelectMesh);
851 if (myEditCurrentArgument != LineEditElements) {
852 LineEditElements->clear();
856 mySelectionMgr->clearFilters();
857 SMESH::SetPointRepresentation(false);
860 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
861 aViewWindow->SetSelectionMode(ActorSelection);
862 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
863 LineEditElements->setReadOnly(true);
864 LineEditElements->setValidator(0);
866 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
867 aViewWindow->SetSelectionMode( CellSelection );
868 LineEditElements->setReadOnly(false);
869 LineEditElements->setValidator(myIdValidator);
870 onTextChange(LineEditElements->text());
873 SelectionIntoArgument();
876 //=================================================================================
877 // function : IsAxisOk()
879 //=================================================================================
880 bool SMESHGUI_RotationDlg::IsAxisOk()
882 return (SpinBox_DX->GetValue() != 0 ||
883 SpinBox_DY->GetValue() != 0 ||
884 SpinBox_DZ->GetValue() != 0);
887 //=================================================================================
888 // function : onVectorChanged()
890 //=================================================================================
891 void SMESHGUI_RotationDlg::onVectorChanged()
894 buttonOk->setEnabled(true);
895 buttonApply->setEnabled(true);
897 buttonOk->setEnabled(false);
898 buttonApply->setEnabled(false);
903 //=======================================================================
904 //function : onActionClicked
905 //purpose : slot called when an action type changed
906 //=======================================================================
908 void SMESHGUI_RotationDlg::onActionClicked(int button)
911 case MOVE_ELEMS_BUTTON:
912 MakeGroupsCheck->setEnabled(false);
913 LineEditNewMesh->setEnabled(false);
915 case COPY_ELEMS_BUTTON:
916 LineEditNewMesh->setEnabled(false);
917 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
918 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
919 MakeGroupsCheck->setEnabled(true);
921 MakeGroupsCheck->setEnabled(false);
923 case MAKE_MESH_BUTTON:
924 LineEditNewMesh->setEnabled(true);
925 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
926 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
927 MakeGroupsCheck->setEnabled(true);
929 MakeGroupsCheck->setEnabled(false);
935 //=======================================================================
936 //function : setNewMeshName
937 //purpose : update contents of LineEditNewMesh
938 //=======================================================================
940 void SMESHGUI_RotationDlg::setNewMeshName()
942 LineEditNewMesh->setText("");
943 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
945 if ( CheckBoxMesh->isChecked() ) {
946 name = LineEditElements->text();
949 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
950 name = meshSO->GetName().c_str();
952 if ( !name.isEmpty() )
953 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
957 //=================================================================================
958 // function : keyPressEvent()
960 //=================================================================================
961 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
963 QDialog::keyPressEvent( e );
964 if ( e->isAccepted() )
967 if ( e->key() == Qt::Key_F1 ) {
973 //=================================================================================
974 // function : setFilters()
975 // purpose : SLOT. Called when "Filter" button pressed.
976 //=================================================================================
977 void SMESHGUI_RotationDlg::setFilters()
979 if(myMesh->_is_nil()) {
980 SUIT_MessageBox::critical(this,
982 tr("NO_MESH_SELECTED"));
986 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
988 myFilterDlg->SetSelection();
989 myFilterDlg->SetMesh( myMesh );
990 myFilterDlg->SetSourceWg( LineEditElements );
995 //=================================================================================
996 // function : isValid
998 //=================================================================================
999 bool SMESHGUI_RotationDlg::isValid()
1004 ok = SpinBox_X->isValid( msg, true ) && ok;
1005 ok = SpinBox_Y->isValid( msg, true ) && ok;
1006 ok = SpinBox_Z->isValid( msg, true ) && ok;
1007 ok = SpinBox_DX->isValid( msg, true ) && ok;
1008 ok = SpinBox_DY->isValid( msg, true ) && ok;
1009 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1010 ok = SpinBox_Angle->isValid( msg, true ) && ok;
1013 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1014 if ( !msg.isEmpty() )
1016 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );