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 );
148 switch( (*anIt).myValue.type() )
152 QtxIntSpinBox* sb = new QtxIntSpinBox( GroupC1, (*anIt).myName.latin1() );
153 attuneStdWidget( sb, i );
154 sb->setValue( (*anIt).myValue.toInt() );
155 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
159 case QVariant::Double:
161 QtxDblSpinBox* sb = new SMESHGUI_SpinBox( GroupC1, (*anIt).myName.latin1() );
162 attuneStdWidget( sb, i );
163 sb->setValue( (*anIt).myValue.toDouble() );
164 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
168 case QVariant::String:
170 QLineEdit* le = new QLineEdit( GroupC1, (*anIt).myName.latin1() );
171 attuneStdWidget( le, i );
172 le->setText( (*anIt).myValue.toString() );
173 connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
181 GroupC1Layout->addWidget( w, i, 1 );
182 changeWidgets().append( w );
189 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
193 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
198 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
202 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
203 for( ; anIt!=aLast; anIt++ )
205 item.myName = (*anIt)->name();
206 if( (*anIt)->inherits( "QtxIntSpinBox" ) )
208 QtxIntSpinBox* sb = ( QtxIntSpinBox* )( *anIt );
209 item.myValue = sb->value();
210 params.append( item );
213 else if( (*anIt)->inherits( "QtxDblSpinBox" ) )
215 QtxDblSpinBox* sb = ( QtxDblSpinBox* )( *anIt );
216 item.myValue = sb->value();
217 params.append( item );
220 else if( (*anIt)->inherits( "QLineEdit" ) )
222 QLineEdit* line = ( QLineEdit* )( *anIt );
223 item.myValue = line->text();
224 params.append( item );
233 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
238 QString SMESHGUI_GenericHypothesisCreator::hypType() const
243 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
245 return myParamWidgets;
248 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
250 return myParamWidgets;
253 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
258 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
262 QString SMESHGUI_GenericHypothesisCreator::caption() const
267 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
272 QString SMESHGUI_GenericHypothesisCreator::type() const
284 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
285 : QtxDialog( parent, "", true, true, QtxDialog::OKCancel ),
288 setMinimumSize( 300, height() );
289 // setFixedSize( 300, height() );
290 myLayout = new QVBoxLayout( mainFrame(), 0, 0 );
292 QFrame* titFrame = new QFrame( mainFrame() );
293 QHBoxLayout* titLay = new QHBoxLayout( titFrame, 0, 5 );
295 myIconLabel = new QLabel( titFrame );
296 myIconLabel->setScaledContents( false );
297 myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
298 myTypeLabel = new QLabel( titFrame );
300 myTypeLabel->setText( creator->hypType() );
302 titLay->addWidget( myIconLabel, 0 );
303 titLay->addWidget( myTypeLabel, 0 );
304 titLay->addStretch( 1 );
306 myLayout->addWidget( titFrame, 0 );
309 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
313 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
317 f->reparent( mainFrame(), QPoint( 0, 0 ) );
318 myLayout->insertWidget( 1, f, 1 );
322 void SMESHGUI_HypothesisDlg::accept()
324 if( !myCreator || myCreator->checkParams() )
328 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
330 myIconLabel->setPixmap( p );
333 void SMESHGUI_HypothesisDlg::setType( const QString& t )
335 myTypeLabel->setText( t );