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 <QtxIntSpinBox.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <LightApp_Application.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 QtxIntSpinBox* sb = new QtxIntSpinBox( 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 QtxDoubleSpinBox* 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 QLineEdit* le = new QLineEdit( GroupC1 );
235 le->setObjectName( (*anIt).myName );
236 attuneStdWidget( le, i );
237 le->setText( (*anIt).myValue.toString() );
238 connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
246 GroupC1Layout->addWidget( w, i, 1 );
247 changeWidgets().append( w );
254 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
256 valueChanged( (QWidget*) sender() );
259 void SMESHGUI_GenericHypothesisCreator::valueChanged( QWidget* )
263 void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int /*result*/ )
269 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
274 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
278 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
279 for( ; anIt!=aLast; anIt++ )
281 item.myName = (*anIt)->objectName();
282 if( (*anIt)->inherits( "QtxIntSpinBox" ) )
284 QtxIntSpinBox* sb = ( QtxIntSpinBox* )( *anIt );
285 item.myValue = sb->value();
286 params.append( item );
289 else if( (*anIt)->inherits( "QtxDoubleSpinBox" ) )
291 QtxDoubleSpinBox* sb = ( QtxDoubleSpinBox* )( *anIt );
292 item.myValue = sb->value();
293 params.append( item );
296 else if( (*anIt)->inherits( "QLineEdit" ) )
298 QLineEdit* line = ( QLineEdit* )( *anIt );
299 item.myValue = line->text();
300 params.append( item );
303 else if ( getParamFromCustomWidget( item, *anIt ))
305 params.append( item );
314 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
316 QString valueStr = "";
317 ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
319 for( int i=0; param!=aLast; param++, i++ )
321 if ( valueStr.length() > len0 ) {
323 len0 = valueStr.length();
325 switch( (*param).myValue.type() )
328 valueStr += valueStr.number( (*param).myValue.toInt() );
330 case QVariant::Double:
331 valueStr += valueStr.number( (*param).myValue.toDouble() );
333 case QVariant::String:
334 valueStr += (*param).myValue.toString();
337 QVariant valCopy = (*param).myValue;
338 valueStr += valCopy.toString();
344 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
349 //================================================================================
351 * \brief Return hypothesis containing initial parameters
352 * \param strictly - if true, always return myInitParamsHypo,
353 * else, return myInitParamsHypo only in creation mode and if it
356 //================================================================================
358 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis(const bool strictly) const
361 return myInitParamsHypo;
362 if ( !isCreation() || CORBA::is_nil( myInitParamsHypo ))
364 return myInitParamsHypo;
367 bool SMESHGUI_GenericHypothesisCreator::hasInitParamsHypothesis() const
369 return !CORBA::is_nil( myInitParamsHypo );
372 QString SMESHGUI_GenericHypothesisCreator::hypType() const
377 QString SMESHGUI_GenericHypothesisCreator::hypName() const
382 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
384 return myParamWidgets;
387 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
389 return myParamWidgets;
392 QtxDialog* SMESHGUI_GenericHypothesisCreator:: dlg() const
397 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
402 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
406 QString SMESHGUI_GenericHypothesisCreator::caption() const
411 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
416 QString SMESHGUI_GenericHypothesisCreator::type() const
420 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
422 const int /*index*/) const
426 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWidget* ) const
431 void SMESHGUI_GenericHypothesisCreator::onReject()
435 QString SMESHGUI_GenericHypothesisCreator::helpPage() const
437 QString aHypType = hypType();
438 QString aHelpFileName;
439 if ( aHypType == "LocalLength" )
440 aHelpFileName = "a1d_meshing_hypo_page.html#average_length_anchor";
441 else if ( aHypType == "Arithmetic1D")
442 aHelpFileName = "a1d_meshing_hypo_page.html#arithmetic_1d_anchor";
443 else if ( aHypType == "MaxElementArea")
444 aHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
445 else if ( aHypType == "MaxElementVolume")
446 aHelpFileName = "max_element_volume_hypo_page.html";
447 else if ( aHypType == "StartEndLength")
448 aHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
449 else if ( aHypType == "Deflection1D")
450 aHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
451 else if ( aHypType == "AutomaticLength")
452 aHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
453 else if ( aHypType == "NumberOfSegments")
454 aHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
455 else if ( aHypType == "ProjectionSource1D")
456 aHelpFileName = "projection_algos_page.html";
457 else if ( aHypType == "ProjectionSource2D")
458 aHelpFileName = "projection_algos_page.html";
459 else if ( aHypType == "ProjectionSource3D")
460 aHelpFileName = "projection_algos_page.html";
461 else if ( aHypType == "NumberOfLayers")
462 aHelpFileName = "radial_prism_algo_page.html";
463 else if ( aHypType == "LayerDistribution")
464 aHelpFileName = "radial_prism_algo_page.html";
465 else if ( aHypType == "SegmentLengthAroundVertex")
466 aHelpFileName = "segments_around_vertex_algo.html";
469 return aHelpFileName;
475 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
476 : QtxDialog( parent, false, true ),
479 setMinimumSize( 300, height() );
480 // setFixedSize( 300, height() );
481 QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
482 topLayout->setMargin( 0 );
483 topLayout->setSpacing( 0 );
485 QFrame* titFrame = new QFrame( mainFrame() );
486 QHBoxLayout* titLay = new QHBoxLayout( titFrame );
487 titLay->setMargin( 0 );
488 titLay->setSpacing( SPACING );
490 myIconLabel = new QLabel( titFrame );
491 myIconLabel->setScaledContents( false );
492 myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
493 myTypeLabel = new QLabel( titFrame );
495 myTypeLabel->setText( creator->hypType() );
497 titLay->addWidget( myIconLabel, 0 );
498 titLay->addWidget( myTypeLabel, 0 );
499 titLay->addStretch( 1 );
501 topLayout->addWidget( titFrame, 0 );
503 myHelpFileName = creator->helpPage();
505 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
508 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
512 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
516 f->setParent( mainFrame() );
517 qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
521 void SMESHGUI_HypothesisDlg::accept()
523 if ( myCreator && !myCreator->checkParams() )
528 void SMESHGUI_HypothesisDlg::reject()
530 if ( myCreator ) myCreator->onReject();
534 void SMESHGUI_HypothesisDlg::onHelp()
536 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
538 SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
539 app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->moduleName()) : QString(""), myHelpFileName);
544 platform = "winapplication";
546 platform = "application";
548 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
549 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
550 arg(app->resourceMgr()->stringValue("ExternalBrowser",
552 arg(myHelpFileName));
556 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
558 myIconLabel->setPixmap( p );
561 void SMESHGUI_HypothesisDlg::setType( const QString& t )
563 myTypeLabel->setText( t );
566 HypothesisData::HypothesisData( const QString& theTypeName,
567 const QString& thePluginName,
568 const QString& theServerLibName,
569 const QString& theClientLibName,
570 const QString& theLabel,
571 const QString& theIconId,
572 const QList<int>& theDim,
574 const QStringList& theNeededHypos,
575 const QStringList& theOptionalHypos,
576 const QStringList& theInputTypes,
577 const QStringList& theOutputTypes,
578 const bool theIsNeedGeometry,
579 const bool supportSub)
580 : TypeName( theTypeName ),
581 PluginName( thePluginName ),
582 ServerLibName( theServerLibName ),
583 ClientLibName( theClientLibName ),
588 NeededHypos( theNeededHypos ),
589 OptionalHypos( theOptionalHypos ),
590 InputTypes( theInputTypes ),
591 OutputTypes( theOutputTypes ),
592 IsNeedGeometry( theIsNeedGeometry ),
593 IsSupportSubmeshes( supportSub )
597 HypothesesSet::HypothesesSet( const QString& theSetName )
598 : HypoSetName( theSetName )
602 HypothesesSet::HypothesesSet( const QString& theSetName,
603 const QStringList& theHypoList,
604 const QStringList& theAlgoList )
605 : HypoSetName( theSetName ),
606 HypoList( theHypoList ),
607 AlgoList( theAlgoList )