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
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_RotationDlg.cxx
24 // Author : Michael ZORIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_RotationDlg.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESHGUI_FilterDlg.h"
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_LogicalFilter.hxx>
40 #include <SMDS_Mesh.hxx>
42 // SALOME GUI includes
43 #include <SUIT_Desktop.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_OverrideCursor.h>
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <SALOME_ListIO.hxx>
56 // SALOME KERNEL includes
57 #include <SALOMEDSClient_SObject.hxx>
60 #include <TColStd_MapOfInteger.hxx>
63 #include <QApplication>
64 #include <QButtonGroup>
68 #include <QPushButton>
69 #include <QRadioButton>
71 #include <QHBoxLayout>
72 #include <QVBoxLayout>
73 #include <QGridLayout>
77 #include <SALOMEconfig.h>
78 #include CORBA_SERVER_HEADER(SMESH_Group)
79 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
81 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
86 //To disable automatic genericobj management, the following line should be commented.
87 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
88 #define WITHGENERICOBJ
90 //=================================================================================
91 // class : SMESHGUI_RotationDlg()
93 //=================================================================================
94 SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule )
95 : QDialog( SMESH::GetDesktop( theModule ) ),
96 mySMESHGUI( theModule ),
97 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
99 mySelectedObject(SMESH::SMESH_IDSource::_nil())
101 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_ROTATION")));
102 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
105 setAttribute(Qt::WA_DeleteOnClose, true);
106 setWindowTitle(tr("SMESH_ROTATION_TITLE"));
107 setSizeGripEnabled(true);
109 QVBoxLayout* SMESHGUI_RotationDlgLayout = new QVBoxLayout(this);
110 SMESHGUI_RotationDlgLayout->setSpacing(SPACING);
111 SMESHGUI_RotationDlgLayout->setMargin(MARGIN);
113 /***************************************************************/
114 GroupConstructors = new QGroupBox(tr("SMESH_ROTATION"), this);
115 QButtonGroup* ButtonGroup = new QButtonGroup(this);
116 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
117 GroupConstructorsLayout->setSpacing(SPACING);
118 GroupConstructorsLayout->setMargin(MARGIN);
120 RadioButton1= new QRadioButton(GroupConstructors);
121 RadioButton1->setIcon(image0);
123 GroupConstructorsLayout->addWidget(RadioButton1);
124 ButtonGroup->addButton(RadioButton1, 0);
126 /***************************************************************/
127 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
128 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
129 GroupArgumentsLayout->setSpacing(SPACING);
130 GroupArgumentsLayout->setMargin(MARGIN);
132 myIdValidator = new SMESHGUI_IdValidator(this);
134 // Controls for elements selection
135 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
136 SelectElementsButton = new QPushButton(GroupArguments);
137 SelectElementsButton->setIcon(image1);
138 LineEditElements = new QLineEdit(GroupArguments);
139 LineEditElements->setValidator(myIdValidator);
140 LineEditElements->setMaxLength(-1);
141 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
142 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
144 // Control for the whole mesh selection
145 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
147 // Controls for axis defining
148 GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
149 QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
150 GroupAxisLayout->setSpacing(SPACING);
151 GroupAxisLayout->setMargin(MARGIN);
153 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
154 SelectPointButton = new QPushButton(GroupAxis);
155 SelectPointButton->setIcon(image1);
157 TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
158 SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
159 TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
160 SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
161 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
162 SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
164 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
165 SelectVectorButton = new QPushButton(GroupAxis);
166 SelectVectorButton->setIcon(image1);
168 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
169 SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
170 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
171 SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
172 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
173 SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
175 GroupAxisLayout->addWidget(TextLabelPoint, 0, 0);
176 GroupAxisLayout->addWidget(SelectPointButton, 0, 1);
177 GroupAxisLayout->addWidget(TextLabelX, 0, 2);
178 GroupAxisLayout->addWidget(SpinBox_X, 0, 3);
179 GroupAxisLayout->addWidget(TextLabelY, 0, 4);
180 GroupAxisLayout->addWidget(SpinBox_Y, 0, 5);
181 GroupAxisLayout->addWidget(TextLabelZ, 0, 6);
182 GroupAxisLayout->addWidget(SpinBox_Z, 0, 7);
183 GroupAxisLayout->addWidget(TextLabelVector, 1, 0);
184 GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
185 GroupAxisLayout->addWidget(TextLabelDX, 1, 2);
186 GroupAxisLayout->addWidget(SpinBox_DX, 1, 3);
187 GroupAxisLayout->addWidget(TextLabelDY, 1, 4);
188 GroupAxisLayout->addWidget(SpinBox_DY, 1, 5);
189 GroupAxisLayout->addWidget(TextLabelDZ, 1, 6);
190 GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7);
192 // Controls for angle defining
193 TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupArguments);
194 SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments);
197 ActionBox = new QGroupBox(GroupArguments);
198 ActionGroup = new QButtonGroup(GroupArguments);
199 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
200 ActionBoxLayout->setSpacing(SPACING);
201 ActionBoxLayout->setMargin(MARGIN);
203 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
204 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
205 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
207 ActionBoxLayout->addWidget(aMoveElements);
208 ActionBoxLayout->addWidget(aCopyElements);
209 ActionBoxLayout->addWidget(aCreateMesh);
210 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
211 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
212 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
214 // CheckBox for groups generation
215 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
217 // Name of a mesh to create
218 LineEditNewMesh = new QLineEdit(GroupArguments);
220 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
221 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
222 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
223 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
224 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
225 GroupArgumentsLayout->addWidget(GroupAxis, 2, 0, 1, 4);
226 GroupArgumentsLayout->addWidget(TextLabelAngle, 3, 0, 1, 2);
227 GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
228 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 3);
229 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 3);
230 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 3);
232 /***************************************************************/
233 GroupButtons = new QGroupBox(this);
234 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
235 GroupButtonsLayout->setSpacing(SPACING);
236 GroupButtonsLayout->setMargin(MARGIN);
238 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
239 buttonOk->setAutoDefault(true);
240 buttonOk->setDefault(true);
241 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
242 buttonApply->setAutoDefault(true);
243 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
244 buttonCancel->setAutoDefault(true);
245 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
246 buttonHelp->setAutoDefault(true);
248 GroupButtonsLayout->addWidget(buttonOk);
249 GroupButtonsLayout->addSpacing(10);
250 GroupButtonsLayout->addWidget(buttonApply);
251 GroupButtonsLayout->addSpacing(10);
252 GroupButtonsLayout->addStretch();
253 GroupButtonsLayout->addWidget(buttonCancel);
254 GroupButtonsLayout->addWidget(buttonHelp);
256 /***************************************************************/
257 SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors);
258 SMESHGUI_RotationDlgLayout->addWidget(GroupArguments);
259 SMESHGUI_RotationDlgLayout->addWidget(GroupButtons);
261 /* Initialisations */
262 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
263 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
264 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
265 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
266 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
267 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
269 SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, "angle_precision");
272 RadioButton1->setChecked(true);
274 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
276 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
278 // Costruction of the logical filter
279 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
280 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
282 QList<SUIT_SelectionFilter*> aListOfFilters;
283 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
284 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
286 myMeshOrSubMeshOrGroupFilter =
287 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
289 myHelpFileName = "rotation_page.html";
293 /* signals and slots connections */
294 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
295 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
296 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
297 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
299 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
300 connect(SelectPointButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
301 connect(SelectVectorButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
303 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
304 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
305 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
307 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
308 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
309 /* to close dialog if study change */
310 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
311 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
312 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
313 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
315 onActionClicked(MOVE_ELEMS_BUTTON);
318 //=================================================================================
319 // function : ~SMESHGUI_RotationDlg()
320 // purpose : Destroys the object and frees any allocated resources
321 //=================================================================================
322 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
325 myFilterDlg->setParent( 0 );
331 //=================================================================================
334 //=================================================================================
335 void SMESHGUI_RotationDlg::Init (bool ResetControls)
339 myEditCurrentArgument = (QWidget*)LineEditElements;
340 LineEditElements->setFocus();
344 buttonOk->setEnabled(false);
345 buttonApply->setEnabled(false);
348 myMesh = SMESH::SMESH_Mesh::_nil();
351 SpinBox_X->SetValue(0.0);
352 SpinBox_Y->SetValue(0.0);
353 SpinBox_Z->SetValue(0.0);
354 SpinBox_DX->SetValue(0.0);
355 SpinBox_DY->SetValue(0.0);
356 SpinBox_DZ->SetValue(0.0);
358 SpinBox_Angle->SetValue(45);
360 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
361 CheckBoxMesh->setChecked(false);
362 // MakeGroupsCheck->setChecked(false);
363 // MakeGroupsCheck->setEnabled(false);
364 // onSelectMesh(false);
367 onSelectMesh(CheckBoxMesh->isChecked());
370 //=================================================================================
371 // function : ClickOnApply()
373 //=================================================================================
374 bool SMESHGUI_RotationDlg::ClickOnApply()
376 if (mySMESHGUI->isActiveStudyLocked())
382 if (myNbOkElements && IsAxisOk()) {
383 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
385 SMESH::long_array_var anElementsId = new SMESH::long_array;
387 anElementsId->length(aListElementsId.count());
388 for (int i = 0; i < aListElementsId.count(); i++)
389 anElementsId[i] = aListElementsId[i].toInt();
391 SMESH::AxisStruct anAxis;
393 anAxis.x = SpinBox_X->GetValue();
394 anAxis.y = SpinBox_Y->GetValue();
395 anAxis.z = SpinBox_Z->GetValue();;
396 anAxis.vx = SpinBox_DX->GetValue();
397 anAxis.vy = SpinBox_DY->GetValue();
398 anAxis.vz = SpinBox_DZ->GetValue();
400 double anAngle = (SpinBox_Angle->GetValue())*PI/180;
402 QStringList aParameters;
403 aParameters << SpinBox_X->text();
404 aParameters << SpinBox_Y->text();
405 aParameters << SpinBox_Z->text();
406 aParameters << SpinBox_DX->text();
407 aParameters << SpinBox_DY->text();
408 aParameters << SpinBox_DZ->text();
409 aParameters << SpinBox_Angle->text();
411 int actionButton = ActionGroup->checkedId();
412 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
414 SUIT_OverrideCursor aWaitCursor;
415 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
416 switch ( actionButton ) {
417 case MOVE_ELEMS_BUTTON:
418 if(CheckBoxMesh->isChecked())
419 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, false);
421 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
422 if( !myMesh->_is_nil())
423 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
425 case COPY_ELEMS_BUTTON:
427 SMESH::ListOfGroups_var groups;
428 if(CheckBoxMesh->isChecked())
429 groups = aMeshEditor->RotateObjectMakeGroups(mySelectedObject, anAxis, anAngle);
431 groups = aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
434 if(CheckBoxMesh->isChecked())
435 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, true);
437 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
439 if( !myMesh->_is_nil())
440 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
442 case MAKE_MESH_BUTTON: {
443 SMESH::SMESH_Mesh_var mesh;
444 if (CheckBoxMesh->isChecked())
445 mesh = aMeshEditor->RotateObjectMakeMesh(mySelectedObject, anAxis, anAngle, makeGroups,
446 LineEditNewMesh->text().toLatin1().data());
448 mesh = aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
449 LineEditNewMesh->text().toLatin1().data());
450 if (!mesh->_is_nil()) {
451 mesh->SetParameters(aParameters.join(":").toLatin1().constData());
452 #ifdef WITHGENERICOBJ
453 // obj has been published in study. Its refcount has been incremented.
454 // It is safe to decrement its refcount
455 // so that it will be destroyed when the entry in study will be removed
466 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
467 actionButton == MAKE_MESH_BUTTON )
468 mySMESHGUI->updateObjBrowser(true); // new groups may appear
470 mySelectedObject = SMESH::SMESH_IDSource::_nil();
471 SelectionIntoArgument();
473 SMESHGUI::Modified();
479 //=================================================================================
480 // function : ClickOnOk()
482 //=================================================================================
483 void SMESHGUI_RotationDlg::ClickOnOk()
489 //=================================================================================
490 // function : ClickOnCancel()
492 //=================================================================================
493 void SMESHGUI_RotationDlg::ClickOnCancel()
495 disconnect(mySelectionMgr, 0, this, 0);
496 mySelectionMgr->clearFilters();
497 //mySelectionMgr->clearSelected();
498 if (SMESH::GetCurrentVtkView()) {
499 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
500 SMESH::SetPointRepresentation(false);
502 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
503 aViewWindow->SetSelectionMode(ActorSelection);
504 mySMESHGUI->ResetState();
508 //=================================================================================
509 // function : ClickOnHelp()
511 //=================================================================================
512 void SMESHGUI_RotationDlg::ClickOnHelp()
514 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
516 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
520 platform = "winapplication";
522 platform = "application";
524 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
525 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
526 arg(app->resourceMgr()->stringValue("ExternalBrowser",
528 arg(myHelpFileName));
532 //=======================================================================
533 // function : onTextChange()
535 //=======================================================================
536 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
538 QLineEdit* send = (QLineEdit*)sender();
543 if (send == LineEditElements)
546 buttonOk->setEnabled(false);
547 buttonApply->setEnabled(false);
549 // hilight entered elements
550 SMDS_Mesh* aMesh = 0;
552 aMesh = myActor->GetObject()->GetMesh();
555 if (send == LineEditElements) {
556 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
558 TColStd_MapOfInteger newIndices;
560 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
561 for (int i = 0; i < aListId.count(); i++) {
562 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
564 newIndices.Add(e->GetID());
568 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
569 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
570 aViewWindow->highlight( anIO, true, true );
572 myElementsId = theNewText;
576 if (myNbOkElements && IsAxisOk()) {
577 buttonOk->setEnabled(true);
578 buttonApply->setEnabled(true);
584 //=================================================================================
585 // function : SelectionIntoArgument()
586 // purpose : Called when selection as changed or other case
587 //=================================================================================
588 void SMESHGUI_RotationDlg::SelectionIntoArgument()
594 QString aString = "";
597 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
598 LineEditElements->setText(aString);
600 buttonOk->setEnabled(false);
601 buttonApply->setEnabled(false);
605 if (!GroupButtons->isEnabled()) // inactive
610 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
612 int nbSel = aList.Extent();
616 Handle(SALOME_InteractiveObject) IO = aList.First();
617 myMesh = SMESH::GetMeshByIO(IO);
618 if (myMesh->_is_nil())
621 myActor = SMESH::FindActorByObject(myMesh);
623 myActor = SMESH::FindActorByEntry(IO->getEntry());
624 if (!myActor && !CheckBoxMesh->isChecked())
629 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
632 // MakeGroups is available if there are groups and "Copy"
633 if ( myMesh->NbGroups() == 0 ) {
634 MakeGroupsCheck->setChecked(false);
635 MakeGroupsCheck->setEnabled(false);
637 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
638 MakeGroupsCheck->setEnabled(true);
640 if (CheckBoxMesh->isChecked()) {
641 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
643 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
644 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
650 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
654 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
655 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
657 myElementsId += QString(" %1").arg(i);
661 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
663 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
665 // get IDs from submesh
666 SMESH::long_array_var anElementsIds = new SMESH::long_array;
667 anElementsIds = aSubMesh->GetElementsId();
668 for (int i = 0; i < anElementsIds->length(); i++) {
669 myElementsId += QString(" %1").arg(anElementsIds[i]);
671 aNbUnits = anElementsIds->length();
674 SMESH::SMESH_GroupBase_var aGroup =
675 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
676 if (aGroup->_is_nil())
679 // get IDs from smesh group
680 SMESH::long_array_var anElementsIds = new SMESH::long_array;
681 anElementsIds = aGroup->GetListOfID();
682 for (int i = 0; i < anElementsIds->length(); i++) {
683 myElementsId += QString(" %1").arg(anElementsIds[i]);
685 aNbUnits = anElementsIds->length();
689 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
690 myElementsId = aString;
695 myNbOkElements = true;
698 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
702 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
706 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
714 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
715 SpinBox_X->SetValue(x);
716 SpinBox_Y->SetValue(y);
717 SpinBox_Z->SetValue(z);
718 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
719 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
720 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
721 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
726 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
727 LineEditElements->setText(aString);
728 LineEditElements->repaint();
729 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
730 LineEditElements->setEnabled(true);
736 if (myNbOkElements && IsAxisOk()) {
737 buttonOk->setEnabled(true);
738 buttonApply->setEnabled(true);
742 //=================================================================================
743 // function : SetEditCurrentArgument()
745 //=================================================================================
746 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
748 QPushButton* send = (QPushButton*)sender();
750 disconnect(mySelectionMgr, 0, this, 0);
751 mySelectionMgr->clearSelected();
752 mySelectionMgr->clearFilters();
754 switch (myConstructorId) {
755 case 0: /* default constructor */
757 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
758 if (send == SelectElementsButton) {
759 myEditCurrentArgument = (QWidget*)LineEditElements;
760 SMESH::SetPointRepresentation(false);
761 if (CheckBoxMesh->isChecked()) {
763 aViewWindow->SetSelectionMode(ActorSelection);
764 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
767 aViewWindow->SetSelectionMode( CellSelection );
769 } else if (send == SelectPointButton) {
770 myEditCurrentArgument = (QWidget*)SpinBox_X;
771 SMESH::SetPointRepresentation(true);
773 aViewWindow->SetSelectionMode( NodeSelection );
774 } else if (send == SelectVectorButton) {
775 myEditCurrentArgument = (QWidget*)SpinBox_DX;
776 SMESH::SetPointRepresentation(true);
778 aViewWindow->SetSelectionMode( NodeSelection );
785 myEditCurrentArgument->setFocus();
786 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
787 SelectionIntoArgument();
790 //=================================================================================
791 // function : DeactivateActiveDialog()
793 //=================================================================================
794 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
796 if (GroupConstructors->isEnabled()) {
797 GroupConstructors->setEnabled(false);
798 GroupArguments->setEnabled(false);
799 GroupButtons->setEnabled(false);
800 mySMESHGUI->ResetState();
801 mySMESHGUI->SetActiveDialogBox(0);
805 //=================================================================================
806 // function : ActivateThisDialog()
808 //=================================================================================
809 void SMESHGUI_RotationDlg::ActivateThisDialog()
811 /* Emit a signal to deactivate the active dialog */
812 mySMESHGUI->EmitSignalDeactivateDialog();
813 GroupConstructors->setEnabled(true);
814 GroupArguments->setEnabled(true);
815 GroupButtons->setEnabled(true);
817 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
819 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
820 aViewWindow->SetSelectionMode( CellSelection );
821 SelectionIntoArgument();
824 //=================================================================================
825 // function : enterEvent()
827 //=================================================================================
828 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
830 if (!GroupConstructors->isEnabled())
831 ActivateThisDialog();
834 //=================================================================================
835 // function : closeEvent()
837 //=================================================================================
838 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
840 /* same than click on cancel button */
844 //=================================================================================
845 // function : hideEvent()
846 // purpose : caused by ESC key
847 //=================================================================================
848 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
854 //=================================================================================
855 // function : onSelectMesh()
857 //=================================================================================
858 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
861 TextLabelElements->setText(tr("SMESH_NAME"));
863 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
864 myFilterBtn->setEnabled(!toSelectMesh);
866 if (myEditCurrentArgument != LineEditElements) {
867 LineEditElements->clear();
871 mySelectionMgr->clearFilters();
872 SMESH::SetPointRepresentation(false);
875 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
876 aViewWindow->SetSelectionMode(ActorSelection);
877 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
878 LineEditElements->setReadOnly(true);
879 LineEditElements->setValidator(0);
881 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
882 aViewWindow->SetSelectionMode( CellSelection );
883 LineEditElements->setReadOnly(false);
884 LineEditElements->setValidator(myIdValidator);
885 onTextChange(LineEditElements->text());
888 SelectionIntoArgument();
891 //=================================================================================
892 // function : IsAxisOk()
894 //=================================================================================
895 bool SMESHGUI_RotationDlg::IsAxisOk()
897 return (SpinBox_DX->GetValue() != 0 ||
898 SpinBox_DY->GetValue() != 0 ||
899 SpinBox_DZ->GetValue() != 0);
902 //=================================================================================
903 // function : onVectorChanged()
905 //=================================================================================
906 void SMESHGUI_RotationDlg::onVectorChanged()
909 buttonOk->setEnabled(true);
910 buttonApply->setEnabled(true);
912 buttonOk->setEnabled(false);
913 buttonApply->setEnabled(false);
918 //=======================================================================
919 //function : onActionClicked
920 //purpose : slot called when an action type changed
921 //=======================================================================
923 void SMESHGUI_RotationDlg::onActionClicked(int button)
926 case MOVE_ELEMS_BUTTON:
927 MakeGroupsCheck->setEnabled(false);
928 LineEditNewMesh->setEnabled(false);
930 case COPY_ELEMS_BUTTON:
931 LineEditNewMesh->setEnabled(false);
932 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
933 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
934 MakeGroupsCheck->setEnabled(true);
936 MakeGroupsCheck->setEnabled(false);
938 case MAKE_MESH_BUTTON:
939 LineEditNewMesh->setEnabled(true);
940 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
941 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
942 MakeGroupsCheck->setEnabled(true);
944 MakeGroupsCheck->setEnabled(false);
950 //=======================================================================
951 //function : setNewMeshName
952 //purpose : update contents of LineEditNewMesh
953 //=======================================================================
955 void SMESHGUI_RotationDlg::setNewMeshName()
957 LineEditNewMesh->setText("");
958 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
960 if ( CheckBoxMesh->isChecked() ) {
961 name = LineEditElements->text();
964 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
965 name = meshSO->GetName().c_str();
967 if ( !name.isEmpty() )
968 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
972 //=================================================================================
973 // function : keyPressEvent()
975 //=================================================================================
976 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
978 QDialog::keyPressEvent( e );
979 if ( e->isAccepted() )
982 if ( e->key() == Qt::Key_F1 ) {
988 //=================================================================================
989 // function : setFilters()
990 // purpose : SLOT. Called when "Filter" button pressed.
991 //=================================================================================
992 void SMESHGUI_RotationDlg::setFilters()
994 if(myMesh->_is_nil()) {
995 SUIT_MessageBox::critical(this,
997 tr("NO_MESH_SELECTED"));
1001 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1003 myFilterDlg->SetSelection();
1004 myFilterDlg->SetMesh( myMesh );
1005 myFilterDlg->SetSourceWg( LineEditElements );
1007 myFilterDlg->show();
1010 //=================================================================================
1011 // function : isValid
1013 //=================================================================================
1014 bool SMESHGUI_RotationDlg::isValid()
1019 ok = SpinBox_X->isValid( msg, true ) && ok;
1020 ok = SpinBox_Y->isValid( msg, true ) && ok;
1021 ok = SpinBox_Z->isValid( msg, true ) && ok;
1022 ok = SpinBox_DX->isValid( msg, true ) && ok;
1023 ok = SpinBox_DY->isValid( msg, true ) && ok;
1024 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1025 ok = SpinBox_Angle->isValid( msg, true ) && ok;
1028 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1029 if ( !msg.isEmpty() )
1031 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );