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