2 #include "SMESHGUI_Hypotheses.h"
4 #include "SMESHGUI_HypothesesUtils.h"
5 #include "SMESHGUI_Utils.h"
6 #include "SMESHGUI_SpinBox.h"
8 #include <SALOMEDSClient_Study.hxx>
11 #include <QtxIntSpinBox.h>
15 #include <qlineedit.h>
18 #include <qgroupbox.h>
20 SMESHGUI_GenericHypothesisCreator::SMESHGUI_GenericHypothesisCreator( const QString& aHypType )
21 : myHypType( aHypType ),
26 SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator()
30 void SMESHGUI_GenericHypothesisCreator::create( const bool isAlgo, QWidget* parent )
32 MESSAGE( "Creation of hypothesis" );
34 // Get default name for hypothesis/algorithm creation
35 HypothesisData* aHypData = SMESH::GetHypothesisData( hypType().latin1() );
36 QString aHypName = aHypData ? aHypData->Label : hypType();
40 // Create hypothesis/algorithm
42 SMESH::CreateHypothesis( hypType(), aHypName, isAlgo );
46 SMESH::SMESH_Hypothesis_var newHypo = SMESH::SMESH_Hypothesis::_narrow
47 ( SMESH::CreateHypothesis( hypType(), aHypName, false ) );
49 if( !editHypothesis( newHypo.in(), parent ) )
50 { //remove just created hypothesis
51 _PTR(SObject) SHyp = SMESH::FindSObject( newHypo.in() );
52 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
53 if( aStudy && !aStudy->GetProperties()->IsLocked() )
55 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
56 aBuilder->RemoveObjectWithChildren( SHyp );
60 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
63 void SMESHGUI_GenericHypothesisCreator::edit( SMESH::SMESH_Hypothesis_ptr h, QWidget* parent )
65 if( CORBA::is_nil( h ) )
68 MESSAGE("Edition of hypothesis");
72 if( !editHypothesis( h, parent ) )
75 SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( h );
76 if( listSOmesh.size() > 0 )
77 for( int i=0; i<listSOmesh.size(); i++ )
79 _PTR(SObject) submSO = listSOmesh[i];
80 SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
81 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
82 if( !aSubMesh->_is_nil() )
83 aMesh = aSubMesh->GetFather();
84 _PTR(SObject) meshSO = SMESH::FindSObject( aMesh );
85 SMESH::ModifiedMesh( meshSO, false);
87 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
90 bool SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ptr h, QWidget* parent )
92 if( CORBA::is_nil( h ) )
96 myHypo = SMESH::SMESH_Hypothesis::_duplicate( h );
97 QFrame* fr = buildFrame();
100 SMESHGUI_HypothesisDlg* dlg =
101 new SMESHGUI_HypothesisDlg( const_cast<SMESHGUI_GenericHypothesisCreator*>( this ), parent );
102 dlg->setCustomFrame( fr );
103 dlg->setCaption( caption() );
104 dlg->setHIcon( icon() );
105 dlg->setType( type() );
107 res = dlg->exec()==QDialog::Accepted;
112 changeWidgets().clear();
113 myHypo = SMESH::SMESH_Hypothesis::_nil();
117 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
119 if( CORBA::is_nil( hypothesis() ) )
122 ListOfStdParams params;
123 if( !stdParams( params ) || params.isEmpty() )
126 QFrame* fr = new QFrame( 0, "myframe" );
127 QVBoxLayout* lay = new QVBoxLayout( fr, 5, 0 );
129 QGroupBox* GroupC1 = new QGroupBox( fr, "GroupC1" );
130 lay->addWidget( GroupC1 );
132 GroupC1->setTitle( tr( "SMESH_ARGUMENTS" ) );
133 GroupC1->setColumnLayout(0, Qt::Vertical );
134 GroupC1->layout()->setSpacing( 0 );
135 GroupC1->layout()->setMargin( 0 );
136 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
137 GroupC1Layout->setAlignment( Qt::AlignTop );
138 GroupC1Layout->setSpacing( 6 );
139 GroupC1Layout->setMargin( 11 );
141 ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end();
142 for( int i=0; anIt!=aLast; anIt++, i++ )
144 QLabel* lab = new QLabel( (*anIt).myName, GroupC1 );
145 GroupC1Layout->addWidget( lab, i, 0 );
147 QWidget* w = getCustomWidget( *anIt, GroupC1 );
149 switch( (*anIt).myValue.type() )
153 QtxIntSpinBox* sb = new QtxIntSpinBox( GroupC1, (*anIt).myName.latin1() );
154 attuneStdWidget( sb, i );
155 sb->setValue( (*anIt).myValue.toInt() );
156 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
160 case QVariant::Double:
162 QtxDblSpinBox* sb = new SMESHGUI_SpinBox( GroupC1, (*anIt).myName.latin1() );
163 attuneStdWidget( sb, i );
164 sb->setValue( (*anIt).myValue.toDouble() );
165 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
169 case QVariant::String:
171 QLineEdit* le = new QLineEdit( GroupC1, (*anIt).myName.latin1() );
172 attuneStdWidget( le, i );
173 le->setText( (*anIt).myValue.toString() );
174 connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
182 GroupC1Layout->addWidget( w, i, 1 );
183 changeWidgets().append( w );
190 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
194 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
199 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
203 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
204 for( ; anIt!=aLast; anIt++ )
206 item.myName = (*anIt)->name();
207 if( (*anIt)->inherits( "QtxIntSpinBox" ) )
209 QtxIntSpinBox* sb = ( QtxIntSpinBox* )( *anIt );
210 item.myValue = sb->value();
211 params.append( item );
214 else if( (*anIt)->inherits( "QtxDblSpinBox" ) )
216 QtxDblSpinBox* sb = ( QtxDblSpinBox* )( *anIt );
217 item.myValue = sb->value();
218 params.append( item );
221 else if( (*anIt)->inherits( "QLineEdit" ) )
223 QLineEdit* line = ( QLineEdit* )( *anIt );
224 item.myValue = line->text();
225 params.append( item );
228 else if ( getParamFromCustomWidget( item, *anIt ))
230 params.append( item );
239 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
244 QString SMESHGUI_GenericHypothesisCreator::hypType() const
249 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
251 return myParamWidgets;
254 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
256 return myParamWidgets;
259 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
264 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
268 QString SMESHGUI_GenericHypothesisCreator::caption() const
273 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
278 QString SMESHGUI_GenericHypothesisCreator::type() const
282 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
283 QWidget* /*parent*/) const
287 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam& , QWidget* ) const
295 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
296 : QtxDialog( parent, "", true, true, QtxDialog::OKCancel ),
299 setMinimumSize( 300, height() );
300 // setFixedSize( 300, height() );
301 myLayout = new QVBoxLayout( mainFrame(), 0, 0 );
303 QFrame* titFrame = new QFrame( mainFrame() );
304 QHBoxLayout* titLay = new QHBoxLayout( titFrame, 0, 5 );
306 myIconLabel = new QLabel( titFrame );
307 myIconLabel->setScaledContents( false );
308 myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
309 myTypeLabel = new QLabel( titFrame );
311 myTypeLabel->setText( creator->hypType() );
313 titLay->addWidget( myIconLabel, 0 );
314 titLay->addWidget( myTypeLabel, 0 );
315 titLay->addStretch( 1 );
317 myLayout->addWidget( titFrame, 0 );
320 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
324 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
328 f->reparent( mainFrame(), QPoint( 0, 0 ) );
329 myLayout->insertWidget( 1, f, 1 );
333 void SMESHGUI_HypothesisDlg::accept()
335 if( !myCreator || myCreator->checkParams() )
339 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
341 myIconLabel->setPixmap( p );
344 void SMESHGUI_HypothesisDlg::setType( const QString& t )
346 myTypeLabel->setText( t );