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>
54 #include <qtextedit.h>
58 //=================================================================================
59 // class : StdMeshersGUI_CreateHypothesisDlg()
60 // purpose : Constructs a StdMeshersGUI_CreateHypothesisDlg which is a child of 'parent', with the
61 // name 'name' and widget flags set to 'f'.
62 // The dialog will by default be modeless, unless you set 'modal' to
63 // TRUE to construct a modal dialog.
64 //=================================================================================
65 StdMeshersGUI_CreateHypothesisDlg::StdMeshersGUI_CreateHypothesisDlg (const QString& hypType,
70 : QDialog (parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose), myHypType( hypType )
74 //=======================================================================
75 //function : CreateDlgLayout
77 //=======================================================================
79 void StdMeshersGUI_CreateHypothesisDlg::CreateDlgLayout(const QString & theCaption,
80 const QPixmap & theHypIcon,
81 const QString & theHypTypeName)
83 setCaption( theCaption );
85 setSizeGripEnabled( TRUE );
86 QGridLayout* StdMeshersGUI_CreateHypothesisDlgLayout = new QGridLayout( this );
87 StdMeshersGUI_CreateHypothesisDlgLayout->setSpacing( 6 );
88 StdMeshersGUI_CreateHypothesisDlgLayout->setMargin( 11 );
90 /***************************************************************/
91 iconLabel = new QLabel( this );
92 iconLabel->setPixmap( theHypIcon );
93 iconLabel->setScaledContents( false );
94 iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
95 typeLabel = new QLabel( this );
96 typeLabel->setText( theHypTypeName );
97 StdMeshersGUI_CreateHypothesisDlgLayout->addWidget( iconLabel, 0, 0 );
98 StdMeshersGUI_CreateHypothesisDlgLayout->addWidget( typeLabel, 0, 1 );
100 /***************************************************************/
101 GroupC1 = new QGroupBox( this, "GroupC1" );
102 GroupC1->setTitle( tr( "SMESH_ARGUMENTS" ) );
103 GroupC1->setColumnLayout(0, Qt::Vertical );
104 GroupC1->layout()->setSpacing( 0 );
105 GroupC1->layout()->setMargin( 0 );
106 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
107 GroupC1Layout->setAlignment( Qt::AlignTop );
108 GroupC1Layout->setSpacing( 6 );
109 GroupC1Layout->setMargin( 11 );
111 TextLabel_NameHypothesis = new QLabel( GroupC1, "TextLabel_NameHypothesis" );
112 TextLabel_NameHypothesis->setText( tr( "SMESH_NAME" ) );
113 GroupC1Layout->addWidget( TextLabel_NameHypothesis, 0, 0 );
115 LineEdit_NameHypothesis = new QLineEdit( GroupC1, "LineEdit_NameHypothesis" );
116 GroupC1Layout->addWidget( LineEdit_NameHypothesis, 0, 1 );
119 GetParameters( myHypType, myParamList );
120 ASSERT( !myParamList.empty() );
122 /* Spin boxes with labels */
123 list<SMESHGUI_aParameterPtr>::iterator paramIt = myParamList.begin();
124 for ( int row = 1; paramIt != myParamList.end(); paramIt++ , row++ )
126 SMESHGUI_aParameterPtr param = (*paramIt);
127 QLabel * label = new QLabel( GroupC1, "TextLabel" );
128 GroupC1Layout->addWidget( label, row, 0 );
129 label->setText( param->Label() );
130 QWidget* aSpinWidget = 0;
131 switch ( param->GetType() ) {
132 case SMESHGUI_aParameter::DOUBLE: {
133 SMESHGUI_SpinBox* spin = new SMESHGUI_SpinBox( GroupC1 );
135 spin->setPrecision( 12 );
138 case SMESHGUI_aParameter::INT: {
139 QSpinBox* spin = new QSpinBox( GroupC1 );
143 case SMESHGUI_aParameter::TEXT: {
144 QTextEdit* edit = new QTextEdit( GroupC1 );
145 edit->setWordWrap( QTextEdit::NoWrap );
146 edit->setTextFormat( Qt::PlainText );
154 GroupC1Layout->addWidget( aSpinWidget, row, 1 );
155 aSpinWidget->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );
156 aSpinWidget->setMinimumSize( 150, 0 );
157 param->InitializeWidget( aSpinWidget );
158 mySpinList.push_back( aSpinWidget );
162 StdMeshersGUI_CreateHypothesisDlgLayout->addMultiCellWidget(GroupC1 , 1, 1, 0, 1 );
164 /***************************************************************/
165 GroupButtons = new QGroupBox( this, "GroupButtons" );
166 GroupButtons->setColumnLayout(0, Qt::Vertical );
167 GroupButtons->layout()->setSpacing( 0 );
168 GroupButtons->layout()->setMargin( 0 );
169 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
170 GroupButtonsLayout->setAlignment( Qt::AlignTop );
171 GroupButtonsLayout->setSpacing( 6 );
172 GroupButtonsLayout->setMargin( 11 );
173 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
174 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
175 buttonOk->setAutoDefault( TRUE );
176 buttonOk->setDefault( TRUE );
177 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
178 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
179 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
180 buttonApply->setAutoDefault( TRUE );
181 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
182 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
183 GroupButtonsLayout->addItem( spacer, 0, 2 );
184 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
185 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
186 buttonCancel->setAutoDefault( TRUE );
187 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
188 StdMeshersGUI_CreateHypothesisDlgLayout->addMultiCellWidget( GroupButtons, 2, 2, 0, 1 );
190 /***************************************************************/
195 //=================================================================================
196 // function : ~StdMeshersGUI_CreateHypothesisDlg()
197 // purpose : Destroys the object and frees any allocated resources
198 //=================================================================================
199 StdMeshersGUI_CreateHypothesisDlg::~StdMeshersGUI_CreateHypothesisDlg()
201 // no need to delete child widgets, Qt does it all for us
205 //=================================================================================
208 //=================================================================================
209 void StdMeshersGUI_CreateHypothesisDlg::Init()
211 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
213 char* sHypType = const_cast<char*>(myHypType.latin1());
214 HypothesisData* aHypData = SMESH::GetHypothesisData(sHypType);
215 LineEdit_NameHypothesis->setText( aHypData ? aHypData->Label : QString("") );
217 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
219 /* signals and slots connections */
220 connect( buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()) );
221 connect( buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()) ) ;
222 connect( buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()) );
224 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
225 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
227 /* Move widget on the botton right corner of main widget */
229 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
231 this->show() ; /* displays Dialog */
235 //=================================================================================
236 // function : ClickOnOk()
238 //=================================================================================
239 void StdMeshersGUI_CreateHypothesisDlg::ClickOnOk()
241 if ( ClickOnApply() )
245 //=================================================================================
246 // function : ClickOnApply()
248 //=================================================================================
249 bool StdMeshersGUI_CreateHypothesisDlg::ClickOnApply()
251 if ( !mySMESHGUI || mySMESHGUI->ActiveStudyLocked() )
254 QString myHypName = LineEdit_NameHypothesis->text().stripWhiteSpace();
255 if ( myHypName.isEmpty() ) {
256 QAD_MessageBox::warn1 (this, tr( "SMESH_WRN_WARNING" ),
257 tr( "SMESH_WRN_EMPTY_NAME" ), tr( "SMESH_BUT_OK" ) );
264 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow
265 ( SMESH::CreateHypothesis (myHypType,
267 false )); // isAlgorithm
269 list<SMESHGUI_aParameterPtr>::iterator paramIt = myParamList.begin();
270 list<QWidget*>::iterator widgetIt = mySpinList.begin();
272 paramIt != myParamList.end() && widgetIt != mySpinList.end();
273 paramIt++ , widgetIt++ )
274 (*paramIt)->TakeValue( *widgetIt );
276 SetParameters( Hyp, myParamList );
278 //set new Attribute Comment for hypothesis which parameters were set
279 QString aParams = "";
280 StdMeshersGUI_Parameters::GetParameters( Hyp.in(), myParamList, aParams );
281 SALOMEDS::SObject_var SHyp = SMESH::FindSObject(Hyp.in());
282 if (!SHyp->_is_nil())
283 if (!aParams.isEmpty()) {
284 SMESH::SetValue(SHyp, aParams);
285 mySMESHGUI->GetActiveStudy()->updateObjBrowser(true);
288 catch (const SALOME::SALOME_Exception& S_ex) {
290 QtCatchCorbaException(S_ex);
296 //=================================================================================
297 // function : ClickOnCancel()
299 //=================================================================================
300 void StdMeshersGUI_CreateHypothesisDlg::ClickOnCancel()
305 //=================================================================================
306 // function : DeactivateActiveDialog()
308 //=================================================================================
309 void StdMeshersGUI_CreateHypothesisDlg::DeactivateActiveDialog()
311 // iconLabel->setEnabled(false) ;
312 // typeLabel->setEnabled(false) ;
313 // GroupC1->setEnabled(false) ;
314 // GroupButtons->setEnabled(false) ;
319 //=================================================================================
320 // function : ActivateThisDialog()
322 //=================================================================================
323 void StdMeshersGUI_CreateHypothesisDlg::ActivateThisDialog()
325 if (! isEnabled() ) {
326 mySMESHGUI->EmitSignalDeactivateDialog() ;
327 // iconLabel->setEnabled(true) ;
328 // typeLabel->setEnabled(true) ;
329 // GroupC1->setEnabled(true) ;
330 // GroupButtons->setEnabled(true) ;
336 //=================================================================================
337 // function : enterEvent()
339 //=================================================================================
340 void StdMeshersGUI_CreateHypothesisDlg::enterEvent(QEvent* e)
342 ActivateThisDialog() ;
346 //=================================================================================
347 // function : closeEvent()
349 //=================================================================================
350 void StdMeshersGUI_CreateHypothesisDlg::closeEvent( QCloseEvent* e )
352 mySMESHGUI->ResetState();
353 QDialog::closeEvent( e );