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_AddSubMeshDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "SMESHGUI_AddSubMeshDlg.h"
32 #include "SALOME_ListIteratorOfListIO.hxx"
34 #include "QAD_Application.h"
35 #include "QAD_Desktop.h"
36 #include "utilities.h"
39 #include <qbuttongroup.h>
40 #include <qgroupbox.h>
42 #include <qlineedit.h>
43 #include <qpushbutton.h>
44 #include <qradiobutton.h>
48 #include <qwhatsthis.h>
53 //=================================================================================
54 // class : SMESHGUI_AddSubMeshDlg()
55 // purpose : Constructs a SMESHGUI_AddSubMeshDlg which is a child of 'parent', with the
56 // name 'name' and widget flags set to 'f'.
57 // The dialog will by default be modeless, unless you set 'modal' to
58 // TRUE to construct a modal dialog.
59 //=================================================================================
60 SMESHGUI_AddSubMeshDlg::SMESHGUI_AddSubMeshDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
61 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
63 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_ADD_SUBMESH")));
64 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
66 setName( "SMESHGUI_AddSubMeshDlg" );
68 setCaption( tr( "SMESH_ADD_SUBMESH" ) );
69 setSizeGripEnabled( TRUE );
70 SMESHGUI_AddSubMeshDlgLayout = new QGridLayout( this );
71 SMESHGUI_AddSubMeshDlgLayout->setSpacing( 6 );
72 SMESHGUI_AddSubMeshDlgLayout->setMargin( 11 );
74 /***************************************************************/
75 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
76 GroupConstructors->setTitle( tr( "SMESH_SUBMESH" ) );
77 GroupConstructors->setExclusive( TRUE );
78 GroupConstructors->setColumnLayout(0, Qt::Vertical );
79 GroupConstructors->layout()->setSpacing( 0 );
80 GroupConstructors->layout()->setMargin( 0 );
81 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
82 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
83 GroupConstructorsLayout->setSpacing( 6 );
84 GroupConstructorsLayout->setMargin( 11 );
85 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
86 Constructor1->setText( tr( "" ) );
87 Constructor1->setPixmap( image1 );
88 Constructor1->setChecked( TRUE );
89 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
90 Constructor1->setMinimumSize( QSize( 50, 0 ) );
91 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
92 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
93 GroupConstructorsLayout->addItem( spacer, 0, 1 );
94 SMESHGUI_AddSubMeshDlgLayout->addWidget( GroupConstructors, 0, 0 );
96 /***************************************************************/
97 GroupButtons = new QGroupBox( this, "GroupButtons" );
98 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
99 GroupButtons->setTitle( tr( "" ) );
100 GroupButtons->setColumnLayout(0, Qt::Vertical );
101 GroupButtons->layout()->setSpacing( 0 );
102 GroupButtons->layout()->setMargin( 0 );
103 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
104 GroupButtonsLayout->setAlignment( Qt::AlignTop );
105 GroupButtonsLayout->setSpacing( 6 );
106 GroupButtonsLayout->setMargin( 11 );
107 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
108 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
109 buttonCancel->setAutoDefault( TRUE );
110 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
111 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
112 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
113 buttonApply->setAutoDefault( TRUE );
114 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
115 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
116 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
117 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
118 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
119 buttonOk->setAutoDefault( TRUE );
120 buttonOk->setDefault( TRUE );
121 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
122 SMESHGUI_AddSubMeshDlgLayout->addWidget( GroupButtons, 2, 0 );
124 /***************************************************************/
125 GroupC1 = new QGroupBox( this, "GroupC1" );
126 GroupC1->setTitle( tr( "SMESH_ARGUMENTS" ) );
127 GroupC1->setMinimumSize( QSize( 0, 0 ) );
128 GroupC1->setFrameShape( QGroupBox::Box );
129 GroupC1->setFrameShadow( QGroupBox::Sunken );
130 GroupC1->setColumnLayout(0, Qt::Vertical );
131 GroupC1->layout()->setSpacing( 0 );
132 GroupC1->layout()->setMargin( 0 );
133 GroupC1Layout = new QGridLayout( GroupC1->layout() );
134 GroupC1Layout->setAlignment( Qt::AlignTop );
135 GroupC1Layout->setSpacing( 6 );
136 GroupC1Layout->setMargin( 11 );
138 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
139 TextLabelC1A1->setText( tr( "SMESH_OBJECT_MESH" ) );
140 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
141 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
142 TextLabelC1A1->setFrameShadow( QLabel::Plain );
143 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
144 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
145 SelectButtonC1A1->setText( tr( "" ) );
146 SelectButtonC1A1->setPixmap( image0 );
147 SelectButtonC1A1->setToggleButton( FALSE );
148 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
149 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
150 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
152 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
153 TextLabelC1A2->setText( tr( "SMESH_OBJECT_GEOM" ) );
154 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
155 TextLabelC1A2->setFrameShape( QLabel::NoFrame );
156 TextLabelC1A2->setFrameShadow( QLabel::Plain );
157 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
158 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
159 SelectButtonC1A2->setText( tr( "" ) );
160 SelectButtonC1A2->setPixmap( image0 );
161 SelectButtonC1A2->setToggleButton( FALSE );
162 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
163 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
164 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
166 TextLabel_NameMesh = new QLabel( GroupC1, "TextLabel_NameMesh" );
167 TextLabel_NameMesh->setText( tr( "SMESH_NAME" ) );
168 GroupC1Layout->addWidget( TextLabel_NameMesh, 2, 0 );
169 LineEdit_NameMesh = new QLineEdit( GroupC1, "LineEdit_NameMesh" );
170 GroupC1Layout->addWidget( LineEdit_NameMesh, 2, 2 );
172 TextLabelC1A1Hyp = new QLabel( GroupC1, "TextLabelC1A1Hyp" );
173 TextLabelC1A1Hyp->setText( tr( "SMESH_OBJECT_HYPOTHESIS" ) );
174 TextLabelC1A1Hyp->setMinimumSize( QSize( 50, 0 ) );
175 TextLabelC1A1Hyp->setFrameShape( QLabel::NoFrame );
176 TextLabelC1A1Hyp->setFrameShadow( QLabel::Plain );
177 GroupC1Layout->addWidget( TextLabelC1A1Hyp, 3, 0 );
178 SelectButtonC1A1Hyp = new QPushButton( GroupC1, "SelectButtonC1A1Hyp" );
179 SelectButtonC1A1Hyp->setText( tr( "" ) );
180 SelectButtonC1A1Hyp->setPixmap( image0 );
181 GroupC1Layout->addWidget( SelectButtonC1A1Hyp, 3, 1 );
182 LineEditC1A1Hyp = new QLineEdit( GroupC1, "LineEditC1A1Hyp" );
183 LineEditC1A1Hyp->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Hyp->sizePolicy().hasHeightForWidth() ) );
184 GroupC1Layout->addWidget( LineEditC1A1Hyp, 3, 2 );
186 TextLabelC1A1Algo = new QLabel( GroupC1, "TextLabelC1A1Algo" );
187 TextLabelC1A1Algo->setText( tr( "SMESH_OBJECT_ALGORITHM" ) );
188 TextLabelC1A1Algo->setMinimumSize( QSize( 50, 0 ) );
189 TextLabelC1A1Algo->setFrameShape( QLabel::NoFrame );
190 TextLabelC1A1Algo->setFrameShadow( QLabel::Plain );
191 GroupC1Layout->addWidget( TextLabelC1A1Algo, 4, 0 );
192 SelectButtonC1A1Algo = new QPushButton( GroupC1, "SelectButtonC1A1Algo" );
193 SelectButtonC1A1Algo->setText( tr( "" ) );
194 SelectButtonC1A1Algo->setPixmap( image0 );
195 GroupC1Layout->addWidget( SelectButtonC1A1Algo, 4, 1 );
196 LineEditC1A1Algo = new QLineEdit( GroupC1, "LineEditC1A1Algo" );
197 LineEditC1A1Algo->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Algo->sizePolicy().hasHeightForWidth() ) );
198 GroupC1Layout->addWidget( LineEditC1A1Algo, 4, 2 );
200 SMESHGUI_AddSubMeshDlgLayout->addWidget( GroupC1, 1, 0 );
201 /***************************************************************/
207 //=================================================================================
208 // function : ~SMESHGUI_AddSubMeshDlg()
209 // purpose : Destroys the object and frees any allocated resources
210 //=================================================================================
211 SMESHGUI_AddSubMeshDlg::~SMESHGUI_AddSubMeshDlg()
213 // no need to delete child widgets, Qt does it all for us
217 //=================================================================================
220 //=================================================================================
221 void SMESHGUI_AddSubMeshDlg::Init( SALOME_Selection* Sel )
224 myConstructorId = 0 ;
225 Constructor1->setChecked( TRUE );
226 myEditCurrentArgument = LineEditC1A1 ;
228 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
229 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
231 myGeomFilter = new SALOME_TypeFilter( "GEOM" );
232 myMeshFilter = new SMESH_TypeFilter( MESH );
234 myAlgorithmFilter = new SMESH_TypeFilter( ALGORITHM );
235 myHypothesisFilter = new SMESH_TypeFilter( HYPOTHESIS );
237 myNameSubMesh = "SubMesh";
239 myGeomShape = GEOM::GEOM_Shape::_nil();
240 myMesh = SMESH::SMESH_Mesh::_nil();
242 /* signals and slots connections */
243 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
244 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
245 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
246 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
248 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
249 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
250 connect( LineEdit_NameMesh, SIGNAL (textChanged(const QString&) ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
252 connect( SelectButtonC1A1Hyp, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
253 connect( SelectButtonC1A1Algo, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
255 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
256 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
257 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
260 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
264 SelectionIntoArgument();
270 //=================================================================================
271 // function : ConstructorsClicked()
272 // purpose : Radio button management
273 //=================================================================================
274 void SMESHGUI_AddSubMeshDlg::ConstructorsClicked(int constructorId)
279 //=================================================================================
280 // function : ClickOnOk()
282 //=================================================================================
283 void SMESHGUI_AddSubMeshDlg::ClickOnOk()
285 this->ClickOnApply() ;
286 this->ClickOnCancel() ;
289 //=================================================================================
290 // function : ClickOnApply()
292 //=================================================================================
293 void SMESHGUI_AddSubMeshDlg::ClickOnApply()
295 switch(myConstructorId)
299 if ( !myNameSubMesh.isEmpty() && !myNameSubMesh.isNull() &&
300 !myGeomShape->_is_nil() && !myMesh->_is_nil()) {
301 mySubMesh = mySMESHGUI->AddSubMesh( myMesh, myGeomShape, myNameSubMesh ) ;
304 if( myOkHypothesis && !mySubMesh->_is_nil() ) {
305 SALOME_ListIteratorOfListIO It( HypoList );
306 for(;It.More();It.Next()) {
307 Handle(SALOME_InteractiveObject) IObject = It.Value();
308 Standard_Boolean testResult;
309 myHypothesis = mySMESHGUI->ConvertIOinSMESHHypothesis(IObject, testResult) ;
311 mySMESHGUI->AddHypothesisOnSubMesh(mySubMesh, myHypothesis) ;
315 if( myOkAlgorithm && !mySubMesh->_is_nil() ) {
316 SALOME_ListIteratorOfListIO It( AlgoList );
317 for(;It.More();It.Next()) {
318 Handle(SALOME_InteractiveObject) IObject = It.Value();
319 Standard_Boolean testResult;
320 myAlgorithm = mySMESHGUI->ConvertIOinSMESHHypothesis(IObject, testResult) ;
322 mySMESHGUI->AddAlgorithmOnSubMesh(mySubMesh, myAlgorithm) ;
332 //=================================================================================
333 // function : ClickOnCancel()
335 //=================================================================================
336 void SMESHGUI_AddSubMeshDlg::ClickOnCancel()
338 disconnect( mySelection, 0, this, 0 );
339 mySMESHGUI->ResetState() ;
340 mySelection->ClearFilters() ;
346 //=================================================================================
347 // function : SelectionIntoArgument()
348 // purpose : Called when selection as changed or other case
349 //=================================================================================
350 void SMESHGUI_AddSubMeshDlg::SelectionIntoArgument()
352 myEditCurrentArgument->setText("") ;
353 QString aString = "";
355 int nbSel = mySMESHGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
357 switch (myConstructorId)
361 if ( myEditCurrentArgument == LineEditC1A1 ) {
363 myOkHypothesis = false;
364 myOkAlgorithm = false;
367 Standard_Boolean testResult ;
368 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
369 myMesh = mySMESHGUI->ConvertIOinMesh(IO, testResult) ;
371 myMesh = SMESH::SMESH_Mesh::_nil();
375 } else if ( myEditCurrentArgument == LineEditC1A2 ) {
377 myOkHypothesis = false;
378 myOkAlgorithm = false;
381 Standard_Boolean testResult ;
382 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
383 myGeomShape = mySMESHGUI->ConvertIOinGEOMShape(IO, testResult) ;
385 myGeomShape = GEOM::GEOM_Shape::_nil();
389 } else if ( myEditCurrentArgument == LineEditC1A1Hyp ) {
392 SALOME_ListIteratorOfListIO Itinit( mySelection->StoredIObjects() );
393 for (; Itinit.More(); Itinit.Next()) {
394 HypoList.Append(Itinit.Value());
396 myOkHypothesis = true ;
398 aString = tr("%1 Hypothesis").arg(nbSel) ;
399 LineEditC1A1Hyp->setText(aString) ;
402 myOkHypothesis = false ;
405 } else if ( myEditCurrentArgument == LineEditC1A1Algo ) {
408 SALOME_ListIteratorOfListIO Itinit( mySelection->StoredIObjects() );
409 for (; Itinit.More(); Itinit.Next()) {
410 AlgoList.Append(Itinit.Value());
412 myOkAlgorithm = true ;
414 aString = tr("%1 Algorithms").arg(nbSel) ;
415 LineEditC1A1Algo->setText(aString) ;
418 myOkAlgorithm = false ;
426 myEditCurrentArgument->setText(aString) ;
430 //=================================================================================
431 // function : SetEditCurrentArgument()
433 //=================================================================================
434 void SMESHGUI_AddSubMeshDlg::SetEditCurrentArgument()
436 QPushButton* send = (QPushButton*)sender();
437 switch (myConstructorId)
439 case 0: /* default constructor */
441 if(send == SelectButtonC1A1) {
442 LineEditC1A1->setFocus() ;
443 myEditCurrentArgument = LineEditC1A1;
444 mySelection->ClearFilters() ;
445 mySelection->AddFilter(myMeshFilter) ;
446 } else if (send == SelectButtonC1A2) {
447 LineEditC1A2->setFocus() ;
448 myEditCurrentArgument = LineEditC1A2;
449 mySelection->ClearFilters() ;
450 mySelection->AddFilter(myGeomFilter) ;
451 } else if( send == SelectButtonC1A1Hyp ) {
452 LineEditC1A1Hyp->setFocus() ;
453 myEditCurrentArgument = LineEditC1A1Hyp ;
454 mySelection->ClearFilters() ;
455 mySelection->AddFilter(myHypothesisFilter) ;
456 } else if( send == SelectButtonC1A1Algo ) {
457 LineEditC1A1Algo->setFocus() ;
458 myEditCurrentArgument = LineEditC1A1Algo ;
459 mySelection->ClearFilters() ;
460 mySelection->AddFilter(myAlgorithmFilter) ;
462 SelectionIntoArgument() ;
469 //=================================================================================
470 // function : DeactivateActiveDialog()
472 //=================================================================================
473 void SMESHGUI_AddSubMeshDlg::DeactivateActiveDialog()
475 if ( GroupConstructors->isEnabled() ) {
476 disconnect( mySelection, 0, this, 0 );
477 GroupConstructors->setEnabled(false) ;
478 GroupC1->setEnabled(false) ;
479 GroupButtons->setEnabled(false) ;
484 //=================================================================================
485 // function : ActivateThisDialog()
487 //=================================================================================
488 void SMESHGUI_AddSubMeshDlg::ActivateThisDialog()
490 mySMESHGUI->EmitSignalDeactivateDialog() ;
491 GroupConstructors->setEnabled(true) ;
492 GroupC1->setEnabled(true) ;
493 GroupButtons->setEnabled(true) ;
494 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
499 //=================================================================================
500 // function : enterEvent()
502 //=================================================================================
503 void SMESHGUI_AddSubMeshDlg::enterEvent(QEvent* e)
505 if ( GroupConstructors->isEnabled() )
507 ActivateThisDialog() ;
512 //=================================================================================
513 // function : closeEvent()
515 //=================================================================================
516 void SMESHGUI_AddSubMeshDlg::closeEvent( QCloseEvent* e )
518 this->ClickOnCancel() ;
522 //=================================================================================
523 // function : TextChangedInLineEdit()
525 //=================================================================================
526 void SMESHGUI_AddSubMeshDlg::TextChangedInLineEdit(const QString& newText)
528 QLineEdit* send = (QLineEdit*)sender();
529 QString newT = strdup(newText) ;
531 if (send == LineEdit_NameMesh) {
532 myNameSubMesh = newText;