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