2 // File : SMESHGUI_AddSubMeshDlg.cxx
3 // Created : Mon May 27 10:20:11 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
11 #include "SMESHGUI_AddSubMeshDlg.h"
13 #include "SALOME_ListIteratorOfListIO.hxx"
15 #include "QAD_Application.h"
16 #include "QAD_Desktop.h"
17 #include "utilities.h"
20 #include <qbuttongroup.h>
21 #include <qgroupbox.h>
23 #include <qlineedit.h>
24 #include <qpushbutton.h>
25 #include <qradiobutton.h>
29 #include <qwhatsthis.h>
34 //=================================================================================
35 // class : SMESHGUI_AddSubMeshDlg()
36 // purpose : Constructs a SMESHGUI_AddSubMeshDlg which is a child of 'parent', with the
37 // name 'name' and widget flags set to 'f'.
38 // The dialog will by default be modeless, unless you set 'modal' to
39 // TRUE to construct a modal dialog.
40 //=================================================================================
41 SMESHGUI_AddSubMeshDlg::SMESHGUI_AddSubMeshDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
42 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
44 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_ADD_SUBMESH")));
45 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
47 setName( "SMESHGUI_AddSubMeshDlg" );
49 setCaption( tr( "SMESH_ADD_SUBMESH" ) );
50 setSizeGripEnabled( TRUE );
51 SMESHGUI_AddSubMeshDlgLayout = new QGridLayout( this );
52 SMESHGUI_AddSubMeshDlgLayout->setSpacing( 6 );
53 SMESHGUI_AddSubMeshDlgLayout->setMargin( 11 );
55 /***************************************************************/
56 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
57 GroupConstructors->setTitle( tr( "SMESH_SUBMESH" ) );
58 GroupConstructors->setExclusive( TRUE );
59 GroupConstructors->setColumnLayout(0, Qt::Vertical );
60 GroupConstructors->layout()->setSpacing( 0 );
61 GroupConstructors->layout()->setMargin( 0 );
62 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
63 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
64 GroupConstructorsLayout->setSpacing( 6 );
65 GroupConstructorsLayout->setMargin( 11 );
66 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
67 Constructor1->setText( tr( "" ) );
68 Constructor1->setPixmap( image1 );
69 Constructor1->setChecked( TRUE );
70 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
71 Constructor1->setMinimumSize( QSize( 50, 0 ) );
72 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
73 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
74 GroupConstructorsLayout->addItem( spacer, 0, 1 );
75 SMESHGUI_AddSubMeshDlgLayout->addWidget( GroupConstructors, 0, 0 );
77 /***************************************************************/
78 GroupButtons = new QGroupBox( this, "GroupButtons" );
79 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
80 GroupButtons->setTitle( tr( "" ) );
81 GroupButtons->setColumnLayout(0, Qt::Vertical );
82 GroupButtons->layout()->setSpacing( 0 );
83 GroupButtons->layout()->setMargin( 0 );
84 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
85 GroupButtonsLayout->setAlignment( Qt::AlignTop );
86 GroupButtonsLayout->setSpacing( 6 );
87 GroupButtonsLayout->setMargin( 11 );
88 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
89 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
90 buttonCancel->setAutoDefault( TRUE );
91 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
92 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
93 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
94 buttonApply->setAutoDefault( TRUE );
95 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
96 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
97 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
98 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
99 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
100 buttonOk->setAutoDefault( TRUE );
101 buttonOk->setDefault( TRUE );
102 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
103 SMESHGUI_AddSubMeshDlgLayout->addWidget( GroupButtons, 2, 0 );
105 /***************************************************************/
106 GroupC1 = new QGroupBox( this, "GroupC1" );
107 GroupC1->setTitle( tr( "SMESH_ARGUMENTS" ) );
108 GroupC1->setMinimumSize( QSize( 0, 0 ) );
109 GroupC1->setFrameShape( QGroupBox::Box );
110 GroupC1->setFrameShadow( QGroupBox::Sunken );
111 GroupC1->setColumnLayout(0, Qt::Vertical );
112 GroupC1->layout()->setSpacing( 0 );
113 GroupC1->layout()->setMargin( 0 );
114 GroupC1Layout = new QGridLayout( GroupC1->layout() );
115 GroupC1Layout->setAlignment( Qt::AlignTop );
116 GroupC1Layout->setSpacing( 6 );
117 GroupC1Layout->setMargin( 11 );
119 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
120 TextLabelC1A1->setText( tr( "SMESH_OBJECT_MESH" ) );
121 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
122 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
123 TextLabelC1A1->setFrameShadow( QLabel::Plain );
124 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
125 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
126 SelectButtonC1A1->setText( tr( "" ) );
127 SelectButtonC1A1->setPixmap( image0 );
128 SelectButtonC1A1->setToggleButton( FALSE );
129 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
130 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
131 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
133 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
134 TextLabelC1A2->setText( tr( "SMESH_OBJECT_GEOM" ) );
135 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
136 TextLabelC1A2->setFrameShape( QLabel::NoFrame );
137 TextLabelC1A2->setFrameShadow( QLabel::Plain );
138 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
139 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
140 SelectButtonC1A2->setText( tr( "" ) );
141 SelectButtonC1A2->setPixmap( image0 );
142 SelectButtonC1A2->setToggleButton( FALSE );
143 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
144 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
145 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
147 TextLabel_NameMesh = new QLabel( GroupC1, "TextLabel_NameMesh" );
148 TextLabel_NameMesh->setText( tr( "SMESH_NAME" ) );
149 GroupC1Layout->addWidget( TextLabel_NameMesh, 2, 0 );
150 LineEdit_NameMesh = new QLineEdit( GroupC1, "LineEdit_NameMesh" );
151 GroupC1Layout->addWidget( LineEdit_NameMesh, 2, 2 );
153 TextLabelC1A1Hyp = new QLabel( GroupC1, "TextLabelC1A1Hyp" );
154 TextLabelC1A1Hyp->setText( tr( "SMESH_OBJECT_HYPOTHESIS" ) );
155 TextLabelC1A1Hyp->setMinimumSize( QSize( 50, 0 ) );
156 TextLabelC1A1Hyp->setFrameShape( QLabel::NoFrame );
157 TextLabelC1A1Hyp->setFrameShadow( QLabel::Plain );
158 GroupC1Layout->addWidget( TextLabelC1A1Hyp, 3, 0 );
159 SelectButtonC1A1Hyp = new QPushButton( GroupC1, "SelectButtonC1A1Hyp" );
160 SelectButtonC1A1Hyp->setText( tr( "" ) );
161 SelectButtonC1A1Hyp->setPixmap( image0 );
162 GroupC1Layout->addWidget( SelectButtonC1A1Hyp, 3, 1 );
163 LineEditC1A1Hyp = new QLineEdit( GroupC1, "LineEditC1A1Hyp" );
164 LineEditC1A1Hyp->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Hyp->sizePolicy().hasHeightForWidth() ) );
165 GroupC1Layout->addWidget( LineEditC1A1Hyp, 3, 2 );
167 TextLabelC1A1Algo = new QLabel( GroupC1, "TextLabelC1A1Algo" );
168 TextLabelC1A1Algo->setText( tr( "SMESH_OBJECT_ALGORITHM" ) );
169 TextLabelC1A1Algo->setMinimumSize( QSize( 50, 0 ) );
170 TextLabelC1A1Algo->setFrameShape( QLabel::NoFrame );
171 TextLabelC1A1Algo->setFrameShadow( QLabel::Plain );
172 GroupC1Layout->addWidget( TextLabelC1A1Algo, 4, 0 );
173 SelectButtonC1A1Algo = new QPushButton( GroupC1, "SelectButtonC1A1Algo" );
174 SelectButtonC1A1Algo->setText( tr( "" ) );
175 SelectButtonC1A1Algo->setPixmap( image0 );
176 GroupC1Layout->addWidget( SelectButtonC1A1Algo, 4, 1 );
177 LineEditC1A1Algo = new QLineEdit( GroupC1, "LineEditC1A1Algo" );
178 LineEditC1A1Algo->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Algo->sizePolicy().hasHeightForWidth() ) );
179 GroupC1Layout->addWidget( LineEditC1A1Algo, 4, 2 );
181 SMESHGUI_AddSubMeshDlgLayout->addWidget( GroupC1, 1, 0 );
182 /***************************************************************/
188 //=================================================================================
189 // function : ~SMESHGUI_AddSubMeshDlg()
190 // purpose : Destroys the object and frees any allocated resources
191 //=================================================================================
192 SMESHGUI_AddSubMeshDlg::~SMESHGUI_AddSubMeshDlg()
194 // no need to delete child widgets, Qt does it all for us
198 //=================================================================================
201 //=================================================================================
202 void SMESHGUI_AddSubMeshDlg::Init( SALOME_Selection* Sel )
205 myConstructorId = 0 ;
206 Constructor1->setChecked( TRUE );
207 myEditCurrentArgument = LineEditC1A1 ;
209 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
210 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
212 myGeomFilter = new SALOME_TypeFilter( "GEOM" );
213 myMeshFilter = new SMESH_TypeFilter( MESH );
215 myAlgorithmFilter = new SMESH_TypeFilter( ALGORITHM );
216 myHypothesisFilter = new SMESH_TypeFilter( HYPOTHESIS );
218 myNameSubMesh = "SubMesh";
220 myGeomShape = GEOM::GEOM_Shape::_nil();
221 myMesh = SMESH::SMESH_Mesh::_nil();
223 /* signals and slots connections */
224 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
225 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
226 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
227 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
229 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
230 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
231 connect( LineEdit_NameMesh, SIGNAL (textChanged(const QString&) ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
233 connect( SelectButtonC1A1Hyp, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
234 connect( SelectButtonC1A1Algo, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
236 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
237 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
238 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
241 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
245 SelectionIntoArgument();
251 //=================================================================================
252 // function : ConstructorsClicked()
253 // purpose : Radio button management
254 //=================================================================================
255 void SMESHGUI_AddSubMeshDlg::ConstructorsClicked(int constructorId)
260 //=================================================================================
261 // function : ClickOnOk()
263 //=================================================================================
264 void SMESHGUI_AddSubMeshDlg::ClickOnOk()
266 this->ClickOnApply() ;
267 this->ClickOnCancel() ;
270 //=================================================================================
271 // function : ClickOnApply()
273 //=================================================================================
274 void SMESHGUI_AddSubMeshDlg::ClickOnApply()
276 switch(myConstructorId)
280 if ( !myNameSubMesh.isEmpty() && !myNameSubMesh.isNull() &&
281 !myGeomShape->_is_nil() && !myMesh->_is_nil()) {
282 mySubMesh = mySMESHGUI->AddSubMesh( myMesh, myGeomShape, myNameSubMesh ) ;
285 if( myOkHypothesis && !mySubMesh->_is_nil() ) {
286 SALOME_ListIteratorOfListIO It( HypoList );
287 for(;It.More();It.Next()) {
288 Handle(SALOME_InteractiveObject) IObject = It.Value();
289 Standard_Boolean testResult;
290 myHypothesis = mySMESHGUI->ConvertIOinSMESHHypothesis(IObject, testResult) ;
292 mySMESHGUI->AddHypothesisOnSubMesh(mySubMesh, myHypothesis) ;
296 if( myOkAlgorithm && !mySubMesh->_is_nil() ) {
297 SALOME_ListIteratorOfListIO It( AlgoList );
298 for(;It.More();It.Next()) {
299 Handle(SALOME_InteractiveObject) IObject = It.Value();
300 Standard_Boolean testResult;
301 myAlgorithm = mySMESHGUI->ConvertIOinSMESHHypothesis(IObject, testResult) ;
303 mySMESHGUI->AddAlgorithmOnSubMesh(mySubMesh, myAlgorithm) ;
313 //=================================================================================
314 // function : ClickOnCancel()
316 //=================================================================================
317 void SMESHGUI_AddSubMeshDlg::ClickOnCancel()
319 disconnect( mySelection, 0, this, 0 );
320 mySMESHGUI->ResetState() ;
321 mySelection->ClearFilters() ;
327 //=================================================================================
328 // function : SelectionIntoArgument()
329 // purpose : Called when selection as changed or other case
330 //=================================================================================
331 void SMESHGUI_AddSubMeshDlg::SelectionIntoArgument()
333 myEditCurrentArgument->setText("") ;
334 QString aString = "";
336 int nbSel = mySMESHGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
338 switch (myConstructorId)
342 if ( myEditCurrentArgument == LineEditC1A1 ) {
344 myOkHypothesis = false;
345 myOkAlgorithm = false;
348 Standard_Boolean testResult ;
349 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
350 myMesh = mySMESHGUI->ConvertIOinMesh(IO, testResult) ;
352 myMesh = SMESH::SMESH_Mesh::_nil();
356 } else if ( myEditCurrentArgument == LineEditC1A2 ) {
358 myOkHypothesis = false;
359 myOkAlgorithm = false;
362 Standard_Boolean testResult ;
363 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
364 myGeomShape = mySMESHGUI->ConvertIOinGEOMShape(IO, testResult) ;
366 myGeomShape = GEOM::GEOM_Shape::_nil();
370 } else if ( myEditCurrentArgument == LineEditC1A1Hyp ) {
373 SALOME_ListIteratorOfListIO Itinit( mySelection->StoredIObjects() );
374 for (; Itinit.More(); Itinit.Next()) {
375 HypoList.Append(Itinit.Value());
377 myOkHypothesis = true ;
379 aString = tr("%1 Hypothesis").arg(nbSel) ;
380 LineEditC1A1Hyp->setText(aString) ;
383 myOkHypothesis = false ;
386 } else if ( myEditCurrentArgument == LineEditC1A1Algo ) {
389 SALOME_ListIteratorOfListIO Itinit( mySelection->StoredIObjects() );
390 for (; Itinit.More(); Itinit.Next()) {
391 AlgoList.Append(Itinit.Value());
393 myOkAlgorithm = true ;
395 aString = tr("%1 Algorithms").arg(nbSel) ;
396 LineEditC1A1Algo->setText(aString) ;
399 myOkAlgorithm = false ;
407 myEditCurrentArgument->setText(aString) ;
411 //=================================================================================
412 // function : SetEditCurrentArgument()
414 //=================================================================================
415 void SMESHGUI_AddSubMeshDlg::SetEditCurrentArgument()
417 QPushButton* send = (QPushButton*)sender();
418 switch (myConstructorId)
420 case 0: /* default constructor */
422 if(send == SelectButtonC1A1) {
423 LineEditC1A1->setFocus() ;
424 myEditCurrentArgument = LineEditC1A1;
425 mySelection->ClearFilters() ;
426 mySelection->AddFilter(myMeshFilter) ;
427 } else if (send == SelectButtonC1A2) {
428 LineEditC1A2->setFocus() ;
429 myEditCurrentArgument = LineEditC1A2;
430 mySelection->ClearFilters() ;
431 mySelection->AddFilter(myGeomFilter) ;
432 } else if( send == SelectButtonC1A1Hyp ) {
433 LineEditC1A1Hyp->setFocus() ;
434 myEditCurrentArgument = LineEditC1A1Hyp ;
435 mySelection->ClearFilters() ;
436 mySelection->AddFilter(myHypothesisFilter) ;
437 } else if( send == SelectButtonC1A1Algo ) {
438 LineEditC1A1Algo->setFocus() ;
439 myEditCurrentArgument = LineEditC1A1Algo ;
440 mySelection->ClearFilters() ;
441 mySelection->AddFilter(myAlgorithmFilter) ;
443 SelectionIntoArgument() ;
450 //=================================================================================
451 // function : DeactivateActiveDialog()
453 //=================================================================================
454 void SMESHGUI_AddSubMeshDlg::DeactivateActiveDialog()
456 if ( GroupConstructors->isEnabled() ) {
457 disconnect( mySelection, 0, this, 0 );
458 GroupConstructors->setEnabled(false) ;
459 GroupC1->setEnabled(false) ;
460 GroupButtons->setEnabled(false) ;
465 //=================================================================================
466 // function : ActivateThisDialog()
468 //=================================================================================
469 void SMESHGUI_AddSubMeshDlg::ActivateThisDialog()
471 mySMESHGUI->EmitSignalDeactivateDialog() ;
472 GroupConstructors->setEnabled(true) ;
473 GroupC1->setEnabled(true) ;
474 GroupButtons->setEnabled(true) ;
475 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
480 //=================================================================================
481 // function : enterEvent()
483 //=================================================================================
484 void SMESHGUI_AddSubMeshDlg::enterEvent(QEvent* e)
486 if ( GroupConstructors->isEnabled() )
488 ActivateThisDialog() ;
493 //=================================================================================
494 // function : closeEvent()
496 //=================================================================================
497 void SMESHGUI_AddSubMeshDlg::closeEvent( QCloseEvent* e )
499 this->ClickOnCancel() ;
503 //=================================================================================
504 // function : TextChangedInLineEdit()
506 //=================================================================================
507 void SMESHGUI_AddSubMeshDlg::TextChangedInLineEdit(const QString& newText)
509 QLineEdit* send = (QLineEdit*)sender();
510 QString newT = strdup(newText) ;
512 if (send == LineEdit_NameMesh) {
513 myNameSubMesh = newText;