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() );
162 Dlg->resize( Dlg->minimumSizeHint() );
164 myEventLoop = new QEventLoop( this );
165 myEventLoop->exec(); // make myDlg not modal
166 res = myDlg->result();
168 /*QString paramValues = */storeParams();
169 // No longer needed since NoteBook appears and "Value" OB field shows names of variable
170 // if ( !paramValues.isEmpty() ) {
171 // if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
172 // SMESH::SetValue( SHyp, paramValues );
176 delete Dlg; myDlg = 0;
177 changeWidgets().clear();
178 myHypo = SMESH::SMESH_Hypothesis::_nil();
179 myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
183 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
185 if( CORBA::is_nil( hypothesis() ) )
188 ListOfStdParams params;
189 if( !stdParams( params ) || params.isEmpty() )
192 QFrame* fr = new QFrame( 0 );
193 QVBoxLayout* lay = new QVBoxLayout( fr );
195 lay->setSpacing( 0 );
197 QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
198 lay->addWidget( GroupC1 );
200 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
201 GroupC1Layout->setSpacing( SPACING );
202 GroupC1Layout->setMargin( MARGIN );
204 ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end();
205 for( int i=0; anIt!=aLast; anIt++, i++ )
207 QLabel* lab = new QLabel( (*anIt).myName, GroupC1 );
208 GroupC1Layout->addWidget( lab, i, 0 );
210 QWidget* w = getCustomWidget( *anIt, GroupC1, i );
212 switch( (*anIt).myValue.type() )
216 SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
217 sb->setObjectName( (*anIt).myName );
218 attuneStdWidget( sb, i );
219 sb->setValue( (*anIt).myValue.toInt() );
220 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
224 case QVariant::Double:
226 SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
227 sb->setObjectName( (*anIt).myName );
228 attuneStdWidget( sb, i );
229 sb->setValue( (*anIt).myValue.toDouble() );
230 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
234 case QVariant::String:
236 if((*anIt).isVariable) {
237 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
238 QString aVar = (*anIt).myValue.toString();
239 if(aStudy->IsInteger(aVar.toLatin1().constData())){
240 SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
241 sb->setObjectName( (*anIt).myName );
242 attuneStdWidget( sb, i );
244 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
247 else if(aStudy->IsReal(aVar.toLatin1().constData())){
248 SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
249 sb->setObjectName( (*anIt).myName );
250 attuneStdWidget( sb, i );
252 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
257 QLineEdit* le = new QLineEdit( GroupC1 );
258 le->setObjectName( (*anIt).myName );
259 attuneStdWidget( le, i );
260 le->setText( (*anIt).myValue.toString() );
261 connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
270 GroupC1Layout->addWidget( w, i, 1 );
271 changeWidgets().append( w );
278 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
280 valueChanged( (QWidget*) sender() );
283 void SMESHGUI_GenericHypothesisCreator::valueChanged( QWidget* )
287 void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int /*result*/ )
293 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
298 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
302 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
303 for( ; anIt!=aLast; anIt++ )
305 item.myName = (*anIt)->objectName();
306 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
308 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
309 item.myValue = sb->value();
310 params.append( item );
313 else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
315 SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
316 item.myValue = sb->value();
317 params.append( item );
320 else if( (*anIt)->inherits( "QLineEdit" ) )
322 QLineEdit* line = ( QLineEdit* )( *anIt );
323 item.myValue = line->text();
324 params.append( item );
327 else if ( getParamFromCustomWidget( item, *anIt ))
329 params.append( item );
339 QStringList SMESHGUI_GenericHypothesisCreator::getVariablesFromDlg() const
342 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
343 for( ; anIt!=aLast; anIt++ ) {
344 if( (*anIt)->inherits( "QAbstractSpinBox" ) ) {
345 QAbstractSpinBox* sb = ( QAbstractSpinBox* )( *anIt );
346 aResult.append(sb->text());
352 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
354 QString valueStr = "";
355 ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
357 for( int i=0; param!=aLast; param++, i++ )
359 if ( valueStr.length() > len0 ) {
361 len0 = valueStr.length();
363 switch( (*param).myValue.type() )
366 valueStr += valueStr.number( (*param).myValue.toInt() );
368 case QVariant::Double:
369 valueStr += valueStr.number( (*param).myValue.toDouble() );
371 case QVariant::String:
372 valueStr += (*param).myValue.toString();
375 QVariant valCopy = (*param).myValue;
376 valueStr += valCopy.toString();
382 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
387 void SMESHGUI_GenericHypothesisCreator::setShapeEntry( const QString& theEntry )
389 myShapeEntry = theEntry;
392 //================================================================================
394 * \brief Return hypothesis containing initial parameters
395 * \param strictly - if true, always return myInitParamsHypo,
396 * else, return myInitParamsHypo only in creation mode and if it
399 //================================================================================
401 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis(const bool strictly) const
404 return myInitParamsHypo;
405 if ( !isCreation() || CORBA::is_nil( myInitParamsHypo ))
407 return myInitParamsHypo;
410 bool SMESHGUI_GenericHypothesisCreator::hasInitParamsHypothesis() const
412 return !CORBA::is_nil( myInitParamsHypo );
415 QString SMESHGUI_GenericHypothesisCreator::hypType() const
420 QString SMESHGUI_GenericHypothesisCreator::hypName() const
425 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
427 return myParamWidgets;
430 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
432 return myParamWidgets;
435 QtxDialog* SMESHGUI_GenericHypothesisCreator:: dlg() const
440 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
445 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
449 QString SMESHGUI_GenericHypothesisCreator::caption() const
454 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
459 QString SMESHGUI_GenericHypothesisCreator::type() const
463 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
465 const int /*index*/) const
469 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWidget* ) const
474 bool SMESHGUI_GenericHypothesisCreator::checkParams( QString& msg ) const
477 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
478 for( ; anIt!=aLast; anIt++ )
480 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
482 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
483 ok = sb->isValid( msg, true ) && ok;
485 else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
487 SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
488 ok = sb->isValid( msg, true ) && ok;
494 void SMESHGUI_GenericHypothesisCreator::onReject()
498 QString SMESHGUI_GenericHypothesisCreator::helpPage() const
500 QString aHypType = hypType();
501 QString aHelpFileName = "";
502 if ( aHypType == "LocalLength" )
503 aHelpFileName = "a1d_meshing_hypo_page.html#average_length_anchor";
504 else if ( aHypType == "MaxLength" )
505 aHelpFileName = "a1d_meshing_hypo_page.html#max_length_anchor";
506 else if ( aHypType == "Arithmetic1D")
507 aHelpFileName = "a1d_meshing_hypo_page.html#arithmetic_1d_anchor";
508 else if ( aHypType == "MaxElementArea")
509 aHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
510 else if ( aHypType == "MaxElementVolume")
511 aHelpFileName = "max_element_volume_hypo_page.html";
512 else if ( aHypType == "StartEndLength")
513 aHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
514 else if ( aHypType == "Deflection1D")
515 aHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
516 else if ( aHypType == "AutomaticLength")
517 aHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
518 else if ( aHypType == "NumberOfSegments")
519 aHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
520 else if ( aHypType == "ProjectionSource1D")
521 aHelpFileName = "projection_algos_page.html";
522 else if ( aHypType == "ProjectionSource2D")
523 aHelpFileName = "projection_algos_page.html";
524 else if ( aHypType == "ProjectionSource3D")
525 aHelpFileName = "projection_algos_page.html";
526 else if ( aHypType == "NumberOfLayers")
527 aHelpFileName = "radial_prism_algo_page.html";
528 else if ( aHypType == "LayerDistribution")
529 aHelpFileName = "radial_prism_algo_page.html";
530 else if ( aHypType == "SegmentLengthAroundVertex")
531 aHelpFileName = "segments_around_vertex_algo_page.html";
533 return aHelpFileName;
539 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
540 : QtxDialog( parent, false, true ),
543 setMinimumSize( 300, height() );
544 // setFixedSize( 300, height() );
545 QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
546 topLayout->setMargin( 0 );
547 topLayout->setSpacing( 0 );
549 QFrame* titFrame = new QFrame( mainFrame() );
550 QHBoxLayout* titLay = new QHBoxLayout( titFrame );
551 titLay->setMargin( 0 );
552 titLay->setSpacing( SPACING );
554 myIconLabel = new QLabel( titFrame );
555 myIconLabel->setScaledContents( false );
556 myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
557 myTypeLabel = new QLabel( titFrame );
559 myTypeLabel->setText( creator->hypType() );
561 titLay->addWidget( myIconLabel, 0 );
562 titLay->addWidget( myTypeLabel, 0 );
563 titLay->addStretch( 1 );
565 topLayout->addWidget( titFrame, 0 );
567 myHelpFileName = creator->helpPage();
569 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
572 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
576 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
580 f->setParent( mainFrame() );
581 qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
585 void SMESHGUI_HypothesisDlg::accept()
588 if ( myCreator && !myCreator->checkParams( msg ) )
590 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
591 if ( !msg.isEmpty() )
593 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
599 void SMESHGUI_HypothesisDlg::reject()
601 if ( myCreator ) myCreator->onReject();
605 void SMESHGUI_HypothesisDlg::onHelp()
607 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
609 SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
610 app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->moduleName()) : QString(""), myHelpFileName);
615 platform = "winapplication";
617 platform = "application";
619 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
620 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
621 arg(app->resourceMgr()->stringValue("ExternalBrowser",
623 arg(myHelpFileName));
627 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
629 myIconLabel->setPixmap( p );
632 void SMESHGUI_HypothesisDlg::setType( const QString& t )
634 myTypeLabel->setText( t );
637 HypothesisData::HypothesisData( const QString& theTypeName,
638 const QString& thePluginName,
639 const QString& theServerLibName,
640 const QString& theClientLibName,
641 const QString& theLabel,
642 const QString& theIconId,
643 const QList<int>& theDim,
645 const QStringList& theNeededHypos,
646 const QStringList& theOptionalHypos,
647 const QStringList& theInputTypes,
648 const QStringList& theOutputTypes,
649 const bool theIsNeedGeometry,
650 const bool supportSub)
651 : TypeName( theTypeName ),
652 PluginName( thePluginName ),
653 ServerLibName( theServerLibName ),
654 ClientLibName( theClientLibName ),
659 NeededHypos( theNeededHypos ),
660 OptionalHypos( theOptionalHypos ),
661 InputTypes( theInputTypes ),
662 OutputTypes( theOutputTypes ),
663 IsNeedGeometry( theIsNeedGeometry ),
664 IsSupportSubmeshes( supportSub )
668 HypothesesSet::HypothesesSet( const QString& theSetName )
669 : HypoSetName( theSetName )
673 HypothesesSet::HypothesesSet( const QString& theSetName,
674 const QStringList& theHypoList,
675 const QStringList& theAlgoList )
676 : HypoSetName( theSetName ),
677 HypoList( theHypoList ),
678 AlgoList( theAlgoList )