1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_ExtrusionDlg.cxx
25 // Author : Michael ZORIN
29 #include "SMESHGUI_ExtrusionDlg.h"
31 #include "SMESHGUI_SpinBox.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESH_Actor.h"
36 #include "SMDS_Mesh.hxx"
41 #include <BRepAdaptor_Curve.hxx>
43 #include "QAD_Application.h"
44 #include "QAD_Desktop.h"
45 #include "QAD_MessageBox.h"
46 #include "utilities.h"
49 #include <qapplication.h>
50 #include <qbuttongroup.h>
51 #include <qgroupbox.h>
53 #include <qlineedit.h>
54 #include <qpushbutton.h>
55 #include <qradiobutton.h>
58 #include <qvalidator.h>
63 //=================================================================================
64 // class : SMESHGUI_ExtrusionDlg()
66 //=================================================================================
67 SMESHGUI_ExtrusionDlg::SMESHGUI_ExtrusionDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
68 bool modal, WFlags fl )
69 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu |
70 Qt::WDestructiveClose)
72 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_EDGE")));
73 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_TRIANGLE")));
74 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
77 setName( "SMESHGUI_ExtrusionDlg" );
79 setCaption( tr( "EXTRUSION_ALONG_LINE" ) );
80 setSizeGripEnabled( TRUE );
81 SMESHGUI_ExtrusionDlgLayout = new QGridLayout( this );
82 SMESHGUI_ExtrusionDlgLayout->setSpacing( 6 );
83 SMESHGUI_ExtrusionDlgLayout->setMargin( 11 );
85 /***************************************************************/
86 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
87 GroupConstructors->setTitle( tr( "SMESH_EXTRUSION" ) );
88 GroupConstructors->setExclusive( TRUE );
89 GroupConstructors->setColumnLayout(0, Qt::Vertical );
90 GroupConstructors->layout()->setSpacing( 0 );
91 GroupConstructors->layout()->setMargin( 0 );
92 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
93 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
94 GroupConstructorsLayout->setSpacing( 6 );
95 GroupConstructorsLayout->setMargin( 11 );
96 RadioButton1= new QRadioButton( GroupConstructors, "RadioButton1" );
97 RadioButton1->setText( tr( "" ) );
98 RadioButton1->setPixmap( image0 );
99 GroupConstructorsLayout->addWidget( RadioButton1, 0, 0 );
100 RadioButton2= new QRadioButton( GroupConstructors, "RadioButton2" );
101 RadioButton2->setText( tr( "" ) );
102 RadioButton2->setPixmap( image1 );
103 GroupConstructorsLayout->addWidget( RadioButton2, 0, 2 );
104 SMESHGUI_ExtrusionDlgLayout->addWidget( GroupConstructors, 0, 0 );
106 /***************************************************************/
107 GroupButtons = new QGroupBox( this, "GroupButtons" );
108 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
109 GroupButtons->setTitle( tr( "" ) );
110 GroupButtons->setColumnLayout(0, Qt::Vertical );
111 GroupButtons->layout()->setSpacing( 0 );
112 GroupButtons->layout()->setMargin( 0 );
113 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
114 GroupButtonsLayout->setAlignment( Qt::AlignTop );
115 GroupButtonsLayout->setSpacing( 6 );
116 GroupButtonsLayout->setMargin( 11 );
117 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
118 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
119 buttonCancel->setAutoDefault( TRUE );
120 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
121 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
122 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
123 buttonApply->setAutoDefault( TRUE );
124 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
125 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
126 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
127 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
128 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
129 buttonOk->setAutoDefault( TRUE );
130 buttonOk->setDefault( TRUE );
131 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
132 SMESHGUI_ExtrusionDlgLayout->addWidget( GroupButtons, 2, 0 );
134 /***************************************************************/
135 GroupArguments = new QGroupBox( this, "GroupArguments" );
136 GroupArguments->setTitle( tr( "EXTRUSION_1D" ) );
137 GroupArguments->setColumnLayout(0, Qt::Vertical );
138 GroupArguments->layout()->setSpacing( 0 );
139 GroupArguments->layout()->setMargin( 0 );
140 GroupArgumentsLayout = new QGridLayout( GroupArguments->layout());
141 GroupArgumentsLayout->setAlignment( Qt::AlignTop );
142 GroupArgumentsLayout->setSpacing( 6 );
143 GroupArgumentsLayout->setMargin( 11 );
145 // Controls for elements selection
146 TextLabelElements = new QLabel( GroupArguments, "TextLabelElements" );
147 TextLabelElements->setText( tr( "SMESH_ID_ELEMENTS" ) );
148 GroupArgumentsLayout->addWidget( TextLabelElements, 0, 0 );
150 SelectElementsButton = new QPushButton( GroupArguments, "SelectElementsButton" );
151 SelectElementsButton->setText( tr( "" ) );
152 SelectElementsButton->setPixmap( image2 );
153 SelectElementsButton->setToggleButton( FALSE );
154 GroupArgumentsLayout->addWidget( SelectElementsButton, 0, 1 );
156 LineEditElements = new QLineEdit( GroupArguments, "LineEditElements" );
157 LineEditElements->setValidator( new SMESHGUI_IdValidator( this, "validator" ));
158 GroupArgumentsLayout->addMultiCellWidget( LineEditElements, 0, 0, 2, 7 );
160 // Controls for vector selection
161 TextLabelVector = new QLabel( GroupArguments, "TextLabelVector" );
162 TextLabelVector->setText( tr( "SMESH_VECTOR" ) );
163 GroupArgumentsLayout->addWidget( TextLabelVector, 1, 0 );
165 TextLabelDx = new QLabel( GroupArguments, "TextLabelDx" );
166 TextLabelDx->setText( tr( "SMESH_DX" ) );
167 GroupArgumentsLayout->addWidget( TextLabelDx, 1, 2 );
169 SpinBox_Dx = new SMESHGUI_SpinBox(GroupArguments, "SpinBox_Dx");
170 GroupArgumentsLayout->addWidget( SpinBox_Dx, 1, 3 );
172 TextLabelDy = new QLabel( GroupArguments, "TextLabelDy" );
173 TextLabelDy->setText( tr( "SMESH_DY" ) );
174 GroupArgumentsLayout->addWidget( TextLabelDy, 1, 4 );
176 SpinBox_Dy = new SMESHGUI_SpinBox(GroupArguments, "SpinBox_Dy");
177 GroupArgumentsLayout->addWidget( SpinBox_Dy, 1, 5 );
179 TextLabelDz = new QLabel( GroupArguments, "TextLabelDz" );
180 TextLabelDz->setText( tr( "SMESH_DZ" ) );
181 GroupArgumentsLayout->addWidget( TextLabelDz, 1, 6 );
183 SpinBox_Dz = new SMESHGUI_SpinBox(GroupArguments, "SpinBox_Dz");
184 GroupArgumentsLayout->addWidget( SpinBox_Dz, 1, 7 );
186 // Controls for nb. steps defining
187 TextLabelNbSteps = new QLabel( GroupArguments, "TextLabelNbSteps" );
188 TextLabelNbSteps->setText( tr( "SMESH_NUMBEROFSTEPS" ) );
189 GroupArgumentsLayout->addMultiCellWidget( TextLabelNbSteps, 2, 2, 0, 1 );
191 SpinBox_NbSteps = new QSpinBox(GroupArguments, "SpinBox_NbSteps");
192 GroupArgumentsLayout->addMultiCellWidget( SpinBox_NbSteps, 2, 2, 2, 7 );
194 SMESHGUI_ExtrusionDlgLayout->addWidget( GroupArguments, 1, 0 );
196 /* Initialisations */
197 SpinBox_Dx->RangeStepAndValidator( -999999.999, +999999.999, 10.0, 3 );
198 SpinBox_Dy->RangeStepAndValidator( -999999.999, +999999.999, 10.0, 3 );
199 SpinBox_Dz->RangeStepAndValidator( -999999.999, +999999.999, 10.0, 3 );
201 QIntValidator* anIntValidator = new QIntValidator(SpinBox_NbSteps);
202 SpinBox_NbSteps->setValidator(anIntValidator);
203 SpinBox_NbSteps->setRange( 1, 999999 );
205 GroupArguments->show();
206 RadioButton1->setChecked( TRUE );
209 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
210 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
213 /* signals and slots connections */
214 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
215 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
216 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
217 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
219 connect( SelectElementsButton, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
220 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
221 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
222 /* to close dialog if study change */
223 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
224 connect( LineEditElements, SIGNAL( textChanged( const QString& )),
225 SLOT( onTextChange( const QString& )));
227 /* Move widget on the botton right corner of main widget */
229 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
231 this->show() ; /* displays Dialog */
233 ConstructorsClicked(0);
236 //=================================================================================
237 // function : ~SMESHGUI_ExtrusionDlg()
238 // purpose : Destroys the object and frees any allocated resources
239 //=================================================================================
240 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
242 // no need to delete child widgets, Qt does it all for us
246 //=================================================================================
249 //=================================================================================
250 void SMESHGUI_ExtrusionDlg::Init()
254 SpinBox_NbSteps->setValue(1);
256 myEditCurrentArgument = LineEditElements;
257 LineEditElements->setFocus();
260 myMesh = SMESH::SMESH_Mesh::_nil();
262 SpinBox_Dx->SetValue(0);
263 SpinBox_Dy->SetValue(0);
264 SpinBox_Dz->SetValue(0);
266 SelectionIntoArgument();
270 //=================================================================================
271 // function : ConstructorsClicked()
272 // purpose : Radio button management
273 //=================================================================================
274 void SMESHGUI_ExtrusionDlg::ConstructorsClicked(int constructorId)
276 disconnect(mySelection, 0, this, 0);
277 mySelection->ClearIObjects();
278 mySelection->ClearFilters();
280 myEditCurrentArgument = LineEditElements;
281 LineEditElements->setText("");
282 LineEditElements->setFocus();
284 switch(constructorId)
288 GroupArguments->setTitle( tr( "EXTRUSION_1D" ) );
289 QAD_Application::getDesktop()->SetSelectionMode( EdgeSelection, true );
294 GroupArguments->setTitle( tr( "EXTRUSION_2D" ) );
295 QAD_Application::getDesktop()->SetSelectionMode( FaceSelection, true );
299 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
303 //=================================================================================
304 // function : ClickOnApply()
306 //=================================================================================
307 void SMESHGUI_ExtrusionDlg::ClickOnApply()
309 if (mySMESHGUI->ActiveStudyLocked())
314 QStringList aListElementsId = QStringList::split( " ", LineEditElements->text(), false);
316 SMESH::long_array_var anElementsId = new SMESH::long_array;
318 anElementsId->length( aListElementsId.count() );
319 for ( int i = 0; i < aListElementsId.count(); i++ )
320 anElementsId[i] = aListElementsId[i].toInt();
322 SMESH::DirStruct aVector;
323 aVector.PS.x = SpinBox_Dx->GetValue();
324 aVector.PS.y = SpinBox_Dy->GetValue();
325 aVector.PS.z = SpinBox_Dz->GetValue();
327 long aNbSteps = (long)SpinBox_NbSteps->value();
331 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
332 QApplication::setOverrideCursor(Qt::waitCursor);
333 aMeshEditor->ExtrusionSweep(anElementsId.inout(), aVector, aNbSteps);
334 QApplication::restoreOverrideCursor();
340 mySelection->ClearIObjects();
346 //=================================================================================
347 // function : ClickOnOk()
349 //=================================================================================
350 void SMESHGUI_ExtrusionDlg::ClickOnOk()
352 this->ClickOnApply() ;
353 this->ClickOnCancel() ;
357 //=================================================================================
358 // function : ClickOnCancel()
360 //=================================================================================
361 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
363 mySelection->ClearFilters();
364 mySelection->ClearIObjects();
365 SMESH::SetPointRepresentation(false);
366 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
367 disconnect( mySelection, 0, this, 0 );
368 mySMESHGUI->ResetState() ;
372 //=======================================================================
373 //function : onTextChange
375 //=======================================================================
376 void SMESHGUI_ExtrusionDlg::onTextChange(const QString& theNewText)
378 QLineEdit* send = (QLineEdit*)sender();
380 if ( myBusy ) return;
383 if (send == LineEditElements)
386 buttonOk->setEnabled( false );
387 buttonApply->setEnabled( false );
389 // hilight entered elements/nodes
390 SMDS_Mesh* aMesh = 0;
392 aMesh = myActor->GetObject()->GetMesh();
396 mySelection->ClearIObjects();
397 mySelection->AddIObject( myActor->getIO() );
399 QStringList aListId = QStringList::split( " ", theNewText, false);
401 if (send == LineEditElements) {
402 for ( int i = 0; i < aListId.count(); i++ ) {
403 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
405 if ( !mySelection->IsIndexSelected( myActor->getIO(), e->GetID() ))
406 mySelection->AddOrRemoveIndex (myActor->getIO(), e->GetID(), true);
413 if ( myNbOkElements ) {
414 buttonOk->setEnabled( true );
415 buttonApply->setEnabled( true );
421 //=================================================================================
422 // function : SelectionIntoArgument()
423 // purpose : Called when selection as changed or other case
424 //=================================================================================
425 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
427 if ( myBusy ) return;
432 QString aString = "";
435 myEditCurrentArgument->setText( aString );
438 if ( !GroupButtons->isEnabled() ) // inactive
441 buttonOk->setEnabled( false );
442 buttonApply->setEnabled( false );
446 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelection, aString);
450 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
452 if (myEditCurrentArgument == LineEditElements)
454 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO) ;
456 myActor = SMESH::FindActorByEntry( mySelection->firstIObject()->getEntry() );
458 // get selected elements
461 aNbElements = SMESH::GetNameOfSelectedElements(mySelection, aString) ;
468 myEditCurrentArgument->setText( aString );
473 if (myEditCurrentArgument == LineEditElements )
474 myNbOkElements = true;
478 buttonOk->setEnabled( true );
479 buttonApply->setEnabled( true );
484 //=================================================================================
485 // function : SetEditCurrentArgument()
487 //=================================================================================
488 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
490 QPushButton* send = (QPushButton*)sender();
491 disconnect( mySelection, 0, this, 0 );
492 mySelection->ClearIObjects();
493 mySelection->ClearFilters();
495 if(send == SelectElementsButton) {
496 myEditCurrentArgument = LineEditElements;
497 int aConstructorId = GetConstructorId();
498 if (aConstructorId == 0)
499 QAD_Application::getDesktop()->SetSelectionMode( EdgeSelection, true );
500 else if (aConstructorId == 1)
501 QAD_Application::getDesktop()->SetSelectionMode( FaceSelection, true );
504 myEditCurrentArgument->setFocus();
505 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
506 SelectionIntoArgument() ;
509 //=================================================================================
510 // function : DeactivateActiveDialog()
512 //=================================================================================
513 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
515 if ( GroupConstructors->isEnabled() ) {
516 GroupConstructors->setEnabled(false) ;
517 GroupArguments->setEnabled(false) ;
518 GroupButtons->setEnabled(false) ;
519 mySMESHGUI->ResetState() ;
520 mySMESHGUI->SetActiveDialogBox(0) ;
526 //=================================================================================
527 // function : ActivateThisDialog()
529 //=================================================================================
530 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
532 /* Emit a signal to deactivate the active dialog */
533 mySMESHGUI->EmitSignalDeactivateDialog() ;
534 GroupConstructors->setEnabled(true) ;
535 GroupArguments->setEnabled(true) ;
536 GroupButtons->setEnabled(true) ;
538 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
540 ConstructorsClicked(GetConstructorId());
541 SelectionIntoArgument();
545 //=================================================================================
546 // function : enterEvent()
548 //=================================================================================
549 void SMESHGUI_ExtrusionDlg::enterEvent(QEvent* e)
551 if ( GroupConstructors->isEnabled() )
553 ActivateThisDialog() ;
558 //=================================================================================
559 // function : closeEvent()
561 //=================================================================================
562 void SMESHGUI_ExtrusionDlg::closeEvent( QCloseEvent* e )
564 /* same than click on cancel button */
565 this->ClickOnCancel() ;
569 //=======================================================================
570 //function : hideEvent
571 //purpose : caused by ESC key
572 //=======================================================================
574 void SMESHGUI_ExtrusionDlg::hideEvent ( QHideEvent * e )
576 if ( !isMinimized() )
581 //=================================================================================
582 // function : GetConstructorId()
584 //=================================================================================
585 int SMESHGUI_ExtrusionDlg::GetConstructorId()
587 if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
588 return GroupConstructors->id( GroupConstructors->selected() );