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 // No longer needed since NoteBook appears and "Value" OB field shows names of variable
169 // if ( !paramValues.isEmpty() ) {
170 // if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
171 // SMESH::SetValue( SHyp, paramValues );
175 delete Dlg; myDlg = 0;
176 changeWidgets().clear();
177 myHypo = SMESH::SMESH_Hypothesis::_nil();
178 myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
182 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
184 if( CORBA::is_nil( hypothesis() ) )
187 ListOfStdParams params;
188 if( !stdParams( params ) || params.isEmpty() )
191 QFrame* fr = new QFrame( 0 );
192 QVBoxLayout* lay = new QVBoxLayout( fr );
194 lay->setSpacing( 0 );
196 QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
197 lay->addWidget( GroupC1 );
199 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
200 GroupC1Layout->setSpacing( SPACING );
201 GroupC1Layout->setMargin( MARGIN );
203 ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end();
204 for( int i=0; anIt!=aLast; anIt++, i++ )
206 QLabel* lab = new QLabel( (*anIt).myName, GroupC1 );
207 GroupC1Layout->addWidget( lab, i, 0 );
209 QWidget* w = getCustomWidget( *anIt, GroupC1, i );
211 switch( (*anIt).myValue.type() )
215 SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
216 sb->setObjectName( (*anIt).myName );
217 attuneStdWidget( sb, i );
218 sb->setValue( (*anIt).myValue.toInt() );
219 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
223 case QVariant::Double:
225 SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
226 sb->setObjectName( (*anIt).myName );
227 attuneStdWidget( sb, i );
228 sb->setValue( (*anIt).myValue.toDouble() );
229 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
233 case QVariant::String:
235 if((*anIt).isVariable) {
236 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
237 QString aVar = (*anIt).myValue.toString();
238 if(aStudy->IsInteger(aVar.toLatin1().constData())){
239 SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
240 sb->setObjectName( (*anIt).myName );
241 attuneStdWidget( sb, i );
243 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
246 else if(aStudy->IsReal(aVar.toLatin1().constData())){
247 SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
248 sb->setObjectName( (*anIt).myName );
249 attuneStdWidget( sb, i );
251 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
256 QLineEdit* le = new QLineEdit( GroupC1 );
257 le->setObjectName( (*anIt).myName );
258 attuneStdWidget( le, i );
259 le->setText( (*anIt).myValue.toString() );
260 connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
269 GroupC1Layout->addWidget( w, i, 1 );
270 changeWidgets().append( w );
277 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
279 valueChanged( (QWidget*) sender() );
282 void SMESHGUI_GenericHypothesisCreator::valueChanged( QWidget* )
286 void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int /*result*/ )
292 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
297 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
301 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
302 for( ; anIt!=aLast; anIt++ )
304 item.myName = (*anIt)->objectName();
305 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
307 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
308 item.myValue = sb->value();
309 params.append( item );
312 else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
314 SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
315 item.myValue = sb->value();
316 params.append( item );
319 else if( (*anIt)->inherits( "QLineEdit" ) )
321 QLineEdit* line = ( QLineEdit* )( *anIt );
322 item.myValue = line->text();
323 params.append( item );
326 else if ( getParamFromCustomWidget( item, *anIt ))
328 params.append( item );
338 QStringList SMESHGUI_GenericHypothesisCreator::getVariablesFromDlg() const
341 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
342 for( ; anIt!=aLast; anIt++ ) {
343 if( (*anIt)->inherits( "QAbstractSpinBox" ) ) {
344 QAbstractSpinBox* sb = ( QAbstractSpinBox* )( *anIt );
345 aResult.append(sb->text());
351 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
353 QString valueStr = "";
354 ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
356 for( int i=0; param!=aLast; param++, i++ )
358 if ( valueStr.length() > len0 ) {
360 len0 = valueStr.length();
362 switch( (*param).myValue.type() )
365 valueStr += valueStr.number( (*param).myValue.toInt() );
367 case QVariant::Double:
368 valueStr += valueStr.number( (*param).myValue.toDouble() );
370 case QVariant::String:
371 valueStr += (*param).myValue.toString();
374 QVariant valCopy = (*param).myValue;
375 valueStr += valCopy.toString();
381 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
386 //================================================================================
388 * \brief Return hypothesis containing initial parameters
389 * \param strictly - if true, always return myInitParamsHypo,
390 * else, return myInitParamsHypo only in creation mode and if it
393 //================================================================================
395 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis(const bool strictly) const
398 return myInitParamsHypo;
399 if ( !isCreation() || CORBA::is_nil( myInitParamsHypo ))
401 return myInitParamsHypo;
404 bool SMESHGUI_GenericHypothesisCreator::hasInitParamsHypothesis() const
406 return !CORBA::is_nil( myInitParamsHypo );
409 QString SMESHGUI_GenericHypothesisCreator::hypType() const
414 QString SMESHGUI_GenericHypothesisCreator::hypName() const
419 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
421 return myParamWidgets;
424 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
426 return myParamWidgets;
429 QtxDialog* SMESHGUI_GenericHypothesisCreator:: dlg() const
434 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
439 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
443 QString SMESHGUI_GenericHypothesisCreator::caption() const
448 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
453 QString SMESHGUI_GenericHypothesisCreator::type() const
457 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
459 const int /*index*/) const
463 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWidget* ) const
468 bool SMESHGUI_GenericHypothesisCreator::checkParams( QString& msg ) const
471 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
472 for( ; anIt!=aLast; anIt++ )
474 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
476 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
477 ok = sb->isValid( msg, true ) && ok;
479 else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
481 SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
482 ok = sb->isValid( msg, true ) && ok;
488 void SMESHGUI_GenericHypothesisCreator::onReject()
492 QString SMESHGUI_GenericHypothesisCreator::helpPage() const
494 QString aHypType = hypType();
495 QString aHelpFileName = "";
496 if ( aHypType == "LocalLength" )
497 aHelpFileName = "a1d_meshing_hypo_page.html#average_length_anchor";
498 else if ( aHypType == "MaxLength" )
499 aHelpFileName = "a1d_meshing_hypo_page.html#max_length_anchor";
500 else if ( aHypType == "Arithmetic1D")
501 aHelpFileName = "a1d_meshing_hypo_page.html#arithmetic_1d_anchor";
502 else if ( aHypType == "MaxElementArea")
503 aHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
504 else if ( aHypType == "MaxElementVolume")
505 aHelpFileName = "max_element_volume_hypo_page.html";
506 else if ( aHypType == "StartEndLength")
507 aHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
508 else if ( aHypType == "Deflection1D")
509 aHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
510 else if ( aHypType == "AutomaticLength")
511 aHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
512 else if ( aHypType == "NumberOfSegments")
513 aHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
514 else if ( aHypType == "ProjectionSource1D")
515 aHelpFileName = "projection_algos_page.html";
516 else if ( aHypType == "ProjectionSource2D")
517 aHelpFileName = "projection_algos_page.html";
518 else if ( aHypType == "ProjectionSource3D")
519 aHelpFileName = "projection_algos_page.html";
520 else if ( aHypType == "NumberOfLayers")
521 aHelpFileName = "radial_prism_algo_page.html";
522 else if ( aHypType == "LayerDistribution")
523 aHelpFileName = "radial_prism_algo_page.html";
524 else if ( aHypType == "SegmentLengthAroundVertex")
525 aHelpFileName = "segments_around_vertex_algo_page.html";
527 return aHelpFileName;
533 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
534 : QtxDialog( parent, false, true ),
537 setMinimumSize( 300, height() );
538 // setFixedSize( 300, height() );
539 QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
540 topLayout->setMargin( 0 );
541 topLayout->setSpacing( 0 );
543 QFrame* titFrame = new QFrame( mainFrame() );
544 QHBoxLayout* titLay = new QHBoxLayout( titFrame );
545 titLay->setMargin( 0 );
546 titLay->setSpacing( SPACING );
548 myIconLabel = new QLabel( titFrame );
549 myIconLabel->setScaledContents( false );
550 myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
551 myTypeLabel = new QLabel( titFrame );
553 myTypeLabel->setText( creator->hypType() );
555 titLay->addWidget( myIconLabel, 0 );
556 titLay->addWidget( myTypeLabel, 0 );
557 titLay->addStretch( 1 );
559 topLayout->addWidget( titFrame, 0 );
561 myHelpFileName = creator->helpPage();
563 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
566 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
570 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
574 f->setParent( mainFrame() );
575 qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
579 void SMESHGUI_HypothesisDlg::accept()
582 if ( myCreator && !myCreator->checkParams( msg ) )
584 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
585 if ( !msg.isEmpty() )
587 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
593 void SMESHGUI_HypothesisDlg::reject()
595 if ( myCreator ) myCreator->onReject();
599 void SMESHGUI_HypothesisDlg::onHelp()
601 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
603 SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
604 app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->moduleName()) : QString(""), myHelpFileName);
609 platform = "winapplication";
611 platform = "application";
613 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
614 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
615 arg(app->resourceMgr()->stringValue("ExternalBrowser",
617 arg(myHelpFileName));
621 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
623 myIconLabel->setPixmap( p );
626 void SMESHGUI_HypothesisDlg::setType( const QString& t )
628 myTypeLabel->setText( t );
631 HypothesisData::HypothesisData( const QString& theTypeName,
632 const QString& thePluginName,
633 const QString& theServerLibName,
634 const QString& theClientLibName,
635 const QString& theLabel,
636 const QString& theIconId,
637 const QList<int>& theDim,
639 const QStringList& theNeededHypos,
640 const QStringList& theOptionalHypos,
641 const QStringList& theInputTypes,
642 const QStringList& theOutputTypes,
643 const bool theIsNeedGeometry,
644 const bool supportSub)
645 : TypeName( theTypeName ),
646 PluginName( thePluginName ),
647 ServerLibName( theServerLibName ),
648 ClientLibName( theClientLibName ),
653 NeededHypos( theNeededHypos ),
654 OptionalHypos( theOptionalHypos ),
655 InputTypes( theInputTypes ),
656 OutputTypes( theOutputTypes ),
657 IsNeedGeometry( theIsNeedGeometry ),
658 IsSupportSubmeshes( supportSub )
662 HypothesesSet::HypothesesSet( const QString& theSetName )
663 : HypoSetName( theSetName )
667 HypothesesSet::HypothesesSet( const QString& theSetName,
668 const QStringList& theHypoList,
669 const QStringList& theAlgoList )
670 : HypoSetName( theSetName ),
671 HypoList( theHypoList ),
672 AlgoList( theAlgoList )