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>
56 SMESHGUI_GenericHypothesisCreator::SMESHGUI_GenericHypothesisCreator( const QString& theHypType )
57 : myHypType( theHypType ), myIsCreate( false ), myDlg( 0 ), myEventLoop( 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,
75 MESSAGE( "Creation of hypothesis with initial params" );
76 setInitParamsHypothesis( initParamsHyp );
77 create( false, theHypName, parent );
80 void SMESHGUI_GenericHypothesisCreator::create( bool isAlgo,
81 const QString& theHypName,
84 MESSAGE( "Creation of hypothesis" );
88 // Create hypothesis/algorithm
90 SMESH::CreateHypothesis( hypType(), theHypName, isAlgo );
93 SMESH::SMESH_Hypothesis_var aHypothesis =
94 SMESH::CreateHypothesis( hypType(), theHypName, false );
95 if( !editHypothesis( aHypothesis.in(), theHypName, theParent ) )
96 { //remove just created hypothesis
97 _PTR(SObject) aHypSObject = SMESH::FindSObject( aHypothesis.in() );
98 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
99 if( aStudy && !aStudy->GetProperties()->IsLocked() )
101 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
102 aBuilder->RemoveObjectWithChildren( aHypSObject );
106 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
109 void SMESHGUI_GenericHypothesisCreator::edit( SMESH::SMESH_Hypothesis_ptr theHypothesis,
110 const QString& theHypName,
113 if( CORBA::is_nil( theHypothesis ) )
116 MESSAGE("Edition of hypothesis");
120 if( !editHypothesis( theHypothesis, theHypName, theParent ) )
123 SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( theHypothesis );
124 if( listSOmesh.size() > 0 )
125 for( int i = 0; i < listSOmesh.size(); i++ )
127 _PTR(SObject) submSO = listSOmesh[i];
128 SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
129 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
130 if( !aSubMesh->_is_nil() )
131 aMesh = aSubMesh->GetFather();
132 _PTR(SObject) meshSO = SMESH::FindSObject( aMesh );
133 SMESH::ModifiedMesh( meshSO, false, aMesh->NbNodes()==0);
135 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
138 bool SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ptr h,
139 const QString& theHypName,
142 if( CORBA::is_nil( h ) )
146 myHypName = theHypName;
147 myHypo = SMESH::SMESH_Hypothesis::_duplicate( h );
149 SMESHGUI_HypothesisDlg* Dlg = new SMESHGUI_HypothesisDlg( this, theParent );
150 connect( Dlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
152 QFrame* fr = buildFrame();
155 Dlg->setCustomFrame( fr );
156 Dlg->setWindowTitle( caption() );
157 Dlg->setObjectName( theHypName );
158 Dlg->setHIcon( icon() );
159 Dlg->setType( type() );
163 myEventLoop = new QEventLoop( this );
164 myEventLoop->exec(); // make myDlg not modal
165 res = myDlg->result();
167 QString paramValues = storeParams();
168 if ( !paramValues.isEmpty() ) {
169 if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
170 SMESH::SetValue( SHyp, paramValues );
174 delete Dlg; myDlg = 0;
175 changeWidgets().clear();
176 myHypo = SMESH::SMESH_Hypothesis::_nil();
177 myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
181 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
183 if( CORBA::is_nil( hypothesis() ) )
186 ListOfStdParams params;
187 if( !stdParams( params ) || params.isEmpty() )
190 QFrame* fr = new QFrame( 0 );
191 QVBoxLayout* lay = new QVBoxLayout( fr );
193 lay->setSpacing( 0 );
195 QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
196 lay->addWidget( GroupC1 );
198 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
199 GroupC1Layout->setSpacing( SPACING );
200 GroupC1Layout->setMargin( MARGIN );
202 ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end();
203 for( int i=0; anIt!=aLast; anIt++, i++ )
205 QLabel* lab = new QLabel( (*anIt).myName, GroupC1 );
206 GroupC1Layout->addWidget( lab, i, 0 );
208 QWidget* w = getCustomWidget( *anIt, GroupC1, i );
210 switch( (*anIt).myValue.type() )
214 SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
215 sb->setObjectName( (*anIt).myName );
216 attuneStdWidget( sb, i );
217 sb->setValue( (*anIt).myValue.toInt() );
218 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
222 case QVariant::Double:
224 SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
225 sb->setObjectName( (*anIt).myName );
226 attuneStdWidget( sb, i );
227 sb->setValue( (*anIt).myValue.toDouble() );
228 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
232 case QVariant::String:
234 if((*anIt).isVariable) {
235 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
236 QString aVar = (*anIt).myValue.toString();
237 if(aStudy->IsInteger(aVar.toLatin1().constData())){
238 SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
239 sb->setObjectName( (*anIt).myName );
240 attuneStdWidget( sb, i );
242 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
245 else if(aStudy->IsReal(aVar.toLatin1().constData())){
246 SalomeApp_DoubleSpinBox* sb = new SalomeApp_DoubleSpinBox( GroupC1 );
247 sb->setObjectName( (*anIt).myName );
248 attuneStdWidget( sb, i );
250 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
255 QLineEdit* le = new QLineEdit( GroupC1 );
256 le->setObjectName( (*anIt).myName );
257 attuneStdWidget( le, i );
258 le->setText( (*anIt).myValue.toString() );
259 connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
268 GroupC1Layout->addWidget( w, i, 1 );
269 changeWidgets().append( w );
276 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
278 valueChanged( (QWidget*) sender() );
281 void SMESHGUI_GenericHypothesisCreator::valueChanged( QWidget* )
285 void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int /*result*/ )
291 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
296 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
300 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
301 for( ; anIt!=aLast; anIt++ )
303 item.myName = (*anIt)->objectName();
304 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
306 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
307 item.myValue = sb->value();
308 params.append( item );
311 else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
313 SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
314 item.myValue = sb->value();
315 params.append( item );
318 else if( (*anIt)->inherits( "QLineEdit" ) )
320 QLineEdit* line = ( QLineEdit* )( *anIt );
321 item.myValue = line->text();
322 params.append( item );
325 else if ( getParamFromCustomWidget( item, *anIt ))
327 params.append( item );
337 QStringList SMESHGUI_GenericHypothesisCreator::getVariablesFromDlg() const
340 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
341 for( ; anIt!=aLast; anIt++ ) {
342 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) ) {
343 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
344 aResult.append(sb->text());
346 else if( (*anIt)->inherits( "QtxDoubleSpinBox" ) ) {
347 QtxDoubleSpinBox* sb = ( QtxDoubleSpinBox* )( *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 //================================================================================
391 * \brief Return hypothesis containing initial parameters
392 * \param strictly - if true, always return myInitParamsHypo,
393 * else, return myInitParamsHypo only in creation mode and if it
396 //================================================================================
398 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis(const bool strictly) const
401 return myInitParamsHypo;
402 if ( !isCreation() || CORBA::is_nil( myInitParamsHypo ))
404 return myInitParamsHypo;
407 bool SMESHGUI_GenericHypothesisCreator::hasInitParamsHypothesis() const
409 return !CORBA::is_nil( myInitParamsHypo );
412 QString SMESHGUI_GenericHypothesisCreator::hypType() const
417 QString SMESHGUI_GenericHypothesisCreator::hypName() const
422 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
424 return myParamWidgets;
427 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
429 return myParamWidgets;
432 QtxDialog* SMESHGUI_GenericHypothesisCreator:: dlg() const
437 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
442 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
446 QString SMESHGUI_GenericHypothesisCreator::caption() const
451 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
456 QString SMESHGUI_GenericHypothesisCreator::type() const
460 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
462 const int /*index*/) const
466 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWidget* ) const
471 bool SMESHGUI_GenericHypothesisCreator::checkParams( QString& msg ) const
474 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
475 for( ; anIt!=aLast; anIt++ )
477 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
479 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
480 ok = sb->isValid( msg, true ) && ok;
482 else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
484 SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
485 ok = sb->isValid( msg, true ) && ok;
491 void SMESHGUI_GenericHypothesisCreator::onReject()
495 QString SMESHGUI_GenericHypothesisCreator::helpPage() const
497 QString aHypType = hypType();
498 QString aHelpFileName;
499 if ( aHypType == "LocalLength" )
500 aHelpFileName = "a1d_meshing_hypo_page.html#average_length_anchor";
501 else if ( aHypType == "Arithmetic1D")
502 aHelpFileName = "a1d_meshing_hypo_page.html#arithmetic_1d_anchor";
503 else if ( aHypType == "MaxElementArea")
504 aHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
505 else if ( aHypType == "MaxElementVolume")
506 aHelpFileName = "max_element_volume_hypo_page.html";
507 else if ( aHypType == "StartEndLength")
508 aHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
509 else if ( aHypType == "Deflection1D")
510 aHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
511 else if ( aHypType == "AutomaticLength")
512 aHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
513 else if ( aHypType == "NumberOfSegments")
514 aHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
515 else if ( aHypType == "ProjectionSource1D")
516 aHelpFileName = "projection_algos_page.html";
517 else if ( aHypType == "ProjectionSource2D")
518 aHelpFileName = "projection_algos_page.html";
519 else if ( aHypType == "ProjectionSource3D")
520 aHelpFileName = "projection_algos_page.html";
521 else if ( aHypType == "NumberOfLayers")
522 aHelpFileName = "radial_prism_algo_page.html";
523 else if ( aHypType == "LayerDistribution")
524 aHelpFileName = "radial_prism_algo_page.html";
525 else if ( aHypType == "SegmentLengthAroundVertex")
526 aHelpFileName = "segments_around_vertex_algo.html";
529 return aHelpFileName;
535 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
536 : QtxDialog( parent, false, true ),
539 setMinimumSize( 300, height() );
540 // setFixedSize( 300, height() );
541 QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
542 topLayout->setMargin( 0 );
543 topLayout->setSpacing( 0 );
545 QFrame* titFrame = new QFrame( mainFrame() );
546 QHBoxLayout* titLay = new QHBoxLayout( titFrame );
547 titLay->setMargin( 0 );
548 titLay->setSpacing( SPACING );
550 myIconLabel = new QLabel( titFrame );
551 myIconLabel->setScaledContents( false );
552 myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
553 myTypeLabel = new QLabel( titFrame );
555 myTypeLabel->setText( creator->hypType() );
557 titLay->addWidget( myIconLabel, 0 );
558 titLay->addWidget( myTypeLabel, 0 );
559 titLay->addStretch( 1 );
561 topLayout->addWidget( titFrame, 0 );
563 myHelpFileName = creator->helpPage();
565 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
568 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
572 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
576 f->setParent( mainFrame() );
577 qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
581 void SMESHGUI_HypothesisDlg::accept()
584 if ( myCreator && !myCreator->checkParams( msg ) )
586 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
587 if ( !msg.isEmpty() )
589 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
595 void SMESHGUI_HypothesisDlg::reject()
597 if ( myCreator ) myCreator->onReject();
601 void SMESHGUI_HypothesisDlg::onHelp()
603 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
605 SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
606 app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->moduleName()) : QString(""), myHelpFileName);
611 platform = "winapplication";
613 platform = "application";
615 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
616 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
617 arg(app->resourceMgr()->stringValue("ExternalBrowser",
619 arg(myHelpFileName));
623 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
625 myIconLabel->setPixmap( p );
628 void SMESHGUI_HypothesisDlg::setType( const QString& t )
630 myTypeLabel->setText( t );
633 HypothesisData::HypothesisData( const QString& theTypeName,
634 const QString& thePluginName,
635 const QString& theServerLibName,
636 const QString& theClientLibName,
637 const QString& theLabel,
638 const QString& theIconId,
639 const QList<int>& theDim,
641 const QStringList& theNeededHypos,
642 const QStringList& theOptionalHypos,
643 const QStringList& theInputTypes,
644 const QStringList& theOutputTypes,
645 const bool theIsNeedGeometry,
646 const bool supportSub)
647 : TypeName( theTypeName ),
648 PluginName( thePluginName ),
649 ServerLibName( theServerLibName ),
650 ClientLibName( theClientLibName ),
655 NeededHypos( theNeededHypos ),
656 OptionalHypos( theOptionalHypos ),
657 InputTypes( theInputTypes ),
658 OutputTypes( theOutputTypes ),
659 IsNeedGeometry( theIsNeedGeometry ),
660 IsSupportSubmeshes( supportSub )
664 HypothesesSet::HypothesesSet( const QString& theSetName )
665 : HypoSetName( theSetName )
669 HypothesesSet::HypothesesSet( const QString& theSetName,
670 const QStringList& theHypoList,
671 const QStringList& theAlgoList )
672 : HypoSetName( theSetName ),
673 HypoList( theHypoList ),
674 AlgoList( theAlgoList )