1 // Copyright (C) 2007-2015 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"
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.hxx>
58 #include <SALOMEDSClient_SObject.hxx>
61 #include <TColStd_MapOfInteger.hxx>
64 #include <QApplication>
65 #include <QButtonGroup>
69 #include <QPushButton>
70 #include <QRadioButton>
72 #include <QHBoxLayout>
73 #include <QVBoxLayout>
74 #include <QGridLayout>
78 #include <SALOMEconfig.h>
79 #include CORBA_SERVER_HEADER(SMESH_Group)
80 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
82 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
88 //=================================================================================
89 // class : SMESHGUI_RotationDlg()
91 //=================================================================================
92 SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule ) :
93 SMESHGUI_MultiPreviewDlg( theModule ),
94 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
97 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_ROTATION")));
98 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
101 setAttribute(Qt::WA_DeleteOnClose, true);
102 setWindowTitle(tr("SMESH_ROTATION_TITLE"));
103 setSizeGripEnabled(true);
105 QVBoxLayout* SMESHGUI_RotationDlgLayout = new QVBoxLayout(this);
106 SMESHGUI_RotationDlgLayout->setSpacing(SPACING);
107 SMESHGUI_RotationDlgLayout->setMargin(MARGIN);
109 /***************************************************************/
110 GroupConstructors = new QGroupBox(tr("SMESH_ROTATION"), this);
111 QButtonGroup* ButtonGroup = new QButtonGroup(this);
112 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
113 GroupConstructorsLayout->setSpacing(SPACING);
114 GroupConstructorsLayout->setMargin(MARGIN);
116 RadioButton1= new QRadioButton(GroupConstructors);
117 RadioButton1->setIcon(image0);
119 GroupConstructorsLayout->addWidget(RadioButton1);
120 ButtonGroup->addButton(RadioButton1, 0);
122 /***************************************************************/
123 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
124 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
125 GroupArgumentsLayout->setSpacing(SPACING);
126 GroupArgumentsLayout->setMargin(MARGIN);
128 myIdValidator = new SMESHGUI_IdValidator(this);
130 // Controls for elements selection
131 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
132 SelectElementsButton = new QPushButton(GroupArguments);
133 SelectElementsButton->setIcon(image1);
134 LineEditElements = new QLineEdit(GroupArguments);
135 LineEditElements->setValidator(myIdValidator);
136 LineEditElements->setMaxLength(-1);
137 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
138 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
140 // Control for the whole mesh selection
141 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
143 // Controls for axis defining
144 GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
145 QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
146 GroupAxisLayout->setSpacing(SPACING);
147 GroupAxisLayout->setMargin(MARGIN);
149 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
150 SelectPointButton = new QPushButton(GroupAxis);
151 SelectPointButton->setIcon(image1);
153 TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
154 SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
155 TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
156 SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
157 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
158 SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
160 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
161 SelectVectorButton = new QPushButton(GroupAxis);
162 SelectVectorButton->setIcon(image1);
164 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
165 SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
166 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
167 SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
168 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
169 SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
171 GroupAxisLayout->addWidget(TextLabelPoint, 0, 0);
172 GroupAxisLayout->addWidget(SelectPointButton, 0, 1);
173 GroupAxisLayout->addWidget(TextLabelX, 0, 2);
174 GroupAxisLayout->addWidget(SpinBox_X, 0, 3);
175 GroupAxisLayout->addWidget(TextLabelY, 0, 4);
176 GroupAxisLayout->addWidget(SpinBox_Y, 0, 5);
177 GroupAxisLayout->addWidget(TextLabelZ, 0, 6);
178 GroupAxisLayout->addWidget(SpinBox_Z, 0, 7);
179 GroupAxisLayout->addWidget(TextLabelVector, 1, 0);
180 GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
181 GroupAxisLayout->addWidget(TextLabelDX, 1, 2);
182 GroupAxisLayout->addWidget(SpinBox_DX, 1, 3);
183 GroupAxisLayout->addWidget(TextLabelDY, 1, 4);
184 GroupAxisLayout->addWidget(SpinBox_DY, 1, 5);
185 GroupAxisLayout->addWidget(TextLabelDZ, 1, 6);
186 GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7);
188 // Controls for angle defining
189 TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupArguments);
190 SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments);
193 ActionBox = new QGroupBox(GroupArguments);
194 ActionGroup = new QButtonGroup(GroupArguments);
195 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
196 ActionBoxLayout->setSpacing(SPACING);
197 ActionBoxLayout->setMargin(MARGIN);
199 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
200 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
201 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
203 ActionBoxLayout->addWidget(aMoveElements);
204 ActionBoxLayout->addWidget(aCopyElements);
205 ActionBoxLayout->addWidget(aCreateMesh);
206 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
207 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
208 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
210 // CheckBox for groups generation
211 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
213 // Name of a mesh to create
214 LineEditNewMesh = new QLineEdit(GroupArguments);
218 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
220 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
221 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
222 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
223 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
224 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
225 GroupArgumentsLayout->addWidget(GroupAxis, 2, 0, 1, 4);
226 GroupArgumentsLayout->addWidget(TextLabelAngle, 3, 0, 1, 2);
227 GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
228 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 3);
229 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 3);
230 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 3);
231 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 7, 0);
234 /***************************************************************/
235 GroupButtons = new QGroupBox(this);
236 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
237 GroupButtonsLayout->setSpacing(SPACING);
238 GroupButtonsLayout->setMargin(MARGIN);
240 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
241 buttonOk->setAutoDefault(true);
242 buttonOk->setDefault(true);
243 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
244 buttonApply->setAutoDefault(true);
245 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
246 buttonCancel->setAutoDefault(true);
247 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
248 buttonHelp->setAutoDefault(true);
250 GroupButtonsLayout->addWidget(buttonOk);
251 GroupButtonsLayout->addSpacing(10);
252 GroupButtonsLayout->addWidget(buttonApply);
253 GroupButtonsLayout->addSpacing(10);
254 GroupButtonsLayout->addStretch();
255 GroupButtonsLayout->addWidget(buttonCancel);
256 GroupButtonsLayout->addWidget(buttonHelp);
258 /***************************************************************/
259 SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors);
260 SMESHGUI_RotationDlgLayout->addWidget(GroupArguments);
261 SMESHGUI_RotationDlgLayout->addWidget(GroupButtons);
263 /* Initialisations */
264 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
265 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
266 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
267 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
268 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
269 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
271 SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, "angle_precision");
274 RadioButton1->setChecked(true);
276 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
278 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
280 // Costruction of the logical filter
281 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
282 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::GROUP);
284 QList<SUIT_SelectionFilter*> aListOfFilters;
285 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
286 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
288 myMeshOrSubMeshOrGroupFilter =
289 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
291 myHelpFileName = "rotation_page.html";
295 /* signals and slots connections */
296 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
297 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
298 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
299 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
301 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
302 connect(SelectPointButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
303 connect(SelectVectorButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
305 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
306 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
307 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
309 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
310 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
311 /* to close dialog if study change */
312 connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView()));
313 connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView()));
314 connect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView()));
315 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
316 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
317 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
319 connect(SpinBox_X, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
320 connect(SpinBox_Y, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
321 connect(SpinBox_Z, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
322 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
323 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
324 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
325 connect(SpinBox_Angle, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
327 //To Connect preview check box
328 connectPreviewControl();
330 onActionClicked(MOVE_ELEMS_BUTTON);
333 //=================================================================================
334 // function : ~SMESHGUI_RotationDlg()
335 // purpose : Destroys the object and frees any allocated resources
336 //=================================================================================
337 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
340 myFilterDlg->setParent( 0 );
346 //=================================================================================
349 //=================================================================================
350 void SMESHGUI_RotationDlg::Init (bool ResetControls)
355 myObjectsNames.clear();
357 myEditCurrentArgument = (QWidget*)LineEditElements;
358 LineEditElements->setFocus();
362 buttonOk->setEnabled(false);
363 buttonApply->setEnabled(false);
368 SpinBox_X->SetValue(0.0);
369 SpinBox_Y->SetValue(0.0);
370 SpinBox_Z->SetValue(0.0);
371 SpinBox_DX->SetValue(0.0);
372 SpinBox_DY->SetValue(0.0);
373 SpinBox_DZ->SetValue(0.0);
375 SpinBox_Angle->SetValue(45);
377 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
378 CheckBoxMesh->setChecked(false);
379 myPreviewCheckBox->setChecked(false);
380 onDisplaySimulation(false);
382 // MakeGroupsCheck->setChecked(false);
383 // MakeGroupsCheck->setEnabled(false);
384 // onSelectMesh(false);
387 onSelectMesh(CheckBoxMesh->isChecked());
390 //=================================================================================
391 // function : ClickOnApply()
393 //=================================================================================
394 bool SMESHGUI_RotationDlg::ClickOnApply()
396 if (mySMESHGUI->isActiveStudyLocked())
402 if (myNbOkElements && IsAxisOk()) {
403 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
405 SMESH::long_array_var anElementsId = new SMESH::long_array;
407 anElementsId->length(aListElementsId.count());
408 for (int i = 0; i < aListElementsId.count(); i++)
409 anElementsId[i] = aListElementsId[i].toInt();
411 SMESH::AxisStruct anAxis;
413 anAxis.x = SpinBox_X->GetValue();
414 anAxis.y = SpinBox_Y->GetValue();
415 anAxis.z = SpinBox_Z->GetValue();;
416 anAxis.vx = SpinBox_DX->GetValue();
417 anAxis.vy = SpinBox_DY->GetValue();
418 anAxis.vz = SpinBox_DZ->GetValue();
420 double anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
422 QStringList aParameters;
423 aParameters << SpinBox_X->text();
424 aParameters << SpinBox_Y->text();
425 aParameters << SpinBox_Z->text();
426 aParameters << SpinBox_DX->text();
427 aParameters << SpinBox_DY->text();
428 aParameters << SpinBox_DZ->text();
429 aParameters << SpinBox_Angle->text();
431 int actionButton = ActionGroup->checkedId();
432 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
433 QStringList anEntryList;
435 SUIT_OverrideCursor aWaitCursor;
437 switch ( actionButton ) {
438 case MOVE_ELEMS_BUTTON:
439 if(CheckBoxMesh->isChecked()) {
440 for ( int i = 0; i < myObjects.count(); i++ ) {
441 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
442 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
443 aMeshEditor->RotateObject(myObjects[i], anAxis, anAngle, false);
447 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
448 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
449 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
452 case COPY_ELEMS_BUTTON:
454 SMESH::ListOfGroups_var groups;
455 if(CheckBoxMesh->isChecked()) {
456 for ( int i = 0; i < myObjects.count(); i++ ) {
457 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
458 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
459 groups = aMeshEditor->RotateObjectMakeGroups(myObjects[i], anAxis, anAngle);
463 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
464 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
465 groups = aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
469 if(CheckBoxMesh->isChecked()) {
470 for ( int i = 0; i < myObjects.count(); i++ ) {
471 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
472 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
473 aMeshEditor->RotateObject(myObjects[i], anAxis, anAngle, true);
477 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
478 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
479 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
483 case MAKE_MESH_BUTTON: {
484 SMESH::SMESH_Mesh_var mesh;
485 if (CheckBoxMesh->isChecked()) {
486 for ( int i = 0; i < myObjects.count(); i++ ) {
487 QString aName = SMESH::UniqueMeshName( LineEditNewMesh->text().replace( "*", myObjectsNames[i] ) );
488 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
489 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
490 mesh = aMeshEditor->RotateObjectMakeMesh(myObjects[i], anAxis, anAngle, makeGroups,
491 aName.toLatin1().data());
492 if (!mesh->_is_nil()) {
493 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
494 anEntryList.append( aSObject->GetID().c_str() );
499 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
500 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
501 mesh = aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
502 LineEditNewMesh->text().toLatin1().data());
503 if (!mesh->_is_nil()) {
504 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
505 anEntryList.append( aSObject->GetID().c_str() );
514 for ( int i = 0; i < myObjects.count(); i++ ) {
515 SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
516 if ( actor ) SMESH::Update( actor->getIO(), true );
519 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
520 actionButton == MAKE_MESH_BUTTON ) {
521 mySMESHGUI->updateObjBrowser(true); // new groups may appear
522 if( LightApp_Application* anApp =
523 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
524 anApp->browseObjects( anEntryList, isApplyAndClose() );
527 SelectionIntoArgument();
529 SMESHGUI::Modified();
535 //=================================================================================
536 // function : ClickOnOk()
538 //=================================================================================
539 void SMESHGUI_RotationDlg::ClickOnOk()
541 setIsApplyAndClose( true );
546 //=================================================================================
547 // function : reject()
549 //=================================================================================
550 void SMESHGUI_RotationDlg::reject()
552 disconnect(mySelectionMgr, 0, this, 0);
553 mySelectionMgr->clearFilters();
554 //mySelectionMgr->clearSelected();
555 if (SMESH::GetCurrentVtkView()) {
556 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
557 SMESH::SetPointRepresentation(false);
559 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
560 aViewWindow->SetSelectionMode(ActorSelection);
561 mySMESHGUI->ResetState();
566 //=================================================================================
567 // function : onOpenView()
569 //=================================================================================
570 void SMESHGUI_RotationDlg::onOpenView()
573 SMESH::SetPointRepresentation(false);
576 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
577 ActivateThisDialog();
581 //=================================================================================
582 // function : onCloseView()
584 //=================================================================================
585 void SMESHGUI_RotationDlg::onCloseView()
587 DeactivateActiveDialog();
591 //=================================================================================
592 // function : ClickOnHelp()
594 //=================================================================================
595 void SMESHGUI_RotationDlg::ClickOnHelp()
597 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
599 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
603 platform = "winapplication";
605 platform = "application";
607 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
608 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
609 arg(app->resourceMgr()->stringValue("ExternalBrowser",
611 arg(myHelpFileName));
615 //=======================================================================
616 // function : onTextChange()
618 //=======================================================================
619 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
621 QLineEdit* send = (QLineEdit*)sender();
626 if (send == LineEditElements)
629 buttonOk->setEnabled(false);
630 buttonApply->setEnabled(false);
632 // hilight entered elements
633 SMDS_Mesh* aMesh = 0;
635 aMesh = myActor->GetObject()->GetMesh();
638 if (send == LineEditElements) {
639 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
641 TColStd_MapOfInteger newIndices;
643 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
644 for (int i = 0; i < aListId.count(); i++) {
645 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
647 newIndices.Add(e->GetID());
651 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
652 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
653 aViewWindow->highlight( anIO, true, true );
655 myElementsId = theNewText;
659 if (myNbOkElements && IsAxisOk()) {
660 buttonOk->setEnabled(true);
661 buttonApply->setEnabled(true);
667 //=================================================================================
668 // function : SelectionIntoArgument()
669 // purpose : Called when selection as changed or other case
670 //=================================================================================
671 void SMESHGUI_RotationDlg::SelectionIntoArgument()
677 QString aString = "";
678 onDisplaySimulation(false);
681 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
682 LineEditElements->setText(aString);
684 buttonOk->setEnabled(false);
685 buttonApply->setEnabled(false);
689 if (!GroupButtons->isEnabled()) // inactive
694 mySelectionMgr->selectedObjects(aList);
696 int nbSel = aList.Extent();
702 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
705 myObjectsNames.clear();
708 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
709 Handle(SALOME_InteractiveObject) IO = it.Value();
710 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
711 if ( aMesh->_is_nil() )
714 myActor = SMESH::FindActorByObject( aMesh );
716 myActor = SMESH::FindActorByEntry( IO->getEntry() );
717 if ( !myActor && !CheckBoxMesh->isChecked() )
720 if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
721 if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
722 _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
723 _PTR(GenericAttribute) anAttr;
724 if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
725 _PTR(AttributeName) aNameAttr( anAttr );
726 myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
727 myObjectsNames << aNameAttr->Value().c_str();
734 // MakeGroups is available if there are groups and "Copy"
736 for ( int i = 0; i < myMeshes.count(); i++ )
737 aNbGroups += myMeshes[i]->NbGroups();
738 if ( aNbGroups == 0 ) {
739 MakeGroupsCheck->setChecked(false);
740 MakeGroupsCheck->setEnabled(false);
742 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
743 MakeGroupsCheck->setEnabled(true);
745 if (CheckBoxMesh->isChecked()) {
746 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
748 if ( myMeshes.isEmpty() )
752 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
756 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
757 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
759 myElementsId += QString(" %1").arg(i);
763 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
765 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
767 // get IDs from submesh
768 SMESH::long_array_var anElementsIds = new SMESH::long_array;
769 anElementsIds = aSubMesh->GetElementsId();
770 for (int i = 0; i < anElementsIds->length(); i++) {
771 myElementsId += QString(" %1").arg(anElementsIds[i]);
773 aNbUnits = anElementsIds->length();
776 SMESH::SMESH_GroupBase_var aGroup =
777 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
778 if (aGroup->_is_nil())
781 // get IDs from smesh group
782 SMESH::long_array_var anElementsIds = new SMESH::long_array;
783 anElementsIds = aGroup->GetListOfID();
784 for (int i = 0; i < anElementsIds->length(); i++) {
785 myElementsId += QString(" %1").arg(anElementsIds[i]);
787 aNbUnits = anElementsIds->length();
791 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
792 myElementsId = aString;
797 myNbOkElements = true;
800 Handle(SALOME_InteractiveObject) IO = aList.First();
801 if ((SMESH::GetMeshByIO(IO))->_is_nil())
804 SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
806 anActor = SMESH::FindActorByEntry(IO->getEntry());
807 if (!anActor && !CheckBoxMesh->isChecked())
810 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
814 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
818 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
826 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
827 SpinBox_X->SetValue(x);
828 SpinBox_Y->SetValue(y);
829 SpinBox_Z->SetValue(z);
830 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
831 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
832 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
833 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
838 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
839 LineEditElements->setText(aString);
840 LineEditElements->repaint();
841 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
842 LineEditElements->setEnabled(true);
848 if (myNbOkElements && IsAxisOk()) {
849 buttonOk->setEnabled(true);
850 buttonApply->setEnabled(true);
852 onDisplaySimulation(true);
855 //=================================================================================
856 // function : SetEditCurrentArgument()
858 //=================================================================================
859 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
861 QPushButton* send = (QPushButton*)sender();
863 disconnect(mySelectionMgr, 0, this, 0);
864 mySelectionMgr->clearSelected();
865 mySelectionMgr->clearFilters();
867 switch (myConstructorId) {
868 case 0: /* default constructor */
870 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
871 if (send == SelectElementsButton) {
872 myEditCurrentArgument = (QWidget*)LineEditElements;
873 SMESH::SetPointRepresentation(false);
874 if (CheckBoxMesh->isChecked()) {
876 aViewWindow->SetSelectionMode(ActorSelection);
877 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
880 aViewWindow->SetSelectionMode( CellSelection );
882 } else if (send == SelectPointButton) {
883 myEditCurrentArgument = (QWidget*)SpinBox_X;
884 SMESH::SetPointRepresentation(true);
886 aViewWindow->SetSelectionMode( NodeSelection );
887 } else if (send == SelectVectorButton) {
888 myEditCurrentArgument = (QWidget*)SpinBox_DX;
889 SMESH::SetPointRepresentation(true);
891 aViewWindow->SetSelectionMode( NodeSelection );
898 myEditCurrentArgument->setFocus();
899 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
900 SelectionIntoArgument();
903 //=================================================================================
904 // function : DeactivateActiveDialog()
906 //=================================================================================
907 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
909 if (GroupConstructors->isEnabled()) {
910 GroupConstructors->setEnabled(false);
911 GroupArguments->setEnabled(false);
912 GroupButtons->setEnabled(false);
913 mySMESHGUI->ResetState();
914 mySMESHGUI->SetActiveDialogBox(0);
918 //=================================================================================
919 // function : ActivateThisDialog()
921 //=================================================================================
922 void SMESHGUI_RotationDlg::ActivateThisDialog()
924 /* Emit a signal to deactivate the active dialog */
925 mySMESHGUI->EmitSignalDeactivateDialog();
926 GroupConstructors->setEnabled(true);
927 GroupArguments->setEnabled(true);
928 GroupButtons->setEnabled(true);
930 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
932 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
933 aViewWindow->SetSelectionMode( CellSelection );
934 SelectionIntoArgument();
937 //=================================================================================
938 // function : enterEvent()
940 //=================================================================================
941 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
943 if (!GroupConstructors->isEnabled()) {
944 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
945 if ( aViewWindow && !mySelector) {
946 mySelector = aViewWindow->GetSelector();
948 ActivateThisDialog();
952 //=================================================================================
953 // function : onSelectMesh()
955 //=================================================================================
956 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
959 TextLabelElements->setText(tr("SMESH_NAME"));
961 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
962 myFilterBtn->setEnabled(!toSelectMesh);
964 if (myEditCurrentArgument != LineEditElements) {
965 LineEditElements->clear();
969 mySelectionMgr->clearFilters();
970 SMESH::SetPointRepresentation(false);
973 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
974 aViewWindow->SetSelectionMode(ActorSelection);
975 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
976 LineEditElements->setReadOnly(true);
977 LineEditElements->setValidator(0);
979 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
980 aViewWindow->SetSelectionMode( CellSelection );
981 LineEditElements->setReadOnly(false);
982 LineEditElements->setValidator(myIdValidator);
983 onTextChange(LineEditElements->text());
987 SelectionIntoArgument();
990 //=================================================================================
991 // function : IsAxisOk()
993 //=================================================================================
994 bool SMESHGUI_RotationDlg::IsAxisOk()
996 return (SpinBox_DX->GetValue() != 0 ||
997 SpinBox_DY->GetValue() != 0 ||
998 SpinBox_DZ->GetValue() != 0);
1001 //=================================================================================
1002 // function : onVectorChanged()
1004 //=================================================================================
1005 void SMESHGUI_RotationDlg::onVectorChanged()
1008 buttonOk->setEnabled(true);
1009 buttonApply->setEnabled(true);
1011 buttonOk->setEnabled(false);
1012 buttonApply->setEnabled(false);
1017 //=======================================================================
1018 //function : onActionClicked
1019 //purpose : slot called when an action type changed
1020 //=======================================================================
1022 void SMESHGUI_RotationDlg::onActionClicked(int button)
1025 for ( int i = 0; i < myMeshes.count(); i++ )
1026 aNbGroups += myMeshes[i]->NbGroups();
1029 case MOVE_ELEMS_BUTTON:
1030 MakeGroupsCheck->setEnabled(false);
1031 LineEditNewMesh->setEnabled(false);
1033 case COPY_ELEMS_BUTTON:
1034 LineEditNewMesh->setEnabled(false);
1035 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1036 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1038 case MAKE_MESH_BUTTON:
1039 LineEditNewMesh->setEnabled(true);
1040 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1041 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1045 toDisplaySimulation();
1048 //=======================================================================
1049 //function : setNewMeshName
1050 //purpose : update contents of LineEditNewMesh
1051 //=======================================================================
1053 void SMESHGUI_RotationDlg::setNewMeshName()
1055 LineEditNewMesh->setText("");
1056 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1058 if ( CheckBoxMesh->isChecked() ) {
1059 name = myMeshes.count() > 1 ? "*" : LineEditElements->text();
1062 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1063 name = meshSO->GetName().c_str();
1065 if ( !name.isEmpty() )
1066 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
1070 //=================================================================================
1071 // function : keyPressEvent()
1073 //=================================================================================
1074 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
1076 QDialog::keyPressEvent( e );
1077 if ( e->isAccepted() )
1080 if ( e->key() == Qt::Key_F1 ) {
1086 //=================================================================================
1087 // function : setFilters()
1088 // purpose : SLOT. Called when "Filter" button pressed.
1089 //=================================================================================
1090 void SMESHGUI_RotationDlg::setFilters()
1092 if ( myMeshes.isEmpty() ) {
1093 SUIT_MessageBox::critical(this,
1095 tr("NO_MESH_SELECTED"));
1099 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1101 myFilterDlg->SetSelection();
1102 myFilterDlg->SetMesh( myMeshes[0] );
1103 myFilterDlg->SetSourceWg( LineEditElements );
1105 myFilterDlg->show();
1108 //=================================================================================
1109 // function : isValid
1111 //=================================================================================
1112 bool SMESHGUI_RotationDlg::isValid()
1117 ok = SpinBox_X->isValid( msg, true ) && ok;
1118 ok = SpinBox_Y->isValid( msg, true ) && ok;
1119 ok = SpinBox_Z->isValid( msg, true ) && ok;
1120 ok = SpinBox_DX->isValid( msg, true ) && ok;
1121 ok = SpinBox_DY->isValid( msg, true ) && ok;
1122 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1123 ok = SpinBox_Angle->isValid( msg, true ) && ok;
1126 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1127 if ( !msg.isEmpty() )
1129 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1136 //=================================================================================
1137 // function : onDisplaySimulation
1138 // purpose : Show/Hide preview
1139 //=================================================================================
1140 void SMESHGUI_RotationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1141 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1142 if(myNbOkElements && isValid() && IsAxisOk()) {
1143 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1144 SMESH::long_array_var anElementsId = new SMESH::long_array;
1146 anElementsId->length(aListElementsId.count());
1147 for (int i = 0; i < aListElementsId.count(); i++)
1148 anElementsId[i] = aListElementsId[i].toInt();
1150 SMESH::AxisStruct anAxis;
1152 anAxis.x = SpinBox_X->GetValue();
1153 anAxis.y = SpinBox_Y->GetValue();
1154 anAxis.z = SpinBox_Z->GetValue();;
1155 anAxis.vx = SpinBox_DX->GetValue();
1156 anAxis.vy = SpinBox_DY->GetValue();
1157 anAxis.vz = SpinBox_DZ->GetValue();
1158 double anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
1161 SUIT_OverrideCursor aWaitCursor;
1162 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1163 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1164 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1165 if(CheckBoxMesh->isChecked())
1166 for ( int i = 0; i < myObjects.count(); i++ ) {
1167 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1168 aMeshEditor->RotateObject(myObjects[i], anAxis, anAngle, copy);
1169 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1172 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1173 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, copy);
1174 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1176 setSimulationPreview( aMeshPreviewStruct );