1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 CEA
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : SMESHGUI_Hypotheses.cxx
22 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
26 #include "SMESHGUI_Hypotheses.h"
29 #include "SMESHGUI_HypothesesUtils.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_SpinBox.h"
33 // SALOME KERNEL includes
34 #include <SALOMEDSClient_Study.hxx>
35 #include <utilities.h>
37 // SALOME GUI includes
38 #include <QtxIntSpinBox.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_MessageBox.h>
41 #include <SUIT_ResourceMgr.h>
42 #include <LightApp_Application.h>
49 #include <QVBoxLayout>
55 SMESHGUI_GenericHypothesisCreator::SMESHGUI_GenericHypothesisCreator( const QString& theHypType )
56 : myHypType( theHypType ), myIsCreate( false ), myDlg( 0 ), myEventLoop( 0 )
60 SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator()
64 void SMESHGUI_GenericHypothesisCreator::setInitParamsHypothesis(SMESH::SMESH_Hypothesis_ptr hyp)
66 if ( !CORBA::is_nil( hyp ) && hypType() == hyp->GetName() )
67 myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( hyp );
70 void SMESHGUI_GenericHypothesisCreator::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp,
71 const QString& theHypName,
74 MESSAGE( "Creation of hypothesis with initial params" );
75 setInitParamsHypothesis( initParamsHyp );
76 create( false, theHypName, parent );
79 void SMESHGUI_GenericHypothesisCreator::create( bool isAlgo,
80 const QString& theHypName,
83 MESSAGE( "Creation of hypothesis" );
87 // Create hypothesis/algorithm
89 SMESH::CreateHypothesis( hypType(), theHypName, isAlgo );
92 SMESH::SMESH_Hypothesis_var aHypothesis =
93 SMESH::CreateHypothesis( hypType(), theHypName, false );
94 if( !editHypothesis( aHypothesis.in(), theHypName, theParent ) )
95 { //remove just created hypothesis
96 _PTR(SObject) aHypSObject = SMESH::FindSObject( aHypothesis.in() );
97 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
98 if( aStudy && !aStudy->GetProperties()->IsLocked() )
100 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
101 aBuilder->RemoveObjectWithChildren( aHypSObject );
105 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
108 void SMESHGUI_GenericHypothesisCreator::edit( SMESH::SMESH_Hypothesis_ptr theHypothesis,
109 const QString& theHypName,
112 if( CORBA::is_nil( theHypothesis ) )
115 MESSAGE("Edition of hypothesis");
119 if( !editHypothesis( theHypothesis, theHypName, theParent ) )
122 SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( theHypothesis );
123 if( listSOmesh.size() > 0 )
124 for( int i = 0; i < listSOmesh.size(); i++ )
126 _PTR(SObject) submSO = listSOmesh[i];
127 SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
128 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
129 if( !aSubMesh->_is_nil() )
130 aMesh = aSubMesh->GetFather();
131 _PTR(SObject) meshSO = SMESH::FindSObject( aMesh );
132 SMESH::ModifiedMesh( meshSO, false, aMesh->NbNodes()==0);
134 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
137 bool SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ptr h,
138 const QString& theHypName,
141 if( CORBA::is_nil( h ) )
145 myHypName = theHypName;
146 myHypo = SMESH::SMESH_Hypothesis::_duplicate( h );
148 SMESHGUI_HypothesisDlg* Dlg = new SMESHGUI_HypothesisDlg( this, theParent );
149 connect( Dlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
151 QFrame* fr = buildFrame();
154 Dlg->setCustomFrame( fr );
155 Dlg->setWindowTitle( caption() );
156 Dlg->setObjectName( theHypName );
157 Dlg->setHIcon( icon() );
158 Dlg->setType( type() );
162 myEventLoop = new QEventLoop( this );
163 myEventLoop->exec(); // make myDlg not modal
164 res = myDlg->result();
166 QString paramValues = storeParams();
167 if ( !paramValues.isEmpty() ) {
168 if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
169 SMESH::SetValue( SHyp, paramValues );
173 delete Dlg; myDlg = 0;
174 changeWidgets().clear();
175 myHypo = SMESH::SMESH_Hypothesis::_nil();
176 myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
180 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
182 if( CORBA::is_nil( hypothesis() ) )
185 ListOfStdParams params;
186 if( !stdParams( params ) || params.isEmpty() )
189 QFrame* fr = new QFrame( 0 );
190 QVBoxLayout* lay = new QVBoxLayout( fr );
192 lay->setSpacing( 0 );
194 QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
195 lay->addWidget( GroupC1 );
197 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
198 GroupC1Layout->setSpacing( SPACING );
199 GroupC1Layout->setMargin( MARGIN );
201 ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end();
202 for( int i=0; anIt!=aLast; anIt++, i++ )
204 QLabel* lab = new QLabel( (*anIt).myName, GroupC1 );
205 GroupC1Layout->addWidget( lab, i, 0 );
207 QWidget* w = getCustomWidget( *anIt, GroupC1, i );
209 switch( (*anIt).myValue.type() )
213 QtxIntSpinBox* sb = new QtxIntSpinBox( GroupC1 );
214 sb->setObjectName( (*anIt).myName );
215 attuneStdWidget( sb, i );
216 sb->setValue( (*anIt).myValue.toInt() );
217 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
221 case QVariant::Double:
223 QtxDoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
224 sb->setObjectName( (*anIt).myName );
225 attuneStdWidget( sb, i );
226 sb->setValue( (*anIt).myValue.toDouble() );
227 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
231 case QVariant::String:
233 QLineEdit* le = new QLineEdit( GroupC1 );
234 le->setObjectName( (*anIt).myName );
235 attuneStdWidget( le, i );
236 le->setText( (*anIt).myValue.toString() );
237 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*/ )
268 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
273 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
277 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
278 for( ; anIt!=aLast; anIt++ )
280 item.myName = (*anIt)->objectName();
281 if( (*anIt)->inherits( "QtxIntSpinBox" ) )
283 QtxIntSpinBox* sb = ( QtxIntSpinBox* )( *anIt );
284 item.myValue = sb->value();
285 params.append( item );
288 else if( (*anIt)->inherits( "QtxDoubleSpinBox" ) )
290 QtxDoubleSpinBox* sb = ( QtxDoubleSpinBox* )( *anIt );
291 item.myValue = sb->value();
292 params.append( item );
295 else if( (*anIt)->inherits( "QLineEdit" ) )
297 QLineEdit* line = ( QLineEdit* )( *anIt );
298 item.myValue = line->text();
299 params.append( item );
302 else if ( getParamFromCustomWidget( item, *anIt ))
304 params.append( item );
313 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
315 QString valueStr = "";
316 ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
318 for( int i=0; param!=aLast; param++, i++ )
320 if ( valueStr.length() > len0 ) {
322 len0 = valueStr.length();
324 switch( (*param).myValue.type() )
327 valueStr += valueStr.number( (*param).myValue.toInt() );
329 case QVariant::Double:
330 valueStr += valueStr.number( (*param).myValue.toDouble() );
332 case QVariant::String:
333 valueStr += (*param).myValue.toString();
336 QVariant valCopy = (*param).myValue;
337 valueStr += valCopy.toString();
343 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
348 //================================================================================
350 * \brief Return hypothesis containing initial parameters
351 * \param strictly - if true, always return myInitParamsHypo,
352 * else, return myInitParamsHypo only in creation mode and if it
355 //================================================================================
357 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis(const bool strictly) const
360 return myInitParamsHypo;
361 if ( !isCreation() || CORBA::is_nil( myInitParamsHypo ))
363 return myInitParamsHypo;
366 bool SMESHGUI_GenericHypothesisCreator::hasInitParamsHypothesis() const
368 return !CORBA::is_nil( myInitParamsHypo );
371 QString SMESHGUI_GenericHypothesisCreator::hypType() const
376 QString SMESHGUI_GenericHypothesisCreator::hypName() const
381 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
383 return myParamWidgets;
386 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
388 return myParamWidgets;
391 QtxDialog* SMESHGUI_GenericHypothesisCreator:: dlg() const
396 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
401 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
405 QString SMESHGUI_GenericHypothesisCreator::caption() const
410 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
415 QString SMESHGUI_GenericHypothesisCreator::type() const
419 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
421 const int /*index*/) const
425 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWidget* ) const
430 void SMESHGUI_GenericHypothesisCreator::onReject()
434 QString SMESHGUI_GenericHypothesisCreator::helpPage() const
436 QString aHypType = hypType();
437 QString aHelpFileName;
438 if ( aHypType == "LocalLength" )
439 aHelpFileName = "a1d_meshing_hypo_page.html#average_length_anchor";
440 else if ( aHypType == "Arithmetic1D")
441 aHelpFileName = "a1d_meshing_hypo_page.html#arithmetic_1d_anchor";
442 else if ( aHypType == "MaxElementArea")
443 aHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
444 else if ( aHypType == "MaxElementVolume")
445 aHelpFileName = "max_element_volume_hypo_page.html";
446 else if ( aHypType == "StartEndLength")
447 aHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
448 else if ( aHypType == "Deflection1D")
449 aHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
450 else if ( aHypType == "AutomaticLength")
451 aHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
452 else if ( aHypType == "NumberOfSegments")
453 aHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
456 return aHelpFileName;
462 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
463 : QtxDialog( parent, false, true ),
466 setMinimumSize( 300, height() );
467 // setFixedSize( 300, height() );
468 QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
469 topLayout->setMargin( 0 );
470 topLayout->setSpacing( 0 );
472 QFrame* titFrame = new QFrame( mainFrame() );
473 QHBoxLayout* titLay = new QHBoxLayout( titFrame );
474 titLay->setMargin( 0 );
475 titLay->setSpacing( SPACING );
477 myIconLabel = new QLabel( titFrame );
478 myIconLabel->setScaledContents( false );
479 myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
480 myTypeLabel = new QLabel( titFrame );
482 myTypeLabel->setText( creator->hypType() );
484 titLay->addWidget( myIconLabel, 0 );
485 titLay->addWidget( myTypeLabel, 0 );
486 titLay->addStretch( 1 );
488 topLayout->addWidget( titFrame, 0 );
490 myHelpFileName = creator->helpPage();
492 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
495 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
499 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
503 f->setParent( mainFrame() );
504 qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
508 void SMESHGUI_HypothesisDlg::accept()
510 if ( myCreator && !myCreator->checkParams() )
515 void SMESHGUI_HypothesisDlg::reject()
517 if ( myCreator ) myCreator->onReject();
521 void SMESHGUI_HypothesisDlg::onHelp()
523 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
525 SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
526 app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->moduleName()) : QString(""), myHelpFileName);
531 platform = "winapplication";
533 platform = "application";
535 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
536 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
537 arg(app->resourceMgr()->stringValue("ExternalBrowser",
539 arg(myHelpFileName));
543 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
545 myIconLabel->setPixmap( p );
548 void SMESHGUI_HypothesisDlg::setType( const QString& t )
550 myTypeLabel->setText( t );
553 HypothesisData::HypothesisData( const QString& theTypeName,
554 const QString& thePluginName,
555 const QString& theServerLibName,
556 const QString& theClientLibName,
557 const QString& theLabel,
558 const QString& theIconId,
559 const QList<int>& theDim,
561 const QStringList& theNeededHypos,
562 const QStringList& theOptionalHypos,
563 const QStringList& theInputTypes,
564 const QStringList& theOutputTypes,
565 const bool theIsNeedGeometry,
566 const bool supportSub)
567 : TypeName( theTypeName ),
568 PluginName( thePluginName ),
569 ServerLibName( theServerLibName ),
570 ClientLibName( theClientLibName ),
575 NeededHypos( theNeededHypos ),
576 OptionalHypos( theOptionalHypos ),
577 InputTypes( theInputTypes ),
578 OutputTypes( theOutputTypes ),
579 IsNeedGeometry( theIsNeedGeometry ),
580 IsSupportSubmeshes( supportSub )
584 HypothesesSet::HypothesesSet( const QString& theSetName )
585 : HypoSetName( theSetName )
589 HypothesesSet::HypothesesSet( const QString& theSetName,
590 const QStringList& theHypoList,
591 const QStringList& theAlgoList )
592 : HypoSetName( theSetName ),
593 HypoList( theHypoList ),
594 AlgoList( theAlgoList )