1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_Hypotheses.cxx
24 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
27 #include "SMESHGUI_Hypotheses.h"
30 #include "SMESHGUI_HypothesesUtils.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_SpinBox.h"
34 // SALOME KERNEL includes
35 #include <SALOMEDSClient_Study.hxx>
36 #include <utilities.h>
38 // SALOME GUI includes
39 #include <SUIT_Session.h>
40 #include <SUIT_MessageBox.h>
41 #include <SUIT_ResourceMgr.h>
42 #include <LightApp_Application.h>
43 #include <SalomeApp_Application.h>
44 #include <SalomeApp_IntSpinBox.h>
51 #include <QVBoxLayout>
56 SMESHGUI_GenericHypothesisCreator::SMESHGUI_GenericHypothesisCreator( const QString& theHypType )
57 : myHypType( theHypType ), myIsCreate( false ), myDlg( 0 )
61 SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator()
65 void SMESHGUI_GenericHypothesisCreator::setInitParamsHypothesis(SMESH::SMESH_Hypothesis_ptr hyp)
67 if ( !CORBA::is_nil( hyp ) && hypType() == hyp->GetName() )
68 myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( hyp );
71 void SMESHGUI_GenericHypothesisCreator::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp,
72 const QString& theHypName,
73 QWidget* parent, QObject* obj, const QString& slot )
75 MESSAGE( "Creation of hypothesis with initial params" );
76 setInitParamsHypothesis( initParamsHyp );
77 create( false, theHypName, parent, obj, slot );
80 void SMESHGUI_GenericHypothesisCreator::create( bool isAlgo,
81 const QString& theHypName,
82 QWidget* theParent, QObject* obj, const QString& slot )
84 MESSAGE( "Creation of hypothesis" );
88 // Create hypothesis/algorithm
90 SMESH::CreateHypothesis( hypType(), theHypName, isAlgo );
94 SMESH::SMESH_Hypothesis_var aHypothesis =
95 SMESH::CreateHypothesis( hypType(), theHypName, false );
96 editHypothesis( aHypothesis.in(), theHypName, theParent, obj, slot );
100 void SMESHGUI_GenericHypothesisCreator::edit( SMESH::SMESH_Hypothesis_ptr theHypothesis,
101 const QString& theHypName,
102 QWidget* theParent, QObject* obj, const QString& slot )
104 if( CORBA::is_nil( theHypothesis ) )
107 MESSAGE("Edition of hypothesis");
111 editHypothesis( theHypothesis, theHypName, theParent, obj, slot );
114 void SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ptr h,
115 const QString& theHypName,
117 QObject* obj, const QString& slot )
119 myHypName = theHypName;
120 myHypo = SMESH::SMESH_Hypothesis::_duplicate( h );
122 SMESHGUI_HypothesisDlg* Dlg = new SMESHGUI_HypothesisDlg( this, theParent );
123 connect( Dlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
124 connect( this, SIGNAL( finished( int ) ), obj, slot.toLatin1().constData() );
127 QFrame* fr = buildFrame();
130 Dlg->setCustomFrame( fr );
131 Dlg->setWindowTitle( caption() );
132 Dlg->setObjectName( theHypName );
133 Dlg->setHIcon( icon() );
134 Dlg->setType( type() );
137 Dlg->resize( Dlg->minimumSizeHint() );
140 emit finished( QDialog::Accepted );
143 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
145 if( CORBA::is_nil( hypothesis() ) )
148 ListOfStdParams params;
149 if( !stdParams( params ) || params.isEmpty() )
152 QFrame* fr = new QFrame( 0 );
153 QVBoxLayout* lay = new QVBoxLayout( fr );
155 lay->setSpacing( 0 );
157 QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
158 lay->addWidget( GroupC1 );
160 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
161 GroupC1Layout->setSpacing( SPACING );
162 GroupC1Layout->setMargin( MARGIN );
164 ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end();
165 for( int i=0; anIt!=aLast; anIt++, i++ )
167 QLabel* lab = new QLabel( (*anIt).myName, GroupC1 );
168 GroupC1Layout->addWidget( lab, i, 0 );
170 QWidget* w = getCustomWidget( *anIt, GroupC1, i );
172 switch( (*anIt).myValue.type() )
176 SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
177 sb->setObjectName( (*anIt).myName );
178 attuneStdWidget( sb, i );
179 sb->setValue( (*anIt).myValue.toInt() );
180 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
184 case QVariant::Double:
186 SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
187 sb->setObjectName( (*anIt).myName );
188 attuneStdWidget( sb, i );
189 sb->setValue( (*anIt).myValue.toDouble() );
190 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
194 case QVariant::String:
196 /* ouv: temporarily disabled
197 if((*anIt).isVariable) {
198 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
199 QString aVar = (*anIt).myValue.toString();
200 if(aStudy->IsInteger(aVar.toLatin1().constData())){
201 SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
202 sb->setObjectName( (*anIt).myName );
203 attuneStdWidget( sb, i );
205 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
208 else if(aStudy->IsReal(aVar.toLatin1().constData())){
209 SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
210 sb->setObjectName( (*anIt).myName );
211 attuneStdWidget( sb, i );
213 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
219 QLineEdit* le = new QLineEdit( GroupC1 );
220 le->setObjectName( (*anIt).myName );
221 attuneStdWidget( le, i );
222 le->setText( (*anIt).myValue.toString() );
223 connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
232 GroupC1Layout->addWidget( w, i, 1 );
233 changeWidgets().append( w );
240 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
242 valueChanged( (QWidget*) sender() );
245 void SMESHGUI_GenericHypothesisCreator::valueChanged( QWidget* )
249 void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int result )
251 bool res = result==QDialog::Accepted;
254 /*QString paramValues = */storeParams();
255 // No longer needed since NoteBook appears and "Value" OB field shows names of variable
256 // if ( !paramValues.isEmpty() ) {
257 // if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
258 // SMESH::SetValue( SHyp, paramValues );
262 changeWidgets().clear();
264 if( myIsCreate && !res )
266 //remove just created hypothesis
267 _PTR(SObject) aHypSObject = SMESH::FindSObject( myHypo );
268 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
269 if( aStudy && !aStudy->GetProperties()->IsLocked() )
271 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
272 aBuilder->RemoveObjectWithChildren( aHypSObject );
275 else if( !myIsCreate && res )
277 SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( myHypo );
278 if( listSOmesh.size() > 0 )
279 for( int i = 0; i < listSOmesh.size(); i++ )
281 _PTR(SObject) submSO = listSOmesh[i];
282 SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
283 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
284 if( !aSubMesh->_is_nil() )
285 aMesh = aSubMesh->GetFather();
286 _PTR(SObject) meshSO = SMESH::FindSObject( aMesh );
287 SMESH::ModifiedMesh( meshSO, false, aMesh->NbNodes()==0);
290 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
291 myHypo = SMESH::SMESH_Hypothesis::_nil();
292 myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
294 disconnect( myDlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
298 emit finished( result );
301 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
306 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
310 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
311 for( ; anIt!=aLast; anIt++ )
313 item.myName = (*anIt)->objectName();
314 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
316 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
317 item.myValue = sb->value();
318 params.append( item );
321 else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
323 SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
324 item.myValue = sb->value();
325 params.append( item );
328 else if( (*anIt)->inherits( "QLineEdit" ) )
330 QLineEdit* line = ( QLineEdit* )( *anIt );
331 item.myValue = line->text();
332 params.append( item );
335 else if ( getParamFromCustomWidget( item, *anIt ))
337 params.append( item );
347 QStringList SMESHGUI_GenericHypothesisCreator::getVariablesFromDlg() const
350 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
351 for( ; anIt!=aLast; anIt++ ) {
352 if( (*anIt)->inherits( "QAbstractSpinBox" ) ) {
353 QAbstractSpinBox* sb = ( QAbstractSpinBox* )( *anIt );
354 aResult.append(sb->text());
360 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
362 QString valueStr = "";
363 ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
365 for( int i=0; param!=aLast; param++, i++ )
367 if ( valueStr.length() > len0 ) {
369 len0 = valueStr.length();
371 switch( (*param).myValue.type() )
374 valueStr += valueStr.number( (*param).myValue.toInt() );
376 case QVariant::Double:
377 valueStr += valueStr.number( (*param).myValue.toDouble() );
379 case QVariant::String:
380 valueStr += (*param).myValue.toString();
383 QVariant valCopy = (*param).myValue;
384 valueStr += valCopy.toString();
390 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
395 void SMESHGUI_GenericHypothesisCreator::setShapeEntry( const QString& theEntry )
397 myShapeEntry = theEntry;
400 //================================================================================
402 * \brief Return hypothesis containing initial parameters
403 * \param strictly - if true, always return myInitParamsHypo,
404 * else, return myInitParamsHypo only in creation mode and if it
407 //================================================================================
409 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis(const bool strictly) const
412 return myInitParamsHypo;
413 if ( !isCreation() || CORBA::is_nil( myInitParamsHypo ))
415 return myInitParamsHypo;
418 bool SMESHGUI_GenericHypothesisCreator::hasInitParamsHypothesis() const
420 return !CORBA::is_nil( myInitParamsHypo );
423 QString SMESHGUI_GenericHypothesisCreator::hypType() const
428 QString SMESHGUI_GenericHypothesisCreator::hypName() const
433 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
435 return myParamWidgets;
438 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
440 return myParamWidgets;
443 QtxDialog* SMESHGUI_GenericHypothesisCreator:: dlg() const
448 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
453 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
457 QString SMESHGUI_GenericHypothesisCreator::caption() const
462 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
467 QString SMESHGUI_GenericHypothesisCreator::type() const
471 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
473 const int /*index*/) const
477 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWidget* ) const
482 bool SMESHGUI_GenericHypothesisCreator::checkParams( QString& msg, QStringList& absentParams ) const
485 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
486 for( ; anIt!=aLast; anIt++ )
488 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
490 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
491 ok = sb->isValid( msg, absentParams, true ) && ok;
493 else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
495 SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
496 ok = sb->isValid( msg, absentParams, true ) && ok;
502 void SMESHGUI_GenericHypothesisCreator::onReject()
506 QString SMESHGUI_GenericHypothesisCreator::helpPage() const
508 QString aHypType = hypType();
509 QString aHelpFileName = "";
510 if ( aHypType == "LocalLength" )
511 aHelpFileName = "a1d_meshing_hypo_page.html#average_length_anchor";
512 else if ( aHypType == "MaxLength" )
513 aHelpFileName = "a1d_meshing_hypo_page.html#max_length_anchor";
514 else if ( aHypType == "Arithmetic1D")
515 aHelpFileName = "a1d_meshing_hypo_page.html#arithmetic_1d_anchor";
516 else if ( aHypType == "FixedPoints1D")
517 aHelpFileName = "a1d_meshing_hypo_page.html#fixed_points_1d_anchor";
518 else if ( aHypType == "MaxElementArea")
519 aHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
520 else if ( aHypType == "MaxElementVolume")
521 aHelpFileName = "max_element_volume_hypo_page.html";
522 else if ( aHypType == "StartEndLength")
523 aHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
524 else if ( aHypType == "Deflection1D")
525 aHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
526 else if ( aHypType == "AutomaticLength")
527 aHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
528 else if ( aHypType == "NumberOfSegments")
529 aHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
530 else if ( aHypType == "ProjectionSource1D")
531 aHelpFileName = "projection_algos_page.html";
532 else if ( aHypType == "ProjectionSource2D")
533 aHelpFileName = "projection_algos_page.html";
534 else if ( aHypType == "ProjectionSource3D")
535 aHelpFileName = "projection_algos_page.html";
536 else if ( aHypType == "NumberOfLayers")
537 aHelpFileName = "radial_prism_algo_page.html";
538 else if ( aHypType == "NumberOfLayers2D")
539 aHelpFileName = "radial_quadrangle_1D2D_algo_page.html";
540 else if ( aHypType == "LayerDistribution")
541 aHelpFileName = "radial_prism_algo_page.html";
542 else if ( aHypType == "LayerDistribution2D")
543 aHelpFileName = "radial_quadrangle_1D2D_algo_page.html";
544 else if ( aHypType == "SegmentLengthAroundVertex")
545 aHelpFileName = "segments_around_vertex_algo_page.html";
546 else if ( aHypType == "QuadrangleParams")
547 aHelpFileName = "a2d_meshing_hypo_page.html#hypo_quad_params_anchor";
548 return aHelpFileName;
554 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
555 : QtxDialog( parent, false, true ),
558 setAttribute(Qt::WA_DeleteOnClose, true);
559 setMinimumSize( 300, height() );
560 // setFixedSize( 300, height() );
561 QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
562 topLayout->setMargin( 0 );
563 topLayout->setSpacing( 0 );
565 QFrame* titFrame = new QFrame( mainFrame() );
566 QHBoxLayout* titLay = new QHBoxLayout( titFrame );
567 titLay->setMargin( 0 );
568 titLay->setSpacing( SPACING );
570 myIconLabel = new QLabel( titFrame );
571 myIconLabel->setScaledContents( false );
572 myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
573 myTypeLabel = new QLabel( titFrame );
575 myTypeLabel->setText( creator->hypType() );
577 titLay->addWidget( myIconLabel, 0 );
578 titLay->addWidget( myTypeLabel, 0 );
579 titLay->addStretch( 1 );
581 topLayout->addWidget( titFrame, 0 );
583 myHelpFileName = creator->helpPage();
585 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
588 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
593 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
597 f->setParent( mainFrame() );
598 qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
602 void SMESHGUI_HypothesisDlg::accept()
605 QStringList absentParams;
606 if ( myCreator && !myCreator->checkParams( msg, absentParams ) )
608 if( !absentParams.isEmpty() )
610 SalomeApp_Application* app =
611 dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
613 app->defineAbsentParameters( absentParams );
616 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
617 if ( !msg.isEmpty() )
619 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
625 void SMESHGUI_HypothesisDlg::reject()
627 if ( myCreator ) myCreator->onReject();
631 void SMESHGUI_HypothesisDlg::onHelp()
633 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
635 SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
636 app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->moduleName()) : QString(""), myHelpFileName);
641 platform = "winapplication";
643 platform = "application";
645 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
646 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
647 arg(app->resourceMgr()->stringValue("ExternalBrowser",
649 arg(myHelpFileName));
653 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
655 myIconLabel->setPixmap( p );
658 void SMESHGUI_HypothesisDlg::setType( const QString& t )
660 myTypeLabel->setText( t );
663 HypothesisData::HypothesisData( const QString& theTypeName,
664 const QString& thePluginName,
665 const QString& theServerLibName,
666 const QString& theClientLibName,
667 const QString& theLabel,
668 const QString& theIconId,
669 const QList<int>& theDim,
671 const QStringList& theNeededHypos,
672 const QStringList& theOptionalHypos,
673 const QStringList& theInputTypes,
674 const QStringList& theOutputTypes,
675 const bool theIsNeedGeometry,
676 const bool supportSub)
677 : TypeName( theTypeName ),
678 PluginName( thePluginName ),
679 ServerLibName( theServerLibName ),
680 ClientLibName( theClientLibName ),
685 NeededHypos( theNeededHypos ),
686 OptionalHypos( theOptionalHypos ),
687 InputTypes( theInputTypes ),
688 OutputTypes( theOutputTypes ),
689 IsNeedGeometry( theIsNeedGeometry ),
690 IsSupportSubmeshes( supportSub )
694 HypothesesSet::HypothesesSet( const QString& theSetName )
695 : myHypoSetName( theSetName ),
700 HypothesesSet::HypothesesSet( const QString& theSetName,
701 const QStringList& theHypoList,
702 const QStringList& theAlgoList )
703 : myHypoSetName( theSetName ),
704 myHypoList( theHypoList ),
705 myAlgoList( theAlgoList ),
710 QStringList* HypothesesSet::list(bool is_algo) const
712 return const_cast<QStringList*>( &( is_algo ? myAlgoList : myHypoList ) );
715 QStringList* HypothesesSet::list() const
717 return list( myIsAlgo );
720 QString HypothesesSet::name() const
722 return myHypoSetName;
725 void HypothesesSet::set( bool isAlgo, const QStringList& lst )
730 int HypothesesSet::count( bool isAlgo ) const
732 return list(isAlgo)->count();
735 bool HypothesesSet::isAlgo() const
740 void HypothesesSet::init( bool isAlgo )
746 bool HypothesesSet::more() const
748 return myIndex < list()->count();
751 void HypothesesSet::next()
756 QString HypothesesSet::current() const
758 return list()->at(myIndex);