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