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>
13 #include <QtxIntSpinBox.h>
15 #include <SUIT_Session.h>
16 #include <SUIT_MessageBox.h>
18 #include <LightApp_Application.h>
22 #include <qlineedit.h>
25 #include <qgroupbox.h>
27 SMESHGUI_GenericHypothesisCreator::SMESHGUI_GenericHypothesisCreator( const QString& aHypType )
28 : myHypType( aHypType ),
33 SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator()
37 void SMESHGUI_GenericHypothesisCreator::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp,
40 MESSAGE( "Creation of hypothesis with initial params" );
42 if ( !CORBA::is_nil( initParamsHyp ) && hypType() == initParamsHyp->GetName() )
43 myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( initParamsHyp );
44 create( false, parent );
47 void SMESHGUI_GenericHypothesisCreator::create( const bool isAlgo, QWidget* parent )
49 MESSAGE( "Creation of hypothesis" );
51 // Get default name for hypothesis/algorithm creation
52 HypothesisData* aHypData = SMESH::GetHypothesisData( hypType().latin1() );
53 QString aHypName = aHypData ? aHypData->Label : hypType();
57 // Create hypothesis/algorithm
59 SMESH::CreateHypothesis( hypType(), aHypName, isAlgo );
63 SMESH::SMESH_Hypothesis_var newHypo = SMESH::SMESH_Hypothesis::_narrow
64 ( SMESH::CreateHypothesis( hypType(), aHypName, false ) );
66 if( !editHypothesis( newHypo.in(), parent ) )
67 { //remove just created hypothesis
68 _PTR(SObject) SHyp = SMESH::FindSObject( newHypo.in() );
69 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
70 if( aStudy && !aStudy->GetProperties()->IsLocked() )
72 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
73 aBuilder->RemoveObjectWithChildren( SHyp );
77 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
80 void SMESHGUI_GenericHypothesisCreator::edit( SMESH::SMESH_Hypothesis_ptr h, QWidget* parent )
82 if( CORBA::is_nil( h ) )
85 MESSAGE("Edition of hypothesis");
89 if( !editHypothesis( h, parent ) )
92 SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( h );
93 if( listSOmesh.size() > 0 )
94 for( int i=0; i<listSOmesh.size(); i++ )
96 _PTR(SObject) submSO = listSOmesh[i];
97 SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
98 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
99 if( !aSubMesh->_is_nil() )
100 aMesh = aSubMesh->GetFather();
101 _PTR(SObject) meshSO = SMESH::FindSObject( aMesh );
102 SMESH::ModifiedMesh( meshSO, false);
104 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
107 bool SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ptr h, QWidget* parent )
109 if( CORBA::is_nil( h ) )
113 myHypo = SMESH::SMESH_Hypothesis::_duplicate( h );
115 QFrame* fr = buildFrame();
118 SMESHGUI_HypothesisDlg* dlg =
119 new SMESHGUI_HypothesisDlg( const_cast<SMESHGUI_GenericHypothesisCreator*>( this ), parent );
120 dlg->setCustomFrame( fr );
121 dlg->setCaption( caption() );
122 dlg->setHIcon( icon() );
123 dlg->setType( type() );
125 res = dlg->exec()==QDialog::Accepted;
127 QString paramValues = storeParams();
128 if ( !paramValues.isEmpty() ) {
129 if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
130 SMESH::SetValue( SHyp, paramValues );
135 changeWidgets().clear();
136 myHypo = SMESH::SMESH_Hypothesis::_nil();
137 myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
141 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
143 if( CORBA::is_nil( hypothesis() ) )
146 ListOfStdParams params;
147 if( !stdParams( params ) || params.isEmpty() )
150 QFrame* fr = new QFrame( 0, "myframe" );
151 QVBoxLayout* lay = new QVBoxLayout( fr, 5, 0 );
153 QGroupBox* GroupC1 = new QGroupBox( fr, "GroupC1" );
154 lay->addWidget( GroupC1 );
156 GroupC1->setTitle( tr( "SMESH_ARGUMENTS" ) );
157 GroupC1->setColumnLayout(0, Qt::Vertical );
158 GroupC1->layout()->setSpacing( 0 );
159 GroupC1->layout()->setMargin( 0 );
160 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
161 GroupC1Layout->setAlignment( Qt::AlignTop );
162 GroupC1Layout->setSpacing( 6 );
163 GroupC1Layout->setMargin( 11 );
165 ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end();
166 for( int i=0; anIt!=aLast; anIt++, i++ )
168 QLabel* lab = new QLabel( (*anIt).myName, GroupC1 );
169 GroupC1Layout->addWidget( lab, i, 0 );
171 QWidget* w = getCustomWidget( *anIt, GroupC1 );
173 switch( (*anIt).myValue.type() )
177 QtxIntSpinBox* sb = new QtxIntSpinBox( GroupC1, (*anIt).myName.latin1() );
178 attuneStdWidget( sb, i );
179 sb->setValue( (*anIt).myValue.toInt() );
180 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
184 case QVariant::Double:
186 QtxDblSpinBox* sb = new SMESHGUI_SpinBox( GroupC1, (*anIt).myName.latin1() );
187 attuneStdWidget( sb, i );
188 sb->setValue( (*anIt).myValue.toDouble() );
189 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
193 case QVariant::String:
195 QLineEdit* le = new QLineEdit( GroupC1, (*anIt).myName.latin1() );
196 attuneStdWidget( le, i );
197 le->setText( (*anIt).myValue.toString() );
198 connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
206 GroupC1Layout->addWidget( w, i, 1 );
207 changeWidgets().append( w );
214 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
218 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
223 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
227 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
228 for( ; anIt!=aLast; anIt++ )
230 item.myName = (*anIt)->name();
231 if( (*anIt)->inherits( "QtxIntSpinBox" ) )
233 QtxIntSpinBox* sb = ( QtxIntSpinBox* )( *anIt );
234 item.myValue = sb->value();
235 params.append( item );
238 else if( (*anIt)->inherits( "QtxDblSpinBox" ) )
240 QtxDblSpinBox* sb = ( QtxDblSpinBox* )( *anIt );
241 item.myValue = sb->value();
242 params.append( item );
245 else if( (*anIt)->inherits( "QLineEdit" ) )
247 QLineEdit* line = ( QLineEdit* )( *anIt );
248 item.myValue = line->text();
249 params.append( item );
252 else if ( getParamFromCustomWidget( item, *anIt ))
254 params.append( item );
263 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
265 QString valueStr = "";
266 ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
267 for( int i=0; param!=aLast; param++, i++ )
271 switch( (*param).myValue.type() )
274 valueStr += valueStr.number( (*param).myValue.toInt() );
276 case QVariant::Double:
277 valueStr += valueStr.number( (*param).myValue.toDouble() );
279 case QVariant::String:
280 valueStr += (*param).myValue.toString();
283 QVariant valCopy = (*param).myValue;
284 valueStr += valCopy.asString();
290 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
295 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis() const
297 if ( CORBA::is_nil( myInitParamsHypo ))
299 return myInitParamsHypo;
302 QString SMESHGUI_GenericHypothesisCreator::hypType() const
307 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
309 return myParamWidgets;
312 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
314 return myParamWidgets;
317 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
322 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
326 QString SMESHGUI_GenericHypothesisCreator::caption() const
331 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
336 QString SMESHGUI_GenericHypothesisCreator::type() const
340 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
341 QWidget* /*parent*/) const
345 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam& , QWidget* ) const
353 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
354 : QtxDialog( parent, "", true, true ),
357 setMinimumSize( 300, height() );
358 // setFixedSize( 300, height() );
359 myLayout = new QVBoxLayout( mainFrame(), 0, 0 );
361 QFrame* titFrame = new QFrame( mainFrame() );
362 QHBoxLayout* titLay = new QHBoxLayout( titFrame, 0, 5 );
364 myIconLabel = new QLabel( titFrame );
365 myIconLabel->setScaledContents( false );
366 myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
367 myTypeLabel = new QLabel( titFrame );
369 myTypeLabel->setText( creator->hypType() );
371 titLay->addWidget( myIconLabel, 0 );
372 titLay->addWidget( myTypeLabel, 0 );
373 titLay->addStretch( 1 );
375 myLayout->addWidget( titFrame, 0 );
377 QString aHypType = creator->hypType();
378 if ( aHypType == "LocalLength" )
379 myHelpFileName = "/files/arithmetic_1d.htm#Average_length";
380 else if ( aHypType == "Arithmetic1D")
381 myHelpFileName = "/files/arithmetic_1d.htm#arithmetic_1D";
382 else if ( aHypType == "MaxElementArea")
383 myHelpFileName = "/files/max._element_area_hypothesis.htm";
384 else if ( aHypType == "MaxElementVolume")
385 myHelpFileName = "/files/max._element_volume_hypothsis.htm";
386 else if ( aHypType == "StartEndLength")
387 myHelpFileName = "/files/arithmetic_1d.htm#start_and_end_length";
388 else if ( aHypType == "Deflection1D")
389 myHelpFileName = "/files/arithmetic_1d.htm#deflection_1D";
390 else if ( aHypType == "AutomaticLength")
391 myHelpFileName = "/files/arithmetic_1d.htm#automatic_length";
392 else if ( aHypType == "NumberOfSegments")
393 myHelpFileName = "/files/arithmetic_1d.htm#Number_of_elements";
397 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
401 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
405 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
409 f->reparent( mainFrame(), QPoint( 0, 0 ) );
410 myLayout->insertWidget( 1, f, 1 );
414 void SMESHGUI_HypothesisDlg::accept()
416 if( !myCreator || myCreator->checkParams() )
420 void SMESHGUI_HypothesisDlg::onHelp()
422 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
424 SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
425 app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->moduleName()) : QString(""), myHelpFileName);
428 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
429 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
430 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
431 QObject::tr("BUT_OK"));
435 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
437 myIconLabel->setPixmap( p );
440 void SMESHGUI_HypothesisDlg::setType( const QString& t )
442 myTypeLabel->setText( t );