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() );
433 QStringList anEntryList;
435 SUIT_OverrideCursor aWaitCursor;
436 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
437 switch ( actionButton ) {
438 case MOVE_ELEMS_BUTTON:
439 if(CheckBoxMesh->isChecked())
440 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, false);
442 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
443 if( !myMesh->_is_nil())
444 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
446 case COPY_ELEMS_BUTTON:
448 SMESH::ListOfGroups_var groups;
449 if(CheckBoxMesh->isChecked())
450 groups = aMeshEditor->RotateObjectMakeGroups(mySelectedObject, anAxis, anAngle);
452 groups = aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
455 if(CheckBoxMesh->isChecked())
456 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, true);
458 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
460 if( !myMesh->_is_nil())
461 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
463 case MAKE_MESH_BUTTON: {
464 SMESH::SMESH_Mesh_var mesh;
465 if (CheckBoxMesh->isChecked())
466 mesh = aMeshEditor->RotateObjectMakeMesh(mySelectedObject, anAxis, anAngle, makeGroups,
467 LineEditNewMesh->text().toLatin1().data());
469 mesh = aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
470 LineEditNewMesh->text().toLatin1().data());
471 if (!mesh->_is_nil()) {
472 mesh->SetParameters(aParameters.join(":").toLatin1().constData());
473 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
474 anEntryList.append( aSObject->GetID().c_str() );
475 #ifdef WITHGENERICOBJ
476 // obj has been published in study. Its refcount has been incremented.
477 // It is safe to decrement its refcount
478 // so that it will be destroyed when the entry in study will be removed
489 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
490 actionButton == MAKE_MESH_BUTTON ) {
491 mySMESHGUI->updateObjBrowser(true); // new groups may appear
492 if( LightApp_Application* anApp =
493 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
494 anApp->browseObjects( anEntryList, isApplyAndClose() );
497 mySelectedObject = SMESH::SMESH_IDSource::_nil();
498 SelectionIntoArgument();
500 SMESHGUI::Modified();
506 //=================================================================================
507 // function : ClickOnOk()
509 //=================================================================================
510 void SMESHGUI_RotationDlg::ClickOnOk()
512 setIsApplyAndClose( true );
517 //=================================================================================
518 // function : ClickOnCancel()
520 //=================================================================================
521 void SMESHGUI_RotationDlg::ClickOnCancel()
523 disconnect(mySelectionMgr, 0, this, 0);
524 mySelectionMgr->clearFilters();
525 //mySelectionMgr->clearSelected();
526 if (SMESH::GetCurrentVtkView()) {
527 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
528 SMESH::SetPointRepresentation(false);
530 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
531 aViewWindow->SetSelectionMode(ActorSelection);
532 mySMESHGUI->ResetState();
536 //=================================================================================
537 // function : ClickOnHelp()
539 //=================================================================================
540 void SMESHGUI_RotationDlg::ClickOnHelp()
542 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
544 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
548 platform = "winapplication";
550 platform = "application";
552 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
553 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
554 arg(app->resourceMgr()->stringValue("ExternalBrowser",
556 arg(myHelpFileName));
560 //=======================================================================
561 // function : onTextChange()
563 //=======================================================================
564 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
566 QLineEdit* send = (QLineEdit*)sender();
571 if (send == LineEditElements)
574 buttonOk->setEnabled(false);
575 buttonApply->setEnabled(false);
577 // hilight entered elements
578 SMDS_Mesh* aMesh = 0;
580 aMesh = myActor->GetObject()->GetMesh();
583 if (send == LineEditElements) {
584 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
586 TColStd_MapOfInteger newIndices;
588 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
589 for (int i = 0; i < aListId.count(); i++) {
590 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
592 newIndices.Add(e->GetID());
596 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
597 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
598 aViewWindow->highlight( anIO, true, true );
600 myElementsId = theNewText;
604 if (myNbOkElements && IsAxisOk()) {
605 buttonOk->setEnabled(true);
606 buttonApply->setEnabled(true);
612 //=================================================================================
613 // function : SelectionIntoArgument()
614 // purpose : Called when selection as changed or other case
615 //=================================================================================
616 void SMESHGUI_RotationDlg::SelectionIntoArgument()
622 QString aString = "";
625 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
626 LineEditElements->setText(aString);
628 buttonOk->setEnabled(false);
629 buttonApply->setEnabled(false);
633 if (!GroupButtons->isEnabled()) // inactive
638 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
640 int nbSel = aList.Extent();
644 Handle(SALOME_InteractiveObject) IO = aList.First();
645 myMesh = SMESH::GetMeshByIO(IO);
646 if (myMesh->_is_nil())
649 myActor = SMESH::FindActorByObject(myMesh);
651 myActor = SMESH::FindActorByEntry(IO->getEntry());
652 if (!myActor && !CheckBoxMesh->isChecked())
657 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
660 // MakeGroups is available if there are groups and "Copy"
661 if ( myMesh->NbGroups() == 0 ) {
662 MakeGroupsCheck->setChecked(false);
663 MakeGroupsCheck->setEnabled(false);
665 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
666 MakeGroupsCheck->setEnabled(true);
668 if (CheckBoxMesh->isChecked()) {
669 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
671 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
672 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
678 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
682 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
683 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
685 myElementsId += QString(" %1").arg(i);
689 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
691 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
693 // get IDs from submesh
694 SMESH::long_array_var anElementsIds = new SMESH::long_array;
695 anElementsIds = aSubMesh->GetElementsId();
696 for (int i = 0; i < anElementsIds->length(); i++) {
697 myElementsId += QString(" %1").arg(anElementsIds[i]);
699 aNbUnits = anElementsIds->length();
702 SMESH::SMESH_GroupBase_var aGroup =
703 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
704 if (aGroup->_is_nil())
707 // get IDs from smesh group
708 SMESH::long_array_var anElementsIds = new SMESH::long_array;
709 anElementsIds = aGroup->GetListOfID();
710 for (int i = 0; i < anElementsIds->length(); i++) {
711 myElementsId += QString(" %1").arg(anElementsIds[i]);
713 aNbUnits = anElementsIds->length();
717 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
718 myElementsId = aString;
723 myNbOkElements = true;
726 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
730 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
734 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
742 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
743 SpinBox_X->SetValue(x);
744 SpinBox_Y->SetValue(y);
745 SpinBox_Z->SetValue(z);
746 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
747 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
748 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
749 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
754 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
755 LineEditElements->setText(aString);
756 LineEditElements->repaint();
757 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
758 LineEditElements->setEnabled(true);
764 if (myNbOkElements && IsAxisOk()) {
765 buttonOk->setEnabled(true);
766 buttonApply->setEnabled(true);
768 onDisplaySimulation(true);
771 //=================================================================================
772 // function : SetEditCurrentArgument()
774 //=================================================================================
775 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
777 QPushButton* send = (QPushButton*)sender();
779 disconnect(mySelectionMgr, 0, this, 0);
780 mySelectionMgr->clearSelected();
781 mySelectionMgr->clearFilters();
783 switch (myConstructorId) {
784 case 0: /* default constructor */
786 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
787 if (send == SelectElementsButton) {
788 myEditCurrentArgument = (QWidget*)LineEditElements;
789 SMESH::SetPointRepresentation(false);
790 if (CheckBoxMesh->isChecked()) {
792 aViewWindow->SetSelectionMode(ActorSelection);
793 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
796 aViewWindow->SetSelectionMode( CellSelection );
798 } else if (send == SelectPointButton) {
799 myEditCurrentArgument = (QWidget*)SpinBox_X;
800 SMESH::SetPointRepresentation(true);
802 aViewWindow->SetSelectionMode( NodeSelection );
803 } else if (send == SelectVectorButton) {
804 myEditCurrentArgument = (QWidget*)SpinBox_DX;
805 SMESH::SetPointRepresentation(true);
807 aViewWindow->SetSelectionMode( NodeSelection );
814 myEditCurrentArgument->setFocus();
815 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
816 SelectionIntoArgument();
819 //=================================================================================
820 // function : DeactivateActiveDialog()
822 //=================================================================================
823 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
825 if (GroupConstructors->isEnabled()) {
826 GroupConstructors->setEnabled(false);
827 GroupArguments->setEnabled(false);
828 GroupButtons->setEnabled(false);
829 mySMESHGUI->ResetState();
830 mySMESHGUI->SetActiveDialogBox(0);
834 //=================================================================================
835 // function : ActivateThisDialog()
837 //=================================================================================
838 void SMESHGUI_RotationDlg::ActivateThisDialog()
840 /* Emit a signal to deactivate the active dialog */
841 mySMESHGUI->EmitSignalDeactivateDialog();
842 GroupConstructors->setEnabled(true);
843 GroupArguments->setEnabled(true);
844 GroupButtons->setEnabled(true);
846 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
848 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
849 aViewWindow->SetSelectionMode( CellSelection );
850 SelectionIntoArgument();
853 //=================================================================================
854 // function : enterEvent()
856 //=================================================================================
857 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
859 if (!GroupConstructors->isEnabled())
860 ActivateThisDialog();
863 //=================================================================================
864 // function : closeEvent()
866 //=================================================================================
867 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
869 /* same than click on cancel button */
873 //=================================================================================
874 // function : hideEvent()
875 // purpose : caused by ESC key
876 //=================================================================================
877 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
883 //=================================================================================
884 // function : onSelectMesh()
886 //=================================================================================
887 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
890 TextLabelElements->setText(tr("SMESH_NAME"));
892 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
893 myFilterBtn->setEnabled(!toSelectMesh);
895 if (myEditCurrentArgument != LineEditElements) {
896 LineEditElements->clear();
900 mySelectionMgr->clearFilters();
901 SMESH::SetPointRepresentation(false);
904 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
905 aViewWindow->SetSelectionMode(ActorSelection);
906 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
907 LineEditElements->setReadOnly(true);
908 LineEditElements->setValidator(0);
910 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
911 aViewWindow->SetSelectionMode( CellSelection );
912 LineEditElements->setReadOnly(false);
913 LineEditElements->setValidator(myIdValidator);
914 onTextChange(LineEditElements->text());
918 SelectionIntoArgument();
921 //=================================================================================
922 // function : IsAxisOk()
924 //=================================================================================
925 bool SMESHGUI_RotationDlg::IsAxisOk()
927 return (SpinBox_DX->GetValue() != 0 ||
928 SpinBox_DY->GetValue() != 0 ||
929 SpinBox_DZ->GetValue() != 0);
932 //=================================================================================
933 // function : onVectorChanged()
935 //=================================================================================
936 void SMESHGUI_RotationDlg::onVectorChanged()
939 buttonOk->setEnabled(true);
940 buttonApply->setEnabled(true);
942 buttonOk->setEnabled(false);
943 buttonApply->setEnabled(false);
948 //=======================================================================
949 //function : onActionClicked
950 //purpose : slot called when an action type changed
951 //=======================================================================
953 void SMESHGUI_RotationDlg::onActionClicked(int button)
956 case MOVE_ELEMS_BUTTON:
957 MakeGroupsCheck->setEnabled(false);
958 LineEditNewMesh->setEnabled(false);
960 case COPY_ELEMS_BUTTON:
961 LineEditNewMesh->setEnabled(false);
962 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
963 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
964 MakeGroupsCheck->setEnabled(true);
966 MakeGroupsCheck->setEnabled(false);
968 case MAKE_MESH_BUTTON:
969 LineEditNewMesh->setEnabled(true);
970 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
971 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
972 MakeGroupsCheck->setEnabled(true);
974 MakeGroupsCheck->setEnabled(false);
978 toDisplaySimulation();
981 //=======================================================================
982 //function : setNewMeshName
983 //purpose : update contents of LineEditNewMesh
984 //=======================================================================
986 void SMESHGUI_RotationDlg::setNewMeshName()
988 LineEditNewMesh->setText("");
989 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
991 if ( CheckBoxMesh->isChecked() ) {
992 name = LineEditElements->text();
995 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
996 name = meshSO->GetName().c_str();
998 if ( !name.isEmpty() )
999 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
1003 //=================================================================================
1004 // function : keyPressEvent()
1006 //=================================================================================
1007 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
1009 QDialog::keyPressEvent( e );
1010 if ( e->isAccepted() )
1013 if ( e->key() == Qt::Key_F1 ) {
1019 //=================================================================================
1020 // function : setFilters()
1021 // purpose : SLOT. Called when "Filter" button pressed.
1022 //=================================================================================
1023 void SMESHGUI_RotationDlg::setFilters()
1025 if(myMesh->_is_nil()) {
1026 SUIT_MessageBox::critical(this,
1028 tr("NO_MESH_SELECTED"));
1032 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1034 myFilterDlg->SetSelection();
1035 myFilterDlg->SetMesh( myMesh );
1036 myFilterDlg->SetSourceWg( LineEditElements );
1038 myFilterDlg->show();
1041 //=================================================================================
1042 // function : isValid
1044 //=================================================================================
1045 bool SMESHGUI_RotationDlg::isValid()
1050 ok = SpinBox_X->isValid( msg, true ) && ok;
1051 ok = SpinBox_Y->isValid( msg, true ) && ok;
1052 ok = SpinBox_Z->isValid( msg, true ) && ok;
1053 ok = SpinBox_DX->isValid( msg, true ) && ok;
1054 ok = SpinBox_DY->isValid( msg, true ) && ok;
1055 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1056 ok = SpinBox_Angle->isValid( msg, true ) && ok;
1059 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1060 if ( !msg.isEmpty() )
1062 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1069 //=================================================================================
1070 // function : onDisplaySimulation
1071 // purpose : Show/Hide preview
1072 //=================================================================================
1073 void SMESHGUI_RotationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1074 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1075 if(myNbOkElements && isValid() && IsAxisOk()) {
1076 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1077 SMESH::long_array_var anElementsId = new SMESH::long_array;
1079 anElementsId->length(aListElementsId.count());
1080 for (int i = 0; i < aListElementsId.count(); i++)
1081 anElementsId[i] = aListElementsId[i].toInt();
1083 SMESH::AxisStruct anAxis;
1085 anAxis.x = SpinBox_X->GetValue();
1086 anAxis.y = SpinBox_Y->GetValue();
1087 anAxis.z = SpinBox_Z->GetValue();;
1088 anAxis.vx = SpinBox_DX->GetValue();
1089 anAxis.vy = SpinBox_DY->GetValue();
1090 anAxis.vz = SpinBox_DZ->GetValue();
1091 double anAngle = (SpinBox_Angle->GetValue())*PI/180;
1094 SUIT_OverrideCursor aWaitCursor;
1095 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1096 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1097 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1098 if(CheckBoxMesh->isChecked())
1099 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, copy);
1101 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, copy);
1103 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1104 mySimulation->SetData(aMeshPreviewStruct._retn());