1 // Copyright (C) 2007-2010 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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_Hypotheses.cxx
25 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
28 #include "SMESHGUI_Hypotheses.h"
31 #include "SMESHGUI_HypothesesUtils.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_SpinBox.h"
35 // SALOME KERNEL includes
36 #include <SALOMEDSClient_Study.hxx>
37 #include <utilities.h>
39 // SALOME GUI includes
40 #include <SUIT_Session.h>
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <LightApp_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 if((*anIt).isVariable) {
197 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
198 QString aVar = (*anIt).myValue.toString();
199 if(aStudy->IsInteger(aVar.toLatin1().constData())){
200 SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
201 sb->setObjectName( (*anIt).myName );
202 attuneStdWidget( sb, i );
204 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
207 else if(aStudy->IsReal(aVar.toLatin1().constData())){
208 SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
209 sb->setObjectName( (*anIt).myName );
210 attuneStdWidget( sb, i );
212 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
217 QLineEdit* le = new QLineEdit( GroupC1 );
218 le->setObjectName( (*anIt).myName );
219 attuneStdWidget( le, i );
220 le->setText( (*anIt).myValue.toString() );
221 connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
230 GroupC1Layout->addWidget( w, i, 1 );
231 changeWidgets().append( w );
238 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
240 valueChanged( (QWidget*) sender() );
243 void SMESHGUI_GenericHypothesisCreator::valueChanged( QWidget* )
247 void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int result )
249 bool res = result==QDialog::Accepted;
252 /*QString paramValues = */storeParams();
253 // No longer needed since NoteBook appears and "Value" OB field shows names of variable
254 // if ( !paramValues.isEmpty() ) {
255 // if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
256 // SMESH::SetValue( SHyp, paramValues );
260 changeWidgets().clear();
262 if( myIsCreate && !res )
264 //remove just created hypothesis
265 _PTR(SObject) aHypSObject = SMESH::FindSObject( myHypo );
266 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
267 if( aStudy && !aStudy->GetProperties()->IsLocked() )
269 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
270 aBuilder->RemoveObjectWithChildren( aHypSObject );
273 else if( !myIsCreate && res )
275 SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( myHypo );
276 if( listSOmesh.size() > 0 )
277 for( int i = 0; i < listSOmesh.size(); i++ )
279 _PTR(SObject) submSO = listSOmesh[i];
280 SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
281 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
282 if( !aSubMesh->_is_nil() )
283 aMesh = aSubMesh->GetFather();
284 _PTR(SObject) meshSO = SMESH::FindSObject( aMesh );
285 SMESH::ModifiedMesh( meshSO, false, aMesh->NbNodes()==0);
288 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
289 myHypo = SMESH::SMESH_Hypothesis::_nil();
290 myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
292 disconnect( myDlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
296 emit finished( result );
299 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
304 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
308 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
309 for( ; anIt!=aLast; anIt++ )
311 item.myName = (*anIt)->objectName();
312 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
314 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
315 item.myValue = sb->value();
316 params.append( item );
319 else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
321 SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
322 item.myValue = sb->value();
323 params.append( item );
326 else if( (*anIt)->inherits( "QLineEdit" ) )
328 QLineEdit* line = ( QLineEdit* )( *anIt );
329 item.myValue = line->text();
330 params.append( item );
333 else if ( getParamFromCustomWidget( item, *anIt ))
335 params.append( item );
345 QStringList SMESHGUI_GenericHypothesisCreator::getVariablesFromDlg() const
348 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
349 for( ; anIt!=aLast; anIt++ ) {
350 if( (*anIt)->inherits( "QAbstractSpinBox" ) ) {
351 QAbstractSpinBox* sb = ( QAbstractSpinBox* )( *anIt );
352 aResult.append(sb->text());
358 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
360 QString valueStr = "";
361 ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
363 for( int i=0; param!=aLast; param++, i++ )
365 if ( valueStr.length() > len0 ) {
367 len0 = valueStr.length();
369 switch( (*param).myValue.type() )
372 valueStr += valueStr.number( (*param).myValue.toInt() );
374 case QVariant::Double:
375 valueStr += valueStr.number( (*param).myValue.toDouble() );
377 case QVariant::String:
378 valueStr += (*param).myValue.toString();
381 QVariant valCopy = (*param).myValue;
382 valueStr += valCopy.toString();
388 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
393 void SMESHGUI_GenericHypothesisCreator::setShapeEntry( const QString& theEntry )
395 myShapeEntry = theEntry;
398 //================================================================================
400 * \brief Return hypothesis containing initial parameters
401 * \param strictly - if true, always return myInitParamsHypo,
402 * else, return myInitParamsHypo only in creation mode and if it
405 //================================================================================
407 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis(const bool strictly) const
410 return myInitParamsHypo;
411 if ( !isCreation() || CORBA::is_nil( myInitParamsHypo ))
413 return myInitParamsHypo;
416 bool SMESHGUI_GenericHypothesisCreator::hasInitParamsHypothesis() const
418 return !CORBA::is_nil( myInitParamsHypo );
421 QString SMESHGUI_GenericHypothesisCreator::hypType() const
426 QString SMESHGUI_GenericHypothesisCreator::hypName() const
431 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
433 return myParamWidgets;
436 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
438 return myParamWidgets;
441 QtxDialog* SMESHGUI_GenericHypothesisCreator:: dlg() const
446 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
451 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
455 QString SMESHGUI_GenericHypothesisCreator::caption() const
460 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
465 QString SMESHGUI_GenericHypothesisCreator::type() const
469 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
471 const int /*index*/) const
475 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWidget* ) const
480 bool SMESHGUI_GenericHypothesisCreator::checkParams( QString& msg ) const
483 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
484 for( ; anIt!=aLast; anIt++ )
486 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
488 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
489 ok = sb->isValid( msg, true ) && ok;
491 else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
493 SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
494 ok = sb->isValid( msg, true ) && ok;
500 void SMESHGUI_GenericHypothesisCreator::onReject()
504 QString SMESHGUI_GenericHypothesisCreator::helpPage() const
506 QString aHypType = hypType();
507 QString aHelpFileName = "";
508 if ( aHypType == "LocalLength" )
509 aHelpFileName = "a1d_meshing_hypo_page.html#average_length_anchor";
510 else if ( aHypType == "MaxLength" )
511 aHelpFileName = "a1d_meshing_hypo_page.html#max_length_anchor";
512 else if ( aHypType == "Arithmetic1D")
513 aHelpFileName = "a1d_meshing_hypo_page.html#arithmetic_1d_anchor";
514 else if ( aHypType == "FixedPoints1D")
515 aHelpFileName = "a1d_meshing_hypo_page.html#fixed_points_1d_anchor";
516 else if ( aHypType == "MaxElementArea")
517 aHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
518 else if ( aHypType == "MaxElementVolume")
519 aHelpFileName = "max_element_volume_hypo_page.html";
520 else if ( aHypType == "StartEndLength")
521 aHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
522 else if ( aHypType == "Deflection1D")
523 aHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
524 else if ( aHypType == "AutomaticLength")
525 aHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
526 else if ( aHypType == "NumberOfSegments")
527 aHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
528 else if ( aHypType == "ProjectionSource1D")
529 aHelpFileName = "projection_algos_page.html";
530 else if ( aHypType == "ProjectionSource2D")
531 aHelpFileName = "projection_algos_page.html";
532 else if ( aHypType == "ProjectionSource3D")
533 aHelpFileName = "projection_algos_page.html";
534 else if ( aHypType == "NumberOfLayers")
535 aHelpFileName = "radial_prism_algo_page.html";
536 else if ( aHypType == "NumberOfLayers2D")
537 aHelpFileName = "radial_quadrangle_1D2D_algo_page.html";
538 else if ( aHypType == "LayerDistribution")
539 aHelpFileName = "radial_prism_algo_page.html";
540 else if ( aHypType == "LayerDistribution2D")
541 aHelpFileName = "radial_quadrangle_1D2D_algo_page.html";
542 else if ( aHypType == "SegmentLengthAroundVertex")
543 aHelpFileName = "segments_around_vertex_algo_page.html";
544 else if ( aHypType == "QuadrangleParams")
545 aHelpFileName = "a2d_meshing_hypo_page.html#hypo_quad_params_anchor";
546 return aHelpFileName;
552 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
553 : QtxDialog( parent, false, true ),
556 setAttribute(Qt::WA_DeleteOnClose, true);
557 setMinimumSize( 300, height() );
558 // setFixedSize( 300, height() );
559 QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
560 topLayout->setMargin( 0 );
561 topLayout->setSpacing( 0 );
563 QFrame* titFrame = new QFrame( mainFrame() );
564 QHBoxLayout* titLay = new QHBoxLayout( titFrame );
565 titLay->setMargin( 0 );
566 titLay->setSpacing( SPACING );
568 myIconLabel = new QLabel( titFrame );
569 myIconLabel->setScaledContents( false );
570 myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
571 myTypeLabel = new QLabel( titFrame );
573 myTypeLabel->setText( creator->hypType() );
575 titLay->addWidget( myIconLabel, 0 );
576 titLay->addWidget( myTypeLabel, 0 );
577 titLay->addStretch( 1 );
579 topLayout->addWidget( titFrame, 0 );
581 myHelpFileName = creator->helpPage();
583 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
586 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
591 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
595 f->setParent( mainFrame() );
596 qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
600 void SMESHGUI_HypothesisDlg::accept()
603 if ( myCreator && !myCreator->checkParams( msg ) )
605 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
606 if ( !msg.isEmpty() )
608 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
614 void SMESHGUI_HypothesisDlg::reject()
616 if ( myCreator ) myCreator->onReject();
620 void SMESHGUI_HypothesisDlg::onHelp()
622 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
624 SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
625 app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->moduleName()) : QString(""), myHelpFileName);
630 platform = "winapplication";
632 platform = "application";
634 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
635 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
636 arg(app->resourceMgr()->stringValue("ExternalBrowser",
638 arg(myHelpFileName));
642 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
644 myIconLabel->setPixmap( p );
647 void SMESHGUI_HypothesisDlg::setType( const QString& t )
649 myTypeLabel->setText( t );
652 HypothesisData::HypothesisData( const QString& theTypeName,
653 const QString& thePluginName,
654 const QString& theServerLibName,
655 const QString& theClientLibName,
656 const QString& theLabel,
657 const QString& theIconId,
658 const QList<int>& theDim,
660 const QStringList& theNeededHypos,
661 const QStringList& theOptionalHypos,
662 const QStringList& theInputTypes,
663 const QStringList& theOutputTypes,
664 const bool theIsNeedGeometry,
665 const bool supportSub)
666 : TypeName( theTypeName ),
667 PluginName( thePluginName ),
668 ServerLibName( theServerLibName ),
669 ClientLibName( theClientLibName ),
674 NeededHypos( theNeededHypos ),
675 OptionalHypos( theOptionalHypos ),
676 InputTypes( theInputTypes ),
677 OutputTypes( theOutputTypes ),
678 IsNeedGeometry( theIsNeedGeometry ),
679 IsSupportSubmeshes( supportSub )
683 HypothesesSet::HypothesesSet( const QString& theSetName )
684 : myHypoSetName( theSetName ),
689 HypothesesSet::HypothesesSet( const QString& theSetName,
690 const QStringList& theHypoList,
691 const QStringList& theAlgoList )
692 : myHypoSetName( theSetName ),
693 myHypoList( theHypoList ),
694 myAlgoList( theAlgoList ),
699 QStringList* HypothesesSet::list(bool is_algo) const
701 return const_cast<QStringList*>( &( is_algo ? myAlgoList : myHypoList ) );
704 QStringList* HypothesesSet::list() const
706 return list( myIsAlgo );
709 QString HypothesesSet::name() const
711 return myHypoSetName;
714 void HypothesesSet::set( bool isAlgo, const QStringList& lst )
719 int HypothesesSet::count( bool isAlgo ) const
721 return list(isAlgo)->count();
724 bool HypothesesSet::isAlgo() const
729 void HypothesesSet::init( bool isAlgo )
735 bool HypothesesSet::more() const
737 return myIndex < list()->count();
740 void HypothesesSet::next()
745 QString HypothesesSet::current() const
747 return list()->at(myIndex);