Salome HOME
Replace oe by ?
[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->UnRegister();
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->UnRegister();
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->UnRegister();
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 == "ViscousLayers")
561     aHelpFileName = "additional_hypo_page.html#viscous_layers_anchor";
562   else if ( aHypType == "ImportSource1D" || aHypType == "ImportSource2D")
563     aHelpFileName = "import_algos_page.html";
564   return aHelpFileName;
565 }
566
567 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
568 : QtxDialog( parent, false, true ),
569   myCreator( creator )
570 {
571   setAttribute(Qt::WA_DeleteOnClose, true);
572  // setMinimumSize( 300, height() );
573 //  setFixedSize( 300, height() );
574   QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
575   topLayout->setMargin( 0 );
576   topLayout->setSpacing( 0 );
577
578   QFrame* titFrame = new QFrame( mainFrame() );
579   QHBoxLayout* titLay = new QHBoxLayout( titFrame );
580   titLay->setMargin( 0 );
581   titLay->setSpacing( SPACING );
582
583   myIconLabel = new QLabel( titFrame );
584   myIconLabel->setScaledContents( false );
585   myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
586   myTypeLabel = new QLabel( titFrame );
587   if( creator )
588     myTypeLabel->setText( creator->hypType() );
589
590   titLay->addWidget( myIconLabel, 0 );
591   titLay->addWidget( myTypeLabel, 0 );
592   titLay->addStretch( 1 );
593
594   topLayout->addWidget( titFrame, 0 );
595
596   myHelpFileName = creator->helpPage();
597
598   connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
599 }
600
601 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
602 {
603   delete myCreator;
604 }
605
606 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
607 {
608   if( f )
609   {
610     f->setParent( mainFrame() );
611     qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
612   }
613 }
614
615 void SMESHGUI_HypothesisDlg::accept()
616 {
617   QString msg;
618   if ( myCreator && !myCreator->checkParams( msg ) )
619   {
620     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
621     if ( !msg.isEmpty() )
622       str += "\n" + msg;
623     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
624     return;
625   }
626   QtxDialog::accept();
627 }
628
629 void SMESHGUI_HypothesisDlg::reject()
630 {
631   if ( myCreator ) myCreator->onReject();
632   QtxDialog::reject();
633 }
634
635 void SMESHGUI_HypothesisDlg::onHelp()
636 {
637   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
638   if (app) {
639     SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
640     app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->moduleName()) : QString(""), myHelpFileName);
641   }
642   else {
643     QString platform;
644 #ifdef WIN32
645     platform = "winapplication";
646 #else
647     platform = "application";
648 #endif
649     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
650                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
651                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
652                                                                  platform)).
653                              arg(myHelpFileName));
654   }
655 }
656
657 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
658 {
659   myIconLabel->setPixmap( p );
660 }
661
662 void SMESHGUI_HypothesisDlg::setType( const QString& t )
663 {
664   myTypeLabel->setText( t );
665 }
666
667 HypothesisData::HypothesisData( const QString& theTypeName,
668                                 const QString& thePluginName,
669                                 const QString& theServerLibName,
670                                 const QString& theClientLibName,
671                                 const QString& theLabel,
672                                 const QString& theIconId,
673                                 const QList<int>& theDim,
674                                 const bool theIsAux,
675                                 const QStringList& theNeededHypos,
676                                 const QStringList& theOptionalHypos,
677                                 const QStringList& theInputTypes,
678                                 const QStringList& theOutputTypes,
679                                 const bool theIsNeedGeometry,
680                                 const bool supportSub)
681   : TypeName( theTypeName ),
682     PluginName( thePluginName ),
683     ServerLibName( theServerLibName ),
684     ClientLibName( theClientLibName ),
685     Label( theLabel ),
686     IconId( theIconId ),
687     Dim( theDim ),
688     IsAux( theIsAux ),
689     NeededHypos( theNeededHypos ),
690     OptionalHypos( theOptionalHypos ),
691     InputTypes( theInputTypes ),
692     OutputTypes( theOutputTypes ),
693     IsNeedGeometry( theIsNeedGeometry ),
694     IsSupportSubmeshes( supportSub )
695 {
696 }
697
698 HypothesesSet::HypothesesSet( const QString& theSetName )
699   : myHypoSetName( theSetName ),
700     myIsAlgo( false ),
701     myIsCustom( 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     myIsCustom( false )
713 {
714 }
715
716 QStringList* HypothesesSet::list(bool is_algo) const
717 {
718   return const_cast<QStringList*>( &( is_algo ? myAlgoList : myHypoList ) );
719 }
720
721 QStringList* HypothesesSet::list() const
722 {
723   return list( myIsAlgo );
724 }
725
726 QString HypothesesSet::name() const
727 {
728   return myHypoSetName;
729 }
730
731 void HypothesesSet::set( bool isAlgo, const QStringList& lst )
732 {
733   *list(isAlgo) = lst;
734 }
735
736 int HypothesesSet::count( bool isAlgo ) const
737 {
738   return list(isAlgo)->count();
739 }
740
741 bool HypothesesSet::isAlgo() const
742 {
743   return myIsAlgo;
744 }
745
746 void HypothesesSet::init( bool isAlgo )
747 {
748   myIsAlgo = isAlgo;
749   myIndex = -1;
750 }
751
752 bool HypothesesSet::more() const
753 {
754   return myIndex < list()->count();
755 }
756
757 void HypothesesSet::next()
758 {
759   myIndex++;
760 }
761
762 QString HypothesesSet::current() const
763 {
764   return list()->at(myIndex);
765 }
766
767 void HypothesesSet::setIsCustom( bool isCustom )
768 {
769   myIsCustom = isCustom;
770 }
771
772 bool HypothesesSet::getIsCustom() const
773 {
774   return myIsCustom;
775 }
776
777 int HypothesesSet::maxDim() const
778 {
779   HypothesesSet * thisSet = (HypothesesSet*) this;
780   int dim = -1;
781   for ( int isAlgo = 0; isAlgo < 2; ++isAlgo )
782   {
783     thisSet->init( isAlgo );
784     while ( thisSet->next(), thisSet->more() )
785       if ( HypothesisData* hypData = SMESH::GetHypothesisData( thisSet->current() ))
786         for ( int i = 0; i < hypData->Dim.count(); ++i )
787           dim = qMax( dim, hypData->Dim[i] );
788   }
789   return dim;
790 }