1 // SMESH StdMeshersGUI : GUI for StdMeshers plugin
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_CreateHypothesisDlg.cxx
25 // Moved here from SMESHGUI_CreateHypothesisDlg.cxx
26 // Author : Nicolas REJNERI
30 #include "StdMeshersGUI_CreateHypothesisDlg.h"
31 #include "StdMeshersGUI_Parameters.h"
33 #include "SMESHGUI_SpinBox.h"
34 #include "SMESHGUI_Hypotheses.h"
35 #include "SMESHGUI_HypothesesUtils.h"
36 #include "SMESHGUI_Utils.h"
38 #include "QAD_Application.h"
39 #include "QAD_Desktop.h"
40 #include "utilities.h"
42 #include "SALOMEGUI_QtCatchCorbaException.hxx"
43 #include "QAD_MessageBox.h"
44 #include "QAD_WaitCursor.h"
47 #include <qgroupbox.h>
49 #include <qlineedit.h>
50 #include <qpushbutton.h>
57 //=================================================================================
58 // class : StdMeshersGUI_CreateHypothesisDlg()
59 // purpose : Constructs a StdMeshersGUI_CreateHypothesisDlg which is a child of 'parent', with the
60 // name 'name' and widget flags set to 'f'.
61 // The dialog will by default be modeless, unless you set 'modal' to
62 // TRUE to construct a modal dialog.
63 //=================================================================================
64 StdMeshersGUI_CreateHypothesisDlg::StdMeshersGUI_CreateHypothesisDlg (const QString& hypType,
69 : QDialog (parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose), myHypType( hypType )
73 //=======================================================================
74 //function : CreateDlgLayout
76 //=======================================================================
78 void StdMeshersGUI_CreateHypothesisDlg::CreateDlgLayout(const QString & theCaption,
79 const QPixmap & theHypIcon,
80 const QString & theHypTypeName)
82 setCaption( theCaption );
84 setSizeGripEnabled( TRUE );
85 QGridLayout* StdMeshersGUI_CreateHypothesisDlgLayout = new QGridLayout( this );
86 StdMeshersGUI_CreateHypothesisDlgLayout->setSpacing( 6 );
87 StdMeshersGUI_CreateHypothesisDlgLayout->setMargin( 11 );
89 /***************************************************************/
90 iconLabel = new QLabel( this );
91 iconLabel->setPixmap( theHypIcon );
92 iconLabel->setScaledContents( false );
93 iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
94 typeLabel = new QLabel( this );
95 typeLabel->setText( theHypTypeName );
96 StdMeshersGUI_CreateHypothesisDlgLayout->addWidget( iconLabel, 0, 0 );
97 StdMeshersGUI_CreateHypothesisDlgLayout->addWidget( typeLabel, 0, 1 );
99 /***************************************************************/
100 GroupC1 = new QGroupBox( this, "GroupC1" );
101 GroupC1->setTitle( tr( "SMESH_ARGUMENTS" ) );
102 GroupC1->setColumnLayout(0, Qt::Vertical );
103 GroupC1->layout()->setSpacing( 0 );
104 GroupC1->layout()->setMargin( 0 );
105 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
106 GroupC1Layout->setAlignment( Qt::AlignTop );
107 GroupC1Layout->setSpacing( 6 );
108 GroupC1Layout->setMargin( 11 );
110 TextLabel_NameHypothesis = new QLabel( GroupC1, "TextLabel_NameHypothesis" );
111 TextLabel_NameHypothesis->setText( tr( "SMESH_NAME" ) );
112 GroupC1Layout->addWidget( TextLabel_NameHypothesis, 0, 0 );
114 LineEdit_NameHypothesis = new QLineEdit( GroupC1, "LineEdit_NameHypothesis" );
115 GroupC1Layout->addWidget( LineEdit_NameHypothesis, 0, 1 );
118 GetParameters( myHypType, myParamList );
119 ASSERT( !myParamList.empty() );
121 /* Spin boxes with labels */
122 list<SMESHGUI_aParameterPtr>::iterator paramIt = myParamList.begin();
123 for ( int row = 1; paramIt != myParamList.end(); paramIt++ , row++ )
125 SMESHGUI_aParameterPtr param = (*paramIt);
126 QLabel * label = new QLabel( GroupC1, "TextLabel" );
127 GroupC1Layout->addWidget( label, row, 0 );
128 label->setText( param->Label() );
129 QWidget* aSpinWidget;
130 switch ( param->GetType() ) {
131 case SMESHGUI_aParameter::DOUBLE: {
132 SMESHGUI_SpinBox* spin = new SMESHGUI_SpinBox( GroupC1 );
134 spin->setPrecision( 12 );
137 case SMESHGUI_aParameter::INT: {
138 QSpinBox* spin = new QSpinBox( GroupC1 );
144 GroupC1Layout->addWidget( aSpinWidget, row, 1 );
145 aSpinWidget->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );
146 aSpinWidget->setMinimumSize( 150, 0 );
147 param->InitializeWidget( aSpinWidget );
148 mySpinList.push_back( aSpinWidget );
151 StdMeshersGUI_CreateHypothesisDlgLayout->addMultiCellWidget(GroupC1 , 1, 1, 0, 1 );
153 /***************************************************************/
154 GroupButtons = new QGroupBox( this, "GroupButtons" );
155 GroupButtons->setColumnLayout(0, Qt::Vertical );
156 GroupButtons->layout()->setSpacing( 0 );
157 GroupButtons->layout()->setMargin( 0 );
158 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
159 GroupButtonsLayout->setAlignment( Qt::AlignTop );
160 GroupButtonsLayout->setSpacing( 6 );
161 GroupButtonsLayout->setMargin( 11 );
162 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
163 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
164 buttonOk->setAutoDefault( TRUE );
165 buttonOk->setDefault( TRUE );
166 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
167 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
168 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
169 buttonApply->setAutoDefault( TRUE );
170 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
171 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
172 GroupButtonsLayout->addItem( spacer, 0, 2 );
173 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
174 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
175 buttonCancel->setAutoDefault( TRUE );
176 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
177 StdMeshersGUI_CreateHypothesisDlgLayout->addMultiCellWidget( GroupButtons, 2, 2, 0, 1 );
179 /***************************************************************/
184 //=================================================================================
185 // function : ~StdMeshersGUI_CreateHypothesisDlg()
186 // purpose : Destroys the object and frees any allocated resources
187 //=================================================================================
188 StdMeshersGUI_CreateHypothesisDlg::~StdMeshersGUI_CreateHypothesisDlg()
190 // no need to delete child widgets, Qt does it all for us
194 //=================================================================================
197 //=================================================================================
198 void StdMeshersGUI_CreateHypothesisDlg::Init()
200 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
202 char* sHypType = const_cast<char*>(myHypType.latin1());
203 HypothesisData* aHypData = SMESH::GetHypothesisData(sHypType);
204 LineEdit_NameHypothesis->setText( aHypData ? aHypData->Label : QString("") );
206 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
208 /* signals and slots connections */
209 connect( buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()) );
210 connect( buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()) ) ;
211 connect( buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()) );
213 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
214 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
216 /* Move widget on the botton right corner of main widget */
218 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
220 this->show() ; /* displays Dialog */
224 //=================================================================================
225 // function : ClickOnOk()
227 //=================================================================================
228 void StdMeshersGUI_CreateHypothesisDlg::ClickOnOk()
230 if ( ClickOnApply() )
234 //=================================================================================
235 // function : ClickOnApply()
237 //=================================================================================
238 bool StdMeshersGUI_CreateHypothesisDlg::ClickOnApply()
240 if ( !mySMESHGUI || mySMESHGUI->ActiveStudyLocked() )
243 QString myHypName = LineEdit_NameHypothesis->text().stripWhiteSpace();
244 if ( myHypName.isEmpty() ) {
245 QAD_MessageBox::warn1 (this, tr( "SMESH_WRN_WARNING" ),
246 tr( "SMESH_WRN_EMPTY_NAME" ), tr( "SMESH_BUT_OK" ) );
253 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow
254 ( SMESH::CreateHypothesis (myHypType,
256 false )); // isAlgorithm
258 list<SMESHGUI_aParameterPtr>::iterator paramIt = myParamList.begin();
259 list<QWidget*>::iterator widgetIt = mySpinList.begin();
261 paramIt != myParamList.end() && widgetIt != mySpinList.end();
262 paramIt++ , widgetIt++ )
263 (*paramIt)->TakeValue( *widgetIt );
265 SetParameters( Hyp, myParamList );
267 //set new Attribute Comment for hypothesis which parameters were set
268 QString aParams = "";
269 StdMeshersGUI_Parameters::GetParameters( Hyp.in(), myParamList, aParams );
270 SALOMEDS::SObject_var SHyp = SMESH::FindSObject(Hyp.in());
271 if (!SHyp->_is_nil())
272 if (!aParams.isEmpty()) {
273 SMESH::SetValue(SHyp, aParams);
274 mySMESHGUI->GetActiveStudy()->updateObjBrowser(true);
277 catch (const SALOME::SALOME_Exception& S_ex) {
279 QtCatchCorbaException(S_ex);
285 //=================================================================================
286 // function : ClickOnCancel()
288 //=================================================================================
289 void StdMeshersGUI_CreateHypothesisDlg::ClickOnCancel()
294 //=================================================================================
295 // function : DeactivateActiveDialog()
297 //=================================================================================
298 void StdMeshersGUI_CreateHypothesisDlg::DeactivateActiveDialog()
300 // iconLabel->setEnabled(false) ;
301 // typeLabel->setEnabled(false) ;
302 // GroupC1->setEnabled(false) ;
303 // GroupButtons->setEnabled(false) ;
308 //=================================================================================
309 // function : ActivateThisDialog()
311 //=================================================================================
312 void StdMeshersGUI_CreateHypothesisDlg::ActivateThisDialog()
314 if (! isEnabled() ) {
315 mySMESHGUI->EmitSignalDeactivateDialog() ;
316 // iconLabel->setEnabled(true) ;
317 // typeLabel->setEnabled(true) ;
318 // GroupC1->setEnabled(true) ;
319 // GroupButtons->setEnabled(true) ;
325 //=================================================================================
326 // function : enterEvent()
328 //=================================================================================
329 void StdMeshersGUI_CreateHypothesisDlg::enterEvent(QEvent* e)
331 ActivateThisDialog() ;
335 //=================================================================================
336 // function : closeEvent()
338 //=================================================================================
339 void StdMeshersGUI_CreateHypothesisDlg::closeEvent( QCloseEvent* e )
341 mySMESHGUI->ResetState();
342 QDialog::closeEvent( e );