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