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 < myMeshes.count(); i++ )
529 SMESH::Update( (SMESH::FindActorByObject( myMeshes[i] ))->getIO(), true );
531 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
532 actionButton == MAKE_MESH_BUTTON ) {
533 mySMESHGUI->updateObjBrowser(true); // new groups may appear
534 if( LightApp_Application* anApp =
535 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
536 anApp->browseObjects( anEntryList, isApplyAndClose() );
539 SelectionIntoArgument();
541 SMESHGUI::Modified();
547 //=================================================================================
548 // function : ClickOnOk()
550 //=================================================================================
551 void SMESHGUI_RotationDlg::ClickOnOk()
553 setIsApplyAndClose( true );
558 //=================================================================================
559 // function : reject()
561 //=================================================================================
562 void SMESHGUI_RotationDlg::reject()
564 disconnect(mySelectionMgr, 0, this, 0);
565 mySelectionMgr->clearFilters();
566 //mySelectionMgr->clearSelected();
567 if (SMESH::GetCurrentVtkView()) {
568 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
569 SMESH::SetPointRepresentation(false);
571 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
572 aViewWindow->SetSelectionMode(ActorSelection);
573 mySMESHGUI->ResetState();
577 //=================================================================================
578 // function : ClickOnHelp()
580 //=================================================================================
581 void SMESHGUI_RotationDlg::ClickOnHelp()
583 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
585 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
589 platform = "winapplication";
591 platform = "application";
593 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
594 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
595 arg(app->resourceMgr()->stringValue("ExternalBrowser",
597 arg(myHelpFileName));
601 //=======================================================================
602 // function : onTextChange()
604 //=======================================================================
605 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
607 QLineEdit* send = (QLineEdit*)sender();
612 if (send == LineEditElements)
615 buttonOk->setEnabled(false);
616 buttonApply->setEnabled(false);
618 // hilight entered elements
619 SMDS_Mesh* aMesh = 0;
621 aMesh = myActor->GetObject()->GetMesh();
624 if (send == LineEditElements) {
625 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
627 TColStd_MapOfInteger newIndices;
629 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
630 for (int i = 0; i < aListId.count(); i++) {
631 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
633 newIndices.Add(e->GetID());
637 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
638 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
639 aViewWindow->highlight( anIO, true, true );
641 myElementsId = theNewText;
645 if (myNbOkElements && IsAxisOk()) {
646 buttonOk->setEnabled(true);
647 buttonApply->setEnabled(true);
653 //=================================================================================
654 // function : SelectionIntoArgument()
655 // purpose : Called when selection as changed or other case
656 //=================================================================================
657 void SMESHGUI_RotationDlg::SelectionIntoArgument()
663 QString aString = "";
664 onDisplaySimulation(false);
667 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
668 LineEditElements->setText(aString);
670 buttonOk->setEnabled(false);
671 buttonApply->setEnabled(false);
675 if (!GroupButtons->isEnabled()) // inactive
680 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
682 int nbSel = aList.Extent();
688 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
691 myObjectsNames.clear();
694 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
695 Handle(SALOME_InteractiveObject) IO = it.Value();
696 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
697 if ( aMesh->_is_nil() )
700 myActor = SMESH::FindActorByObject( aMesh );
702 myActor = SMESH::FindActorByEntry( IO->getEntry() );
703 if ( !myActor && !CheckBoxMesh->isChecked() )
706 if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
707 if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
708 _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
709 _PTR(GenericAttribute) anAttr;
710 if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
711 _PTR(AttributeName) aNameAttr( anAttr );
712 myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
713 myObjectsNames << aNameAttr->Value().c_str();
720 // MakeGroups is available if there are groups and "Copy"
722 for ( int i = 0; i < myMeshes.count(); i++ )
723 aNbGroups += myMeshes[i]->NbGroups();
724 if ( aNbGroups == 0 ) {
725 MakeGroupsCheck->setChecked(false);
726 MakeGroupsCheck->setEnabled(false);
728 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
729 MakeGroupsCheck->setEnabled(true);
731 if (CheckBoxMesh->isChecked()) {
732 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
734 if ( myMeshes.isEmpty() )
738 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
742 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
743 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
745 myElementsId += QString(" %1").arg(i);
749 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
751 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
753 // get IDs from submesh
754 SMESH::long_array_var anElementsIds = new SMESH::long_array;
755 anElementsIds = aSubMesh->GetElementsId();
756 for (int i = 0; i < anElementsIds->length(); i++) {
757 myElementsId += QString(" %1").arg(anElementsIds[i]);
759 aNbUnits = anElementsIds->length();
762 SMESH::SMESH_GroupBase_var aGroup =
763 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
764 if (aGroup->_is_nil())
767 // get IDs from smesh group
768 SMESH::long_array_var anElementsIds = new SMESH::long_array;
769 anElementsIds = aGroup->GetListOfID();
770 for (int i = 0; i < anElementsIds->length(); i++) {
771 myElementsId += QString(" %1").arg(anElementsIds[i]);
773 aNbUnits = anElementsIds->length();
777 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
778 myElementsId = aString;
783 myNbOkElements = true;
786 Handle(SALOME_InteractiveObject) IO = aList.First();
787 if ((SMESH::GetMeshByIO(IO))->_is_nil())
790 SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
792 anActor = SMESH::FindActorByEntry(IO->getEntry());
793 if (!anActor && !CheckBoxMesh->isChecked())
796 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
800 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
804 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
812 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
813 SpinBox_X->SetValue(x);
814 SpinBox_Y->SetValue(y);
815 SpinBox_Z->SetValue(z);
816 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
817 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
818 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
819 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
824 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
825 LineEditElements->setText(aString);
826 LineEditElements->repaint();
827 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
828 LineEditElements->setEnabled(true);
834 if (myNbOkElements && IsAxisOk()) {
835 buttonOk->setEnabled(true);
836 buttonApply->setEnabled(true);
838 onDisplaySimulation(true);
841 //=================================================================================
842 // function : SetEditCurrentArgument()
844 //=================================================================================
845 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
847 QPushButton* send = (QPushButton*)sender();
849 disconnect(mySelectionMgr, 0, this, 0);
850 mySelectionMgr->clearSelected();
851 mySelectionMgr->clearFilters();
853 switch (myConstructorId) {
854 case 0: /* default constructor */
856 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
857 if (send == SelectElementsButton) {
858 myEditCurrentArgument = (QWidget*)LineEditElements;
859 SMESH::SetPointRepresentation(false);
860 if (CheckBoxMesh->isChecked()) {
862 aViewWindow->SetSelectionMode(ActorSelection);
863 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
866 aViewWindow->SetSelectionMode( CellSelection );
868 } else if (send == SelectPointButton) {
869 myEditCurrentArgument = (QWidget*)SpinBox_X;
870 SMESH::SetPointRepresentation(true);
872 aViewWindow->SetSelectionMode( NodeSelection );
873 } else if (send == SelectVectorButton) {
874 myEditCurrentArgument = (QWidget*)SpinBox_DX;
875 SMESH::SetPointRepresentation(true);
877 aViewWindow->SetSelectionMode( NodeSelection );
884 myEditCurrentArgument->setFocus();
885 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
886 SelectionIntoArgument();
889 //=================================================================================
890 // function : DeactivateActiveDialog()
892 //=================================================================================
893 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
895 if (GroupConstructors->isEnabled()) {
896 GroupConstructors->setEnabled(false);
897 GroupArguments->setEnabled(false);
898 GroupButtons->setEnabled(false);
899 mySMESHGUI->ResetState();
900 mySMESHGUI->SetActiveDialogBox(0);
904 //=================================================================================
905 // function : ActivateThisDialog()
907 //=================================================================================
908 void SMESHGUI_RotationDlg::ActivateThisDialog()
910 /* Emit a signal to deactivate the active dialog */
911 mySMESHGUI->EmitSignalDeactivateDialog();
912 GroupConstructors->setEnabled(true);
913 GroupArguments->setEnabled(true);
914 GroupButtons->setEnabled(true);
916 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
918 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
919 aViewWindow->SetSelectionMode( CellSelection );
920 SelectionIntoArgument();
923 //=================================================================================
924 // function : enterEvent()
926 //=================================================================================
927 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
929 if (!GroupConstructors->isEnabled())
930 ActivateThisDialog();
933 //=================================================================================
934 // function : onSelectMesh()
936 //=================================================================================
937 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
940 TextLabelElements->setText(tr("SMESH_NAME"));
942 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
943 myFilterBtn->setEnabled(!toSelectMesh);
945 if (myEditCurrentArgument != LineEditElements) {
946 LineEditElements->clear();
950 mySelectionMgr->clearFilters();
951 SMESH::SetPointRepresentation(false);
954 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
955 aViewWindow->SetSelectionMode(ActorSelection);
956 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
957 LineEditElements->setReadOnly(true);
958 LineEditElements->setValidator(0);
960 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
961 aViewWindow->SetSelectionMode( CellSelection );
962 LineEditElements->setReadOnly(false);
963 LineEditElements->setValidator(myIdValidator);
964 onTextChange(LineEditElements->text());
968 SelectionIntoArgument();
971 //=================================================================================
972 // function : IsAxisOk()
974 //=================================================================================
975 bool SMESHGUI_RotationDlg::IsAxisOk()
977 return (SpinBox_DX->GetValue() != 0 ||
978 SpinBox_DY->GetValue() != 0 ||
979 SpinBox_DZ->GetValue() != 0);
982 //=================================================================================
983 // function : onVectorChanged()
985 //=================================================================================
986 void SMESHGUI_RotationDlg::onVectorChanged()
989 buttonOk->setEnabled(true);
990 buttonApply->setEnabled(true);
992 buttonOk->setEnabled(false);
993 buttonApply->setEnabled(false);
998 //=======================================================================
999 //function : onActionClicked
1000 //purpose : slot called when an action type changed
1001 //=======================================================================
1003 void SMESHGUI_RotationDlg::onActionClicked(int button)
1006 for ( int i = 0; i < myMeshes.count(); i++ )
1007 aNbGroups += myMeshes[i]->NbGroups();
1010 case MOVE_ELEMS_BUTTON:
1011 MakeGroupsCheck->setEnabled(false);
1012 LineEditNewMesh->setEnabled(false);
1014 case COPY_ELEMS_BUTTON:
1015 LineEditNewMesh->setEnabled(false);
1016 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1017 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1019 case MAKE_MESH_BUTTON:
1020 LineEditNewMesh->setEnabled(true);
1021 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1022 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1026 toDisplaySimulation();
1029 //=======================================================================
1030 //function : setNewMeshName
1031 //purpose : update contents of LineEditNewMesh
1032 //=======================================================================
1034 void SMESHGUI_RotationDlg::setNewMeshName()
1036 LineEditNewMesh->setText("");
1037 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1039 if ( CheckBoxMesh->isChecked() ) {
1040 name = myMeshes.count() > 1 ? "*" : LineEditElements->text();
1043 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1044 name = meshSO->GetName().c_str();
1046 if ( !name.isEmpty() )
1047 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
1051 //=================================================================================
1052 // function : keyPressEvent()
1054 //=================================================================================
1055 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
1057 QDialog::keyPressEvent( e );
1058 if ( e->isAccepted() )
1061 if ( e->key() == Qt::Key_F1 ) {
1067 //=================================================================================
1068 // function : setFilters()
1069 // purpose : SLOT. Called when "Filter" button pressed.
1070 //=================================================================================
1071 void SMESHGUI_RotationDlg::setFilters()
1073 if ( myMeshes.isEmpty() ) {
1074 SUIT_MessageBox::critical(this,
1076 tr("NO_MESH_SELECTED"));
1080 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1082 myFilterDlg->SetSelection();
1083 myFilterDlg->SetMesh( myMeshes[0] );
1084 myFilterDlg->SetSourceWg( LineEditElements );
1086 myFilterDlg->show();
1089 //=================================================================================
1090 // function : isValid
1092 //=================================================================================
1093 bool SMESHGUI_RotationDlg::isValid()
1098 ok = SpinBox_X->isValid( msg, true ) && ok;
1099 ok = SpinBox_Y->isValid( msg, true ) && ok;
1100 ok = SpinBox_Z->isValid( msg, true ) && ok;
1101 ok = SpinBox_DX->isValid( msg, true ) && ok;
1102 ok = SpinBox_DY->isValid( msg, true ) && ok;
1103 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1104 ok = SpinBox_Angle->isValid( msg, true ) && ok;
1107 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1108 if ( !msg.isEmpty() )
1110 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1117 //=================================================================================
1118 // function : onDisplaySimulation
1119 // purpose : Show/Hide preview
1120 //=================================================================================
1121 void SMESHGUI_RotationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1122 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1123 if(myNbOkElements && isValid() && IsAxisOk()) {
1124 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1125 SMESH::long_array_var anElementsId = new SMESH::long_array;
1127 anElementsId->length(aListElementsId.count());
1128 for (int i = 0; i < aListElementsId.count(); i++)
1129 anElementsId[i] = aListElementsId[i].toInt();
1131 SMESH::AxisStruct anAxis;
1133 anAxis.x = SpinBox_X->GetValue();
1134 anAxis.y = SpinBox_Y->GetValue();
1135 anAxis.z = SpinBox_Z->GetValue();;
1136 anAxis.vx = SpinBox_DX->GetValue();
1137 anAxis.vy = SpinBox_DY->GetValue();
1138 anAxis.vz = SpinBox_DZ->GetValue();
1139 double anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
1142 SUIT_OverrideCursor aWaitCursor;
1143 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1144 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1145 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1146 if(CheckBoxMesh->isChecked())
1147 for ( int i = 0; i < myObjects.count(); i++ ) {
1148 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1149 aMeshEditor->RotateObject(myObjects[i], anAxis, anAngle, copy);
1150 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1153 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1154 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, copy);
1155 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1157 setSimulationPreview( aMeshPreviewStruct );