Salome HOME
IMP: SMESH: Japanese translations
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Hypotheses.cxx
1 // Copyright (C) 2007-2013  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 SMESHGUI_GenericHypothesisCreator::SMESHGUI_GenericHypothesisCreator( const QString& theHypType )
55   : myToDeleteInitParamsHypo( false ),
56     myHypType( theHypType ),
57     myIsCreate( false ),
58     myDlg( 0 )
59 {
60 }
61
62 SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator()
63 {
64   if ( myToDeleteInitParamsHypo && !myInitParamsHypo->_is_nil() )
65     myInitParamsHypo->UnRegister();
66 }
67
68 void SMESHGUI_GenericHypothesisCreator::setInitParamsHypothesis(SMESH::SMESH_Hypothesis_ptr hyp)
69 {
70   if ( !CORBA::is_nil( hyp ) ) {
71     if ( myToDeleteInitParamsHypo && !myInitParamsHypo->_is_nil() )
72       myInitParamsHypo->UnRegister();
73     CORBA::String_var hypName = hyp->GetName();
74     if ( hypType() == hypName.in() )
75     {
76       myInitParamsHypo         = SMESH::SMESH_Hypothesis::_duplicate( hyp );
77       myToDeleteInitParamsHypo = !SMESH::FindSObject( myInitParamsHypo );
78     }
79   }
80 }
81
82 void SMESHGUI_GenericHypothesisCreator::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp,
83                                                 const QString& theHypName,
84                                                 QWidget* parent, QObject* obj, const QString& slot )
85 {
86   MESSAGE( "Creation of hypothesis with initial params" );
87   setInitParamsHypothesis( initParamsHyp );
88   create( false, theHypName, parent, obj, slot );
89 }
90
91 void SMESHGUI_GenericHypothesisCreator::create( bool           isAlgo,
92                                                 const QString& theHypName,
93                                                 QWidget* theParent, QObject* obj, const QString& slot )
94 {
95   MESSAGE( "Creation of hypothesis" );
96
97   myIsCreate = true;
98
99   // Create hypothesis/algorithm
100   if (isAlgo) {
101     SMESH::SMESH_Hypothesis_var anAlgo =
102       SMESH::CreateHypothesis( hypType(), theHypName, isAlgo );
103     anAlgo.out(); // avoid unused variable warning
104   }
105   else {
106     SMESH::SMESH_Hypothesis_var aHypothesis =
107       SMESH::CreateHypothesis( hypType(), theHypName, false );
108     editHypothesis( aHypothesis.in(), theHypName, theParent, obj, slot );
109   }
110 }
111
112 void SMESHGUI_GenericHypothesisCreator::edit( SMESH::SMESH_Hypothesis_ptr theHypothesis,
113                                               const QString&              theHypName,
114                                               QWidget* theParent, QObject* obj, const QString& slot )
115 {
116   if( CORBA::is_nil( theHypothesis ) )
117     return;
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   myHypo->Register();
132
133   SMESHGUI_HypothesisDlg* Dlg = new SMESHGUI_HypothesisDlg( this, theParent );
134   connect( Dlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
135   connect( this, SIGNAL( finished( int ) ), obj, slot.toLatin1().constData() );
136   connect( SMESHGUI::GetSMESHGUI(), SIGNAL( SignalCloseAllDialogs() ), Dlg, SLOT( reject() ));
137
138   myDlg = Dlg;
139   QFrame* fr = buildFrame();
140   if( fr )
141   {
142     Dlg->setCustomFrame( fr );
143     Dlg->setWindowTitle( caption() );
144     Dlg->setObjectName( theHypName );
145     Dlg->setHIcon( icon() );
146     Dlg->setType( type() );
147     retrieveParams();
148     Dlg->show();
149     Dlg->resize( Dlg->minimumSizeHint() );
150   }
151   else {
152     emit finished( QDialog::Accepted );
153         delete myDlg;
154   }
155 }
156
157 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
158 {
159   if( CORBA::is_nil( hypothesis() ) )
160     return 0;
161
162   ListOfStdParams params;
163   if( !stdParams( params ) || params.isEmpty() )
164     return 0;
165
166   QFrame* fr = new QFrame( 0 );
167   QVBoxLayout* lay = new QVBoxLayout( fr );
168   lay->setMargin( 5 );
169   lay->setSpacing( 0 );
170
171   QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
172   lay->addWidget( GroupC1 );
173
174   QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
175   GroupC1Layout->setSpacing( SPACING );
176   GroupC1Layout->setMargin( MARGIN );
177
178   ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end();
179   for( int i=0; anIt!=aLast; anIt++, i++ )
180   {
181     QLabel* lab = new QLabel( (*anIt).myName, GroupC1 );
182     GroupC1Layout->addWidget( lab, i, 0 );
183     myParamLabels << lab;
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   myHypo->UnRegister();
305   myHypo = SMESH::SMESH_Hypothesis::_nil();
306   myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
307
308   disconnect( myDlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
309   myDlg->close();
310   //delete myDlg; since WA_DeleteOnClose==true
311   myDlg = 0;
312   emit finished( result );
313 }
314
315 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
316 {
317   return false;
318 }
319
320 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
321 {
322   bool res = true;
323   StdParam item;
324   ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
325   for( ; anIt!=aLast; anIt++ )
326   {
327     item.myName = (*anIt)->objectName();
328     if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
329     {
330       SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
331       item.myValue = sb->value();
332       item.myText = sb->text();
333       params.append( item );
334     }
335     else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
336     {
337       SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
338       item.myValue = sb->value();
339       item.myText = sb->text();
340       params.append( item );
341     }
342     else if( (*anIt)->inherits( "QLineEdit" ) )
343     {
344       QLineEdit* line = ( QLineEdit* )( *anIt );
345       item.myValue = item.myText = 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 QString SMESHGUI_GenericHypothesisCreator::getVariableName(const char* methodName) const
359 {
360   SMESH::SMESH_Hypothesis_var h = hypothesis();
361   if ( !h->_is_nil() )
362   {
363     CORBA::String_var aVaribaleName = h->GetVarParameter( methodName );
364     return QString( aVaribaleName.in() );
365   }
366   return QString();
367 }
368
369 QStringList SMESHGUI_GenericHypothesisCreator::getVariablesFromDlg() const
370 {
371   QStringList aResult;
372   ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
373   for( ; anIt!=aLast; anIt++ ) {
374     if( (*anIt)->inherits( "QAbstractSpinBox" ) ) {
375       QAbstractSpinBox* sb = ( QAbstractSpinBox* )( *anIt );
376       aResult.append(sb->text());
377     }
378   }
379   return aResult;
380 }
381
382 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
383 {
384   QString valueStr = "";
385   ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
386   uint len0 = 0;
387   for( int i=0; param!=aLast; param++, i++ )
388   {
389     if ( valueStr.length() > len0 ) {
390       valueStr += "; ";
391       len0 = valueStr.length();
392     }
393     switch( (*param).myValue.type() )
394     {
395     case QVariant::Int:
396       valueStr += valueStr.number( (*param).myValue.toInt() );
397       break;
398     case QVariant::Double:
399       valueStr += valueStr.number( (*param).myValue.toDouble() );
400       break;
401     case QVariant::String:
402       valueStr += (*param).myValue.toString();
403       break;
404     default:
405       QVariant valCopy = (*param).myValue;
406       valueStr += valCopy.toString();
407     }
408   }
409   return valueStr;
410 }
411
412 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
413 {
414   return myHypo;
415 }
416
417 void SMESHGUI_GenericHypothesisCreator::setShapeEntry( const QString& theEntry )
418 {
419   myShapeEntry = theEntry;
420 }
421
422 //================================================================================
423 /*!
424  * \brief Return hypothesis containing initial parameters
425  *  \param strictly - if true, always return myInitParamsHypo,
426  *                    else, return myInitParamsHypo only in creation mode and if it
427  *                    is non-nil
428  */
429 //================================================================================
430
431 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis(const bool strictly) const
432 {
433   if ( strictly )
434     return myInitParamsHypo;
435   if ( !isCreation() || CORBA::is_nil( myInitParamsHypo ))
436     return myHypo;
437   return myInitParamsHypo;
438 }
439
440 bool SMESHGUI_GenericHypothesisCreator::hasInitParamsHypothesis() const
441 {
442   return !CORBA::is_nil( myInitParamsHypo );
443 }
444
445 QString SMESHGUI_GenericHypothesisCreator::hypType() const
446 {
447   return myHypType;
448 }
449
450 QString SMESHGUI_GenericHypothesisCreator::hypName() const
451 {
452   return myHypName;
453 }
454
455 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
456 {
457   return myParamWidgets;
458 }
459
460 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
461 {
462   return myParamWidgets;
463 }
464
465 //================================================================================
466 /*!
467  * \brief Returns a QLabel of a spesified parameter.
468  * If isCreation(), the 1st label (supposed to be "Name") is not countered.
469  */
470 //================================================================================
471
472 QLabel* SMESHGUI_GenericHypothesisCreator::getLabel(int i) const
473 {
474   if ( isCreation() )
475     i++;
476   if ( i < myParamLabels.size() )
477     return (QLabel*) myParamLabels.at(i);
478   return NULL;
479 }
480
481 QtxDialog* SMESHGUI_GenericHypothesisCreator:: dlg() const
482 {
483   return myDlg;
484 }
485
486 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
487 {
488   return myIsCreate;
489 }
490
491 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
492 {
493 }
494
495 QString SMESHGUI_GenericHypothesisCreator::caption() const
496 {
497   return QString();
498 }
499
500 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
501 {
502   return QPixmap();
503 }
504
505 QString SMESHGUI_GenericHypothesisCreator::type() const
506 {
507   return QString();
508 }
509 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
510                                                              QWidget*   /*parent*/,
511                                                              const int  /*index*/) const
512 {
513   return 0;
514 }
515 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWidget* ) const
516 {
517   return false;
518 }
519
520 bool SMESHGUI_GenericHypothesisCreator::checkParams( QString& msg ) const
521 {
522   bool ok = true;
523   ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
524   for( ; anIt!=aLast; anIt++ )
525   {
526     if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
527     {
528       SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
529       ok = sb->isValid( msg, true ) && ok;
530     }
531     else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
532     {
533       SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
534       ok = sb->isValid( msg, true ) && ok;
535     }
536   }
537   return ok;
538 }
539
540 void SMESHGUI_GenericHypothesisCreator::onReject()
541 {
542 }
543
544 QString SMESHGUI_GenericHypothesisCreator::helpPage() const
545 {
546   QString aHypType = hypType();
547   QString aHelpFileName = "";
548   if ( aHypType == "LocalLength" )
549     aHelpFileName = "a1d_meshing_hypo_page.html#average_length_anchor";
550   else if ( aHypType == "MaxLength" )
551     aHelpFileName = "a1d_meshing_hypo_page.html#max_length_anchor";
552   else if ( aHypType == "Arithmetic1D")
553     aHelpFileName = "a1d_meshing_hypo_page.html#arithmetic_1d_anchor";
554   else if ( aHypType == "FixedPoints1D")
555     aHelpFileName = "a1d_meshing_hypo_page.html#fixed_points_1d_anchor";
556   else if ( aHypType == "MaxElementArea")
557     aHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
558   else if ( aHypType == "MaxElementVolume")
559     aHelpFileName = "max_element_volume_hypo_page.html";
560   else if ( aHypType == "StartEndLength")
561     aHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
562   else if ( aHypType == "Deflection1D")
563     aHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
564   else if ( aHypType == "AutomaticLength")
565     aHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
566   else if ( aHypType == "NumberOfSegments")
567     aHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
568   else if ( aHypType == "ProjectionSource1D")
569     aHelpFileName = "projection_algos_page.html";
570   else if ( aHypType == "ProjectionSource2D")
571     aHelpFileName = "projection_algos_page.html";
572   else if ( aHypType == "ProjectionSource3D")
573     aHelpFileName = "projection_algos_page.html";
574   else if ( aHypType == "NumberOfLayers")
575     aHelpFileName = "radial_prism_algo_page.html";
576   else if ( aHypType == "NumberOfLayers2D")
577     aHelpFileName = "radial_quadrangle_1D2D_algo_page.html";
578   else if ( aHypType == "LayerDistribution")
579     aHelpFileName = "radial_prism_algo_page.html";
580   else if ( aHypType == "LayerDistribution2D")
581     aHelpFileName = "radial_quadrangle_1D2D_algo_page.html";
582   else if ( aHypType == "SegmentLengthAroundVertex")
583     aHelpFileName = "segments_around_vertex_algo_page.html";
584   else if ( aHypType == "QuadrangleParams")
585     aHelpFileName = "a2d_meshing_hypo_page.html#hypo_quad_params_anchor";
586   else if ( aHypType == "ViscousLayers")
587     aHelpFileName = "additional_hypo_page.html#viscous_layers_anchor";
588   else if ( aHypType == "ViscousLayers2D")
589     aHelpFileName = "additional_hypo_page.html#viscous_layers_anchor";
590   else if ( aHypType == "ImportSource1D" || aHypType == "ImportSource2D")
591     aHelpFileName = "import_algos_page.html";
592   return aHelpFileName;
593 }
594
595 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
596 : QtxDialog( parent, false, true ),
597   myCreator( creator )
598 {
599   setAttribute(Qt::WA_DeleteOnClose, true);
600  // setMinimumSize( 300, height() );
601 //  setFixedSize( 300, height() );
602   QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
603   topLayout->setMargin( 0 );
604   topLayout->setSpacing( 0 );
605
606   QFrame* titFrame = new QFrame( mainFrame() );
607   QHBoxLayout* titLay = new QHBoxLayout( titFrame );
608   titLay->setMargin( 0 );
609   titLay->setSpacing( SPACING );
610
611   myIconLabel = new QLabel( titFrame );
612   myIconLabel->setScaledContents( false );
613   myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
614   myTypeLabel = new QLabel( titFrame );
615   if( creator )
616     myTypeLabel->setText( creator->hypType() );
617
618   titLay->addWidget( myIconLabel, 0 );
619   titLay->addWidget( myTypeLabel, 0 );
620   titLay->addStretch( 1 );
621
622   topLayout->addWidget( titFrame, 0 );
623
624   myHelpFileName = creator->helpPage();
625
626   connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
627 }
628
629 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
630 {
631   delete myCreator;
632 }
633
634 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
635 {
636   if( f )
637   {
638     f->setParent( mainFrame() );
639     qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
640   }
641 }
642
643 void SMESHGUI_HypothesisDlg::accept()
644 {
645   QString msg;
646   if ( myCreator && !myCreator->checkParams( msg ) )
647   {
648     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
649     if ( !msg.isEmpty() )
650       str += "\n" + msg;
651     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
652     return;
653   }
654   QtxDialog::accept();
655 }
656
657 void SMESHGUI_HypothesisDlg::reject()
658 {
659   if ( myCreator ) myCreator->onReject();
660   QtxDialog::reject();
661 }
662
663 void SMESHGUI_HypothesisDlg::onHelp()
664 {
665   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
666   if (app) {
667     QString name = "SMESH";
668     if(myCreator) {
669       QVariant pluginName = myCreator->property( PLUGIN_NAME );
670       if( pluginName.isValid() ) {
671         QString rootDir = pluginName.toString() + "PLUGIN_ROOT_DIR";
672         QString varValue = QString( getenv(rootDir.toLatin1().constData()));
673         if(!varValue.isEmpty())
674           name = pluginName.toString() + "PLUGIN";
675       }
676     }    
677     app->onHelpContextModule(name, myHelpFileName);
678   }
679   else {
680     QString platform;
681 #ifdef WIN32
682     platform = "winapplication";
683 #else
684     platform = "application";
685 #endif
686     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
687                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
688                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
689                                                                  platform)).
690                              arg(myHelpFileName));
691   }
692 }
693
694 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
695 {
696   myIconLabel->setPixmap( p );
697 }
698
699 void SMESHGUI_HypothesisDlg::setType( const QString& t )
700 {
701   myTypeLabel->setText( t );
702 }
703
704 HypothesisData::HypothesisData( const QString& theTypeName,
705                                 const QString& thePluginName,
706                                 const QString& theServerLibName,
707                                 const QString& theClientLibName,
708                                 const QString& theLabel,
709                                 const QString& theIconId,
710                                 const QList<int>& theDim,
711                                 const bool theIsAux,
712                                 const QStringList& theNeededHypos,
713                                 const QStringList& theOptionalHypos,
714                                 const QStringList& theInputTypes,
715                                 const QStringList& theOutputTypes,
716                                 const bool theIsNeedGeometry,
717                                 const bool supportSub)
718   : TypeName( theTypeName ),
719     PluginName( thePluginName ),
720     ServerLibName( theServerLibName ),
721     ClientLibName( theClientLibName ),
722     Label( theLabel ),
723     IconId( theIconId ),
724     Dim( theDim ),
725     IsAux( theIsAux ),
726     NeededHypos( theNeededHypos ),
727     OptionalHypos( theOptionalHypos ),
728     InputTypes( theInputTypes ),
729     OutputTypes( theOutputTypes ),
730     IsNeedGeometry( theIsNeedGeometry ),
731     IsSupportSubmeshes( supportSub )
732 {
733 }
734
735 HypothesesSet::HypothesesSet( const QString& theSetName )
736   : myHypoSetName( theSetName ),
737     myIsAlgo( false ),
738     myIsCustom( false )
739 {
740 }
741
742 HypothesesSet::HypothesesSet( const QString&     theSetName,
743                               const QStringList& theHypoList,
744                               const QStringList& theAlgoList )
745   : myHypoSetName( theSetName ),
746     myHypoList( theHypoList ),
747     myAlgoList( theAlgoList ),
748     myIsAlgo( false ),
749     myIsCustom( false )
750 {
751 }
752
753 QStringList* HypothesesSet::list(bool is_algo) const
754 {
755   return const_cast<QStringList*>( &( is_algo ? myAlgoList : myHypoList ) );
756 }
757
758 QStringList* HypothesesSet::list() const
759 {
760   return list( myIsAlgo );
761 }
762
763 QString HypothesesSet::name() const
764 {
765   return myHypoSetName;
766 }
767
768 void HypothesesSet::set( bool isAlgo, const QStringList& lst )
769 {
770   *list(isAlgo) = lst;
771 }
772
773 int HypothesesSet::count( bool isAlgo ) const
774 {
775   return list(isAlgo)->count();
776 }
777
778 bool HypothesesSet::isAlgo() const
779 {
780   return myIsAlgo;
781 }
782
783 void HypothesesSet::init( bool isAlgo )
784 {
785   myIsAlgo = isAlgo;
786   myIndex = -1;
787 }
788
789 bool HypothesesSet::more() const
790 {
791   return myIndex < list()->count();
792 }
793
794 void HypothesesSet::next()
795 {
796   myIndex++;
797 }
798
799 QString HypothesesSet::current() const
800 {
801   return list()->at(myIndex);
802 }
803
804 void HypothesesSet::setIsCustom( bool isCustom )
805 {
806   myIsCustom = isCustom;
807 }
808
809 bool HypothesesSet::getIsCustom() const
810 {
811   return myIsCustom;
812 }
813
814 int HypothesesSet::maxDim() const
815 {
816   HypothesesSet * thisSet = (HypothesesSet*) this;
817   int dim = -1;
818   for ( int isAlgo = 0; isAlgo < 2; ++isAlgo )
819   {
820     thisSet->init( isAlgo );
821     while ( thisSet->next(), thisSet->more() )
822       if ( HypothesisData* hypData = SMESH::GetHypothesisData( thisSet->current() ))
823         for ( int i = 0; i < hypData->Dim.count(); ++i )
824           dim = qMax( dim, hypData->Dim[i] );
825   }
826   return dim;
827 }