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