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