Salome HOME
0021208: EDF 1138 SMESH: Performance issue when loading SMESH with an hdf file contai...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Hypotheses.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SMESHGUI_Hypotheses.cxx
23 //  Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
24 //  SMESH includes
25
26 #include "SMESHGUI_Hypotheses.h"
27
28 #include "SMESHGUI.h"
29 #include "SMESHGUI_HypothesesUtils.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_SpinBox.h"
32
33 // SALOME KERNEL includes
34 #include <SALOMEDSClient_Study.hxx>
35 #include <utilities.h>
36
37 // SALOME GUI includes
38 #include <SUIT_Session.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <LightApp_Application.h>
42 #include <SalomeApp_IntSpinBox.h>
43
44 // Qt includes
45 #include <QFrame>
46 #include <QLineEdit>
47 #include <QLabel>
48 #include <QGroupBox>
49 #include <QVBoxLayout>
50
51 #define SPACING 6
52 #define MARGIN  11
53
54 //To disable automatic genericobj management, the following line should be commented.
55 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
56 #define WITHGENERICOBJ
57
58 SMESHGUI_GenericHypothesisCreator::SMESHGUI_GenericHypothesisCreator( const QString& theHypType )
59   : myHypType( theHypType ), myIsCreate( false ), myDlg( 0 )
60 {
61 }
62
63 SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator()
64 {
65 }
66
67 void SMESHGUI_GenericHypothesisCreator::setInitParamsHypothesis(SMESH::SMESH_Hypothesis_ptr hyp)
68 {
69   if ( !CORBA::is_nil( hyp ) && hypType() == hyp->GetName() )
70     myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( hyp );
71 }
72
73 void SMESHGUI_GenericHypothesisCreator::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp,
74                                                 const QString& theHypName,
75                                                 QWidget* parent, QObject* obj, const QString& slot )
76 {
77   MESSAGE( "Creation of hypothesis with initial params" );
78   setInitParamsHypothesis( initParamsHyp );
79   create( false, theHypName, parent, obj, slot );
80 }
81
82 void SMESHGUI_GenericHypothesisCreator::create( bool isAlgo,
83                                                 const QString& theHypName,
84                                                 QWidget* theParent, QObject* obj, const QString& slot )
85 {
86   MESSAGE( "Creation of hypothesis" );
87
88   myIsCreate = true;
89
90   // Create hypothesis/algorithm
91   if (isAlgo) {
92     SMESH::SMESH_Hypothesis_var anAlgo =
93       SMESH::CreateHypothesis( hypType(), theHypName, isAlgo );
94 #ifdef WITHGENERICOBJ
95     if (!CORBA::is_nil(anAlgo))
96       anAlgo->UnRegister();
97 #endif
98   }
99   else {
100     SMESH::SMESH_Hypothesis_var aHypothesis =
101       SMESH::CreateHypothesis( hypType(), theHypName, false );
102     editHypothesis( aHypothesis.in(), theHypName, theParent, obj, slot );
103 #ifdef WITHGENERICOBJ
104     if (!CORBA::is_nil(aHypothesis))
105       aHypothesis->UnRegister();
106 #endif
107   }
108 }
109
110 void SMESHGUI_GenericHypothesisCreator::edit( SMESH::SMESH_Hypothesis_ptr theHypothesis,
111                                               const QString& theHypName,
112                                               QWidget* theParent, QObject* obj, const QString& slot )
113 {
114   if( CORBA::is_nil( theHypothesis ) )
115     return;
116
117   MESSAGE("Edition of hypothesis");
118
119   myIsCreate = false;
120
121   editHypothesis( theHypothesis, theHypName, theParent, obj, slot );
122 }
123
124 void SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ptr h,
125                                                         const QString& theHypName,
126                                                         QWidget* theParent,
127                                                         QObject* obj, const QString& slot )
128 {
129   myHypName = theHypName;
130   myHypo = SMESH::SMESH_Hypothesis::_duplicate( h );
131 #ifdef WITHGENERICOBJ
132   myHypo->Register();
133 #endif
134
135   SMESHGUI_HypothesisDlg* Dlg = new SMESHGUI_HypothesisDlg( this, theParent );
136   connect( Dlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
137   connect( this, SIGNAL( finished( int ) ), obj, slot.toLatin1().constData() );
138   connect( SMESHGUI::GetSMESHGUI(), SIGNAL( SignalCloseAllDialogs() ), Dlg, SLOT( reject() ));
139
140   myDlg = Dlg;
141   QFrame* fr = buildFrame();
142   if( fr )
143   {
144     Dlg->setCustomFrame( fr );
145     Dlg->setWindowTitle( caption() );
146     Dlg->setObjectName( theHypName );
147     Dlg->setHIcon( icon() );
148     Dlg->setType( type() );
149     retrieveParams();
150     Dlg->show();
151     Dlg->resize( Dlg->minimumSizeHint() );
152   }
153   else {
154     emit finished( QDialog::Accepted );
155         delete myDlg;
156   }
157 }
158
159 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
160 {
161   if( CORBA::is_nil( hypothesis() ) )
162     return 0;
163
164   ListOfStdParams params;
165   if( !stdParams( params ) || params.isEmpty() )
166     return 0;
167
168   QFrame* fr = new QFrame( 0 );
169   QVBoxLayout* lay = new QVBoxLayout( fr );
170   lay->setMargin( 5 );
171   lay->setSpacing( 0 );
172
173   QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
174   lay->addWidget( GroupC1 );
175
176   QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
177   GroupC1Layout->setSpacing( SPACING );
178   GroupC1Layout->setMargin( MARGIN );
179
180   ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end();
181   for( int i=0; anIt!=aLast; anIt++, i++ )
182   {
183     QLabel* lab = new QLabel( (*anIt).myName, GroupC1 );
184     GroupC1Layout->addWidget( lab, i, 0 );
185
186     QWidget* w = getCustomWidget( *anIt, GroupC1, i );
187     if ( !w )
188       switch( (*anIt).myValue.type() )
189       {
190       case QVariant::Int:
191         {
192           SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
193           sb->setObjectName( (*anIt).myName );
194           attuneStdWidget( sb, i );
195           sb->setValue( (*anIt).myValue.toInt() );
196           connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
197           w = sb;
198         }
199         break;
200       case QVariant::Double:
201         {
202           SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
203           sb->setObjectName( (*anIt).myName );
204           attuneStdWidget( sb, i );
205           sb->setValue( (*anIt).myValue.toDouble() );
206           connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
207           w = sb;
208         }
209         break;
210       case QVariant::String:
211         {
212           if((*anIt).isVariable) {
213             _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
214             QString aVar = (*anIt).myValue.toString();
215             if(aStudy->IsInteger(aVar.toLatin1().constData())){
216               SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
217               sb->setObjectName( (*anIt).myName );
218               attuneStdWidget( sb, i );
219               sb->setText( aVar );
220               connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
221               w = sb;
222             }
223             else if(aStudy->IsReal(aVar.toLatin1().constData())){
224               SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
225               sb->setObjectName( (*anIt).myName );
226               attuneStdWidget( sb, i );
227               sb->setText( aVar );
228               connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
229               w = sb;
230             }
231           }
232           else {
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() ) );
238             w = le;
239           }
240         }
241         break;
242       }
243
244     if( w )
245     {
246       GroupC1Layout->addWidget( w, i, 1 );
247       changeWidgets().append( w );
248     }
249   }
250
251   return fr;
252 }
253
254 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
255 {
256   valueChanged( (QWidget*) sender() );
257 }
258
259 void SMESHGUI_GenericHypothesisCreator::valueChanged( QWidget* )
260 {
261 }
262
263 void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int result )
264 {
265   bool res = result==QDialog::Accepted;
266   if( res )
267   {
268       /*QString paramValues = */storeParams();
269       // No longer needed since NoteBook appears and "Value" OB field shows names of variable
270 //       if ( !paramValues.isEmpty() ) {
271 //         if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
272 //           SMESH::SetValue( SHyp, paramValues );
273 //       }
274   }
275
276   changeWidgets().clear();
277
278   if( myIsCreate && !res )
279   {
280     //remove just created hypothesis
281     _PTR(SObject) aHypSObject = SMESH::FindSObject( myHypo );
282     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
283     if( aStudy && !aStudy->GetProperties()->IsLocked() )
284     {
285       _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
286       aBuilder->RemoveObjectWithChildren( aHypSObject );
287     }
288   }
289   else if( !myIsCreate && res )
290   {
291     SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( myHypo );
292     if( listSOmesh.size() > 0 )
293       for( int i = 0; i < listSOmesh.size(); i++ )
294       {
295         _PTR(SObject) submSO = listSOmesh[i];
296         SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
297         SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
298         if( !aSubMesh->_is_nil() )
299           aMesh = aSubMesh->GetFather();
300         _PTR(SObject) meshSO = SMESH::FindSObject( aMesh );
301         SMESH::ModifiedMesh( meshSO, false, aMesh->NbNodes()==0);
302       }
303   }
304   SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
305 #ifdef WITHGENERICOBJ
306   myHypo->UnRegister();
307 #endif
308   myHypo = SMESH::SMESH_Hypothesis::_nil();
309   myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
310
311   disconnect( myDlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
312   myDlg->close();
313   //delete myDlg; since WA_DeleteOnClose==true
314   myDlg = 0;
315   emit finished( result );
316 }
317
318 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
319 {
320   return false;
321 }
322
323 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
324 {
325   bool res = true;
326   StdParam item;
327   ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
328   for( ; anIt!=aLast; anIt++ )
329   {
330     item.myName = (*anIt)->objectName();
331     if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
332     {
333       SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
334       item.myValue = sb->value();
335       item.myText = sb->text();
336       params.append( item );
337     }
338     else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
339     {
340       SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
341       item.myValue = sb->value();
342       item.myText = sb->text();
343       params.append( item );
344     }
345     else if( (*anIt)->inherits( "QLineEdit" ) )
346     {
347       QLineEdit* line = ( QLineEdit* )( *anIt );
348       item.myValue = item.myText = line->text();
349       params.append( item );
350     }
351     else if ( getParamFromCustomWidget( item, *anIt ))
352     {
353       params.append( item );
354     }
355     else
356       res = false;
357   }
358   return res;
359 }
360
361 QString SMESHGUI_GenericHypothesisCreator::getVariableName(const char* methodName) const
362 {
363   SMESH::SMESH_Hypothesis_var h = hypothesis();
364   if ( !h->_is_nil() )
365   {
366     CORBA::String_var aVaribaleName = h->GetVarParameter( methodName );
367     return QString( aVaribaleName.in() );
368   }
369   return QString();
370 }
371
372 QStringList SMESHGUI_GenericHypothesisCreator::getVariablesFromDlg() const
373 {
374   QStringList aResult;
375   ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
376   for( ; anIt!=aLast; anIt++ ) {
377     if( (*anIt)->inherits( "QAbstractSpinBox" ) ) {
378       QAbstractSpinBox* sb = ( QAbstractSpinBox* )( *anIt );
379       aResult.append(sb->text());
380     }
381   }
382   return aResult;
383 }
384
385 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
386 {
387   QString valueStr = "";
388   ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
389   uint len0 = 0;
390   for( int i=0; param!=aLast; param++, i++ )
391   {
392     if ( valueStr.length() > len0 ) {
393       valueStr += "; ";
394       len0 = valueStr.length();
395     }
396     switch( (*param).myValue.type() )
397     {
398     case QVariant::Int:
399       valueStr += valueStr.number( (*param).myValue.toInt() );
400       break;
401     case QVariant::Double:
402       valueStr += valueStr.number( (*param).myValue.toDouble() );
403       break;
404     case QVariant::String:
405       valueStr += (*param).myValue.toString();
406       break;
407     default:
408       QVariant valCopy = (*param).myValue;
409       valueStr += valCopy.toString();
410     }
411   }
412   return valueStr;
413 }
414
415 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
416 {
417   return myHypo;
418 }
419
420 void SMESHGUI_GenericHypothesisCreator::setShapeEntry( const QString& theEntry )
421 {
422   myShapeEntry = theEntry;
423 }
424
425 //================================================================================
426 /*!
427  * \brief Return hypothesis containing initial parameters
428  *  \param strictly - if true, always return myInitParamsHypo,
429  *                    else, return myInitParamsHypo only in creation mode and if it
430  *                    is non-nil
431  */
432 //================================================================================
433
434 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis(const bool strictly) const
435 {
436   if ( strictly )
437     return myInitParamsHypo;
438   if ( !isCreation() || CORBA::is_nil( myInitParamsHypo ))
439     return myHypo;
440   return myInitParamsHypo;
441 }
442
443 bool SMESHGUI_GenericHypothesisCreator::hasInitParamsHypothesis() const
444 {
445   return !CORBA::is_nil( myInitParamsHypo );
446 }
447
448 QString SMESHGUI_GenericHypothesisCreator::hypType() const
449 {
450   return myHypType;
451 }
452
453 QString SMESHGUI_GenericHypothesisCreator::hypName() const
454 {
455   return myHypName;
456 }
457
458 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
459 {
460   return myParamWidgets;
461 }
462
463 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
464 {
465   return myParamWidgets;
466 }
467
468 QtxDialog* SMESHGUI_GenericHypothesisCreator:: dlg() const
469 {
470   return myDlg;
471 }
472
473 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
474 {
475   return myIsCreate;
476 }
477
478 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
479 {
480 }
481
482 QString SMESHGUI_GenericHypothesisCreator::caption() const
483 {
484   return QString();
485 }
486
487 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
488 {
489   return QPixmap();
490 }
491
492 QString SMESHGUI_GenericHypothesisCreator::type() const
493 {
494   return QString();
495 }
496 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
497                                                              QWidget*   /*parent*/,
498                                                              const int  /*index*/) const
499 {
500   return 0;
501 }
502 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWidget* ) const
503 {
504   return false;
505 }
506
507 bool SMESHGUI_GenericHypothesisCreator::checkParams( QString& msg ) const
508 {
509   bool ok = true;
510   ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
511   for( ; anIt!=aLast; anIt++ )
512   {
513     if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
514     {
515       SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
516       ok = sb->isValid( msg, true ) && ok;
517     }
518     else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
519     {
520       SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
521       ok = sb->isValid( msg, true ) && ok;
522     }
523   }
524   return ok;
525 }
526
527 void SMESHGUI_GenericHypothesisCreator::onReject()
528 {
529 }
530
531 QString SMESHGUI_GenericHypothesisCreator::helpPage() const
532 {
533   QString aHypType = hypType();
534   QString aHelpFileName = "";
535   if ( aHypType == "LocalLength" )
536     aHelpFileName = "a1d_meshing_hypo_page.html#average_length_anchor";
537   else if ( aHypType == "MaxLength" )
538     aHelpFileName = "a1d_meshing_hypo_page.html#max_length_anchor";
539   else if ( aHypType == "Arithmetic1D")
540     aHelpFileName = "a1d_meshing_hypo_page.html#arithmetic_1d_anchor";
541   else if ( aHypType == "FixedPoints1D")
542     aHelpFileName = "a1d_meshing_hypo_page.html#fixed_points_1d_anchor";
543   else if ( aHypType == "MaxElementArea")
544     aHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
545   else if ( aHypType == "MaxElementVolume")
546     aHelpFileName = "max_element_volume_hypo_page.html";
547   else if ( aHypType == "StartEndLength")
548     aHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
549   else if ( aHypType == "Deflection1D")
550     aHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
551   else if ( aHypType == "AutomaticLength")
552     aHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
553   else if ( aHypType == "NumberOfSegments")
554     aHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
555   else if ( aHypType == "ProjectionSource1D")
556     aHelpFileName = "projection_algos_page.html";
557   else if ( aHypType == "ProjectionSource2D")
558     aHelpFileName = "projection_algos_page.html";
559   else if ( aHypType == "ProjectionSource3D")
560     aHelpFileName = "projection_algos_page.html";
561   else if ( aHypType == "NumberOfLayers")
562     aHelpFileName = "radial_prism_algo_page.html";
563   else if ( aHypType == "NumberOfLayers2D")
564     aHelpFileName = "radial_quadrangle_1D2D_algo_page.html";
565   else if ( aHypType == "LayerDistribution")
566     aHelpFileName = "radial_prism_algo_page.html";
567   else if ( aHypType == "LayerDistribution2D")
568     aHelpFileName = "radial_quadrangle_1D2D_algo_page.html";
569   else if ( aHypType == "SegmentLengthAroundVertex")
570     aHelpFileName = "segments_around_vertex_algo_page.html";
571   else if ( aHypType == "QuadrangleParams")
572     aHelpFileName = "a2d_meshing_hypo_page.html#hypo_quad_params_anchor";
573   else if ( aHypType == "ViscousLayers")
574     aHelpFileName = "additional_hypo_page.html#viscous_layers_anchor";
575   else if ( aHypType == "ImportSource1D" || aHypType == "ImportSource2D")
576     aHelpFileName = "import_algos_page.html";
577   return aHelpFileName;
578 }
579
580 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
581 : QtxDialog( parent, false, true ),
582   myCreator( creator )
583 {
584   setAttribute(Qt::WA_DeleteOnClose, true);
585  // setMinimumSize( 300, height() );
586 //  setFixedSize( 300, height() );
587   QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
588   topLayout->setMargin( 0 );
589   topLayout->setSpacing( 0 );
590
591   QFrame* titFrame = new QFrame( mainFrame() );
592   QHBoxLayout* titLay = new QHBoxLayout( titFrame );
593   titLay->setMargin( 0 );
594   titLay->setSpacing( SPACING );
595
596   myIconLabel = new QLabel( titFrame );
597   myIconLabel->setScaledContents( false );
598   myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
599   myTypeLabel = new QLabel( titFrame );
600   if( creator )
601     myTypeLabel->setText( creator->hypType() );
602
603   titLay->addWidget( myIconLabel, 0 );
604   titLay->addWidget( myTypeLabel, 0 );
605   titLay->addStretch( 1 );
606
607   topLayout->addWidget( titFrame, 0 );
608
609   myHelpFileName = creator->helpPage();
610
611   connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
612 }
613
614 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
615 {
616   delete myCreator;
617 }
618
619 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
620 {
621   if( f )
622   {
623     f->setParent( mainFrame() );
624     qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
625   }
626 }
627
628 void SMESHGUI_HypothesisDlg::accept()
629 {
630   QString msg;
631   if ( myCreator && !myCreator->checkParams( msg ) )
632   {
633     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
634     if ( !msg.isEmpty() )
635       str += "\n" + msg;
636     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
637     return;
638   }
639   QtxDialog::accept();
640 }
641
642 void SMESHGUI_HypothesisDlg::reject()
643 {
644   if ( myCreator ) myCreator->onReject();
645   QtxDialog::reject();
646 }
647
648 void SMESHGUI_HypothesisDlg::onHelp()
649 {
650   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
651   if (app) {
652     SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
653     app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->moduleName()) : QString(""), myHelpFileName);
654   }
655   else {
656     QString platform;
657 #ifdef WIN32
658     platform = "winapplication";
659 #else
660     platform = "application";
661 #endif
662     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
663                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
664                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
665                                                                  platform)).
666                              arg(myHelpFileName));
667   }
668 }
669
670 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
671 {
672   myIconLabel->setPixmap( p );
673 }
674
675 void SMESHGUI_HypothesisDlg::setType( const QString& t )
676 {
677   myTypeLabel->setText( t );
678 }
679
680 HypothesisData::HypothesisData( const QString& theTypeName,
681                                 const QString& thePluginName,
682                                 const QString& theServerLibName,
683                                 const QString& theClientLibName,
684                                 const QString& theLabel,
685                                 const QString& theIconId,
686                                 const QList<int>& theDim,
687                                 const bool theIsAux,
688                                 const QStringList& theNeededHypos,
689                                 const QStringList& theOptionalHypos,
690                                 const QStringList& theInputTypes,
691                                 const QStringList& theOutputTypes,
692                                 const bool theIsNeedGeometry,
693                                 const bool supportSub)
694   : TypeName( theTypeName ),
695     PluginName( thePluginName ),
696     ServerLibName( theServerLibName ),
697     ClientLibName( theClientLibName ),
698     Label( theLabel ),
699     IconId( theIconId ),
700     Dim( theDim ),
701     IsAux( theIsAux ),
702     NeededHypos( theNeededHypos ),
703     OptionalHypos( theOptionalHypos ),
704     InputTypes( theInputTypes ),
705     OutputTypes( theOutputTypes ),
706     IsNeedGeometry( theIsNeedGeometry ),
707     IsSupportSubmeshes( supportSub )
708 {
709 }
710
711 HypothesesSet::HypothesesSet( const QString& theSetName )
712   : myHypoSetName( theSetName ),
713     myIsAlgo( false ),
714     myIsCustom( false )
715 {
716 }
717
718 HypothesesSet::HypothesesSet( const QString&     theSetName,
719                               const QStringList& theHypoList,
720                               const QStringList& theAlgoList )
721   : myHypoSetName( theSetName ),
722     myHypoList( theHypoList ),
723     myAlgoList( theAlgoList ),
724     myIsAlgo( false ),
725     myIsCustom( false )
726 {
727 }
728
729 QStringList* HypothesesSet::list(bool is_algo) const
730 {
731   return const_cast<QStringList*>( &( is_algo ? myAlgoList : myHypoList ) );
732 }
733
734 QStringList* HypothesesSet::list() const
735 {
736   return list( myIsAlgo );
737 }
738
739 QString HypothesesSet::name() const
740 {
741   return myHypoSetName;
742 }
743
744 void HypothesesSet::set( bool isAlgo, const QStringList& lst )
745 {
746   *list(isAlgo) = lst;
747 }
748
749 int HypothesesSet::count( bool isAlgo ) const
750 {
751   return list(isAlgo)->count();
752 }
753
754 bool HypothesesSet::isAlgo() const
755 {
756   return myIsAlgo;
757 }
758
759 void HypothesesSet::init( bool isAlgo )
760 {
761   myIsAlgo = isAlgo;
762   myIndex = -1;
763 }
764
765 bool HypothesesSet::more() const
766 {
767   return myIndex < list()->count();
768 }
769
770 void HypothesesSet::next()
771 {
772   myIndex++;
773 }
774
775 QString HypothesesSet::current() const
776 {
777   return list()->at(myIndex);
778 }
779
780 void HypothesesSet::setIsCustom( bool isCustom )
781 {
782   myIsCustom = isCustom;
783 }
784
785 bool HypothesesSet::getIsCustom() const
786 {
787   return myIsCustom;
788 }
789
790 int HypothesesSet::maxDim() const
791 {
792   HypothesesSet * thisSet = (HypothesesSet*) this;
793   int dim = -1;
794   for ( int isAlgo = 0; isAlgo < 2; ++isAlgo )
795   {
796     thisSet->init( isAlgo );
797     while ( thisSet->next(), thisSet->more() )
798       if ( HypothesisData* hypData = SMESH::GetHypothesisData( thisSet->current() ))
799         for ( int i = 0; i < hypData->Dim.count(); ++i )
800           dim = qMax( dim, hypData->Dim[i] );
801   }
802   return dim;
803 }