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"
36 #include "SMESHGUI_MeshEditPreview.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 //To disable automatic genericobj management, the following line should be commented.
88 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
89 #define WITHGENERICOBJ
91 //=================================================================================
92 // class : SMESHGUI_RotationDlg()
94 //=================================================================================
95 SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule ) :
96 SMESHGUI_PreviewDlg( 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);
222 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
224 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
225 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
226 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
227 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
228 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
229 GroupArgumentsLayout->addWidget(GroupAxis, 2, 0, 1, 4);
230 GroupArgumentsLayout->addWidget(TextLabelAngle, 3, 0, 1, 2);
231 GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
232 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 3);
233 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 3);
234 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 3);
235 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 7, 0);
238 /***************************************************************/
239 GroupButtons = new QGroupBox(this);
240 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
241 GroupButtonsLayout->setSpacing(SPACING);
242 GroupButtonsLayout->setMargin(MARGIN);
244 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
245 buttonOk->setAutoDefault(true);
246 buttonOk->setDefault(true);
247 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
248 buttonApply->setAutoDefault(true);
249 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
250 buttonCancel->setAutoDefault(true);
251 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
252 buttonHelp->setAutoDefault(true);
254 GroupButtonsLayout->addWidget(buttonOk);
255 GroupButtonsLayout->addSpacing(10);
256 GroupButtonsLayout->addWidget(buttonApply);
257 GroupButtonsLayout->addSpacing(10);
258 GroupButtonsLayout->addStretch();
259 GroupButtonsLayout->addWidget(buttonCancel);
260 GroupButtonsLayout->addWidget(buttonHelp);
262 /***************************************************************/
263 SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors);
264 SMESHGUI_RotationDlgLayout->addWidget(GroupArguments);
265 SMESHGUI_RotationDlgLayout->addWidget(GroupButtons);
267 /* Initialisations */
268 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
269 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
270 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
271 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
272 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
273 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
275 SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, "angle_precision");
278 RadioButton1->setChecked(true);
280 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
282 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
284 // Costruction of the logical filter
285 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
286 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
288 QList<SUIT_SelectionFilter*> aListOfFilters;
289 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
290 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
292 myMeshOrSubMeshOrGroupFilter =
293 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
295 myHelpFileName = "rotation_page.html";
299 /* signals and slots connections */
300 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
301 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
302 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
303 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
305 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
306 connect(SelectPointButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
307 connect(SelectVectorButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
309 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
310 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
311 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
313 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
314 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
315 /* to close dialog if study change */
316 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
317 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
318 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
319 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
321 connect(SpinBox_X, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
322 connect(SpinBox_Y, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
323 connect(SpinBox_Z, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
324 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
325 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
327 connect(SpinBox_Angle, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
329 //To Connect preview check box
330 connectPreviewControl();
332 onActionClicked(MOVE_ELEMS_BUTTON);
335 //=================================================================================
336 // function : ~SMESHGUI_RotationDlg()
337 // purpose : Destroys the object and frees any allocated resources
338 //=================================================================================
339 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
342 myFilterDlg->setParent( 0 );
348 //=================================================================================
351 //=================================================================================
352 void SMESHGUI_RotationDlg::Init (bool ResetControls)
356 myEditCurrentArgument = (QWidget*)LineEditElements;
357 LineEditElements->setFocus();
361 buttonOk->setEnabled(false);
362 buttonApply->setEnabled(false);
365 myMesh = SMESH::SMESH_Mesh::_nil();
368 SpinBox_X->SetValue(0.0);
369 SpinBox_Y->SetValue(0.0);
370 SpinBox_Z->SetValue(0.0);
371 SpinBox_DX->SetValue(0.0);
372 SpinBox_DY->SetValue(0.0);
373 SpinBox_DZ->SetValue(0.0);
375 SpinBox_Angle->SetValue(45);
377 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
378 CheckBoxMesh->setChecked(false);
379 myPreviewCheckBox->setChecked(false);
380 onDisplaySimulation(false);
382 // MakeGroupsCheck->setChecked(false);
383 // MakeGroupsCheck->setEnabled(false);
384 // onSelectMesh(false);
387 onSelectMesh(CheckBoxMesh->isChecked());
390 //=================================================================================
391 // function : ClickOnApply()
393 //=================================================================================
394 bool SMESHGUI_RotationDlg::ClickOnApply()
396 if (mySMESHGUI->isActiveStudyLocked())
402 if (myNbOkElements && IsAxisOk()) {
403 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
405 SMESH::long_array_var anElementsId = new SMESH::long_array;
407 anElementsId->length(aListElementsId.count());
408 for (int i = 0; i < aListElementsId.count(); i++)
409 anElementsId[i] = aListElementsId[i].toInt();
411 SMESH::AxisStruct anAxis;
413 anAxis.x = SpinBox_X->GetValue();
414 anAxis.y = SpinBox_Y->GetValue();
415 anAxis.z = SpinBox_Z->GetValue();;
416 anAxis.vx = SpinBox_DX->GetValue();
417 anAxis.vy = SpinBox_DY->GetValue();
418 anAxis.vz = SpinBox_DZ->GetValue();
420 double anAngle = (SpinBox_Angle->GetValue())*PI/180;
422 QStringList aParameters;
423 aParameters << SpinBox_X->text();
424 aParameters << SpinBox_Y->text();
425 aParameters << SpinBox_Z->text();
426 aParameters << SpinBox_DX->text();
427 aParameters << SpinBox_DY->text();
428 aParameters << SpinBox_DZ->text();
429 aParameters << SpinBox_Angle->text();
431 int actionButton = ActionGroup->checkedId();
432 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
434 SUIT_OverrideCursor aWaitCursor;
435 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
436 switch ( actionButton ) {
437 case MOVE_ELEMS_BUTTON:
438 if(CheckBoxMesh->isChecked())
439 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, false);
441 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
442 if( !myMesh->_is_nil())
443 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
445 case COPY_ELEMS_BUTTON:
447 SMESH::ListOfGroups_var groups;
448 if(CheckBoxMesh->isChecked())
449 groups = aMeshEditor->RotateObjectMakeGroups(mySelectedObject, anAxis, anAngle);
451 groups = aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
454 if(CheckBoxMesh->isChecked())
455 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, true);
457 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
459 if( !myMesh->_is_nil())
460 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
462 case MAKE_MESH_BUTTON: {
463 SMESH::SMESH_Mesh_var mesh;
464 if (CheckBoxMesh->isChecked())
465 mesh = aMeshEditor->RotateObjectMakeMesh(mySelectedObject, anAxis, anAngle, makeGroups,
466 LineEditNewMesh->text().toLatin1().data());
468 mesh = aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
469 LineEditNewMesh->text().toLatin1().data());
470 if (!mesh->_is_nil()) {
471 mesh->SetParameters(aParameters.join(":").toLatin1().constData());
472 #ifdef WITHGENERICOBJ
473 // obj has been published in study. Its refcount has been incremented.
474 // It is safe to decrement its refcount
475 // so that it will be destroyed when the entry in study will be removed
486 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
487 actionButton == MAKE_MESH_BUTTON )
488 mySMESHGUI->updateObjBrowser(true); // new groups may appear
490 mySelectedObject = SMESH::SMESH_IDSource::_nil();
491 SelectionIntoArgument();
493 SMESHGUI::Modified();
499 //=================================================================================
500 // function : ClickOnOk()
502 //=================================================================================
503 void SMESHGUI_RotationDlg::ClickOnOk()
509 //=================================================================================
510 // function : ClickOnCancel()
512 //=================================================================================
513 void SMESHGUI_RotationDlg::ClickOnCancel()
515 disconnect(mySelectionMgr, 0, this, 0);
516 mySelectionMgr->clearFilters();
517 //mySelectionMgr->clearSelected();
518 if (SMESH::GetCurrentVtkView()) {
519 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
520 SMESH::SetPointRepresentation(false);
522 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
523 aViewWindow->SetSelectionMode(ActorSelection);
524 mySMESHGUI->ResetState();
528 //=================================================================================
529 // function : ClickOnHelp()
531 //=================================================================================
532 void SMESHGUI_RotationDlg::ClickOnHelp()
534 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
536 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
540 platform = "winapplication";
542 platform = "application";
544 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
545 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
546 arg(app->resourceMgr()->stringValue("ExternalBrowser",
548 arg(myHelpFileName));
552 //=======================================================================
553 // function : onTextChange()
555 //=======================================================================
556 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
558 QLineEdit* send = (QLineEdit*)sender();
563 if (send == LineEditElements)
566 buttonOk->setEnabled(false);
567 buttonApply->setEnabled(false);
569 // hilight entered elements
570 SMDS_Mesh* aMesh = 0;
572 aMesh = myActor->GetObject()->GetMesh();
575 if (send == LineEditElements) {
576 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
578 TColStd_MapOfInteger newIndices;
580 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
581 for (int i = 0; i < aListId.count(); i++) {
582 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
584 newIndices.Add(e->GetID());
588 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
589 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
590 aViewWindow->highlight( anIO, true, true );
592 myElementsId = theNewText;
596 if (myNbOkElements && IsAxisOk()) {
597 buttonOk->setEnabled(true);
598 buttonApply->setEnabled(true);
604 //=================================================================================
605 // function : SelectionIntoArgument()
606 // purpose : Called when selection as changed or other case
607 //=================================================================================
608 void SMESHGUI_RotationDlg::SelectionIntoArgument()
614 QString aString = "";
617 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
618 LineEditElements->setText(aString);
620 buttonOk->setEnabled(false);
621 buttonApply->setEnabled(false);
625 if (!GroupButtons->isEnabled()) // inactive
630 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
632 int nbSel = aList.Extent();
636 Handle(SALOME_InteractiveObject) IO = aList.First();
637 myMesh = SMESH::GetMeshByIO(IO);
638 if (myMesh->_is_nil())
641 myActor = SMESH::FindActorByObject(myMesh);
643 myActor = SMESH::FindActorByEntry(IO->getEntry());
644 if (!myActor && !CheckBoxMesh->isChecked())
649 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
652 // MakeGroups is available if there are groups and "Copy"
653 if ( myMesh->NbGroups() == 0 ) {
654 MakeGroupsCheck->setChecked(false);
655 MakeGroupsCheck->setEnabled(false);
657 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
658 MakeGroupsCheck->setEnabled(true);
660 if (CheckBoxMesh->isChecked()) {
661 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
663 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
664 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
670 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
674 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
675 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
677 myElementsId += QString(" %1").arg(i);
681 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
683 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
685 // get IDs from submesh
686 SMESH::long_array_var anElementsIds = new SMESH::long_array;
687 anElementsIds = aSubMesh->GetElementsId();
688 for (int i = 0; i < anElementsIds->length(); i++) {
689 myElementsId += QString(" %1").arg(anElementsIds[i]);
691 aNbUnits = anElementsIds->length();
694 SMESH::SMESH_GroupBase_var aGroup =
695 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
696 if (aGroup->_is_nil())
699 // get IDs from smesh group
700 SMESH::long_array_var anElementsIds = new SMESH::long_array;
701 anElementsIds = aGroup->GetListOfID();
702 for (int i = 0; i < anElementsIds->length(); i++) {
703 myElementsId += QString(" %1").arg(anElementsIds[i]);
705 aNbUnits = anElementsIds->length();
709 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
710 myElementsId = aString;
715 myNbOkElements = true;
718 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
722 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
726 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
734 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
735 SpinBox_X->SetValue(x);
736 SpinBox_Y->SetValue(y);
737 SpinBox_Z->SetValue(z);
738 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
739 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
740 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
741 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
746 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
747 LineEditElements->setText(aString);
748 LineEditElements->repaint();
749 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
750 LineEditElements->setEnabled(true);
756 if (myNbOkElements && IsAxisOk()) {
757 buttonOk->setEnabled(true);
758 buttonApply->setEnabled(true);
760 onDisplaySimulation(true);
763 //=================================================================================
764 // function : SetEditCurrentArgument()
766 //=================================================================================
767 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
769 QPushButton* send = (QPushButton*)sender();
771 disconnect(mySelectionMgr, 0, this, 0);
772 mySelectionMgr->clearSelected();
773 mySelectionMgr->clearFilters();
775 switch (myConstructorId) {
776 case 0: /* default constructor */
778 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
779 if (send == SelectElementsButton) {
780 myEditCurrentArgument = (QWidget*)LineEditElements;
781 SMESH::SetPointRepresentation(false);
782 if (CheckBoxMesh->isChecked()) {
784 aViewWindow->SetSelectionMode(ActorSelection);
785 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
788 aViewWindow->SetSelectionMode( CellSelection );
790 } else if (send == SelectPointButton) {
791 myEditCurrentArgument = (QWidget*)SpinBox_X;
792 SMESH::SetPointRepresentation(true);
794 aViewWindow->SetSelectionMode( NodeSelection );
795 } else if (send == SelectVectorButton) {
796 myEditCurrentArgument = (QWidget*)SpinBox_DX;
797 SMESH::SetPointRepresentation(true);
799 aViewWindow->SetSelectionMode( NodeSelection );
806 myEditCurrentArgument->setFocus();
807 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
808 SelectionIntoArgument();
811 //=================================================================================
812 // function : DeactivateActiveDialog()
814 //=================================================================================
815 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
817 if (GroupConstructors->isEnabled()) {
818 GroupConstructors->setEnabled(false);
819 GroupArguments->setEnabled(false);
820 GroupButtons->setEnabled(false);
821 mySMESHGUI->ResetState();
822 mySMESHGUI->SetActiveDialogBox(0);
826 //=================================================================================
827 // function : ActivateThisDialog()
829 //=================================================================================
830 void SMESHGUI_RotationDlg::ActivateThisDialog()
832 /* Emit a signal to deactivate the active dialog */
833 mySMESHGUI->EmitSignalDeactivateDialog();
834 GroupConstructors->setEnabled(true);
835 GroupArguments->setEnabled(true);
836 GroupButtons->setEnabled(true);
838 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
840 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
841 aViewWindow->SetSelectionMode( CellSelection );
842 SelectionIntoArgument();
845 //=================================================================================
846 // function : enterEvent()
848 //=================================================================================
849 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
851 if (!GroupConstructors->isEnabled())
852 ActivateThisDialog();
855 //=================================================================================
856 // function : closeEvent()
858 //=================================================================================
859 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
861 /* same than click on cancel button */
865 //=================================================================================
866 // function : hideEvent()
867 // purpose : caused by ESC key
868 //=================================================================================
869 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
875 //=================================================================================
876 // function : onSelectMesh()
878 //=================================================================================
879 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
882 TextLabelElements->setText(tr("SMESH_NAME"));
884 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
885 myFilterBtn->setEnabled(!toSelectMesh);
887 if (myEditCurrentArgument != LineEditElements) {
888 LineEditElements->clear();
892 mySelectionMgr->clearFilters();
893 SMESH::SetPointRepresentation(false);
896 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
897 aViewWindow->SetSelectionMode(ActorSelection);
898 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
899 LineEditElements->setReadOnly(true);
900 LineEditElements->setValidator(0);
902 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
903 aViewWindow->SetSelectionMode( CellSelection );
904 LineEditElements->setReadOnly(false);
905 LineEditElements->setValidator(myIdValidator);
906 onTextChange(LineEditElements->text());
910 SelectionIntoArgument();
913 //=================================================================================
914 // function : IsAxisOk()
916 //=================================================================================
917 bool SMESHGUI_RotationDlg::IsAxisOk()
919 return (SpinBox_DX->GetValue() != 0 ||
920 SpinBox_DY->GetValue() != 0 ||
921 SpinBox_DZ->GetValue() != 0);
924 //=================================================================================
925 // function : onVectorChanged()
927 //=================================================================================
928 void SMESHGUI_RotationDlg::onVectorChanged()
931 buttonOk->setEnabled(true);
932 buttonApply->setEnabled(true);
934 buttonOk->setEnabled(false);
935 buttonApply->setEnabled(false);
940 //=======================================================================
941 //function : onActionClicked
942 //purpose : slot called when an action type changed
943 //=======================================================================
945 void SMESHGUI_RotationDlg::onActionClicked(int button)
948 case MOVE_ELEMS_BUTTON:
949 MakeGroupsCheck->setEnabled(false);
950 LineEditNewMesh->setEnabled(false);
952 case COPY_ELEMS_BUTTON:
953 LineEditNewMesh->setEnabled(false);
954 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
955 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
956 MakeGroupsCheck->setEnabled(true);
958 MakeGroupsCheck->setEnabled(false);
960 case MAKE_MESH_BUTTON:
961 LineEditNewMesh->setEnabled(true);
962 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
963 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
964 MakeGroupsCheck->setEnabled(true);
966 MakeGroupsCheck->setEnabled(false);
970 toDisplaySimulation();
973 //=======================================================================
974 //function : setNewMeshName
975 //purpose : update contents of LineEditNewMesh
976 //=======================================================================
978 void SMESHGUI_RotationDlg::setNewMeshName()
980 LineEditNewMesh->setText("");
981 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
983 if ( CheckBoxMesh->isChecked() ) {
984 name = LineEditElements->text();
987 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
988 name = meshSO->GetName().c_str();
990 if ( !name.isEmpty() )
991 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
995 //=================================================================================
996 // function : keyPressEvent()
998 //=================================================================================
999 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
1001 QDialog::keyPressEvent( e );
1002 if ( e->isAccepted() )
1005 if ( e->key() == Qt::Key_F1 ) {
1011 //=================================================================================
1012 // function : setFilters()
1013 // purpose : SLOT. Called when "Filter" button pressed.
1014 //=================================================================================
1015 void SMESHGUI_RotationDlg::setFilters()
1017 if(myMesh->_is_nil()) {
1018 SUIT_MessageBox::critical(this,
1020 tr("NO_MESH_SELECTED"));
1024 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1026 myFilterDlg->SetSelection();
1027 myFilterDlg->SetMesh( myMesh );
1028 myFilterDlg->SetSourceWg( LineEditElements );
1030 myFilterDlg->show();
1033 //=================================================================================
1034 // function : isValid
1036 //=================================================================================
1037 bool SMESHGUI_RotationDlg::isValid()
1042 ok = SpinBox_X->isValid( msg, true ) && ok;
1043 ok = SpinBox_Y->isValid( msg, true ) && ok;
1044 ok = SpinBox_Z->isValid( msg, true ) && ok;
1045 ok = SpinBox_DX->isValid( msg, true ) && ok;
1046 ok = SpinBox_DY->isValid( msg, true ) && ok;
1047 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1048 ok = SpinBox_Angle->isValid( msg, true ) && ok;
1051 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1052 if ( !msg.isEmpty() )
1054 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1061 //=================================================================================
1062 // function : onDisplaySimulation
1063 // purpose : Show/Hide preview
1064 //=================================================================================
1065 void SMESHGUI_RotationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1066 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1067 if(myNbOkElements && isValid() && IsAxisOk()) {
1068 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1069 SMESH::long_array_var anElementsId = new SMESH::long_array;
1071 anElementsId->length(aListElementsId.count());
1072 for (int i = 0; i < aListElementsId.count(); i++)
1073 anElementsId[i] = aListElementsId[i].toInt();
1075 SMESH::AxisStruct anAxis;
1077 anAxis.x = SpinBox_X->GetValue();
1078 anAxis.y = SpinBox_Y->GetValue();
1079 anAxis.z = SpinBox_Z->GetValue();;
1080 anAxis.vx = SpinBox_DX->GetValue();
1081 anAxis.vy = SpinBox_DY->GetValue();
1082 anAxis.vz = SpinBox_DZ->GetValue();
1083 double anAngle = (SpinBox_Angle->GetValue())*PI/180;
1086 SUIT_OverrideCursor aWaitCursor;
1087 bool copy = ActionGroup->checkedId() == COPY_ELEMS_BUTTON;
1088 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1089 if(CheckBoxMesh->isChecked())
1090 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, copy);
1092 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, copy);
1094 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1095 mySimulation->SetData(aMeshPreviewStruct._retn());