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() );
158 myEventLoop = new QEventLoop( this );
159 myEventLoop->exec(); // make myDlg not modal
160 res = myDlg->result();
162 QString paramValues = storeParams();
163 if ( !paramValues.isEmpty() ) {
164 if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
165 SMESH::SetValue( SHyp, paramValues );
169 delete Dlg; myDlg = 0;
170 changeWidgets().clear();
171 myHypo = SMESH::SMESH_Hypothesis::_nil();
172 myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
176 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
178 if( CORBA::is_nil( hypothesis() ) )
181 ListOfStdParams params;
182 if( !stdParams( params ) || params.isEmpty() )
185 QFrame* fr = new QFrame( 0 );
186 QVBoxLayout* lay = new QVBoxLayout( fr );
188 lay->setSpacing( 0 );
190 QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
191 lay->addWidget( GroupC1 );
193 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
194 GroupC1Layout->setSpacing( SPACING );
195 GroupC1Layout->setMargin( MARGIN );
197 ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end();
198 for( int i=0; anIt!=aLast; anIt++, i++ )
200 QLabel* lab = new QLabel( (*anIt).myName, GroupC1 );
201 GroupC1Layout->addWidget( lab, i, 0 );
203 QWidget* w = getCustomWidget( *anIt, GroupC1, i );
205 switch( (*anIt).myValue.type() )
209 QtxIntSpinBox* sb = new QtxIntSpinBox( GroupC1 );
210 sb->setObjectName( (*anIt).myName );
211 attuneStdWidget( sb, i );
212 sb->setValue( (*anIt).myValue.toInt() );
213 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
217 case QVariant::Double:
219 QtxDoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
220 sb->setObjectName( (*anIt).myName );
221 attuneStdWidget( sb, i );
222 sb->setValue( (*anIt).myValue.toDouble() );
223 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
227 case QVariant::String:
229 QLineEdit* le = new QLineEdit( GroupC1 );
230 le->setObjectName( (*anIt).myName );
231 attuneStdWidget( le, i );
232 le->setText( (*anIt).myValue.toString() );
233 connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
241 GroupC1Layout->addWidget( w, i, 1 );
242 changeWidgets().append( w );
249 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
253 void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int /*result*/ )
259 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
264 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
268 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
269 for( ; anIt!=aLast; anIt++ )
271 item.myName = (*anIt)->objectName();
272 if( (*anIt)->inherits( "QtxIntSpinBox" ) )
274 QtxIntSpinBox* sb = ( QtxIntSpinBox* )( *anIt );
275 item.myValue = sb->value();
276 params.append( item );
279 else if( (*anIt)->inherits( "QtxDoubleSpinBox" ) )
281 QtxDoubleSpinBox* sb = ( QtxDoubleSpinBox* )( *anIt );
282 item.myValue = sb->value();
283 params.append( item );
286 else if( (*anIt)->inherits( "QLineEdit" ) )
288 QLineEdit* line = ( QLineEdit* )( *anIt );
289 item.myValue = line->text();
290 params.append( item );
293 else if ( getParamFromCustomWidget( item, *anIt ))
295 params.append( item );
304 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
306 QString valueStr = "";
307 ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
309 for( int i=0; param!=aLast; param++, i++ )
311 if ( valueStr.length() > len0 ) {
313 len0 = valueStr.length();
315 switch( (*param).myValue.type() )
318 valueStr += valueStr.number( (*param).myValue.toInt() );
320 case QVariant::Double:
321 valueStr += valueStr.number( (*param).myValue.toDouble() );
323 case QVariant::String:
324 valueStr += (*param).myValue.toString();
327 QVariant valCopy = (*param).myValue;
328 valueStr += valCopy.toString();
334 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
339 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis() const
341 if ( CORBA::is_nil( myInitParamsHypo ))
343 return myInitParamsHypo;
346 QString SMESHGUI_GenericHypothesisCreator::hypType() const
351 QString SMESHGUI_GenericHypothesisCreator::hypName() const
356 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
358 return myParamWidgets;
361 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
363 return myParamWidgets;
366 QtxDialog* SMESHGUI_GenericHypothesisCreator:: dlg() const
371 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
376 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
380 QString SMESHGUI_GenericHypothesisCreator::caption() const
385 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
390 QString SMESHGUI_GenericHypothesisCreator::type() const
394 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
396 const int /*index*/) const
400 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWidget* ) const
405 void SMESHGUI_GenericHypothesisCreator::onReject()
409 QString SMESHGUI_GenericHypothesisCreator::helpPage() const
411 QString aHypType = hypType();
412 QString aHelpFileName;
413 if ( aHypType == "LocalLength" )
414 aHelpFileName = "a1d_meshing_hypo_page.html#average_length_anchor";
415 else if ( aHypType == "Arithmetic1D")
416 aHelpFileName = "a1d_meshing_hypo_page.html#arithmetic_1d_anchor";
417 else if ( aHypType == "MaxElementArea")
418 aHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
419 else if ( aHypType == "MaxElementVolume")
420 aHelpFileName = "max_element_volume_hypo_page.html";
421 else if ( aHypType == "StartEndLength")
422 aHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
423 else if ( aHypType == "Deflection1D")
424 aHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
425 else if ( aHypType == "AutomaticLength")
426 aHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
427 else if ( aHypType == "NumberOfSegments")
428 aHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
429 else if ( aHypType == "ProjectionSource1D")
430 aHelpFileName = "projection_algos_page.html";
431 else if ( aHypType == "ProjectionSource2D")
432 aHelpFileName = "projection_algos_page.html";
433 else if ( aHypType == "ProjectionSource3D")
434 aHelpFileName = "projection_algos_page.html";
435 else if ( aHypType == "NumberOfLayers")
436 aHelpFileName = "radial_prism_algo_page.html";
437 else if ( aHypType == "LayerDistribution")
438 aHelpFileName = "radial_prism_algo_page.html";
439 else if ( aHypType == "SegmentLengthAroundVertex")
440 aHelpFileName = "segments_around_vertex_algo.html";
443 return aHelpFileName;
449 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
450 : QtxDialog( parent, false, true ),
453 setMinimumSize( 300, height() );
454 // setFixedSize( 300, height() );
455 QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
456 topLayout->setMargin( 0 );
457 topLayout->setSpacing( 0 );
459 QFrame* titFrame = new QFrame( mainFrame() );
460 QHBoxLayout* titLay = new QHBoxLayout( titFrame );
461 titLay->setMargin( 0 );
462 titLay->setSpacing( SPACING );
464 myIconLabel = new QLabel( titFrame );
465 myIconLabel->setScaledContents( false );
466 myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
467 myTypeLabel = new QLabel( titFrame );
469 myTypeLabel->setText( creator->hypType() );
471 titLay->addWidget( myIconLabel, 0 );
472 titLay->addWidget( myTypeLabel, 0 );
473 titLay->addStretch( 1 );
475 topLayout->addWidget( titFrame, 0 );
477 myHelpFileName = creator->helpPage();
479 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
482 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
486 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
490 f->setParent( mainFrame() );
491 qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
495 void SMESHGUI_HypothesisDlg::accept()
497 if ( myCreator && !myCreator->checkParams() )
502 void SMESHGUI_HypothesisDlg::reject()
504 if ( myCreator ) myCreator->onReject();
508 void SMESHGUI_HypothesisDlg::onHelp()
510 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
512 SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
513 app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->moduleName()) : QString(""), myHelpFileName);
518 platform = "winapplication";
520 platform = "application";
522 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
523 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
524 arg(app->resourceMgr()->stringValue("ExternalBrowser",
526 arg(myHelpFileName));
530 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
532 myIconLabel->setPixmap( p );
535 void SMESHGUI_HypothesisDlg::setType( const QString& t )
537 myTypeLabel->setText( t );
540 HypothesisData::HypothesisData( const QString& theTypeName,
541 const QString& thePluginName,
542 const QString& theServerLibName,
543 const QString& theClientLibName,
544 const QString& theLabel,
545 const QString& theIconId,
546 const QList<int>& theDim,
548 const QStringList& theNeededHypos,
549 const QStringList& theOptionalHypos,
550 const QStringList& theInputTypes,
551 const QStringList& theOutputTypes,
552 const bool theIsNeedGeometry,
553 const bool supportSub)
554 : TypeName( theTypeName ),
555 PluginName( thePluginName ),
556 ServerLibName( theServerLibName ),
557 ClientLibName( theClientLibName ),
562 NeededHypos( theNeededHypos ),
563 OptionalHypos( theOptionalHypos ),
564 InputTypes( theInputTypes ),
565 OutputTypes( theOutputTypes ),
566 IsNeedGeometry( theIsNeedGeometry ),
567 IsSupportSubmeshes( supportSub )
571 HypothesesSet::HypothesesSet( const QString& theSetName )
572 : HypoSetName( theSetName )
576 HypothesesSet::HypothesesSet( const QString& theSetName,
577 const QStringList& theHypoList,
578 const QStringList& theAlgoList )
579 : HypoSetName( theSetName ),
580 HypoList( theHypoList ),
581 AlgoList( theAlgoList )