X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FStdMeshersGUI%2FStdMeshersGUI_CreateHypothesisDlg.cxx;h=d399b595c901ff70d6edfc5b5cf5129e6a386d95;hb=94bdfc735c8615ab24bb304128c1b3c49bc597f4;hp=90c3632f5e523404dfb4c32c7f20123e34763f6e;hpb=e4737e85f0da6d3f90fd08f6be1c2825195fe16f;p=modules%2Fsmesh.git diff --git a/src/StdMeshersGUI/StdMeshersGUI_CreateHypothesisDlg.cxx b/src/StdMeshersGUI/StdMeshersGUI_CreateHypothesisDlg.cxx index 90c3632f5..d399b595c 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_CreateHypothesisDlg.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_CreateHypothesisDlg.cxx @@ -35,13 +35,16 @@ #include "SMESHGUI_HypothesesUtils.h" #include "SMESHGUI_Utils.h" -#include "QAD_Application.h" -#include "QAD_Desktop.h" +#include "SUIT_Application.h" +#include "SUIT_Desktop.h" +#include "SUIT_MessageBox.h" +#include "SUIT_OverrideCursor.h" #include "utilities.h" -#include "SALOMEGUI_QtCatchCorbaException.hxx" -#include "QAD_MessageBox.h" -#include "QAD_WaitCursor.h" +#include "SalomeApp_Tools.h" +#include "SalomeApp_Application.h" + +#include "OB_Browser.h" // QT Includes #include @@ -51,6 +54,9 @@ #include #include #include +#include +#include +#include using namespace std; @@ -82,19 +88,25 @@ void StdMeshersGUI_CreateHypothesisDlg::CreateDlgLayout(const QString & theCapti setCaption( theCaption ); setSizeGripEnabled( TRUE ); - QGridLayout* StdMeshersGUI_CreateHypothesisDlgLayout = new QGridLayout( this ); + QVBoxLayout* StdMeshersGUI_CreateHypothesisDlgLayout = new QVBoxLayout( this ); StdMeshersGUI_CreateHypothesisDlgLayout->setSpacing( 6 ); StdMeshersGUI_CreateHypothesisDlgLayout->setMargin( 11 ); /***************************************************************/ - iconLabel = new QLabel( this ); + QFrame* titFrame = new QFrame( this ); + QHBoxLayout* titLay = new QHBoxLayout( titFrame, 0, 0 ); + + iconLabel = new QLabel( titFrame ); iconLabel->setPixmap( theHypIcon ); iconLabel->setScaledContents( false ); iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); - typeLabel = new QLabel( this ); + typeLabel = new QLabel( titFrame ); typeLabel->setText( theHypTypeName ); - StdMeshersGUI_CreateHypothesisDlgLayout->addWidget( iconLabel, 0, 0 ); - StdMeshersGUI_CreateHypothesisDlgLayout->addWidget( typeLabel, 0, 1 ); + titLay->addWidget( iconLabel, 0 ); + titLay->addWidget( typeLabel, 0 ); + titLay->addStretch( 1 ); + + StdMeshersGUI_CreateHypothesisDlgLayout->addWidget( titFrame, 0); /***************************************************************/ GroupC1 = new QGroupBox( this, "GroupC1" ); @@ -114,41 +126,42 @@ void StdMeshersGUI_CreateHypothesisDlg::CreateDlgLayout(const QString & theCapti LineEdit_NameHypothesis = new QLineEdit( GroupC1, "LineEdit_NameHypothesis" ); GroupC1Layout->addWidget( LineEdit_NameHypothesis, 0, 1 ); - myParamList.clear(); - GetParameters( myHypType, myParamList ); - ASSERT( !myParamList.empty() ); + myParamMap.clear(); + std::list aParamList; + GetParameters( myHypType, aParamList ); + ASSERT( !aParamList.empty() ); /* Spin boxes with labels */ - list::iterator paramIt = myParamList.begin(); - for ( int row = 1; paramIt != myParamList.end(); paramIt++ , row++ ) + list::iterator paramIt = aParamList.begin(); + for ( int row = 1; paramIt != aParamList.end(); paramIt++ , row++ ) { SMESHGUI_aParameterPtr param = (*paramIt); QLabel * label = new QLabel( GroupC1, "TextLabel" ); GroupC1Layout->addWidget( label, row, 0 ); label->setText( param->Label() ); - QWidget* aSpinWidget; - switch ( param->GetType() ) { - case SMESHGUI_aParameter::DOUBLE: { - SMESHGUI_SpinBox* spin = new SMESHGUI_SpinBox( GroupC1 ); - aSpinWidget = spin; - spin->setPrecision( 12 ); - break; - } - case SMESHGUI_aParameter::INT: { - QSpinBox* spin = new QSpinBox( GroupC1 ); - aSpinWidget = spin; - break; + QWidget* aWidget = param->CreateWidget( GroupC1 ); + + if ( aWidget ) { + GroupC1Layout->addWidget( aWidget, row, 1 ); + aWidget->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); + aWidget->setMinimumSize( 150, 0 ); + + QString sig = param->sigValueChanged(); + if( !sig.isEmpty() && param->GetType()!=SMESHGUI_aParameter::TABLE ) + connect( aWidget, sig.latin1(), this, SLOT( onValueChanged() ) ); + + param->InitializeWidget( aWidget ); + + ParamInfo info; + info.editor = aWidget; + info.label = label; + info.order = row-1; + + myParamMap.insert( param, info ); } - default:; - } - GroupC1Layout->addWidget( aSpinWidget, row, 1 ); - aSpinWidget->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); - aSpinWidget->setMinimumSize( 150, 0 ); - param->InitializeWidget( aSpinWidget ); - mySpinList.push_back( aSpinWidget ); } - StdMeshersGUI_CreateHypothesisDlgLayout->addMultiCellWidget(GroupC1 , 1, 1, 0, 1 ); + StdMeshersGUI_CreateHypothesisDlgLayout->addWidget( GroupC1, 1 ); /***************************************************************/ GroupButtons = new QGroupBox( this, "GroupButtons" ); @@ -174,7 +187,7 @@ void StdMeshersGUI_CreateHypothesisDlg::CreateDlgLayout(const QString & theCapti buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) ); buttonCancel->setAutoDefault( TRUE ); GroupButtonsLayout->addWidget( buttonCancel, 0, 3 ); - StdMeshersGUI_CreateHypothesisDlgLayout->addMultiCellWidget( GroupButtons, 2, 2, 0, 1 ); + StdMeshersGUI_CreateHypothesisDlgLayout->addWidget( GroupButtons, 0 ); /***************************************************************/ Init() ; @@ -197,6 +210,11 @@ StdMeshersGUI_CreateHypothesisDlg::~StdMeshersGUI_CreateHypothesisDlg() //================================================================================= void StdMeshersGUI_CreateHypothesisDlg::Init() { + ParameterMap::const_iterator anIt = myParamMap.begin(), + aLast = myParamMap.end(); + for( ; anIt!=aLast; anIt++ ) + UpdateShown( anIt.key() ); + mySMESHGUI = SMESHGUI::GetSMESHGUI() ; char* sHypType = const_cast(myHypType.latin1()); @@ -216,7 +234,7 @@ void StdMeshersGUI_CreateHypothesisDlg::Init() /* Move widget on the botton right corner of main widget */ int x, y ; mySMESHGUI->DefineDlgPosition( this, x, y ) ; - this->move( x, y ) ; + this->move( x, y ) ; this->show() ; /* displays Dialog */ } @@ -237,46 +255,62 @@ void StdMeshersGUI_CreateHypothesisDlg::ClickOnOk() //================================================================================= bool StdMeshersGUI_CreateHypothesisDlg::ClickOnApply() { - if ( !mySMESHGUI || mySMESHGUI->ActiveStudyLocked() ) + if ( !mySMESHGUI || mySMESHGUI->isActiveStudyLocked() ) return false; QString myHypName = LineEdit_NameHypothesis->text().stripWhiteSpace(); if ( myHypName.isEmpty() ) { - QAD_MessageBox::warn1 (this, tr( "SMESH_WRN_WARNING" ), + SUIT_MessageBox::warn1 (this, tr( "SMESH_WRN_WARNING" ), tr( "SMESH_WRN_EMPTY_NAME" ), tr( "SMESH_BUT_OK" ) ); return false; } - QAD_WaitCursor wc; + SUIT_OverrideCursor wc; + SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow + ( SMESH::CreateHypothesis( myHypType, myHypName, false ) ); // isAlgorithm + try { - SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow - ( SMESH::CreateHypothesis (myHypType, - myHypName, - false )); // isAlgorithm - - list::iterator paramIt = myParamList.begin(); - list::iterator widgetIt = mySpinList.begin(); - for ( ; - paramIt != myParamList.end() && widgetIt != mySpinList.end(); - paramIt++ , widgetIt++ ) - (*paramIt)->TakeValue( *widgetIt ); - SetParameters( Hyp, myParamList ); + list aParamList; + ParameterMap::const_iterator anIt = myParamMap.begin(), + aLast = myParamMap.end(); + for( int i=0; iTakeValue( anIt.data().editor ); + aParamList.push_back( anIt.key() ); + break; + } + + SetParameters( Hyp, aParamList ); //set new Attribute Comment for hypothesis which parameters were set QString aParams = ""; - StdMeshersGUI_Parameters::GetParameters( Hyp.in(), myParamList, aParams ); - SALOMEDS::SObject_var SHyp = SMESH::FindSObject(Hyp.in()); - if (!SHyp->_is_nil()) - if (!aParams.isEmpty()) { - SMESH::SetValue(SHyp, aParams); - mySMESHGUI->GetActiveStudy()->updateObjBrowser(true); - } + StdMeshersGUI_Parameters::GetParameters( Hyp.in(), aParamList, aParams ); + _PTR(SObject) SHyp = SMESH::FindSObject(Hyp.in()); + if (SHyp) + if (!aParams.isEmpty()) + { + SMESH::SetValue(SHyp, aParams); + mySMESHGUI->getApp()->objectBrowser()->updateTree(); + } } - catch (const SALOME::SALOME_Exception& S_ex) { - wc.stop(); - QtCatchCorbaException(S_ex); + catch (const SALOME::SALOME_Exception& S_ex) + { + wc.suspend(); + + _PTR(SObject) SHyp = SMESH::FindSObject(Hyp.in()); + _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); + if( aStudy && !aStudy->GetProperties()->IsLocked() ) + { + _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder(); + aBuilder->RemoveObjectWithChildren( SHyp ); + mySMESHGUI->updateObjBrowser( true, 0 ); + } + + SalomeApp_Tools::QtCatchCorbaException(S_ex); return false; } return true; @@ -341,3 +375,61 @@ void StdMeshersGUI_CreateHypothesisDlg::closeEvent( QCloseEvent* e ) mySMESHGUI->ResetState(); QDialog::closeEvent( e ); } + +//================================================================================= +// function : onValueChanged() +// purpose : +//================================================================================= +void StdMeshersGUI_CreateHypothesisDlg::onValueChanged() +{ + if( sender()->inherits( "QWidget" ) ) + { + QWidget* w = ( QWidget* )sender(); + + SMESHGUI_aParameterPtr param; + + ParameterMap::const_iterator anIt = myParamMap.begin(), + aLast = myParamMap.end(); + for( ; anIt!=aLast; anIt++ ) + if( anIt.data().editor == w ) + { + param = anIt.key(); + param->TakeValue( w ); + UpdateShown( param ); + break; + } + } +} + +//================================================================================= +// function : UpdateShown() +// purpose : +//================================================================================= +void StdMeshersGUI_CreateHypothesisDlg::UpdateShown( const SMESHGUI_aParameterPtr param ) +{ + SMESHGUI_dependParameter* depPar = dynamic_cast( param.get() ); + if( !depPar ) + depPar = dynamic_cast( param.get() ); + + if( !depPar ) + return; + + SMESHGUI_dependParameter::ShownMap& map = depPar->shownMap(); + if( map.isEmpty() ) + return; + + int val; + depPar->TakeValue( myParamMap[ param ].editor ); + depPar->GetNewInt( val ); + + bool hasValue = map.contains( val ); + + ParameterMap::const_iterator anIt = myParamMap.begin(), + aLast = myParamMap.end(); + for( ; anIt!=aLast; anIt++ ) + { + bool shown = hasValue && map[ val ].contains( (*anIt).order ); + (*anIt).editor->setShown( shown ); + (*anIt).label->setShown( shown ); + } +}