Salome HOME
Merge from V5_1_main 10/12/2010
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Hypotheses.cxx
1 //  Copyright (C) 2007-2010  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 //  SMESH SMESHGUI : GUI for SMESH component
23 //  File   : SMESHGUI_Hypotheses.cxx
24 //  Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
25 //  SMESH includes
26
27 #include "SMESHGUI_Hypotheses.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_HypothesesUtils.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_SpinBox.h"
33
34 // SALOME KERNEL includes
35 #include <SALOMEDSClient_Study.hxx>
36 #include <utilities.h>
37
38 // SALOME GUI includes
39 #include <SUIT_Session.h>
40 #include <SUIT_MessageBox.h>
41 #include <SUIT_ResourceMgr.h>
42 #include <LightApp_Application.h>
43 #include <SalomeApp_IntSpinBox.h>
44
45 // Qt includes
46 #include <QFrame>
47 #include <QLineEdit>
48 #include <QLabel>
49 #include <QGroupBox>
50 #include <QVBoxLayout>
51
52 #define SPACING 6
53 #define MARGIN  11
54
55 //To disable automatic genericobj management, the following line should be commented.
56 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
57 #define WITHGENERICOBJ
58
59 SMESHGUI_GenericHypothesisCreator::SMESHGUI_GenericHypothesisCreator( const QString& theHypType )
60   : myHypType( theHypType ), myIsCreate( false ), myDlg( 0 )
61 {
62 }
63
64 SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator()
65 {
66 }
67
68 void SMESHGUI_GenericHypothesisCreator::setInitParamsHypothesis(SMESH::SMESH_Hypothesis_ptr hyp)
69 {
70   if ( !CORBA::is_nil( hyp ) && hypType() == hyp->GetName() )
71     myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( hyp );
72 }
73
74 void SMESHGUI_GenericHypothesisCreator::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp,
75                                                 const QString& theHypName,
76                                                 QWidget* parent, QObject* obj, const QString& slot )
77 {
78   MESSAGE( "Creation of hypothesis with initial params" );
79   setInitParamsHypothesis( initParamsHyp );
80   create( false, theHypName, parent, obj, slot );
81 }
82
83 void SMESHGUI_GenericHypothesisCreator::create( bool isAlgo,
84                                                 const QString& theHypName,
85                                                 QWidget* theParent, QObject* obj, const QString& slot )
86 {
87   MESSAGE( "Creation of hypothesis" );
88
89   myIsCreate = true;
90
91   // Create hypothesis/algorithm
92   if (isAlgo) {
93     SMESH::SMESH_Hypothesis_var anAlgo =
94       SMESH::CreateHypothesis( hypType(), theHypName, isAlgo );
95 #ifdef WITHGENERICOBJ
96     if (!CORBA::is_nil(anAlgo))
97       anAlgo->Destroy();
98 #endif
99   }
100   else {
101     SMESH::SMESH_Hypothesis_var aHypothesis =
102       SMESH::CreateHypothesis( hypType(), theHypName, false );
103     editHypothesis( aHypothesis.in(), theHypName, theParent, obj, slot );
104 #ifdef WITHGENERICOBJ
105     if (!CORBA::is_nil(aHypothesis))
106       aHypothesis->Destroy();
107 #endif
108   }
109 }
110
111 void SMESHGUI_GenericHypothesisCreator::edit( SMESH::SMESH_Hypothesis_ptr theHypothesis,
112                                               const QString& theHypName,
113                                               QWidget* theParent, QObject* obj, const QString& slot )
114 {
115   if( CORBA::is_nil( theHypothesis ) )
116     return;
117
118   MESSAGE("Edition of hypothesis");
119
120   myIsCreate = false;
121
122   editHypothesis( theHypothesis, theHypName, theParent, obj, slot );
123 }
124
125 void SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ptr h,
126                                                         const QString& theHypName,
127                                                         QWidget* theParent,
128                                                         QObject* obj, const QString& slot )
129 {
130   myHypName = theHypName;
131   myHypo = SMESH::SMESH_Hypothesis::_duplicate( h );
132 #ifdef WITHGENERICOBJ
133   myHypo->Register();
134 #endif
135
136   SMESHGUI_HypothesisDlg* Dlg = new SMESHGUI_HypothesisDlg( this, theParent );
137   connect( Dlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
138   connect( this, SIGNAL( finished( int ) ), obj, slot.toLatin1().constData() );
139   connect( SMESHGUI::GetSMESHGUI(), SIGNAL( SignalCloseAllDialogs() ), Dlg, SLOT( reject() ));
140
141   myDlg = Dlg;
142   QFrame* fr = buildFrame();
143   if( fr )
144   {
145     Dlg->setCustomFrame( fr );
146     Dlg->setWindowTitle( caption() );
147     Dlg->setObjectName( theHypName );
148     Dlg->setHIcon( icon() );
149     Dlg->setType( type() );
150     retrieveParams();
151     Dlg->show();
152     Dlg->resize( Dlg->minimumSizeHint() );
153   }
154   else
155     emit finished( QDialog::Accepted );
156 }
157
158 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
159 {
160   if( CORBA::is_nil( hypothesis() ) )
161     return 0;
162
163   ListOfStdParams params;
164   if( !stdParams( params ) || params.isEmpty() )
165     return 0;
166
167   QFrame* fr = new QFrame( 0 );
168   QVBoxLayout* lay = new QVBoxLayout( fr );
169   lay->setMargin( 5 );
170   lay->setSpacing( 0 );
171
172   QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
173   lay->addWidget( GroupC1 );
174
175   QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
176   GroupC1Layout->setSpacing( SPACING );
177   GroupC1Layout->setMargin( MARGIN );
178
179   ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end();
180   for( int i=0; anIt!=aLast; anIt++, i++ )
181   {
182     QLabel* lab = new QLabel( (*anIt).myName, GroupC1 );
183     GroupC1Layout->addWidget( lab, i, 0 );
184
185     QWidget* w = getCustomWidget( *anIt, GroupC1, i );
186     if ( !w )
187       switch( (*anIt).myValue.type() )
188       {
189       case QVariant::Int:
190         {
191           SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
192           sb->setObjectName( (*anIt).myName );
193           attuneStdWidget( sb, i );
194           sb->setValue( (*anIt).myValue.toInt() );
195           connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
196           w = sb;
197         }
198         break;
199       case QVariant::Double:
200         {
201           SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
202           sb->setObjectName( (*anIt).myName );
203           attuneStdWidget( sb, i );
204           sb->setValue( (*anIt).myValue.toDouble() );
205           connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
206           w = sb;
207         }
208         break;
209       case QVariant::String:
210         {
211           if((*anIt).isVariable) {
212             _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
213             QString aVar = (*anIt).myValue.toString();
214             if(aStudy->IsInteger(aVar.toLatin1().constData())){
215               SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
216               sb->setObjectName( (*anIt).myName );
217               attuneStdWidget( sb, i );
218               sb->setText( aVar );
219               connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
220               w = sb;
221             }
222             else if(aStudy->IsReal(aVar.toLatin1().constData())){
223               SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
224               sb->setObjectName( (*anIt).myName );
225               attuneStdWidget( sb, i );
226               sb->setText( aVar );
227               connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
228               w = sb;
229             }
230           }
231           else {
232             QLineEdit* le = new QLineEdit( GroupC1 );
233             le->setObjectName( (*anIt).myName );
234             attuneStdWidget( le, i );
235             le->setText( (*anIt).myValue.toString() );
236             connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
237             w = le;
238           }
239         }
240         break;
241       }
242
243     if( w )
244     {
245       GroupC1Layout->addWidget( w, i, 1 );
246       changeWidgets().append( w );
247     }
248   }
249
250   return fr;
251 }
252
253 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
254 {
255   valueChanged( (QWidget*) sender() );
256 }
257
258 void SMESHGUI_GenericHypothesisCreator::valueChanged( QWidget* )
259 {
260 }
261
262 void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int result )
263 {
264   bool res = result==QDialog::Accepted;
265   if( res )
266   {
267       /*QString paramValues = */storeParams();
268       // No longer needed since NoteBook appears and "Value" OB field shows names of variable
269 //       if ( !paramValues.isEmpty() ) {
270 //         if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
271 //           SMESH::SetValue( SHyp, paramValues );
272 //       }
273   }
274
275   changeWidgets().clear();
276
277   if( myIsCreate && !res )
278   {
279     //remove just created hypothesis
280     _PTR(SObject) aHypSObject = SMESH::FindSObject( myHypo );
281     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
282     if( aStudy && !aStudy->GetProperties()->IsLocked() )
283     {
284       _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
285       aBuilder->RemoveObjectWithChildren( aHypSObject );
286     }
287   }
288   else if( !myIsCreate && res )
289   {
290     SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( myHypo );
291     if( listSOmesh.size() > 0 )
292       for( int i = 0; i < listSOmesh.size(); i++ )
293       {
294         _PTR(SObject) submSO = listSOmesh[i];
295         SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
296         SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
297         if( !aSubMesh->_is_nil() )
298           aMesh = aSubMesh->GetFather();
299         _PTR(SObject) meshSO = SMESH::FindSObject( aMesh );
300         SMESH::ModifiedMesh( meshSO, false, aMesh->NbNodes()==0);
301       }
302   }
303   SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
304 #ifdef WITHGENERICOBJ
305   myHypo->Destroy();
306 #endif
307   myHypo = SMESH::SMESH_Hypothesis::_nil();
308   myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
309
310   disconnect( myDlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
311   myDlg->close();
312   //delete myDlg; since WA_DeleteOnClose==true
313   myDlg = 0;
314   emit finished( result );
315 }
316
317 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
318 {
319   return false;
320 }
321
322 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
323 {
324   bool res = true;
325   StdParam item;
326   ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
327   for( ; anIt!=aLast; anIt++ )
328   {
329     item.myName = (*anIt)->objectName();
330     if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
331     {
332       SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
333       item.myValue = sb->value();
334       params.append( item );
335     }
336     else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
337     {
338       SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
339       item.myValue = sb->value();
340       params.append( item );
341     }
342     else if( (*anIt)->inherits( "QLineEdit" ) )
343     {
344       QLineEdit* line = ( QLineEdit* )( *anIt );
345       item.myValue = line->text();
346       params.append( item );
347     }
348     else if ( getParamFromCustomWidget( item, *anIt ))
349     {
350       params.append( item );
351     }
352     else
353       res = false;
354   }
355   return res;
356 }
357
358
359 QStringList SMESHGUI_GenericHypothesisCreator::getVariablesFromDlg() const
360 {
361   QStringList aResult;
362   ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
363   for( ; anIt!=aLast; anIt++ ) {
364     if( (*anIt)->inherits( "QAbstractSpinBox" ) ) {
365       QAbstractSpinBox* sb = ( QAbstractSpinBox* )( *anIt );
366       aResult.append(sb->text());
367     }
368   }
369   return aResult;
370 }
371
372 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
373 {
374   QString valueStr = "";
375   ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
376   uint len0 = 0;
377   for( int i=0; param!=aLast; param++, i++ )
378   {
379     if ( valueStr.length() > len0 ) {
380       valueStr += "; ";
381       len0 = valueStr.length();
382     }
383     switch( (*param).myValue.type() )
384     {
385     case QVariant::Int:
386       valueStr += valueStr.number( (*param).myValue.toInt() );
387       break;
388     case QVariant::Double:
389       valueStr += valueStr.number( (*param).myValue.toDouble() );
390       break;
391     case QVariant::String:
392       valueStr += (*param).myValue.toString();
393       break;
394     default:
395       QVariant valCopy = (*param).myValue;
396       valueStr += valCopy.toString();
397     }
398   }
399   return valueStr;
400 }
401
402 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
403 {
404   return myHypo;
405 }
406
407 void SMESHGUI_GenericHypothesisCreator::setShapeEntry( const QString& theEntry )
408 {
409   myShapeEntry = theEntry;
410 }
411
412 //================================================================================
413 /*!
414  * \brief Return hypothesis containing initial parameters
415  *  \param strictly - if true, always return myInitParamsHypo,
416  *                    else, return myInitParamsHypo only in creation mode and if it
417  *                    is non-nil
418  */
419 //================================================================================
420
421 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis(const bool strictly) const
422 {
423   if ( strictly )
424     return myInitParamsHypo;
425   if ( !isCreation() || CORBA::is_nil( myInitParamsHypo ))
426     return myHypo;
427   return myInitParamsHypo;
428 }
429
430 bool SMESHGUI_GenericHypothesisCreator::hasInitParamsHypothesis() const
431 {
432   return !CORBA::is_nil( myInitParamsHypo );
433 }
434
435 QString SMESHGUI_GenericHypothesisCreator::hypType() const
436 {
437   return myHypType;
438 }
439
440 QString SMESHGUI_GenericHypothesisCreator::hypName() const
441 {
442   return myHypName;
443 }
444
445 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
446 {
447   return myParamWidgets;
448 }
449
450 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
451 {
452   return myParamWidgets;
453 }
454
455 QtxDialog* SMESHGUI_GenericHypothesisCreator:: dlg() const
456 {
457   return myDlg;
458 }
459
460 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
461 {
462   return myIsCreate;
463 }
464
465 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
466 {
467 }
468
469 QString SMESHGUI_GenericHypothesisCreator::caption() const
470 {
471   return QString();
472 }
473
474 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
475 {
476   return QPixmap();
477 }
478
479 QString SMESHGUI_GenericHypothesisCreator::type() const
480 {
481   return QString();
482 }
483 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
484                                                              QWidget*   /*parent*/,
485                                                              const int  /*index*/) const
486 {
487   return 0;
488 }
489 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWidget* ) const
490 {
491   return false;
492 }
493
494 bool SMESHGUI_GenericHypothesisCreator::checkParams( QString& msg ) const
495 {
496   bool ok = true;
497   ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
498   for( ; anIt!=aLast; anIt++ )
499   {
500     if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
501     {
502       SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
503       ok = sb->isValid( msg, true ) && ok;
504     }
505     else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
506     {
507       SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
508       ok = sb->isValid( msg, true ) && ok;
509     }
510   }
511   return ok;
512 }
513
514 void SMESHGUI_GenericHypothesisCreator::onReject()
515 {
516 }
517
518 QString SMESHGUI_GenericHypothesisCreator::helpPage() const
519 {
520   QString aHypType = hypType();
521   QString aHelpFileName = "";
522   if ( aHypType == "LocalLength" )
523     aHelpFileName = "a1d_meshing_hypo_page.html#average_length_anchor";
524   else if ( aHypType == "MaxLength" )
525     aHelpFileName = "a1d_meshing_hypo_page.html#max_length_anchor";
526   else if ( aHypType == "Arithmetic1D")
527     aHelpFileName = "a1d_meshing_hypo_page.html#arithmetic_1d_anchor";
528   else if ( aHypType == "FixedPoints1D")
529     aHelpFileName = "a1d_meshing_hypo_page.html#fixed_points_1d_anchor";
530   else if ( aHypType == "MaxElementArea")
531     aHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
532   else if ( aHypType == "MaxElementVolume")
533     aHelpFileName = "max_element_volume_hypo_page.html";
534   else if ( aHypType == "StartEndLength")
535     aHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
536   else if ( aHypType == "Deflection1D")
537     aHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
538   else if ( aHypType == "AutomaticLength")
539     aHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
540   else if ( aHypType == "NumberOfSegments")
541     aHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
542   else if ( aHypType == "ProjectionSource1D")
543     aHelpFileName = "projection_algos_page.html";
544   else if ( aHypType == "ProjectionSource2D")
545     aHelpFileName = "projection_algos_page.html";
546   else if ( aHypType == "ProjectionSource3D")
547     aHelpFileName = "projection_algos_page.html";
548   else if ( aHypType == "NumberOfLayers")
549     aHelpFileName = "radial_prism_algo_page.html";
550   else if ( aHypType == "NumberOfLayers2D")
551     aHelpFileName = "radial_quadrangle_1D2D_algo_page.html";
552   else if ( aHypType == "LayerDistribution")
553     aHelpFileName = "radial_prism_algo_page.html";
554   else if ( aHypType == "LayerDistribution2D")
555     aHelpFileName = "radial_quadrangle_1D2D_algo_page.html";
556   else if ( aHypType == "SegmentLengthAroundVertex")
557     aHelpFileName = "segments_around_vertex_algo_page.html";
558   else if ( aHypType == "QuadrangleParams")
559     aHelpFileName = "a2d_meshing_hypo_page.html#hypo_quad_params_anchor";
560   return aHelpFileName;
561 }
562
563
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 {
701 }
702
703 HypothesesSet::HypothesesSet( const QString&     theSetName,
704                               const QStringList& theHypoList,
705                               const QStringList& theAlgoList )
706   : myHypoSetName( theSetName ),
707     myHypoList( theHypoList ),
708     myAlgoList( theAlgoList ),
709     myIsAlgo( false )
710 {
711 }
712
713 QStringList* HypothesesSet::list(bool is_algo) const
714 {
715   return const_cast<QStringList*>( &( is_algo ? myAlgoList : myHypoList ) );
716 }
717
718 QStringList* HypothesesSet::list() const
719 {
720   return list( myIsAlgo );
721 }
722
723 QString HypothesesSet::name() const
724 {
725   return myHypoSetName;
726 }
727
728 void HypothesesSet::set( bool isAlgo, const QStringList& lst )
729 {
730   *list(isAlgo) = lst;
731 }
732
733 int HypothesesSet::count( bool isAlgo ) const
734 {
735   return list(isAlgo)->count();
736 }
737
738 bool HypothesesSet::isAlgo() const
739 {
740   return myIsAlgo;
741 }
742
743 void HypothesesSet::init( bool isAlgo )
744 {
745   myIsAlgo = isAlgo;
746   myIndex = -1;
747 }
748
749 bool HypothesesSet::more() const
750 {
751   return myIndex < list()->count();
752 }
753
754 void HypothesesSet::next()
755 {
756   myIndex++;
757 }
758
759 QString HypothesesSet::current() const
760 {
761   return list()->at(myIndex);
762 }