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