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() );
125 connect( SMESHGUI::GetSMESHGUI(), SIGNAL( SignalCloseAllDialogs() ), Dlg, SLOT( reject() ));
128 QFrame* fr = buildFrame();
131 Dlg->setCustomFrame( fr );
132 Dlg->setWindowTitle( caption() );
133 Dlg->setObjectName( theHypName );
134 Dlg->setHIcon( icon() );
135 Dlg->setType( type() );
138 Dlg->resize( Dlg->minimumSizeHint() );
141 emit finished( QDialog::Accepted );
144 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
146 if( CORBA::is_nil( hypothesis() ) )
149 ListOfStdParams params;
150 if( !stdParams( params ) || params.isEmpty() )
153 QFrame* fr = new QFrame( 0 );
154 QVBoxLayout* lay = new QVBoxLayout( fr );
156 lay->setSpacing( 0 );
158 QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
159 lay->addWidget( GroupC1 );
161 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
162 GroupC1Layout->setSpacing( SPACING );
163 GroupC1Layout->setMargin( MARGIN );
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, i );
173 switch( (*anIt).myValue.type() )
177 SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
178 sb->setObjectName( (*anIt).myName );
179 attuneStdWidget( sb, i );
180 sb->setValue( (*anIt).myValue.toInt() );
181 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
185 case QVariant::Double:
187 SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
188 sb->setObjectName( (*anIt).myName );
189 attuneStdWidget( sb, i );
190 sb->setValue( (*anIt).myValue.toDouble() );
191 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
195 case QVariant::String:
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() ) );
218 QLineEdit* le = new QLineEdit( GroupC1 );
219 le->setObjectName( (*anIt).myName );
220 attuneStdWidget( le, i );
221 le->setText( (*anIt).myValue.toString() );
222 connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
231 GroupC1Layout->addWidget( w, i, 1 );
232 changeWidgets().append( w );
239 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
241 valueChanged( (QWidget*) sender() );
244 void SMESHGUI_GenericHypothesisCreator::valueChanged( QWidget* )
248 void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int result )
250 bool res = result==QDialog::Accepted;
253 /*QString paramValues = */storeParams();
254 // No longer needed since NoteBook appears and "Value" OB field shows names of variable
255 // if ( !paramValues.isEmpty() ) {
256 // if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
257 // SMESH::SetValue( SHyp, paramValues );
261 changeWidgets().clear();
263 if( myIsCreate && !res )
265 //remove just created hypothesis
266 _PTR(SObject) aHypSObject = SMESH::FindSObject( myHypo );
267 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
268 if( aStudy && !aStudy->GetProperties()->IsLocked() )
270 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
271 aBuilder->RemoveObjectWithChildren( aHypSObject );
274 else if( !myIsCreate && res )
276 SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( myHypo );
277 if( listSOmesh.size() > 0 )
278 for( int i = 0; i < listSOmesh.size(); i++ )
280 _PTR(SObject) submSO = listSOmesh[i];
281 SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
282 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
283 if( !aSubMesh->_is_nil() )
284 aMesh = aSubMesh->GetFather();
285 _PTR(SObject) meshSO = SMESH::FindSObject( aMesh );
286 SMESH::ModifiedMesh( meshSO, false, aMesh->NbNodes()==0);
289 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
290 myHypo = SMESH::SMESH_Hypothesis::_nil();
291 myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
293 disconnect( myDlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
297 emit finished( result );
300 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
305 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
309 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
310 for( ; anIt!=aLast; anIt++ )
312 item.myName = (*anIt)->objectName();
313 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
315 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
316 item.myValue = sb->value();
317 params.append( item );
320 else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
322 SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
323 item.myValue = sb->value();
324 params.append( item );
327 else if( (*anIt)->inherits( "QLineEdit" ) )
329 QLineEdit* line = ( QLineEdit* )( *anIt );
330 item.myValue = line->text();
331 params.append( item );
334 else if ( getParamFromCustomWidget( item, *anIt ))
336 params.append( item );
346 QStringList SMESHGUI_GenericHypothesisCreator::getVariablesFromDlg() const
349 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
350 for( ; anIt!=aLast; anIt++ ) {
351 if( (*anIt)->inherits( "QAbstractSpinBox" ) ) {
352 QAbstractSpinBox* sb = ( QAbstractSpinBox* )( *anIt );
353 aResult.append(sb->text());
359 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
361 QString valueStr = "";
362 ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
364 for( int i=0; param!=aLast; param++, i++ )
366 if ( valueStr.length() > len0 ) {
368 len0 = valueStr.length();
370 switch( (*param).myValue.type() )
373 valueStr += valueStr.number( (*param).myValue.toInt() );
375 case QVariant::Double:
376 valueStr += valueStr.number( (*param).myValue.toDouble() );
378 case QVariant::String:
379 valueStr += (*param).myValue.toString();
382 QVariant valCopy = (*param).myValue;
383 valueStr += valCopy.toString();
389 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
394 void SMESHGUI_GenericHypothesisCreator::setShapeEntry( const QString& theEntry )
396 myShapeEntry = theEntry;
399 //================================================================================
401 * \brief Return hypothesis containing initial parameters
402 * \param strictly - if true, always return myInitParamsHypo,
403 * else, return myInitParamsHypo only in creation mode and if it
406 //================================================================================
408 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis(const bool strictly) const
411 return myInitParamsHypo;
412 if ( !isCreation() || CORBA::is_nil( myInitParamsHypo ))
414 return myInitParamsHypo;
417 bool SMESHGUI_GenericHypothesisCreator::hasInitParamsHypothesis() const
419 return !CORBA::is_nil( myInitParamsHypo );
422 QString SMESHGUI_GenericHypothesisCreator::hypType() const
427 QString SMESHGUI_GenericHypothesisCreator::hypName() const
432 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
434 return myParamWidgets;
437 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
439 return myParamWidgets;
442 QtxDialog* SMESHGUI_GenericHypothesisCreator:: dlg() const
447 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
452 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
456 QString SMESHGUI_GenericHypothesisCreator::caption() const
461 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
466 QString SMESHGUI_GenericHypothesisCreator::type() const
470 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
472 const int /*index*/) const
476 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWidget* ) const
481 bool SMESHGUI_GenericHypothesisCreator::checkParams( QString& msg ) const
484 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
485 for( ; anIt!=aLast; anIt++ )
487 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
489 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
490 ok = sb->isValid( msg, true ) && ok;
492 else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
494 SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
495 ok = sb->isValid( msg, true ) && ok;
501 void SMESHGUI_GenericHypothesisCreator::onReject()
505 QString SMESHGUI_GenericHypothesisCreator::helpPage() const
507 QString aHypType = hypType();
508 QString aHelpFileName = "";
509 if ( aHypType == "LocalLength" )
510 aHelpFileName = "a1d_meshing_hypo_page.html#average_length_anchor";
511 else if ( aHypType == "MaxLength" )
512 aHelpFileName = "a1d_meshing_hypo_page.html#max_length_anchor";
513 else if ( aHypType == "Arithmetic1D")
514 aHelpFileName = "a1d_meshing_hypo_page.html#arithmetic_1d_anchor";
515 else if ( aHypType == "FixedPoints1D")
516 aHelpFileName = "a1d_meshing_hypo_page.html#fixed_points_1d_anchor";
517 else if ( aHypType == "MaxElementArea")
518 aHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
519 else if ( aHypType == "MaxElementVolume")
520 aHelpFileName = "max_element_volume_hypo_page.html";
521 else if ( aHypType == "StartEndLength")
522 aHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
523 else if ( aHypType == "Deflection1D")
524 aHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
525 else if ( aHypType == "AutomaticLength")
526 aHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
527 else if ( aHypType == "NumberOfSegments")
528 aHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
529 else if ( aHypType == "ProjectionSource1D")
530 aHelpFileName = "projection_algos_page.html";
531 else if ( aHypType == "ProjectionSource2D")
532 aHelpFileName = "projection_algos_page.html";
533 else if ( aHypType == "ProjectionSource3D")
534 aHelpFileName = "projection_algos_page.html";
535 else if ( aHypType == "NumberOfLayers")
536 aHelpFileName = "radial_prism_algo_page.html";
537 else if ( aHypType == "NumberOfLayers2D")
538 aHelpFileName = "radial_quadrangle_1D2D_algo_page.html";
539 else if ( aHypType == "LayerDistribution")
540 aHelpFileName = "radial_prism_algo_page.html";
541 else if ( aHypType == "LayerDistribution2D")
542 aHelpFileName = "radial_quadrangle_1D2D_algo_page.html";
543 else if ( aHypType == "SegmentLengthAroundVertex")
544 aHelpFileName = "segments_around_vertex_algo_page.html";
545 else if ( aHypType == "QuadrangleParams")
546 aHelpFileName = "a2d_meshing_hypo_page.html#hypo_quad_params_anchor";
547 return aHelpFileName;
553 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
554 : QtxDialog( parent, false, true ),
557 setAttribute(Qt::WA_DeleteOnClose, true);
558 setMinimumSize( 300, height() );
559 // setFixedSize( 300, height() );
560 QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
561 topLayout->setMargin( 0 );
562 topLayout->setSpacing( 0 );
564 QFrame* titFrame = new QFrame( mainFrame() );
565 QHBoxLayout* titLay = new QHBoxLayout( titFrame );
566 titLay->setMargin( 0 );
567 titLay->setSpacing( SPACING );
569 myIconLabel = new QLabel( titFrame );
570 myIconLabel->setScaledContents( false );
571 myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
572 myTypeLabel = new QLabel( titFrame );
574 myTypeLabel->setText( creator->hypType() );
576 titLay->addWidget( myIconLabel, 0 );
577 titLay->addWidget( myTypeLabel, 0 );
578 titLay->addStretch( 1 );
580 topLayout->addWidget( titFrame, 0 );
582 myHelpFileName = creator->helpPage();
584 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
587 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
592 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
596 f->setParent( mainFrame() );
597 qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
601 void SMESHGUI_HypothesisDlg::accept()
604 if ( myCreator && !myCreator->checkParams( msg ) )
606 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
607 if ( !msg.isEmpty() )
609 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
615 void SMESHGUI_HypothesisDlg::reject()
617 if ( myCreator ) myCreator->onReject();
621 void SMESHGUI_HypothesisDlg::onHelp()
623 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
625 SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
626 app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->moduleName()) : QString(""), myHelpFileName);
631 platform = "winapplication";
633 platform = "application";
635 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
636 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
637 arg(app->resourceMgr()->stringValue("ExternalBrowser",
639 arg(myHelpFileName));
643 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
645 myIconLabel->setPixmap( p );
648 void SMESHGUI_HypothesisDlg::setType( const QString& t )
650 myTypeLabel->setText( t );
653 HypothesisData::HypothesisData( const QString& theTypeName,
654 const QString& thePluginName,
655 const QString& theServerLibName,
656 const QString& theClientLibName,
657 const QString& theLabel,
658 const QString& theIconId,
659 const QList<int>& theDim,
661 const QStringList& theNeededHypos,
662 const QStringList& theOptionalHypos,
663 const QStringList& theInputTypes,
664 const QStringList& theOutputTypes,
665 const bool theIsNeedGeometry,
666 const bool supportSub)
667 : TypeName( theTypeName ),
668 PluginName( thePluginName ),
669 ServerLibName( theServerLibName ),
670 ClientLibName( theClientLibName ),
675 NeededHypos( theNeededHypos ),
676 OptionalHypos( theOptionalHypos ),
677 InputTypes( theInputTypes ),
678 OutputTypes( theOutputTypes ),
679 IsNeedGeometry( theIsNeedGeometry ),
680 IsSupportSubmeshes( supportSub )
684 HypothesesSet::HypothesesSet( const QString& theSetName )
685 : myHypoSetName( theSetName ),
690 HypothesesSet::HypothesesSet( const QString& theSetName,
691 const QStringList& theHypoList,
692 const QStringList& theAlgoList )
693 : myHypoSetName( theSetName ),
694 myHypoList( theHypoList ),
695 myAlgoList( theAlgoList ),
700 QStringList* HypothesesSet::list(bool is_algo) const
702 return const_cast<QStringList*>( &( is_algo ? myAlgoList : myHypoList ) );
705 QStringList* HypothesesSet::list() const
707 return list( myIsAlgo );
710 QString HypothesesSet::name() const
712 return myHypoSetName;
715 void HypothesesSet::set( bool isAlgo, const QStringList& lst )
720 int HypothesesSet::count( bool isAlgo ) const
722 return list(isAlgo)->count();
725 bool HypothesesSet::isAlgo() const
730 void HypothesesSet::init( bool isAlgo )
736 bool HypothesesSet::more() const
738 return myIndex < list()->count();
741 void HypothesesSet::next()
746 QString HypothesesSet::current() const
748 return list()->at(myIndex);