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 : StdMeshersGUI_NbSegmentsDlg.cxx
25 // Moved here from SMESHGUI_NbSegmentsDlg.cxx
26 // Author : Nicolas REJNERI
31 #include "StdMeshersGUI_NbSegmentsDlg.h"
34 #include <SALOMEconfig.h>
35 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
37 #include "QAD_Application.h"
38 #include "QAD_Desktop.h"
39 #include "utilities.h"
41 #include "SALOMEGUI_QtCatchCorbaException.hxx"
42 #include "QAD_MessageBox.h"
43 #include "QAD_WaitCursor.h"
46 #include <qgroupbox.h>
48 #include <qlineedit.h>
49 #include <qpushbutton.h>
54 //=================================================================================
55 // class : StdMeshersGUI_NbSegmentsDlg()
56 // purpose : Constructs a StdMeshersGUI_NbSegmentsDlg which is a child of 'parent', with the
57 // name 'name' and widget flags set to 'f'.
58 // The dialog will by default be modeless, unless you set 'modal' to
59 // TRUE to construct a modal dialog.
60 //=================================================================================
61 StdMeshersGUI_NbSegmentsDlg::StdMeshersGUI_NbSegmentsDlg (const QString& hypType,
66 : QDialog (parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
69 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_NB_SEGMENTS")));
72 setName( "StdMeshersGUI_NbSegmentsDlg" );
73 setCaption( tr( "SMESH_NB_SEGMENTS_TITLE" ) );
74 setSizeGripEnabled( TRUE );
75 QGridLayout* StdMeshersGUI_NbSegmentsDlgLayout = new QGridLayout( this );
76 StdMeshersGUI_NbSegmentsDlgLayout->setSpacing( 6 );
77 StdMeshersGUI_NbSegmentsDlgLayout->setMargin( 11 );
79 /***************************************************************/
80 iconLabel = new QLabel( this );
81 iconLabel->setPixmap( image0 );
82 iconLabel->setScaledContents( false );
83 iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
84 typeLabel = new QLabel( this );
85 typeLabel->setText( tr( "SMESH_NB_SEGMENTS_HYPOTHESIS" ) );
86 StdMeshersGUI_NbSegmentsDlgLayout->addWidget( iconLabel, 0, 0 );
87 StdMeshersGUI_NbSegmentsDlgLayout->addWidget( typeLabel, 0, 1 );
89 /***************************************************************/
90 GroupC1 = new QGroupBox( this, "GroupC1" );
91 GroupC1->setTitle( tr( "SMESH_ARGUMENTS" ) );
92 GroupC1->setColumnLayout(0, Qt::Vertical );
93 GroupC1->layout()->setSpacing( 0 );
94 GroupC1->layout()->setMargin( 0 );
95 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
96 GroupC1Layout->setAlignment( Qt::AlignTop );
97 GroupC1Layout->setSpacing( 6 );
98 GroupC1Layout->setMargin( 11 );
100 LineEdit_NameHypothesis = new QLineEdit( GroupC1, "LineEdit_NameHypothesis" );
101 GroupC1Layout->addWidget( LineEdit_NameHypothesis, 0, 1 );
103 TextLabel_NameHypothesis = new QLabel( GroupC1, "TextLabel_NameHypothesis" );
104 TextLabel_NameHypothesis->setText( tr( "SMESH_NAME" ) );
105 GroupC1Layout->addWidget( TextLabel_NameHypothesis, 0, 0 );
107 TextLabel_NbSeg = new QLabel(GroupC1 , "TextLabel_NbSeg" );
108 TextLabel_NbSeg->setText( tr( "SMESH_SEGMENTS" ) );
109 GroupC1Layout->addWidget( TextLabel_NbSeg, 1, 0 );
111 SpinBox_NbSeg = new QSpinBox( GroupC1, "SpinBox_NbSeg" );
112 GroupC1Layout->addWidget( SpinBox_NbSeg, 1, 1 );
114 StdMeshersGUI_NbSegmentsDlgLayout->addMultiCellWidget(GroupC1 , 1, 1, 0, 1 );
116 /***************************************************************/
117 GroupButtons = new QGroupBox( this, "GroupButtons" );
118 GroupButtons->setColumnLayout(0, Qt::Vertical );
119 GroupButtons->layout()->setSpacing( 0 );
120 GroupButtons->layout()->setMargin( 0 );
121 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
122 GroupButtonsLayout->setAlignment( Qt::AlignTop );
123 GroupButtonsLayout->setSpacing( 6 );
124 GroupButtonsLayout->setMargin( 11 );
125 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
126 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
127 buttonOk->setAutoDefault( TRUE );
128 buttonOk->setDefault( TRUE );
129 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
130 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
131 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
132 buttonApply->setAutoDefault( TRUE );
133 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
134 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
135 GroupButtonsLayout->addItem( spacer, 0, 2 );
136 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
137 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
138 buttonCancel->setAutoDefault( TRUE );
139 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
140 StdMeshersGUI_NbSegmentsDlgLayout->addMultiCellWidget( GroupButtons, 2, 2, 0, 1 );
142 /***************************************************************/
147 //=================================================================================
148 // function : ~StdMeshersGUI_NbSegmentsDlg()
149 // purpose : Destroys the object and frees any allocated resources
150 //=================================================================================
151 StdMeshersGUI_NbSegmentsDlg::~StdMeshersGUI_NbSegmentsDlg()
153 // no need to delete child widgets, Qt does it all for us
157 //=================================================================================
160 //=================================================================================
161 void StdMeshersGUI_NbSegmentsDlg::Init()
163 SpinBox_NbSeg->setMinValue( 1 );
164 SpinBox_NbSeg->setMaxValue( 9999 );
165 SpinBox_NbSeg->setValue(3) ; /* myNbSeg */
167 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
169 char* sHypType = (char*)myHypType.latin1();
170 HypothesisData* aHypData = mySMESHGUI->GetHypothesisData(sHypType);
171 LineEdit_NameHypothesis->setText( aHypData ? aHypData->Label : "" );
173 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
175 /* signals and slots connections */
176 connect( buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()) );
177 connect( buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()) ) ;
178 connect( buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()) );
180 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
181 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
183 /* Move widget on the botton right corner of main widget */
185 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
187 this->show() ; /* displays Dialog */
191 //=================================================================================
192 // function : ClickOnOk()
194 //=================================================================================
195 void StdMeshersGUI_NbSegmentsDlg::ClickOnOk()
197 if ( this->ClickOnApply() )
198 this->ClickOnCancel() ;
201 //=================================================================================
202 // function : ClickOnApply()
204 //=================================================================================
205 bool StdMeshersGUI_NbSegmentsDlg::ClickOnApply()
207 QString myHypName = LineEdit_NameHypothesis->text().stripWhiteSpace();
208 if ( myHypName.isEmpty() ) {
209 QAD_MessageBox::warn1( this, tr( "SMESH_WRN_WARNING" ), tr( "SMESH_WRN_EMPTY_NAME" ), tr( "SMESH_BUT_OK" ) );
213 long myNbSeg = SpinBox_NbSeg->value();
217 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow
218 (mySMESHGUI->CreateHypothesis(myHypType,
220 false)); // isAlgorithm
221 StdMeshers::StdMeshers_NumberOfSegments_var NbS =
222 StdMeshers::StdMeshers_NumberOfSegments::_narrow(Hyp);
224 NbS->SetNumberOfSegments(myNbSeg);
226 catch (const SALOME::SALOME_Exception& S_ex) {
228 QtCatchCorbaException(S_ex);
235 //=================================================================================
236 // function : ClickOnCancel()
238 //=================================================================================
239 void StdMeshersGUI_NbSegmentsDlg::ClickOnCancel()
244 //=================================================================================
245 // function : DeactivateActiveDialog()
247 //=================================================================================
248 void StdMeshersGUI_NbSegmentsDlg::DeactivateActiveDialog()
250 iconLabel->setEnabled(false) ;
251 typeLabel->setEnabled(false) ;
252 GroupC1->setEnabled(false) ;
253 GroupButtons->setEnabled(false) ;
257 //=================================================================================
258 // function : ActivateThisDialog()
260 //=================================================================================
261 void StdMeshersGUI_NbSegmentsDlg::ActivateThisDialog()
263 mySMESHGUI->EmitSignalDeactivateDialog() ;
264 iconLabel->setEnabled(true) ;
265 typeLabel->setEnabled(true) ;
266 GroupC1->setEnabled(true) ;
267 GroupButtons->setEnabled(true) ;
271 //=================================================================================
272 // function : enterEvent()
274 //=================================================================================
275 void StdMeshersGUI_NbSegmentsDlg::enterEvent(QEvent* e)
277 ActivateThisDialog() ;
281 //=================================================================================
282 // function : closeEvent()
284 //=================================================================================
285 void StdMeshersGUI_NbSegmentsDlg::closeEvent( QCloseEvent* e )
287 mySMESHGUI->ResetState();
288 QDialog::closeEvent( e );