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