2 // File : SMESHGUI_InitMeshDlg.cxx
3 // Created : Mon May 27 10:20:11 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
11 #include "SMESHGUI_InitMeshDlg.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_InitMeshDlg()
36 // purpose : Constructs a SMESHGUI_InitMeshDlg 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_InitMeshDlg::SMESHGUI_InitMeshDlg( 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( "SMESHGUI",tr("ICON_DLG_INIT_MESH")));
45 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESHGUI",tr("ICON_SELECT")));
47 setName( "SMESHGUI_InitMeshDlg" );
49 setCaption( tr( "SMESH_INIT_MESH" ) );
50 setSizeGripEnabled( TRUE );
51 SMESHGUI_InitMeshDlgLayout = new QGridLayout( this );
52 SMESHGUI_InitMeshDlgLayout->setSpacing( 6 );
53 SMESHGUI_InitMeshDlgLayout->setMargin( 11 );
55 /***************************************************************/
56 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
57 GroupConstructors->setTitle( tr( "SMESH_INIT" ) );
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_InitMeshDlgLayout->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_InitMeshDlgLayout->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_GEOM" ) );
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 TextLabel_NameMesh = new QLabel( GroupC1, "TextLabel_NameMesh" );
134 TextLabel_NameMesh->setText( tr( "SMESH_NAME" ) );
135 GroupC1Layout->addWidget( TextLabel_NameMesh, 1, 0 );
136 LineEdit_NameMesh = new QLineEdit( GroupC1, "LineEdit_NameMesh" );
137 GroupC1Layout->addWidget( LineEdit_NameMesh, 1, 2 );
139 TextLabelC1A1Hyp = new QLabel( GroupC1, "TextLabelC1A1Hyp" );
140 TextLabelC1A1Hyp->setText( tr( "SMESH_OBJECT_HYPOTHESIS" ) );
141 TextLabelC1A1Hyp->setMinimumSize( QSize( 50, 0 ) );
142 TextLabelC1A1Hyp->setFrameShape( QLabel::NoFrame );
143 TextLabelC1A1Hyp->setFrameShadow( QLabel::Plain );
144 GroupC1Layout->addWidget( TextLabelC1A1Hyp, 2, 0 );
145 SelectButtonC1A1Hyp = new QPushButton( GroupC1, "SelectButtonC1A1Hyp" );
146 SelectButtonC1A1Hyp->setText( tr( "" ) );
147 SelectButtonC1A1Hyp->setPixmap( image0 );
148 GroupC1Layout->addWidget( SelectButtonC1A1Hyp, 2, 1 );
149 LineEditC1A1Hyp = new QLineEdit( GroupC1, "LineEditC1A1Hyp" );
150 LineEditC1A1Hyp->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Hyp->sizePolicy().hasHeightForWidth() ) );
151 GroupC1Layout->addWidget( LineEditC1A1Hyp, 2, 2 );
153 TextLabelC1A1Algo = new QLabel( GroupC1, "TextLabelC1A1Algo" );
154 TextLabelC1A1Algo->setText( tr( "SMESH_OBJECT_ALGORITHM" ) );
155 TextLabelC1A1Algo->setMinimumSize( QSize( 50, 0 ) );
156 TextLabelC1A1Algo->setFrameShape( QLabel::NoFrame );
157 TextLabelC1A1Algo->setFrameShadow( QLabel::Plain );
158 GroupC1Layout->addWidget( TextLabelC1A1Algo, 3, 0 );
159 SelectButtonC1A1Algo = new QPushButton( GroupC1, "SelectButtonC1A1Algo" );
160 SelectButtonC1A1Algo->setText( tr( "" ) );
161 SelectButtonC1A1Algo->setPixmap( image0 );
162 GroupC1Layout->addWidget( SelectButtonC1A1Algo, 3, 1 );
163 LineEditC1A1Algo = new QLineEdit( GroupC1, "LineEditC1A1Algo" );
164 LineEditC1A1Algo->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Algo->sizePolicy().hasHeightForWidth() ) );
165 GroupC1Layout->addWidget( LineEditC1A1Algo, 3, 2 );
167 SMESHGUI_InitMeshDlgLayout->addWidget( GroupC1, 1, 0 );
168 /***************************************************************/
174 //=================================================================================
175 // function : ~SMESHGUI_InitMeshDlg()
176 // purpose : Destroys the object and frees any allocated resources
177 //=================================================================================
178 SMESHGUI_InitMeshDlg::~SMESHGUI_InitMeshDlg()
180 // no need to delete child widgets, Qt does it all for us
184 //=================================================================================
187 //=================================================================================
188 void SMESHGUI_InitMeshDlg::Init( SALOME_Selection* Sel )
191 myConstructorId = 0 ;
192 Constructor1->setChecked( TRUE );
193 myEditCurrentArgument = LineEditC1A1 ;
195 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
196 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
198 myGeomFilter = new SALOME_TypeFilter( "GEOM" );
199 myAlgorithmFilter = new SMESH_TypeFilter( ALGORITHM );
200 myHypothesisFilter = new SMESH_TypeFilter( HYPOTHESIS );
204 /* signals and slots connections */
205 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
206 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
207 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
208 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
210 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
211 connect( LineEdit_NameMesh, SIGNAL (textChanged(const QString&) ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
213 connect( SelectButtonC1A1Hyp, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
214 connect( SelectButtonC1A1Algo, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
216 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
217 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
218 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
221 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
229 //=================================================================================
230 // function : ConstructorsClicked()
231 // purpose : Radio button management
232 //=================================================================================
233 void SMESHGUI_InitMeshDlg::ConstructorsClicked(int constructorId)
238 //=================================================================================
239 // function : ClickOnOk()
241 //=================================================================================
242 void SMESHGUI_InitMeshDlg::ClickOnOk()
244 this->ClickOnApply() ;
245 this->ClickOnCancel() ;
250 //=================================================================================
251 // function : ClickOnApply()
253 //=================================================================================
254 void SMESHGUI_InitMeshDlg::ClickOnApply()
256 switch(myConstructorId)
260 MESSAGE ( " myNameMesh " << myNameMesh.isEmpty() )
261 MESSAGE ( " myGeomShape " << myGeomShape->_is_nil() )
262 if ( !myNameMesh.isEmpty() && !myNameMesh.isNull() && !myGeomShape->_is_nil() )
263 myMesh = mySMESHGUI->InitMesh( myGeomShape, myNameMesh ) ;
265 MESSAGE ( " myMesh " << myMesh->_is_nil() )
266 MESSAGE ( " myOkHypothesis " )
267 MESSAGE ( " myOkAlgorithm " )
268 if( myOkHypothesis && !myMesh->_is_nil() ) {
269 SALOME_ListIteratorOfListIO It( HypoList );
270 for(;It.More();It.Next()) {
271 Handle(SALOME_InteractiveObject) IObject = It.Value();
272 Standard_Boolean testResult;
273 myHypothesis = mySMESHGUI->ConvertIOinSMESHHypothesis(IObject, testResult) ;
275 mySMESHGUI->AddHypothesisOnMesh(myMesh, myHypothesis) ;
279 if( myOkAlgorithm && !myMesh->_is_nil() ) {
280 SALOME_ListIteratorOfListIO It( AlgoList );
281 for(;It.More();It.Next()) {
282 Handle(SALOME_InteractiveObject) IObject = It.Value();
283 Standard_Boolean testResult;
284 myAlgorithm = mySMESHGUI->ConvertIOinSMESHHypothesis(IObject, testResult) ;
286 mySMESHGUI->AddAlgorithmOnMesh(myMesh, myAlgorithm) ;
295 //=================================================================================
296 // function : ClickOnCancel()
298 //=================================================================================
299 void SMESHGUI_InitMeshDlg::ClickOnCancel()
301 mySelection->ClearFilters() ;
302 disconnect( mySelection, 0, this, 0 );
303 mySMESHGUI->ResetState() ;
309 //=================================================================================
310 // function : SelectionIntoArgument()
311 // purpose : Called when selection as changed or other case
312 //=================================================================================
313 void SMESHGUI_InitMeshDlg::SelectionIntoArgument()
315 myEditCurrentArgument->setText("") ;
316 QString aString = "";
317 int nbSel = mySMESHGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
318 if ( myEditCurrentArgument == LineEditC1A1 ) {
320 myOkHypothesis = false;
321 myOkAlgorithm = false;
322 myGeomShape = GEOM::GEOM_Shape::_nil();
325 Standard_Boolean testResult ;
326 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
327 myGeomShape = mySMESHGUI->ConvertIOinGEOMShape(IO, testResult) ;
329 myOkHypothesis = false;
330 myOkAlgorithm = false;
335 else if ( myEditCurrentArgument == LineEditC1A1Hyp ) {
338 SALOME_ListIteratorOfListIO Itinit( mySelection->StoredIObjects() );
339 for (; Itinit.More(); Itinit.Next()) {
340 HypoList.Append(Itinit.Value());
342 myOkHypothesis = true ;
344 aString = tr("%1 Hypothesis").arg(nbSel) ;
345 LineEditC1A1Hyp->setText(aString) ;
348 myOkHypothesis = false ;
351 } else if ( myEditCurrentArgument == LineEditC1A1Algo ) {
354 SALOME_ListIteratorOfListIO Itinit( mySelection->StoredIObjects() );
355 for (; Itinit.More(); Itinit.Next()) {
356 AlgoList.Append(Itinit.Value());
358 myOkAlgorithm = true ;
360 aString = tr("%1 Algorithms").arg(nbSel) ;
361 LineEditC1A1Algo->setText(aString) ;
364 myOkAlgorithm = false ;
369 myEditCurrentArgument->setText(aString) ;
373 //=================================================================================
374 // function : SetEditCurrentArgument()
376 //=================================================================================
377 void SMESHGUI_InitMeshDlg::SetEditCurrentArgument()
379 QPushButton* send = (QPushButton*)sender();
380 switch (myConstructorId)
382 case 0: /* default constructor */
384 if(send == SelectButtonC1A1) {
385 LineEditC1A1->setFocus() ;
386 myEditCurrentArgument = LineEditC1A1;
387 mySelection->ClearFilters() ;
388 mySelection->AddFilter(myGeomFilter) ;
389 } else if( send == SelectButtonC1A1Hyp ) {
390 LineEditC1A1Hyp->setFocus() ;
391 myEditCurrentArgument = LineEditC1A1Hyp ;
392 mySelection->ClearFilters() ;
393 mySelection->AddFilter(myHypothesisFilter) ;
394 } else if( send == SelectButtonC1A1Algo ) {
395 LineEditC1A1Algo->setFocus() ;
396 myEditCurrentArgument = LineEditC1A1Algo ;
397 mySelection->ClearFilters() ;
398 mySelection->AddFilter(myAlgorithmFilter) ;
400 SelectionIntoArgument() ;
407 //=================================================================================
408 // function : DeactivateActiveDialog()
410 //=================================================================================
411 void SMESHGUI_InitMeshDlg::DeactivateActiveDialog()
413 if ( GroupConstructors->isEnabled() ) {
414 disconnect( mySelection, 0, this, 0 );
415 GroupConstructors->setEnabled(false) ;
416 GroupC1->setEnabled(false) ;
417 GroupButtons->setEnabled(false) ;
422 //=================================================================================
423 // function : ActivateThisDialog()
425 //=================================================================================
426 void SMESHGUI_InitMeshDlg::ActivateThisDialog()
428 mySMESHGUI->EmitSignalDeactivateDialog() ;
429 GroupConstructors->setEnabled(true) ;
430 GroupC1->setEnabled(true) ;
431 GroupButtons->setEnabled(true) ;
432 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
437 //=================================================================================
438 // function : enterEvent()
440 //=================================================================================
441 void SMESHGUI_InitMeshDlg::enterEvent(QEvent* e)
443 if ( GroupConstructors->isEnabled() )
445 ActivateThisDialog() ;
450 //=================================================================================
451 // function : closeEvent()
453 //=================================================================================
454 void SMESHGUI_InitMeshDlg::closeEvent( QCloseEvent* e )
456 this->ClickOnCancel() ;
460 //=================================================================================
461 // function : TextChangedInLineEdit()
463 //=================================================================================
464 void SMESHGUI_InitMeshDlg::TextChangedInLineEdit(const QString& newText)
466 QLineEdit* send = (QLineEdit*)sender();
467 QString newT = strdup(newText) ;
469 if (send == LineEdit_NameMesh) {
470 myNameMesh = newText;