Salome HOME
Implementation NoteBook in SMESH module.
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_StdHypothesisCreator.cxx
1 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 //
4 // This library is free software; you can redistribute it and/or 
5 // modify it under the terms of the GNU Lesser General Public 
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License. 
8 //
9 // This library is distributed in the hope that it will be useful, 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details. 
13 //
14 // You should have received a copy of the GNU Lesser General Public 
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 // File   : StdMeshersGUI_StdHypothesisCreator.cxx
21 // Author : Alexander SOLOVYOV, Open CASCADE S.A.S.
22 //
23
24 // SMESH includes
25 #include "StdMeshersGUI_StdHypothesisCreator.h"
26
27 #include <SMESHGUI.h>
28 #include <SMESHGUI_SpinBox.h>
29 #include <SMESHGUI_HypothesesUtils.h>
30 #include <SMESHGUI_Utils.h>
31 #include <SMESH_TypeFilter.hxx>
32 #include <SMESH_NumberFilter.hxx>
33 #include <StdMeshersGUI_ObjectReferenceParamWdg.h>
34 #include <StdMeshersGUI_LayerDistributionParamWdg.h>
35 #include <SALOMEDSClient_Study.hxx>
36
37 // SALOME GUI includes
38 #include <SUIT_ResourceMgr.h>
39
40 // IDL includes
41 #include <SALOMEconfig.h>
42 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
43 #include CORBA_SERVER_HEADER(SMESH_Mesh)
44
45 // Qt includes
46 #include <QHBoxLayout>
47 #include <QSlider>
48 #include <QLabel>
49
50 const double VALUE_MAX = 1.0e+15, // COORD_MAX
51              VALUE_MAX_2  = VALUE_MAX * VALUE_MAX,
52              VALUE_MAX_3  = VALUE_MAX_2 * VALUE_MAX,
53              VALUE_SMALL = 1.0e-15,
54              VALUE_SMALL_2 = VALUE_SMALL * VALUE_SMALL,
55              VALUE_SMALL_3 = VALUE_SMALL_2 * VALUE_SMALL;
56
57 //================================================================================
58 /*!
59  * \brief Constructor
60   * \param type - hypothesis type
61  */
62 //================================================================================
63
64 StdMeshersGUI_StdHypothesisCreator::StdMeshersGUI_StdHypothesisCreator( const QString& type )
65 : SMESHGUI_GenericHypothesisCreator( type )
66 {
67 }
68
69 //================================================================================
70 /*!
71  * \brief Destructor
72  */
73 //================================================================================
74
75 StdMeshersGUI_StdHypothesisCreator::~StdMeshersGUI_StdHypothesisCreator()
76 {
77 }
78
79 //================================================================================
80 /*!
81  * \brief Return widget for i-th hypothesis parameter (got from myParamWidgets)
82   * \param i - index of hypothesis parameter
83   * \retval QWidget* - found widget
84  */
85 //================================================================================
86
87 QWidget* StdMeshersGUI_StdHypothesisCreator::getWidgetForParam( int i ) const
88 {
89   QWidget* w = 0;
90   if ( isCreation() ) ++i; // skip widget of 'name' parameter
91
92   if ( i < myCustomWidgets.count() ) {
93     QList<QWidget*>::const_iterator anIt  = myCustomWidgets.begin();
94     QList<QWidget*>::const_iterator aLast = myCustomWidgets.end();
95     for ( int j = 0 ; !w && anIt != aLast; ++anIt )
96       if ( i == j )
97         w = *anIt;
98   }
99   if ( !w ) {
100     // list has no at() const, so we iterate
101     QList<QWidget*>::const_iterator anIt  = widgets().begin();
102     QList<QWidget*>::const_iterator aLast = widgets().end();
103     for( int j = 0; !w && anIt!=aLast; anIt++, ++j ) {
104       if ( i == j )
105         w = *anIt;
106     }
107   }
108   return w;
109 }
110
111 //================================================================================
112 /*!
113  * \brief Allow modifing myCustomWidgets in const methods
114   * \retval ListOfWidgets* - non-const pointer to myCustomWidgets
115  */
116 //================================================================================
117
118 StdMeshersGUI_StdHypothesisCreator::ListOfWidgets*
119 StdMeshersGUI_StdHypothesisCreator::customWidgets() const
120 {
121   return const_cast< ListOfWidgets* >( & myCustomWidgets );
122 }
123
124 //================================================================================
125 /*!
126  * \brief Builds dlg layout
127   * \retval QFrame* - the built widget
128  */
129 //================================================================================
130
131 QFrame* StdMeshersGUI_StdHypothesisCreator::buildFrame()
132 {
133   return buildStdFrame();
134 }
135
136 //================================================================================
137 /*!
138  * \brief Initialise parameter values in controls
139  */
140 //================================================================================
141
142 void StdMeshersGUI_StdHypothesisCreator::retrieveParams() const
143 {
144   // buildStdFrame() sets values itself calling stdParams()
145
146   if ( hypType().startsWith("ProjectionSource" ))
147   {
148     // we use this method to connect depending custom widgets
149     StdMeshersGUI_ObjectReferenceParamWdg* widgetToActivate = 0;
150     ListOfWidgets::const_iterator anIt = myCustomWidgets.begin();
151     for ( ; anIt != myCustomWidgets.end(); anIt++)
152     {
153       if ( *anIt && (*anIt)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
154       {
155         StdMeshersGUI_ObjectReferenceParamWdg * w1 =
156           ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
157         ListOfWidgets::const_iterator anIt2 = anIt;
158         for ( ++anIt2; anIt2 != myCustomWidgets.end(); anIt2++)
159           if ( *anIt2 && (*anIt2)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
160           {
161             StdMeshersGUI_ObjectReferenceParamWdg * w2 =
162               ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt2 );
163             w1->AvoidSimultaneousSelection( w2 );
164           }
165         if ( !widgetToActivate )
166           widgetToActivate = w1;
167       }
168     }
169     if ( widgetToActivate )
170       widgetToActivate->activateSelection();
171   }
172
173   if ( dlg() )
174     dlg()->setMinimumSize( dlg()->minimumSizeHint().width(), dlg()->minimumSizeHint().height() );
175 }
176
177 namespace {
178
179   //================================================================================
180   /*!
181    * \brief Widget: slider with left and right labels
182    */
183   //================================================================================
184
185   class TDoubleSliderWith2Lables: public QWidget
186   {
187   public:
188     TDoubleSliderWith2Lables( const QString& leftLabel, const QString& rightLabel,
189                               const double   initValue, const double   bottom,
190                               const double   top      , const double   precision,
191                               QWidget *      parent=0 , const char *   name=0 )
192       :QWidget(parent), _bottom(bottom), _precision(precision)
193     {
194       setObjectName(name);
195
196       QHBoxLayout* aHBoxL = new QHBoxLayout(this);
197       
198       if ( !leftLabel.isEmpty() ) {
199         QLabel* aLeftLabel = new QLabel( this );
200         aLeftLabel->setText( leftLabel );
201         aHBoxL->addWidget( aLeftLabel );
202       }
203
204       _slider = new QSlider( Qt::Horizontal, this );
205       _slider->setRange( 0, toInt( top ));
206       _slider->setValue( toInt( initValue ));
207       aHBoxL->addWidget( _slider );
208
209       if ( !rightLabel.isEmpty() ) {
210         QLabel* aRightLabel = new QLabel( this );
211         aRightLabel->setText( rightLabel );
212         aHBoxL->addWidget( aRightLabel );
213       }
214
215       setLayout( aHBoxL );
216     }
217     double value() const { return _bottom + _slider->value() * _precision; }
218     QSlider * getSlider() const { return _slider; }
219     int toInt( double val ) const { return (int) ceil(( val - _bottom ) / _precision ); }
220   private:
221     double _bottom, _precision;
222     QSlider * _slider;
223   };
224
225   //================================================================================
226   /*!
227    * \brief Retrieve GEOM_Object held by widget
228    */
229   //================================================================================
230
231   inline GEOM::GEOM_Object_var geomFromWdg(const QWidget* wdg)
232   {
233     const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
234       dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
235     if ( objRefWdg )
236       return objRefWdg->GetObject< GEOM::GEOM_Object >();
237
238     return GEOM::GEOM_Object::_nil();
239   }
240   //================================================================================
241   /*!
242    * \brief Retrieve SMESH_Mesh held by widget
243    */
244   //================================================================================
245
246   inline SMESH::SMESH_Mesh_var meshFromWdg(const QWidget* wdg)
247   {
248     const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
249       dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
250     if ( objRefWdg )
251       return objRefWdg->GetObject< SMESH::SMESH_Mesh >();
252
253     return SMESH::SMESH_Mesh::_nil();
254   }
255   //================================================================================
256   /*!
257    * \brief creates a filter for selection of shapes of given dimension
258     * \param dim - dimension
259     * \param subShapeType - required type of subshapes, number of which must be \a nbSubShapes
260     * \param nbSubShapes - number of subshapes of given type
261     * \param closed - required closeness flag of a shape
262     * \retval SUIT_SelectionFilter* - created filter
263    */
264   //================================================================================
265
266   SUIT_SelectionFilter* filterForShapeOfDim(const int        dim,
267                                             TopAbs_ShapeEnum subShapeType = TopAbs_SHAPE,
268                                             const int        nbSubShapes = 0,
269                                             bool             closed = false)
270   {
271     TColStd_MapOfInteger shapeTypes;
272     switch ( dim ) {
273     case 0: shapeTypes.Add( TopAbs_VERTEX ); break;
274     case 1:
275       if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_EDGE;
276       shapeTypes.Add( TopAbs_EDGE );
277       shapeTypes.Add( TopAbs_COMPOUND ); // for a group
278       break;
279     case 2:
280       if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_FACE;
281       shapeTypes.Add( TopAbs_FACE );
282       shapeTypes.Add( TopAbs_COMPOUND ); // for a group
283       break;
284     case 3:
285       shapeTypes.Add( TopAbs_SHELL );
286       shapeTypes.Add( TopAbs_SOLID );
287       shapeTypes.Add( TopAbs_COMPSOLID );
288       shapeTypes.Add( TopAbs_COMPOUND );
289       break;
290     }
291     return new SMESH_NumberFilter("GEOM", subShapeType, nbSubShapes,
292                                   shapeTypes, GEOM::GEOM_Object::_nil(), closed);
293   }
294
295   //================================================================================
296   /*!
297    * \brief Create a widget for object selection
298     * \param object - initial object
299     * \param filter - selection filter
300     * \retval QWidget* - created widget
301    */
302   //================================================================================
303
304   QWidget* newObjRefParamWdg( SUIT_SelectionFilter* filter,
305                               CORBA::Object_var     object)
306   {
307     StdMeshersGUI_ObjectReferenceParamWdg* w =
308       new StdMeshersGUI_ObjectReferenceParamWdg( filter, 0);
309     w->SetObject( object.in() );
310     return w;
311   }
312
313   //================================================================================
314   /*!
315    * \brief calls deactivateSelection() for StdMeshersGUI_ObjectReferenceParamWdg
316     * \param widgetList - list of widgets
317    */
318   //================================================================================
319
320   void deactivateObjRefParamWdg( QList<QWidget*>* widgetList )
321   {
322     StdMeshersGUI_ObjectReferenceParamWdg* w = 0;
323     QList<QWidget*>::iterator anIt  = widgetList->begin();
324     QList<QWidget*>::iterator aLast = widgetList->end();
325     for ( ; anIt != aLast; anIt++ ) {
326       if ( (*anIt) && (*anIt)->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
327       {
328         w = (StdMeshersGUI_ObjectReferenceParamWdg* )( *anIt );
329         w->deactivateSelection();
330       }
331     }
332   }
333 }
334
335 //================================================================================
336 /*!
337  * \brief Check parameter values before accept()
338   * \retval bool - true if OK
339  */
340 //================================================================================
341
342 bool StdMeshersGUI_StdHypothesisCreator::checkParams( QString& msg ) const
343 {
344   if( !SMESHGUI_GenericHypothesisCreator::checkParams( msg ) )
345     return false;
346
347   // check if object reference parameter is set, as it has no default value
348   bool ok = true;
349   if ( hypType().startsWith("ProjectionSource" ))
350   {
351     StdMeshersGUI_ObjectReferenceParamWdg* w =
352       widget< StdMeshersGUI_ObjectReferenceParamWdg >( 0 );
353     ok = ( w->IsObjectSelected() );
354     if ( !ok ) w->SetObject( CORBA::Object::_nil() );
355     int nbAssocVert = ( hypType() == "ProjectionSource1D" ? 1 : 2 );
356     for ( int i = 0; ok && i < nbAssocVert; i += 2)
357     {
358       QString srcV, tgtV;
359       StdMeshersGUI_ObjectReferenceParamWdg* w1 =
360         widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+2 );
361       StdMeshersGUI_ObjectReferenceParamWdg* w2 =
362         widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+3 );
363       srcV = w1->GetValue();
364       tgtV = w2->GetValue();
365       ok = (( srcV.isEmpty()  && tgtV.isEmpty() ) ||
366             ( !srcV.isEmpty() && !tgtV.isEmpty() && srcV != tgtV ));
367       if ( !ok ) {
368         w1->SetObject( CORBA::Object::_nil() );
369         w2->SetObject( CORBA::Object::_nil() );
370       }
371     }
372
373     // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
374     if ( ok )
375       deactivateObjRefParamWdg( customWidgets() );
376   }
377   else if ( hypType() == "LayerDistribution" )
378   {
379     StdMeshersGUI_LayerDistributionParamWdg* w = 
380       widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
381     ok = ( w && w->IsOk() );
382   }
383   return ok;
384 }
385
386 //================================================================================
387 /*!
388  * \brief Store params from GUI controls to a hypothesis
389   * \retval QString - text representation of parameters
390  */
391 //================================================================================
392
393 QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
394 {
395   ListOfStdParams params;
396   bool res = getStdParamFromDlg( params );
397   if( isCreation() )
398   {
399     SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().toLatin1().data() );
400     params.erase( params.begin() );
401   }
402
403   QString valueStr = stdParamValues( params );
404   QStringList aVariablesList = getVariablesFromDlg();
405
406   if( res && !params.isEmpty() )
407   {
408     if( hypType()=="LocalLength" )
409     {
410       StdMeshers::StdMeshers_LocalLength_var h =
411         StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
412
413       h->SetLength( params[0].myValue.toDouble() );
414       h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
415       h->SetPrecision( params[1].myValue.toDouble() );
416       h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
417     }
418     else if( hypType()=="SegmentLengthAroundVertex" )
419     {
420       StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
421         StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hypothesis() );
422
423       h->SetLength( params[0].myValue.toDouble() );
424       h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
425     }
426     else if( hypType()=="Arithmetic1D" )
427     {
428       StdMeshers::StdMeshers_Arithmetic1D_var h =
429         StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
430
431       h->SetLength( params[0].myValue.toDouble(), true );
432       h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
433       h->SetLength( params[1].myValue.toDouble(), false );
434       h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
435     }
436     else if( hypType()=="MaxElementArea" )
437     {
438       StdMeshers::StdMeshers_MaxElementArea_var h =
439         StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
440
441       h->SetMaxElementArea( params[0].myValue.toDouble() );
442     }
443     else if( hypType()=="MaxElementVolume" )
444     {
445       StdMeshers::StdMeshers_MaxElementVolume_var h =
446         StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
447
448       h->SetMaxElementVolume( params[0].myValue.toDouble() );
449     }
450     else if( hypType()=="StartEndLength" )
451     {
452       StdMeshers::StdMeshers_StartEndLength_var h =
453         StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
454
455       h->SetLength( params[0].myValue.toDouble(), true );
456       h->SetLength( params[1].myValue.toDouble(), false );
457     }
458     else if( hypType()=="Deflection1D" )
459     {
460       StdMeshers::StdMeshers_Deflection1D_var h =
461         StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
462
463       h->SetDeflection( params[0].myValue.toDouble() );
464     }
465     else if( hypType()=="AutomaticLength" )
466     {
467       StdMeshers::StdMeshers_AutomaticLength_var h =
468         StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() );
469
470       h->SetFineness( params[0].myValue.toDouble() );
471     }
472     else if( hypType()=="NumberOfLayers" )
473     {
474       StdMeshers::StdMeshers_NumberOfLayers_var h =
475         StdMeshers::StdMeshers_NumberOfLayers::_narrow( hypothesis() );
476
477       h->SetNumberOfLayers( params[0].myValue.toInt() );
478     }
479     else if( hypType()=="LayerDistribution" )
480     {
481       StdMeshers::StdMeshers_LayerDistribution_var h =
482         StdMeshers::StdMeshers_LayerDistribution::_narrow( hypothesis() );
483       StdMeshersGUI_LayerDistributionParamWdg* w = 
484         widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
485       
486       h->SetLayerDistribution( w->GetHypothesis() );
487       /*      h->SetParameters(w->GetHypothesis()->GetParameters());
488       if(QString(w->GetHypothesis()->GetName()) == "LocalLength")
489         h->SetParameters(w->GetHypothesis()->GetParameters());
490       */
491     }
492     else if( hypType()=="ProjectionSource1D" )
493     {
494       StdMeshers::StdMeshers_ProjectionSource1D_var h =
495         StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hypothesis() );
496
497       h->SetSourceEdge       ( geomFromWdg ( getWidgetForParam( 0 )));
498       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
499       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )),
500                                geomFromWdg ( getWidgetForParam( 3 )));
501     }
502     else if( hypType()=="ProjectionSource2D" )
503     {
504       StdMeshers::StdMeshers_ProjectionSource2D_var h =
505         StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hypothesis() );
506
507       h->SetSourceFace       ( geomFromWdg ( getWidgetForParam( 0 )));
508       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
509       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
510                                geomFromWdg ( getWidgetForParam( 4 )), // src2
511                                geomFromWdg ( getWidgetForParam( 3 )), // tgt1
512                                geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
513     }
514     else if( hypType()=="ProjectionSource3D" )
515     {
516       StdMeshers::StdMeshers_ProjectionSource3D_var h =
517         StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hypothesis() );
518
519       h->SetSource3DShape    ( geomFromWdg ( getWidgetForParam( 0 )));
520       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
521       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
522                                geomFromWdg ( getWidgetForParam( 4 )), // src2
523                                geomFromWdg ( getWidgetForParam( 3 )), // tgt1
524                                geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
525     }
526   }
527   return valueStr;
528 }
529
530 //================================================================================
531 /*!
532  * \brief Return parameter values as SMESHGUI_GenericHypothesisCreator::StdParam
533   * \param p - list of parameters
534   * \retval bool - success flag
535   *
536   * Is called from SMESHGUI_GenericHypothesisCreator::buildStdFrame().
537   * Parameters will be shown using "standard" controls:
538   *   Int by QtxIntSpinBox
539   *   Double by SMESHGUI_SpinBox
540   *   String by QLineEdit
541   * getCustomWidget() allows to redefine control for a parameter
542  */
543 //================================================================================
544
545 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
546 {
547   bool res = true;
548   SMESHGUI_GenericHypothesisCreator::StdParam item;
549
550   p.clear();
551   customWidgets()->clear();
552   if( isCreation() )
553   {
554     HypothesisData* data = SMESH::GetHypothesisData( hypType() );
555     item.myName = tr( "SMESH_NAME" );
556     item.myValue = data ? hypName() : QString();
557     p.append( item );
558     customWidgets()->append(0);
559   }
560   
561   SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
562   SMESH::ListOfParameters_var aParameters = hyp->GetLastParameters();
563   QString aVaribaleName; 
564
565   if( hypType()=="LocalLength" )
566   {
567     StdMeshers::StdMeshers_LocalLength_var h =
568       StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
569     
570     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
571
572     aVaribaleName = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString("");
573     item.isVariable = !aVaribaleName.isEmpty();
574     if(item.isVariable) 
575       item.myValue = aVaribaleName;
576     else
577       item.myValue = h->GetLength();
578     p.append( item );
579      
580     item.myName = tr("SMESH_LOCAL_LENGTH_PRECISION");
581     aVaribaleName = (aParameters->length() > 1) ? QString(aParameters[1].in()) : QString("");
582     item.isVariable = !aVaribaleName.isEmpty();
583     if(item.isVariable)
584       item.myValue = aVaribaleName;
585     else
586       item.myValue = h->GetPrecision();
587     p.append( item );
588     
589   }
590   else if( hypType()=="SegmentLengthAroundVertex" )
591   {
592     StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
593       StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hyp );
594     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
595
596     aVaribaleName = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString("");    
597     item.isVariable = !aVaribaleName.isEmpty();
598
599     if(item.isVariable)
600       item.myValue = aVaribaleName;
601     else
602       item.myValue = h->GetLength();
603     p.append( item );
604   }
605   else if( hypType()=="Arithmetic1D" )
606   {
607     StdMeshers::StdMeshers_Arithmetic1D_var h =
608       StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
609
610     aVaribaleName = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString("");
611     
612     item.isVariable = !aVaribaleName.isEmpty();
613
614     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
615     if(item.isVariable)
616       item.myValue = aVaribaleName;
617     else
618       item.myValue = h->GetLength( true );
619     p.append( item );
620
621     aVaribaleName = (aParameters->length() > 1) ? QString(aParameters[1].in()) : QString("");
622
623     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
624
625     if(item.isVariable)
626       item.myValue = aVaribaleName;
627     else
628       item.myValue = h->GetLength( false );
629     p.append( item );
630   }
631   else if( hypType()=="MaxElementArea" )
632   {
633     StdMeshers::StdMeshers_MaxElementArea_var h =
634       StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
635
636     item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
637     item.myValue = h->GetMaxElementArea();
638     p.append( item );
639   }
640   else if( hypType()=="MaxElementVolume" )
641   {
642     StdMeshers::StdMeshers_MaxElementVolume_var h =
643       StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
644
645     item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
646     item.myValue = h->GetMaxElementVolume();
647     p.append( item );
648   }
649   else if( hypType()=="StartEndLength" )
650   {
651     StdMeshers::StdMeshers_StartEndLength_var h =
652       StdMeshers::StdMeshers_StartEndLength::_narrow( hyp );
653
654     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
655     item.myValue = h->GetLength( true );
656     p.append( item );
657     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
658     item.myValue = h->GetLength( false );
659     p.append( item );
660   }
661   else if( hypType()=="Deflection1D" )
662   {
663     StdMeshers::StdMeshers_Deflection1D_var h =
664       StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
665
666     item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
667     item.myValue = h->GetDeflection();
668     p.append( item );
669   }
670   else if( hypType()=="AutomaticLength" )
671   {
672     StdMeshers::StdMeshers_AutomaticLength_var h =
673       StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
674
675     item.myName = tr( "SMESH_FINENESS_PARAM" );
676     //item.myValue = h->GetFineness();
677     p.append( item );
678     customWidgets()->append
679       ( new TDoubleSliderWith2Lables( "0 ", " 1", h->GetFineness(), 0, 1, 0.01, 0 ));
680   }
681   else if( hypType()=="NumberOfLayers" )
682   {
683     StdMeshers::StdMeshers_NumberOfLayers_var h =
684       StdMeshers::StdMeshers_NumberOfLayers::_narrow( hyp );
685
686     item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
687     item.myValue = (int) h->GetNumberOfLayers();
688     p.append( item );
689   }
690   else if( hypType()=="LayerDistribution" )
691     {
692       StdMeshers::StdMeshers_LayerDistribution_var h =
693       StdMeshers::StdMeshers_LayerDistribution::_narrow( hyp );
694
695     item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
696     
697     //Set into not published hypo last variables
698     /*    QStringList aLastVarsList;
699     for(int i = 0;i<aParameters->length();i++) 
700       aLastVarsList.append(QString(aParameters[i].in()));
701
702     if(!aLastVarsList.isEmpty())
703       h->GetLayerDistribution()->SetParameters(SMESHGUI::JoinObjectParameters(aLastVarsList));
704     */    
705     customWidgets()->append
706       ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
707   }
708   else if( hypType()=="ProjectionSource1D" )
709   {
710     StdMeshers::StdMeshers_ProjectionSource1D_var h =
711       StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hyp );
712
713     item.myName = tr( "SMESH_SOURCE_EDGE" ); p.append( item );
714     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 1 ),
715                                                h->GetSourceEdge()));
716     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
717     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
718                                                h->GetSourceMesh()));
719     item.myName = tr( "SMESH_SOURCE_VERTEX" ); p.append( item );
720     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
721                                                h->GetSourceVertex()));
722     item.myName = tr( "SMESH_TARGET_VERTEX" ); p.append( item );
723     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
724                                                h->GetTargetVertex()));
725   }
726   else if( hypType()=="ProjectionSource2D" )
727   {
728     StdMeshers::StdMeshers_ProjectionSource2D_var h =
729       StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hyp );
730
731     item.myName = tr( "SMESH_SOURCE_FACE" ); p.append( item );
732     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 2 ),
733                                                h->GetSourceFace()));
734     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
735     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
736                                                h->GetSourceMesh()));
737     item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
738     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
739                                                h->GetSourceVertex( 1 )));
740     item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
741     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
742                                                h->GetTargetVertex( 1 )));
743     item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
744     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
745                                                h->GetSourceVertex( 2 )));
746     item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
747     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
748                                                h->GetTargetVertex( 2 )));
749   }
750   else if( hypType()=="ProjectionSource3D" )
751   {
752     StdMeshers::StdMeshers_ProjectionSource3D_var h =
753       StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hyp );
754
755     item.myName = tr( "SMESH_SOURCE_3DSHAPE" ); p.append( item );
756     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 3, TopAbs_FACE, 6, true ),
757                                                h->GetSource3DShape()));
758     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
759     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
760                                                h->GetSourceMesh()));
761     item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
762     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
763                                                h->GetSourceVertex( 1 )));
764     item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
765     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
766                                                h->GetTargetVertex( 1 )));
767     item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
768     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
769                                                h->GetSourceVertex( 2 )));
770     item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
771     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
772                                                h->GetTargetVertex( 2 )));
773   }
774   else
775     res = false;
776   return res;
777 }
778
779 //================================================================================
780 /*!
781  * \brief tune "standard" control
782   * \param w - control widget
783   * \param int - parameter index
784  */
785 //================================================================================
786
787 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget (QWidget* w, const int) const
788 {
789   SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
790   if( hypType()=="LocalLength" &&  sb )
791   {
792     if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PARAM"))
793       sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
794     else if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PRECISION"))
795       sb->RangeStepAndValidator( 0.0, 1.0, 0.05, 7 );
796   }
797   else if( hypType()=="Arithmetic1D" && sb )
798   {
799     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
800   }
801   else if( hypType()=="MaxElementArea" && sb )
802   {
803     sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6 );
804   }
805   else if( hypType()=="MaxElementVolume" && sb )
806   {
807     sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6 );
808   }
809   else if( hypType()=="StartEndLength" && sb )
810   {
811     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
812   }
813   else if( hypType()=="Deflection1D" && sb )
814   {
815     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
816   }
817   else if ( sb ) // default validator for possible ancestors
818   {
819     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
820   }
821 }
822
823 //================================================================================
824 /*!
825  * \brief Return dlg title
826   * \retval QString - title string
827  */
828 //================================================================================
829
830 QString StdMeshersGUI_StdHypothesisCreator::caption() const
831 {
832   return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
833 }
834
835 //================================================================================
836 /*!
837  * \brief return pixmap for dlg icon
838   * \retval QPixmap - 
839  */
840 //================================================================================
841
842 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
843 {
844   QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
845   return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
846 }
847
848 //================================================================================
849 /*!
850  * \brief Return hypothesis type name to show in dlg
851   * \retval QString - 
852  */
853 //================================================================================
854
855 QString StdMeshersGUI_StdHypothesisCreator::type() const
856 {
857   return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
858 }
859
860 //================================================================================
861 /*!
862  * \brief String to insert in "SMESH_%1_HYPOTHESIS" to get hypothesis type name
863  * from message resouce file
864   * \param t - hypothesis type
865   * \retval QString - result string
866  */
867 //================================================================================
868
869 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
870 {
871   static QMap<QString,QString>  types;
872   if( types.isEmpty() )
873   {
874     types.insert( "LocalLength", "LOCAL_LENGTH" );
875     types.insert( "NumberOfSegments", "NB_SEGMENTS" );
876     types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
877     types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
878     types.insert( "StartEndLength", "START_END_LENGTH" );
879     types.insert( "Deflection1D", "DEFLECTION1D" );
880     types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
881     types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
882     types.insert( "ProjectionSource1D", "PROJECTION_SOURCE_1D" );
883     types.insert( "ProjectionSource2D", "PROJECTION_SOURCE_2D" );
884     types.insert( "ProjectionSource3D", "PROJECTION_SOURCE_3D" );
885     types.insert( "NumberOfLayers", "NUMBER_OF_LAYERS" );
886     types.insert( "LayerDistribution", "LAYER_DISTRIBUTION" );
887     types.insert( "SegmentLengthAroundVertex", "SEGMENT_LENGTH_AROUND_VERTEX" );
888   }
889
890   QString res;
891   if( types.contains( t ) )
892     res = types[ t ];
893
894   return res;
895 }
896
897
898 //=======================================================================
899 //function : getCustomWidget
900 //purpose  : is called from buildStdFrame()
901 //=======================================================================
902
903 QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
904                                                               QWidget*         parent,
905                                                               const int        index) const
906 {
907   QWidget* w = 0;
908   if ( index < customWidgets()->count() ) {
909     w = customWidgets()->at( index );
910     if ( w ) {
911       w->setParent( parent );
912       w->move( QPoint( 0, 0 ) );
913     }
914   }
915   return w;
916 }
917
918 //================================================================================
919 /*!
920  * \brief Set param value taken from a custom widget
921   * \param param - SMESHGUI_GenericHypothesisCreator::StdParam structure
922   * \param widget - widget presenting param
923   * \retval bool - success flag
924  * 
925  * this method is called from getStdParamFromDlg()
926  */
927 //================================================================================
928
929 bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
930                                                                    QWidget*   widget) const
931 {
932   if ( hypType()=="AutomaticLength" ) {
933     TDoubleSliderWith2Lables* w = dynamic_cast<TDoubleSliderWith2Lables*>( widget );
934     if ( w ) {
935       param.myValue = w->value();
936       return true;
937     }
938   }
939   if ( widget->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
940   {
941     // show only 1st reference value
942     if ( true /*widget == getWidgetForParam( 0 )*/) {
943       const StdMeshersGUI_ObjectReferenceParamWdg * w =
944         static_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( widget );
945       param.myValue = w->GetValue();
946     }
947     return true;
948   }
949   if ( widget->inherits( "StdMeshersGUI_LayerDistributionParamWdg" ))
950   {
951     const StdMeshersGUI_LayerDistributionParamWdg * w =
952       static_cast<const StdMeshersGUI_LayerDistributionParamWdg*>( widget );
953     param.myValue = w->GetValue();
954     return true;
955   }
956   return false;
957 }
958
959 //================================================================================
960 /*!
961  * \brief called when operation cancelled
962  */
963 //================================================================================
964
965 void StdMeshersGUI_StdHypothesisCreator::onReject()
966 {
967   if ( hypType().startsWith("ProjectionSource" ))
968   {
969     // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
970     deactivateObjRefParamWdg( customWidgets() );
971   }
972 }
973
974 //================================================================================
975 /*!
976  * \brief
977  */
978 //================================================================================
979 /*QVariant StdMeshersGUI_StdHypothesisCreator::
980 parseParameter(const QStringList& theList, int theNbParam) const
981 {
982   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
983   QVariant aResult;
984   if(theList.size() > theNbParam) {
985     QString aParameter =  theList[theNbParam];
986     if(QString::compare(QString(""),aParameter) !=0 ) {
987       if(aStudy->IsVariable(aParameter.toLatin1().constData())) {
988         aResult=aParameter;
989       }
990       else {
991         bool aResult = false;
992         int anIResult = aParameter.toInt(&aResult);
993         if(aResult)
994           aResult = anIResult;
995         else {
996           double aDResult = aParameter.toDouble(&aResult);
997           if(aResult)
998             aResult = aDResult;
999         } 
1000       }
1001     }
1002   }
1003   return aResult;
1004 }
1005 */