1 // Copyright (C) 2007-2013 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 (SMESH::MESHorSUBMESH);
285 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::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(reject()));
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(reject()));
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();
437 myMesh->SetParameters(aParameters.join(":").toLatin1().constData());
439 switch ( actionButton ) {
440 case MOVE_ELEMS_BUTTON:
441 if(CheckBoxMesh->isChecked())
442 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, false);
444 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
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);
461 case MAKE_MESH_BUTTON: {
462 SMESH::SMESH_Mesh_var mesh;
463 if (CheckBoxMesh->isChecked())
464 mesh = aMeshEditor->RotateObjectMakeMesh(mySelectedObject, anAxis, anAngle, makeGroups,
465 LineEditNewMesh->text().toLatin1().data());
467 mesh = aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
468 LineEditNewMesh->text().toLatin1().data());
469 if (!mesh->_is_nil()) {
470 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
471 anEntryList.append( aSObject->GetID().c_str() );
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
489 if( LightApp_Application* anApp =
490 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
491 anApp->browseObjects( anEntryList, isApplyAndClose() );
494 mySelectedObject = SMESH::SMESH_IDSource::_nil();
495 SelectionIntoArgument();
497 SMESHGUI::Modified();
503 //=================================================================================
504 // function : ClickOnOk()
506 //=================================================================================
507 void SMESHGUI_RotationDlg::ClickOnOk()
509 setIsApplyAndClose( true );
514 //=================================================================================
515 // function : reject()
517 //=================================================================================
518 void SMESHGUI_RotationDlg::reject()
520 disconnect(mySelectionMgr, 0, this, 0);
521 mySelectionMgr->clearFilters();
522 //mySelectionMgr->clearSelected();
523 if (SMESH::GetCurrentVtkView()) {
524 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
525 SMESH::SetPointRepresentation(false);
527 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
528 aViewWindow->SetSelectionMode(ActorSelection);
529 mySMESHGUI->ResetState();
533 //=================================================================================
534 // function : ClickOnHelp()
536 //=================================================================================
537 void SMESHGUI_RotationDlg::ClickOnHelp()
539 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
541 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
545 platform = "winapplication";
547 platform = "application";
549 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
550 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
551 arg(app->resourceMgr()->stringValue("ExternalBrowser",
553 arg(myHelpFileName));
557 //=======================================================================
558 // function : onTextChange()
560 //=======================================================================
561 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
563 QLineEdit* send = (QLineEdit*)sender();
568 if (send == LineEditElements)
571 buttonOk->setEnabled(false);
572 buttonApply->setEnabled(false);
574 // hilight entered elements
575 SMDS_Mesh* aMesh = 0;
577 aMesh = myActor->GetObject()->GetMesh();
580 if (send == LineEditElements) {
581 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
583 TColStd_MapOfInteger newIndices;
585 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
586 for (int i = 0; i < aListId.count(); i++) {
587 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
589 newIndices.Add(e->GetID());
593 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
594 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
595 aViewWindow->highlight( anIO, true, true );
597 myElementsId = theNewText;
601 if (myNbOkElements && IsAxisOk()) {
602 buttonOk->setEnabled(true);
603 buttonApply->setEnabled(true);
609 //=================================================================================
610 // function : SelectionIntoArgument()
611 // purpose : Called when selection as changed or other case
612 //=================================================================================
613 void SMESHGUI_RotationDlg::SelectionIntoArgument()
619 QString aString = "";
622 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
623 LineEditElements->setText(aString);
625 buttonOk->setEnabled(false);
626 buttonApply->setEnabled(false);
630 if (!GroupButtons->isEnabled()) // inactive
635 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
637 int nbSel = aList.Extent();
641 Handle(SALOME_InteractiveObject) IO = aList.First();
642 myMesh = SMESH::GetMeshByIO(IO);
643 if (myMesh->_is_nil())
646 myActor = SMESH::FindActorByObject(myMesh);
648 myActor = SMESH::FindActorByEntry(IO->getEntry());
649 if (!myActor && !CheckBoxMesh->isChecked())
654 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
657 // MakeGroups is available if there are groups and "Copy"
658 if ( myMesh->NbGroups() == 0 ) {
659 MakeGroupsCheck->setChecked(false);
660 MakeGroupsCheck->setEnabled(false);
662 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
663 MakeGroupsCheck->setEnabled(true);
665 if (CheckBoxMesh->isChecked()) {
666 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
668 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
669 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
675 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
679 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
680 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
682 myElementsId += QString(" %1").arg(i);
686 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
688 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
690 // get IDs from submesh
691 SMESH::long_array_var anElementsIds = new SMESH::long_array;
692 anElementsIds = aSubMesh->GetElementsId();
693 for (int i = 0; i < anElementsIds->length(); i++) {
694 myElementsId += QString(" %1").arg(anElementsIds[i]);
696 aNbUnits = anElementsIds->length();
699 SMESH::SMESH_GroupBase_var aGroup =
700 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
701 if (aGroup->_is_nil())
704 // get IDs from smesh group
705 SMESH::long_array_var anElementsIds = new SMESH::long_array;
706 anElementsIds = aGroup->GetListOfID();
707 for (int i = 0; i < anElementsIds->length(); i++) {
708 myElementsId += QString(" %1").arg(anElementsIds[i]);
710 aNbUnits = anElementsIds->length();
714 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
715 myElementsId = aString;
720 myNbOkElements = true;
723 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
727 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
731 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
739 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
740 SpinBox_X->SetValue(x);
741 SpinBox_Y->SetValue(y);
742 SpinBox_Z->SetValue(z);
743 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
744 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
745 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
746 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
751 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
752 LineEditElements->setText(aString);
753 LineEditElements->repaint();
754 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
755 LineEditElements->setEnabled(true);
761 if (myNbOkElements && IsAxisOk()) {
762 buttonOk->setEnabled(true);
763 buttonApply->setEnabled(true);
765 onDisplaySimulation(true);
768 //=================================================================================
769 // function : SetEditCurrentArgument()
771 //=================================================================================
772 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
774 QPushButton* send = (QPushButton*)sender();
776 disconnect(mySelectionMgr, 0, this, 0);
777 mySelectionMgr->clearSelected();
778 mySelectionMgr->clearFilters();
780 switch (myConstructorId) {
781 case 0: /* default constructor */
783 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
784 if (send == SelectElementsButton) {
785 myEditCurrentArgument = (QWidget*)LineEditElements;
786 SMESH::SetPointRepresentation(false);
787 if (CheckBoxMesh->isChecked()) {
789 aViewWindow->SetSelectionMode(ActorSelection);
790 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
793 aViewWindow->SetSelectionMode( CellSelection );
795 } else if (send == SelectPointButton) {
796 myEditCurrentArgument = (QWidget*)SpinBox_X;
797 SMESH::SetPointRepresentation(true);
799 aViewWindow->SetSelectionMode( NodeSelection );
800 } else if (send == SelectVectorButton) {
801 myEditCurrentArgument = (QWidget*)SpinBox_DX;
802 SMESH::SetPointRepresentation(true);
804 aViewWindow->SetSelectionMode( NodeSelection );
811 myEditCurrentArgument->setFocus();
812 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
813 SelectionIntoArgument();
816 //=================================================================================
817 // function : DeactivateActiveDialog()
819 //=================================================================================
820 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
822 if (GroupConstructors->isEnabled()) {
823 GroupConstructors->setEnabled(false);
824 GroupArguments->setEnabled(false);
825 GroupButtons->setEnabled(false);
826 mySMESHGUI->ResetState();
827 mySMESHGUI->SetActiveDialogBox(0);
831 //=================================================================================
832 // function : ActivateThisDialog()
834 //=================================================================================
835 void SMESHGUI_RotationDlg::ActivateThisDialog()
837 /* Emit a signal to deactivate the active dialog */
838 mySMESHGUI->EmitSignalDeactivateDialog();
839 GroupConstructors->setEnabled(true);
840 GroupArguments->setEnabled(true);
841 GroupButtons->setEnabled(true);
843 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
845 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
846 aViewWindow->SetSelectionMode( CellSelection );
847 SelectionIntoArgument();
850 //=================================================================================
851 // function : enterEvent()
853 //=================================================================================
854 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
856 if (!GroupConstructors->isEnabled())
857 ActivateThisDialog();
860 //=================================================================================
861 // function : onSelectMesh()
863 //=================================================================================
864 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
867 TextLabelElements->setText(tr("SMESH_NAME"));
869 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
870 myFilterBtn->setEnabled(!toSelectMesh);
872 if (myEditCurrentArgument != LineEditElements) {
873 LineEditElements->clear();
877 mySelectionMgr->clearFilters();
878 SMESH::SetPointRepresentation(false);
881 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
882 aViewWindow->SetSelectionMode(ActorSelection);
883 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
884 LineEditElements->setReadOnly(true);
885 LineEditElements->setValidator(0);
887 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
888 aViewWindow->SetSelectionMode( CellSelection );
889 LineEditElements->setReadOnly(false);
890 LineEditElements->setValidator(myIdValidator);
891 onTextChange(LineEditElements->text());
895 SelectionIntoArgument();
898 //=================================================================================
899 // function : IsAxisOk()
901 //=================================================================================
902 bool SMESHGUI_RotationDlg::IsAxisOk()
904 return (SpinBox_DX->GetValue() != 0 ||
905 SpinBox_DY->GetValue() != 0 ||
906 SpinBox_DZ->GetValue() != 0);
909 //=================================================================================
910 // function : onVectorChanged()
912 //=================================================================================
913 void SMESHGUI_RotationDlg::onVectorChanged()
916 buttonOk->setEnabled(true);
917 buttonApply->setEnabled(true);
919 buttonOk->setEnabled(false);
920 buttonApply->setEnabled(false);
925 //=======================================================================
926 //function : onActionClicked
927 //purpose : slot called when an action type changed
928 //=======================================================================
930 void SMESHGUI_RotationDlg::onActionClicked(int button)
933 case MOVE_ELEMS_BUTTON:
934 MakeGroupsCheck->setEnabled(false);
935 LineEditNewMesh->setEnabled(false);
937 case COPY_ELEMS_BUTTON:
938 LineEditNewMesh->setEnabled(false);
939 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
940 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
941 MakeGroupsCheck->setEnabled(true);
943 MakeGroupsCheck->setEnabled(false);
945 case MAKE_MESH_BUTTON:
946 LineEditNewMesh->setEnabled(true);
947 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
948 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
949 MakeGroupsCheck->setEnabled(true);
951 MakeGroupsCheck->setEnabled(false);
955 toDisplaySimulation();
958 //=======================================================================
959 //function : setNewMeshName
960 //purpose : update contents of LineEditNewMesh
961 //=======================================================================
963 void SMESHGUI_RotationDlg::setNewMeshName()
965 LineEditNewMesh->setText("");
966 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
968 if ( CheckBoxMesh->isChecked() ) {
969 name = LineEditElements->text();
972 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
973 name = meshSO->GetName().c_str();
975 if ( !name.isEmpty() )
976 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
980 //=================================================================================
981 // function : keyPressEvent()
983 //=================================================================================
984 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
986 QDialog::keyPressEvent( e );
987 if ( e->isAccepted() )
990 if ( e->key() == Qt::Key_F1 ) {
996 //=================================================================================
997 // function : setFilters()
998 // purpose : SLOT. Called when "Filter" button pressed.
999 //=================================================================================
1000 void SMESHGUI_RotationDlg::setFilters()
1002 if(myMesh->_is_nil()) {
1003 SUIT_MessageBox::critical(this,
1005 tr("NO_MESH_SELECTED"));
1009 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1011 myFilterDlg->SetSelection();
1012 myFilterDlg->SetMesh( myMesh );
1013 myFilterDlg->SetSourceWg( LineEditElements );
1015 myFilterDlg->show();
1018 //=================================================================================
1019 // function : isValid
1021 //=================================================================================
1022 bool SMESHGUI_RotationDlg::isValid()
1027 ok = SpinBox_X->isValid( msg, true ) && ok;
1028 ok = SpinBox_Y->isValid( msg, true ) && ok;
1029 ok = SpinBox_Z->isValid( msg, true ) && ok;
1030 ok = SpinBox_DX->isValid( msg, true ) && ok;
1031 ok = SpinBox_DY->isValid( msg, true ) && ok;
1032 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1033 ok = SpinBox_Angle->isValid( msg, true ) && ok;
1036 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1037 if ( !msg.isEmpty() )
1039 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1046 //=================================================================================
1047 // function : onDisplaySimulation
1048 // purpose : Show/Hide preview
1049 //=================================================================================
1050 void SMESHGUI_RotationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1051 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1052 if(myNbOkElements && isValid() && IsAxisOk()) {
1053 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1054 SMESH::long_array_var anElementsId = new SMESH::long_array;
1056 anElementsId->length(aListElementsId.count());
1057 for (int i = 0; i < aListElementsId.count(); i++)
1058 anElementsId[i] = aListElementsId[i].toInt();
1060 SMESH::AxisStruct anAxis;
1062 anAxis.x = SpinBox_X->GetValue();
1063 anAxis.y = SpinBox_Y->GetValue();
1064 anAxis.z = SpinBox_Z->GetValue();;
1065 anAxis.vx = SpinBox_DX->GetValue();
1066 anAxis.vy = SpinBox_DY->GetValue();
1067 anAxis.vz = SpinBox_DZ->GetValue();
1068 double anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
1071 SUIT_OverrideCursor aWaitCursor;
1072 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1073 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1074 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1075 if(CheckBoxMesh->isChecked())
1076 aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, copy);
1078 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, copy);
1080 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1081 mySimulation->SetData(aMeshPreviewStruct._retn());