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