1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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"
36 #include <SMESH_Actor.h>
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_LogicalFilter.hxx>
39 #include <SMDS_Mesh.hxx>
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_OverrideCursor.h>
48 #include <LightApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
51 #include <SVTK_ViewModel.h>
52 #include <SVTK_ViewWindow.h>
53 #include <SALOME_ListIO.hxx>
55 // SALOME KERNEL includes
56 #include <SALOMEDSClient.hxx>
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
87 //=================================================================================
88 // class : SMESHGUI_RotationDlg()
90 //=================================================================================
91 SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule ) :
92 SMESHGUI_MultiPreviewDlg( theModule ),
93 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
96 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_ROTATION")));
97 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
100 setAttribute(Qt::WA_DeleteOnClose, true);
101 setWindowTitle(tr("SMESH_ROTATION_TITLE"));
102 setSizeGripEnabled(true);
104 QVBoxLayout* SMESHGUI_RotationDlgLayout = new QVBoxLayout(this);
105 SMESHGUI_RotationDlgLayout->setSpacing(SPACING);
106 SMESHGUI_RotationDlgLayout->setMargin(MARGIN);
108 /***************************************************************/
109 GroupConstructors = new QGroupBox(tr("SMESH_ROTATION"), this);
110 QButtonGroup* ButtonGroup = new QButtonGroup(this);
111 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
112 GroupConstructorsLayout->setSpacing(SPACING);
113 GroupConstructorsLayout->setMargin(MARGIN);
115 RadioButton1= new QRadioButton(GroupConstructors);
116 RadioButton1->setIcon(image0);
118 GroupConstructorsLayout->addWidget(RadioButton1);
119 ButtonGroup->addButton(RadioButton1, 0);
121 /***************************************************************/
122 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
123 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
124 GroupArgumentsLayout->setSpacing(SPACING);
125 GroupArgumentsLayout->setMargin(MARGIN);
127 myIdValidator = new SMESHGUI_IdValidator(this);
129 // Controls for elements selection
130 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
131 SelectElementsButton = new QPushButton(GroupArguments);
132 SelectElementsButton->setIcon(image1);
133 LineEditElements = new QLineEdit(GroupArguments);
134 LineEditElements->setValidator(myIdValidator);
135 LineEditElements->setMaxLength(-1);
136 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
137 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
139 // Control for the whole mesh selection
140 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
142 // Controls for axis defining
143 GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
144 QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
145 GroupAxisLayout->setSpacing(SPACING);
146 GroupAxisLayout->setMargin(MARGIN);
148 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
149 SelectPointButton = new QPushButton(GroupAxis);
150 SelectPointButton->setIcon(image1);
152 TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
153 SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
154 TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
155 SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
156 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
157 SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
159 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
160 SelectVectorButton = new QPushButton(GroupAxis);
161 SelectVectorButton->setIcon(image1);
163 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
164 SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
165 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
166 SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
167 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
168 SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
170 GroupAxisLayout->addWidget(TextLabelPoint, 0, 0);
171 GroupAxisLayout->addWidget(SelectPointButton, 0, 1);
172 GroupAxisLayout->addWidget(TextLabelX, 0, 2);
173 GroupAxisLayout->addWidget(SpinBox_X, 0, 3);
174 GroupAxisLayout->addWidget(TextLabelY, 0, 4);
175 GroupAxisLayout->addWidget(SpinBox_Y, 0, 5);
176 GroupAxisLayout->addWidget(TextLabelZ, 0, 6);
177 GroupAxisLayout->addWidget(SpinBox_Z, 0, 7);
178 GroupAxisLayout->addWidget(TextLabelVector, 1, 0);
179 GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
180 GroupAxisLayout->addWidget(TextLabelDX, 1, 2);
181 GroupAxisLayout->addWidget(SpinBox_DX, 1, 3);
182 GroupAxisLayout->addWidget(TextLabelDY, 1, 4);
183 GroupAxisLayout->addWidget(SpinBox_DY, 1, 5);
184 GroupAxisLayout->addWidget(TextLabelDZ, 1, 6);
185 GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7);
187 // Controls for angle defining
188 TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupArguments);
189 SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments);
192 ActionBox = new QGroupBox(GroupArguments);
193 ActionGroup = new QButtonGroup(GroupArguments);
194 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
195 ActionBoxLayout->setSpacing(SPACING);
196 ActionBoxLayout->setMargin(MARGIN);
198 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
199 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
200 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
202 ActionBoxLayout->addWidget(aMoveElements);
203 ActionBoxLayout->addWidget(aCopyElements);
204 ActionBoxLayout->addWidget(aCreateMesh);
205 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
206 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
207 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
209 // CheckBox for groups generation
210 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
212 // Name of a mesh to create
213 LineEditNewMesh = new QLineEdit(GroupArguments);
217 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
219 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
220 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
221 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
222 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
223 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
224 GroupArgumentsLayout->addWidget(GroupAxis, 2, 0, 1, 4);
225 GroupArgumentsLayout->addWidget(TextLabelAngle, 3, 0, 1, 2);
226 GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
227 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 3);
228 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 3);
229 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 3);
230 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 7, 0);
233 /***************************************************************/
234 GroupButtons = new QGroupBox(this);
235 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
236 GroupButtonsLayout->setSpacing(SPACING);
237 GroupButtonsLayout->setMargin(MARGIN);
239 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
240 buttonOk->setAutoDefault(true);
241 buttonOk->setDefault(true);
242 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
243 buttonApply->setAutoDefault(true);
244 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
245 buttonCancel->setAutoDefault(true);
246 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
247 buttonHelp->setAutoDefault(true);
249 GroupButtonsLayout->addWidget(buttonOk);
250 GroupButtonsLayout->addSpacing(10);
251 GroupButtonsLayout->addWidget(buttonApply);
252 GroupButtonsLayout->addSpacing(10);
253 GroupButtonsLayout->addStretch();
254 GroupButtonsLayout->addWidget(buttonCancel);
255 GroupButtonsLayout->addWidget(buttonHelp);
257 /***************************************************************/
258 SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors);
259 SMESHGUI_RotationDlgLayout->addWidget(GroupArguments);
260 SMESHGUI_RotationDlgLayout->addWidget(GroupButtons);
262 /* Initialisations */
263 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
264 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
265 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
266 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
267 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
268 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
270 SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, "angle_precision");
273 RadioButton1->setChecked(true);
275 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
277 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
279 // Costruction of the logical filter
280 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
281 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::GROUP);
283 QList<SUIT_SelectionFilter*> aListOfFilters;
284 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
285 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
287 myMeshOrSubMeshOrGroupFilter =
288 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
290 myHelpFileName = "rotation_page.html";
294 /* signals and slots connections */
295 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
296 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
297 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
298 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
300 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
301 connect(SelectPointButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
302 connect(SelectVectorButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
304 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
305 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
306 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
308 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
309 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
310 /* to close dialog if study change */
311 connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView()));
312 connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView()));
313 connect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView()));
314 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
315 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
316 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
318 connect(SpinBox_X, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
319 connect(SpinBox_Y, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
320 connect(SpinBox_Z, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
321 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
322 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
323 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
324 connect(SpinBox_Angle, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326 //To Connect preview check box
327 connectPreviewControl();
329 onActionClicked(MOVE_ELEMS_BUTTON);
332 //=================================================================================
333 // function : ~SMESHGUI_RotationDlg()
334 // purpose : Destroys the object and frees any allocated resources
335 //=================================================================================
336 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
339 myFilterDlg->setParent( 0 );
345 //=================================================================================
348 //=================================================================================
349 void SMESHGUI_RotationDlg::Init (bool ResetControls)
354 myObjectsNames.clear();
356 myEditCurrentArgument = (QWidget*)LineEditElements;
357 LineEditElements->setFocus();
361 buttonOk->setEnabled(false);
362 buttonApply->setEnabled(false);
364 if ( !ResetControls && !isApplyAndClose() && // make highlight move upon [Apply] (IPAL20729)
365 myActor && !myActor->getIO().IsNull() &&
366 ActionGroup->button( MOVE_ELEMS_BUTTON )->isChecked() &&
367 !CheckBoxMesh->isChecked() ) // move selected elements
369 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
371 aViewWindow->highlight( myActor->getIO(), false, false );
372 aViewWindow->highlight( myActor->getIO(), true, true );
379 SpinBox_X->SetValue(0.0);
380 SpinBox_Y->SetValue(0.0);
381 SpinBox_Z->SetValue(0.0);
382 SpinBox_DX->SetValue(0.0);
383 SpinBox_DY->SetValue(0.0);
384 SpinBox_DZ->SetValue(0.0);
386 SpinBox_Angle->SetValue(45);
388 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
389 CheckBoxMesh->setChecked(false);
390 myPreviewCheckBox->setChecked(false);
391 onDisplaySimulation(false);
394 onSelectMesh(CheckBoxMesh->isChecked());
397 //=================================================================================
398 // function : ClickOnApply()
400 //=================================================================================
401 bool SMESHGUI_RotationDlg::ClickOnApply()
403 if (mySMESHGUI->isActiveStudyLocked())
409 if (myNbOkElements && IsAxisOk()) {
410 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
412 SMESH::long_array_var anElementsId = new SMESH::long_array;
414 anElementsId->length(aListElementsId.count());
415 for (int i = 0; i < aListElementsId.count(); i++)
416 anElementsId[i] = aListElementsId[i].toInt();
418 SMESH::AxisStruct anAxis;
420 anAxis.x = SpinBox_X->GetValue();
421 anAxis.y = SpinBox_Y->GetValue();
422 anAxis.z = SpinBox_Z->GetValue();;
423 anAxis.vx = SpinBox_DX->GetValue();
424 anAxis.vy = SpinBox_DY->GetValue();
425 anAxis.vz = SpinBox_DZ->GetValue();
427 double anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
429 QStringList aParameters;
430 aParameters << SpinBox_X->text();
431 aParameters << SpinBox_Y->text();
432 aParameters << SpinBox_Z->text();
433 aParameters << SpinBox_DX->text();
434 aParameters << SpinBox_DY->text();
435 aParameters << SpinBox_DZ->text();
436 aParameters << SpinBox_Angle->text();
438 int actionButton = ActionGroup->checkedId();
439 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
440 QStringList anEntryList;
442 SUIT_OverrideCursor aWaitCursor;
444 switch ( actionButton ) {
445 case MOVE_ELEMS_BUTTON:
446 if(CheckBoxMesh->isChecked()) {
447 for ( int i = 0; i < myObjects.count(); i++ ) {
448 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
449 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
450 aMeshEditor->RotateObject(myObjects[i], anAxis, anAngle, false);
454 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
455 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
456 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
459 case COPY_ELEMS_BUTTON:
461 SMESH::ListOfGroups_var groups;
462 if(CheckBoxMesh->isChecked()) {
463 for ( int i = 0; i < myObjects.count(); i++ ) {
464 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
465 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
466 groups = aMeshEditor->RotateObjectMakeGroups(myObjects[i], anAxis, anAngle);
470 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
471 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
472 groups = aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
476 if(CheckBoxMesh->isChecked()) {
477 for ( int i = 0; i < myObjects.count(); i++ ) {
478 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
479 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
480 aMeshEditor->RotateObject(myObjects[i], anAxis, anAngle, true);
484 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
485 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
486 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
490 case MAKE_MESH_BUTTON: {
491 SMESH::SMESH_Mesh_var mesh;
492 if (CheckBoxMesh->isChecked()) {
493 for ( int i = 0; i < myObjects.count(); i++ ) {
494 QString aName = SMESH::UniqueMeshName( LineEditNewMesh->text().replace( "*", myObjectsNames[i] ) );
495 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
496 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
497 mesh = aMeshEditor->RotateObjectMakeMesh(myObjects[i], anAxis, anAngle, makeGroups,
498 aName.toLatin1().data());
499 if (!mesh->_is_nil()) {
500 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
501 anEntryList.append( aSObject->GetID().c_str() );
506 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
507 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
508 mesh = aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
509 LineEditNewMesh->text().toLatin1().data());
510 if (!mesh->_is_nil()) {
511 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
512 anEntryList.append( aSObject->GetID().c_str() );
521 for ( int i = 0; i < myObjects.count(); i++ ) {
522 SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
523 if ( actor ) SMESH::Update( actor->getIO(), true );
526 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
527 actionButton == MAKE_MESH_BUTTON ) {
528 mySMESHGUI->updateObjBrowser(true); // new groups may appear
529 if( LightApp_Application* anApp =
530 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
531 anApp->browseObjects( anEntryList, isApplyAndClose() );
535 SMESHGUI::Modified();
541 //=================================================================================
542 // function : ClickOnOk()
544 //=================================================================================
545 void SMESHGUI_RotationDlg::ClickOnOk()
547 setIsApplyAndClose( true );
552 //=================================================================================
553 // function : reject()
555 //=================================================================================
556 void SMESHGUI_RotationDlg::reject()
558 disconnect(mySelectionMgr, 0, this, 0);
559 mySelectionMgr->clearFilters();
560 //mySelectionMgr->clearSelected();
561 if (SMESH::GetCurrentVtkView()) {
562 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
563 SMESH::SetPointRepresentation(false);
565 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
566 aViewWindow->SetSelectionMode(ActorSelection);
567 mySMESHGUI->ResetState();
572 //=================================================================================
573 // function : onOpenView()
575 //=================================================================================
576 void SMESHGUI_RotationDlg::onOpenView()
579 SMESH::SetPointRepresentation(false);
582 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
583 ActivateThisDialog();
587 //=================================================================================
588 // function : onCloseView()
590 //=================================================================================
591 void SMESHGUI_RotationDlg::onCloseView()
593 DeactivateActiveDialog();
597 //=================================================================================
598 // function : ClickOnHelp()
600 //=================================================================================
601 void SMESHGUI_RotationDlg::ClickOnHelp()
603 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
605 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
609 platform = "winapplication";
611 platform = "application";
613 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
614 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
615 arg(app->resourceMgr()->stringValue("ExternalBrowser",
617 arg(myHelpFileName));
621 //=======================================================================
622 // function : onTextChange()
624 //=======================================================================
625 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
627 QLineEdit* send = (QLineEdit*)sender();
632 if (send == LineEditElements)
635 buttonOk->setEnabled(false);
636 buttonApply->setEnabled(false);
638 // hilight entered elements
639 SMDS_Mesh* aMesh = 0;
641 aMesh = myActor->GetObject()->GetMesh();
644 if (send == LineEditElements) {
645 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
647 TColStd_MapOfInteger newIndices;
649 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
650 for (int i = 0; i < aListId.count(); i++) {
651 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
653 newIndices.Add(e->GetID());
657 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
658 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
659 aViewWindow->highlight( anIO, true, true );
661 myElementsId = theNewText;
665 if (myNbOkElements && IsAxisOk()) {
666 buttonOk->setEnabled(true);
667 buttonApply->setEnabled(true);
673 //=================================================================================
674 // function : SelectionIntoArgument()
675 // purpose : Called when selection as changed or other case
676 //=================================================================================
677 void SMESHGUI_RotationDlg::SelectionIntoArgument()
680 if (myFilterDlg && myFilterDlg->isVisible()) return; // filter dlg active
684 QString aString = "";
685 onDisplaySimulation(false);
688 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
689 LineEditElements->setText(aString);
691 buttonOk->setEnabled(false);
692 buttonApply->setEnabled(false);
696 if (!GroupButtons->isEnabled()) // inactive
701 mySelectionMgr->selectedObjects(aList);
703 int nbSel = aList.Extent();
709 if (myEditCurrentArgument == (QWidget*)LineEditElements)
713 myObjectsNames.clear();
716 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() )
718 Handle(SALOME_InteractiveObject) IO = it.Value();
719 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
720 if ( aMesh->_is_nil() )
723 myActor = SMESH::FindActorByObject( aMesh );
725 myActor = SMESH::FindActorByEntry( IO->getEntry() );
726 // if ( !myActor && !CheckBoxMesh->isChecked() ) -- elems can be selected by Filter
729 SMESH::SMESH_IDSource_var idSrc = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
730 if ( _PTR(SObject) obj = SMESH::FindSObject( idSrc ))
732 std::string name = obj->GetName();
736 myObjectsNames << name.c_str();
742 // MakeGroups is available if there are groups and "Copy"
744 for ( int i = 0; i < myMeshes.count(); i++ )
745 aNbGroups += myMeshes[i]->NbGroups();
746 if ( aNbGroups == 0 ) {
747 MakeGroupsCheck->setChecked(false);
748 MakeGroupsCheck->setEnabled(false);
750 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
751 MakeGroupsCheck->setEnabled(true);
754 if (CheckBoxMesh->isChecked()) {
755 if ( myMeshes.isEmpty() )
757 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
760 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
761 myElementsId = aString;
766 myNbOkElements = true;
769 else // set coordinates by picked nodes
771 Handle(SALOME_InteractiveObject) IO = aList.First();
773 SMESH_Actor* anActor = SMESH::FindActorByEntry( IO->getEntry() );
777 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
781 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
785 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
793 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
794 SpinBox_X->SetValue(x);
795 SpinBox_Y->SetValue(y);
796 SpinBox_Z->SetValue(z);
797 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
798 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
799 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
800 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
805 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
806 LineEditElements->setText(aString);
807 LineEditElements->repaint();
808 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
809 LineEditElements->setEnabled(true);
815 if (myNbOkElements && IsAxisOk()) {
816 buttonOk->setEnabled(true);
817 buttonApply->setEnabled(true);
819 onDisplaySimulation(true);
822 //=================================================================================
823 // function : SetEditCurrentArgument()
825 //=================================================================================
826 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
828 QPushButton* send = (QPushButton*)sender();
830 disconnect(mySelectionMgr, 0, this, 0);
831 mySelectionMgr->clearSelected();
832 mySelectionMgr->clearFilters();
834 switch (myConstructorId) {
835 case 0: /* default constructor */
837 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
838 if (send == SelectElementsButton) {
839 myEditCurrentArgument = (QWidget*)LineEditElements;
840 SMESH::SetPointRepresentation(false);
841 if (CheckBoxMesh->isChecked()) {
843 aViewWindow->SetSelectionMode(ActorSelection);
844 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
847 aViewWindow->SetSelectionMode( CellSelection );
849 } else if (send == SelectPointButton) {
850 myEditCurrentArgument = (QWidget*)SpinBox_X;
851 SMESH::SetPointRepresentation(true);
853 aViewWindow->SetSelectionMode( NodeSelection );
854 } else if (send == SelectVectorButton) {
855 myEditCurrentArgument = (QWidget*)SpinBox_DX;
856 SMESH::SetPointRepresentation(true);
858 aViewWindow->SetSelectionMode( NodeSelection );
865 myEditCurrentArgument->setFocus();
866 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
867 SelectionIntoArgument();
870 //=================================================================================
871 // function : DeactivateActiveDialog()
873 //=================================================================================
874 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
876 if (GroupConstructors->isEnabled()) {
877 GroupConstructors->setEnabled(false);
878 GroupArguments->setEnabled(false);
879 GroupButtons->setEnabled(false);
880 mySMESHGUI->ResetState();
881 mySMESHGUI->SetActiveDialogBox(0);
885 //=================================================================================
886 // function : ActivateThisDialog()
888 //=================================================================================
889 void SMESHGUI_RotationDlg::ActivateThisDialog()
891 /* Emit a signal to deactivate the active dialog */
892 mySMESHGUI->EmitSignalDeactivateDialog();
893 GroupConstructors->setEnabled(true);
894 GroupArguments->setEnabled(true);
895 GroupButtons->setEnabled(true);
897 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
899 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
900 aViewWindow->SetSelectionMode( CellSelection );
901 SelectionIntoArgument();
904 //=================================================================================
905 // function : enterEvent()
907 //=================================================================================
908 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
910 if (!GroupConstructors->isEnabled()) {
911 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
912 if ( aViewWindow && !mySelector) {
913 mySelector = aViewWindow->GetSelector();
915 ActivateThisDialog();
919 //=================================================================================
920 // function : onSelectMesh()
922 //=================================================================================
923 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
926 TextLabelElements->setText(tr("SMESH_NAME"));
928 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
929 myFilterBtn->setEnabled(!toSelectMesh);
931 if (myEditCurrentArgument != LineEditElements) {
932 LineEditElements->clear();
936 mySelectionMgr->clearFilters();
937 SMESH::SetPointRepresentation(false);
940 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
941 aViewWindow->SetSelectionMode(ActorSelection);
942 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
943 LineEditElements->setReadOnly(true);
944 LineEditElements->setValidator(0);
946 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
947 aViewWindow->SetSelectionMode( CellSelection );
948 LineEditElements->setReadOnly(false);
949 LineEditElements->setValidator(myIdValidator);
953 SelectionIntoArgument();
956 //=================================================================================
957 // function : IsAxisOk()
959 //=================================================================================
960 bool SMESHGUI_RotationDlg::IsAxisOk()
962 return (SpinBox_DX->GetValue() != 0 ||
963 SpinBox_DY->GetValue() != 0 ||
964 SpinBox_DZ->GetValue() != 0);
967 //=================================================================================
968 // function : onVectorChanged()
970 //=================================================================================
971 void SMESHGUI_RotationDlg::onVectorChanged()
974 buttonOk->setEnabled(true);
975 buttonApply->setEnabled(true);
977 buttonOk->setEnabled(false);
978 buttonApply->setEnabled(false);
983 //=======================================================================
984 //function : onActionClicked
985 //purpose : slot called when an action type changed
986 //=======================================================================
988 void SMESHGUI_RotationDlg::onActionClicked(int button)
991 for ( int i = 0; i < myMeshes.count(); i++ )
992 aNbGroups += myMeshes[i]->NbGroups();
995 case MOVE_ELEMS_BUTTON:
996 MakeGroupsCheck->setEnabled(false);
997 LineEditNewMesh->setEnabled(false);
999 case COPY_ELEMS_BUTTON:
1000 LineEditNewMesh->setEnabled(false);
1001 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1002 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1004 case MAKE_MESH_BUTTON:
1005 LineEditNewMesh->setEnabled(true);
1006 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1007 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1011 toDisplaySimulation();
1014 //=======================================================================
1015 //function : setNewMeshName
1016 //purpose : update contents of LineEditNewMesh
1017 //=======================================================================
1019 void SMESHGUI_RotationDlg::setNewMeshName()
1021 LineEditNewMesh->setText("");
1022 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1024 if ( CheckBoxMesh->isChecked() ) {
1025 name = myMeshes.count() > 1 ? "*" : LineEditElements->text();
1028 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1029 name = meshSO->GetName().c_str();
1031 if ( !name.isEmpty() )
1032 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
1036 //=================================================================================
1037 // function : keyPressEvent()
1039 //=================================================================================
1040 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
1042 QDialog::keyPressEvent( e );
1043 if ( e->isAccepted() )
1046 if ( e->key() == Qt::Key_F1 ) {
1052 //=================================================================================
1053 // function : setFilters()
1054 // purpose : SLOT. Called when "Filter" button pressed.
1055 //=================================================================================
1056 void SMESHGUI_RotationDlg::setFilters()
1058 if ( myMeshes.isEmpty() ) {
1059 SUIT_MessageBox::critical(this,
1061 tr("NO_MESH_SELECTED"));
1064 if ( !myFilterDlg ) {
1065 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1066 connect(myFilterDlg, SIGNAL(Accepted()), SLOT(onFilterAccepted()));
1070 if ( myMeshes[0]->NbEdges() ) types << SMESH::EDGE;
1071 if ( myMeshes[0]->NbFaces() ) types << SMESH::FACE;
1072 if ( myMeshes[0]->NbVolumes() ) types << SMESH::VOLUME;
1073 if ( myMeshes[0]->NbBalls() ) types << SMESH::BALL;
1074 if ( myMeshes[0]->Nb0DElements()) types << SMESH::ELEM0D;
1075 if ( types.count() > 1 ) types << SMESH::ALL;
1077 myFilterDlg->Init( types );
1078 myFilterDlg->SetSelection();
1079 myFilterDlg->SetMesh( myMeshes[0] );
1080 myFilterDlg->SetSourceWg( LineEditElements );
1082 myFilterDlg->show();
1085 //=======================================================================
1086 // name : onFilterAccepted()
1087 // Purpose : SLOT. Called when Filter dlg closed with OK button.
1088 // Activate [Apply] if no Actor is available
1089 //=======================================================================
1090 void SMESHGUI_RotationDlg::onFilterAccepted()
1092 if ( myMeshes.length() > 0 && !buttonOk->isEnabled() )
1094 myElementsId = LineEditElements->text();
1095 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1096 myNbOkElements = aListElementsId.count();
1097 buttonOk->setEnabled( myNbOkElements );
1098 buttonApply->setEnabled( myNbOkElements );
1102 //=================================================================================
1103 // function : isValid
1105 //=================================================================================
1106 bool SMESHGUI_RotationDlg::isValid()
1111 ok = SpinBox_X->isValid( msg, true ) && ok;
1112 ok = SpinBox_Y->isValid( msg, true ) && ok;
1113 ok = SpinBox_Z->isValid( msg, true ) && ok;
1114 ok = SpinBox_DX->isValid( msg, true ) && ok;
1115 ok = SpinBox_DY->isValid( msg, true ) && ok;
1116 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1117 ok = SpinBox_Angle->isValid( msg, true ) && ok;
1120 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1121 if ( !msg.isEmpty() )
1123 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1130 //=================================================================================
1131 // function : onDisplaySimulation
1132 // purpose : Show/Hide preview
1133 //=================================================================================
1134 void SMESHGUI_RotationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1135 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1136 if(myNbOkElements && isValid() && IsAxisOk()) {
1137 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1138 SMESH::long_array_var anElementsId = new SMESH::long_array;
1140 anElementsId->length(aListElementsId.count());
1141 for (int i = 0; i < aListElementsId.count(); i++)
1142 anElementsId[i] = aListElementsId[i].toInt();
1144 SMESH::AxisStruct anAxis;
1146 anAxis.x = SpinBox_X->GetValue();
1147 anAxis.y = SpinBox_Y->GetValue();
1148 anAxis.z = SpinBox_Z->GetValue();;
1149 anAxis.vx = SpinBox_DX->GetValue();
1150 anAxis.vy = SpinBox_DY->GetValue();
1151 anAxis.vz = SpinBox_DZ->GetValue();
1152 double anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
1155 SUIT_OverrideCursor aWaitCursor;
1156 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1157 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1158 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1159 if(CheckBoxMesh->isChecked())
1160 for ( int i = 0; i < myObjects.count(); i++ ) {
1161 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1162 aMeshEditor->RotateObject(myObjects[i], anAxis, anAngle, copy);
1163 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1166 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1167 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, copy);
1168 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1170 setSimulationPreview( aMeshPreviewStruct );