2 // File : SMESHGUI_AddHypothesisDlg.cxx
3 // Created : Wed May 22 19:05:31 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
12 #include "SMESHGUI_AddHypothesisDlg.h"
13 #include "SALOME_ListIteratorOfListIO.hxx"
16 #include "QAD_Application.h"
17 #include "QAD_Desktop.h"
18 #include "utilities.h"
21 #include <qbuttongroup.h>
23 #include <qgroupbox.h>
25 #include <qlineedit.h>
26 #include <qpushbutton.h>
27 #include <qradiobutton.h>
31 #include <qwhatsthis.h>
37 //=================================================================================
38 // class : SMESHGUI_AddHypothesisDlg()
39 // purpose : Constructs a SMESHGUI_AddHypothesisDlg which is a child of 'parent', with the
40 // name 'name' and widget flags set to 'f'.
41 // The dialog will by default be modeless, unless you set 'modal' to
42 // TRUE to construct a modal dialog.
43 //=================================================================================
44 SMESHGUI_AddHypothesisDlg::SMESHGUI_AddHypothesisDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
45 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
47 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESHGUI",tr("ICON_DLG_ADD_HYPOTHESIS")));
48 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESHGUI",tr("ICON_SELECT")));
51 setName( "SMESHGUI_AddHypothesisDlg" );
53 setCaption( tr( "SMESH_ADD_HYPOTHESIS_TITLE" ) );
54 setSizeGripEnabled( TRUE );
56 SMESHGUI_AddHypothesisDlgLayout = new QGridLayout( this );
57 SMESHGUI_AddHypothesisDlgLayout->setSpacing( 6 );
58 SMESHGUI_AddHypothesisDlgLayout->setMargin( 11 );
60 /***************************************************************/
61 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
62 GroupConstructors->setTitle( tr( "SMESH_ADD_HYPOTHESIS" ) );
63 GroupConstructors->setExclusive( TRUE );
64 GroupConstructors->setColumnLayout(0, Qt::Vertical );
65 GroupConstructors->layout()->setSpacing( 0 );
66 GroupConstructors->layout()->setMargin( 0 );
67 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
68 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
69 GroupConstructorsLayout->setSpacing( 6 );
70 GroupConstructorsLayout->setMargin( 11 );
71 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
72 GroupConstructorsLayout->addItem( spacer, 0, 1 );
73 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
74 Constructor1->setText( tr( "" ) );
75 Constructor1->setPixmap( image0 );
76 Constructor1->setChecked( TRUE );
77 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
78 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
79 SMESHGUI_AddHypothesisDlgLayout->addWidget( GroupConstructors, 0, 0 );
81 /***************************************************************/
82 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
83 GroupConstructor1->setTitle( tr( "SMESH_ARGUMENTS" ) );
84 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
85 GroupConstructor1->layout()->setSpacing( 0 );
86 GroupConstructor1->layout()->setMargin( 0 );
87 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
88 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
89 GroupConstructor1Layout->setSpacing( 6 );
90 GroupConstructor1Layout->setMargin( 11 );
91 LineEditC1A2Mesh = new QLineEdit( GroupConstructor1, "LineEditC1A2Mesh" );
92 LineEditC1A2Mesh->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A2Mesh->sizePolicy().hasHeightForWidth() ) );
93 GroupConstructor1Layout->addWidget( LineEditC1A2Mesh, 1, 2 );
94 LineEditC1A1Hyp = new QLineEdit( GroupConstructor1, "LineEditC1A1Hyp" );
95 LineEditC1A1Hyp->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Hyp->sizePolicy().hasHeightForWidth() ) );
96 GroupConstructor1Layout->addWidget( LineEditC1A1Hyp, 0, 2 );
97 SelectButtonC1A1Hyp = new QPushButton( GroupConstructor1, "SelectButtonC1A1Hyp" );
98 SelectButtonC1A1Hyp->setText( tr( "" ) );
99 SelectButtonC1A1Hyp->setPixmap( image1 );
100 GroupConstructor1Layout->addWidget( SelectButtonC1A1Hyp, 0, 1 );
101 SelectButtonC1A2Mesh = new QPushButton( GroupConstructor1, "SelectButtonC1A2Mesh" );
102 SelectButtonC1A2Mesh->setText( tr( "" ) );
103 SelectButtonC1A2Mesh->setPixmap( image1 );
104 GroupConstructor1Layout->addWidget( SelectButtonC1A2Mesh, 1, 1 );
105 TextLabelC1A2Mesh = new QLabel( GroupConstructor1, "TextLabelC1A2Mesh" );
106 TextLabelC1A2Mesh->setText( tr( "SMESH_OBJECT_MESHorSUBMESH" ) );
107 TextLabelC1A2Mesh->setMinimumSize( QSize( 50, 0 ) );
108 TextLabelC1A2Mesh->setFrameShape( QLabel::NoFrame );
109 TextLabelC1A2Mesh->setFrameShadow( QLabel::Plain );
110 GroupConstructor1Layout->addWidget( TextLabelC1A2Mesh, 1, 0 );
111 TextLabelC1A1Hyp = new QLabel( GroupConstructor1, "TextLabelC1A1Hyp" );
112 TextLabelC1A1Hyp->setText( tr( "SMESH_OBJECT_HYPOTHESIS" ) );
113 TextLabelC1A1Hyp->setMinimumSize( QSize( 50, 0 ) );
114 TextLabelC1A1Hyp->setFrameShape( QLabel::NoFrame );
115 TextLabelC1A1Hyp->setFrameShadow( QLabel::Plain );
116 GroupConstructor1Layout->addWidget( TextLabelC1A1Hyp, 0, 0 );
117 SMESHGUI_AddHypothesisDlgLayout->addWidget( GroupConstructor1, 1, 0 );
119 /***************************************************************/
120 GroupButtons = new QGroupBox( this, "GroupButtons" );
121 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
122 GroupButtons->setTitle( tr( "" ) );
123 GroupButtons->setColumnLayout(0, Qt::Vertical );
124 GroupButtons->layout()->setSpacing( 0 );
125 GroupButtons->layout()->setMargin( 0 );
126 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
127 GroupButtonsLayout->setAlignment( Qt::AlignTop );
128 GroupButtonsLayout->setSpacing( 6 );
129 GroupButtonsLayout->setMargin( 11 );
130 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
131 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
132 buttonCancel->setAutoDefault( TRUE );
133 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
134 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
135 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
136 buttonApply->setAutoDefault( TRUE );
137 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
138 QSpacerItem* spacer_1 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
139 GroupButtonsLayout->addItem( spacer_1, 0, 2 );
140 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
141 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
142 buttonOk->setAutoDefault( TRUE );
143 buttonOk->setDefault( TRUE );
144 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
145 SMESHGUI_AddHypothesisDlgLayout->addWidget( GroupButtons, 2, 0 );
152 //=================================================================================
153 // function : ~SMESHGUI_AddHypothesisDlg()
154 // purpose : Destroys the object and frees any allocated resources
155 //=================================================================================
156 SMESHGUI_AddHypothesisDlg::~SMESHGUI_AddHypothesisDlg()
158 /* no need to delete child widgets, Qt does it all for us */
159 this->destroy(TRUE, TRUE) ;
164 //=================================================================================
167 //=================================================================================
168 void SMESHGUI_AddHypothesisDlg::Init( SALOME_Selection* Sel )
171 myConstructorId = 0 ;
173 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
175 GroupConstructor1->show();
176 myConstructorId = 0 ;
177 myEditCurrentArgument = LineEditC1A1Hyp ;
178 Constructor1->setChecked( TRUE );
179 myOkMesh = myOkSubMesh = myOkHypothesis = false ;
181 myHypothesisFilter = new SMESH_TypeFilter( HYPOTHESIS );
182 myMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
184 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
186 /* signals and slots connections */
187 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
188 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
189 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
190 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
191 connect( SelectButtonC1A1Hyp, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
192 connect( SelectButtonC1A2Mesh, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
193 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
194 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
195 /* to close dialog if study change */
196 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
198 /* Move widget on the botton right corner of main widget */
200 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
202 this->show() ; /* Displays Dialog */
209 //=================================================================================
210 // function : ConstructorsClicked()
211 // purpose : Radio button management
212 //=================================================================================
213 void SMESHGUI_AddHypothesisDlg::ConstructorsClicked(int constructorId)
215 switch (constructorId)
219 GroupConstructor1->show();
220 myConstructorId = constructorId ;
221 myEditCurrentArgument = LineEditC1A1Hyp ;
222 LineEditC1A2Mesh->setText(tr("")) ;
223 Constructor1->setChecked( TRUE );
224 myOkMesh = myOkSubMesh = myOkHypothesis = false ;
231 //=================================================================================
232 // function : ClickOnOk()
234 //=================================================================================
235 void SMESHGUI_AddHypothesisDlg::ClickOnOk()
237 this->ClickOnApply() ;
238 this->ClickOnCancel() ;
243 //=================================================================================
244 // function : ClickOnApply()
246 //=================================================================================
247 void SMESHGUI_AddHypothesisDlg::ClickOnApply()
249 switch(myConstructorId)
253 if(myOkMesh && myOkHypothesis ) {
254 SALOME_ListIteratorOfListIO It( HypoList );
255 for(;It.More();It.Next()) {
256 Handle(SALOME_InteractiveObject) IObject = It.Value();
257 Standard_Boolean testResult;
258 myHypothesis = mySMESHGUI->ConvertIOinSMESHHypothesis(IObject, testResult) ;
260 mySMESHGUI->AddHypothesisOnMesh(myMesh, myHypothesis) ;
262 } else if( myOkSubMesh && myOkHypothesis ) {
263 SALOME_ListIteratorOfListIO It( HypoList );
264 for(;It.More();It.Next()) {
265 Handle(SALOME_InteractiveObject) IObject = It.Value();
266 Standard_Boolean testResult;
267 myHypothesis = mySMESHGUI->ConvertIOinSMESHHypothesis(IObject, testResult) ;
269 mySMESHGUI->AddHypothesisOnSubMesh(mySubMesh, myHypothesis) ;
278 //=================================================================================
279 // function : ClickOnCancel()
281 //=================================================================================
282 void SMESHGUI_AddHypothesisDlg::ClickOnCancel()
284 mySelection->ClearFilters() ;
285 disconnect( mySelection, 0, this, 0 );
286 mySMESHGUI->ResetState() ;
293 //=================================================================================
294 // function : SelectionIntoArgument()
295 // purpose : Called when selection has changed
296 //=================================================================================
297 void SMESHGUI_AddHypothesisDlg::SelectionIntoArgument()
299 myEditCurrentArgument->setText("") ;
300 QString aString = "";
302 int nbSel = mySMESHGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
304 if ( myEditCurrentArgument == LineEditC1A2Mesh ) {
306 Handle(SALOME_InteractiveObject) IObject = mySelection->firstIObject();
307 QString aName = IObject->getName();
308 Standard_Boolean testResult;
310 myMesh = mySMESHGUI->ConvertIOinMesh(IObject, testResult) ;
314 mySubMesh = mySMESHGUI->ConvertIOinSubMesh(IObject, testResult) ;
320 LineEditC1A2Mesh->setText(aString) ;
323 myOkMesh = myOkSubMesh = false ;
327 else if ( myEditCurrentArgument == LineEditC1A1Hyp ) {
329 HypoList.Clear(); // = mySelection->StoredIObjects() ;
330 SALOME_ListIteratorOfListIO Itinit( mySelection->StoredIObjects() );
331 for (; Itinit.More(); Itinit.Next()) {
332 HypoList.Append(Itinit.Value());
334 myOkHypothesis = true ;
336 aString = tr("%1 Hypothesis").arg(nbSel) ;
337 LineEditC1A1Hyp->setText(aString) ;
340 myOkHypothesis = false ;
349 //=================================================================================
350 // function : SetEditCurrentArgument()
352 //=================================================================================
353 void SMESHGUI_AddHypothesisDlg::SetEditCurrentArgument()
355 QPushButton* send = (QPushButton*)sender();
357 switch (myConstructorId)
359 case 0: /* default constructor */
361 if( send == SelectButtonC1A1Hyp ) {
362 myEditCurrentArgument = LineEditC1A1Hyp ;
363 LineEditC1A1Hyp->setFocus() ;
364 mySelection->ClearFilters() ;
365 mySelection->AddFilter(myHypothesisFilter) ;
367 else if(send == SelectButtonC1A2Mesh) {
368 myEditCurrentArgument = LineEditC1A2Mesh;
369 LineEditC1A2Mesh->setFocus() ;
370 mySelection->ClearFilters() ;
371 mySelection->AddFilter(myMeshOrSubMeshFilter) ;
373 SelectionIntoArgument() ;
382 //=================================================================================
383 // function : LineEditReturnPressed()
385 //=================================================================================
386 void SMESHGUI_AddHypothesisDlg::LineEditReturnPressed()
394 //=================================================================================
395 // function : DeactivateActiveDialog()
397 //=================================================================================
398 void SMESHGUI_AddHypothesisDlg::DeactivateActiveDialog()
400 if ( GroupConstructors->isEnabled() ) {
402 GroupConstructors->setEnabled(false) ;
403 GroupConstructor1->setEnabled(false) ;
404 GroupButtons->setEnabled(false) ;
405 disconnect( mySelection, 0, this, 0 );
412 //=================================================================================
413 // function : closeEvent()
415 //=================================================================================
416 void SMESHGUI_AddHypothesisDlg::closeEvent( QCloseEvent* e )
418 this->ClickOnCancel() ; /* same than click on cancel button */
422 //=================================================================================
423 // function : enterEvent()
424 // purpose : when mouse enter onto the QWidget
425 //=================================================================================
426 void SMESHGUI_AddHypothesisDlg::enterEvent( QEvent * )
428 if ( GroupConstructors->isEnabled() )
430 ActivateThisDialog() ;
435 //=================================================================================
436 // function : ActivateThisDialog()
438 //=================================================================================
439 void SMESHGUI_AddHypothesisDlg::ActivateThisDialog()
441 /* Emit a signal to deactivate any active dialog */
442 mySMESHGUI->EmitSignalDeactivateDialog() ;
443 GroupConstructors->setEnabled(true) ;
444 GroupConstructor1->setEnabled(true) ;
445 GroupButtons->setEnabled(true) ;
447 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );