Salome HOME
Fix for bug IPAL19890(Qt4 porting. Default Presicion = 0. Mesh Algorithm Wire Discret...
[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   // check if object reference parameter is set, as it has no default value
344   bool ok = true;
345   if ( hypType().startsWith("ProjectionSource" ))
346   {
347     StdMeshersGUI_ObjectReferenceParamWdg* w =
348       widget< StdMeshersGUI_ObjectReferenceParamWdg >( 0 );
349     ok = ( w->IsObjectSelected() );
350     if ( !ok ) w->SetObject( CORBA::Object::_nil() );
351     int nbAssocVert = ( hypType() == "ProjectionSource1D" ? 1 : 2 );
352     for ( int i = 0; ok && i < nbAssocVert; i += 2)
353     {
354       QString srcV, tgtV;
355       StdMeshersGUI_ObjectReferenceParamWdg* w1 =
356         widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+2 );
357       StdMeshersGUI_ObjectReferenceParamWdg* w2 =
358         widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+3 );
359       srcV = w1->GetValue();
360       tgtV = w2->GetValue();
361       ok = (( srcV.isEmpty()  && tgtV.isEmpty() ) ||
362             ( !srcV.isEmpty() && !tgtV.isEmpty() && srcV != tgtV ));
363       if ( !ok ) {
364         w1->SetObject( CORBA::Object::_nil() );
365         w2->SetObject( CORBA::Object::_nil() );
366       }
367     }
368
369     // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
370     if ( ok )
371       deactivateObjRefParamWdg( customWidgets() );
372   }
373   else if ( hypType() == "LayerDistribution" )
374   {
375     StdMeshersGUI_LayerDistributionParamWdg* w = 
376       widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
377     ok = ( w && w->IsOk() );
378   }
379   return ok;
380 }
381
382 //================================================================================
383 /*!
384  * \brief Store params from GUI controls to a hypothesis
385   * \retval QString - text representation of parameters
386  */
387 //================================================================================
388
389 QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
390 {
391   ListOfStdParams params;
392   bool res = getStdParamFromDlg( params );
393   if( isCreation() )
394   {
395     SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().toLatin1().data() );
396     params.erase( params.begin() );
397   }
398
399   QString valueStr = stdParamValues( params );
400
401   if( res && !params.isEmpty() )
402   {
403     if( hypType()=="LocalLength" )
404     {
405       StdMeshers::StdMeshers_LocalLength_var h =
406         StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
407
408       h->SetLength( params[0].myValue.toDouble() );
409       h->SetPrecision( params[1].myValue.toDouble() );
410     }
411     else if( hypType()=="SegmentLengthAroundVertex" )
412     {
413       StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
414         StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hypothesis() );
415
416       h->SetLength( params[0].myValue.toDouble() );
417     }
418     else if( hypType()=="Arithmetic1D" )
419     {
420       StdMeshers::StdMeshers_Arithmetic1D_var h =
421         StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
422
423       h->SetLength( params[0].myValue.toDouble(), true );
424       h->SetLength( params[1].myValue.toDouble(), false );
425     }
426     else if( hypType()=="MaxElementArea" )
427     {
428       StdMeshers::StdMeshers_MaxElementArea_var h =
429         StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
430
431       h->SetMaxElementArea( params[0].myValue.toDouble() );
432     }
433     else if( hypType()=="MaxElementVolume" )
434     {
435       StdMeshers::StdMeshers_MaxElementVolume_var h =
436         StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
437
438       h->SetMaxElementVolume( params[0].myValue.toDouble() );
439     }
440     else if( hypType()=="StartEndLength" )
441     {
442       StdMeshers::StdMeshers_StartEndLength_var h =
443         StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
444
445       h->SetLength( params[0].myValue.toDouble(), true );
446       h->SetLength( params[1].myValue.toDouble(), false );
447     }
448     else if( hypType()=="Deflection1D" )
449     {
450       StdMeshers::StdMeshers_Deflection1D_var h =
451         StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
452
453       h->SetDeflection( params[0].myValue.toDouble() );
454     }
455     else if( hypType()=="AutomaticLength" )
456     {
457       StdMeshers::StdMeshers_AutomaticLength_var h =
458         StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() );
459
460       h->SetFineness( params[0].myValue.toDouble() );
461     }
462     else if( hypType()=="NumberOfLayers" )
463     {
464       StdMeshers::StdMeshers_NumberOfLayers_var h =
465         StdMeshers::StdMeshers_NumberOfLayers::_narrow( hypothesis() );
466
467       h->SetNumberOfLayers( params[0].myValue.toInt() );
468     }
469     else if( hypType()=="LayerDistribution" )
470     {
471       StdMeshers::StdMeshers_LayerDistribution_var h =
472         StdMeshers::StdMeshers_LayerDistribution::_narrow( hypothesis() );
473       StdMeshersGUI_LayerDistributionParamWdg* w = 
474         widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
475
476       h->SetLayerDistribution( w->GetHypothesis() );
477     }
478     else if( hypType()=="ProjectionSource1D" )
479     {
480       StdMeshers::StdMeshers_ProjectionSource1D_var h =
481         StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hypothesis() );
482
483       h->SetSourceEdge       ( geomFromWdg ( getWidgetForParam( 0 )));
484       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
485       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )),
486                                geomFromWdg ( getWidgetForParam( 3 )));
487     }
488     else if( hypType()=="ProjectionSource2D" )
489     {
490       StdMeshers::StdMeshers_ProjectionSource2D_var h =
491         StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hypothesis() );
492
493       h->SetSourceFace       ( geomFromWdg ( getWidgetForParam( 0 )));
494       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
495       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
496                                geomFromWdg ( getWidgetForParam( 4 )), // src2
497                                geomFromWdg ( getWidgetForParam( 3 )), // tgt1
498                                geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
499     }
500     else if( hypType()=="ProjectionSource3D" )
501     {
502       StdMeshers::StdMeshers_ProjectionSource3D_var h =
503         StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hypothesis() );
504
505       h->SetSource3DShape    ( geomFromWdg ( getWidgetForParam( 0 )));
506       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
507       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
508                                geomFromWdg ( getWidgetForParam( 4 )), // src2
509                                geomFromWdg ( getWidgetForParam( 3 )), // tgt1
510                                geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
511     }
512   }
513   return valueStr;
514 }
515
516 //================================================================================
517 /*!
518  * \brief Return parameter values as SMESHGUI_GenericHypothesisCreator::StdParam
519   * \param p - list of parameters
520   * \retval bool - success flag
521   *
522   * Is called from SMESHGUI_GenericHypothesisCreator::buildStdFrame().
523   * Parameters will be shown using "standard" controls:
524   *   Int by QtxIntSpinBox
525   *   Double by SMESHGUI_SpinBox
526   *   String by QLineEdit
527   * getCustomWidget() allows to redefine control for a parameter
528  */
529 //================================================================================
530
531 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
532 {
533   bool res = true;
534   SMESHGUI_GenericHypothesisCreator::StdParam item;
535
536   p.clear();
537   customWidgets()->clear();
538   if( isCreation() )
539   {
540     HypothesisData* data = SMESH::GetHypothesisData( hypType() );
541     item.myName = tr( "SMESH_NAME" );
542     item.myValue = data ? hypName() : QString();
543     p.append( item );
544     customWidgets()->append(0);
545   }
546
547   SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
548
549   if( hypType()=="LocalLength" )
550   {
551     StdMeshers::StdMeshers_LocalLength_var h =
552       StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
553
554     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
555     item.myValue = h->GetLength();
556     p.append( item );
557     item.myName = tr("SMESH_LOCAL_LENGTH_PRECISION");
558     item.myValue = h->GetPrecision();
559     p.append( item );
560   }
561   else if( hypType()=="SegmentLengthAroundVertex" )
562   {
563     StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
564       StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hyp );
565
566     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
567     item.myValue = h->GetLength();
568     p.append( item );
569   }
570   else if( hypType()=="Arithmetic1D" )
571   {
572     StdMeshers::StdMeshers_Arithmetic1D_var h =
573       StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
574
575     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
576     item.myValue = h->GetLength( true );
577     p.append( item );
578     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
579     item.myValue = h->GetLength( false );
580     p.append( item );
581   }
582   else if( hypType()=="MaxElementArea" )
583   {
584     StdMeshers::StdMeshers_MaxElementArea_var h =
585       StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
586
587     item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
588     item.myValue = h->GetMaxElementArea();
589     p.append( item );
590   }
591   else if( hypType()=="MaxElementVolume" )
592   {
593     StdMeshers::StdMeshers_MaxElementVolume_var h =
594       StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
595
596     item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
597     item.myValue = h->GetMaxElementVolume();
598     p.append( item );
599   }
600   else if( hypType()=="StartEndLength" )
601   {
602     StdMeshers::StdMeshers_StartEndLength_var h =
603       StdMeshers::StdMeshers_StartEndLength::_narrow( hyp );
604
605     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
606     item.myValue = h->GetLength( true );
607     p.append( item );
608     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
609     item.myValue = h->GetLength( false );
610     p.append( item );
611   }
612   else if( hypType()=="Deflection1D" )
613   {
614     StdMeshers::StdMeshers_Deflection1D_var h =
615       StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
616
617     item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
618     item.myValue = h->GetDeflection();
619     p.append( item );
620   }
621   else if( hypType()=="AutomaticLength" )
622   {
623     StdMeshers::StdMeshers_AutomaticLength_var h =
624       StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
625
626     item.myName = tr( "SMESH_FINENESS_PARAM" );
627     //item.myValue = h->GetFineness();
628     p.append( item );
629     customWidgets()->append
630       ( new TDoubleSliderWith2Lables( "0 ", " 1", h->GetFineness(), 0, 1, 0.01, 0 ));
631   }
632   else if( hypType()=="NumberOfLayers" )
633   {
634     StdMeshers::StdMeshers_NumberOfLayers_var h =
635       StdMeshers::StdMeshers_NumberOfLayers::_narrow( hyp );
636
637     item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
638     item.myValue = (int) h->GetNumberOfLayers();
639     p.append( item );
640   }
641   else if( hypType()=="LayerDistribution" )
642   {
643     StdMeshers::StdMeshers_LayerDistribution_var h =
644       StdMeshers::StdMeshers_LayerDistribution::_narrow( hyp );
645
646     item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
647     customWidgets()->append
648       ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
649   }
650   else if( hypType()=="ProjectionSource1D" )
651   {
652     StdMeshers::StdMeshers_ProjectionSource1D_var h =
653       StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hyp );
654
655     item.myName = tr( "SMESH_SOURCE_EDGE" ); p.append( item );
656     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 1 ),
657                                                h->GetSourceEdge()));
658     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
659     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
660                                                h->GetSourceMesh()));
661     item.myName = tr( "SMESH_SOURCE_VERTEX" ); p.append( item );
662     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
663                                                h->GetSourceVertex()));
664     item.myName = tr( "SMESH_TARGET_VERTEX" ); p.append( item );
665     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
666                                                h->GetTargetVertex()));
667   }
668   else if( hypType()=="ProjectionSource2D" )
669   {
670     StdMeshers::StdMeshers_ProjectionSource2D_var h =
671       StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hyp );
672
673     item.myName = tr( "SMESH_SOURCE_FACE" ); p.append( item );
674     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 2 ),
675                                                h->GetSourceFace()));
676     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
677     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
678                                                h->GetSourceMesh()));
679     item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
680     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
681                                                h->GetSourceVertex( 1 )));
682     item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
683     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
684                                                h->GetTargetVertex( 1 )));
685     item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
686     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
687                                                h->GetSourceVertex( 2 )));
688     item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
689     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
690                                                h->GetTargetVertex( 2 )));
691   }
692   else if( hypType()=="ProjectionSource3D" )
693   {
694     StdMeshers::StdMeshers_ProjectionSource3D_var h =
695       StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hyp );
696
697     item.myName = tr( "SMESH_SOURCE_3DSHAPE" ); p.append( item );
698     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 3, TopAbs_FACE, 6, true ),
699                                                h->GetSource3DShape()));
700     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
701     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
702                                                h->GetSourceMesh()));
703     item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
704     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
705                                                h->GetSourceVertex( 1 )));
706     item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
707     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
708                                                h->GetTargetVertex( 1 )));
709     item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
710     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
711                                                h->GetSourceVertex( 2 )));
712     item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
713     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
714                                                h->GetTargetVertex( 2 )));
715   }
716   else
717     res = false;
718   return res;
719 }
720
721 //================================================================================
722 /*!
723  * \brief tune "standard" control
724   * \param w - control widget
725   * \param int - parameter index
726  */
727 //================================================================================
728
729 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget (QWidget* w, const int) const
730 {
731   SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
732   if( hypType()=="LocalLength" &&  sb )
733   {
734     if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PARAM"))
735       sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
736     else if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PRECISION"))
737       sb->RangeStepAndValidator( 0.0, 1.0, 0.05, 7 );
738   }
739   else if( hypType()=="Arithmetic1D" && sb )
740   {
741     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
742   }
743   else if( hypType()=="MaxElementArea" && sb )
744   {
745     sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6 );
746   }
747   else if( hypType()=="MaxElementVolume" && sb )
748   {
749     sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6 );
750   }
751   else if( hypType()=="StartEndLength" && sb )
752   {
753     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
754   }
755   else if( hypType()=="Deflection1D" && sb )
756   {
757     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
758   }
759   else if ( sb ) // default validator for possible ancestors
760   {
761     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
762   }
763 }
764
765 //================================================================================
766 /*!
767  * \brief Return dlg title
768   * \retval QString - title string
769  */
770 //================================================================================
771
772 QString StdMeshersGUI_StdHypothesisCreator::caption() const
773 {
774   return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
775 }
776
777 //================================================================================
778 /*!
779  * \brief return pixmap for dlg icon
780   * \retval QPixmap - 
781  */
782 //================================================================================
783
784 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
785 {
786   QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
787   return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
788 }
789
790 //================================================================================
791 /*!
792  * \brief Return hypothesis type name to show in dlg
793   * \retval QString - 
794  */
795 //================================================================================
796
797 QString StdMeshersGUI_StdHypothesisCreator::type() const
798 {
799   return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
800 }
801
802 //================================================================================
803 /*!
804  * \brief String to insert in "SMESH_%1_HYPOTHESIS" to get hypothesis type name
805  * from message resouce file
806   * \param t - hypothesis type
807   * \retval QString - result string
808  */
809 //================================================================================
810
811 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
812 {
813   static QMap<QString,QString>  types;
814   if( types.isEmpty() )
815   {
816     types.insert( "LocalLength", "LOCAL_LENGTH" );
817     types.insert( "NumberOfSegments", "NB_SEGMENTS" );
818     types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
819     types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
820     types.insert( "StartEndLength", "START_END_LENGTH" );
821     types.insert( "Deflection1D", "DEFLECTION1D" );
822     types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
823     types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
824     types.insert( "ProjectionSource1D", "PROJECTION_SOURCE_1D" );
825     types.insert( "ProjectionSource2D", "PROJECTION_SOURCE_2D" );
826     types.insert( "ProjectionSource3D", "PROJECTION_SOURCE_3D" );
827     types.insert( "NumberOfLayers", "NUMBER_OF_LAYERS" );
828     types.insert( "LayerDistribution", "LAYER_DISTRIBUTION" );
829     types.insert( "SegmentLengthAroundVertex", "SEGMENT_LENGTH_AROUND_VERTEX" );
830   }
831
832   QString res;
833   if( types.contains( t ) )
834     res = types[ t ];
835
836   return res;
837 }
838
839
840 //=======================================================================
841 //function : getCustomWidget
842 //purpose  : is called from buildStdFrame()
843 //=======================================================================
844
845 QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
846                                                               QWidget*         parent,
847                                                               const int        index) const
848 {
849   QWidget* w = 0;
850   if ( index < customWidgets()->count() ) {
851     w = customWidgets()->at( index );
852     if ( w ) {
853       w->setParent( parent );
854       w->move( QPoint( 0, 0 ) );
855     }
856   }
857   return w;
858 }
859
860 //================================================================================
861 /*!
862  * \brief Set param value taken from a custom widget
863   * \param param - SMESHGUI_GenericHypothesisCreator::StdParam structure
864   * \param widget - widget presenting param
865   * \retval bool - success flag
866  * 
867  * this method is called from getStdParamFromDlg()
868  */
869 //================================================================================
870
871 bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
872                                                                    QWidget*   widget) const
873 {
874   if ( hypType()=="AutomaticLength" ) {
875     TDoubleSliderWith2Lables* w = dynamic_cast<TDoubleSliderWith2Lables*>( widget );
876     if ( w ) {
877       param.myValue = w->value();
878       return true;
879     }
880   }
881   if ( widget->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
882   {
883     // show only 1st reference value
884     if ( true /*widget == getWidgetForParam( 0 )*/) {
885       const StdMeshersGUI_ObjectReferenceParamWdg * w =
886         static_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( widget );
887       param.myValue = w->GetValue();
888     }
889     return true;
890   }
891   if ( widget->inherits( "StdMeshersGUI_LayerDistributionParamWdg" ))
892   {
893     const StdMeshersGUI_LayerDistributionParamWdg * w =
894       static_cast<const StdMeshersGUI_LayerDistributionParamWdg*>( widget );
895     param.myValue = w->GetValue();
896     return true;
897   }
898   return false;
899 }
900
901 //================================================================================
902 /*!
903  * \brief called when operation cancelled
904  */
905 //================================================================================
906
907 void StdMeshersGUI_StdHypothesisCreator::onReject()
908 {
909   if ( hypType().startsWith("ProjectionSource" ))
910   {
911     // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
912     deactivateObjRefParamWdg( customWidgets() );
913   }
914 }