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