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::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp,
65 const QString& theHypName,
68 MESSAGE( "Creation of hypothesis with initial params" );
70 if ( !CORBA::is_nil( initParamsHyp ) && hypType() == initParamsHyp->GetName() )
71 myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( initParamsHyp );
72 create( false, theHypName, parent );
75 void SMESHGUI_GenericHypothesisCreator::create( bool isAlgo,
76 const QString& theHypName,
79 MESSAGE( "Creation of hypothesis" );
83 // Create hypothesis/algorithm
85 SMESH::CreateHypothesis( hypType(), theHypName, isAlgo );
88 SMESH::SMESH_Hypothesis_var aHypothesis =
89 SMESH::CreateHypothesis( hypType(), theHypName, false );
90 if( !editHypothesis( aHypothesis.in(), theHypName, theParent ) )
91 { //remove just created hypothesis
92 _PTR(SObject) aHypSObject = SMESH::FindSObject( aHypothesis.in() );
93 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
94 if( aStudy && !aStudy->GetProperties()->IsLocked() )
96 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
97 aBuilder->RemoveObjectWithChildren( aHypSObject );
101 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
104 void SMESHGUI_GenericHypothesisCreator::edit( SMESH::SMESH_Hypothesis_ptr theHypothesis,
105 const QString& theHypName,
108 if( CORBA::is_nil( theHypothesis ) )
111 MESSAGE("Edition of hypothesis");
115 if( !editHypothesis( theHypothesis, theHypName, theParent ) )
118 SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( theHypothesis );
119 if( listSOmesh.size() > 0 )
120 for( int i = 0; i < listSOmesh.size(); i++ )
122 _PTR(SObject) submSO = listSOmesh[i];
123 SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
124 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
125 if( !aSubMesh->_is_nil() )
126 aMesh = aSubMesh->GetFather();
127 _PTR(SObject) meshSO = SMESH::FindSObject( aMesh );
128 SMESH::ModifiedMesh( meshSO, false, aMesh->NbNodes()==0);
130 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
133 bool SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ptr h,
134 const QString& theHypName,
137 if( CORBA::is_nil( h ) )
141 myHypName = theHypName;
142 myHypo = SMESH::SMESH_Hypothesis::_duplicate( h );
144 SMESHGUI_HypothesisDlg* Dlg = new SMESHGUI_HypothesisDlg( this, theParent );
145 connect( Dlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
147 QFrame* fr = buildFrame();
150 Dlg->setCustomFrame( fr );
151 Dlg->setWindowTitle( caption() );
152 Dlg->setObjectName( theHypName );
153 Dlg->setHIcon( icon() );
154 Dlg->setType( type() );
155 Dlg->setMinimumSize( Dlg->minimumSizeHint().width(), Dlg->minimumSizeHint().height() );
159 myEventLoop = new QEventLoop( this );
160 myEventLoop->exec(); // make myDlg not modal
161 res = myDlg->result();
163 QString paramValues = storeParams();
164 if ( !paramValues.isEmpty() ) {
165 if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
166 SMESH::SetValue( SHyp, paramValues );
170 delete Dlg; myDlg = 0;
171 changeWidgets().clear();
172 myHypo = SMESH::SMESH_Hypothesis::_nil();
173 myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
177 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
179 if( CORBA::is_nil( hypothesis() ) )
182 ListOfStdParams params;
183 if( !stdParams( params ) || params.isEmpty() )
186 QFrame* fr = new QFrame( 0 );
187 QVBoxLayout* lay = new QVBoxLayout( fr );
189 lay->setSpacing( 0 );
191 QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
192 lay->addWidget( GroupC1 );
194 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
195 GroupC1Layout->setSpacing( SPACING );
196 GroupC1Layout->setMargin( MARGIN );
198 ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end();
199 for( int i=0; anIt!=aLast; anIt++, i++ )
201 QLabel* lab = new QLabel( (*anIt).myName, GroupC1 );
202 GroupC1Layout->addWidget( lab, i, 0 );
204 QWidget* w = getCustomWidget( *anIt, GroupC1, i );
206 switch( (*anIt).myValue.type() )
210 QtxIntSpinBox* sb = new QtxIntSpinBox( GroupC1 );
211 sb->setObjectName( (*anIt).myName );
212 attuneStdWidget( sb, i );
213 sb->setValue( (*anIt).myValue.toInt() );
214 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
218 case QVariant::Double:
220 QtxDoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
221 sb->setObjectName( (*anIt).myName );
222 attuneStdWidget( sb, i );
223 sb->setValue( (*anIt).myValue.toDouble() );
224 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
228 case QVariant::String:
230 QLineEdit* le = new QLineEdit( GroupC1 );
231 le->setObjectName( (*anIt).myName );
232 attuneStdWidget( le, i );
233 le->setText( (*anIt).myValue.toString() );
234 connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
242 GroupC1Layout->addWidget( w, i, 1 );
243 changeWidgets().append( w );
250 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
254 void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int /*result*/ )
260 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
265 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
269 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
270 for( ; anIt!=aLast; anIt++ )
272 item.myName = (*anIt)->objectName();
273 if( (*anIt)->inherits( "QtxIntSpinBox" ) )
275 QtxIntSpinBox* sb = ( QtxIntSpinBox* )( *anIt );
276 item.myValue = sb->value();
277 params.append( item );
280 else if( (*anIt)->inherits( "QtxDoubleSpinBox" ) )
282 QtxDoubleSpinBox* sb = ( QtxDoubleSpinBox* )( *anIt );
283 item.myValue = sb->value();
284 params.append( item );
287 else if( (*anIt)->inherits( "QLineEdit" ) )
289 QLineEdit* line = ( QLineEdit* )( *anIt );
290 item.myValue = line->text();
291 params.append( item );
294 else if ( getParamFromCustomWidget( item, *anIt ))
296 params.append( item );
305 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
307 QString valueStr = "";
308 ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
310 for( int i=0; param!=aLast; param++, i++ )
312 if ( valueStr.length() > len0 ) {
314 len0 = valueStr.length();
316 switch( (*param).myValue.type() )
319 valueStr += valueStr.number( (*param).myValue.toInt() );
321 case QVariant::Double:
322 valueStr += valueStr.number( (*param).myValue.toDouble() );
324 case QVariant::String:
325 valueStr += (*param).myValue.toString();
328 QVariant valCopy = (*param).myValue;
329 valueStr += valCopy.toString();
335 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
340 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis() const
342 if ( CORBA::is_nil( myInitParamsHypo ))
344 return myInitParamsHypo;
347 QString SMESHGUI_GenericHypothesisCreator::hypType() const
352 QString SMESHGUI_GenericHypothesisCreator::hypName() const
357 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
359 return myParamWidgets;
362 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
364 return myParamWidgets;
367 QtxDialog* SMESHGUI_GenericHypothesisCreator:: dlg() const
372 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
377 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
381 QString SMESHGUI_GenericHypothesisCreator::caption() const
386 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
391 QString SMESHGUI_GenericHypothesisCreator::type() const
395 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
397 const int /*index*/) const
401 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWidget* ) const
406 void SMESHGUI_GenericHypothesisCreator::onReject()
413 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
414 : QtxDialog( parent, false, true ),
417 setMinimumSize( 300, height() );
418 // setFixedSize( 300, height() );
419 QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
420 topLayout->setMargin( 0 );
421 topLayout->setSpacing( 0 );
423 QFrame* titFrame = new QFrame( mainFrame() );
424 QHBoxLayout* titLay = new QHBoxLayout( titFrame );
425 titLay->setMargin( 0 );
426 titLay->setSpacing( SPACING );
428 myIconLabel = new QLabel( titFrame );
429 myIconLabel->setScaledContents( false );
430 myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
431 myTypeLabel = new QLabel( titFrame );
433 myTypeLabel->setText( creator->hypType() );
435 titLay->addWidget( myIconLabel, 0 );
436 titLay->addWidget( myTypeLabel, 0 );
437 titLay->addStretch( 1 );
439 topLayout->addWidget( titFrame, 0 );
441 QString aHypType = creator->hypType();
442 if ( aHypType == "LocalLength" )
443 myHelpFileName = "a1d_meshing_hypo_page.html#average_length_anchor";
444 else if ( aHypType == "Arithmetic1D")
445 myHelpFileName = "a1d_meshing_hypo_page.html#arithmetic_1d_anchor";
446 else if ( aHypType == "MaxElementArea")
447 myHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
448 else if ( aHypType == "MaxElementVolume")
449 myHelpFileName = "max_element_volume_hypo_page.html";
450 else if ( aHypType == "StartEndLength")
451 myHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
452 else if ( aHypType == "Deflection1D")
453 myHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
454 else if ( aHypType == "AutomaticLength")
455 myHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
456 else if ( aHypType == "NumberOfSegments")
457 myHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
461 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
464 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
468 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
472 f->setParent( mainFrame() );
473 qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
477 void SMESHGUI_HypothesisDlg::accept()
479 if ( myCreator && !myCreator->checkParams() )
484 void SMESHGUI_HypothesisDlg::reject()
486 if ( myCreator ) myCreator->onReject();
490 void SMESHGUI_HypothesisDlg::onHelp()
492 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
494 SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
495 app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->moduleName()) : QString(""), myHelpFileName);
500 platform = "winapplication";
502 platform = "application";
504 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
505 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
506 arg(app->resourceMgr()->stringValue("ExternalBrowser",
508 arg(myHelpFileName));
512 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
514 myIconLabel->setPixmap( p );
517 void SMESHGUI_HypothesisDlg::setType( const QString& t )
519 myTypeLabel->setText( t );
522 HypothesisData::HypothesisData( const QString& theTypeName,
523 const QString& thePluginName,
524 const QString& theServerLibName,
525 const QString& theClientLibName,
526 const QString& theLabel,
527 const QString& theIconId,
528 const QList<int>& theDim,
530 const QStringList& theNeededHypos,
531 const QStringList& theOptionalHypos,
532 const QStringList& theInputTypes,
533 const QStringList& theOutputTypes,
534 const bool theIsNeedGeometry )
535 : TypeName( theTypeName ),
536 PluginName( thePluginName ),
537 ServerLibName( theServerLibName ),
538 ClientLibName( theClientLibName ),
543 NeededHypos( theNeededHypos ),
544 OptionalHypos( theOptionalHypos ),
545 InputTypes( theInputTypes ),
546 OutputTypes( theOutputTypes ),
547 IsNeedGeometry( theIsNeedGeometry )
551 HypothesesSet::HypothesesSet( const QString& theSetName )
552 : HypoSetName( theSetName )
556 HypothesesSet::HypothesesSet( const QString& theSetName,
557 const QStringList& theHypoList,
558 const QStringList& theAlgoList )
559 : HypoSetName( theSetName ),
560 HypoList( theHypoList ),
561 AlgoList( theAlgoList )