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