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