1 // Copyright (C) 2007-2011 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 // File : SMESHGUI_RotationDlg.cxx
23 // Author : Michael ZORIN, Open CASCADE S.A.S.
26 #include "SMESHGUI_RotationDlg.h"
29 #include "SMESHGUI_SpinBox.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_IdValidator.h"
34 #include "SMESHGUI_FilterDlg.h"
35 #include "SMESHGUI_MeshEditPreview.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 SMESHGUI_PreviewDlg( theModule ),
96 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
98 mySelectedObject(SMESH::SMESH_IDSource::_nil())
100 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_ROTATION")));
101 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
104 setAttribute(Qt::WA_DeleteOnClose, true);
105 setWindowTitle(tr("SMESH_ROTATION_TITLE"));
106 setSizeGripEnabled(true);
108 QVBoxLayout* SMESHGUI_RotationDlgLayout = new QVBoxLayout(this);
109 SMESHGUI_RotationDlgLayout->setSpacing(SPACING);
110 SMESHGUI_RotationDlgLayout->setMargin(MARGIN);
112 /***************************************************************/
113 GroupConstructors = new QGroupBox(tr("SMESH_ROTATION"), this);
114 QButtonGroup* ButtonGroup = new QButtonGroup(this);
115 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
116 GroupConstructorsLayout->setSpacing(SPACING);
117 GroupConstructorsLayout->setMargin(MARGIN);
119 RadioButton1= new QRadioButton(GroupConstructors);
120 RadioButton1->setIcon(image0);
122 GroupConstructorsLayout->addWidget(RadioButton1);
123 ButtonGroup->addButton(RadioButton1, 0);
125 /***************************************************************/
126 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
127 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
128 GroupArgumentsLayout->setSpacing(SPACING);
129 GroupArgumentsLayout->setMargin(MARGIN);
131 myIdValidator = new SMESHGUI_IdValidator(this);
133 // Controls for elements selection
134 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
135 SelectElementsButton = new QPushButton(GroupArguments);
136 SelectElementsButton->setIcon(image1);
137 LineEditElements = new QLineEdit(GroupArguments);
138 LineEditElements->setValidator(myIdValidator);
139 LineEditElements->setMaxLength(-1);
140 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
141 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
143 // Control for the whole mesh selection
144 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
146 // Controls for axis defining
147 GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
148 QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
149 GroupAxisLayout->setSpacing(SPACING);
150 GroupAxisLayout->setMargin(MARGIN);
152 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
153 SelectPointButton = new QPushButton(GroupAxis);
154 SelectPointButton->setIcon(image1);
156 TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
157 SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
158 TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
159 SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
160 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
161 SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
163 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
164 SelectVectorButton = new QPushButton(GroupAxis);
165 SelectVectorButton->setIcon(image1);
167 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
168 SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
169 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
170 SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
171 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
172 SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
174 GroupAxisLayout->addWidget(TextLabelPoint, 0, 0);
175 GroupAxisLayout->addWidget(SelectPointButton, 0, 1);
176 GroupAxisLayout->addWidget(TextLabelX, 0, 2);
177 GroupAxisLayout->addWidget(SpinBox_X, 0, 3);
178 GroupAxisLayout->addWidget(TextLabelY, 0, 4);
179 GroupAxisLayout->addWidget(SpinBox_Y, 0, 5);
180 GroupAxisLayout->addWidget(TextLabelZ, 0, 6);
181 GroupAxisLayout->addWidget(SpinBox_Z, 0, 7);
182 GroupAxisLayout->addWidget(TextLabelVector, 1, 0);
183 GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
184 GroupAxisLayout->addWidget(TextLabelDX, 1, 2);
185 GroupAxisLayout->addWidget(SpinBox_DX, 1, 3);
186 GroupAxisLayout->addWidget(TextLabelDY, 1, 4);
187 GroupAxisLayout->addWidget(SpinBox_DY, 1, 5);
188 GroupAxisLayout->addWidget(TextLabelDZ, 1, 6);
189 GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7);
191 // Controls for angle defining
192 TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupArguments);
193 SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments);
196 ActionBox = new QGroupBox(GroupArguments);
197 ActionGroup = new QButtonGroup(GroupArguments);
198 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
199 ActionBoxLayout->setSpacing(SPACING);
200 ActionBoxLayout->setMargin(MARGIN);
202 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
203 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
204 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
206 ActionBoxLayout->addWidget(aMoveElements);
207 ActionBoxLayout->addWidget(aCopyElements);
208 ActionBoxLayout->addWidget(aCreateMesh);
209 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
210 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
211 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
213 // CheckBox for groups generation
214 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
216 // Name of a mesh to create
217 LineEditNewMesh = new QLineEdit(GroupArguments);
221 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
223 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
224 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
225 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
226 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
227 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
228 GroupArgumentsLayout->addWidget(GroupAxis, 2, 0, 1, 4);
229 GroupArgumentsLayout->addWidget(TextLabelAngle, 3, 0, 1, 2);
230 GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
231 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 3);
232 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 3);
233 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 3);
234 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 7, 0);
237 /***************************************************************/
238 GroupButtons = new QGroupBox(this);
239 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
240 GroupButtonsLayout->setSpacing(SPACING);
241 GroupButtonsLayout->setMargin(MARGIN);
243 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
244 buttonOk->setAutoDefault(true);
245 buttonOk->setDefault(true);
246 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
247 buttonApply->setAutoDefault(true);
248 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
249 buttonCancel->setAutoDefault(true);
250 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
251 buttonHelp->setAutoDefault(true);
253 GroupButtonsLayout->addWidget(buttonOk);
254 GroupButtonsLayout->addSpacing(10);
255 GroupButtonsLayout->addWidget(buttonApply);
256 GroupButtonsLayout->addSpacing(10);
257 GroupButtonsLayout->addStretch();
258 GroupButtonsLayout->addWidget(buttonCancel);
259 GroupButtonsLayout->addWidget(buttonHelp);
261 /***************************************************************/
262 SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors);
263 SMESHGUI_RotationDlgLayout->addWidget(GroupArguments);
264 SMESHGUI_RotationDlgLayout->addWidget(GroupButtons);
266 /* Initialisations */
267 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
268 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
269 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
270 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
271 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
272 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
274 SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, "angle_precision");
277 RadioButton1->setChecked(true);
279 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
281 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
283 // Costruction of the logical filter
284 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
285 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
287 QList<SUIT_SelectionFilter*> aListOfFilters;
288 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
289 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
291 myMeshOrSubMeshOrGroupFilter =
292 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
294 myHelpFileName = "rotation_page.html";
298 /* signals and slots connections */
299 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
300 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
301 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
302 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
304 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
305 connect(SelectPointButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
306 connect(SelectVectorButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
308 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
309 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
310 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
312 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
313 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
314 /* to close dialog if study change */
315 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
316 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
317 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
318 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
320 connect(SpinBox_X, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
321 connect(SpinBox_Y, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
322 connect(SpinBox_Z, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
323 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
324 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
325 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326 connect(SpinBox_Angle, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
328 //To Connect preview check box
329 connectPreviewControl();
331 onActionClicked(MOVE_ELEMS_BUTTON);
334 //=================================================================================
335 // function : ~SMESHGUI_RotationDlg()
336 // purpose : Destroys the object and frees any allocated resources
337 //=================================================================================
338 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
341 myFilterDlg->setParent( 0 );
347 //=================================================================================
350 //=================================================================================
351 void SMESHGUI_RotationDlg::Init (bool ResetControls)
355 myEditCurrentArgument = (QWidget*)LineEditElements;
356 LineEditElements->setFocus();
360 buttonOk->setEnabled(false);
361 buttonApply->setEnabled(false);
364 myMesh = SMESH::SMESH_Mesh::_nil();
367 SpinBox_X->SetValue(0.0);
368 SpinBox_Y->SetValue(0.0);
369 SpinBox_Z->SetValue(0.0);
370 SpinBox_DX->SetValue(0.0);
371 SpinBox_DY->SetValue(0.0);
372 SpinBox_DZ->SetValue(0.0);
374 SpinBox_Angle->SetValue(45);
376 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
377 CheckBoxMesh->setChecked(false);
378 myPreviewCheckBox->setChecked(false);
379 onDisplaySimulation(false);
381 // MakeGroupsCheck->setChecked(false);
382 // MakeGroupsCheck->setEnabled(false);
383 // onSelectMesh(false);
386 onSelectMesh(CheckBoxMesh->isChecked());
389 //=================================================================================
390 // function : ClickOnApply()
392 //=================================================================================
393 bool SMESHGUI_RotationDlg::ClickOnApply()
395 if (mySMESHGUI->isActiveStudyLocked())
401 if (myNbOkElements && IsAxisOk()) {
402 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
404 SMESH::long_array_var anElementsId = new SMESH::long_array;
406 anElementsId->length(aListElementsId.count());
407 for (int i = 0; i < aListElementsId.count(); i++)
408 anElementsId[i] = aListElementsId[i].toInt();
410 SMESH::AxisStruct anAxis;
412 anAxis.x = SpinBox_X->GetValue();
413 anAxis.y = SpinBox_Y->GetValue();
414 anAxis.z = SpinBox_Z->GetValue();;
415 anAxis.vx = SpinBox_DX->GetValue();
416 anAxis.vy = SpinBox_DY->GetValue();
417 anAxis.vz = SpinBox_DZ->GetValue();
419 double anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
421 QStringList aParameters;
422 aParameters << SpinBox_X->text();
423 aParameters << SpinBox_Y->text();
424 aParameters << SpinBox_Z->text();
425 aParameters << SpinBox_DX->text();
426 aParameters << SpinBox_DY->text();
427 aParameters << SpinBox_DZ->text();
428 aParameters << SpinBox_Angle->text();
430 int actionButton = ActionGroup->checkedId();
431 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
432 QStringList anEntryList;
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 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
473 anEntryList.append( aSObject->GetID().c_str() );
474 #ifdef WITHGENERICOBJ
475 // obj has been published in study. Its refcount has been incremented.
476 // It is safe to decrement its refcount
477 // so that it will be destroyed when the entry in study will be removed
488 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
489 actionButton == MAKE_MESH_BUTTON ) {
490 mySMESHGUI->updateObjBrowser(true); // new groups may appear
491 if( LightApp_Application* anApp =
492 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
493 anApp->browseObjects( anEntryList, isApplyAndClose() );
496 mySelectedObject = SMESH::SMESH_IDSource::_nil();
497 SelectionIntoArgument();
499 SMESHGUI::Modified();
505 //=================================================================================
506 // function : ClickOnOk()
508 //=================================================================================
509 void SMESHGUI_RotationDlg::ClickOnOk()
511 setIsApplyAndClose( true );
516 //=================================================================================
517 // function : ClickOnCancel()
519 //=================================================================================
520 void SMESHGUI_RotationDlg::ClickOnCancel()
522 disconnect(mySelectionMgr, 0, this, 0);
523 mySelectionMgr->clearFilters();
524 //mySelectionMgr->clearSelected();
525 if (SMESH::GetCurrentVtkView()) {
526 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
527 SMESH::SetPointRepresentation(false);
529 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
530 aViewWindow->SetSelectionMode(ActorSelection);
531 mySMESHGUI->ResetState();
535 //=================================================================================
536 // function : ClickOnHelp()
538 //=================================================================================
539 void SMESHGUI_RotationDlg::ClickOnHelp()
541 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
543 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
547 platform = "winapplication";
549 platform = "application";
551 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
552 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
553 arg(app->resourceMgr()->stringValue("ExternalBrowser",
555 arg(myHelpFileName));
559 //=======================================================================
560 // function : onTextChange()
562 //=======================================================================
563 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
565 QLineEdit* send = (QLineEdit*)sender();
570 if (send == LineEditElements)
573 buttonOk->setEnabled(false);
574 buttonApply->setEnabled(false);
576 // hilight entered elements
577 SMDS_Mesh* aMesh = 0;
579 aMesh = myActor->GetObject()->GetMesh();
582 if (send == LineEditElements) {
583 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
585 TColStd_MapOfInteger newIndices;
587 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
588 for (int i = 0; i < aListId.count(); i++) {
589 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
591 newIndices.Add(e->GetID());
595 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
596 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
597 aViewWindow->highlight( anIO, true, true );
599 myElementsId = theNewText;
603 if (myNbOkElements && IsAxisOk()) {
604 buttonOk->setEnabled(true);
605 buttonApply->setEnabled(true);
611 //=================================================================================
612 // function : SelectionIntoArgument()
613 // purpose : Called when selection as changed or other case
614 //=================================================================================
615 void SMESHGUI_RotationDlg::SelectionIntoArgument()
621 QString aString = "";
624 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
625 LineEditElements->setText(aString);
627 buttonOk->setEnabled(false);
628 buttonApply->setEnabled(false);
632 if (!GroupButtons->isEnabled()) // inactive
637 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
639 int nbSel = aList.Extent();
643 Handle(SALOME_InteractiveObject) IO = aList.First();
644 myMesh = SMESH::GetMeshByIO(IO);
645 if (myMesh->_is_nil())
648 myActor = SMESH::FindActorByObject(myMesh);
650 myActor = SMESH::FindActorByEntry(IO->getEntry());
651 if (!myActor && !CheckBoxMesh->isChecked())
656 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
659 // MakeGroups is available if there are groups and "Copy"
660 if ( myMesh->NbGroups() == 0 ) {
661 MakeGroupsCheck->setChecked(false);
662 MakeGroupsCheck->setEnabled(false);
664 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
665 MakeGroupsCheck->setEnabled(true);
667 if (CheckBoxMesh->isChecked()) {
668 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
670 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
671 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
677 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
681 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
682 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
684 myElementsId += QString(" %1").arg(i);
688 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
690 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
692 // get IDs from submesh
693 SMESH::long_array_var anElementsIds = new SMESH::long_array;
694 anElementsIds = aSubMesh->GetElementsId();
695 for (int i = 0; i < anElementsIds->length(); i++) {
696 myElementsId += QString(" %1").arg(anElementsIds[i]);
698 aNbUnits = anElementsIds->length();
701 SMESH::SMESH_GroupBase_var aGroup =
702 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
703 if (aGroup->_is_nil())
706 // get IDs from smesh group
707 SMESH::long_array_var anElementsIds = new SMESH::long_array;
708 anElementsIds = aGroup->GetListOfID();
709 for (int i = 0; i < anElementsIds->length(); i++) {
710 myElementsId += QString(" %1").arg(anElementsIds[i]);
712 aNbUnits = anElementsIds->length();
716 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
717 myElementsId = aString;
722 myNbOkElements = true;
725 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
729 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
733 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
741 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
742 SpinBox_X->SetValue(x);
743 SpinBox_Y->SetValue(y);
744 SpinBox_Z->SetValue(z);
745 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
746 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
747 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
748 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
753 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
754 LineEditElements->setText(aString);
755 LineEditElements->repaint();
756 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
757 LineEditElements->setEnabled(true);
763 if (myNbOkElements && IsAxisOk()) {
764 buttonOk->setEnabled(true);
765 buttonApply->setEnabled(true);
767 onDisplaySimulation(true);
770 //=================================================================================
771 // function : SetEditCurrentArgument()
773 //=================================================================================
774 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
776 QPushButton* send = (QPushButton*)sender();
778 disconnect(mySelectionMgr, 0, this, 0);
779 mySelectionMgr->clearSelected();
780 mySelectionMgr->clearFilters();
782 switch (myConstructorId) {
783 case 0: /* default constructor */
785 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
786 if (send == SelectElementsButton) {
787 myEditCurrentArgument = (QWidget*)LineEditElements;
788 SMESH::SetPointRepresentation(false);
789 if (CheckBoxMesh->isChecked()) {
791 aViewWindow->SetSelectionMode(ActorSelection);
792 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
795 aViewWindow->SetSelectionMode( CellSelection );
797 } else if (send == SelectPointButton) {
798 myEditCurrentArgument = (QWidget*)SpinBox_X;
799 SMESH::SetPointRepresentation(true);
801 aViewWindow->SetSelectionMode( NodeSelection );
802 } else if (send == SelectVectorButton) {
803 myEditCurrentArgument = (QWidget*)SpinBox_DX;
804 SMESH::SetPointRepresentation(true);
806 aViewWindow->SetSelectionMode( NodeSelection );
813 myEditCurrentArgument->setFocus();
814 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
815 SelectionIntoArgument();
818 //=================================================================================
819 // function : DeactivateActiveDialog()
821 //=================================================================================
822 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
824 if (GroupConstructors->isEnabled()) {
825 GroupConstructors->setEnabled(false);
826 GroupArguments->setEnabled(false);
827 GroupButtons->setEnabled(false);
828 mySMESHGUI->ResetState();
829 mySMESHGUI->SetActiveDialogBox(0);
833 //=================================================================================
834 // function : ActivateThisDialog()
836 //=================================================================================
837 void SMESHGUI_RotationDlg::ActivateThisDialog()
839 /* Emit a signal to deactivate the active dialog */
840 mySMESHGUI->EmitSignalDeactivateDialog();
841 GroupConstructors->setEnabled(true);
842 GroupArguments->setEnabled(true);
843 GroupButtons->setEnabled(true);
845 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
847 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
848 aViewWindow->SetSelectionMode( CellSelection );
849 SelectionIntoArgument();
852 //=================================================================================
853 // function : enterEvent()
855 //=================================================================================
856 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
858 if (!GroupConstructors->isEnabled())
859 ActivateThisDialog();
862 //=================================================================================
863 // function : closeEvent()
865 //=================================================================================
866 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
868 /* same than click on cancel button */
872 //=================================================================================
873 // function : hideEvent()
874 // purpose : caused by ESC key
875 //=================================================================================
876 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
882 //=================================================================================
883 // function : onSelectMesh()
885 //=================================================================================
886 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
889 TextLabelElements->setText(tr("SMESH_NAME"));
891 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
892 myFilterBtn->setEnabled(!toSelectMesh);
894 if (myEditCurrentArgument != LineEditElements) {
895 LineEditElements->clear();
899 mySelectionMgr->clearFilters();
900 SMESH::SetPointRepresentation(false);
903 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
904 aViewWindow->SetSelectionMode(ActorSelection);
905 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
906 LineEditElements->setReadOnly(true);
907 LineEditElements->setValidator(0);
909 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
910 aViewWindow->SetSelectionMode( CellSelection );
911 LineEditElements->setReadOnly(false);
912 LineEditElements->setValidator(myIdValidator);
913 onTextChange(LineEditElements->text());
917 SelectionIntoArgument();
920 //=================================================================================
921 // function : IsAxisOk()
923 //=================================================================================
924 bool SMESHGUI_RotationDlg::IsAxisOk()
926 return (SpinBox_DX->GetValue() != 0 ||
927 SpinBox_DY->GetValue() != 0 ||
928 SpinBox_DZ->GetValue() != 0);
931 //=================================================================================
932 // function : onVectorChanged()
934 //=================================================================================
935 void SMESHGUI_RotationDlg::onVectorChanged()
938 buttonOk->setEnabled(true);
939 buttonApply->setEnabled(true);
941 buttonOk->setEnabled(false);
942 buttonApply->setEnabled(false);
947 //=======================================================================
948 //function : onActionClicked
949 //purpose : slot called when an action type changed
950 //=======================================================================
952 void SMESHGUI_RotationDlg::onActionClicked(int button)
955 case MOVE_ELEMS_BUTTON:
956 MakeGroupsCheck->setEnabled(false);
957 LineEditNewMesh->setEnabled(false);
959 case COPY_ELEMS_BUTTON:
960 LineEditNewMesh->setEnabled(false);
961 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
962 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
963 MakeGroupsCheck->setEnabled(true);
965 MakeGroupsCheck->setEnabled(false);
967 case MAKE_MESH_BUTTON:
968 LineEditNewMesh->setEnabled(true);
969 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
970 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
971 MakeGroupsCheck->setEnabled(true);
973 MakeGroupsCheck->setEnabled(false);
977 toDisplaySimulation();
980 //=======================================================================
981 //function : setNewMeshName
982 //purpose : update contents of LineEditNewMesh
983 //=======================================================================
985 void SMESHGUI_RotationDlg::setNewMeshName()
987 LineEditNewMesh->setText("");
988 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
990 if ( CheckBoxMesh->isChecked() ) {
991 name = LineEditElements->text();
994 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
995 name = meshSO->GetName().c_str();
997 if ( !name.isEmpty() )
998 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
1002 //=================================================================================
1003 // function : keyPressEvent()
1005 //=================================================================================
1006 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
1008 QDialog::keyPressEvent( e );
1009 if ( e->isAccepted() )
1012 if ( e->key() == Qt::Key_F1 ) {
1018 //=================================================================================
1019 // function : setFilters()
1020 // purpose : SLOT. Called when "Filter" button pressed.
1021 //=================================================================================
1022 void SMESHGUI_RotationDlg::setFilters()
1024 if(myMesh->_is_nil()) {
1025 SUIT_MessageBox::critical(this,
1027 tr("NO_MESH_SELECTED"));
1031 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1033 myFilterDlg->SetSelection();
1034 myFilterDlg->SetMesh( myMesh );
1035 myFilterDlg->SetSourceWg( LineEditElements );
1037 myFilterDlg->show();
1040 //=================================================================================
1041 // function : isValid
1043 //=================================================================================
1044 bool SMESHGUI_RotationDlg::isValid()
1049 ok = SpinBox_X->isValid( msg, true ) && ok;
1050 ok = SpinBox_Y->isValid( msg, true ) && ok;
1051 ok = SpinBox_Z->isValid( msg, true ) && ok;
1052 ok = SpinBox_DX->isValid( msg, true ) && ok;
1053 ok = SpinBox_DY->isValid( msg, true ) && ok;
1054 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1055 ok = SpinBox_Angle->isValid( msg, true ) && ok;
1058 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1059 if ( !msg.isEmpty() )
1061 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1068 //=================================================================================
1069 // function : onDisplaySimulation
1070 // purpose : Show/Hide preview
1071 //=================================================================================
1072 void SMESHGUI_RotationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1073 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1074 if(myNbOkElements && isValid() && IsAxisOk()) {
1075 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1076 SMESH::long_array_var anElementsId = new SMESH::long_array;
1078 anElementsId->length(aListElementsId.count());
1079 for (int i = 0; i < aListElementsId.count(); i++)
1080 anElementsId[i] = aListElementsId[i].toInt();
1082 SMESH::AxisStruct anAxis;
1084 anAxis.x = SpinBox_X->GetValue();
1085 anAxis.y = SpinBox_Y->GetValue();
1086 anAxis.z = SpinBox_Z->GetValue();;
1087 anAxis.vx = SpinBox_DX->GetValue();
1088 anAxis.vy = SpinBox_DY->GetValue();
1089 anAxis.vz = SpinBox_DZ->GetValue();
1090 double anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
1093 SUIT_OverrideCursor aWaitCursor;
1094 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1095 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1096 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1097 if(CheckBoxMesh->isChecked())
1098 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, copy);
1100 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, copy);
1102 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1103 mySimulation->SetData(aMeshPreviewStruct._retn());