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_IntSpinBox.h>
50 #include <QVBoxLayout>
55 SMESHGUI_GenericHypothesisCreator::SMESHGUI_GenericHypothesisCreator( const QString& theHypType )
56 : myHypType( theHypType ), myIsCreate( false ), myDlg( 0 )
60 SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator()
64 void SMESHGUI_GenericHypothesisCreator::setInitParamsHypothesis(SMESH::SMESH_Hypothesis_ptr hyp)
66 if ( !CORBA::is_nil( hyp ) && hypType() == hyp->GetName() )
67 myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( hyp );
70 void SMESHGUI_GenericHypothesisCreator::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp,
71 const QString& theHypName,
72 QWidget* parent, QObject* obj, const QString& slot )
74 MESSAGE( "Creation of hypothesis with initial params" );
75 setInitParamsHypothesis( initParamsHyp );
76 create( false, theHypName, parent, obj, slot );
79 void SMESHGUI_GenericHypothesisCreator::create( bool isAlgo,
80 const QString& theHypName,
81 QWidget* theParent, QObject* obj, const QString& slot )
83 MESSAGE( "Creation of hypothesis" );
87 // Create hypothesis/algorithm
89 SMESH::CreateHypothesis( hypType(), theHypName, isAlgo );
93 SMESH::SMESH_Hypothesis_var aHypothesis =
94 SMESH::CreateHypothesis( hypType(), theHypName, false );
95 editHypothesis( aHypothesis.in(), theHypName, theParent, obj, slot );
99 void SMESHGUI_GenericHypothesisCreator::edit( SMESH::SMESH_Hypothesis_ptr theHypothesis,
100 const QString& theHypName,
101 QWidget* theParent, QObject* obj, const QString& slot )
103 if( CORBA::is_nil( theHypothesis ) )
106 MESSAGE("Edition of hypothesis");
110 editHypothesis( theHypothesis, theHypName, theParent, obj, slot );
113 void SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ptr h,
114 const QString& theHypName,
116 QObject* obj, const QString& slot )
118 myHypName = theHypName;
119 myHypo = SMESH::SMESH_Hypothesis::_duplicate( h );
121 SMESHGUI_HypothesisDlg* Dlg = new SMESHGUI_HypothesisDlg( this, theParent );
122 connect( Dlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
123 connect( this, SIGNAL( finished( int ) ), obj, slot.toLatin1().constData() );
126 QFrame* fr = buildFrame();
129 Dlg->setCustomFrame( fr );
130 Dlg->setWindowTitle( caption() );
131 Dlg->setObjectName( theHypName );
132 Dlg->setHIcon( icon() );
133 Dlg->setType( type() );
136 Dlg->resize( Dlg->minimumSizeHint() );
139 emit finished( QDialog::Accepted );
142 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
144 if( CORBA::is_nil( hypothesis() ) )
147 ListOfStdParams params;
148 if( !stdParams( params ) || params.isEmpty() )
151 QFrame* fr = new QFrame( 0 );
152 QVBoxLayout* lay = new QVBoxLayout( fr );
154 lay->setSpacing( 0 );
156 QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
157 lay->addWidget( GroupC1 );
159 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
160 GroupC1Layout->setSpacing( SPACING );
161 GroupC1Layout->setMargin( MARGIN );
163 ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end();
164 for( int i=0; anIt!=aLast; anIt++, i++ )
166 QLabel* lab = new QLabel( (*anIt).myName, GroupC1 );
167 GroupC1Layout->addWidget( lab, i, 0 );
169 QWidget* w = getCustomWidget( *anIt, GroupC1, i );
171 switch( (*anIt).myValue.type() )
175 SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
176 sb->setObjectName( (*anIt).myName );
177 attuneStdWidget( sb, i );
178 sb->setValue( (*anIt).myValue.toInt() );
179 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
183 case QVariant::Double:
185 SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
186 sb->setObjectName( (*anIt).myName );
187 attuneStdWidget( sb, i );
188 sb->setValue( (*anIt).myValue.toDouble() );
189 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
193 case QVariant::String:
195 if((*anIt).isVariable) {
196 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
197 QString aVar = (*anIt).myValue.toString();
198 if(aStudy->IsInteger(aVar.toLatin1().constData())){
199 SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
200 sb->setObjectName( (*anIt).myName );
201 attuneStdWidget( sb, i );
203 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
206 else if(aStudy->IsReal(aVar.toLatin1().constData())){
207 SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
208 sb->setObjectName( (*anIt).myName );
209 attuneStdWidget( sb, i );
211 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
216 QLineEdit* le = new QLineEdit( GroupC1 );
217 le->setObjectName( (*anIt).myName );
218 attuneStdWidget( le, i );
219 le->setText( (*anIt).myValue.toString() );
220 connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
229 GroupC1Layout->addWidget( w, i, 1 );
230 changeWidgets().append( w );
237 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
239 valueChanged( (QWidget*) sender() );
242 void SMESHGUI_GenericHypothesisCreator::valueChanged( QWidget* )
246 void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int result )
248 bool res = result==QDialog::Accepted;
251 /*QString paramValues = */storeParams();
252 // No longer needed since NoteBook appears and "Value" OB field shows names of variable
253 // if ( !paramValues.isEmpty() ) {
254 // if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
255 // SMESH::SetValue( SHyp, paramValues );
259 changeWidgets().clear();
261 if( myIsCreate && !res )
263 //remove just created hypothesis
264 _PTR(SObject) aHypSObject = SMESH::FindSObject( myHypo );
265 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
266 if( aStudy && !aStudy->GetProperties()->IsLocked() )
268 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
269 aBuilder->RemoveObjectWithChildren( aHypSObject );
272 else if( !myIsCreate && res )
274 SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( myHypo );
275 if( listSOmesh.size() > 0 )
276 for( int i = 0; i < listSOmesh.size(); i++ )
278 _PTR(SObject) submSO = listSOmesh[i];
279 SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
280 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
281 if( !aSubMesh->_is_nil() )
282 aMesh = aSubMesh->GetFather();
283 _PTR(SObject) meshSO = SMESH::FindSObject( aMesh );
284 SMESH::ModifiedMesh( meshSO, false, aMesh->NbNodes()==0);
287 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
288 myHypo = SMESH::SMESH_Hypothesis::_nil();
289 myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
290 myDlg->close(); myDlg = 0;
291 //delete myDlg; myDlg = 0;
292 emit finished( result );
295 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
300 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
304 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
305 for( ; anIt!=aLast; anIt++ )
307 item.myName = (*anIt)->objectName();
308 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
310 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
311 item.myValue = sb->value();
312 params.append( item );
315 else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
317 SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
318 item.myValue = sb->value();
319 params.append( item );
322 else if( (*anIt)->inherits( "QLineEdit" ) )
324 QLineEdit* line = ( QLineEdit* )( *anIt );
325 item.myValue = line->text();
326 params.append( item );
329 else if ( getParamFromCustomWidget( item, *anIt ))
331 params.append( item );
341 QStringList SMESHGUI_GenericHypothesisCreator::getVariablesFromDlg() const
344 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
345 for( ; anIt!=aLast; anIt++ ) {
346 if( (*anIt)->inherits( "QAbstractSpinBox" ) ) {
347 QAbstractSpinBox* sb = ( QAbstractSpinBox* )( *anIt );
348 aResult.append(sb->text());
354 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
356 QString valueStr = "";
357 ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
359 for( int i=0; param!=aLast; param++, i++ )
361 if ( valueStr.length() > len0 ) {
363 len0 = valueStr.length();
365 switch( (*param).myValue.type() )
368 valueStr += valueStr.number( (*param).myValue.toInt() );
370 case QVariant::Double:
371 valueStr += valueStr.number( (*param).myValue.toDouble() );
373 case QVariant::String:
374 valueStr += (*param).myValue.toString();
377 QVariant valCopy = (*param).myValue;
378 valueStr += valCopy.toString();
384 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
389 void SMESHGUI_GenericHypothesisCreator::setShapeEntry( const QString& theEntry )
391 myShapeEntry = theEntry;
394 //================================================================================
396 * \brief Return hypothesis containing initial parameters
397 * \param strictly - if true, always return myInitParamsHypo,
398 * else, return myInitParamsHypo only in creation mode and if it
401 //================================================================================
403 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis(const bool strictly) const
406 return myInitParamsHypo;
407 if ( !isCreation() || CORBA::is_nil( myInitParamsHypo ))
409 return myInitParamsHypo;
412 bool SMESHGUI_GenericHypothesisCreator::hasInitParamsHypothesis() const
414 return !CORBA::is_nil( myInitParamsHypo );
417 QString SMESHGUI_GenericHypothesisCreator::hypType() const
422 QString SMESHGUI_GenericHypothesisCreator::hypName() const
427 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
429 return myParamWidgets;
432 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
434 return myParamWidgets;
437 QtxDialog* SMESHGUI_GenericHypothesisCreator:: dlg() const
442 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
447 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
451 QString SMESHGUI_GenericHypothesisCreator::caption() const
456 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
461 QString SMESHGUI_GenericHypothesisCreator::type() const
465 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
467 const int /*index*/) const
471 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWidget* ) const
476 bool SMESHGUI_GenericHypothesisCreator::checkParams( QString& msg ) const
479 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
480 for( ; anIt!=aLast; anIt++ )
482 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
484 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
485 ok = sb->isValid( msg, true ) && ok;
487 else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
489 SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
490 ok = sb->isValid( msg, true ) && ok;
496 void SMESHGUI_GenericHypothesisCreator::onReject()
500 QString SMESHGUI_GenericHypothesisCreator::helpPage() const
502 QString aHypType = hypType();
503 QString aHelpFileName = "";
504 if ( aHypType == "LocalLength" )
505 aHelpFileName = "a1d_meshing_hypo_page.html#average_length_anchor";
506 else if ( aHypType == "MaxLength" )
507 aHelpFileName = "a1d_meshing_hypo_page.html#max_length_anchor";
508 else if ( aHypType == "Arithmetic1D")
509 aHelpFileName = "a1d_meshing_hypo_page.html#arithmetic_1d_anchor";
510 else if ( aHypType == "FixedPointsc1D")
511 aHelpFileName = "a1d_meshing_hypo_page.html#fixed_points_1d_anchor";
512 else if ( aHypType == "MaxElementArea")
513 aHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
514 else if ( aHypType == "MaxElementVolume")
515 aHelpFileName = "max_element_volume_hypo_page.html";
516 else if ( aHypType == "StartEndLength")
517 aHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
518 else if ( aHypType == "Deflection1D")
519 aHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
520 else if ( aHypType == "AutomaticLength")
521 aHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
522 else if ( aHypType == "NumberOfSegments")
523 aHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
524 else if ( aHypType == "ProjectionSource1D")
525 aHelpFileName = "projection_algos_page.html";
526 else if ( aHypType == "ProjectionSource2D")
527 aHelpFileName = "projection_algos_page.html";
528 else if ( aHypType == "ProjectionSource3D")
529 aHelpFileName = "projection_algos_page.html";
530 else if ( aHypType == "NumberOfLayers")
531 aHelpFileName = "radial_prism_algo_page.html";
532 else if ( aHypType == "LayerDistribution")
533 aHelpFileName = "radial_prism_algo_page.html";
534 else if ( aHypType == "SegmentLengthAroundVertex")
535 aHelpFileName = "segments_around_vertex_algo_page.html";
537 return aHelpFileName;
543 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
544 : QtxDialog( parent, false, true ),
547 setAttribute(Qt::WA_DeleteOnClose, true);
548 setMinimumSize( 300, height() );
549 // setFixedSize( 300, height() );
550 QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
551 topLayout->setMargin( 0 );
552 topLayout->setSpacing( 0 );
554 QFrame* titFrame = new QFrame( mainFrame() );
555 QHBoxLayout* titLay = new QHBoxLayout( titFrame );
556 titLay->setMargin( 0 );
557 titLay->setSpacing( SPACING );
559 myIconLabel = new QLabel( titFrame );
560 myIconLabel->setScaledContents( false );
561 myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
562 myTypeLabel = new QLabel( titFrame );
564 myTypeLabel->setText( creator->hypType() );
566 titLay->addWidget( myIconLabel, 0 );
567 titLay->addWidget( myTypeLabel, 0 );
568 titLay->addStretch( 1 );
570 topLayout->addWidget( titFrame, 0 );
572 myHelpFileName = creator->helpPage();
574 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
577 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
582 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
586 f->setParent( mainFrame() );
587 qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
591 void SMESHGUI_HypothesisDlg::accept()
594 if ( myCreator && !myCreator->checkParams( msg ) )
596 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
597 if ( !msg.isEmpty() )
599 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
605 void SMESHGUI_HypothesisDlg::reject()
607 if ( myCreator ) myCreator->onReject();
611 void SMESHGUI_HypothesisDlg::onHelp()
613 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
615 SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
616 app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->moduleName()) : QString(""), myHelpFileName);
621 platform = "winapplication";
623 platform = "application";
625 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
626 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
627 arg(app->resourceMgr()->stringValue("ExternalBrowser",
629 arg(myHelpFileName));
633 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
635 myIconLabel->setPixmap( p );
638 void SMESHGUI_HypothesisDlg::setType( const QString& t )
640 myTypeLabel->setText( t );
643 HypothesisData::HypothesisData( const QString& theTypeName,
644 const QString& thePluginName,
645 const QString& theServerLibName,
646 const QString& theClientLibName,
647 const QString& theLabel,
648 const QString& theIconId,
649 const QList<int>& theDim,
651 const QStringList& theNeededHypos,
652 const QStringList& theOptionalHypos,
653 const QStringList& theInputTypes,
654 const QStringList& theOutputTypes,
655 const bool theIsNeedGeometry,
656 const bool supportSub)
657 : TypeName( theTypeName ),
658 PluginName( thePluginName ),
659 ServerLibName( theServerLibName ),
660 ClientLibName( theClientLibName ),
665 NeededHypos( theNeededHypos ),
666 OptionalHypos( theOptionalHypos ),
667 InputTypes( theInputTypes ),
668 OutputTypes( theOutputTypes ),
669 IsNeedGeometry( theIsNeedGeometry ),
670 IsSupportSubmeshes( supportSub )
674 HypothesesSet::HypothesesSet( const QString& theSetName )
675 : myHypoSetName( theSetName ),
680 HypothesesSet::HypothesesSet( const QString& theSetName,
681 const QStringList& theHypoList,
682 const QStringList& theAlgoList )
683 : myHypoSetName( theSetName ),
684 myHypoList( theHypoList ),
685 myAlgoList( theAlgoList ),
690 QStringList* HypothesesSet::list(bool is_algo) const
692 return const_cast<QStringList*>( &( is_algo ? myAlgoList : myHypoList ) );
695 QStringList* HypothesesSet::list() const
697 return list( myIsAlgo );
700 QString HypothesesSet::name() const
702 return myHypoSetName;
705 void HypothesesSet::set( bool isAlgo, const QStringList& lst )
710 int HypothesesSet::count( bool isAlgo ) const
712 return list(isAlgo)->count();
715 bool HypothesesSet::isAlgo() const
720 void HypothesesSet::init( bool isAlgo )
726 bool HypothesesSet::more() const
728 return myIndex < list()->count();
731 void HypothesesSet::next()
736 QString HypothesesSet::current() const
738 return list()->at(myIndex);