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 == "FixedPointsc1D")
509 aHelpFileName = "a1d_meshing_hypo_page.html#fixed_points_1d_anchor";
510 else if ( aHypType == "MaxElementArea")
511 aHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
512 else if ( aHypType == "MaxElementVolume")
513 aHelpFileName = "max_element_volume_hypo_page.html";
514 else if ( aHypType == "StartEndLength")
515 aHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
516 else if ( aHypType == "Deflection1D")
517 aHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
518 else if ( aHypType == "AutomaticLength")
519 aHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
520 else if ( aHypType == "NumberOfSegments")
521 aHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
522 else if ( aHypType == "ProjectionSource1D")
523 aHelpFileName = "projection_algos_page.html";
524 else if ( aHypType == "ProjectionSource2D")
525 aHelpFileName = "projection_algos_page.html";
526 else if ( aHypType == "ProjectionSource3D")
527 aHelpFileName = "projection_algos_page.html";
528 else if ( aHypType == "NumberOfLayers")
529 aHelpFileName = "radial_prism_algo_page.html";
530 else if ( aHypType == "LayerDistribution")
531 aHelpFileName = "radial_prism_algo_page.html";
532 else if ( aHypType == "SegmentLengthAroundVertex")
533 aHelpFileName = "segments_around_vertex_algo_page.html";
535 return aHelpFileName;
541 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
542 : QtxDialog( parent, false, true ),
545 setMinimumSize( 300, height() );
546 // setFixedSize( 300, height() );
547 QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
548 topLayout->setMargin( 0 );
549 topLayout->setSpacing( 0 );
551 QFrame* titFrame = new QFrame( mainFrame() );
552 QHBoxLayout* titLay = new QHBoxLayout( titFrame );
553 titLay->setMargin( 0 );
554 titLay->setSpacing( SPACING );
556 myIconLabel = new QLabel( titFrame );
557 myIconLabel->setScaledContents( false );
558 myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
559 myTypeLabel = new QLabel( titFrame );
561 myTypeLabel->setText( creator->hypType() );
563 titLay->addWidget( myIconLabel, 0 );
564 titLay->addWidget( myTypeLabel, 0 );
565 titLay->addStretch( 1 );
567 topLayout->addWidget( titFrame, 0 );
569 myHelpFileName = creator->helpPage();
571 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
574 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
578 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
582 f->setParent( mainFrame() );
583 qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
587 void SMESHGUI_HypothesisDlg::accept()
590 if ( myCreator && !myCreator->checkParams( msg ) )
592 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
593 if ( !msg.isEmpty() )
595 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
601 void SMESHGUI_HypothesisDlg::reject()
603 if ( myCreator ) myCreator->onReject();
607 void SMESHGUI_HypothesisDlg::onHelp()
609 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
611 SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
612 app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->moduleName()) : QString(""), myHelpFileName);
617 platform = "winapplication";
619 platform = "application";
621 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
622 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
623 arg(app->resourceMgr()->stringValue("ExternalBrowser",
625 arg(myHelpFileName));
629 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
631 myIconLabel->setPixmap( p );
634 void SMESHGUI_HypothesisDlg::setType( const QString& t )
636 myTypeLabel->setText( t );
639 HypothesisData::HypothesisData( const QString& theTypeName,
640 const QString& thePluginName,
641 const QString& theServerLibName,
642 const QString& theClientLibName,
643 const QString& theLabel,
644 const QString& theIconId,
645 const QList<int>& theDim,
647 const QStringList& theNeededHypos,
648 const QStringList& theOptionalHypos,
649 const QStringList& theInputTypes,
650 const QStringList& theOutputTypes,
651 const bool theIsNeedGeometry,
652 const bool supportSub)
653 : TypeName( theTypeName ),
654 PluginName( thePluginName ),
655 ServerLibName( theServerLibName ),
656 ClientLibName( theClientLibName ),
661 NeededHypos( theNeededHypos ),
662 OptionalHypos( theOptionalHypos ),
663 InputTypes( theInputTypes ),
664 OutputTypes( theOutputTypes ),
665 IsNeedGeometry( theIsNeedGeometry ),
666 IsSupportSubmeshes( supportSub )
670 HypothesesSet::HypothesesSet( const QString& theSetName )
671 : HypoSetName( theSetName )
675 HypothesesSet::HypothesesSet( const QString& theSetName,
676 const QStringList& theHypoList,
677 const QStringList& theAlgoList )
678 : HypoSetName( theSetName ),
679 HypoList( theHypoList ),
680 AlgoList( theAlgoList )