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