1 // Copyright (C) 2007-2010 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 //To disable automatic genericobj management, the following line should be commented.
56 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
57 #define WITHGENERICOBJ
59 SMESHGUI_GenericHypothesisCreator::SMESHGUI_GenericHypothesisCreator( const QString& theHypType )
60 : myHypType( theHypType ), myIsCreate( false ), myDlg( 0 )
64 SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator()
68 void SMESHGUI_GenericHypothesisCreator::setInitParamsHypothesis(SMESH::SMESH_Hypothesis_ptr hyp)
70 if ( !CORBA::is_nil( hyp ) && hypType() == hyp->GetName() )
71 myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( hyp );
74 void SMESHGUI_GenericHypothesisCreator::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp,
75 const QString& theHypName,
76 QWidget* parent, QObject* obj, const QString& slot )
78 MESSAGE( "Creation of hypothesis with initial params" );
79 setInitParamsHypothesis( initParamsHyp );
80 create( false, theHypName, parent, obj, slot );
83 void SMESHGUI_GenericHypothesisCreator::create( bool isAlgo,
84 const QString& theHypName,
85 QWidget* theParent, QObject* obj, const QString& slot )
87 MESSAGE( "Creation of hypothesis" );
91 // Create hypothesis/algorithm
93 SMESH::SMESH_Hypothesis_var anAlgo =
94 SMESH::CreateHypothesis( hypType(), theHypName, isAlgo );
96 if (!CORBA::is_nil(anAlgo))
101 SMESH::SMESH_Hypothesis_var aHypothesis =
102 SMESH::CreateHypothesis( hypType(), theHypName, false );
103 editHypothesis( aHypothesis.in(), theHypName, theParent, obj, slot );
104 #ifdef WITHGENERICOBJ
105 if (!CORBA::is_nil(aHypothesis))
106 aHypothesis->Destroy();
111 void SMESHGUI_GenericHypothesisCreator::edit( SMESH::SMESH_Hypothesis_ptr theHypothesis,
112 const QString& theHypName,
113 QWidget* theParent, QObject* obj, const QString& slot )
115 if( CORBA::is_nil( theHypothesis ) )
118 MESSAGE("Edition of hypothesis");
122 editHypothesis( theHypothesis, theHypName, theParent, obj, slot );
125 void SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ptr h,
126 const QString& theHypName,
128 QObject* obj, const QString& slot )
130 myHypName = theHypName;
131 myHypo = SMESH::SMESH_Hypothesis::_duplicate( h );
132 #ifdef WITHGENERICOBJ
136 SMESHGUI_HypothesisDlg* Dlg = new SMESHGUI_HypothesisDlg( this, theParent );
137 connect( Dlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
138 connect( this, SIGNAL( finished( int ) ), obj, slot.toLatin1().constData() );
139 connect( SMESHGUI::GetSMESHGUI(), SIGNAL( SignalCloseAllDialogs() ), Dlg, SLOT( reject() ));
142 QFrame* fr = buildFrame();
145 Dlg->setCustomFrame( fr );
146 Dlg->setWindowTitle( caption() );
147 Dlg->setObjectName( theHypName );
148 Dlg->setHIcon( icon() );
149 Dlg->setType( type() );
152 Dlg->resize( Dlg->minimumSizeHint() );
155 emit finished( QDialog::Accepted );
158 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
160 if( CORBA::is_nil( hypothesis() ) )
163 ListOfStdParams params;
164 if( !stdParams( params ) || params.isEmpty() )
167 QFrame* fr = new QFrame( 0 );
168 QVBoxLayout* lay = new QVBoxLayout( fr );
170 lay->setSpacing( 0 );
172 QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
173 lay->addWidget( GroupC1 );
175 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
176 GroupC1Layout->setSpacing( SPACING );
177 GroupC1Layout->setMargin( MARGIN );
179 ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end();
180 for( int i=0; anIt!=aLast; anIt++, i++ )
182 QLabel* lab = new QLabel( (*anIt).myName, GroupC1 );
183 GroupC1Layout->addWidget( lab, i, 0 );
185 QWidget* w = getCustomWidget( *anIt, GroupC1, i );
187 switch( (*anIt).myValue.type() )
191 SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
192 sb->setObjectName( (*anIt).myName );
193 attuneStdWidget( sb, i );
194 sb->setValue( (*anIt).myValue.toInt() );
195 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
199 case QVariant::Double:
201 SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
202 sb->setObjectName( (*anIt).myName );
203 attuneStdWidget( sb, i );
204 sb->setValue( (*anIt).myValue.toDouble() );
205 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
209 case QVariant::String:
211 if((*anIt).isVariable) {
212 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
213 QString aVar = (*anIt).myValue.toString();
214 if(aStudy->IsInteger(aVar.toLatin1().constData())){
215 SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
216 sb->setObjectName( (*anIt).myName );
217 attuneStdWidget( sb, i );
219 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
222 else if(aStudy->IsReal(aVar.toLatin1().constData())){
223 SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
224 sb->setObjectName( (*anIt).myName );
225 attuneStdWidget( sb, i );
227 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
232 QLineEdit* le = new QLineEdit( GroupC1 );
233 le->setObjectName( (*anIt).myName );
234 attuneStdWidget( le, i );
235 le->setText( (*anIt).myValue.toString() );
236 connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
245 GroupC1Layout->addWidget( w, i, 1 );
246 changeWidgets().append( w );
253 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
255 valueChanged( (QWidget*) sender() );
258 void SMESHGUI_GenericHypothesisCreator::valueChanged( QWidget* )
262 void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int result )
264 bool res = result==QDialog::Accepted;
267 /*QString paramValues = */storeParams();
268 // No longer needed since NoteBook appears and "Value" OB field shows names of variable
269 // if ( !paramValues.isEmpty() ) {
270 // if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
271 // SMESH::SetValue( SHyp, paramValues );
275 changeWidgets().clear();
277 if( myIsCreate && !res )
279 //remove just created hypothesis
280 _PTR(SObject) aHypSObject = SMESH::FindSObject( myHypo );
281 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
282 if( aStudy && !aStudy->GetProperties()->IsLocked() )
284 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
285 aBuilder->RemoveObjectWithChildren( aHypSObject );
288 else if( !myIsCreate && res )
290 SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( myHypo );
291 if( listSOmesh.size() > 0 )
292 for( int i = 0; i < listSOmesh.size(); i++ )
294 _PTR(SObject) submSO = listSOmesh[i];
295 SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
296 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
297 if( !aSubMesh->_is_nil() )
298 aMesh = aSubMesh->GetFather();
299 _PTR(SObject) meshSO = SMESH::FindSObject( aMesh );
300 SMESH::ModifiedMesh( meshSO, false, aMesh->NbNodes()==0);
303 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
304 #ifdef WITHGENERICOBJ
307 myHypo = SMESH::SMESH_Hypothesis::_nil();
308 myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
310 disconnect( myDlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
314 emit finished( result );
317 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
322 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
326 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
327 for( ; anIt!=aLast; anIt++ )
329 item.myName = (*anIt)->objectName();
330 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
332 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
333 item.myValue = sb->value();
334 params.append( item );
336 else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
338 SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
339 item.myValue = sb->value();
340 params.append( item );
342 else if( (*anIt)->inherits( "QLineEdit" ) )
344 QLineEdit* line = ( QLineEdit* )( *anIt );
345 item.myValue = line->text();
346 params.append( item );
348 else if ( getParamFromCustomWidget( item, *anIt ))
350 params.append( item );
359 QStringList SMESHGUI_GenericHypothesisCreator::getVariablesFromDlg() const
362 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
363 for( ; anIt!=aLast; anIt++ ) {
364 if( (*anIt)->inherits( "QAbstractSpinBox" ) ) {
365 QAbstractSpinBox* sb = ( QAbstractSpinBox* )( *anIt );
366 aResult.append(sb->text());
372 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
374 QString valueStr = "";
375 ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
377 for( int i=0; param!=aLast; param++, i++ )
379 if ( valueStr.length() > len0 ) {
381 len0 = valueStr.length();
383 switch( (*param).myValue.type() )
386 valueStr += valueStr.number( (*param).myValue.toInt() );
388 case QVariant::Double:
389 valueStr += valueStr.number( (*param).myValue.toDouble() );
391 case QVariant::String:
392 valueStr += (*param).myValue.toString();
395 QVariant valCopy = (*param).myValue;
396 valueStr += valCopy.toString();
402 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
407 void SMESHGUI_GenericHypothesisCreator::setShapeEntry( const QString& theEntry )
409 myShapeEntry = theEntry;
412 //================================================================================
414 * \brief Return hypothesis containing initial parameters
415 * \param strictly - if true, always return myInitParamsHypo,
416 * else, return myInitParamsHypo only in creation mode and if it
419 //================================================================================
421 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis(const bool strictly) const
424 return myInitParamsHypo;
425 if ( !isCreation() || CORBA::is_nil( myInitParamsHypo ))
427 return myInitParamsHypo;
430 bool SMESHGUI_GenericHypothesisCreator::hasInitParamsHypothesis() const
432 return !CORBA::is_nil( myInitParamsHypo );
435 QString SMESHGUI_GenericHypothesisCreator::hypType() const
440 QString SMESHGUI_GenericHypothesisCreator::hypName() const
445 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
447 return myParamWidgets;
450 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
452 return myParamWidgets;
455 QtxDialog* SMESHGUI_GenericHypothesisCreator:: dlg() const
460 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
465 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
469 QString SMESHGUI_GenericHypothesisCreator::caption() const
474 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
479 QString SMESHGUI_GenericHypothesisCreator::type() const
483 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
485 const int /*index*/) const
489 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWidget* ) const
494 bool SMESHGUI_GenericHypothesisCreator::checkParams( QString& msg ) const
497 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
498 for( ; anIt!=aLast; anIt++ )
500 if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
502 SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
503 ok = sb->isValid( msg, true ) && ok;
505 else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
507 SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
508 ok = sb->isValid( msg, true ) && ok;
514 void SMESHGUI_GenericHypothesisCreator::onReject()
518 QString SMESHGUI_GenericHypothesisCreator::helpPage() const
520 QString aHypType = hypType();
521 QString aHelpFileName = "";
522 if ( aHypType == "LocalLength" )
523 aHelpFileName = "a1d_meshing_hypo_page.html#average_length_anchor";
524 else if ( aHypType == "MaxLength" )
525 aHelpFileName = "a1d_meshing_hypo_page.html#max_length_anchor";
526 else if ( aHypType == "Arithmetic1D")
527 aHelpFileName = "a1d_meshing_hypo_page.html#arithmetic_1d_anchor";
528 else if ( aHypType == "FixedPoints1D")
529 aHelpFileName = "a1d_meshing_hypo_page.html#fixed_points_1d_anchor";
530 else if ( aHypType == "MaxElementArea")
531 aHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
532 else if ( aHypType == "MaxElementVolume")
533 aHelpFileName = "max_element_volume_hypo_page.html";
534 else if ( aHypType == "StartEndLength")
535 aHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
536 else if ( aHypType == "Deflection1D")
537 aHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
538 else if ( aHypType == "AutomaticLength")
539 aHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
540 else if ( aHypType == "NumberOfSegments")
541 aHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
542 else if ( aHypType == "ProjectionSource1D")
543 aHelpFileName = "projection_algos_page.html";
544 else if ( aHypType == "ProjectionSource2D")
545 aHelpFileName = "projection_algos_page.html";
546 else if ( aHypType == "ProjectionSource3D")
547 aHelpFileName = "projection_algos_page.html";
548 else if ( aHypType == "NumberOfLayers")
549 aHelpFileName = "radial_prism_algo_page.html";
550 else if ( aHypType == "NumberOfLayers2D")
551 aHelpFileName = "radial_quadrangle_1D2D_algo_page.html";
552 else if ( aHypType == "LayerDistribution")
553 aHelpFileName = "radial_prism_algo_page.html";
554 else if ( aHypType == "LayerDistribution2D")
555 aHelpFileName = "radial_quadrangle_1D2D_algo_page.html";
556 else if ( aHypType == "SegmentLengthAroundVertex")
557 aHelpFileName = "segments_around_vertex_algo_page.html";
558 else if ( aHypType == "QuadrangleParams")
559 aHelpFileName = "a2d_meshing_hypo_page.html#hypo_quad_params_anchor";
560 return aHelpFileName;
566 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
567 : QtxDialog( parent, false, true ),
570 setAttribute(Qt::WA_DeleteOnClose, true);
571 setMinimumSize( 300, height() );
572 // setFixedSize( 300, height() );
573 QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
574 topLayout->setMargin( 0 );
575 topLayout->setSpacing( 0 );
577 QFrame* titFrame = new QFrame( mainFrame() );
578 QHBoxLayout* titLay = new QHBoxLayout( titFrame );
579 titLay->setMargin( 0 );
580 titLay->setSpacing( SPACING );
582 myIconLabel = new QLabel( titFrame );
583 myIconLabel->setScaledContents( false );
584 myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
585 myTypeLabel = new QLabel( titFrame );
587 myTypeLabel->setText( creator->hypType() );
589 titLay->addWidget( myIconLabel, 0 );
590 titLay->addWidget( myTypeLabel, 0 );
591 titLay->addStretch( 1 );
593 topLayout->addWidget( titFrame, 0 );
595 myHelpFileName = creator->helpPage();
597 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
600 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
605 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
609 f->setParent( mainFrame() );
610 qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
614 void SMESHGUI_HypothesisDlg::accept()
617 if ( myCreator && !myCreator->checkParams( msg ) )
619 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
620 if ( !msg.isEmpty() )
622 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
628 void SMESHGUI_HypothesisDlg::reject()
630 if ( myCreator ) myCreator->onReject();
634 void SMESHGUI_HypothesisDlg::onHelp()
636 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
638 SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
639 app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->moduleName()) : QString(""), myHelpFileName);
644 platform = "winapplication";
646 platform = "application";
648 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
649 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
650 arg(app->resourceMgr()->stringValue("ExternalBrowser",
652 arg(myHelpFileName));
656 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
658 myIconLabel->setPixmap( p );
661 void SMESHGUI_HypothesisDlg::setType( const QString& t )
663 myTypeLabel->setText( t );
666 HypothesisData::HypothesisData( const QString& theTypeName,
667 const QString& thePluginName,
668 const QString& theServerLibName,
669 const QString& theClientLibName,
670 const QString& theLabel,
671 const QString& theIconId,
672 const QList<int>& theDim,
674 const QStringList& theNeededHypos,
675 const QStringList& theOptionalHypos,
676 const QStringList& theInputTypes,
677 const QStringList& theOutputTypes,
678 const bool theIsNeedGeometry,
679 const bool supportSub)
680 : TypeName( theTypeName ),
681 PluginName( thePluginName ),
682 ServerLibName( theServerLibName ),
683 ClientLibName( theClientLibName ),
688 NeededHypos( theNeededHypos ),
689 OptionalHypos( theOptionalHypos ),
690 InputTypes( theInputTypes ),
691 OutputTypes( theOutputTypes ),
692 IsNeedGeometry( theIsNeedGeometry ),
693 IsSupportSubmeshes( supportSub )
697 HypothesesSet::HypothesesSet( const QString& theSetName )
698 : myHypoSetName( theSetName ),
703 HypothesesSet::HypothesesSet( const QString& theSetName,
704 const QStringList& theHypoList,
705 const QStringList& theAlgoList )
706 : myHypoSetName( theSetName ),
707 myHypoList( theHypoList ),
708 myAlgoList( theAlgoList ),
713 QStringList* HypothesesSet::list(bool is_algo) const
715 return const_cast<QStringList*>( &( is_algo ? myAlgoList : myHypoList ) );
718 QStringList* HypothesesSet::list() const
720 return list( myIsAlgo );
723 QString HypothesesSet::name() const
725 return myHypoSetName;
728 void HypothesesSet::set( bool isAlgo, const QStringList& lst )
733 int HypothesesSet::count( bool isAlgo ) const
735 return list(isAlgo)->count();
738 bool HypothesesSet::isAlgo() const
743 void HypothesesSet::init( bool isAlgo )
749 bool HypothesesSet::more() const
751 return myIndex < list()->count();
754 void HypothesesSet::next()
759 QString HypothesesSet::current() const
761 return list()->at(myIndex);