Salome HOME
b2e1e2496f0a27467720213ee1ed6152dfe603fd
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Hypotheses.cxx
1 // Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SMESHGUI_Hypotheses.cxx
23 //  Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
24 //  SMESH includes
25
26 #include "SMESHGUI_Hypotheses.h"
27
28 #include "SMESHGUI.h"
29 #include "SMESHGUI_HypothesesUtils.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESH_Actor.h"
34 #include "SMESH_TypeDefs.hxx"
35
36 // SALOME KERNEL includes
37 #include <SALOMEDSClient_Study.hxx>
38 #include <utilities.h>
39
40 // SALOME GUI includes
41 #include <LightApp_Application.h>
42 #include <SUIT_MessageBox.h>
43 #include <SUIT_OverrideCursor.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Session.h>
46 #include <SalomeApp_IntSpinBox.h>
47 #include <SalomeApp_Tools.h>
48 #include <SVTK_ViewWindow.h>
49
50 // Qt includes
51 #include <QFrame>
52 #include <QLineEdit>
53 #include <QLabel>
54 #include <QGroupBox>
55 #include <QVBoxLayout>
56
57 #define SPACING 6
58 #define MARGIN  11
59
60 SMESHGUI_GenericHypothesisCreator::SMESHGUI_GenericHypothesisCreator( const QString& theHypType )
61   : myToDeleteInitParamsHypo( false ),
62     myHypType( theHypType ),
63     myIsCreate( false ),
64     myDlg( 0 )
65 {
66 }
67
68 SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator()
69 {
70   if ( myToDeleteInitParamsHypo && !myInitParamsHypo->_is_nil() )
71     myInitParamsHypo->UnRegister();
72 }
73
74 void SMESHGUI_GenericHypothesisCreator::setInitParamsHypothesis(SMESH::SMESH_Hypothesis_ptr hyp)
75 {
76   if ( !CORBA::is_nil( hyp ) ) {
77     if ( myToDeleteInitParamsHypo && !myInitParamsHypo->_is_nil() )
78       myInitParamsHypo->UnRegister();
79     CORBA::String_var hypName = hyp->GetName();
80     if ( hypType() == hypName.in() )
81     {
82       myInitParamsHypo         = SMESH::SMESH_Hypothesis::_duplicate( hyp );
83       myToDeleteInitParamsHypo = !SMESH::FindSObject( myInitParamsHypo );
84     }
85   }
86 }
87
88 void SMESHGUI_GenericHypothesisCreator::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp,
89                                                 const QString& theHypName,
90                                                 QWidget* parent, QObject* obj, const QString& slot )
91 {
92   setInitParamsHypothesis( initParamsHyp );
93   create( false, theHypName, parent, obj, slot );
94 }
95
96 void SMESHGUI_GenericHypothesisCreator::create( bool           isAlgo,
97                                                 const QString& theHypName,
98                                                 QWidget*       theParent,
99                                                 QObject*       obj,
100                                                 const QString& slot )
101 {
102   myIsCreate = true;
103
104   // Create hypothesis/algorithm
105   if (isAlgo) {
106     SMESH::SMESH_Hypothesis_var anAlgo =
107       SMESH::CreateHypothesis( hypType(), theHypName, isAlgo );
108     anAlgo.out(); // avoid unused variable warning
109   }
110   else {
111     SMESH::SMESH_Hypothesis_var aHypothesis =
112       SMESH::CreateHypothesis( hypType(), theHypName, false );
113     editHypothesis( aHypothesis.in(), theHypName, theParent, obj, slot );
114   }
115 }
116
117 void SMESHGUI_GenericHypothesisCreator::edit( SMESH::SMESH_Hypothesis_ptr theHypothesis,
118                                               const QString&              theHypName,
119                                               QWidget* theParent, QObject* obj, const QString& slot )
120 {
121   if( CORBA::is_nil( theHypothesis ) )
122     return;
123
124   myIsCreate = false;
125
126   editHypothesis( theHypothesis, theHypName, theParent, obj, slot );
127 }
128
129 void SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ptr h,
130                                                         const QString& theHypName,
131                                                         QWidget* theParent,
132                                                         QObject* obj, const QString& slot )
133 {
134   myHypName = theHypName;
135   myHypo = SMESH::SMESH_Hypothesis::_duplicate( h );
136   myHypo->Register();
137
138   SMESHGUI_HypothesisDlg* Dlg = new SMESHGUI_HypothesisDlg( this, theParent );
139   connect( Dlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
140   connect( this, SIGNAL( finished( int ) ), obj, slot.toLatin1().constData() );
141   connect( SMESHGUI::GetSMESHGUI(), SIGNAL( SignalCloseAllDialogs() ), Dlg, SLOT( reject() ));
142
143   myDlg = Dlg;
144   QFrame* fr = buildFrame();
145   if( fr )
146   {
147     Dlg->setCustomFrame( fr );
148     Dlg->setWindowTitle( caption() );
149     Dlg->setObjectName( theHypName );
150     Dlg->setHIcon( icon() );
151     if ( theHypName == HypothesesSet::getCommonHypoSetHypoType() )
152       Dlg->setType( tr( HypothesesSet::getCommonHypoSetHypoType()) );
153     else
154       Dlg->setType( type() );
155     retrieveParams();
156     Dlg->show(); // w/o this Dlg blocks selection
157     Dlg->resize( Dlg->minimumSizeHint() );
158     Dlg->exec(); // w/o this we cant wait until edition ends when applying a hypo-set
159   }
160   else {
161     emit finished( QDialog::Accepted );
162     delete myDlg;
163   }
164 }
165
166 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
167 {
168   if( CORBA::is_nil( hypothesis() ) )
169     return 0;
170
171   ListOfStdParams params;
172   if( !stdParams( params ) || params.isEmpty() )
173     return 0;
174
175   QFrame* fr = new QFrame( 0 );
176   QVBoxLayout* lay = new QVBoxLayout( fr );
177   lay->setMargin( 5 );
178   lay->setSpacing( 0 );
179
180   QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
181   lay->addWidget( GroupC1 );
182
183   QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
184   GroupC1Layout->setSpacing( SPACING );
185   GroupC1Layout->setMargin( MARGIN );
186
187   ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end();
188   for( int i = 0; anIt != aLast; anIt++, i++ )
189   {
190     QLabel* lab = anIt->hasName() ? new QLabel( anIt->myName, GroupC1 ) : NULL;
191     if ( lab )
192       GroupC1Layout->addWidget( lab, i, 0 );
193     myParamLabels << lab;
194
195     QWidget* w = getCustomWidget( *anIt, GroupC1, i );
196     if ( !w )
197       switch( (*anIt).myValue.type() )
198       {
199       case QVariant::Int:
200         {
201           SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
202           sb->setObjectName( (*anIt).myName );
203           attuneStdWidget( sb, i );
204           sb->setValue( (*anIt).myValue.toInt() );
205           connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
206           w = sb;
207         }
208         break;
209       case QVariant::Double:
210         {
211           SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
212           sb->setObjectName( (*anIt).myName );
213           attuneStdWidget( sb, i );
214           sb->setValue( (*anIt).myValue.toDouble() );
215           connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
216           w = sb;
217         }
218         break;
219       case QVariant::String:
220         {
221           if((*anIt).isVariable) {
222             _PTR(Study) aStudy = SMESH::getStudy();
223             QString aVar = (*anIt).myValue.toString();
224             if(aStudy->IsInteger(aVar.toLatin1().constData())){
225               SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
226               sb->setObjectName( (*anIt).myName );
227               attuneStdWidget( sb, i );
228               sb->setText( aVar );
229               connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
230               w = sb;
231             }
232             else if(aStudy->IsReal(aVar.toLatin1().constData())){
233               SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
234               sb->setObjectName( (*anIt).myName );
235               attuneStdWidget( sb, i );
236               sb->setText( aVar );
237               connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
238               w = sb;
239             }
240           }
241           else {
242             QLineEdit* le = new QLineEdit( GroupC1 );
243             le->setObjectName( (*anIt).myName );
244             attuneStdWidget( le, i );
245             le->setText( (*anIt).myValue.toString() );
246             connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
247             w = le;
248           }
249         }
250         break;
251
252       default:;
253       } // switch( (*anIt).myValue.type() )
254
255     if ( w )
256     {
257       if ( lab )
258         GroupC1Layout->addWidget( w, i, 1 );
259       else
260         GroupC1Layout->addWidget( w, i, 0, 1, 2 );
261       changeWidgets().append( w );
262     }
263   }
264   if ( QWidget* w = getHelperWidget() )
265   {
266     w->setParent( fr );
267     w->move( QPoint( 0, 0 ) );
268     lay->addWidget( w );
269   }
270
271   return fr;
272 }
273
274 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
275 {
276   valueChanged( (QWidget*) sender() );
277 }
278
279 void SMESHGUI_GenericHypothesisCreator::valueChanged( QWidget* )
280 {
281 }
282
283 void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int result )
284 {
285   bool res = result==QDialog::Accepted;
286   if( res )
287   {
288     try
289     {
290       SUIT_OverrideCursor wc;
291       storeParams();
292       // No longer needed since NoteBook appears and "Value" OB field shows names of variable
293       // QString paramValues = storeParams();
294       // if ( !paramValues.isEmpty() ) {
295       //   if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
296       //     SMESH::SetValue( SHyp, paramValues );
297       // }
298     }
299     catch ( const SALOME::SALOME_Exception& S_ex ) {
300       SalomeApp_Tools::QtCatchCorbaException( S_ex );
301     }
302   }
303
304   changeWidgets().clear();
305
306   if( myIsCreate && !res )
307   {
308     //remove just created hypothesis
309     _PTR(SObject) aHypSObject = SMESH::FindSObject( myHypo );
310     _PTR(Study) aStudy = SMESH::getStudy();
311     if( aStudy && !aStudy->GetProperties()->IsLocked() )
312     {
313       _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
314       aBuilder->RemoveObjectWithChildren( aHypSObject );
315     }
316   }
317   else if( !myIsCreate && res )
318   {
319     SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( myHypo );
320     if( listSOmesh.size() > 0 )
321       for( size_t i = 0; i < listSOmesh.size(); i++ )
322       {
323         _PTR(SObject) submSO = listSOmesh[i];
324         SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
325         SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
326         if( !aSubMesh->_is_nil() )
327           aMesh = aSubMesh->GetFather();
328         _PTR(SObject) meshSO = SMESH::FindSObject( aMesh );
329         SMESH_Actor* actor = SMESH::FindActorByEntry( meshSO->GetID().c_str() );
330         if( actor && actor->GetVisibility() )
331           actor->Update();
332       }
333   }
334   SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
335   myHypo->UnRegister();
336   myHypo = SMESH::SMESH_Hypothesis::_nil();
337   myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
338
339   disconnect( myDlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
340   myDlg->close();
341   //delete myDlg; since WA_DeleteOnClose==true
342   myDlg = 0;
343
344   SMESH::UpdateActorsAfterUpdateStudy();// remove actors of removed groups (#16522)
345   if (SVTK_ViewWindow* vf = SMESH::GetCurrentVtkView()) {
346     vf->Repaint();
347   }
348   emit finished( result );
349 }
350
351 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
352 {
353   return false;
354 }
355
356 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
357 {
358   bool res = true;
359   StdParam item;
360   ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
361   for( ; anIt!=aLast; anIt++ )
362   {
363     item.myName = (*anIt)->objectName();
364     if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
365     {
366       SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
367       item.myValue = sb->value();
368       item.myText = sb->text();
369       params.append( item );
370     }
371     else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
372     {
373       SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
374       item.myValue = sb->value();
375       item.myText = sb->text();
376       params.append( item );
377     }
378     else if( (*anIt)->inherits( "QLineEdit" ) )
379     {
380       QLineEdit* line = ( QLineEdit* )( *anIt );
381       item.myValue = item.myText = line->text();
382       params.append( item );
383     }
384     else if ( getParamFromCustomWidget( item, *anIt ))
385     {
386       params.append( item );
387     }
388     else
389       res = false;
390   }
391   return res;
392 }
393
394 QString SMESHGUI_GenericHypothesisCreator::getVariableName(const char* methodName) const
395 {
396   SMESH::SMESH_Hypothesis_var h = hypothesis();
397   if ( !h->_is_nil() )
398   {
399     CORBA::String_var aVaribaleName = h->GetVarParameter( methodName );
400     return QString( aVaribaleName.in() );
401   }
402   return QString();
403 }
404
405 QStringList SMESHGUI_GenericHypothesisCreator::getVariablesFromDlg() const
406 {
407   QStringList aResult;
408   ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
409   for( ; anIt!=aLast; anIt++ ) {
410     if( (*anIt)->inherits( "QAbstractSpinBox" ) ) {
411       QAbstractSpinBox* sb = ( QAbstractSpinBox* )( *anIt );
412       aResult.append(sb->text());
413     }
414   }
415   return aResult;
416 }
417
418 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
419 {
420   QString valueStr = "";
421   ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
422   int len0 = 0;
423   for ( ; param != aLast; param++ )
424   {
425     if ( valueStr.length() > len0 ) {
426       valueStr += "; ";
427       len0 = valueStr.length();
428     }
429     switch( (*param).myValue.type() )
430     {
431     case QVariant::Int:
432       valueStr += valueStr.number( (*param).myValue.toInt() );
433       break;
434     case QVariant::Double:
435       valueStr += valueStr.number( (*param).myValue.toDouble() );
436       break;
437     case QVariant::String:
438       valueStr += (*param).myValue.toString();
439       break;
440     default:
441       QVariant valCopy = (*param).myValue;
442       valueStr += valCopy.toString();
443     }
444   }
445   return valueStr;
446 }
447
448 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
449 {
450   return myHypo;
451 }
452
453 void SMESHGUI_GenericHypothesisCreator::setShapeEntry( const QString& theEntry )
454 {
455   myShapeEntry = theEntry;
456 }
457
458 //================================================================================
459 /*!
460  * \brief Return hypothesis containing initial parameters
461  *  \param strictly - if true, always return myInitParamsHypo,
462  *                    else, return myInitParamsHypo only in creation mode and if it
463  *                    is non-nil
464  */
465 //================================================================================
466
467 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis(const bool strictly) const
468 {
469   if ( strictly )
470     return myInitParamsHypo;
471   if ( !isCreation() || CORBA::is_nil( myInitParamsHypo ))
472     return myHypo;
473   return myInitParamsHypo;
474 }
475
476 bool SMESHGUI_GenericHypothesisCreator::hasInitParamsHypothesis() const
477 {
478   return !CORBA::is_nil( myInitParamsHypo );
479 }
480
481 QString SMESHGUI_GenericHypothesisCreator::hypType() const
482 {
483   return myHypType;
484 }
485
486 QString SMESHGUI_GenericHypothesisCreator::hypName() const
487 {
488   return myHypName;
489 }
490
491 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
492 {
493   return myParamWidgets;
494 }
495
496 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
497 {
498   return myParamWidgets;
499 }
500
501 //================================================================================
502 /*!
503  * \brief Returns a QLabel of a specified parameter.
504  * If isCreation(), the 1st label (supposed to be "Name") is not countered.
505  */
506 //================================================================================
507
508 QLabel* SMESHGUI_GenericHypothesisCreator::getLabel(int i) const
509 {
510   if ( isCreation() )
511     i++;
512   if ( i < myParamLabels.size() )
513     return (QLabel*) myParamLabels.at(i);
514   return NULL;
515 }
516
517 QtxDialog* SMESHGUI_GenericHypothesisCreator:: dlg() const
518 {
519   return myDlg;
520 }
521
522 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
523 {
524   return myIsCreate;
525 }
526
527 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
528 {
529 }
530
531 QString SMESHGUI_GenericHypothesisCreator::caption() const
532 {
533   return QString();
534 }
535
536 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
537 {
538   return QPixmap();
539 }
540
541 QString SMESHGUI_GenericHypothesisCreator::type() const
542 {
543   return QString();
544 }
545 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
546                                                              QWidget*   /*parent*/,
547                                                              const int  /*index*/) const
548 {
549   return 0;
550 }
551 //================================================================================
552 /*!
553  * \brief Returns a widget representing not a hypothesis parameter but some helper widget
554  */
555 //================================================================================
556
557 QWidget* SMESHGUI_GenericHypothesisCreator::getHelperWidget() const
558 {
559   return 0;
560 }
561
562 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWidget* ) const
563 {
564   return false;
565 }
566
567 bool SMESHGUI_GenericHypothesisCreator::checkParams( QString& msg ) const
568 {
569   bool ok = true;
570   ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
571   for( ; anIt!=aLast; anIt++ )
572   {
573     if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
574     {
575       SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
576       ok = sb->isValid( msg, true ) && ok;
577     }
578     else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
579     {
580       SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
581       ok = sb->isValid( msg, true ) && ok;
582     }
583   }
584   return ok;
585 }
586
587 void SMESHGUI_GenericHypothesisCreator::onReject()
588 {
589 }
590
591 QString SMESHGUI_GenericHypothesisCreator::helpPage() const
592 {
593   QString aHypType = hypType();
594   QString aHelpFileName = "";
595   if ( aHypType == "LocalLength" )
596     aHelpFileName = "1d_meshing_hypo.html#average-length-anchor";
597   else if ( aHypType == "MaxLength" )
598     aHelpFileName = "1d_meshing_hypo.html#max-length-anchor";
599   else if ( aHypType == "Arithmetic1D")
600     aHelpFileName = "1d_meshing_hypo.html#arithmetic-1d-anchor";
601   else if ( aHypType == "GeometricProgression")
602     aHelpFileName = "1d_meshing_hypo.html#geometric-1d-anchor";
603   else if ( aHypType == "FixedPoints1D")
604     aHelpFileName = "1d_meshing_hypo.html#fixed-points-1d-anchor";
605   else if ( aHypType == "MaxElementArea")
606     aHelpFileName = "2d_meshing_hypo.html#max-element-area-anchor";
607   else if ( aHypType == "MaxElementVolume")
608     aHelpFileName = "max_element_volume_hypo.html";
609   else if ( aHypType == "StartEndLength")
610     aHelpFileName = "1d_meshing_hypo.html#start-and-end-length-anchor";
611   else if ( aHypType == "Deflection1D")
612     aHelpFileName = "1d_meshing_hypo.html#deflection-1d-anchor";
613   else if ( aHypType == "Adaptive1D")
614     aHelpFileName = "1d_meshing_hypo.html#adaptive-1d-anchor";
615   else if ( aHypType == "AutomaticLength")
616     aHelpFileName = "1d_meshing_hypo.html#automatic-length-anchor";
617   else if ( aHypType == "NumberOfSegments")
618     aHelpFileName = "1d_meshing_hypo.html#number-of-segments-anchor";
619   else if ( aHypType == "ProjectionSource1D")
620     aHelpFileName = "projection_algos.html";
621   else if ( aHypType == "ProjectionSource2D")
622     aHelpFileName = "projection_algos.html";
623   else if ( aHypType == "ProjectionSource3D")
624     aHelpFileName = "projection_algos.html";
625   else if ( aHypType == "NumberOfLayers")
626     aHelpFileName = "radial_prism_algo.html";
627   else if ( aHypType == "NumberOfLayers2D")
628     aHelpFileName = "radial_quadrangle_1D2D_algo.html";
629   else if ( aHypType == "LayerDistribution")
630     aHelpFileName = "radial_prism_algo.html";
631   else if ( aHypType == "LayerDistribution2D")
632     aHelpFileName = "radial_quadrangle_1D2D_algo.html";
633   else if ( aHypType == "SegmentLengthAroundVertex")
634     aHelpFileName = "segments_around_vertex_algo.html";
635   else if ( aHypType == "QuadrangleParams")
636     aHelpFileName = "2d_meshing_hypo.html#hypo-quad-params-anchor";
637   else if ( aHypType == "ViscousLayers")
638     aHelpFileName = "additional_hypo.html#viscous-layers-anchor";
639   else if ( aHypType == "ViscousLayers2D")
640     aHelpFileName = "additional_hypo.html#viscous-layers-anchor";
641   else if ( aHypType == "ImportSource1D" || aHypType == "ImportSource2D")
642     aHelpFileName = "use_existing_algos.html";
643   return aHelpFileName;
644 }
645
646 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
647 : QtxDialog( parent, false, true ),
648   myCreator( creator )
649 {
650   setAttribute(Qt::WA_DeleteOnClose, true);
651  // setMinimumSize( 300, height() );
652 //  setFixedSize( 300, height() );
653   QVBoxLayout* topLayout = new QVBoxLayout( mainFrame() );
654   topLayout->setMargin( 0 );
655   topLayout->setSpacing( 0 );
656
657   QFrame* titFrame = new QFrame( mainFrame() );
658   QHBoxLayout* titLay = new QHBoxLayout( titFrame );
659   titLay->setMargin( 0 );
660   titLay->setSpacing( SPACING );
661
662   myIconLabel = new QLabel( titFrame );
663   myIconLabel->setScaledContents( false );
664   myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
665   myTypeLabel = new QLabel( titFrame );
666   if( creator )
667     myTypeLabel->setText( creator->hypType() );
668
669   titLay->addWidget( myIconLabel, 0 );
670   titLay->addWidget( myTypeLabel, 0 );
671   titLay->addStretch( 1 );
672
673   topLayout->addWidget( titFrame, 0 );
674
675   myHelpFileName = creator->helpPage();
676
677   connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
678 }
679
680 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
681 {
682   delete myCreator;
683 }
684
685 void SMESHGUI_HypothesisDlg::showEvent(QShowEvent *event)
686 {
687   // resize( minimumSizeHint() );
688   // adjustSize();
689
690   QtxDialog::showEvent( event );
691 }
692
693 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
694 {
695   if( f )
696   {
697     f->setParent( mainFrame() );
698     qobject_cast<QVBoxLayout*>( mainFrame()->layout() )->insertWidget( 1, f, 1 );
699   }
700 }
701
702 void SMESHGUI_HypothesisDlg::accept()
703 {
704   SUIT_OverrideCursor wc; // some creators temporary set params to a hyp which can be long
705   QString msg;
706   if ( myCreator && !myCreator->checkParams( msg ) )
707   {
708     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
709     if ( !msg.isEmpty() )
710       str += "\n" + msg;
711     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
712     return;
713   }
714   QtxDialog::accept();
715 }
716
717 void SMESHGUI_HypothesisDlg::reject()
718 {
719   if ( myCreator ) myCreator->onReject();
720   QtxDialog::reject();
721 }
722
723 void SMESHGUI_HypothesisDlg::onHelp()
724 {
725   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
726   if (app) {
727     QString name = "SMESH";
728     if(myCreator) {
729       QVariant pluginName = myCreator->property( SMESH::Plugin_Name() );
730       if( pluginName.isValid() ) {
731         QString rootDir = pluginName.toString() + "PLUGIN_ROOT_DIR";
732         QString varValue = QString( getenv(rootDir.toLatin1().constData()));
733         if(!varValue.isEmpty())
734           name = pluginName.toString() + "PLUGIN";
735       }
736     }    
737     app->onHelpContextModule(name, myHelpFileName);
738   }
739   else {
740     QString platform;
741 #ifdef WIN32
742     platform = "winapplication";
743 #else
744     platform = "application";
745 #endif
746     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
747                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
748                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
749                                                                  platform)).
750                              arg(myHelpFileName));
751   }
752 }
753
754 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
755 {
756   myIconLabel->setPixmap( p );
757 }
758
759 void SMESHGUI_HypothesisDlg::setType( const QString& t )
760 {
761   myTypeLabel->setText( t );
762 }
763
764 HypothesisData::HypothesisData( const QString&     theTypeName,
765                                 const QString&     thePluginName,
766                                 const QString&     theServerLibName,
767                                 const QString&     theClientLibName,
768                                 const QString&     theLabel,
769                                 const QString&     theIconId,
770                                 const QString&     theContext,
771                                 const int          theGroupID,
772                                 const int          thePriority,
773                                 const QList<int>&  theDim,
774                                 const bool         theIsAuxOrNeedHyp,
775                                 const QStringList& theBasicHypos,
776                                 const QStringList& theOptionalHypos,
777                                 const QStringList& theInputTypes,
778                                 const QStringList& theOutputTypes,
779                                 const int          theIsNeedGeometry,
780                                 const bool         theSupportSub)
781   : TypeName( theTypeName ),
782     PluginName( thePluginName ),
783     ServerLibName( theServerLibName ),
784     ClientLibName( theClientLibName ),
785     Label( theLabel ),
786     IconId( theIconId ),
787     Context( theContext ),
788     GroupID( theGroupID ),
789     Priority( thePriority ),
790     Dim( theDim ),
791     IsAuxOrNeedHyp( theIsAuxOrNeedHyp ),
792     IsNeedGeometry( theIsNeedGeometry ),
793     IsSupportSubmeshes( theSupportSub ),
794     BasicHypos( theBasicHypos ),
795     OptionalHypos( theOptionalHypos ),
796     InputTypes( theInputTypes ),
797     OutputTypes( theOutputTypes )
798 {
799 }
800
801 // HypothesesSet::HypothesesSet( const QString& theSetName )
802 //   : myHypoSetName( theSetName ),
803 //     myIsAlgo( false ),
804 //     myIsCustom( false )
805 // {
806 // }
807
808 HypothesesSet::HypothesesSet( const QString& theSetName,
809                               bool useCommonSize, bool isQuadDominated,
810                               const QStringList& mainHypos, const QStringList& mainAlgos,
811                               const QStringList& altHypos,  const QStringList& altAlgos,
812                               const QStringList& intHypos,  const QStringList& intAlgos )
813   : myUseCommonSize( useCommonSize ),
814     myQuadDominated( isQuadDominated ),
815     myHypoSetName( theSetName ),
816         myHypoList { mainHypos, altHypos, intHypos },
817         myAlgoList { mainAlgos, altAlgos, intAlgos },
818     myIsAlgo( false ),
819     myIsCustom( false ),
820     myIndex( 0 )
821 {
822   for ( myHypType = MAIN; myHypType < NB_HYP_TYPES; SMESHUtils::Increment( myHypType ))
823     for ( int isAlgo = myIsAlgo = 0; isAlgo < 2; myIsAlgo = ++isAlgo )
824     {
825       QStringList& hyps = *list();
826       for ( int i = 0; i < hyps.count(); ++i )
827         hyps[ i ] = hyps[ i ].trimmed();
828     }
829 }
830
831 QStringList* HypothesesSet::list( bool is_algo, SetType setType) const
832 {
833   return const_cast<QStringList*>( &( is_algo ? myAlgoList[setType] : myHypoList[setType] ));
834 }
835
836 QStringList* HypothesesSet::list() const
837 {
838   return list( myIsAlgo, myHypType );
839 }
840
841 QString HypothesesSet::name() const
842 {
843   return myHypoSetName;
844 }
845
846 // void HypothesesSet::set( bool isAlgo, const QStringList& lst )
847 // {
848 //   *list(isAlgo) = lst;
849 // }
850
851 // int HypothesesSet::count( bool isAlgo, SetType setType ) const
852 // {
853 //   return list(isAlgo,setType)->count();
854 // }
855
856 // bool HypothesesSet::isAlgo() const
857 // {
858 //   return myIsAlgo;
859 // }
860
861 void HypothesesSet::init( bool isAlgo, SetType setType )
862 {
863   myHypType = setType;
864   myIsAlgo = isAlgo;
865   myIndex = 0;
866 }
867
868 bool HypothesesSet::more() const
869 {
870   return myIndex < list()->count();
871 }
872
873 void HypothesesSet::next()
874 {
875   myIndex++;
876 }
877
878 QString HypothesesSet::current() const
879 {
880   return list()->at(myIndex);
881 }
882
883 void HypothesesSet::setIsCustom( bool isCustom )
884 {
885   myIsCustom = isCustom;
886 }
887
888 bool HypothesesSet::getIsCustom() const
889 {
890   return myIsCustom;
891 }
892
893 void HypothesesSet::setAlgoAvailable( SetType type, bool isAvailable )
894 {
895   if ( MAIN <= type && type < NB_HYP_TYPES )
896     myIsAlgoAvailable[ type ] = isAvailable;
897 }
898
899 bool HypothesesSet::getAlgoAvailable( SetType type )
900 {
901   bool isAva = false;
902   if ( MAIN <= type && type < NB_HYP_TYPES )
903     isAva = myIsAlgoAvailable[ type ];
904   return isAva;
905 }
906
907 HypothesesSet::SetType HypothesesSet::getPreferredHypType()
908 {
909   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
910   int useAltHypos = !resMgr->booleanValue( "SMESH", "use-meshgems-hypo-sets", false );
911   return ( HypothesesSet::SetType ) useAltHypos;
912 }
913
914 int HypothesesSet::maxDim() const
915 {
916   HypothesesSet * thisSet = (HypothesesSet*) this;
917   int dim = -1;
918   for ( int setType = 0; setType < 2; ++setType )
919     for ( int isAlgo = 0; isAlgo < 2; ++isAlgo )
920     {
921       for ( thisSet->init( isAlgo, SetType( setType )); thisSet->more(); thisSet->next() )
922         if ( HypothesisData* hypData = SMESH::GetHypothesisData( thisSet->current() ))
923           for ( int i = 0; i < hypData->Dim.count(); ++i )
924             dim = qMax( dim, hypData->Dim[i] );
925     }
926   return dim;
927 }
928
929 const char* HypothesesSet::getCommonHypoSetHypoType()
930 {
931   return "AverageLengthForHypoSet";
932 }