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