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_InitMeshDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "SMESHGUI_InitMeshDlg.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_InitMeshDlg()
55 // purpose : Constructs a SMESHGUI_InitMeshDlg 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_InitMeshDlg::SMESHGUI_InitMeshDlg( 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_INIT_MESH")));
64 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
66 setName( "SMESHGUI_InitMeshDlg" );
68 setCaption( tr( "SMESH_INIT_MESH" ) );
69 setSizeGripEnabled( TRUE );
70 SMESHGUI_InitMeshDlgLayout = new QGridLayout( this );
71 SMESHGUI_InitMeshDlgLayout->setSpacing( 6 );
72 SMESHGUI_InitMeshDlgLayout->setMargin( 11 );
74 /***************************************************************/
75 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
76 GroupConstructors->setTitle( tr( "SMESH_INIT" ) );
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_InitMeshDlgLayout->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_InitMeshDlgLayout->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_GEOM" ) );
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 TextLabel_NameMesh = new QLabel( GroupC1, "TextLabel_NameMesh" );
153 TextLabel_NameMesh->setText( tr( "SMESH_NAME" ) );
154 GroupC1Layout->addWidget( TextLabel_NameMesh, 1, 0 );
155 LineEdit_NameMesh = new QLineEdit( GroupC1, "LineEdit_NameMesh" );
156 GroupC1Layout->addWidget( LineEdit_NameMesh, 1, 2 );
158 TextLabelC1A1Hyp = new QLabel( GroupC1, "TextLabelC1A1Hyp" );
159 TextLabelC1A1Hyp->setText( tr( "SMESH_OBJECT_HYPOTHESIS" ) );
160 TextLabelC1A1Hyp->setMinimumSize( QSize( 50, 0 ) );
161 TextLabelC1A1Hyp->setFrameShape( QLabel::NoFrame );
162 TextLabelC1A1Hyp->setFrameShadow( QLabel::Plain );
163 GroupC1Layout->addWidget( TextLabelC1A1Hyp, 2, 0 );
164 SelectButtonC1A1Hyp = new QPushButton( GroupC1, "SelectButtonC1A1Hyp" );
165 SelectButtonC1A1Hyp->setText( tr( "" ) );
166 SelectButtonC1A1Hyp->setPixmap( image0 );
167 GroupC1Layout->addWidget( SelectButtonC1A1Hyp, 2, 1 );
168 LineEditC1A1Hyp = new QLineEdit( GroupC1, "LineEditC1A1Hyp" );
169 LineEditC1A1Hyp->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Hyp->sizePolicy().hasHeightForWidth() ) );
170 GroupC1Layout->addWidget( LineEditC1A1Hyp, 2, 2 );
172 TextLabelC1A1Algo = new QLabel( GroupC1, "TextLabelC1A1Algo" );
173 TextLabelC1A1Algo->setText( tr( "SMESH_OBJECT_ALGORITHM" ) );
174 TextLabelC1A1Algo->setMinimumSize( QSize( 50, 0 ) );
175 TextLabelC1A1Algo->setFrameShape( QLabel::NoFrame );
176 TextLabelC1A1Algo->setFrameShadow( QLabel::Plain );
177 GroupC1Layout->addWidget( TextLabelC1A1Algo, 3, 0 );
178 SelectButtonC1A1Algo = new QPushButton( GroupC1, "SelectButtonC1A1Algo" );
179 SelectButtonC1A1Algo->setText( tr( "" ) );
180 SelectButtonC1A1Algo->setPixmap( image0 );
181 GroupC1Layout->addWidget( SelectButtonC1A1Algo, 3, 1 );
182 LineEditC1A1Algo = new QLineEdit( GroupC1, "LineEditC1A1Algo" );
183 LineEditC1A1Algo->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Algo->sizePolicy().hasHeightForWidth() ) );
184 GroupC1Layout->addWidget( LineEditC1A1Algo, 3, 2 );
186 SMESHGUI_InitMeshDlgLayout->addWidget( GroupC1, 1, 0 );
187 /***************************************************************/
193 //=================================================================================
194 // function : ~SMESHGUI_InitMeshDlg()
195 // purpose : Destroys the object and frees any allocated resources
196 //=================================================================================
197 SMESHGUI_InitMeshDlg::~SMESHGUI_InitMeshDlg()
199 // no need to delete child widgets, Qt does it all for us
203 //=================================================================================
206 //=================================================================================
207 void SMESHGUI_InitMeshDlg::Init( SALOME_Selection* Sel )
210 myConstructorId = 0 ;
211 Constructor1->setChecked( TRUE );
212 myEditCurrentArgument = LineEditC1A1 ;
214 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
215 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
217 myGeomFilter = new SALOME_TypeFilter( "GEOM" );
218 myAlgorithmFilter = new SMESH_TypeFilter( ALGORITHM );
219 myHypothesisFilter = new SMESH_TypeFilter( HYPOTHESIS );
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( LineEdit_NameMesh, SIGNAL (textChanged(const QString&) ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
232 connect( SelectButtonC1A1Hyp, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
233 connect( SelectButtonC1A1Algo, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
235 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
236 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
237 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
240 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
248 //=================================================================================
249 // function : ConstructorsClicked()
250 // purpose : Radio button management
251 //=================================================================================
252 void SMESHGUI_InitMeshDlg::ConstructorsClicked(int constructorId)
257 //=================================================================================
258 // function : ClickOnOk()
260 //=================================================================================
261 void SMESHGUI_InitMeshDlg::ClickOnOk()
263 this->ClickOnApply() ;
264 this->ClickOnCancel() ;
269 //=================================================================================
270 // function : ClickOnApply()
272 //=================================================================================
273 void SMESHGUI_InitMeshDlg::ClickOnApply()
275 switch(myConstructorId)
279 MESSAGE ( " myNameMesh " << myNameMesh.isEmpty() )
280 MESSAGE ( " myGeomShape " << myGeomShape->_is_nil() )
281 if ( !myNameMesh.isEmpty() && !myNameMesh.isNull() && !myGeomShape->_is_nil() )
282 myMesh = mySMESHGUI->InitMesh( myGeomShape, myNameMesh ) ;
284 MESSAGE ( " myMesh " << myMesh->_is_nil() )
285 MESSAGE ( " myOkHypothesis " )
286 MESSAGE ( " myOkAlgorithm " )
287 if( myOkHypothesis && !myMesh->_is_nil() ) {
288 SALOME_ListIteratorOfListIO It( HypoList );
289 for(;It.More();It.Next()) {
290 Handle(SALOME_InteractiveObject) IObject = It.Value();
291 Standard_Boolean testResult;
292 myHypothesis = mySMESHGUI->ConvertIOinSMESHHypothesis(IObject, testResult) ;
294 mySMESHGUI->AddHypothesisOnMesh(myMesh, myHypothesis) ;
298 if( myOkAlgorithm && !myMesh->_is_nil() ) {
299 SALOME_ListIteratorOfListIO It( AlgoList );
300 for(;It.More();It.Next()) {
301 Handle(SALOME_InteractiveObject) IObject = It.Value();
302 Standard_Boolean testResult;
303 myAlgorithm = mySMESHGUI->ConvertIOinSMESHHypothesis(IObject, testResult) ;
305 mySMESHGUI->AddAlgorithmOnMesh(myMesh, myAlgorithm) ;
314 //=================================================================================
315 // function : ClickOnCancel()
317 //=================================================================================
318 void SMESHGUI_InitMeshDlg::ClickOnCancel()
320 mySelection->ClearFilters() ;
321 disconnect( mySelection, 0, this, 0 );
322 mySMESHGUI->ResetState() ;
328 //=================================================================================
329 // function : SelectionIntoArgument()
330 // purpose : Called when selection as changed or other case
331 //=================================================================================
332 void SMESHGUI_InitMeshDlg::SelectionIntoArgument()
334 myEditCurrentArgument->setText("") ;
335 QString aString = "";
336 int nbSel = mySMESHGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
337 if ( myEditCurrentArgument == LineEditC1A1 ) {
339 myOkHypothesis = false;
340 myOkAlgorithm = false;
341 myGeomShape = GEOM::GEOM_Shape::_nil();
344 Standard_Boolean testResult ;
345 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
346 myGeomShape = mySMESHGUI->ConvertIOinGEOMShape(IO, testResult) ;
348 myOkHypothesis = false;
349 myOkAlgorithm = false;
354 else if ( myEditCurrentArgument == LineEditC1A1Hyp ) {
357 SALOME_ListIteratorOfListIO Itinit( mySelection->StoredIObjects() );
358 for (; Itinit.More(); Itinit.Next()) {
359 HypoList.Append(Itinit.Value());
361 myOkHypothesis = true ;
363 aString = tr("%1 Hypothesis").arg(nbSel) ;
364 LineEditC1A1Hyp->setText(aString) ;
367 myOkHypothesis = false ;
370 } else if ( myEditCurrentArgument == LineEditC1A1Algo ) {
373 SALOME_ListIteratorOfListIO Itinit( mySelection->StoredIObjects() );
374 for (; Itinit.More(); Itinit.Next()) {
375 AlgoList.Append(Itinit.Value());
377 myOkAlgorithm = true ;
379 aString = tr("%1 Algorithms").arg(nbSel) ;
380 LineEditC1A1Algo->setText(aString) ;
383 myOkAlgorithm = false ;
388 myEditCurrentArgument->setText(aString) ;
392 //=================================================================================
393 // function : SetEditCurrentArgument()
395 //=================================================================================
396 void SMESHGUI_InitMeshDlg::SetEditCurrentArgument()
398 QPushButton* send = (QPushButton*)sender();
399 switch (myConstructorId)
401 case 0: /* default constructor */
403 if(send == SelectButtonC1A1) {
404 LineEditC1A1->setFocus() ;
405 myEditCurrentArgument = LineEditC1A1;
406 mySelection->ClearFilters() ;
407 mySelection->AddFilter(myGeomFilter) ;
408 } else if( send == SelectButtonC1A1Hyp ) {
409 LineEditC1A1Hyp->setFocus() ;
410 myEditCurrentArgument = LineEditC1A1Hyp ;
411 mySelection->ClearFilters() ;
412 mySelection->AddFilter(myHypothesisFilter) ;
413 } else if( send == SelectButtonC1A1Algo ) {
414 LineEditC1A1Algo->setFocus() ;
415 myEditCurrentArgument = LineEditC1A1Algo ;
416 mySelection->ClearFilters() ;
417 mySelection->AddFilter(myAlgorithmFilter) ;
419 SelectionIntoArgument() ;
426 //=================================================================================
427 // function : DeactivateActiveDialog()
429 //=================================================================================
430 void SMESHGUI_InitMeshDlg::DeactivateActiveDialog()
432 if ( GroupConstructors->isEnabled() ) {
433 disconnect( mySelection, 0, this, 0 );
434 GroupConstructors->setEnabled(false) ;
435 GroupC1->setEnabled(false) ;
436 GroupButtons->setEnabled(false) ;
441 //=================================================================================
442 // function : ActivateThisDialog()
444 //=================================================================================
445 void SMESHGUI_InitMeshDlg::ActivateThisDialog()
447 mySMESHGUI->EmitSignalDeactivateDialog() ;
448 GroupConstructors->setEnabled(true) ;
449 GroupC1->setEnabled(true) ;
450 GroupButtons->setEnabled(true) ;
451 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
456 //=================================================================================
457 // function : enterEvent()
459 //=================================================================================
460 void SMESHGUI_InitMeshDlg::enterEvent(QEvent* e)
462 if ( GroupConstructors->isEnabled() )
464 ActivateThisDialog() ;
469 //=================================================================================
470 // function : closeEvent()
472 //=================================================================================
473 void SMESHGUI_InitMeshDlg::closeEvent( QCloseEvent* e )
475 this->ClickOnCancel() ;
479 //=================================================================================
480 // function : TextChangedInLineEdit()
482 //=================================================================================
483 void SMESHGUI_InitMeshDlg::TextChangedInLineEdit(const QString& newText)
485 QLineEdit* send = (QLineEdit*)sender();
486 QString newT = strdup(newText) ;
488 if (send == LineEdit_NameMesh) {
489 myNameMesh = newText;