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>
45 #include <SalomeApp_Notebook.h>
46 //#include <SalomeApp_Study.h>
53 #include <QVBoxLayout>
58 SMESHGUI_GenericHypothesisCreator::SMESHGUI_GenericHypothesisCreator( const QString& theHypType )
59 : SMESHGUI_Helper( SMESHGUI::GetSMESHGUI() ),
60 myHypType( theHypType ), myIsCreate( false ), myDlg( 0 )
64 SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator()
68 void SMESHGUI_GenericHypothesisCreator::setInitParamsHypothesis(SMESH::SMESH_Hypothesis_ptr hyp)
70 if ( !CORBA::is_nil( hyp ) && hypType() == hyp->GetName() )
71 myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( hyp );
74 void SMESHGUI_GenericHypothesisCreator::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp,
75 const QString& theHypName,
76 QWidget* parent, QObject* obj, const QString& slot )
78 MESSAGE( "Creation of hypothesis with initial params" );
79 setInitParamsHypothesis( initParamsHyp );
80 create( false, theHypName, parent, obj, slot );
83 void SMESHGUI_GenericHypothesisCreator::create( bool isAlgo,
84 const QString& theHypName,
85 QWidget* theParent, QObject* obj, const QString& slot )
87 MESSAGE( "Creation of hypothesis" );
91 // Create hypothesis/algorithm
93 SMESH::CreateHypothesis( hypType(), theHypName, isAlgo );
97 SMESH::SMESH_Hypothesis_var aHypothesis =
98 SMESH::CreateHypothesis( hypType(), theHypName, false );
99 editHypothesis( aHypothesis.in(), theHypName, theParent, obj, slot );
103 void SMESHGUI_GenericHypothesisCreator::edit( SMESH::SMESH_Hypothesis_ptr theHypothesis,
104 const QString& theHypName,
105 QWidget* theParent, QObject* obj, const QString& slot )
107 if( CORBA::is_nil( theHypothesis ) )
110 MESSAGE("Edition of hypothesis");
114 editHypothesis( theHypothesis, theHypName, theParent, obj, slot );
117 void SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ptr h,
118 const QString& theHypName,
120 QObject* obj, const QString& slot )
122 myHypName = theHypName;
123 myHypo = SMESH::SMESH_Hypothesis::_duplicate( h );
125 SMESHGUI_HypothesisDlg* Dlg = new SMESHGUI_HypothesisDlg( this, theParent );
126 connect( Dlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
127 connect( this, SIGNAL( finished( int ) ), obj, slot.toLatin1().constData() );
130 QFrame* fr = buildFrame();
133 Dlg->setCustomFrame( fr );
134 Dlg->setWindowTitle( caption() );
135 Dlg->setObjectName( theHypName );
136 Dlg->setHIcon( icon() );
137 Dlg->setType( type() );
140 Dlg->resize( Dlg->minimumSizeHint() );
143 emit finished( QDialog::Accepted );
146 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
148 if( CORBA::is_nil( hypothesis() ) )
151 ListOfStdParams params;
152 if( !stdParams( params ) || params.isEmpty() )
155 QFrame* fr = new QFrame( 0 );
156 QVBoxLayout* lay = new QVBoxLayout( fr );
158 lay->setSpacing( 0 );
160 QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
161 lay->addWidget( GroupC1 );
163 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
164 GroupC1Layout->setSpacing( SPACING );
165 GroupC1Layout->setMargin( MARGIN );
167 ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end();
168 for( int i=0; anIt!=aLast; anIt++, i++ )
170 QLabel* lab = new QLabel( (*anIt).myName, GroupC1 );
171 GroupC1Layout->addWidget( lab, i, 0 );
173 QWidget* w = getCustomWidget( *anIt, GroupC1, i );
175 switch( (*anIt).myValue.type() )
179 SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
180 sb->setObjectName( (*anIt).myName );
181 attuneStdWidget( sb, i );
182 sb->setValue( (*anIt).myValue.toInt() );
183 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
187 case QVariant::Double:
189 SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
190 sb->setObjectName( (*anIt).myName );
191 attuneStdWidget( sb, i );
192 sb->setValue( (*anIt).myValue.toDouble() );
193 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
197 case QVariant::String:
199 if((*anIt).isVariable) {
200 QString aVar = (*anIt).myValue.toString();
201 QVariant::Type aType = getNotebook()->getType( aVar );
202 if(aType == QVariant::Int) {
203 SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
204 sb->setObjectName( (*anIt).myName );
205 attuneStdWidget( sb, i );
207 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
210 else if( aType == QVariant::Double ) {
211 SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
212 sb->setObjectName( (*anIt).myName );
213 attuneStdWidget( sb, i );
215 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
220 QLineEdit* le = new QLineEdit( GroupC1 );
221 le->setObjectName( (*anIt).myName );
222 attuneStdWidget( le, i );
223 le->setText( (*anIt).myValue.toString() );
224 connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
233 GroupC1Layout->addWidget( w, i, 1 );
234 changeWidgets().append( w );
241 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
243 valueChanged( (QWidget*) sender() );
246 void SMESHGUI_GenericHypothesisCreator::valueChanged( QWidget* )
250 void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int result )
252 bool res = result==QDialog::Accepted;
255 /*QString paramValues = */storeParams();
256 // No longer needed since NoteBook appears and "Value" OB field shows names of variable
257 // if ( !paramValues.isEmpty() ) {
258 // if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
259 // SMESH::SetValue( SHyp, paramValues );
263 changeWidgets().clear();
265 if( myIsCreate && !res )
267 //remove just created hypothesis
268 _PTR(SObject) aHypSObject = SMESH::FindSObject( myHypo );
269 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
270 if( aStudy && !aStudy->GetProperties()->IsLocked() )
272 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
273 aBuilder->RemoveObjectWithChildren( aHypSObject );
276 else if( !myIsCreate && res )
278 SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( myHypo );
279 if( listSOmesh.size() > 0 )
280 for( int i = 0; i < listSOmesh.size(); i++ )
282 _PTR(SObject) submSO = listSOmesh[i];
283 SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
284 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
285 if( !aSubMesh->_is_nil() )
286 aMesh = aSubMesh->GetFather();
287 _PTR(SObject) meshSO = SMESH::FindSObject( aMesh );
288 SMESH::ModifiedMesh( meshSO, false, aMesh->NbNodes()==0);
291 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
292 myHypo = SMESH::SMESH_Hypothesis::_nil();
293 myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
295 disconnect( myDlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
299 emit finished( result );
302 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
307 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
311 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
312 for( ; anIt!=aLast; anIt++ )
314 item.myName = (*anIt)->objectName();
315 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
317 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
318 item.myValue = sb->value();
319 params.append( item );
322 else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
324 SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
325 item.myValue = sb->value();
326 params.append( item );
329 else if( (*anIt)->inherits( "QLineEdit" ) )
331 QLineEdit* line = ( QLineEdit* )( *anIt );
332 item.myValue = line->text();
333 params.append( item );
336 else if ( getParamFromCustomWidget( item, *anIt ))
338 params.append( item );
348 QStringList SMESHGUI_GenericHypothesisCreator::getVariablesFromDlg() const
351 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
352 for( ; anIt!=aLast; anIt++ ) {
353 if( (*anIt)->inherits( "QAbstractSpinBox" ) ) {
354 QAbstractSpinBox* sb = ( QAbstractSpinBox* )( *anIt );
355 aResult.append(sb->text());
361 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
363 QString valueStr = "";
364 ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
366 for( int i=0; param!=aLast; param++, i++ )
368 if ( valueStr.length() > len0 ) {
370 len0 = valueStr.length();
372 switch( (*param).myValue.type() )
375 valueStr += valueStr.number( (*param).myValue.toInt() );
377 case QVariant::Double:
378 valueStr += valueStr.number( (*param).myValue.toDouble() );
380 case QVariant::String:
381 valueStr += (*param).myValue.toString();
384 QVariant valCopy = (*param).myValue;
385 valueStr += valCopy.toString();
391 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
396 void SMESHGUI_GenericHypothesisCreator::setShapeEntry( const QString& theEntry )
398 myShapeEntry = theEntry;
401 //================================================================================
403 * \brief Return hypothesis containing initial parameters
404 * \param strictly - if true, always return myInitParamsHypo,
405 * else, return myInitParamsHypo only in creation mode and if it
408 //================================================================================
410 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis(const bool strictly) const
413 return myInitParamsHypo;
414 if ( !isCreation() || CORBA::is_nil( myInitParamsHypo ))
416 return myInitParamsHypo;
419 bool SMESHGUI_GenericHypothesisCreator::hasInitParamsHypothesis() const
421 return !CORBA::is_nil( myInitParamsHypo );
424 QString SMESHGUI_GenericHypothesisCreator::hypType() const
429 QString SMESHGUI_GenericHypothesisCreator::hypName() const
434 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
436 return myParamWidgets;
439 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
441 return myParamWidgets;
444 QtxDialog* SMESHGUI_GenericHypothesisCreator:: dlg() const
449 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
454 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
458 QString SMESHGUI_GenericHypothesisCreator::caption() const
463 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
468 QString SMESHGUI_GenericHypothesisCreator::type() const
472 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
474 const int /*index*/) const
478 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWidget* ) const
483 bool SMESHGUI_GenericHypothesisCreator::checkParams( QString& msg, QStringList& absentParams ) const
486 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
487 for( ; anIt!=aLast; anIt++ )
489 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
491 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
492 ok = sb->isValid( msg, absentParams, true ) && ok;
494 else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
496 SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
497 ok = sb->isValid( msg, absentParams, true ) && ok;
503 void SMESHGUI_GenericHypothesisCreator::onReject()
507 QString SMESHGUI_GenericHypothesisCreator::helpPage() const
509 QString aHypType = hypType();
510 QString aHelpFileName = "";
511 if ( aHypType == "LocalLength" )
512 aHelpFileName = "a1d_meshing_hypo_page.html#average_length_anchor";
513 else if ( aHypType == "MaxLength" )
514 aHelpFileName = "a1d_meshing_hypo_page.html#max_length_anchor";
515 else if ( aHypType == "Arithmetic1D")
516 aHelpFileName = "a1d_meshing_hypo_page.html#arithmetic_1d_anchor";
517 else if ( aHypType == "FixedPoints1D")
518 aHelpFileName = "a1d_meshing_hypo_page.html#fixed_points_1d_anchor";
519 else if ( aHypType == "MaxElementArea")
520 aHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
521 else if ( aHypType == "MaxElementVolume")
522 aHelpFileName = "max_element_volume_hypo_page.html";
523 else if ( aHypType == "StartEndLength")
524 aHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
525 else if ( aHypType == "Deflection1D")
526 aHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
527 else if ( aHypType == "AutomaticLength")
528 aHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
529 else if ( aHypType == "NumberOfSegments")
530 aHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
531 else if ( aHypType == "ProjectionSource1D")
532 aHelpFileName = "projection_algos_page.html";
533 else if ( aHypType == "ProjectionSource2D")
534 aHelpFileName = "projection_algos_page.html";
535 else if ( aHypType == "ProjectionSource3D")
536 aHelpFileName = "projection_algos_page.html";
537 else if ( aHypType == "NumberOfLayers")
538 aHelpFileName = "radial_prism_algo_page.html";
539 else if ( aHypType == "NumberOfLayers2D")
540 aHelpFileName = "radial_quadrangle_1D2D_algo_page.html";
541 else if ( aHypType == "LayerDistribution")
542 aHelpFileName = "radial_prism_algo_page.html";
543 else if ( aHypType == "LayerDistribution2D")
544 aHelpFileName = "radial_quadrangle_1D2D_algo_page.html";
545 else if ( aHypType == "SegmentLengthAroundVertex")
546 aHelpFileName = "segments_around_vertex_algo_page.html";
547 else if ( aHypType == "QuadrangleParams")
548 aHelpFileName = "a2d_meshing_hypo_page.html#hypo_quad_params_anchor";
549 return aHelpFileName;
555 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
556 : QtxDialog( parent, false, true ),
559 setAttribute(Qt::WA_DeleteOnClose, true);
560 setMinimumSize( 300, height() );
561 // setFixedSize( 300, height() );
562 QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
563 topLayout->setMargin( 0 );
564 topLayout->setSpacing( 0 );
566 QFrame* titFrame = new QFrame( mainFrame() );
567 QHBoxLayout* titLay = new QHBoxLayout( titFrame );
568 titLay->setMargin( 0 );
569 titLay->setSpacing( SPACING );
571 myIconLabel = new QLabel( titFrame );
572 myIconLabel->setScaledContents( false );
573 myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
574 myTypeLabel = new QLabel( titFrame );
576 myTypeLabel->setText( creator->hypType() );
578 titLay->addWidget( myIconLabel, 0 );
579 titLay->addWidget( myTypeLabel, 0 );
580 titLay->addStretch( 1 );
582 topLayout->addWidget( titFrame, 0 );
584 myHelpFileName = creator->helpPage();
586 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
589 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
594 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
598 f->setParent( mainFrame() );
599 qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
603 void SMESHGUI_HypothesisDlg::accept()
606 QStringList absentParams;
607 if ( myCreator && !myCreator->checkParams( msg, absentParams ) )
609 if( !absentParams.isEmpty() )
611 SalomeApp_Application* app =
612 dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
614 app->defineAbsentParameters( absentParams );
617 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
618 if ( !msg.isEmpty() )
620 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
626 void SMESHGUI_HypothesisDlg::reject()
628 if ( myCreator ) myCreator->onReject();
632 void SMESHGUI_HypothesisDlg::onHelp()
634 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
636 SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
637 app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->moduleName()) : QString(""), myHelpFileName);
642 platform = "winapplication";
644 platform = "application";
646 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
647 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
648 arg(app->resourceMgr()->stringValue("ExternalBrowser",
650 arg(myHelpFileName));
654 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
656 myIconLabel->setPixmap( p );
659 void SMESHGUI_HypothesisDlg::setType( const QString& t )
661 myTypeLabel->setText( t );
664 HypothesisData::HypothesisData( const QString& theTypeName,
665 const QString& thePluginName,
666 const QString& theServerLibName,
667 const QString& theClientLibName,
668 const QString& theLabel,
669 const QString& theIconId,
670 const QList<int>& theDim,
672 const QStringList& theNeededHypos,
673 const QStringList& theOptionalHypos,
674 const QStringList& theInputTypes,
675 const QStringList& theOutputTypes,
676 const bool theIsNeedGeometry,
677 const bool supportSub)
678 : TypeName( theTypeName ),
679 PluginName( thePluginName ),
680 ServerLibName( theServerLibName ),
681 ClientLibName( theClientLibName ),
686 NeededHypos( theNeededHypos ),
687 OptionalHypos( theOptionalHypos ),
688 InputTypes( theInputTypes ),
689 OutputTypes( theOutputTypes ),
690 IsNeedGeometry( theIsNeedGeometry ),
691 IsSupportSubmeshes( supportSub )
695 HypothesesSet::HypothesesSet( const QString& theSetName )
696 : myHypoSetName( theSetName ),
701 HypothesesSet::HypothesesSet( const QString& theSetName,
702 const QStringList& theHypoList,
703 const QStringList& theAlgoList )
704 : myHypoSetName( theSetName ),
705 myHypoList( theHypoList ),
706 myAlgoList( theAlgoList ),
711 QStringList* HypothesesSet::list(bool is_algo) const
713 return const_cast<QStringList*>( &( is_algo ? myAlgoList : myHypoList ) );
716 QStringList* HypothesesSet::list() const
718 return list( myIsAlgo );
721 QString HypothesesSet::name() const
723 return myHypoSetName;
726 void HypothesesSet::set( bool isAlgo, const QStringList& lst )
731 int HypothesesSet::count( bool isAlgo ) const
733 return list(isAlgo)->count();
736 bool HypothesesSet::isAlgo() const
741 void HypothesesSet::init( bool isAlgo )
747 bool HypothesesSet::more() const
749 return myIndex < list()->count();
752 void HypothesesSet::next()
757 QString HypothesesSet::current() const
759 return list()->at(myIndex);