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 "SUIT_Application.h"
39 #include "SUIT_Desktop.h"
40 #include "SUIT_MessageBox.h"
41 #include "SUIT_OverrideCursor.h"
42 #include "utilities.h"
44 #include "SalomeApp_Tools.h"
45 #include "SalomeApp_Application.h"
47 #include "OB_Browser.h"
50 #include <qgroupbox.h>
52 #include <qlineedit.h>
53 #include <qpushbutton.h>
57 #include <qtextedit.h>
61 //=================================================================================
62 // class : StdMeshersGUI_CreateHypothesisDlg()
63 // purpose : Constructs a StdMeshersGUI_CreateHypothesisDlg which is a child of 'parent', with the
64 // name 'name' and widget flags set to 'f'.
65 // The dialog will by default be modeless, unless you set 'modal' to
66 // TRUE to construct a modal dialog.
67 //=================================================================================
68 StdMeshersGUI_CreateHypothesisDlg::StdMeshersGUI_CreateHypothesisDlg (const QString& hypType,
73 : QDialog (parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose), myHypType( hypType )
77 //=======================================================================
78 //function : CreateDlgLayout
80 //=======================================================================
82 void StdMeshersGUI_CreateHypothesisDlg::CreateDlgLayout(const QString & theCaption,
83 const QPixmap & theHypIcon,
84 const QString & theHypTypeName)
86 setCaption( theCaption );
88 setSizeGripEnabled( TRUE );
89 QGridLayout* StdMeshersGUI_CreateHypothesisDlgLayout = new QGridLayout( this );
90 StdMeshersGUI_CreateHypothesisDlgLayout->setSpacing( 6 );
91 StdMeshersGUI_CreateHypothesisDlgLayout->setMargin( 11 );
93 /***************************************************************/
94 iconLabel = new QLabel( this );
95 iconLabel->setPixmap( theHypIcon );
96 iconLabel->setScaledContents( false );
97 iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
98 typeLabel = new QLabel( this );
99 typeLabel->setText( theHypTypeName );
100 StdMeshersGUI_CreateHypothesisDlgLayout->addWidget( iconLabel, 0, 0 );
101 StdMeshersGUI_CreateHypothesisDlgLayout->addWidget( typeLabel, 0, 1 );
103 /***************************************************************/
104 GroupC1 = new QGroupBox( this, "GroupC1" );
105 GroupC1->setTitle( tr( "SMESH_ARGUMENTS" ) );
106 GroupC1->setColumnLayout(0, Qt::Vertical );
107 GroupC1->layout()->setSpacing( 0 );
108 GroupC1->layout()->setMargin( 0 );
109 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
110 GroupC1Layout->setAlignment( Qt::AlignTop );
111 GroupC1Layout->setSpacing( 6 );
112 GroupC1Layout->setMargin( 11 );
114 TextLabel_NameHypothesis = new QLabel( GroupC1, "TextLabel_NameHypothesis" );
115 TextLabel_NameHypothesis->setText( tr( "SMESH_NAME" ) );
116 GroupC1Layout->addWidget( TextLabel_NameHypothesis, 0, 0 );
118 LineEdit_NameHypothesis = new QLineEdit( GroupC1, "LineEdit_NameHypothesis" );
119 GroupC1Layout->addWidget( LineEdit_NameHypothesis, 0, 1 );
122 GetParameters( myHypType, myParamList );
123 ASSERT( !myParamList.empty() );
125 /* Spin boxes with labels */
126 list<SMESHGUI_aParameterPtr>::iterator paramIt = myParamList.begin();
127 for ( int row = 1; paramIt != myParamList.end(); paramIt++ , row++ )
129 SMESHGUI_aParameterPtr param = (*paramIt);
130 QLabel * label = new QLabel( GroupC1, "TextLabel" );
131 GroupC1Layout->addWidget( label, row, 0 );
132 label->setText( param->Label() );
133 QWidget* aSpinWidget = 0;
134 switch ( param->GetType() ) {
135 case SMESHGUI_aParameter::DOUBLE: {
136 SMESHGUI_SpinBox* spin = new SMESHGUI_SpinBox( GroupC1 );
138 spin->setPrecision( 12 );
141 case SMESHGUI_aParameter::INT: {
142 QSpinBox* spin = new QSpinBox( GroupC1 );
146 case SMESHGUI_aParameter::TEXT: {
147 QTextEdit* edit = new QTextEdit( GroupC1 );
148 edit->setWordWrap( QTextEdit::NoWrap );
149 edit->setTextFormat( Qt::PlainText );
157 GroupC1Layout->addWidget( aSpinWidget, row, 1 );
158 aSpinWidget->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );
159 aSpinWidget->setMinimumSize( 150, 0 );
160 param->InitializeWidget( aSpinWidget );
161 mySpinList.push_back( aSpinWidget );
165 StdMeshersGUI_CreateHypothesisDlgLayout->addMultiCellWidget(GroupC1 , 1, 1, 0, 1 );
167 /***************************************************************/
168 GroupButtons = new QGroupBox( this, "GroupButtons" );
169 GroupButtons->setColumnLayout(0, Qt::Vertical );
170 GroupButtons->layout()->setSpacing( 0 );
171 GroupButtons->layout()->setMargin( 0 );
172 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
173 GroupButtonsLayout->setAlignment( Qt::AlignTop );
174 GroupButtonsLayout->setSpacing( 6 );
175 GroupButtonsLayout->setMargin( 11 );
176 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
177 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
178 buttonOk->setAutoDefault( TRUE );
179 buttonOk->setDefault( TRUE );
180 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
181 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
182 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
183 buttonApply->setAutoDefault( TRUE );
184 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
185 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
186 GroupButtonsLayout->addItem( spacer, 0, 2 );
187 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
188 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
189 buttonCancel->setAutoDefault( TRUE );
190 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
191 StdMeshersGUI_CreateHypothesisDlgLayout->addMultiCellWidget( GroupButtons, 2, 2, 0, 1 );
193 /***************************************************************/
198 //=================================================================================
199 // function : ~StdMeshersGUI_CreateHypothesisDlg()
200 // purpose : Destroys the object and frees any allocated resources
201 //=================================================================================
202 StdMeshersGUI_CreateHypothesisDlg::~StdMeshersGUI_CreateHypothesisDlg()
204 // no need to delete child widgets, Qt does it all for us
208 //=================================================================================
211 //=================================================================================
212 void StdMeshersGUI_CreateHypothesisDlg::Init()
214 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
216 char* sHypType = const_cast<char*>(myHypType.latin1());
217 HypothesisData* aHypData = SMESH::GetHypothesisData(sHypType);
218 LineEdit_NameHypothesis->setText( aHypData ? aHypData->Label : QString("") );
220 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
222 /* signals and slots connections */
223 connect( buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()) );
224 connect( buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()) ) ;
225 connect( buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()) );
227 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
228 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
230 /* Move widget on the botton right corner of main widget */
232 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
234 this->show() ; /* displays Dialog */
238 //=================================================================================
239 // function : ClickOnOk()
241 //=================================================================================
242 void StdMeshersGUI_CreateHypothesisDlg::ClickOnOk()
244 if ( ClickOnApply() )
248 //=================================================================================
249 // function : ClickOnApply()
251 //=================================================================================
252 bool StdMeshersGUI_CreateHypothesisDlg::ClickOnApply()
254 if ( !mySMESHGUI || mySMESHGUI->isActiveStudyLocked() )
257 QString myHypName = LineEdit_NameHypothesis->text().stripWhiteSpace();
258 if ( myHypName.isEmpty() ) {
259 SUIT_MessageBox::warn1 (this, tr( "SMESH_WRN_WARNING" ),
260 tr( "SMESH_WRN_EMPTY_NAME" ), tr( "SMESH_BUT_OK" ) );
264 SUIT_OverrideCursor wc;
267 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow
268 ( SMESH::CreateHypothesis (myHypType,
270 false )); // isAlgorithm
272 list<SMESHGUI_aParameterPtr>::iterator paramIt = myParamList.begin();
273 list<QWidget*>::iterator widgetIt = mySpinList.begin();
275 paramIt != myParamList.end() && widgetIt != mySpinList.end();
276 paramIt++ , widgetIt++ )
277 (*paramIt)->TakeValue( *widgetIt );
279 SetParameters( Hyp, myParamList );
281 //set new Attribute Comment for hypothesis which parameters were set
282 QString aParams = "";
283 StdMeshersGUI_Parameters::GetParameters( Hyp.in(), myParamList, aParams );
284 _PTR(SObject) SHyp = SMESH::FindSObject(Hyp.in());
286 if (!aParams.isEmpty()) {
287 SMESH::SetValue(SHyp, aParams);
288 mySMESHGUI->getApp()->objectBrowser()->updateTree();
291 catch (const SALOME::SALOME_Exception& S_ex) {
293 SalomeApp_Tools::QtCatchCorbaException(S_ex);
299 //=================================================================================
300 // function : ClickOnCancel()
302 //=================================================================================
303 void StdMeshersGUI_CreateHypothesisDlg::ClickOnCancel()
308 //=================================================================================
309 // function : DeactivateActiveDialog()
311 //=================================================================================
312 void StdMeshersGUI_CreateHypothesisDlg::DeactivateActiveDialog()
314 // iconLabel->setEnabled(false) ;
315 // typeLabel->setEnabled(false) ;
316 // GroupC1->setEnabled(false) ;
317 // GroupButtons->setEnabled(false) ;
322 //=================================================================================
323 // function : ActivateThisDialog()
325 //=================================================================================
326 void StdMeshersGUI_CreateHypothesisDlg::ActivateThisDialog()
328 if (! isEnabled() ) {
329 mySMESHGUI->EmitSignalDeactivateDialog() ;
330 // iconLabel->setEnabled(true) ;
331 // typeLabel->setEnabled(true) ;
332 // GroupC1->setEnabled(true) ;
333 // GroupButtons->setEnabled(true) ;
339 //=================================================================================
340 // function : enterEvent()
342 //=================================================================================
343 void StdMeshersGUI_CreateHypothesisDlg::enterEvent(QEvent* e)
345 ActivateThisDialog() ;
349 //=================================================================================
350 // function : closeEvent()
352 //=================================================================================
353 void StdMeshersGUI_CreateHypothesisDlg::closeEvent( QCloseEvent* e )
355 mySMESHGUI->ResetState();
356 QDialog::closeEvent( e );