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