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>
58 #include <qcombobox.h>
59 #include <qcheckbox.h>
63 //=================================================================================
64 // class : StdMeshersGUI_CreateHypothesisDlg()
65 // purpose : Constructs a StdMeshersGUI_CreateHypothesisDlg which is a child of 'parent', with the
66 // name 'name' and widget flags set to 'f'.
67 // The dialog will by default be modeless, unless you set 'modal' to
68 // TRUE to construct a modal dialog.
69 //=================================================================================
70 StdMeshersGUI_CreateHypothesisDlg::StdMeshersGUI_CreateHypothesisDlg (const QString& hypType,
75 : QDialog (parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose), myHypType( hypType )
79 //=======================================================================
80 //function : CreateDlgLayout
82 //=======================================================================
84 void StdMeshersGUI_CreateHypothesisDlg::CreateDlgLayout(const QString & theCaption,
85 const QPixmap & theHypIcon,
86 const QString & theHypTypeName)
88 setCaption( theCaption );
90 setSizeGripEnabled( TRUE );
91 QVBoxLayout* StdMeshersGUI_CreateHypothesisDlgLayout = new QVBoxLayout( this );
92 StdMeshersGUI_CreateHypothesisDlgLayout->setSpacing( 6 );
93 StdMeshersGUI_CreateHypothesisDlgLayout->setMargin( 11 );
95 /***************************************************************/
96 QFrame* titFrame = new QFrame( this );
97 QHBoxLayout* titLay = new QHBoxLayout( titFrame, 0, 0 );
99 iconLabel = new QLabel( titFrame );
100 iconLabel->setPixmap( theHypIcon );
101 iconLabel->setScaledContents( false );
102 iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
103 typeLabel = new QLabel( titFrame );
104 typeLabel->setText( theHypTypeName );
105 titLay->addWidget( iconLabel, 0 );
106 titLay->addWidget( typeLabel, 0 );
107 titLay->addStretch( 1 );
109 StdMeshersGUI_CreateHypothesisDlgLayout->addWidget( titFrame, 0);
111 /***************************************************************/
112 GroupC1 = new QGroupBox( this, "GroupC1" );
113 GroupC1->setTitle( tr( "SMESH_ARGUMENTS" ) );
114 GroupC1->setColumnLayout(0, Qt::Vertical );
115 GroupC1->layout()->setSpacing( 0 );
116 GroupC1->layout()->setMargin( 0 );
117 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
118 GroupC1Layout->setAlignment( Qt::AlignTop );
119 GroupC1Layout->setSpacing( 6 );
120 GroupC1Layout->setMargin( 11 );
122 TextLabel_NameHypothesis = new QLabel( GroupC1, "TextLabel_NameHypothesis" );
123 TextLabel_NameHypothesis->setText( tr( "SMESH_NAME" ) );
124 GroupC1Layout->addWidget( TextLabel_NameHypothesis, 0, 0 );
126 LineEdit_NameHypothesis = new QLineEdit( GroupC1, "LineEdit_NameHypothesis" );
127 GroupC1Layout->addWidget( LineEdit_NameHypothesis, 0, 1 );
130 std::list<SMESHGUI_aParameterPtr> aParamList;
131 GetParameters( myHypType, aParamList );
132 ASSERT( !aParamList.empty() );
134 /* Spin boxes with labels */
135 list<SMESHGUI_aParameterPtr>::iterator paramIt = aParamList.begin();
136 for ( int row = 1; paramIt != aParamList.end(); paramIt++ , row++ )
138 SMESHGUI_aParameterPtr param = (*paramIt);
139 QLabel * label = new QLabel( GroupC1, "TextLabel" );
140 GroupC1Layout->addWidget( label, row, 0 );
141 label->setText( param->Label() );
142 QWidget* aWidget = param->CreateWidget( GroupC1 );
145 GroupC1Layout->addWidget( aWidget, row, 1 );
146 aWidget->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );
147 aWidget->setMinimumSize( 150, 0 );
149 QString sig = param->sigValueChanged();
150 if( !sig.isEmpty() && param->GetType()!=SMESHGUI_aParameter::TABLE )
151 connect( aWidget, sig.latin1(), this, SLOT( onValueChanged() ) );
153 param->InitializeWidget( aWidget );
156 info.editor = aWidget;
160 myParamMap.insert( param, info );
164 StdMeshersGUI_CreateHypothesisDlgLayout->addWidget( GroupC1, 1 );
166 /***************************************************************/
167 GroupButtons = new QGroupBox( this, "GroupButtons" );
168 GroupButtons->setColumnLayout(0, Qt::Vertical );
169 GroupButtons->layout()->setSpacing( 0 );
170 GroupButtons->layout()->setMargin( 0 );
171 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
172 GroupButtonsLayout->setAlignment( Qt::AlignTop );
173 GroupButtonsLayout->setSpacing( 6 );
174 GroupButtonsLayout->setMargin( 11 );
175 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
176 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
177 buttonOk->setAutoDefault( TRUE );
178 buttonOk->setDefault( TRUE );
179 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
180 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
181 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
182 buttonApply->setAutoDefault( TRUE );
183 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
184 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
185 GroupButtonsLayout->addItem( spacer, 0, 2 );
186 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
187 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
188 buttonCancel->setAutoDefault( TRUE );
189 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
190 StdMeshersGUI_CreateHypothesisDlgLayout->addWidget( GroupButtons, 0 );
192 /***************************************************************/
197 //=================================================================================
198 // function : ~StdMeshersGUI_CreateHypothesisDlg()
199 // purpose : Destroys the object and frees any allocated resources
200 //=================================================================================
201 StdMeshersGUI_CreateHypothesisDlg::~StdMeshersGUI_CreateHypothesisDlg()
203 // no need to delete child widgets, Qt does it all for us
207 //=================================================================================
210 //=================================================================================
211 void StdMeshersGUI_CreateHypothesisDlg::Init()
213 ParameterMap::const_iterator anIt = myParamMap.begin(),
214 aLast = myParamMap.end();
215 for( ; anIt!=aLast; anIt++ )
216 UpdateShown( anIt.key() );
218 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
220 char* sHypType = const_cast<char*>(myHypType.latin1());
221 HypothesisData* aHypData = SMESH::GetHypothesisData(sHypType);
222 LineEdit_NameHypothesis->setText( aHypData ? aHypData->Label : QString("") );
224 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
226 /* signals and slots connections */
227 connect( buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()) );
228 connect( buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()) ) ;
229 connect( buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()) );
231 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
232 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
234 /* Move widget on the botton right corner of main widget */
236 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
238 this->show() ; /* displays Dialog */
242 //=================================================================================
243 // function : ClickOnOk()
245 //=================================================================================
246 void StdMeshersGUI_CreateHypothesisDlg::ClickOnOk()
248 if ( ClickOnApply() )
252 //=================================================================================
253 // function : ClickOnApply()
255 //=================================================================================
256 bool StdMeshersGUI_CreateHypothesisDlg::ClickOnApply()
258 if ( !mySMESHGUI || mySMESHGUI->isActiveStudyLocked() )
261 QString myHypName = LineEdit_NameHypothesis->text().stripWhiteSpace();
262 if ( myHypName.isEmpty() ) {
263 SUIT_MessageBox::warn1 (this, tr( "SMESH_WRN_WARNING" ),
264 tr( "SMESH_WRN_EMPTY_NAME" ), tr( "SMESH_BUT_OK" ) );
268 SUIT_OverrideCursor wc;
270 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow
271 ( SMESH::CreateHypothesis( myHypType, myHypName, false ) ); // isAlgorithm
275 list<SMESHGUI_aParameterPtr> aParamList;
276 ParameterMap::const_iterator anIt = myParamMap.begin(),
277 aLast = myParamMap.end();
278 for( int i=0; i<myParamMap.count(); i++ )
279 for( anIt=myParamMap.begin(); anIt!=aLast; anIt++ )
280 if( (*anIt).order==i )
282 anIt.key()->TakeValue( anIt.data().editor );
283 aParamList.push_back( anIt.key() );
287 SetParameters( Hyp, aParamList );
289 //set new Attribute Comment for hypothesis which parameters were set
290 QString aParams = "";
291 StdMeshersGUI_Parameters::GetParameters( Hyp.in(), aParamList, aParams );
292 _PTR(SObject) SHyp = SMESH::FindSObject(Hyp.in());
294 if (!aParams.isEmpty())
296 SMESH::SetValue(SHyp, aParams);
297 mySMESHGUI->getApp()->objectBrowser()->updateTree();
300 catch (const SALOME::SALOME_Exception& S_ex)
304 _PTR(SObject) SHyp = SMESH::FindSObject(Hyp.in());
305 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
306 if( aStudy && !aStudy->GetProperties()->IsLocked() )
308 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
309 aBuilder->RemoveObjectWithChildren( SHyp );
310 mySMESHGUI->updateObjBrowser( true, 0 );
313 SalomeApp_Tools::QtCatchCorbaException(S_ex);
319 //=================================================================================
320 // function : ClickOnCancel()
322 //=================================================================================
323 void StdMeshersGUI_CreateHypothesisDlg::ClickOnCancel()
328 //=================================================================================
329 // function : DeactivateActiveDialog()
331 //=================================================================================
332 void StdMeshersGUI_CreateHypothesisDlg::DeactivateActiveDialog()
334 // iconLabel->setEnabled(false) ;
335 // typeLabel->setEnabled(false) ;
336 // GroupC1->setEnabled(false) ;
337 // GroupButtons->setEnabled(false) ;
342 //=================================================================================
343 // function : ActivateThisDialog()
345 //=================================================================================
346 void StdMeshersGUI_CreateHypothesisDlg::ActivateThisDialog()
348 if (! isEnabled() ) {
349 mySMESHGUI->EmitSignalDeactivateDialog() ;
350 // iconLabel->setEnabled(true) ;
351 // typeLabel->setEnabled(true) ;
352 // GroupC1->setEnabled(true) ;
353 // GroupButtons->setEnabled(true) ;
359 //=================================================================================
360 // function : enterEvent()
362 //=================================================================================
363 void StdMeshersGUI_CreateHypothesisDlg::enterEvent(QEvent* e)
365 ActivateThisDialog() ;
369 //=================================================================================
370 // function : closeEvent()
372 //=================================================================================
373 void StdMeshersGUI_CreateHypothesisDlg::closeEvent( QCloseEvent* e )
375 mySMESHGUI->ResetState();
376 QDialog::closeEvent( e );
379 //=================================================================================
380 // function : onValueChanged()
382 //=================================================================================
383 void StdMeshersGUI_CreateHypothesisDlg::onValueChanged()
385 if( sender()->inherits( "QWidget" ) )
387 QWidget* w = ( QWidget* )sender();
389 SMESHGUI_aParameterPtr param;
391 ParameterMap::const_iterator anIt = myParamMap.begin(),
392 aLast = myParamMap.end();
393 for( ; anIt!=aLast; anIt++ )
394 if( anIt.data().editor == w )
397 param->TakeValue( w );
398 UpdateShown( param );
404 //=================================================================================
405 // function : UpdateShown()
407 //=================================================================================
408 void StdMeshersGUI_CreateHypothesisDlg::UpdateShown( const SMESHGUI_aParameterPtr param )
410 SMESHGUI_dependParameter* depPar = dynamic_cast<SMESHGUI_enumParameter*>( param.get() );
412 depPar = dynamic_cast<SMESHGUI_boolParameter*>( param.get() );
417 SMESHGUI_dependParameter::ShownMap& map = depPar->shownMap();
422 depPar->TakeValue( myParamMap[ param ].editor );
423 depPar->GetNewInt( val );
425 bool hasValue = map.contains( val );
427 ParameterMap::const_iterator anIt = myParamMap.begin(),
428 aLast = myParamMap.end();
429 for( ; anIt!=aLast; anIt++ )
431 bool shown = hasValue && map[ val ].contains( (*anIt).order );
432 (*anIt).editor->setShown( shown );
433 (*anIt).label->setShown( shown );