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