1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_RotationDlg.cxx
23 // Author : Michael ZORIN, Open CASCADE S.A.S.
26 #include "SMESHGUI_RotationDlg.h"
29 #include "SMESHGUI_SpinBox.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_IdValidator.h"
34 #include "SMESHGUI_FilterDlg.h"
35 #include "SMESHGUI_MeshEditPreview.h"
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_LogicalFilter.hxx>
40 #include <SMDS_Mesh.hxx>
42 // SALOME GUI includes
43 #include <SUIT_Desktop.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_OverrideCursor.h>
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <SALOME_ListIO.hxx>
56 // SALOME KERNEL includes
57 #include <SALOMEDSClient.hxx>
58 #include <SALOMEDSClient_SObject.hxx>
61 #include <TColStd_MapOfInteger.hxx>
64 #include <QApplication>
65 #include <QButtonGroup>
69 #include <QPushButton>
70 #include <QRadioButton>
72 #include <QHBoxLayout>
73 #include <QVBoxLayout>
74 #include <QGridLayout>
78 #include <SALOMEconfig.h>
79 #include CORBA_SERVER_HEADER(SMESH_Group)
80 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
82 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
88 //=================================================================================
89 // class : SMESHGUI_RotationDlg()
91 //=================================================================================
92 SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule ) :
93 SMESHGUI_MultiPreviewDlg( theModule ),
94 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
97 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_ROTATION")));
98 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
101 setAttribute(Qt::WA_DeleteOnClose, true);
102 setWindowTitle(tr("SMESH_ROTATION_TITLE"));
103 setSizeGripEnabled(true);
105 QVBoxLayout* SMESHGUI_RotationDlgLayout = new QVBoxLayout(this);
106 SMESHGUI_RotationDlgLayout->setSpacing(SPACING);
107 SMESHGUI_RotationDlgLayout->setMargin(MARGIN);
109 /***************************************************************/
110 GroupConstructors = new QGroupBox(tr("SMESH_ROTATION"), this);
111 QButtonGroup* ButtonGroup = new QButtonGroup(this);
112 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
113 GroupConstructorsLayout->setSpacing(SPACING);
114 GroupConstructorsLayout->setMargin(MARGIN);
116 RadioButton1= new QRadioButton(GroupConstructors);
117 RadioButton1->setIcon(image0);
119 GroupConstructorsLayout->addWidget(RadioButton1);
120 ButtonGroup->addButton(RadioButton1, 0);
122 /***************************************************************/
123 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
124 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
125 GroupArgumentsLayout->setSpacing(SPACING);
126 GroupArgumentsLayout->setMargin(MARGIN);
128 myIdValidator = new SMESHGUI_IdValidator(this);
130 // Controls for elements selection
131 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
132 SelectElementsButton = new QPushButton(GroupArguments);
133 SelectElementsButton->setIcon(image1);
134 LineEditElements = new QLineEdit(GroupArguments);
135 LineEditElements->setValidator(myIdValidator);
136 LineEditElements->setMaxLength(-1);
137 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
138 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
140 // Control for the whole mesh selection
141 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
143 // Controls for axis defining
144 GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
145 QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
146 GroupAxisLayout->setSpacing(SPACING);
147 GroupAxisLayout->setMargin(MARGIN);
149 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
150 SelectPointButton = new QPushButton(GroupAxis);
151 SelectPointButton->setIcon(image1);
153 TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
154 SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
155 TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
156 SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
157 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
158 SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
160 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
161 SelectVectorButton = new QPushButton(GroupAxis);
162 SelectVectorButton->setIcon(image1);
164 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
165 SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
166 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
167 SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
168 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
169 SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
171 GroupAxisLayout->addWidget(TextLabelPoint, 0, 0);
172 GroupAxisLayout->addWidget(SelectPointButton, 0, 1);
173 GroupAxisLayout->addWidget(TextLabelX, 0, 2);
174 GroupAxisLayout->addWidget(SpinBox_X, 0, 3);
175 GroupAxisLayout->addWidget(TextLabelY, 0, 4);
176 GroupAxisLayout->addWidget(SpinBox_Y, 0, 5);
177 GroupAxisLayout->addWidget(TextLabelZ, 0, 6);
178 GroupAxisLayout->addWidget(SpinBox_Z, 0, 7);
179 GroupAxisLayout->addWidget(TextLabelVector, 1, 0);
180 GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
181 GroupAxisLayout->addWidget(TextLabelDX, 1, 2);
182 GroupAxisLayout->addWidget(SpinBox_DX, 1, 3);
183 GroupAxisLayout->addWidget(TextLabelDY, 1, 4);
184 GroupAxisLayout->addWidget(SpinBox_DY, 1, 5);
185 GroupAxisLayout->addWidget(TextLabelDZ, 1, 6);
186 GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7);
188 // Controls for angle defining
189 TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupArguments);
190 SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments);
193 ActionBox = new QGroupBox(GroupArguments);
194 ActionGroup = new QButtonGroup(GroupArguments);
195 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
196 ActionBoxLayout->setSpacing(SPACING);
197 ActionBoxLayout->setMargin(MARGIN);
199 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
200 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
201 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
203 ActionBoxLayout->addWidget(aMoveElements);
204 ActionBoxLayout->addWidget(aCopyElements);
205 ActionBoxLayout->addWidget(aCreateMesh);
206 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
207 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
208 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
210 // CheckBox for groups generation
211 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
213 // Name of a mesh to create
214 LineEditNewMesh = new QLineEdit(GroupArguments);
218 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
220 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
221 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
222 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
223 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
224 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
225 GroupArgumentsLayout->addWidget(GroupAxis, 2, 0, 1, 4);
226 GroupArgumentsLayout->addWidget(TextLabelAngle, 3, 0, 1, 2);
227 GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
228 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 3);
229 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 3);
230 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 3);
231 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 7, 0);
234 /***************************************************************/
235 GroupButtons = new QGroupBox(this);
236 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
237 GroupButtonsLayout->setSpacing(SPACING);
238 GroupButtonsLayout->setMargin(MARGIN);
240 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
241 buttonOk->setAutoDefault(true);
242 buttonOk->setDefault(true);
243 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
244 buttonApply->setAutoDefault(true);
245 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
246 buttonCancel->setAutoDefault(true);
247 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
248 buttonHelp->setAutoDefault(true);
250 GroupButtonsLayout->addWidget(buttonOk);
251 GroupButtonsLayout->addSpacing(10);
252 GroupButtonsLayout->addWidget(buttonApply);
253 GroupButtonsLayout->addSpacing(10);
254 GroupButtonsLayout->addStretch();
255 GroupButtonsLayout->addWidget(buttonCancel);
256 GroupButtonsLayout->addWidget(buttonHelp);
258 /***************************************************************/
259 SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors);
260 SMESHGUI_RotationDlgLayout->addWidget(GroupArguments);
261 SMESHGUI_RotationDlgLayout->addWidget(GroupButtons);
263 /* Initialisations */
264 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
265 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
266 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
267 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
268 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
269 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
271 SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, "angle_precision");
274 RadioButton1->setChecked(true);
276 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
278 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
280 // Costruction of the logical filter
281 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
282 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::GROUP);
284 QList<SUIT_SelectionFilter*> aListOfFilters;
285 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
286 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
288 myMeshOrSubMeshOrGroupFilter =
289 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
291 myHelpFileName = "rotation_page.html";
295 /* signals and slots connections */
296 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
297 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
298 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
299 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
301 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
302 connect(SelectPointButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
303 connect(SelectVectorButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
305 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
306 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
307 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
309 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
310 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
311 /* to close dialog if study change */
312 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
313 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
314 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
315 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
317 connect(SpinBox_X, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
318 connect(SpinBox_Y, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
319 connect(SpinBox_Z, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
320 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
321 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
322 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
323 connect(SpinBox_Angle, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
325 //To Connect preview check box
326 connectPreviewControl();
328 onActionClicked(MOVE_ELEMS_BUTTON);
331 //=================================================================================
332 // function : ~SMESHGUI_RotationDlg()
333 // purpose : Destroys the object and frees any allocated resources
334 //=================================================================================
335 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
338 myFilterDlg->setParent( 0 );
344 //=================================================================================
347 //=================================================================================
348 void SMESHGUI_RotationDlg::Init (bool ResetControls)
353 myObjectsNames.clear();
355 myEditCurrentArgument = (QWidget*)LineEditElements;
356 LineEditElements->setFocus();
360 buttonOk->setEnabled(false);
361 buttonApply->setEnabled(false);
366 SpinBox_X->SetValue(0.0);
367 SpinBox_Y->SetValue(0.0);
368 SpinBox_Z->SetValue(0.0);
369 SpinBox_DX->SetValue(0.0);
370 SpinBox_DY->SetValue(0.0);
371 SpinBox_DZ->SetValue(0.0);
373 SpinBox_Angle->SetValue(45);
375 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
376 CheckBoxMesh->setChecked(false);
377 myPreviewCheckBox->setChecked(false);
378 onDisplaySimulation(false);
380 // MakeGroupsCheck->setChecked(false);
381 // MakeGroupsCheck->setEnabled(false);
382 // onSelectMesh(false);
385 onSelectMesh(CheckBoxMesh->isChecked());
388 //=================================================================================
389 // function : ClickOnApply()
391 //=================================================================================
392 bool SMESHGUI_RotationDlg::ClickOnApply()
394 if (mySMESHGUI->isActiveStudyLocked())
400 if (myNbOkElements && IsAxisOk()) {
401 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
403 SMESH::long_array_var anElementsId = new SMESH::long_array;
405 anElementsId->length(aListElementsId.count());
406 for (int i = 0; i < aListElementsId.count(); i++)
407 anElementsId[i] = aListElementsId[i].toInt();
409 SMESH::AxisStruct anAxis;
411 anAxis.x = SpinBox_X->GetValue();
412 anAxis.y = SpinBox_Y->GetValue();
413 anAxis.z = SpinBox_Z->GetValue();;
414 anAxis.vx = SpinBox_DX->GetValue();
415 anAxis.vy = SpinBox_DY->GetValue();
416 anAxis.vz = SpinBox_DZ->GetValue();
418 double anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
420 QStringList aParameters;
421 aParameters << SpinBox_X->text();
422 aParameters << SpinBox_Y->text();
423 aParameters << SpinBox_Z->text();
424 aParameters << SpinBox_DX->text();
425 aParameters << SpinBox_DY->text();
426 aParameters << SpinBox_DZ->text();
427 aParameters << SpinBox_Angle->text();
429 int actionButton = ActionGroup->checkedId();
430 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
431 QStringList anEntryList;
433 SUIT_OverrideCursor aWaitCursor;
435 switch ( actionButton ) {
436 case MOVE_ELEMS_BUTTON:
437 if(CheckBoxMesh->isChecked()) {
438 for ( int i = 0; i < myObjects.count(); i++ ) {
439 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
440 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
441 aMeshEditor->RotateObject(myObjects[i], anAxis, anAngle, false);
445 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
446 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
447 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
450 case COPY_ELEMS_BUTTON:
452 SMESH::ListOfGroups_var groups;
453 if(CheckBoxMesh->isChecked()) {
454 for ( int i = 0; i < myObjects.count(); i++ ) {
455 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
456 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
457 groups = aMeshEditor->RotateObjectMakeGroups(myObjects[i], anAxis, anAngle);
461 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
462 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
463 groups = aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
467 if(CheckBoxMesh->isChecked()) {
468 for ( int i = 0; i < myObjects.count(); i++ ) {
469 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
470 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
471 aMeshEditor->RotateObject(myObjects[i], anAxis, anAngle, true);
475 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
476 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
477 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
481 case MAKE_MESH_BUTTON: {
482 SMESH::SMESH_Mesh_var mesh;
483 if (CheckBoxMesh->isChecked()) {
484 for ( int i = 0; i < myObjects.count(); i++ ) {
485 QString aName = SMESH::UniqueMeshName( LineEditNewMesh->text().replace( "*", myObjectsNames[i] ) );
486 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
487 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
488 mesh = aMeshEditor->RotateObjectMakeMesh(myObjects[i], anAxis, anAngle, makeGroups,
489 aName.toLatin1().data());
490 if (!mesh->_is_nil()) {
491 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
492 anEntryList.append( aSObject->GetID().c_str() );
497 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
498 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
499 mesh = aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
500 LineEditNewMesh->text().toLatin1().data());
501 if (!mesh->_is_nil()) {
502 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
503 anEntryList.append( aSObject->GetID().c_str() );
512 for ( int i = 0; i < myObjects.count(); i++ ) {
513 SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
514 if ( actor ) SMESH::Update( actor->getIO(), true );
517 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
518 actionButton == MAKE_MESH_BUTTON ) {
519 mySMESHGUI->updateObjBrowser(true); // new groups may appear
520 if( LightApp_Application* anApp =
521 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
522 anApp->browseObjects( anEntryList, isApplyAndClose() );
525 SelectionIntoArgument();
527 SMESHGUI::Modified();
533 //=================================================================================
534 // function : ClickOnOk()
536 //=================================================================================
537 void SMESHGUI_RotationDlg::ClickOnOk()
539 setIsApplyAndClose( true );
544 //=================================================================================
545 // function : reject()
547 //=================================================================================
548 void SMESHGUI_RotationDlg::reject()
550 disconnect(mySelectionMgr, 0, this, 0);
551 mySelectionMgr->clearFilters();
552 //mySelectionMgr->clearSelected();
553 if (SMESH::GetCurrentVtkView()) {
554 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
555 SMESH::SetPointRepresentation(false);
557 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
558 aViewWindow->SetSelectionMode(ActorSelection);
559 mySMESHGUI->ResetState();
563 //=================================================================================
564 // function : ClickOnHelp()
566 //=================================================================================
567 void SMESHGUI_RotationDlg::ClickOnHelp()
569 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
571 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
575 platform = "winapplication";
577 platform = "application";
579 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
580 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
581 arg(app->resourceMgr()->stringValue("ExternalBrowser",
583 arg(myHelpFileName));
587 //=======================================================================
588 // function : onTextChange()
590 //=======================================================================
591 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
593 QLineEdit* send = (QLineEdit*)sender();
598 if (send == LineEditElements)
601 buttonOk->setEnabled(false);
602 buttonApply->setEnabled(false);
604 // hilight entered elements
605 SMDS_Mesh* aMesh = 0;
607 aMesh = myActor->GetObject()->GetMesh();
610 if (send == LineEditElements) {
611 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
613 TColStd_MapOfInteger newIndices;
615 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
616 for (int i = 0; i < aListId.count(); i++) {
617 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
619 newIndices.Add(e->GetID());
623 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
624 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
625 aViewWindow->highlight( anIO, true, true );
627 myElementsId = theNewText;
631 if (myNbOkElements && IsAxisOk()) {
632 buttonOk->setEnabled(true);
633 buttonApply->setEnabled(true);
639 //=================================================================================
640 // function : SelectionIntoArgument()
641 // purpose : Called when selection as changed or other case
642 //=================================================================================
643 void SMESHGUI_RotationDlg::SelectionIntoArgument()
649 QString aString = "";
650 onDisplaySimulation(false);
653 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
654 LineEditElements->setText(aString);
656 buttonOk->setEnabled(false);
657 buttonApply->setEnabled(false);
661 if (!GroupButtons->isEnabled()) // inactive
666 mySelectionMgr->selectedObjects(aList);
668 int nbSel = aList.Extent();
674 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
677 myObjectsNames.clear();
680 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
681 Handle(SALOME_InteractiveObject) IO = it.Value();
682 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
683 if ( aMesh->_is_nil() )
686 myActor = SMESH::FindActorByObject( aMesh );
688 myActor = SMESH::FindActorByEntry( IO->getEntry() );
689 if ( !myActor && !CheckBoxMesh->isChecked() )
692 if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
693 if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
694 _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
695 _PTR(GenericAttribute) anAttr;
696 if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
697 _PTR(AttributeName) aNameAttr( anAttr );
698 myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
699 myObjectsNames << aNameAttr->Value().c_str();
706 // MakeGroups is available if there are groups and "Copy"
708 for ( int i = 0; i < myMeshes.count(); i++ )
709 aNbGroups += myMeshes[i]->NbGroups();
710 if ( aNbGroups == 0 ) {
711 MakeGroupsCheck->setChecked(false);
712 MakeGroupsCheck->setEnabled(false);
714 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
715 MakeGroupsCheck->setEnabled(true);
717 if (CheckBoxMesh->isChecked()) {
718 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
720 if ( myMeshes.isEmpty() )
724 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
728 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
729 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
731 myElementsId += QString(" %1").arg(i);
735 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
737 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
739 // get IDs from submesh
740 SMESH::long_array_var anElementsIds = new SMESH::long_array;
741 anElementsIds = aSubMesh->GetElementsId();
742 for (int i = 0; i < anElementsIds->length(); i++) {
743 myElementsId += QString(" %1").arg(anElementsIds[i]);
745 aNbUnits = anElementsIds->length();
748 SMESH::SMESH_GroupBase_var aGroup =
749 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
750 if (aGroup->_is_nil())
753 // get IDs from smesh group
754 SMESH::long_array_var anElementsIds = new SMESH::long_array;
755 anElementsIds = aGroup->GetListOfID();
756 for (int i = 0; i < anElementsIds->length(); i++) {
757 myElementsId += QString(" %1").arg(anElementsIds[i]);
759 aNbUnits = anElementsIds->length();
763 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
764 myElementsId = aString;
769 myNbOkElements = true;
772 Handle(SALOME_InteractiveObject) IO = aList.First();
773 if ((SMESH::GetMeshByIO(IO))->_is_nil())
776 SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
778 anActor = SMESH::FindActorByEntry(IO->getEntry());
779 if (!anActor && !CheckBoxMesh->isChecked())
782 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
786 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
790 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
798 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
799 SpinBox_X->SetValue(x);
800 SpinBox_Y->SetValue(y);
801 SpinBox_Z->SetValue(z);
802 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
803 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
804 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
805 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
810 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
811 LineEditElements->setText(aString);
812 LineEditElements->repaint();
813 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
814 LineEditElements->setEnabled(true);
820 if (myNbOkElements && IsAxisOk()) {
821 buttonOk->setEnabled(true);
822 buttonApply->setEnabled(true);
824 onDisplaySimulation(true);
827 //=================================================================================
828 // function : SetEditCurrentArgument()
830 //=================================================================================
831 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
833 QPushButton* send = (QPushButton*)sender();
835 disconnect(mySelectionMgr, 0, this, 0);
836 mySelectionMgr->clearSelected();
837 mySelectionMgr->clearFilters();
839 switch (myConstructorId) {
840 case 0: /* default constructor */
842 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
843 if (send == SelectElementsButton) {
844 myEditCurrentArgument = (QWidget*)LineEditElements;
845 SMESH::SetPointRepresentation(false);
846 if (CheckBoxMesh->isChecked()) {
848 aViewWindow->SetSelectionMode(ActorSelection);
849 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
852 aViewWindow->SetSelectionMode( CellSelection );
854 } else if (send == SelectPointButton) {
855 myEditCurrentArgument = (QWidget*)SpinBox_X;
856 SMESH::SetPointRepresentation(true);
858 aViewWindow->SetSelectionMode( NodeSelection );
859 } else if (send == SelectVectorButton) {
860 myEditCurrentArgument = (QWidget*)SpinBox_DX;
861 SMESH::SetPointRepresentation(true);
863 aViewWindow->SetSelectionMode( NodeSelection );
870 myEditCurrentArgument->setFocus();
871 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
872 SelectionIntoArgument();
875 //=================================================================================
876 // function : DeactivateActiveDialog()
878 //=================================================================================
879 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
881 if (GroupConstructors->isEnabled()) {
882 GroupConstructors->setEnabled(false);
883 GroupArguments->setEnabled(false);
884 GroupButtons->setEnabled(false);
885 mySMESHGUI->ResetState();
886 mySMESHGUI->SetActiveDialogBox(0);
890 //=================================================================================
891 // function : ActivateThisDialog()
893 //=================================================================================
894 void SMESHGUI_RotationDlg::ActivateThisDialog()
896 /* Emit a signal to deactivate the active dialog */
897 mySMESHGUI->EmitSignalDeactivateDialog();
898 GroupConstructors->setEnabled(true);
899 GroupArguments->setEnabled(true);
900 GroupButtons->setEnabled(true);
902 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
904 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
905 aViewWindow->SetSelectionMode( CellSelection );
906 SelectionIntoArgument();
909 //=================================================================================
910 // function : enterEvent()
912 //=================================================================================
913 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
915 if (!GroupConstructors->isEnabled())
916 ActivateThisDialog();
919 //=================================================================================
920 // function : onSelectMesh()
922 //=================================================================================
923 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
926 TextLabelElements->setText(tr("SMESH_NAME"));
928 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
929 myFilterBtn->setEnabled(!toSelectMesh);
931 if (myEditCurrentArgument != LineEditElements) {
932 LineEditElements->clear();
936 mySelectionMgr->clearFilters();
937 SMESH::SetPointRepresentation(false);
940 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
941 aViewWindow->SetSelectionMode(ActorSelection);
942 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
943 LineEditElements->setReadOnly(true);
944 LineEditElements->setValidator(0);
946 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
947 aViewWindow->SetSelectionMode( CellSelection );
948 LineEditElements->setReadOnly(false);
949 LineEditElements->setValidator(myIdValidator);
950 onTextChange(LineEditElements->text());
954 SelectionIntoArgument();
957 //=================================================================================
958 // function : IsAxisOk()
960 //=================================================================================
961 bool SMESHGUI_RotationDlg::IsAxisOk()
963 return (SpinBox_DX->GetValue() != 0 ||
964 SpinBox_DY->GetValue() != 0 ||
965 SpinBox_DZ->GetValue() != 0);
968 //=================================================================================
969 // function : onVectorChanged()
971 //=================================================================================
972 void SMESHGUI_RotationDlg::onVectorChanged()
975 buttonOk->setEnabled(true);
976 buttonApply->setEnabled(true);
978 buttonOk->setEnabled(false);
979 buttonApply->setEnabled(false);
984 //=======================================================================
985 //function : onActionClicked
986 //purpose : slot called when an action type changed
987 //=======================================================================
989 void SMESHGUI_RotationDlg::onActionClicked(int button)
992 for ( int i = 0; i < myMeshes.count(); i++ )
993 aNbGroups += myMeshes[i]->NbGroups();
996 case MOVE_ELEMS_BUTTON:
997 MakeGroupsCheck->setEnabled(false);
998 LineEditNewMesh->setEnabled(false);
1000 case COPY_ELEMS_BUTTON:
1001 LineEditNewMesh->setEnabled(false);
1002 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1003 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1005 case MAKE_MESH_BUTTON:
1006 LineEditNewMesh->setEnabled(true);
1007 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1008 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1012 toDisplaySimulation();
1015 //=======================================================================
1016 //function : setNewMeshName
1017 //purpose : update contents of LineEditNewMesh
1018 //=======================================================================
1020 void SMESHGUI_RotationDlg::setNewMeshName()
1022 LineEditNewMesh->setText("");
1023 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1025 if ( CheckBoxMesh->isChecked() ) {
1026 name = myMeshes.count() > 1 ? "*" : LineEditElements->text();
1029 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1030 name = meshSO->GetName().c_str();
1032 if ( !name.isEmpty() )
1033 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
1037 //=================================================================================
1038 // function : keyPressEvent()
1040 //=================================================================================
1041 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
1043 QDialog::keyPressEvent( e );
1044 if ( e->isAccepted() )
1047 if ( e->key() == Qt::Key_F1 ) {
1053 //=================================================================================
1054 // function : setFilters()
1055 // purpose : SLOT. Called when "Filter" button pressed.
1056 //=================================================================================
1057 void SMESHGUI_RotationDlg::setFilters()
1059 if ( myMeshes.isEmpty() ) {
1060 SUIT_MessageBox::critical(this,
1062 tr("NO_MESH_SELECTED"));
1066 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1068 myFilterDlg->SetSelection();
1069 myFilterDlg->SetMesh( myMeshes[0] );
1070 myFilterDlg->SetSourceWg( LineEditElements );
1072 myFilterDlg->show();
1075 //=================================================================================
1076 // function : isValid
1078 //=================================================================================
1079 bool SMESHGUI_RotationDlg::isValid()
1084 ok = SpinBox_X->isValid( msg, true ) && ok;
1085 ok = SpinBox_Y->isValid( msg, true ) && ok;
1086 ok = SpinBox_Z->isValid( msg, true ) && ok;
1087 ok = SpinBox_DX->isValid( msg, true ) && ok;
1088 ok = SpinBox_DY->isValid( msg, true ) && ok;
1089 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1090 ok = SpinBox_Angle->isValid( msg, true ) && ok;
1093 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1094 if ( !msg.isEmpty() )
1096 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1103 //=================================================================================
1104 // function : onDisplaySimulation
1105 // purpose : Show/Hide preview
1106 //=================================================================================
1107 void SMESHGUI_RotationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1108 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1109 if(myNbOkElements && isValid() && IsAxisOk()) {
1110 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1111 SMESH::long_array_var anElementsId = new SMESH::long_array;
1113 anElementsId->length(aListElementsId.count());
1114 for (int i = 0; i < aListElementsId.count(); i++)
1115 anElementsId[i] = aListElementsId[i].toInt();
1117 SMESH::AxisStruct anAxis;
1119 anAxis.x = SpinBox_X->GetValue();
1120 anAxis.y = SpinBox_Y->GetValue();
1121 anAxis.z = SpinBox_Z->GetValue();;
1122 anAxis.vx = SpinBox_DX->GetValue();
1123 anAxis.vy = SpinBox_DY->GetValue();
1124 anAxis.vz = SpinBox_DZ->GetValue();
1125 double anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
1128 SUIT_OverrideCursor aWaitCursor;
1129 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1130 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1131 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1132 if(CheckBoxMesh->isChecked())
1133 for ( int i = 0; i < myObjects.count(); i++ ) {
1134 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1135 aMeshEditor->RotateObject(myObjects[i], anAxis, anAngle, copy);
1136 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1139 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1140 aMeshEditor->Rotate(anElementsId, anAxis, anAngle, copy);
1141 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1143 setSimulationPreview( aMeshPreviewStruct );