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