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>
55 #include <SALOME_ListIteratorOfListIO.hxx>
57 // SALOME KERNEL includes
58 #include <SALOMEDSClient.hxx>
59 #include <SALOMEDSClient_SObject.hxx>
62 #include <TColStd_MapOfInteger.hxx>
65 #include <QApplication>
66 #include <QButtonGroup>
70 #include <QPushButton>
71 #include <QRadioButton>
73 #include <QHBoxLayout>
74 #include <QVBoxLayout>
75 #include <QGridLayout>
79 #include <SALOMEconfig.h>
80 #include CORBA_SERVER_HEADER(SMESH_Group)
81 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
83 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
88 //To disable automatic genericobj management, the following line should be commented.
89 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
90 #define WITHGENERICOBJ
92 //=================================================================================
93 // class : SMESHGUI_RotationDlg()
95 //=================================================================================
96 SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule ) :
97 SMESHGUI_MultiPreviewDlg( theModule ),
98 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
101 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_ROTATION")));
102 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
105 setAttribute(Qt::WA_DeleteOnClose, true);
106 setWindowTitle(tr("SMESH_ROTATION_TITLE"));
107 setSizeGripEnabled(true);
109 QVBoxLayout* SMESHGUI_RotationDlgLayout = new QVBoxLayout(this);
110 SMESHGUI_RotationDlgLayout->setSpacing(SPACING);
111 SMESHGUI_RotationDlgLayout->setMargin(MARGIN);
113 /***************************************************************/
114 GroupConstructors = new QGroupBox(tr("SMESH_ROTATION"), this);
115 QButtonGroup* ButtonGroup = new QButtonGroup(this);
116 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
117 GroupConstructorsLayout->setSpacing(SPACING);
118 GroupConstructorsLayout->setMargin(MARGIN);
120 RadioButton1= new QRadioButton(GroupConstructors);
121 RadioButton1->setIcon(image0);
123 GroupConstructorsLayout->addWidget(RadioButton1);
124 ButtonGroup->addButton(RadioButton1, 0);
126 /***************************************************************/
127 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
128 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
129 GroupArgumentsLayout->setSpacing(SPACING);
130 GroupArgumentsLayout->setMargin(MARGIN);
132 myIdValidator = new SMESHGUI_IdValidator(this);
134 // Controls for elements selection
135 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
136 SelectElementsButton = new QPushButton(GroupArguments);
137 SelectElementsButton->setIcon(image1);
138 LineEditElements = new QLineEdit(GroupArguments);
139 LineEditElements->setValidator(myIdValidator);
140 LineEditElements->setMaxLength(-1);
141 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
142 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
144 // Control for the whole mesh selection
145 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
147 // Controls for axis defining
148 GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
149 QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
150 GroupAxisLayout->setSpacing(SPACING);
151 GroupAxisLayout->setMargin(MARGIN);
153 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
154 SelectPointButton = new QPushButton(GroupAxis);
155 SelectPointButton->setIcon(image1);
157 TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
158 SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
159 TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
160 SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
161 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
162 SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
164 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
165 SelectVectorButton = new QPushButton(GroupAxis);
166 SelectVectorButton->setIcon(image1);
168 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
169 SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
170 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
171 SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
172 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
173 SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
175 GroupAxisLayout->addWidget(TextLabelPoint, 0, 0);
176 GroupAxisLayout->addWidget(SelectPointButton, 0, 1);
177 GroupAxisLayout->addWidget(TextLabelX, 0, 2);
178 GroupAxisLayout->addWidget(SpinBox_X, 0, 3);
179 GroupAxisLayout->addWidget(TextLabelY, 0, 4);
180 GroupAxisLayout->addWidget(SpinBox_Y, 0, 5);
181 GroupAxisLayout->addWidget(TextLabelZ, 0, 6);
182 GroupAxisLayout->addWidget(SpinBox_Z, 0, 7);
183 GroupAxisLayout->addWidget(TextLabelVector, 1, 0);
184 GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
185 GroupAxisLayout->addWidget(TextLabelDX, 1, 2);
186 GroupAxisLayout->addWidget(SpinBox_DX, 1, 3);
187 GroupAxisLayout->addWidget(TextLabelDY, 1, 4);
188 GroupAxisLayout->addWidget(SpinBox_DY, 1, 5);
189 GroupAxisLayout->addWidget(TextLabelDZ, 1, 6);
190 GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7);
192 // Controls for angle defining
193 TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupArguments);
194 SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments);
197 ActionBox = new QGroupBox(GroupArguments);
198 ActionGroup = new QButtonGroup(GroupArguments);
199 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
200 ActionBoxLayout->setSpacing(SPACING);
201 ActionBoxLayout->setMargin(MARGIN);
203 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
204 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
205 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
207 ActionBoxLayout->addWidget(aMoveElements);
208 ActionBoxLayout->addWidget(aCopyElements);
209 ActionBoxLayout->addWidget(aCreateMesh);
210 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
211 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
212 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
214 // CheckBox for groups generation
215 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
217 // Name of a mesh to create
218 LineEditNewMesh = new QLineEdit(GroupArguments);
222 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
224 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
225 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
226 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
227 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
228 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
229 GroupArgumentsLayout->addWidget(GroupAxis, 2, 0, 1, 4);
230 GroupArgumentsLayout->addWidget(TextLabelAngle, 3, 0, 1, 2);
231 GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
232 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 3);
233 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 3);
234 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 3);
235 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 7, 0);
238 /***************************************************************/
239 GroupButtons = new QGroupBox(this);
240 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
241 GroupButtonsLayout->setSpacing(SPACING);
242 GroupButtonsLayout->setMargin(MARGIN);
244 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
245 buttonOk->setAutoDefault(true);
246 buttonOk->setDefault(true);
247 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
248 buttonApply->setAutoDefault(true);
249 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
250 buttonCancel->setAutoDefault(true);
251 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
252 buttonHelp->setAutoDefault(true);
254 GroupButtonsLayout->addWidget(buttonOk);
255 GroupButtonsLayout->addSpacing(10);
256 GroupButtonsLayout->addWidget(buttonApply);
257 GroupButtonsLayout->addSpacing(10);
258 GroupButtonsLayout->addStretch();
259 GroupButtonsLayout->addWidget(buttonCancel);
260 GroupButtonsLayout->addWidget(buttonHelp);
262 /***************************************************************/
263 SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors);
264 SMESHGUI_RotationDlgLayout->addWidget(GroupArguments);
265 SMESHGUI_RotationDlgLayout->addWidget(GroupButtons);
267 /* Initialisations */
268 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
269 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
270 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
271 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
272 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
273 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
275 SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, "angle_precision");
278 RadioButton1->setChecked(true);
280 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
282 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
284 // Costruction of the logical filter
285 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
286 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::GROUP);
288 QList<SUIT_SelectionFilter*> aListOfFilters;
289 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
290 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
292 myMeshOrSubMeshOrGroupFilter =
293 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
295 myHelpFileName = "rotation_page.html";
299 /* signals and slots connections */
300 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
301 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
302 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
303 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
305 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
306 connect(SelectPointButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
307 connect(SelectVectorButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
309 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
310 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
311 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
313 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
314 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
315 /* to close dialog if study change */
316 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
317 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
318 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
319 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
321 connect(SpinBox_X, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
322 connect(SpinBox_Y, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
323 connect(SpinBox_Z, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
324 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
325 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
327 connect(SpinBox_Angle, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
329 //To Connect preview check box
330 connectPreviewControl();
332 onActionClicked(MOVE_ELEMS_BUTTON);
335 //=================================================================================
336 // function : ~SMESHGUI_RotationDlg()
337 // purpose : Destroys the object and frees any allocated resources
338 //=================================================================================
339 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
342 myFilterDlg->setParent( 0 );
348 //=================================================================================
351 //=================================================================================
352 void SMESHGUI_RotationDlg::Init (bool ResetControls)
357 myObjectsNames.clear();
359 myEditCurrentArgument = (QWidget*)LineEditElements;
360 LineEditElements->setFocus();
364 buttonOk->setEnabled(false);
365 buttonApply->setEnabled(false);
370 SpinBox_X->SetValue(0.0);
371 SpinBox_Y->SetValue(0.0);
372 SpinBox_Z->SetValue(0.0);
373 SpinBox_DX->SetValue(0.0);
374 SpinBox_DY->SetValue(0.0);
375 SpinBox_DZ->SetValue(0.0);
377 SpinBox_Angle->SetValue(45);
379 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
380 CheckBoxMesh->setChecked(false);
381 myPreviewCheckBox->setChecked(false);
382 onDisplaySimulation(false);
384 // MakeGroupsCheck->setChecked(false);
385 // MakeGroupsCheck->setEnabled(false);
386 // onSelectMesh(false);
389 onSelectMesh(CheckBoxMesh->isChecked());
392 //=================================================================================
393 // function : ClickOnApply()
395 //=================================================================================
396 bool SMESHGUI_RotationDlg::ClickOnApply()
398 if (mySMESHGUI->isActiveStudyLocked())
404 if (myNbOkElements && IsAxisOk()) {
405 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
407 SMESH::long_array_var anElementsId = new SMESH::long_array;
409 anElementsId->length(aListElementsId.count());
410 for (int i = 0; i < aListElementsId.count(); i++)
411 anElementsId[i] = aListElementsId[i].toInt();
413 SMESH::AxisStruct anAxis;
415 anAxis.x = SpinBox_X->GetValue();
416 anAxis.y = SpinBox_Y->GetValue();
417 anAxis.z = SpinBox_Z->GetValue();;
418 anAxis.vx = SpinBox_DX->GetValue();
419 anAxis.vy = SpinBox_DY->GetValue();
420 anAxis.vz = SpinBox_DZ->GetValue();
422 double anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
424 QStringList aParameters;
425 aParameters << SpinBox_X->text();
426 aParameters << SpinBox_Y->text();
427 aParameters << SpinBox_Z->text();
428 aParameters << SpinBox_DX->text();
429 aParameters << SpinBox_DY->text();
430 aParameters << SpinBox_DZ->text();
431 aParameters << SpinBox_Angle->text();
433 int actionButton = ActionGroup->checkedId();
434 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
435 QStringList anEntryList;
437 SUIT_OverrideCursor aWaitCursor;
439 switch ( actionButton ) {
440 case MOVE_ELEMS_BUTTON:
441 if(CheckBoxMesh->isChecked()) {
442 for ( int i = 0; i < myObjects.count(); i++ ) {
443 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
444 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
445 aMeshEditor->RotateObject(myObjects[i], anAxis, anAngle, false);
449 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
450 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
451 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
454 case COPY_ELEMS_BUTTON:
456 SMESH::ListOfGroups_var groups;
457 if(CheckBoxMesh->isChecked()) {
458 for ( int i = 0; i < myObjects.count(); i++ ) {
459 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
460 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
461 groups = aMeshEditor->RotateObjectMakeGroups(myObjects[i], anAxis, anAngle);
465 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
466 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
467 groups = aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
471 if(CheckBoxMesh->isChecked()) {
472 for ( int i = 0; i < myObjects.count(); i++ ) {
473 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
474 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
475 aMeshEditor->RotateObject(myObjects[i], anAxis, anAngle, true);
479 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
480 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
481 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
485 case MAKE_MESH_BUTTON: {
486 SMESH::SMESH_Mesh_var mesh;
487 if (CheckBoxMesh->isChecked()) {
488 for ( int i = 0; i < myObjects.count(); i++ ) {
489 QString aName = SMESH::UniqueMeshName( LineEditNewMesh->text().replace( "*", myObjectsNames[i] ) );
490 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
491 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
492 mesh = aMeshEditor->RotateObjectMakeMesh(myObjects[i], anAxis, anAngle, makeGroups,
493 aName.toLatin1().data());
494 if (!mesh->_is_nil()) {
495 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
496 anEntryList.append( aSObject->GetID().c_str() );
497 #ifdef WITHGENERICOBJ
498 // obj has been published in study. Its refcount has been incremented.
499 // It is safe to decrement its refcount
500 // so that it will be destroyed when the entry in study will be removed
507 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
508 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
509 mesh = aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
510 LineEditNewMesh->text().toLatin1().data());
511 if (!mesh->_is_nil()) {
512 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
513 anEntryList.append( aSObject->GetID().c_str() );
514 #ifdef WITHGENERICOBJ
515 // obj has been published in study. Its refcount has been incremented.
516 // It is safe to decrement its refcount
517 // so that it will be destroyed when the entry in study will be removed
528 for ( int i = 0; i < myObjects.count(); i++ ) {
529 SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
530 if ( actor ) SMESH::Update( actor->getIO(), true );
533 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
534 actionButton == MAKE_MESH_BUTTON ) {
535 mySMESHGUI->updateObjBrowser(true); // new groups may appear
536 if( LightApp_Application* anApp =
537 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
538 anApp->browseObjects( anEntryList, isApplyAndClose() );
541 SelectionIntoArgument();
543 SMESHGUI::Modified();
549 //=================================================================================
550 // function : ClickOnOk()
552 //=================================================================================
553 void SMESHGUI_RotationDlg::ClickOnOk()
555 setIsApplyAndClose( true );
560 //=================================================================================
561 // function : reject()
563 //=================================================================================
564 void SMESHGUI_RotationDlg::reject()
566 disconnect(mySelectionMgr, 0, this, 0);
567 mySelectionMgr->clearFilters();
568 //mySelectionMgr->clearSelected();
569 if (SMESH::GetCurrentVtkView()) {
570 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
571 SMESH::SetPointRepresentation(false);
573 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
574 aViewWindow->SetSelectionMode(ActorSelection);
575 mySMESHGUI->ResetState();
579 //=================================================================================
580 // function : ClickOnHelp()
582 //=================================================================================
583 void SMESHGUI_RotationDlg::ClickOnHelp()
585 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
587 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
591 platform = "winapplication";
593 platform = "application";
595 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
596 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
597 arg(app->resourceMgr()->stringValue("ExternalBrowser",
599 arg(myHelpFileName));
603 //=======================================================================
604 // function : onTextChange()
606 //=======================================================================
607 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
609 QLineEdit* send = (QLineEdit*)sender();
614 if (send == LineEditElements)
617 buttonOk->setEnabled(false);
618 buttonApply->setEnabled(false);
620 // hilight entered elements
621 SMDS_Mesh* aMesh = 0;
623 aMesh = myActor->GetObject()->GetMesh();
626 if (send == LineEditElements) {
627 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
629 TColStd_MapOfInteger newIndices;
631 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
632 for (int i = 0; i < aListId.count(); i++) {
633 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
635 newIndices.Add(e->GetID());
639 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
640 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
641 aViewWindow->highlight( anIO, true, true );
643 myElementsId = theNewText;
647 if (myNbOkElements && IsAxisOk()) {
648 buttonOk->setEnabled(true);
649 buttonApply->setEnabled(true);
655 //=================================================================================
656 // function : SelectionIntoArgument()
657 // purpose : Called when selection as changed or other case
658 //=================================================================================
659 void SMESHGUI_RotationDlg::SelectionIntoArgument()
665 QString aString = "";
666 onDisplaySimulation(false);
669 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
670 LineEditElements->setText(aString);
672 buttonOk->setEnabled(false);
673 buttonApply->setEnabled(false);
677 if (!GroupButtons->isEnabled()) // inactive
682 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
684 int nbSel = aList.Extent();
690 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
693 myObjectsNames.clear();
696 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
697 Handle(SALOME_InteractiveObject) IO = it.Value();
698 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
699 if ( aMesh->_is_nil() )
702 myActor = SMESH::FindActorByObject( aMesh );
704 myActor = SMESH::FindActorByEntry( IO->getEntry() );
705 if ( !myActor && !CheckBoxMesh->isChecked() )
708 if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
709 if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
710 _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
711 _PTR(GenericAttribute) anAttr;
712 if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
713 _PTR(AttributeName) aNameAttr( anAttr );
714 myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
715 myObjectsNames << aNameAttr->Value().c_str();
722 // MakeGroups is available if there are groups and "Copy"
724 for ( int i = 0; i < myMeshes.count(); i++ )
725 aNbGroups += myMeshes[i]->NbGroups();
726 if ( aNbGroups == 0 ) {
727 MakeGroupsCheck->setChecked(false);
728 MakeGroupsCheck->setEnabled(false);
730 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
731 MakeGroupsCheck->setEnabled(true);
733 if (CheckBoxMesh->isChecked()) {
734 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
736 if ( myMeshes.isEmpty() )
740 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
744 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
745 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
747 myElementsId += QString(" %1").arg(i);
751 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
753 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
755 // get IDs from submesh
756 SMESH::long_array_var anElementsIds = new SMESH::long_array;
757 anElementsIds = aSubMesh->GetElementsId();
758 for (int i = 0; i < anElementsIds->length(); i++) {
759 myElementsId += QString(" %1").arg(anElementsIds[i]);
761 aNbUnits = anElementsIds->length();
764 SMESH::SMESH_GroupBase_var aGroup =
765 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
766 if (aGroup->_is_nil())
769 // get IDs from smesh group
770 SMESH::long_array_var anElementsIds = new SMESH::long_array;
771 anElementsIds = aGroup->GetListOfID();
772 for (int i = 0; i < anElementsIds->length(); i++) {
773 myElementsId += QString(" %1").arg(anElementsIds[i]);
775 aNbUnits = anElementsIds->length();
779 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
780 myElementsId = aString;
785 myNbOkElements = true;
788 Handle(SALOME_InteractiveObject) IO = aList.First();
789 if ((SMESH::GetMeshByIO(IO))->_is_nil())
792 SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
794 anActor = SMESH::FindActorByEntry(IO->getEntry());
795 if (!anActor && !CheckBoxMesh->isChecked())
798 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
802 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
806 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
814 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
815 SpinBox_X->SetValue(x);
816 SpinBox_Y->SetValue(y);
817 SpinBox_Z->SetValue(z);
818 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
819 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
820 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
821 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
826 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
827 LineEditElements->setText(aString);
828 LineEditElements->repaint();
829 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
830 LineEditElements->setEnabled(true);
836 if (myNbOkElements && IsAxisOk()) {
837 buttonOk->setEnabled(true);
838 buttonApply->setEnabled(true);
840 onDisplaySimulation(true);
843 //=================================================================================
844 // function : SetEditCurrentArgument()
846 //=================================================================================
847 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
849 QPushButton* send = (QPushButton*)sender();
851 disconnect(mySelectionMgr, 0, this, 0);
852 mySelectionMgr->clearSelected();
853 mySelectionMgr->clearFilters();
855 switch (myConstructorId) {
856 case 0: /* default constructor */
858 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
859 if (send == SelectElementsButton) {
860 myEditCurrentArgument = (QWidget*)LineEditElements;
861 SMESH::SetPointRepresentation(false);
862 if (CheckBoxMesh->isChecked()) {
864 aViewWindow->SetSelectionMode(ActorSelection);
865 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
868 aViewWindow->SetSelectionMode( CellSelection );
870 } else if (send == SelectPointButton) {
871 myEditCurrentArgument = (QWidget*)SpinBox_X;
872 SMESH::SetPointRepresentation(true);
874 aViewWindow->SetSelectionMode( NodeSelection );
875 } else if (send == SelectVectorButton) {
876 myEditCurrentArgument = (QWidget*)SpinBox_DX;
877 SMESH::SetPointRepresentation(true);
879 aViewWindow->SetSelectionMode( NodeSelection );
886 myEditCurrentArgument->setFocus();
887 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
888 SelectionIntoArgument();
891 //=================================================================================
892 // function : DeactivateActiveDialog()
894 //=================================================================================
895 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
897 if (GroupConstructors->isEnabled()) {
898 GroupConstructors->setEnabled(false);
899 GroupArguments->setEnabled(false);
900 GroupButtons->setEnabled(false);
901 mySMESHGUI->ResetState();
902 mySMESHGUI->SetActiveDialogBox(0);
906 //=================================================================================
907 // function : ActivateThisDialog()
909 //=================================================================================
910 void SMESHGUI_RotationDlg::ActivateThisDialog()
912 /* Emit a signal to deactivate the active dialog */
913 mySMESHGUI->EmitSignalDeactivateDialog();
914 GroupConstructors->setEnabled(true);
915 GroupArguments->setEnabled(true);
916 GroupButtons->setEnabled(true);
918 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
920 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
921 aViewWindow->SetSelectionMode( CellSelection );
922 SelectionIntoArgument();
925 //=================================================================================
926 // function : enterEvent()
928 //=================================================================================
929 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
931 if (!GroupConstructors->isEnabled())
932 ActivateThisDialog();
935 //=================================================================================
936 // function : onSelectMesh()
938 //=================================================================================
939 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
942 TextLabelElements->setText(tr("SMESH_NAME"));
944 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
945 myFilterBtn->setEnabled(!toSelectMesh);
947 if (myEditCurrentArgument != LineEditElements) {
948 LineEditElements->clear();
952 mySelectionMgr->clearFilters();
953 SMESH::SetPointRepresentation(false);
956 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
957 aViewWindow->SetSelectionMode(ActorSelection);
958 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
959 LineEditElements->setReadOnly(true);
960 LineEditElements->setValidator(0);
962 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
963 aViewWindow->SetSelectionMode( CellSelection );
964 LineEditElements->setReadOnly(false);
965 LineEditElements->setValidator(myIdValidator);
966 onTextChange(LineEditElements->text());
970 SelectionIntoArgument();
973 //=================================================================================
974 // function : IsAxisOk()
976 //=================================================================================
977 bool SMESHGUI_RotationDlg::IsAxisOk()
979 return (SpinBox_DX->GetValue() != 0 ||
980 SpinBox_DY->GetValue() != 0 ||
981 SpinBox_DZ->GetValue() != 0);
984 //=================================================================================
985 // function : onVectorChanged()
987 //=================================================================================
988 void SMESHGUI_RotationDlg::onVectorChanged()
991 buttonOk->setEnabled(true);
992 buttonApply->setEnabled(true);
994 buttonOk->setEnabled(false);
995 buttonApply->setEnabled(false);
1000 //=======================================================================
1001 //function : onActionClicked
1002 //purpose : slot called when an action type changed
1003 //=======================================================================
1005 void SMESHGUI_RotationDlg::onActionClicked(int button)
1008 for ( int i = 0; i < myMeshes.count(); i++ )
1009 aNbGroups += myMeshes[i]->NbGroups();
1012 case MOVE_ELEMS_BUTTON:
1013 MakeGroupsCheck->setEnabled(false);
1014 LineEditNewMesh->setEnabled(false);
1016 case COPY_ELEMS_BUTTON:
1017 LineEditNewMesh->setEnabled(false);
1018 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1019 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1021 case MAKE_MESH_BUTTON:
1022 LineEditNewMesh->setEnabled(true);
1023 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1024 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1028 toDisplaySimulation();
1031 //=======================================================================
1032 //function : setNewMeshName
1033 //purpose : update contents of LineEditNewMesh
1034 //=======================================================================
1036 void SMESHGUI_RotationDlg::setNewMeshName()
1038 LineEditNewMesh->setText("");
1039 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1041 if ( CheckBoxMesh->isChecked() ) {
1042 name = myMeshes.count() > 1 ? "*" : LineEditElements->text();
1045 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1046 name = meshSO->GetName().c_str();
1048 if ( !name.isEmpty() )
1049 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
1053 //=================================================================================
1054 // function : keyPressEvent()
1056 //=================================================================================
1057 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
1059 QDialog::keyPressEvent( e );
1060 if ( e->isAccepted() )
1063 if ( e->key() == Qt::Key_F1 ) {
1069 //=================================================================================
1070 // function : setFilters()
1071 // purpose : SLOT. Called when "Filter" button pressed.
1072 //=================================================================================
1073 void SMESHGUI_RotationDlg::setFilters()
1075 if ( myMeshes.isEmpty() ) {
1076 SUIT_MessageBox::critical(this,
1078 tr("NO_MESH_SELECTED"));
1082 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1084 myFilterDlg->SetSelection();
1085 myFilterDlg->SetMesh( myMeshes[0] );
1086 myFilterDlg->SetSourceWg( LineEditElements );
1088 myFilterDlg->show();
1091 //=================================================================================
1092 // function : isValid
1094 //=================================================================================
1095 bool SMESHGUI_RotationDlg::isValid()
1100 ok = SpinBox_X->isValid( msg, true ) && ok;
1101 ok = SpinBox_Y->isValid( msg, true ) && ok;
1102 ok = SpinBox_Z->isValid( msg, true ) && ok;
1103 ok = SpinBox_DX->isValid( msg, true ) && ok;
1104 ok = SpinBox_DY->isValid( msg, true ) && ok;
1105 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1106 ok = SpinBox_Angle->isValid( msg, true ) && ok;
1109 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1110 if ( !msg.isEmpty() )
1112 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1119 //=================================================================================
1120 // function : onDisplaySimulation
1121 // purpose : Show/Hide preview
1122 //=================================================================================
1123 void SMESHGUI_RotationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1124 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1125 if(myNbOkElements && isValid() && IsAxisOk()) {
1126 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1127 SMESH::long_array_var anElementsId = new SMESH::long_array;
1129 anElementsId->length(aListElementsId.count());
1130 for (int i = 0; i < aListElementsId.count(); i++)
1131 anElementsId[i] = aListElementsId[i].toInt();
1133 SMESH::AxisStruct anAxis;
1135 anAxis.x = SpinBox_X->GetValue();
1136 anAxis.y = SpinBox_Y->GetValue();
1137 anAxis.z = SpinBox_Z->GetValue();;
1138 anAxis.vx = SpinBox_DX->GetValue();
1139 anAxis.vy = SpinBox_DY->GetValue();
1140 anAxis.vz = SpinBox_DZ->GetValue();
1141 double anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
1144 SUIT_OverrideCursor aWaitCursor;
1145 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1146 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1147 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1148 if(CheckBoxMesh->isChecked())
1149 for ( int i = 0; i < myObjects.count(); i++ ) {
1150 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1151 aMeshEditor->RotateObject(myObjects[i], anAxis, anAngle, copy);
1152 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1155 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1156 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, copy);
1157 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1159 setSimulationPreview( aMeshPreviewStruct );