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