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_ExtrusionAlongPathDlg.cxx
25 // Author : Vadim SANDLER
29 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
31 #include "SMESHGUI_SpinBox.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_IdValidator.h"
36 #include "SMESH_Actor.h"
37 #include "SMESH_NumberFilter.hxx"
38 #include "SMDS_Mesh.hxx"
39 #include "GEOM_ShapeTypeFilter.hxx"
42 #include "QAD_Application.h"
43 #include "QAD_WaitCursor.h"
44 #include "QAD_Desktop.h"
45 #include "QAD_MessageBox.h"
46 #include "utilities.h"
48 #include <BRep_Tool.hxx>
49 #include <TopoDS_Shape.hxx>
51 #include <TopoDS_Vertex.hxx>
55 #include <qapplication.h>
56 #include <qbuttongroup.h>
57 #include <qgroupbox.h>
59 #include <qlineedit.h>
60 #include <qpushbutton.h>
61 #include <qtoolbutton.h>
62 #include <qradiobutton.h>
63 #include <qcheckbox.h>
66 #include <qvalidator.h>
70 #include "SALOMEconfig.h"
71 #include CORBA_SERVER_HEADER(SMESH_Group)
75 //=================================================================================
76 // function : SMESHGUI_ExtrusionAlongPathDlg::SMESHGUI_ExtrusionAlongPathDlg()
77 // purpose : constructor
78 //=================================================================================
79 SMESHGUI_ExtrusionAlongPathDlg::SMESHGUI_ExtrusionAlongPathDlg( QWidget* parent, SALOME_Selection* Sel, bool modal )
80 : QDialog( parent, "SMESHGUI_ExtrusionAlongPathDlg", modal,
81 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose )
83 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::SMESHGUI_ExtrusionAlongPathDlg");
85 QPixmap edgeImage ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_DLG_EDGE" ) ) );
86 QPixmap faceImage ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_DLG_TRIANGLE" ) ) );
87 QPixmap selectImage( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
88 QPixmap addImage ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_APPEND" ) ) );
89 QPixmap removeImage( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_REMOVE" ) ) );
91 setCaption( tr( "EXTRUSION_ALONG_PATH" ) );
92 setSizeGripEnabled( TRUE );
94 QGridLayout* topLayout = new QGridLayout( this );
95 topLayout->setSpacing( 6 ); topLayout->setMargin( 11 );
97 /***************************************************************/
98 // Elements type group box (1d / 2d elements)
99 ElementsTypeGrp = new QButtonGroup( tr( "SMESH_EXTRUSION" ), this );
100 ElementsTypeGrp->setColumnLayout( 0, Qt::Vertical );
101 ElementsTypeGrp->layout()->setSpacing( 0 ); ElementsTypeGrp->layout()->setMargin( 0 );
102 QGridLayout* ElementsTypeGrpLayout = new QGridLayout( ElementsTypeGrp->layout() );
103 ElementsTypeGrpLayout->setAlignment( Qt::AlignTop );
104 ElementsTypeGrpLayout->setSpacing( 6 ); ElementsTypeGrpLayout->setMargin( 11 );
106 Elements1dRB = new QRadioButton( ElementsTypeGrp );
107 Elements1dRB->setPixmap( edgeImage );
108 Elements2dRB = new QRadioButton( ElementsTypeGrp );
109 Elements2dRB->setPixmap( faceImage );
110 Elements1dRB->setChecked( true );
113 ElementsTypeGrpLayout->addWidget( Elements1dRB, 0, 0 );
114 ElementsTypeGrpLayout->addWidget( Elements2dRB, 0, 2 );
116 /***************************************************************/
117 // Arguments group box
118 ArgumentsGrp = new QGroupBox( tr( "EXTRUSION_1D" ), this );
119 ArgumentsGrp->setColumnLayout( 0, Qt::Vertical );
120 ArgumentsGrp->layout()->setSpacing( 0 ); ArgumentsGrp->layout()->setMargin( 0 );
121 QGridLayout* ArgumentsGrpLayout = new QGridLayout( ArgumentsGrp->layout() );
122 ArgumentsGrpLayout->setAlignment( Qt::AlignTop );
123 ArgumentsGrpLayout->setSpacing( 6 ); ArgumentsGrpLayout->setMargin( 11 );
125 // Controls for elements selection
126 ElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), ArgumentsGrp );
128 SelectElementsButton = new QToolButton( ArgumentsGrp );
129 SelectElementsButton->setPixmap( selectImage );
131 ElementsLineEdit = new QLineEdit( ArgumentsGrp );
132 ElementsLineEdit->setValidator( new SMESHGUI_IdValidator( this ) );
134 // Controls for the whole mesh selection
135 MeshCheck = new QCheckBox( tr( "SMESH_SELECT_WHOLE_MESH" ), ArgumentsGrp );
137 // Controls for path selection
138 PathGrp = new QGroupBox( tr( "SMESH_PATH" ), ArgumentsGrp );
139 PathGrp->setColumnLayout( 0, Qt::Vertical );
140 PathGrp->layout()->setSpacing( 0 ); PathGrp->layout()->setMargin( 0 );
141 QGridLayout* PathGrpLayout = new QGridLayout( PathGrp->layout() );
142 PathGrpLayout->setAlignment( Qt::AlignTop );
143 PathGrpLayout->setSpacing( 6 ); PathGrpLayout->setMargin( 11 );
145 // Controls for path mesh selection
146 PathMeshLab = new QLabel( tr( "SMESH_PATH_MESH" ), PathGrp );
148 SelectPathMeshButton = new QToolButton( PathGrp );
149 SelectPathMeshButton->setPixmap( selectImage );
151 PathMeshLineEdit = new QLineEdit( PathGrp );
152 PathMeshLineEdit->setReadOnly( true );
154 // Controls for path shape selection
155 PathShapeLab = new QLabel( tr( "SMESH_PATH_SHAPE" ), PathGrp );
157 SelectPathShapeButton = new QToolButton( PathGrp );
158 SelectPathShapeButton->setPixmap( selectImage );
160 PathShapeLineEdit = new QLineEdit( PathGrp );
161 PathShapeLineEdit->setReadOnly( true );
163 // Controls for path starting point selection
164 StartPointLab = new QLabel( tr( "SMESH_PATH_START" ), PathGrp );
166 SelectStartPointButton = new QToolButton( PathGrp );
167 SelectStartPointButton->setPixmap( selectImage );
169 StartPointLineEdit = new QLineEdit( PathGrp );
170 StartPointLineEdit->setValidator( new QIntValidator( this ) );
173 PathGrpLayout->addWidget( PathMeshLab, 0, 0 );
174 PathGrpLayout->addWidget( SelectPathMeshButton, 0, 1 );
175 PathGrpLayout->addWidget( PathMeshLineEdit, 0, 2 );
176 PathGrpLayout->addWidget( PathShapeLab, 1, 0 );
177 PathGrpLayout->addWidget( SelectPathShapeButton, 1, 1 );
178 PathGrpLayout->addWidget( PathShapeLineEdit, 1, 2 );
179 PathGrpLayout->addWidget( StartPointLab, 2, 0 );
180 PathGrpLayout->addWidget( SelectStartPointButton, 2, 1 );
181 PathGrpLayout->addWidget( StartPointLineEdit, 2, 2 );
183 // Controls for angles defining
184 AnglesCheck = new QCheckBox( tr( "SMESH_USE_ANGLES" ), ArgumentsGrp );
186 AnglesGrp = new QGroupBox( tr( "SMESH_ANGLES" ), ArgumentsGrp );
187 AnglesGrp->setColumnLayout( 0, Qt::Vertical );
188 AnglesGrp->layout()->setSpacing( 0 ); AnglesGrp->layout()->setMargin( 0 );
189 QGridLayout* AnglesGrpLayout = new QGridLayout( AnglesGrp->layout() );
190 AnglesGrpLayout->setAlignment( Qt::AlignTop );
191 AnglesGrpLayout->setSpacing( 6 ); AnglesGrpLayout->setMargin( 11 );
193 AnglesList = new QListBox( AnglesGrp );
194 AnglesList->setSelectionMode( QListBox::Extended );
196 AddAngleButton = new QToolButton( AnglesGrp );
197 AddAngleButton->setPixmap( addImage );
199 RemoveAngleButton = new QToolButton( AnglesGrp );
200 RemoveAngleButton->setPixmap( removeImage );
202 AngleSpin = new SMESHGUI_SpinBox( AnglesGrp );
205 QVBoxLayout* bLayout = new QVBoxLayout();
206 bLayout->addWidget( AddAngleButton );
207 bLayout->addSpacing( 6 );
208 bLayout->addWidget( RemoveAngleButton );
209 bLayout->addStretch();
210 AnglesGrpLayout->addMultiCellWidget( AnglesList, 0, 1, 0, 0 );
211 AnglesGrpLayout->addMultiCellLayout( bLayout, 0, 1, 1, 1 );
212 AnglesGrpLayout->addWidget( AngleSpin, 0, 2 );
213 AnglesGrpLayout->setRowStretch( 1, 10 );
215 // Controls for base point defining
216 BasePointCheck = new QCheckBox( tr( "SMESH_USE_BASE_POINT" ), ArgumentsGrp );
218 BasePointGrp = new QGroupBox( tr( "SMESH_BASE_POINT" ), ArgumentsGrp );
219 BasePointGrp->setColumnLayout( 0, Qt::Vertical );
220 BasePointGrp->layout()->setSpacing( 0 ); BasePointGrp->layout()->setMargin( 0 );
221 QGridLayout* BasePointGrpLayout = new QGridLayout( BasePointGrp->layout() );
222 BasePointGrpLayout->setAlignment( Qt::AlignTop );
223 BasePointGrpLayout->setSpacing( 6 ); BasePointGrpLayout->setMargin( 11 );
225 SelectBasePointButton = new QToolButton( BasePointGrp );
226 SelectBasePointButton->setPixmap( selectImage );
228 XLab = new QLabel( tr( "SMESH_X" ), BasePointGrp );
229 XSpin = new SMESHGUI_SpinBox( BasePointGrp );
230 YLab = new QLabel( tr( "SMESH_Y" ), BasePointGrp );
231 YSpin = new SMESHGUI_SpinBox( BasePointGrp );
232 ZLab = new QLabel( tr( "SMESH_Z" ), BasePointGrp );
233 ZSpin = new SMESHGUI_SpinBox( BasePointGrp );
236 BasePointGrpLayout->addWidget( SelectBasePointButton, 0, 0 );
237 BasePointGrpLayout->addWidget( XLab, 0, 1 );
238 BasePointGrpLayout->addWidget( XSpin, 0, 2 );
239 BasePointGrpLayout->addWidget( YLab, 0, 3 );
240 BasePointGrpLayout->addWidget( YSpin, 0, 4 );
241 BasePointGrpLayout->addWidget( ZLab, 0, 5 );
242 BasePointGrpLayout->addWidget( ZSpin, 0, 6 );
245 ArgumentsGrpLayout->addWidget( ElementsLab, 0, 0 );
246 ArgumentsGrpLayout->addWidget( SelectElementsButton, 0, 1 );
247 ArgumentsGrpLayout->addWidget( ElementsLineEdit, 0, 2 );
248 ArgumentsGrpLayout->addMultiCellWidget( MeshCheck, 1, 1, 0, 2 );
249 ArgumentsGrpLayout->addMultiCellWidget( PathGrp, 2, 2, 0, 2 );
250 ArgumentsGrpLayout->addWidget( AnglesCheck, 3, 0 );
251 ArgumentsGrpLayout->addMultiCellWidget( AnglesGrp, 3, 4, 1, 2 );
252 ArgumentsGrpLayout->addWidget( BasePointCheck, 5, 0 );
253 ArgumentsGrpLayout->addMultiCellWidget( BasePointGrp, 5, 6, 1, 2 );
254 ArgumentsGrpLayout->setRowStretch( 4, 10 );
256 /***************************************************************/
257 // common buttons group box
258 ButtonsGrp = new QGroupBox( this );
259 ButtonsGrp->setColumnLayout( 0, Qt::Vertical );
260 ButtonsGrp->layout()->setSpacing( 0 ); ButtonsGrp->layout()->setMargin( 0 );
261 QGridLayout* ButtonsGrpLayout = new QGridLayout( ButtonsGrp->layout() );
262 ButtonsGrpLayout->setAlignment( Qt::AlignTop );
263 ButtonsGrpLayout->setSpacing( 6 ); ButtonsGrpLayout->setMargin( 11 );
265 OkButton = new QPushButton( tr( "SMESH_BUT_OK" ), ButtonsGrp );
266 OkButton->setAutoDefault( true );
267 OkButton->setDefault( true );
269 ApplyButton = new QPushButton( tr( "SMESH_BUT_APPLY" ), ButtonsGrp );
270 ApplyButton->setAutoDefault( true );
272 CloseButton = new QPushButton( tr( "SMESH_BUT_CLOSE" ), ButtonsGrp );
273 CloseButton->setAutoDefault( true );
276 ButtonsGrpLayout->addWidget( OkButton, 0, 0 );
277 ButtonsGrpLayout->addWidget( ApplyButton, 0, 1 );
278 ButtonsGrpLayout->addWidget( CloseButton, 0, 3 );
279 ButtonsGrpLayout->addColSpacing( 2, 10 );
280 ButtonsGrpLayout->setColStretch( 2, 10 );
282 /***************************************************************/
284 topLayout->addWidget( ElementsTypeGrp, 0, 0 );
285 topLayout->addWidget( ArgumentsGrp, 1, 0 );
286 topLayout->addWidget( ButtonsGrp, 2, 0 );
288 /***************************************************************/
290 XSpin->RangeStepAndValidator( -999999.999, +999999.999, 10.0, 3 );
291 YSpin->RangeStepAndValidator( -999999.999, +999999.999, 10.0, 3 );
292 ZSpin->RangeStepAndValidator( -999999.999, +999999.999, 10.0, 3 );
293 AngleSpin->RangeStepAndValidator( -999999.999, +999999.999, 5.0, 3 );
296 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
297 mySMESHGUI->SetActiveDialogBox( this ) ;
299 // Costruction of the logical filter for the elements: mesh/sub-mesh/group
300 SMESH_ListOfFilter aListOfFilters;
301 Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
302 if ( !aMeshOrSubMeshFilter.IsNull() )
303 aListOfFilters.Append( aMeshOrSubMeshFilter );
304 Handle(SMESH_TypeFilter) aSmeshGroupFilter = new SMESH_TypeFilter( GROUP );
305 if ( !aSmeshGroupFilter.IsNull() )
306 aListOfFilters.Append( aSmeshGroupFilter );
308 myElementsFilter = new SMESH_LogicalFilter( aListOfFilters, SMESH_LogicalFilter::LO_OR );
310 myPathMeshFilter = new SMESH_TypeFilter( MESH );
314 /***************************************************************/
315 // signals-slots connections
316 connect( OkButton, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
317 connect( CloseButton, SIGNAL( clicked() ), this, SLOT( reject() ) ) ;
318 connect( ApplyButton, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
320 connect( AddAngleButton, SIGNAL( clicked() ), this, SLOT( OnAngleAdded() ) );
321 connect( RemoveAngleButton, SIGNAL( clicked() ), this, SLOT( OnAngleRemoved() ) );
323 connect( ElementsTypeGrp, SIGNAL( clicked( int ) ), SLOT( TypeChanged( int ) ) );
325 connect( SelectElementsButton, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
326 connect( SelectPathMeshButton, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
327 connect( SelectPathShapeButton, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
328 connect( SelectStartPointButton, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
329 connect( SelectBasePointButton, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
331 connect( mySMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
332 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
333 connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( reject() ) ) ;
335 connect( ElementsLineEdit, SIGNAL( textChanged( const QString& ) ),
336 SLOT( onTextChange( const QString& ) ) );
337 connect( StartPointLineEdit, SIGNAL( textChanged( const QString& ) ),
338 SLOT( onTextChange( const QString& ) ) );
340 connect( MeshCheck, SIGNAL( toggled( bool ) ), SLOT( onSelectMesh() ) );
341 connect( AnglesCheck, SIGNAL( toggled( bool ) ), SLOT( onAnglesCheck() ) );
342 connect( BasePointCheck, SIGNAL( toggled( bool ) ), SLOT( onBasePointCheck() ) );
344 AnglesList->installEventFilter( this );
345 ElementsLineEdit->installEventFilter( this );
346 StartPointLineEdit->installEventFilter( this );
347 XSpin->editor()->installEventFilter( this );
348 YSpin->editor()->installEventFilter( this );
349 ZSpin->editor()->installEventFilter( this );
351 /***************************************************************/
352 // set position and show dialog box
354 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
356 this->show() ; // displays Dialog
359 //=================================================================================
360 // function : SMESHGUI_ExtrusionAlongPathDlg::~SMESHGUI_ExtrusionAlongPathDlg()
361 // purpose : destructor
362 //=================================================================================
363 SMESHGUI_ExtrusionAlongPathDlg::~SMESHGUI_ExtrusionAlongPathDlg()
365 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::~SMESHGUI_ExtrusionAlongPathDlg");
366 // no need to delete child widgets, Qt does it all for us
369 //=================================================================================
370 // function : SMESHGUI_ExtrusionAlongPathDlg::eventFilter
371 // purpose : event filter
372 //=================================================================================
373 bool SMESHGUI_ExtrusionAlongPathDlg::eventFilter( QObject* object, QEvent* event )
375 if ( event->type() == QEvent::KeyPress ) {
376 QKeyEvent* ke = ( QKeyEvent* )event;
377 if ( object == AnglesList ) {
378 if ( ke->key() == Key_Delete )
382 else if ( event->type() == QEvent::FocusIn ) {
383 if ( object == ElementsLineEdit ) {
384 if ( myEditCurrentArgument != ElementsLineEdit )
385 SetEditCurrentArgument( SelectElementsButton );
387 else if ( object == StartPointLineEdit ) {
388 if ( myEditCurrentArgument != StartPointLineEdit )
389 SetEditCurrentArgument( SelectStartPointButton );
391 else if ( object == XSpin->editor() || object == YSpin->editor() || object == ZSpin->editor() ) {
392 if ( myEditCurrentArgument != XSpin )
393 SetEditCurrentArgument( SelectBasePointButton );
396 return QDialog::eventFilter( object, event );
399 //=================================================================================
400 // function : SMESHGUI_ExtrusionAlongPathDlg::Init()
401 // purpose : initialization
402 //=================================================================================
403 void SMESHGUI_ExtrusionAlongPathDlg::Init( bool ResetControls )
405 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::Init");
407 myEditCurrentArgument = 0;
409 myMesh = SMESH::SMESH_Mesh::_nil();
410 myIDSource = SMESH::SMESH_IDSource::_nil();
412 myPathMesh = SMESH::SMESH_Mesh::_nil();
413 myPathShape = GEOM::GEOM_Object::_nil();
415 ElementsLineEdit->clear();
416 PathMeshLineEdit->clear();
417 PathShapeLineEdit->clear();
418 StartPointLineEdit->clear();
420 if( ResetControls ) {
421 XSpin->SetValue( 0.0 );
422 YSpin->SetValue( 0.0 );
423 ZSpin->SetValue( 0.0 );
425 AngleSpin->SetValue( 45 );
426 MeshCheck->setChecked( false );
432 SetEditCurrentArgument( 0 );
435 //=================================================================================
436 // function : SMESHGUI_ExtrusionAlongPathDlg::TypeChanged()
437 // purpose : Called when user changes type of elements ( 1d / 2d )
438 //=================================================================================
439 void SMESHGUI_ExtrusionAlongPathDlg::TypeChanged( int type )
441 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::TypeChanged");
442 if ( myType != type ) {
443 disconnect( mySelection, 0, this, 0 );
446 ArgumentsGrp->setTitle( tr( "EXTRUSION_1D" ) );
447 else if ( type == 1 )
448 ArgumentsGrp->setTitle( tr( "EXTRUSION_2D" ) );
450 // clear elements ID list
451 if ( !MeshCheck->isChecked() ) {
452 ElementsLineEdit->clear();
454 // set selection mode if necessary
455 if( myEditCurrentArgument == ElementsLineEdit ) {
456 mySelection->ClearIObjects();
457 mySelection->ClearFilters();
458 SMESH::SetPickable();
460 SMESH::SetPointRepresentation( false );
461 if ( MeshCheck->isChecked() ) {
462 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
463 mySelection->AddFilter( myElementsFilter );
467 QAD_Application::getDesktop()->SetSelectionMode( EdgeSelection, true );
469 QAD_Application::getDesktop()->SetSelectionMode( FaceSelection, true );
472 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
478 //=================================================================================
479 // function : SMESHGUI_ExtrusionAlongPathDlg::ClickOnApply()
480 // purpose : Called when user presses <Apply> button
481 //=================================================================================
482 bool SMESHGUI_ExtrusionAlongPathDlg::ClickOnApply()
484 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::ClickOnApply");
485 if ( mySMESHGUI->ActiveStudyLocked() ) {
489 if( myMesh->_is_nil() || MeshCheck->isChecked() && myIDSource->_is_nil() || !myMeshActor || myPathMesh->_is_nil() || myPathShape->_is_nil() ) {
493 SMESH::long_array_var anElementsId = new SMESH::long_array;
495 if ( MeshCheck->isChecked() ) {
496 // If "Select whole mesh, submesh or group" check box is on ->
497 // get all elements of the required type from the object selected
499 // if MESH object is selected
500 if ( !CORBA::is_nil( SMESH::SMESH_Mesh::_narrow( myIDSource ) ) ) {
502 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( myIDSource );
503 // get IDs from mesh...
504 if ( Elements1dRB->isChecked() )
506 anElementsId = aMesh->GetElementsByType( SMESH::EDGE );
507 else if ( Elements2dRB->isChecked() ) {
508 anElementsId = aMesh->GetElementsByType( SMESH::FACE );
511 // SUBMESH is selected
512 if ( !CORBA::is_nil( SMESH::SMESH_subMesh::_narrow( myIDSource ) ) ) {
514 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( myIDSource );
515 // get IDs from submesh
516 if ( Elements1dRB->isChecked() )
518 anElementsId = aSubMesh->GetElementsByType( SMESH::EDGE );
519 else if ( Elements2dRB->isChecked() )
521 anElementsId = aSubMesh->GetElementsByType( SMESH::FACE );
524 if ( !CORBA::is_nil( SMESH::SMESH_GroupBase::_narrow( myIDSource ) ) ) {
526 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( myIDSource );
527 // get IDs from group
528 // 1d elements or 2d elements
529 if ( Elements1dRB->isChecked() && aGroup->GetType() == SMESH::EDGE ||
530 Elements2dRB->isChecked() && aGroup->GetType() == SMESH::FACE )
531 anElementsId = aGroup->GetListOfID();
535 // If "Select whole mesh, submesh or group" check box is off ->
536 // use only elements of given type selected by user
538 SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh();
540 QStringList aListElementsId = QStringList::split( " ", ElementsLineEdit->text(), false );
541 anElementsId = new SMESH::long_array;
542 anElementsId->length( aListElementsId.count() );
545 for ( int i = 0; i < aListElementsId.count(); i++ ) {
546 long ind = aListElementsId[ i ].toLong( &bOk );
548 const SMDS_MeshElement* e = aMesh->FindElement( ind );
550 bool typeMatch = Elements1dRB->isChecked() && e->GetType() == SMDSAbs_Edge ||
551 Elements2dRB->isChecked() && e->GetType() == SMDSAbs_Face;
553 anElementsId[ j++ ] = ind;
557 anElementsId->length( j );
561 if ( anElementsId->length() <= 0 ) {
565 if ( StartPointLineEdit->text().stripWhiteSpace().isEmpty() ) {
570 long aNodeStart = StartPointLineEdit->text().toLong( &bOk );
576 SMESH::double_array_var anAngles = new SMESH::double_array;
577 if ( AnglesCheck->isChecked() ) {
578 anAngles->length( AnglesList->count() );
581 for ( int i = 0; i < AnglesList->count(); i++ ) {
582 long angle = AnglesList->text( i ).toLong( &bOk );
584 anAngles[ j++ ] = angle;
586 anAngles->length( j );
590 SMESH::PointStruct aBasePoint;
591 if ( BasePointCheck->isChecked() ) {
592 aBasePoint.x = XSpin->GetValue();
593 aBasePoint.y = YSpin->GetValue();
594 aBasePoint.z = ZSpin->GetValue();
599 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
600 aMeshEditor->ExtrusionAlongPath( anElementsId.inout(), myPathMesh, myPathShape, aNodeStart,
601 AnglesCheck->isChecked(), anAngles.inout(),
602 BasePointCheck->isChecked(), aBasePoint );
608 mySelection->ClearIObjects();
611 TypeChanged( GetConstructorId() );
615 //=================================================================================
616 // function : SMESHGUI_ExtrusionAlongPathDlg::ClickOnOk()
617 // purpose : Called when user presses <OK> button
618 //=================================================================================
619 void SMESHGUI_ExtrusionAlongPathDlg::ClickOnOk()
621 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::ClickOnOk");
622 if ( !ClickOnApply() )
627 //=======================================================================
628 // function : SMESHGUI_ExtrusionAlongPathDlg::onTextChange
630 //=======================================================================
632 void SMESHGUI_ExtrusionAlongPathDlg::onTextChange(const QString& theNewText)
634 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::onTextChange");
635 QLineEdit* send = (QLineEdit*)sender();
636 if ( send != StartPointLineEdit && send != ElementsLineEdit )
637 send = ElementsLineEdit;
646 if ( send == ElementsLineEdit && myEditCurrentArgument == ElementsLineEdit ) {
647 // hilight entered elements
648 SMDS_Mesh* aMesh = 0;
650 aMesh = myMeshActor->GetObject()->GetMesh();
652 mySelection->ClearIObjects();
653 mySelection->AddIObject( myMeshActor->getIO() );
655 QStringList aListId = QStringList::split( " ", theNewText, false );
657 for ( int i = 0; i < aListId.count(); i++ ) {
658 long ind = aListId[ i ].toLong( &bOk );
660 const SMDS_MeshElement* e = aMesh->FindElement( ind );
662 // check also type of element
663 bool typeMatch = Elements1dRB->isChecked() && e->GetType() == SMDSAbs_Edge ||
664 Elements2dRB->isChecked() && e->GetType() == SMDSAbs_Face;
666 if ( !mySelection->IsIndexSelected( myMeshActor->getIO(), e->GetID() ) )
667 mySelection->AddOrRemoveIndex( myMeshActor->getIO(), e->GetID(), true );
674 else if ( send == StartPointLineEdit && myEditCurrentArgument == StartPointLineEdit ) {
675 if ( !myPathMesh->_is_nil() ) {
676 SMESH_Actor* aPathActor = SMESH::FindActorByObject( myPathMesh );
677 SMDS_Mesh* aMesh = 0;
679 aMesh = aPathActor->GetObject()->GetMesh();
681 mySelection->ClearIObjects();
682 mySelection->AddIObject( aPathActor->getIO() );
685 long ind = theNewText.toLong( &bOk );
687 const SMDS_MeshNode* n = aMesh->FindNode( ind );
689 if ( !mySelection->IsIndexSelected( aPathActor->getIO(), n->GetID() ) ) {
690 mySelection->AddOrRemoveIndex( aPathActor->getIO(), n->GetID(), true );
699 //=================================================================================
700 // function : SMESHGUI_ExtrusionAlongPathDlg::SelectionIntoArgument()
701 // purpose : Called when selection as changed or other case
702 //=================================================================================
703 void SMESHGUI_ExtrusionAlongPathDlg::SelectionIntoArgument()
705 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::SelectionIntoArgument");
710 // return if dialog box is inactive
711 if ( !ButtonsGrp->isEnabled() )
714 // selected objects count
715 int nbSel = mySelection->IObjectCount();
720 if ( myEditCurrentArgument == ElementsLineEdit ) {
721 // we are now selecting mesh elements (or whole mesh/submesh/group)
723 ElementsLineEdit->clear();
724 myMesh = SMESH::SMESH_Mesh::_nil();
725 myIDSource = SMESH::SMESH_IDSource::_nil();
728 // only one object is acceptable
732 // try to get mesh from selection
733 Handle( SALOME_InteractiveObject ) IO = mySelection->firstIObject();
734 myMesh = SMESH::GetMeshByIO( IO );
735 if( myMesh->_is_nil() )
738 myMeshActor = SMESH::FindActorByObject( myMesh );
742 if ( MeshCheck->isChecked() ) {
743 // If "Select whole mesh, submesh or group" check box is on ->
744 // get ID source and put it's name to the edit box
746 SMESH::GetNameOfSelectedIObjects( mySelection, aString );
748 myIDSource = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
749 ElementsLineEdit->setText( aString );
752 // If "Select whole mesh, submesh or group" check box is off ->
753 // try to get selected elements IDs
755 int aNbUnits = SMESH::GetNameOfSelectedElements( mySelection, aString );
756 ElementsLineEdit->setText( aString );
759 else if ( myEditCurrentArgument == PathMeshLineEdit ) {
760 // we are now selecting path mesh
762 PathMeshLineEdit->clear();
763 myPathMesh = SMESH::SMESH_Mesh::_nil();
764 PathShapeLineEdit->clear();
765 myPathShape = GEOM::GEOM_Object::_nil();
766 StartPointLineEdit->clear();
768 // only one object is acceptable
772 // try to get mesh from selection
773 Handle( SALOME_InteractiveObject ) IO = mySelection->firstIObject();
774 myPathMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>( IO );
775 if( myPathMesh->_is_nil() )
779 SMESH::GetNameOfSelectedIObjects( mySelection, aString );
780 PathMeshLineEdit->setText( aString );
782 else if ( myEditCurrentArgument == PathShapeLineEdit ) {
783 // we are now selecting path mesh
785 PathShapeLineEdit->clear();
786 myPathShape = GEOM::GEOM_Object::_nil();
787 StartPointLineEdit->clear();
789 // return if path mesh is not yet selected
790 if ( myPathMesh->_is_nil() )
793 // only one object is acceptable
797 // try to get shape from selection
798 Handle( SALOME_InteractiveObject ) IO = mySelection->firstIObject();
799 myPathShape = SMESH::IObjectToInterface<GEOM::GEOM_Object>( IO );
800 if ( myPathShape->_is_nil() )
804 SMESH::GetNameOfSelectedIObjects( mySelection, aString );
805 PathShapeLineEdit->setText( aString );
807 else if ( myEditCurrentArgument == StartPointLineEdit ) {
808 // we are now selecting start point of path
810 StartPointLineEdit->clear();
812 // return if path mesh or path shape is not yet selected
813 if ( myPathMesh->_is_nil() || myPathShape->_is_nil() )
816 // only one object is acceptable
820 // try to get shape from selection
821 Handle( SALOME_InteractiveObject ) IO = mySelection->firstIObject();
824 int aNbUnits = SMESH::GetNameOfSelectedElements( mySelection, aString );
826 StartPointLineEdit->setText( aString.stripWhiteSpace() );
828 else if ( myEditCurrentArgument == XSpin ) {
829 // we are now selecting base point
830 // reset is not performed here!
832 // return if is not enabled
833 if ( !BasePointGrp->isEnabled() )
836 // only one object is acceptable
840 // try to get shape from selection
841 Handle( SALOME_InteractiveObject ) IO = mySelection->firstIObject();
843 // check if geom vertex is selected
844 GEOM::GEOM_Object_var aGeomObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>( IO );
845 TopoDS_Vertex aVertex;
846 if( !aGeomObj->_is_nil() ) {
847 if( aGeomObj->IsShape() && GEOMBase::GetShape( aGeomObj, aVertex ) && !aVertex.IsNull() ) {
848 gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
849 XSpin->SetValue( aPnt.X() );
850 YSpin->SetValue( aPnt.Y() );
851 ZSpin->SetValue( aPnt.Z() );
856 // check if smesh node is selected
857 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
858 if( aMesh->_is_nil() )
862 int aNbUnits = SMESH::GetNameOfSelectedNodes( mySelection, aString );
863 // return if more than one node is selected
867 SMESH_Actor* aMeshActor = SMESH::FindActorByObject( aMesh );
871 SMDS_Mesh* mesh = aMeshActor->GetObject()->GetMesh();
875 const SMDS_MeshNode* n = mesh->FindNode( aString.toLong() );
879 XSpin->SetValue( n->X() );
880 YSpin->SetValue( n->Y() );
881 ZSpin->SetValue( n->Z() );
885 //=================================================================================
886 // function : SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument()
888 //=================================================================================
889 void SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument()
891 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument");
892 QToolButton* send = (QToolButton*)sender();
893 if ( send != SelectElementsButton &&
894 send != SelectPathMeshButton &&
895 send != SelectPathShapeButton &&
896 send != SelectStartPointButton &&
897 send != SelectBasePointButton )
899 SetEditCurrentArgument( send );
902 //=================================================================================
903 // function : SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument()
905 //=================================================================================
906 void SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument( QToolButton* button )
908 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument(button)");
909 disconnect( mySelection, 0, this, 0 );
910 mySelection->ClearIObjects();
911 mySelection->ClearFilters();
912 SMESH::SetPickable();
914 if( button == SelectElementsButton ) {
915 myEditCurrentArgument = ElementsLineEdit;
916 SMESH::SetPointRepresentation( false );
917 if ( MeshCheck->isChecked() ) {
918 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
919 mySelection->AddFilter( myElementsFilter );
922 if ( Elements1dRB->isChecked() )
923 QAD_Application::getDesktop()->SetSelectionMode( EdgeSelection, true );
924 else if ( Elements2dRB->isChecked() )
925 QAD_Application::getDesktop()->SetSelectionMode( FaceSelection, true );
928 else if ( button == SelectPathMeshButton ) {
929 myEditCurrentArgument = PathMeshLineEdit;
930 SMESH::SetPointRepresentation( false );
931 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
932 mySelection->AddFilter( myPathMeshFilter );
934 else if ( button == SelectPathShapeButton ) {
935 myEditCurrentArgument = PathShapeLineEdit;
936 SMESH::SetPointRepresentation( false );
937 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
939 if ( !myPathMesh->_is_nil() ) {
940 TColStd_MapOfInteger aTypes;
941 aTypes.Add( TopAbs_EDGE );
942 aTypes.Add( TopAbs_WIRE );
943 GEOM::GEOM_Object_var aMainShape = myPathMesh->GetShapeToMesh();
944 SMESH_Actor* aPathActor = SMESH::FindActorByObject( myPathMesh );
946 if ( !aMainShape->_is_nil() && aPathActor )
947 mySelection->AddFilter( new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, -1, aTypes, aMainShape ) );
948 //SMESH::SetPickable( aPathActor );
951 else if ( button == SelectStartPointButton ) {
952 myEditCurrentArgument = StartPointLineEdit;
953 if ( !myPathMesh->_is_nil() ) {
954 SMESH_Actor* aPathActor = SMESH::FindActorByObject( myPathMesh );
956 SMESH::SetPointRepresentation( true );
957 QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
958 SMESH::SetPickable( aPathActor );
962 else if ( button == SelectBasePointButton ) {
963 myEditCurrentArgument = XSpin;
964 SMESH::SetPointRepresentation( true );
965 QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
967 SMESH_ListOfFilter aListOfFilters;
968 Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
969 if ( !aMeshOrSubMeshFilter.IsNull() )
970 aListOfFilters.Append( aMeshOrSubMeshFilter );
971 Handle(SMESH_TypeFilter) aSmeshGroupFilter = new SMESH_TypeFilter( GROUP );
972 if ( !aSmeshGroupFilter.IsNull() )
973 aListOfFilters.Append( aSmeshGroupFilter );
974 //Handle(GEOM_ShapeTypeFilter) aVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX );
975 Handle(SMESH_NumberFilter) aVertexFilter = new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, -1, TopAbs_VERTEX, GEOM::GEOM_Object::_nil() );
976 if ( !aVertexFilter.IsNull() )
977 aListOfFilters.Append( aVertexFilter );
979 mySelection->AddFilter( new SMESH_LogicalFilter( aListOfFilters, SMESH_LogicalFilter::LO_OR ) );
982 if ( myEditCurrentArgument && !myEditCurrentArgument->hasFocus() )
983 myEditCurrentArgument->setFocus();
985 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
986 SelectionIntoArgument();
989 //=================================================================================
990 // function : SMESHGUI_ExtrusionAlongPathDlg::DeactivateActiveDialog()
991 // purpose : Deactivates this dialog
992 //=================================================================================
993 void SMESHGUI_ExtrusionAlongPathDlg::DeactivateActiveDialog()
995 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::DeactivateActiveDialog");
996 if ( ElementsTypeGrp->isEnabled() ) {
997 ElementsTypeGrp->setEnabled( false );
998 ArgumentsGrp->setEnabled( false );
999 ButtonsGrp->setEnabled( false );
1000 mySMESHGUI->ResetState();
1001 mySMESHGUI->SetActiveDialogBox( 0 );
1005 //=================================================================================
1006 // function : SMESHGUI_ExtrusionAlongPathDlg::ActivateThisDialog()
1007 // purpose : Activates this dialog
1008 //=================================================================================
1009 void SMESHGUI_ExtrusionAlongPathDlg::ActivateThisDialog()
1011 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::ActivateThisDialog");
1012 // Emit a signal to deactivate the active dialog
1013 mySMESHGUI->EmitSignalDeactivateDialog();
1014 ElementsTypeGrp->setEnabled( true );
1015 ArgumentsGrp->setEnabled( true );
1016 ButtonsGrp->setEnabled( true );
1018 mySMESHGUI->SetActiveDialogBox( this );
1020 TypeChanged( GetConstructorId() );
1021 SelectionIntoArgument();
1024 //=================================================================================
1025 // function : SMESHGUI_ExtrusionAlongPathDlg::enterEvent()
1026 // purpose : Mouse enter event
1027 //=================================================================================
1028 void SMESHGUI_ExtrusionAlongPathDlg::enterEvent(QEvent* e)
1030 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::enterEvent");
1031 if ( ElementsTypeGrp->isEnabled() )
1033 ActivateThisDialog();
1036 //=================================================================================
1037 // function : SMESHGUI_ExtrusionAlongPathDlg::reject()
1038 // purpose : Called when dialog box is closed
1039 //=================================================================================
1040 void SMESHGUI_ExtrusionAlongPathDlg::reject()
1042 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::reject");
1043 disconnect( mySelection, 0, this, 0 );
1044 mySelection->ClearFilters();
1045 mySelection->ClearIObjects();
1046 SMESH::SetPickable();
1047 SMESH::SetPointRepresentation( false );
1048 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
1049 mySMESHGUI->ResetState() ;
1053 //=================================================================================
1054 // function : SMESHGUI_ExtrusionAlongPathDlg::GetConstructorId()
1056 //=================================================================================
1057 int SMESHGUI_ExtrusionAlongPathDlg::GetConstructorId()
1059 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::GetConstructorId");
1060 if ( ElementsTypeGrp != NULL && ElementsTypeGrp->selected() != NULL )
1061 return ElementsTypeGrp->id( ElementsTypeGrp->selected() );
1065 //=======================================================================
1066 // function : SMESHGUI_ExtrusionAlongPathDlg::onSelectMesh
1068 //=======================================================================
1069 void SMESHGUI_ExtrusionAlongPathDlg::onSelectMesh()
1071 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::onSelectMesh");
1072 bool toSelectMesh = MeshCheck->isChecked();
1074 ElementsLineEdit->setReadOnly( toSelectMesh );
1075 ElementsLab->setText( toSelectMesh ? tr( "SMESH_NAME" ) : tr( "SMESH_ID_ELEMENTS" ) );
1076 ElementsLineEdit->clear();
1078 SetEditCurrentArgument( SelectElementsButton );
1081 //=======================================================================
1082 // function : SMESHGUI_ExtrusionAlongPathDlg::onAnglesCheck
1083 // purpose : called when "Use Angles" check box is switched
1084 //=======================================================================
1085 void SMESHGUI_ExtrusionAlongPathDlg::onAnglesCheck()
1087 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::onAnglesCheck");
1088 AnglesGrp->setEnabled( AnglesCheck->isChecked() );
1091 //=======================================================================
1092 // function : SMESHGUI_ExtrusionAlongPathDlg::onBasePointCheck
1093 // purpose : called when "Use Base Point" check box is switched
1094 //=======================================================================
1095 void SMESHGUI_ExtrusionAlongPathDlg::onBasePointCheck()
1097 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::onBasePointCheck");
1098 BasePointGrp->setEnabled( BasePointCheck->isChecked() );
1101 //=======================================================================
1102 // function : SMESHGUI_ExtrusionAlongPathDlg::OnAngleAdded
1103 // purpose : Called when user adds angle to the list
1104 //=======================================================================
1105 void SMESHGUI_ExtrusionAlongPathDlg::OnAngleAdded()
1107 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::OnAngleAdded");
1108 AnglesList->insertItem( QString::number( AngleSpin->GetValue() ) );
1111 //=======================================================================
1112 // function : SMESHGUI_ExtrusionAlongPathDlg::OnAngleRemoved
1113 // purpose : Called when user removes angle(s) from the list
1114 //=======================================================================
1115 void SMESHGUI_ExtrusionAlongPathDlg::OnAngleRemoved()
1117 MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::OnAngleRemoved");
1118 QList<QListBoxItem> aList;
1119 aList.setAutoDelete( false );
1120 for ( int i = 0; i < AnglesList->count(); i++ )
1121 if ( AnglesList->isSelected( i ) )
1122 aList.append( AnglesList->item( i ) );
1124 for ( int i = 0; i < aList.count(); i++ )
1125 delete aList.at( i );