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
89 //=================================================================================
90 // class : SMESHGUI_RotationDlg()
92 //=================================================================================
93 SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule ) :
94 SMESHGUI_MultiPreviewDlg( theModule ),
95 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
98 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_ROTATION")));
99 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
102 setAttribute(Qt::WA_DeleteOnClose, true);
103 setWindowTitle(tr("SMESH_ROTATION_TITLE"));
104 setSizeGripEnabled(true);
106 QVBoxLayout* SMESHGUI_RotationDlgLayout = new QVBoxLayout(this);
107 SMESHGUI_RotationDlgLayout->setSpacing(SPACING);
108 SMESHGUI_RotationDlgLayout->setMargin(MARGIN);
110 /***************************************************************/
111 GroupConstructors = new QGroupBox(tr("SMESH_ROTATION"), this);
112 QButtonGroup* ButtonGroup = new QButtonGroup(this);
113 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
114 GroupConstructorsLayout->setSpacing(SPACING);
115 GroupConstructorsLayout->setMargin(MARGIN);
117 RadioButton1= new QRadioButton(GroupConstructors);
118 RadioButton1->setIcon(image0);
120 GroupConstructorsLayout->addWidget(RadioButton1);
121 ButtonGroup->addButton(RadioButton1, 0);
123 /***************************************************************/
124 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
125 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
126 GroupArgumentsLayout->setSpacing(SPACING);
127 GroupArgumentsLayout->setMargin(MARGIN);
129 myIdValidator = new SMESHGUI_IdValidator(this);
131 // Controls for elements selection
132 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
133 SelectElementsButton = new QPushButton(GroupArguments);
134 SelectElementsButton->setIcon(image1);
135 LineEditElements = new QLineEdit(GroupArguments);
136 LineEditElements->setValidator(myIdValidator);
137 LineEditElements->setMaxLength(-1);
138 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
139 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
141 // Control for the whole mesh selection
142 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
144 // Controls for axis defining
145 GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
146 QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
147 GroupAxisLayout->setSpacing(SPACING);
148 GroupAxisLayout->setMargin(MARGIN);
150 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
151 SelectPointButton = new QPushButton(GroupAxis);
152 SelectPointButton->setIcon(image1);
154 TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
155 SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
156 TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
157 SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
158 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
159 SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
161 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
162 SelectVectorButton = new QPushButton(GroupAxis);
163 SelectVectorButton->setIcon(image1);
165 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
166 SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
167 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
168 SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
169 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
170 SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
172 GroupAxisLayout->addWidget(TextLabelPoint, 0, 0);
173 GroupAxisLayout->addWidget(SelectPointButton, 0, 1);
174 GroupAxisLayout->addWidget(TextLabelX, 0, 2);
175 GroupAxisLayout->addWidget(SpinBox_X, 0, 3);
176 GroupAxisLayout->addWidget(TextLabelY, 0, 4);
177 GroupAxisLayout->addWidget(SpinBox_Y, 0, 5);
178 GroupAxisLayout->addWidget(TextLabelZ, 0, 6);
179 GroupAxisLayout->addWidget(SpinBox_Z, 0, 7);
180 GroupAxisLayout->addWidget(TextLabelVector, 1, 0);
181 GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
182 GroupAxisLayout->addWidget(TextLabelDX, 1, 2);
183 GroupAxisLayout->addWidget(SpinBox_DX, 1, 3);
184 GroupAxisLayout->addWidget(TextLabelDY, 1, 4);
185 GroupAxisLayout->addWidget(SpinBox_DY, 1, 5);
186 GroupAxisLayout->addWidget(TextLabelDZ, 1, 6);
187 GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7);
189 // Controls for angle defining
190 TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupArguments);
191 SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments);
194 ActionBox = new QGroupBox(GroupArguments);
195 ActionGroup = new QButtonGroup(GroupArguments);
196 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
197 ActionBoxLayout->setSpacing(SPACING);
198 ActionBoxLayout->setMargin(MARGIN);
200 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
201 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
202 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
204 ActionBoxLayout->addWidget(aMoveElements);
205 ActionBoxLayout->addWidget(aCopyElements);
206 ActionBoxLayout->addWidget(aCreateMesh);
207 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
208 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
209 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
211 // CheckBox for groups generation
212 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
214 // Name of a mesh to create
215 LineEditNewMesh = new QLineEdit(GroupArguments);
219 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
221 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
222 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
223 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
224 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
225 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
226 GroupArgumentsLayout->addWidget(GroupAxis, 2, 0, 1, 4);
227 GroupArgumentsLayout->addWidget(TextLabelAngle, 3, 0, 1, 2);
228 GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
229 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 3);
230 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 3);
231 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 3);
232 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 7, 0);
235 /***************************************************************/
236 GroupButtons = new QGroupBox(this);
237 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
238 GroupButtonsLayout->setSpacing(SPACING);
239 GroupButtonsLayout->setMargin(MARGIN);
241 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
242 buttonOk->setAutoDefault(true);
243 buttonOk->setDefault(true);
244 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
245 buttonApply->setAutoDefault(true);
246 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
247 buttonCancel->setAutoDefault(true);
248 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
249 buttonHelp->setAutoDefault(true);
251 GroupButtonsLayout->addWidget(buttonOk);
252 GroupButtonsLayout->addSpacing(10);
253 GroupButtonsLayout->addWidget(buttonApply);
254 GroupButtonsLayout->addSpacing(10);
255 GroupButtonsLayout->addStretch();
256 GroupButtonsLayout->addWidget(buttonCancel);
257 GroupButtonsLayout->addWidget(buttonHelp);
259 /***************************************************************/
260 SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors);
261 SMESHGUI_RotationDlgLayout->addWidget(GroupArguments);
262 SMESHGUI_RotationDlgLayout->addWidget(GroupButtons);
264 /* Initialisations */
265 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
266 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
267 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
268 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
269 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
270 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
272 SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, "angle_precision");
275 RadioButton1->setChecked(true);
277 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
279 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
281 // Costruction of the logical filter
282 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
283 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::GROUP);
285 QList<SUIT_SelectionFilter*> aListOfFilters;
286 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
287 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
289 myMeshOrSubMeshOrGroupFilter =
290 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
292 myHelpFileName = "rotation_page.html";
296 /* signals and slots connections */
297 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
298 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
299 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
300 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
302 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
303 connect(SelectPointButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
304 connect(SelectVectorButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
306 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
307 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
308 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
310 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
311 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
312 /* to close dialog if study change */
313 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
314 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
315 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
316 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
318 connect(SpinBox_X, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
319 connect(SpinBox_Y, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
320 connect(SpinBox_Z, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
321 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
322 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
323 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
324 connect(SpinBox_Angle, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326 //To Connect preview check box
327 connectPreviewControl();
329 onActionClicked(MOVE_ELEMS_BUTTON);
332 //=================================================================================
333 // function : ~SMESHGUI_RotationDlg()
334 // purpose : Destroys the object and frees any allocated resources
335 //=================================================================================
336 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
339 myFilterDlg->setParent( 0 );
345 //=================================================================================
348 //=================================================================================
349 void SMESHGUI_RotationDlg::Init (bool ResetControls)
354 myObjectsNames.clear();
356 myEditCurrentArgument = (QWidget*)LineEditElements;
357 LineEditElements->setFocus();
361 buttonOk->setEnabled(false);
362 buttonApply->setEnabled(false);
367 SpinBox_X->SetValue(0.0);
368 SpinBox_Y->SetValue(0.0);
369 SpinBox_Z->SetValue(0.0);
370 SpinBox_DX->SetValue(0.0);
371 SpinBox_DY->SetValue(0.0);
372 SpinBox_DZ->SetValue(0.0);
374 SpinBox_Angle->SetValue(45);
376 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
377 CheckBoxMesh->setChecked(false);
378 myPreviewCheckBox->setChecked(false);
379 onDisplaySimulation(false);
381 // MakeGroupsCheck->setChecked(false);
382 // MakeGroupsCheck->setEnabled(false);
383 // onSelectMesh(false);
386 onSelectMesh(CheckBoxMesh->isChecked());
389 //=================================================================================
390 // function : ClickOnApply()
392 //=================================================================================
393 bool SMESHGUI_RotationDlg::ClickOnApply()
395 if (mySMESHGUI->isActiveStudyLocked())
401 if (myNbOkElements && IsAxisOk()) {
402 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
404 SMESH::long_array_var anElementsId = new SMESH::long_array;
406 anElementsId->length(aListElementsId.count());
407 for (int i = 0; i < aListElementsId.count(); i++)
408 anElementsId[i] = aListElementsId[i].toInt();
410 SMESH::AxisStruct anAxis;
412 anAxis.x = SpinBox_X->GetValue();
413 anAxis.y = SpinBox_Y->GetValue();
414 anAxis.z = SpinBox_Z->GetValue();;
415 anAxis.vx = SpinBox_DX->GetValue();
416 anAxis.vy = SpinBox_DY->GetValue();
417 anAxis.vz = SpinBox_DZ->GetValue();
419 double anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
421 QStringList aParameters;
422 aParameters << SpinBox_X->text();
423 aParameters << SpinBox_Y->text();
424 aParameters << SpinBox_Z->text();
425 aParameters << SpinBox_DX->text();
426 aParameters << SpinBox_DY->text();
427 aParameters << SpinBox_DZ->text();
428 aParameters << SpinBox_Angle->text();
430 int actionButton = ActionGroup->checkedId();
431 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
432 QStringList anEntryList;
434 SUIT_OverrideCursor aWaitCursor;
436 switch ( actionButton ) {
437 case MOVE_ELEMS_BUTTON:
438 if(CheckBoxMesh->isChecked()) {
439 for ( int i = 0; i < myObjects.count(); i++ ) {
440 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
441 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
442 aMeshEditor->RotateObject(myObjects[i], anAxis, anAngle, false);
446 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
447 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
448 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
451 case COPY_ELEMS_BUTTON:
453 SMESH::ListOfGroups_var groups;
454 if(CheckBoxMesh->isChecked()) {
455 for ( int i = 0; i < myObjects.count(); i++ ) {
456 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
457 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
458 groups = aMeshEditor->RotateObjectMakeGroups(myObjects[i], anAxis, anAngle);
462 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
463 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
464 groups = aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
468 if(CheckBoxMesh->isChecked()) {
469 for ( int i = 0; i < myObjects.count(); i++ ) {
470 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
471 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
472 aMeshEditor->RotateObject(myObjects[i], anAxis, anAngle, true);
476 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
477 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
478 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
482 case MAKE_MESH_BUTTON: {
483 SMESH::SMESH_Mesh_var mesh;
484 if (CheckBoxMesh->isChecked()) {
485 for ( int i = 0; i < myObjects.count(); i++ ) {
486 QString aName = SMESH::UniqueMeshName( LineEditNewMesh->text().replace( "*", myObjectsNames[i] ) );
487 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
488 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
489 mesh = aMeshEditor->RotateObjectMakeMesh(myObjects[i], anAxis, anAngle, makeGroups,
490 aName.toLatin1().data());
491 if (!mesh->_is_nil()) {
492 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
493 anEntryList.append( aSObject->GetID().c_str() );
498 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
499 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
500 mesh = aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
501 LineEditNewMesh->text().toLatin1().data());
502 if (!mesh->_is_nil()) {
503 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
504 anEntryList.append( aSObject->GetID().c_str() );
513 for ( int i = 0; i < myObjects.count(); i++ ) {
514 SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
515 if ( actor ) SMESH::Update( actor->getIO(), true );
518 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
519 actionButton == MAKE_MESH_BUTTON ) {
520 mySMESHGUI->updateObjBrowser(true); // new groups may appear
521 if( LightApp_Application* anApp =
522 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
523 anApp->browseObjects( anEntryList, isApplyAndClose() );
526 SelectionIntoArgument();
528 SMESHGUI::Modified();
534 //=================================================================================
535 // function : ClickOnOk()
537 //=================================================================================
538 void SMESHGUI_RotationDlg::ClickOnOk()
540 setIsApplyAndClose( true );
545 //=================================================================================
546 // function : reject()
548 //=================================================================================
549 void SMESHGUI_RotationDlg::reject()
551 disconnect(mySelectionMgr, 0, this, 0);
552 mySelectionMgr->clearFilters();
553 //mySelectionMgr->clearSelected();
554 if (SMESH::GetCurrentVtkView()) {
555 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
556 SMESH::SetPointRepresentation(false);
558 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
559 aViewWindow->SetSelectionMode(ActorSelection);
560 mySMESHGUI->ResetState();
564 //=================================================================================
565 // function : ClickOnHelp()
567 //=================================================================================
568 void SMESHGUI_RotationDlg::ClickOnHelp()
570 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
572 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
576 platform = "winapplication";
578 platform = "application";
580 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
581 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
582 arg(app->resourceMgr()->stringValue("ExternalBrowser",
584 arg(myHelpFileName));
588 //=======================================================================
589 // function : onTextChange()
591 //=======================================================================
592 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
594 QLineEdit* send = (QLineEdit*)sender();
599 if (send == LineEditElements)
602 buttonOk->setEnabled(false);
603 buttonApply->setEnabled(false);
605 // hilight entered elements
606 SMDS_Mesh* aMesh = 0;
608 aMesh = myActor->GetObject()->GetMesh();
611 if (send == LineEditElements) {
612 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
614 TColStd_MapOfInteger newIndices;
616 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
617 for (int i = 0; i < aListId.count(); i++) {
618 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
620 newIndices.Add(e->GetID());
624 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
625 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
626 aViewWindow->highlight( anIO, true, true );
628 myElementsId = theNewText;
632 if (myNbOkElements && IsAxisOk()) {
633 buttonOk->setEnabled(true);
634 buttonApply->setEnabled(true);
640 //=================================================================================
641 // function : SelectionIntoArgument()
642 // purpose : Called when selection as changed or other case
643 //=================================================================================
644 void SMESHGUI_RotationDlg::SelectionIntoArgument()
650 QString aString = "";
651 onDisplaySimulation(false);
654 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
655 LineEditElements->setText(aString);
657 buttonOk->setEnabled(false);
658 buttonApply->setEnabled(false);
662 if (!GroupButtons->isEnabled()) // inactive
667 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
669 int nbSel = aList.Extent();
675 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
678 myObjectsNames.clear();
681 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
682 Handle(SALOME_InteractiveObject) IO = it.Value();
683 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
684 if ( aMesh->_is_nil() )
687 myActor = SMESH::FindActorByObject( aMesh );
689 myActor = SMESH::FindActorByEntry( IO->getEntry() );
690 if ( !myActor && !CheckBoxMesh->isChecked() )
693 if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
694 if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
695 _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
696 _PTR(GenericAttribute) anAttr;
697 if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
698 _PTR(AttributeName) aNameAttr( anAttr );
699 myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
700 myObjectsNames << aNameAttr->Value().c_str();
707 // MakeGroups is available if there are groups and "Copy"
709 for ( int i = 0; i < myMeshes.count(); i++ )
710 aNbGroups += myMeshes[i]->NbGroups();
711 if ( aNbGroups == 0 ) {
712 MakeGroupsCheck->setChecked(false);
713 MakeGroupsCheck->setEnabled(false);
715 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
716 MakeGroupsCheck->setEnabled(true);
718 if (CheckBoxMesh->isChecked()) {
719 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
721 if ( myMeshes.isEmpty() )
725 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
729 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
730 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
732 myElementsId += QString(" %1").arg(i);
736 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
738 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
740 // get IDs from submesh
741 SMESH::long_array_var anElementsIds = new SMESH::long_array;
742 anElementsIds = aSubMesh->GetElementsId();
743 for (int i = 0; i < anElementsIds->length(); i++) {
744 myElementsId += QString(" %1").arg(anElementsIds[i]);
746 aNbUnits = anElementsIds->length();
749 SMESH::SMESH_GroupBase_var aGroup =
750 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
751 if (aGroup->_is_nil())
754 // get IDs from smesh group
755 SMESH::long_array_var anElementsIds = new SMESH::long_array;
756 anElementsIds = aGroup->GetListOfID();
757 for (int i = 0; i < anElementsIds->length(); i++) {
758 myElementsId += QString(" %1").arg(anElementsIds[i]);
760 aNbUnits = anElementsIds->length();
764 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
765 myElementsId = aString;
770 myNbOkElements = true;
773 Handle(SALOME_InteractiveObject) IO = aList.First();
774 if ((SMESH::GetMeshByIO(IO))->_is_nil())
777 SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
779 anActor = SMESH::FindActorByEntry(IO->getEntry());
780 if (!anActor && !CheckBoxMesh->isChecked())
783 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
787 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
791 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
799 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
800 SpinBox_X->SetValue(x);
801 SpinBox_Y->SetValue(y);
802 SpinBox_Z->SetValue(z);
803 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
804 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
805 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
806 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
811 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
812 LineEditElements->setText(aString);
813 LineEditElements->repaint();
814 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
815 LineEditElements->setEnabled(true);
821 if (myNbOkElements && IsAxisOk()) {
822 buttonOk->setEnabled(true);
823 buttonApply->setEnabled(true);
825 onDisplaySimulation(true);
828 //=================================================================================
829 // function : SetEditCurrentArgument()
831 //=================================================================================
832 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
834 QPushButton* send = (QPushButton*)sender();
836 disconnect(mySelectionMgr, 0, this, 0);
837 mySelectionMgr->clearSelected();
838 mySelectionMgr->clearFilters();
840 switch (myConstructorId) {
841 case 0: /* default constructor */
843 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
844 if (send == SelectElementsButton) {
845 myEditCurrentArgument = (QWidget*)LineEditElements;
846 SMESH::SetPointRepresentation(false);
847 if (CheckBoxMesh->isChecked()) {
849 aViewWindow->SetSelectionMode(ActorSelection);
850 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
853 aViewWindow->SetSelectionMode( CellSelection );
855 } else if (send == SelectPointButton) {
856 myEditCurrentArgument = (QWidget*)SpinBox_X;
857 SMESH::SetPointRepresentation(true);
859 aViewWindow->SetSelectionMode( NodeSelection );
860 } else if (send == SelectVectorButton) {
861 myEditCurrentArgument = (QWidget*)SpinBox_DX;
862 SMESH::SetPointRepresentation(true);
864 aViewWindow->SetSelectionMode( NodeSelection );
871 myEditCurrentArgument->setFocus();
872 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
873 SelectionIntoArgument();
876 //=================================================================================
877 // function : DeactivateActiveDialog()
879 //=================================================================================
880 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
882 if (GroupConstructors->isEnabled()) {
883 GroupConstructors->setEnabled(false);
884 GroupArguments->setEnabled(false);
885 GroupButtons->setEnabled(false);
886 mySMESHGUI->ResetState();
887 mySMESHGUI->SetActiveDialogBox(0);
891 //=================================================================================
892 // function : ActivateThisDialog()
894 //=================================================================================
895 void SMESHGUI_RotationDlg::ActivateThisDialog()
897 /* Emit a signal to deactivate the active dialog */
898 mySMESHGUI->EmitSignalDeactivateDialog();
899 GroupConstructors->setEnabled(true);
900 GroupArguments->setEnabled(true);
901 GroupButtons->setEnabled(true);
903 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
905 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
906 aViewWindow->SetSelectionMode( CellSelection );
907 SelectionIntoArgument();
910 //=================================================================================
911 // function : enterEvent()
913 //=================================================================================
914 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
916 if (!GroupConstructors->isEnabled())
917 ActivateThisDialog();
920 //=================================================================================
921 // function : onSelectMesh()
923 //=================================================================================
924 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
927 TextLabelElements->setText(tr("SMESH_NAME"));
929 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
930 myFilterBtn->setEnabled(!toSelectMesh);
932 if (myEditCurrentArgument != LineEditElements) {
933 LineEditElements->clear();
937 mySelectionMgr->clearFilters();
938 SMESH::SetPointRepresentation(false);
941 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
942 aViewWindow->SetSelectionMode(ActorSelection);
943 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
944 LineEditElements->setReadOnly(true);
945 LineEditElements->setValidator(0);
947 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
948 aViewWindow->SetSelectionMode( CellSelection );
949 LineEditElements->setReadOnly(false);
950 LineEditElements->setValidator(myIdValidator);
951 onTextChange(LineEditElements->text());
955 SelectionIntoArgument();
958 //=================================================================================
959 // function : IsAxisOk()
961 //=================================================================================
962 bool SMESHGUI_RotationDlg::IsAxisOk()
964 return (SpinBox_DX->GetValue() != 0 ||
965 SpinBox_DY->GetValue() != 0 ||
966 SpinBox_DZ->GetValue() != 0);
969 //=================================================================================
970 // function : onVectorChanged()
972 //=================================================================================
973 void SMESHGUI_RotationDlg::onVectorChanged()
976 buttonOk->setEnabled(true);
977 buttonApply->setEnabled(true);
979 buttonOk->setEnabled(false);
980 buttonApply->setEnabled(false);
985 //=======================================================================
986 //function : onActionClicked
987 //purpose : slot called when an action type changed
988 //=======================================================================
990 void SMESHGUI_RotationDlg::onActionClicked(int button)
993 for ( int i = 0; i < myMeshes.count(); i++ )
994 aNbGroups += myMeshes[i]->NbGroups();
997 case MOVE_ELEMS_BUTTON:
998 MakeGroupsCheck->setEnabled(false);
999 LineEditNewMesh->setEnabled(false);
1001 case COPY_ELEMS_BUTTON:
1002 LineEditNewMesh->setEnabled(false);
1003 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1004 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1006 case MAKE_MESH_BUTTON:
1007 LineEditNewMesh->setEnabled(true);
1008 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1009 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1013 toDisplaySimulation();
1016 //=======================================================================
1017 //function : setNewMeshName
1018 //purpose : update contents of LineEditNewMesh
1019 //=======================================================================
1021 void SMESHGUI_RotationDlg::setNewMeshName()
1023 LineEditNewMesh->setText("");
1024 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1026 if ( CheckBoxMesh->isChecked() ) {
1027 name = myMeshes.count() > 1 ? "*" : LineEditElements->text();
1030 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1031 name = meshSO->GetName().c_str();
1033 if ( !name.isEmpty() )
1034 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
1038 //=================================================================================
1039 // function : keyPressEvent()
1041 //=================================================================================
1042 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
1044 QDialog::keyPressEvent( e );
1045 if ( e->isAccepted() )
1048 if ( e->key() == Qt::Key_F1 ) {
1054 //=================================================================================
1055 // function : setFilters()
1056 // purpose : SLOT. Called when "Filter" button pressed.
1057 //=================================================================================
1058 void SMESHGUI_RotationDlg::setFilters()
1060 if ( myMeshes.isEmpty() ) {
1061 SUIT_MessageBox::critical(this,
1063 tr("NO_MESH_SELECTED"));
1067 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1069 myFilterDlg->SetSelection();
1070 myFilterDlg->SetMesh( myMeshes[0] );
1071 myFilterDlg->SetSourceWg( LineEditElements );
1073 myFilterDlg->show();
1076 //=================================================================================
1077 // function : isValid
1079 //=================================================================================
1080 bool SMESHGUI_RotationDlg::isValid()
1085 ok = SpinBox_X->isValid( msg, true ) && ok;
1086 ok = SpinBox_Y->isValid( msg, true ) && ok;
1087 ok = SpinBox_Z->isValid( msg, true ) && ok;
1088 ok = SpinBox_DX->isValid( msg, true ) && ok;
1089 ok = SpinBox_DY->isValid( msg, true ) && ok;
1090 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1091 ok = SpinBox_Angle->isValid( msg, true ) && ok;
1094 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1095 if ( !msg.isEmpty() )
1097 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1104 //=================================================================================
1105 // function : onDisplaySimulation
1106 // purpose : Show/Hide preview
1107 //=================================================================================
1108 void SMESHGUI_RotationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1109 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1110 if(myNbOkElements && isValid() && IsAxisOk()) {
1111 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1112 SMESH::long_array_var anElementsId = new SMESH::long_array;
1114 anElementsId->length(aListElementsId.count());
1115 for (int i = 0; i < aListElementsId.count(); i++)
1116 anElementsId[i] = aListElementsId[i].toInt();
1118 SMESH::AxisStruct anAxis;
1120 anAxis.x = SpinBox_X->GetValue();
1121 anAxis.y = SpinBox_Y->GetValue();
1122 anAxis.z = SpinBox_Z->GetValue();;
1123 anAxis.vx = SpinBox_DX->GetValue();
1124 anAxis.vy = SpinBox_DY->GetValue();
1125 anAxis.vz = SpinBox_DZ->GetValue();
1126 double anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
1129 SUIT_OverrideCursor aWaitCursor;
1130 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1131 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1132 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1133 if(CheckBoxMesh->isChecked())
1134 for ( int i = 0; i < myObjects.count(); i++ ) {
1135 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1136 aMeshEditor->RotateObject(myObjects[i], anAxis, anAngle, copy);
1137 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1140 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1141 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, copy);
1142 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1144 setSimulationPreview( aMeshPreviewStruct );