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