Back to index

salome-smesh  6.5.0
SMESHGUI_Hypotheses.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 //  File   : SMESHGUI_Hypotheses.cxx
00023 //  Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
00024 //  SMESH includes
00025 
00026 #include "SMESHGUI_Hypotheses.h"
00027 
00028 #include "SMESHGUI.h"
00029 #include "SMESHGUI_HypothesesUtils.h"
00030 #include "SMESHGUI_Utils.h"
00031 #include "SMESHGUI_SpinBox.h"
00032 
00033 // SALOME KERNEL includes
00034 #include <SALOMEDSClient_Study.hxx>
00035 #include <utilities.h>
00036 
00037 // SALOME GUI includes
00038 #include <SUIT_Session.h>
00039 #include <SUIT_MessageBox.h>
00040 #include <SUIT_ResourceMgr.h>
00041 #include <LightApp_Application.h>
00042 #include <SalomeApp_IntSpinBox.h>
00043 
00044 // Qt includes
00045 #include <QFrame>
00046 #include <QLineEdit>
00047 #include <QLabel>
00048 #include <QGroupBox>
00049 #include <QVBoxLayout>
00050 
00051 #define SPACING 6
00052 #define MARGIN  11
00053 
00054 //To disable automatic genericobj management, the following line should be commented.
00055 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
00056 #define WITHGENERICOBJ
00057 
00058 SMESHGUI_GenericHypothesisCreator::SMESHGUI_GenericHypothesisCreator( const QString& theHypType )
00059   : myHypType( theHypType ), myIsCreate( false ), myDlg( 0 )
00060 {
00061 }
00062 
00063 SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator()
00064 {
00065 }
00066 
00067 void SMESHGUI_GenericHypothesisCreator::setInitParamsHypothesis(SMESH::SMESH_Hypothesis_ptr hyp)
00068 {
00069   if ( !CORBA::is_nil( hyp ) && hypType() == hyp->GetName() )
00070     myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( hyp );
00071 }
00072 
00073 void SMESHGUI_GenericHypothesisCreator::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp,
00074                                                 const QString& theHypName,
00075                                                 QWidget* parent, QObject* obj, const QString& slot )
00076 {
00077   MESSAGE( "Creation of hypothesis with initial params" );
00078   setInitParamsHypothesis( initParamsHyp );
00079   create( false, theHypName, parent, obj, slot );
00080 }
00081 
00082 void SMESHGUI_GenericHypothesisCreator::create( bool isAlgo,
00083                                                 const QString& theHypName,
00084                                                 QWidget* theParent, QObject* obj, const QString& slot )
00085 {
00086   MESSAGE( "Creation of hypothesis" );
00087 
00088   myIsCreate = true;
00089 
00090   // Create hypothesis/algorithm
00091   if (isAlgo) {
00092     SMESH::SMESH_Hypothesis_var anAlgo =
00093       SMESH::CreateHypothesis( hypType(), theHypName, isAlgo );
00094 #ifdef WITHGENERICOBJ
00095     if (!CORBA::is_nil(anAlgo))
00096       anAlgo->UnRegister();
00097 #endif
00098   }
00099   else {
00100     SMESH::SMESH_Hypothesis_var aHypothesis =
00101       SMESH::CreateHypothesis( hypType(), theHypName, false );
00102     editHypothesis( aHypothesis.in(), theHypName, theParent, obj, slot );
00103 #ifdef WITHGENERICOBJ
00104     if (!CORBA::is_nil(aHypothesis))
00105       aHypothesis->UnRegister();
00106 #endif
00107   }
00108 }
00109 
00110 void SMESHGUI_GenericHypothesisCreator::edit( SMESH::SMESH_Hypothesis_ptr theHypothesis,
00111                                               const QString& theHypName,
00112                                               QWidget* theParent, QObject* obj, const QString& slot )
00113 {
00114   if( CORBA::is_nil( theHypothesis ) )
00115     return;
00116 
00117   MESSAGE("Edition of hypothesis");
00118 
00119   myIsCreate = false;
00120 
00121   editHypothesis( theHypothesis, theHypName, theParent, obj, slot );
00122 }
00123 
00124 void SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ptr h,
00125                                                         const QString& theHypName,
00126                                                         QWidget* theParent,
00127                                                         QObject* obj, const QString& slot )
00128 {
00129   myHypName = theHypName;
00130   myHypo = SMESH::SMESH_Hypothesis::_duplicate( h );
00131 #ifdef WITHGENERICOBJ
00132   myHypo->Register();
00133 #endif
00134 
00135   SMESHGUI_HypothesisDlg* Dlg = new SMESHGUI_HypothesisDlg( this, theParent );
00136   connect( Dlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
00137   connect( this, SIGNAL( finished( int ) ), obj, slot.toLatin1().constData() );
00138   connect( SMESHGUI::GetSMESHGUI(), SIGNAL( SignalCloseAllDialogs() ), Dlg, SLOT( reject() ));
00139 
00140   myDlg = Dlg;
00141   QFrame* fr = buildFrame();
00142   if( fr )
00143   {
00144     Dlg->setCustomFrame( fr );
00145     Dlg->setWindowTitle( caption() );
00146     Dlg->setObjectName( theHypName );
00147     Dlg->setHIcon( icon() );
00148     Dlg->setType( type() );
00149     retrieveParams();
00150     Dlg->show();
00151     Dlg->resize( Dlg->minimumSizeHint() );
00152   }
00153   else {
00154     emit finished( QDialog::Accepted );
00155         delete myDlg;
00156   }
00157 }
00158 
00159 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
00160 {
00161   if( CORBA::is_nil( hypothesis() ) )
00162     return 0;
00163 
00164   ListOfStdParams params;
00165   if( !stdParams( params ) || params.isEmpty() )
00166     return 0;
00167 
00168   QFrame* fr = new QFrame( 0 );
00169   QVBoxLayout* lay = new QVBoxLayout( fr );
00170   lay->setMargin( 5 );
00171   lay->setSpacing( 0 );
00172 
00173   QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
00174   lay->addWidget( GroupC1 );
00175 
00176   QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
00177   GroupC1Layout->setSpacing( SPACING );
00178   GroupC1Layout->setMargin( MARGIN );
00179 
00180   ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end();
00181   for( int i=0; anIt!=aLast; anIt++, i++ )
00182   {
00183     QLabel* lab = new QLabel( (*anIt).myName, GroupC1 );
00184     GroupC1Layout->addWidget( lab, i, 0 );
00185 
00186     QWidget* w = getCustomWidget( *anIt, GroupC1, i );
00187     if ( !w )
00188       switch( (*anIt).myValue.type() )
00189       {
00190       case QVariant::Int:
00191         {
00192           SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
00193           sb->setObjectName( (*anIt).myName );
00194           attuneStdWidget( sb, i );
00195           sb->setValue( (*anIt).myValue.toInt() );
00196           connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
00197           w = sb;
00198         }
00199         break;
00200       case QVariant::Double:
00201         {
00202           SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
00203           sb->setObjectName( (*anIt).myName );
00204           attuneStdWidget( sb, i );
00205           sb->setValue( (*anIt).myValue.toDouble() );
00206           connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
00207           w = sb;
00208         }
00209         break;
00210       case QVariant::String:
00211         {
00212           if((*anIt).isVariable) {
00213             _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
00214             QString aVar = (*anIt).myValue.toString();
00215             if(aStudy->IsInteger(aVar.toLatin1().constData())){
00216               SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
00217               sb->setObjectName( (*anIt).myName );
00218               attuneStdWidget( sb, i );
00219               sb->setText( aVar );
00220               connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
00221               w = sb;
00222             }
00223             else if(aStudy->IsReal(aVar.toLatin1().constData())){
00224               SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
00225               sb->setObjectName( (*anIt).myName );
00226               attuneStdWidget( sb, i );
00227               sb->setText( aVar );
00228               connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
00229               w = sb;
00230             }
00231           }
00232           else {
00233             QLineEdit* le = new QLineEdit( GroupC1 );
00234             le->setObjectName( (*anIt).myName );
00235             attuneStdWidget( le, i );
00236             le->setText( (*anIt).myValue.toString() );
00237             connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
00238             w = le;
00239           }
00240         }
00241         break;
00242       }
00243 
00244     if( w )
00245     {
00246       GroupC1Layout->addWidget( w, i, 1 );
00247       changeWidgets().append( w );
00248     }
00249   }
00250 
00251   return fr;
00252 }
00253 
00254 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
00255 {
00256   valueChanged( (QWidget*) sender() );
00257 }
00258 
00259 void SMESHGUI_GenericHypothesisCreator::valueChanged( QWidget* )
00260 {
00261 }
00262 
00263 void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int result )
00264 {
00265   bool res = result==QDialog::Accepted;
00266   if( res )
00267   {
00268       /*QString paramValues = */storeParams();
00269       // No longer needed since NoteBook appears and "Value" OB field shows names of variable
00270 //       if ( !paramValues.isEmpty() ) {
00271 //         if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
00272 //           SMESH::SetValue( SHyp, paramValues );
00273 //       }
00274   }
00275 
00276   changeWidgets().clear();
00277 
00278   if( myIsCreate && !res )
00279   {
00280     //remove just created hypothesis
00281     _PTR(SObject) aHypSObject = SMESH::FindSObject( myHypo );
00282     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
00283     if( aStudy && !aStudy->GetProperties()->IsLocked() )
00284     {
00285       _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
00286       aBuilder->RemoveObjectWithChildren( aHypSObject );
00287     }
00288   }
00289   else if( !myIsCreate && res )
00290   {
00291     SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( myHypo );
00292     if( listSOmesh.size() > 0 )
00293       for( int i = 0; i < listSOmesh.size(); i++ )
00294       {
00295         _PTR(SObject) submSO = listSOmesh[i];
00296         SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
00297         SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
00298         if( !aSubMesh->_is_nil() )
00299           aMesh = aSubMesh->GetFather();
00300         _PTR(SObject) meshSO = SMESH::FindSObject( aMesh );
00301         SMESH::ModifiedMesh( meshSO, false, aMesh->NbNodes()==0);
00302       }
00303   }
00304   SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
00305 #ifdef WITHGENERICOBJ
00306   myHypo->UnRegister();
00307 #endif
00308   myHypo = SMESH::SMESH_Hypothesis::_nil();
00309   myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
00310 
00311   disconnect( myDlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
00312   myDlg->close();
00313   //delete myDlg; since WA_DeleteOnClose==true
00314   myDlg = 0;
00315   emit finished( result );
00316 }
00317 
00318 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
00319 {
00320   return false;
00321 }
00322 
00323 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
00324 {
00325   bool res = true;
00326   StdParam item;
00327   ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
00328   for( ; anIt!=aLast; anIt++ )
00329   {
00330     item.myName = (*anIt)->objectName();
00331     if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
00332     {
00333       SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
00334       item.myValue = sb->value();
00335       item.myText = sb->text();
00336       params.append( item );
00337     }
00338     else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
00339     {
00340       SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
00341       item.myValue = sb->value();
00342       item.myText = sb->text();
00343       params.append( item );
00344     }
00345     else if( (*anIt)->inherits( "QLineEdit" ) )
00346     {
00347       QLineEdit* line = ( QLineEdit* )( *anIt );
00348       item.myValue = item.myText = line->text();
00349       params.append( item );
00350     }
00351     else if ( getParamFromCustomWidget( item, *anIt ))
00352     {
00353       params.append( item );
00354     }
00355     else
00356       res = false;
00357   }
00358   return res;
00359 }
00360 
00361 QString SMESHGUI_GenericHypothesisCreator::getVariableName(const char* methodName) const
00362 {
00363   SMESH::SMESH_Hypothesis_var h = hypothesis();
00364   if ( !h->_is_nil() )
00365   {
00366     CORBA::String_var aVaribaleName = h->GetVarParameter( methodName );
00367     return QString( aVaribaleName.in() );
00368   }
00369   return QString();
00370 }
00371 
00372 QStringList SMESHGUI_GenericHypothesisCreator::getVariablesFromDlg() const
00373 {
00374   QStringList aResult;
00375   ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
00376   for( ; anIt!=aLast; anIt++ ) {
00377     if( (*anIt)->inherits( "QAbstractSpinBox" ) ) {
00378       QAbstractSpinBox* sb = ( QAbstractSpinBox* )( *anIt );
00379       aResult.append(sb->text());
00380     }
00381   }
00382   return aResult;
00383 }
00384 
00385 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
00386 {
00387   QString valueStr = "";
00388   ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
00389   uint len0 = 0;
00390   for( int i=0; param!=aLast; param++, i++ )
00391   {
00392     if ( valueStr.length() > len0 ) {
00393       valueStr += "; ";
00394       len0 = valueStr.length();
00395     }
00396     switch( (*param).myValue.type() )
00397     {
00398     case QVariant::Int:
00399       valueStr += valueStr.number( (*param).myValue.toInt() );
00400       break;
00401     case QVariant::Double:
00402       valueStr += valueStr.number( (*param).myValue.toDouble() );
00403       break;
00404     case QVariant::String:
00405       valueStr += (*param).myValue.toString();
00406       break;
00407     default:
00408       QVariant valCopy = (*param).myValue;
00409       valueStr += valCopy.toString();
00410     }
00411   }
00412   return valueStr;
00413 }
00414 
00415 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
00416 {
00417   return myHypo;
00418 }
00419 
00420 void SMESHGUI_GenericHypothesisCreator::setShapeEntry( const QString& theEntry )
00421 {
00422   myShapeEntry = theEntry;
00423 }
00424 
00425 //================================================================================
00432 //================================================================================
00433 
00434 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis(const bool strictly) const
00435 {
00436   if ( strictly )
00437     return myInitParamsHypo;
00438   if ( !isCreation() || CORBA::is_nil( myInitParamsHypo ))
00439     return myHypo;
00440   return myInitParamsHypo;
00441 }
00442 
00443 bool SMESHGUI_GenericHypothesisCreator::hasInitParamsHypothesis() const
00444 {
00445   return !CORBA::is_nil( myInitParamsHypo );
00446 }
00447 
00448 QString SMESHGUI_GenericHypothesisCreator::hypType() const
00449 {
00450   return myHypType;
00451 }
00452 
00453 QString SMESHGUI_GenericHypothesisCreator::hypName() const
00454 {
00455   return myHypName;
00456 }
00457 
00458 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
00459 {
00460   return myParamWidgets;
00461 }
00462 
00463 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
00464 {
00465   return myParamWidgets;
00466 }
00467 
00468 QtxDialog* SMESHGUI_GenericHypothesisCreator:: dlg() const
00469 {
00470   return myDlg;
00471 }
00472 
00473 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
00474 {
00475   return myIsCreate;
00476 }
00477 
00478 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
00479 {
00480 }
00481 
00482 QString SMESHGUI_GenericHypothesisCreator::caption() const
00483 {
00484   return QString();
00485 }
00486 
00487 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
00488 {
00489   return QPixmap();
00490 }
00491 
00492 QString SMESHGUI_GenericHypothesisCreator::type() const
00493 {
00494   return QString();
00495 }
00496 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
00497                                                              QWidget*   /*parent*/,
00498                                                              const int  /*index*/) const
00499 {
00500   return 0;
00501 }
00502 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWidget* ) const
00503 {
00504   return false;
00505 }
00506 
00507 bool SMESHGUI_GenericHypothesisCreator::checkParams( QString& msg ) const
00508 {
00509   bool ok = true;
00510   ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
00511   for( ; anIt!=aLast; anIt++ )
00512   {
00513     if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
00514     {
00515       SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
00516       ok = sb->isValid( msg, true ) && ok;
00517     }
00518     else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
00519     {
00520       SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
00521       ok = sb->isValid( msg, true ) && ok;
00522     }
00523   }
00524   return ok;
00525 }
00526 
00527 void SMESHGUI_GenericHypothesisCreator::onReject()
00528 {
00529 }
00530 
00531 QString SMESHGUI_GenericHypothesisCreator::helpPage() const
00532 {
00533   QString aHypType = hypType();
00534   QString aHelpFileName = "";
00535   if ( aHypType == "LocalLength" )
00536     aHelpFileName = "a1d_meshing_hypo_page.html#average_length_anchor";
00537   else if ( aHypType == "MaxLength" )
00538     aHelpFileName = "a1d_meshing_hypo_page.html#max_length_anchor";
00539   else if ( aHypType == "Arithmetic1D")
00540     aHelpFileName = "a1d_meshing_hypo_page.html#arithmetic_1d_anchor";
00541   else if ( aHypType == "FixedPoints1D")
00542     aHelpFileName = "a1d_meshing_hypo_page.html#fixed_points_1d_anchor";
00543   else if ( aHypType == "MaxElementArea")
00544     aHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
00545   else if ( aHypType == "MaxElementVolume")
00546     aHelpFileName = "max_element_volume_hypo_page.html";
00547   else if ( aHypType == "StartEndLength")
00548     aHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
00549   else if ( aHypType == "Deflection1D")
00550     aHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
00551   else if ( aHypType == "AutomaticLength")
00552     aHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
00553   else if ( aHypType == "NumberOfSegments")
00554     aHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
00555   else if ( aHypType == "ProjectionSource1D")
00556     aHelpFileName = "projection_algos_page.html";
00557   else if ( aHypType == "ProjectionSource2D")
00558     aHelpFileName = "projection_algos_page.html";
00559   else if ( aHypType == "ProjectionSource3D")
00560     aHelpFileName = "projection_algos_page.html";
00561   else if ( aHypType == "NumberOfLayers")
00562     aHelpFileName = "radial_prism_algo_page.html";
00563   else if ( aHypType == "NumberOfLayers2D")
00564     aHelpFileName = "radial_quadrangle_1D2D_algo_page.html";
00565   else if ( aHypType == "LayerDistribution")
00566     aHelpFileName = "radial_prism_algo_page.html";
00567   else if ( aHypType == "LayerDistribution2D")
00568     aHelpFileName = "radial_quadrangle_1D2D_algo_page.html";
00569   else if ( aHypType == "SegmentLengthAroundVertex")
00570     aHelpFileName = "segments_around_vertex_algo_page.html";
00571   else if ( aHypType == "QuadrangleParams")
00572     aHelpFileName = "a2d_meshing_hypo_page.html#hypo_quad_params_anchor";
00573   else if ( aHypType == "ViscousLayers")
00574     aHelpFileName = "additional_hypo_page.html#viscous_layers_anchor";
00575   else if ( aHypType == "ImportSource1D" || aHypType == "ImportSource2D")
00576     aHelpFileName = "import_algos_page.html";
00577   return aHelpFileName;
00578 }
00579 
00580 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
00581 : QtxDialog( parent, false, true ),
00582   myCreator( creator )
00583 {
00584   setAttribute(Qt::WA_DeleteOnClose, true);
00585  // setMinimumSize( 300, height() );
00586 //  setFixedSize( 300, height() );
00587   QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
00588   topLayout->setMargin( 0 );
00589   topLayout->setSpacing( 0 );
00590 
00591   QFrame* titFrame = new QFrame( mainFrame() );
00592   QHBoxLayout* titLay = new QHBoxLayout( titFrame );
00593   titLay->setMargin( 0 );
00594   titLay->setSpacing( SPACING );
00595 
00596   myIconLabel = new QLabel( titFrame );
00597   myIconLabel->setScaledContents( false );
00598   myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
00599   myTypeLabel = new QLabel( titFrame );
00600   if( creator )
00601     myTypeLabel->setText( creator->hypType() );
00602 
00603   titLay->addWidget( myIconLabel, 0 );
00604   titLay->addWidget( myTypeLabel, 0 );
00605   titLay->addStretch( 1 );
00606 
00607   topLayout->addWidget( titFrame, 0 );
00608 
00609   myHelpFileName = creator->helpPage();
00610 
00611   connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
00612 }
00613 
00614 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
00615 {
00616   delete myCreator;
00617 }
00618 
00619 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
00620 {
00621   if( f )
00622   {
00623     f->setParent( mainFrame() );
00624     qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
00625   }
00626 }
00627 
00628 void SMESHGUI_HypothesisDlg::accept()
00629 {
00630   QString msg;
00631   if ( myCreator && !myCreator->checkParams( msg ) )
00632   {
00633     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
00634     if ( !msg.isEmpty() )
00635       str += "\n" + msg;
00636     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
00637     return;
00638   }
00639   QtxDialog::accept();
00640 }
00641 
00642 void SMESHGUI_HypothesisDlg::reject()
00643 {
00644   if ( myCreator ) myCreator->onReject();
00645   QtxDialog::reject();
00646 }
00647 
00648 void SMESHGUI_HypothesisDlg::onHelp()
00649 {
00650   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00651   if (app) {
00652     QString name = "SMESH";
00653     if(myCreator) {
00654       QVariant pluginName = myCreator->property( PLUGIN_NAME );
00655       if( pluginName.isValid() ) {
00656        QString rootDir = pluginName.toString() + "PLUGIN_ROOT_DIR";
00657        QString varValue = QString( getenv(rootDir.toLatin1().constData()));
00658        if(!varValue.isEmpty())
00659          name = pluginName.toString() + "PLUGIN";
00660       }
00661     }    
00662     app->onHelpContextModule(name, myHelpFileName);
00663   }
00664   else {
00665     QString platform;
00666 #ifdef WIN32
00667     platform = "winapplication";
00668 #else
00669     platform = "application";
00670 #endif
00671     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00672                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00673                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
00674                                                                  platform)).
00675                              arg(myHelpFileName));
00676   }
00677 }
00678 
00679 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
00680 {
00681   myIconLabel->setPixmap( p );
00682 }
00683 
00684 void SMESHGUI_HypothesisDlg::setType( const QString& t )
00685 {
00686   myTypeLabel->setText( t );
00687 }
00688 
00689 HypothesisData::HypothesisData( const QString& theTypeName,
00690                                 const QString& thePluginName,
00691                                 const QString& theServerLibName,
00692                                 const QString& theClientLibName,
00693                                 const QString& theLabel,
00694                                 const QString& theIconId,
00695                                 const QList<int>& theDim,
00696                                 const bool theIsAux,
00697                                 const QStringList& theNeededHypos,
00698                                 const QStringList& theOptionalHypos,
00699                                 const QStringList& theInputTypes,
00700                                 const QStringList& theOutputTypes,
00701                                 const bool theIsNeedGeometry,
00702                                 const bool supportSub)
00703   : TypeName( theTypeName ),
00704     PluginName( thePluginName ),
00705     ServerLibName( theServerLibName ),
00706     ClientLibName( theClientLibName ),
00707     Label( theLabel ),
00708     IconId( theIconId ),
00709     Dim( theDim ),
00710     IsAux( theIsAux ),
00711     NeededHypos( theNeededHypos ),
00712     OptionalHypos( theOptionalHypos ),
00713     InputTypes( theInputTypes ),
00714     OutputTypes( theOutputTypes ),
00715     IsNeedGeometry( theIsNeedGeometry ),
00716     IsSupportSubmeshes( supportSub )
00717 {
00718 }
00719 
00720 HypothesesSet::HypothesesSet( const QString& theSetName )
00721   : myHypoSetName( theSetName ),
00722     myIsAlgo( false ),
00723     myIsCustom( false )
00724 {
00725 }
00726 
00727 HypothesesSet::HypothesesSet( const QString&     theSetName,
00728                               const QStringList& theHypoList,
00729                               const QStringList& theAlgoList )
00730   : myHypoSetName( theSetName ),
00731     myHypoList( theHypoList ),
00732     myAlgoList( theAlgoList ),
00733     myIsAlgo( false ),
00734     myIsCustom( false )
00735 {
00736 }
00737 
00738 QStringList* HypothesesSet::list(bool is_algo) const
00739 {
00740   return const_cast<QStringList*>( &( is_algo ? myAlgoList : myHypoList ) );
00741 }
00742 
00743 QStringList* HypothesesSet::list() const
00744 {
00745   return list( myIsAlgo );
00746 }
00747 
00748 QString HypothesesSet::name() const
00749 {
00750   return myHypoSetName;
00751 }
00752 
00753 void HypothesesSet::set( bool isAlgo, const QStringList& lst )
00754 {
00755   *list(isAlgo) = lst;
00756 }
00757 
00758 int HypothesesSet::count( bool isAlgo ) const
00759 {
00760   return list(isAlgo)->count();
00761 }
00762 
00763 bool HypothesesSet::isAlgo() const
00764 {
00765   return myIsAlgo;
00766 }
00767 
00768 void HypothesesSet::init( bool isAlgo )
00769 {
00770   myIsAlgo = isAlgo;
00771   myIndex = -1;
00772 }
00773 
00774 bool HypothesesSet::more() const
00775 {
00776   return myIndex < list()->count();
00777 }
00778 
00779 void HypothesesSet::next()
00780 {
00781   myIndex++;
00782 }
00783 
00784 QString HypothesesSet::current() const
00785 {
00786   return list()->at(myIndex);
00787 }
00788 
00789 void HypothesesSet::setIsCustom( bool isCustom )
00790 {
00791   myIsCustom = isCustom;
00792 }
00793 
00794 bool HypothesesSet::getIsCustom() const
00795 {
00796   return myIsCustom;
00797 }
00798 
00799 int HypothesesSet::maxDim() const
00800 {
00801   HypothesesSet * thisSet = (HypothesesSet*) this;
00802   int dim = -1;
00803   for ( int isAlgo = 0; isAlgo < 2; ++isAlgo )
00804   {
00805     thisSet->init( isAlgo );
00806     while ( thisSet->next(), thisSet->more() )
00807       if ( HypothesisData* hypData = SMESH::GetHypothesisData( thisSet->current() ))
00808         for ( int i = 0; i < hypData->Dim.count(); ++i )
00809           dim = qMax( dim, hypData->Dim[i] );
00810   }
00811   return dim;
00812 }