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