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