Salome HOME
3e8d13ee2d34aced898364f3030df63b56c1a9b4
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_StdHypothesisCreator.cxx
1 //  Copyright (C) 2007-2010  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
33 #include <SMESH_TypeFilter.hxx>
34 #include <SMESH_NumberFilter.hxx>
35
36 #include "StdMeshersGUI_FixedPointsParamWdg.h"
37 #include "StdMeshersGUI_LayerDistributionParamWdg.h"
38 #include "StdMeshersGUI_ObjectReferenceParamWdg.h"
39 #include "StdMeshersGUI_QuadrangleParamWdg.h"
40 #include "StdMeshersGUI_SubShapeSelectorWdg.h"
41
42 #include <SALOMEDSClient_Study.hxx>
43
44 // SALOME GUI includes
45 #include <SUIT_ResourceMgr.h>
46
47 // IDL includes
48 #include <SALOMEconfig.h>
49 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
50 #include CORBA_SERVER_HEADER(SMESH_Mesh)
51
52 // Qt includes
53 #include <QHBoxLayout>
54 #include <QSlider>
55 #include <QLabel>
56 #include <QCheckBox>
57
58 const double VALUE_MAX = 1.0e+15, // COORD_MAX
59              VALUE_MAX_2  = VALUE_MAX * VALUE_MAX,
60              VALUE_MAX_3  = VALUE_MAX_2 * VALUE_MAX,
61              VALUE_SMALL = 1.0e-15,
62              VALUE_SMALL_2 = VALUE_SMALL * VALUE_SMALL,
63              VALUE_SMALL_3 = VALUE_SMALL_2 * VALUE_SMALL;
64
65 //================================================================================
66 /*!
67  * \brief Constructor
68   * \param type - hypothesis type
69  */
70 //================================================================================
71
72 StdMeshersGUI_StdHypothesisCreator::StdMeshersGUI_StdHypothesisCreator( const QString& type )
73 : SMESHGUI_GenericHypothesisCreator( type )
74 {
75 }
76
77 //================================================================================
78 /*!
79  * \brief Destructor
80  */
81 //================================================================================
82
83 StdMeshersGUI_StdHypothesisCreator::~StdMeshersGUI_StdHypothesisCreator()
84 {
85 }
86
87 //================================================================================
88 /*!
89  * \brief Return widget for i-th hypothesis parameter (got from myParamWidgets)
90   * \param i - index of hypothesis parameter
91   * \retval QWidget* - found widget
92  */
93 //================================================================================
94
95 QWidget* StdMeshersGUI_StdHypothesisCreator::getWidgetForParam( int i ) const
96 {
97   QWidget* w = 0;
98   if ( isCreation() ) ++i; // skip widget of 'name' parameter
99
100   if ( i < myCustomWidgets.count() ) {
101     QList<QWidget*>::const_iterator anIt  = myCustomWidgets.begin();
102     QList<QWidget*>::const_iterator aLast = myCustomWidgets.end();
103     for ( int j = 0 ; !w && anIt != aLast; ++anIt, ++j )
104       if ( i == j )
105         w = *anIt;
106   }
107   if ( !w ) {
108     // list has no at() const, so we iterate
109     QList<QWidget*>::const_iterator anIt  = widgets().begin();
110     QList<QWidget*>::const_iterator aLast = widgets().end();
111     for( int j = 0; !w && anIt!=aLast; anIt++, ++j ) {
112       if ( i == j )
113         w = *anIt;
114     }
115   }
116   return w;
117 }
118
119 //================================================================================
120 /*!
121  * \brief Allow modifing myCustomWidgets in const methods
122   * \retval ListOfWidgets* - non-const pointer to myCustomWidgets
123  */
124 //================================================================================
125
126 StdMeshersGUI_StdHypothesisCreator::ListOfWidgets*
127 StdMeshersGUI_StdHypothesisCreator::customWidgets() const
128 {
129   return const_cast< ListOfWidgets* >( & myCustomWidgets );
130 }
131
132 //================================================================================
133 /*!
134  * \brief Builds dlg layout
135   * \retval QFrame* - the built widget
136  */
137 //================================================================================
138
139 QFrame* StdMeshersGUI_StdHypothesisCreator::buildFrame()
140 {
141   return buildStdFrame();
142 }
143
144 //================================================================================
145 /*!
146  * \brief Initialise parameter values in controls
147  */
148 //================================================================================
149
150 void StdMeshersGUI_StdHypothesisCreator::retrieveParams() const
151 {
152   // buildStdFrame() sets values itself calling stdParams()
153
154   if ( hypType().startsWith("ProjectionSource" ))
155   {
156     // we use this method to connect depending custom widgets
157     StdMeshersGUI_ObjectReferenceParamWdg* widgetToActivate = 0;
158     ListOfWidgets::const_iterator anIt = myCustomWidgets.begin();
159     for ( ; anIt != myCustomWidgets.end(); anIt++)
160     {
161       if ( *anIt && (*anIt)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
162       {
163         StdMeshersGUI_ObjectReferenceParamWdg * w1 =
164           ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
165         ListOfWidgets::const_iterator anIt2 = anIt;
166         for ( ++anIt2; anIt2 != myCustomWidgets.end(); anIt2++)
167           if ( *anIt2 && (*anIt2)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
168           {
169             StdMeshersGUI_ObjectReferenceParamWdg * w2 =
170               ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt2 );
171             w1->AvoidSimultaneousSelection( w2 );
172           }
173         if ( !widgetToActivate )
174           widgetToActivate = w1;
175       }
176     }
177     if ( widgetToActivate )
178       widgetToActivate->activateSelection();
179   }
180
181   if ( dlg() )
182     dlg()->setMinimumSize( dlg()->minimumSizeHint().width(), dlg()->minimumSizeHint().height() );
183 }
184
185 namespace {
186
187   //================================================================================
188   /*!
189    * \brief Widget: slider with left and right labels
190    */
191   //================================================================================
192
193   class TDoubleSliderWith2Labels: public QWidget
194   {
195   public:
196     TDoubleSliderWith2Labels( const QString& leftLabel, const QString& rightLabel,
197                               const double   initValue, const double   bottom,
198                               const double   top      , const double   precision,
199                               QWidget *      parent=0 , const char *   name=0 )
200       :QWidget(parent), _bottom(bottom), _precision(precision)
201     {
202       setObjectName(name);
203
204       QHBoxLayout* aHBoxL = new QHBoxLayout(this);
205
206       if ( !leftLabel.isEmpty() ) {
207         QLabel* aLeftLabel = new QLabel( this );
208         aLeftLabel->setText( leftLabel );
209         aHBoxL->addWidget( aLeftLabel );
210       }
211
212       _slider = new QSlider( Qt::Horizontal, this );
213       _slider->setRange( 0, toInt( top ));
214       _slider->setValue( toInt( initValue ));
215       aHBoxL->addWidget( _slider );
216
217       if ( !rightLabel.isEmpty() ) {
218         QLabel* aRightLabel = new QLabel( this );
219         aRightLabel->setText( rightLabel );
220         aHBoxL->addWidget( aRightLabel );
221       }
222
223       setLayout( aHBoxL );
224     }
225     double value() const { return _bottom + _slider->value() * _precision; }
226     QSlider * getSlider() const { return _slider; }
227     int toInt( double val ) const { return (int) ceil(( val - _bottom ) / _precision ); }
228   private:
229     double _bottom, _precision;
230     QSlider * _slider;
231   };
232
233   //================================================================================
234   /*!
235    * \brief Retrieve GEOM_Object held by widget
236    */
237   //================================================================================
238
239   inline GEOM::GEOM_Object_var geomFromWdg(const QWidget* wdg)
240   {
241     const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
242       dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
243     if ( objRefWdg )
244       return objRefWdg->GetObject< GEOM::GEOM_Object >();
245
246     return GEOM::GEOM_Object::_nil();
247   }
248   //================================================================================
249   /*!
250    * \brief Retrieve SMESH_Mesh held by widget
251    */
252   //================================================================================
253
254   inline SMESH::SMESH_Mesh_var meshFromWdg(const QWidget* wdg)
255   {
256     const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
257       dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
258     if ( objRefWdg )
259       return objRefWdg->GetObject< SMESH::SMESH_Mesh >();
260
261     return SMESH::SMESH_Mesh::_nil();
262   }
263   //================================================================================
264   /*!
265    * \brief creates a filter for selection of shapes of given dimension
266     * \param dim - dimension
267     * \param subShapeType - required type of subshapes, number of which must be \a nbSubShapes
268     * \param nbSubShapes - number of subshapes of given type
269     * \param closed - required closeness flag of a shape
270     * \retval SUIT_SelectionFilter* - created filter
271    */
272   //================================================================================
273
274   SUIT_SelectionFilter* filterForShapeOfDim(const int        dim,
275                                             TopAbs_ShapeEnum subShapeType = TopAbs_SHAPE,
276                                             const int        nbSubShapes = 0,
277                                             bool             closed = false)
278   {
279     TColStd_MapOfInteger shapeTypes;
280     switch ( dim ) {
281     case 0: shapeTypes.Add( TopAbs_VERTEX ); break;
282     case 1:
283       if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_EDGE;
284       shapeTypes.Add( TopAbs_EDGE );
285       shapeTypes.Add( TopAbs_COMPOUND ); // for a group
286       break;
287     case 2:
288       if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_FACE;
289       shapeTypes.Add( TopAbs_FACE );
290       shapeTypes.Add( TopAbs_COMPOUND ); // for a group
291       break;
292     case 3:
293       shapeTypes.Add( TopAbs_SHELL );
294       shapeTypes.Add( TopAbs_SOLID );
295       shapeTypes.Add( TopAbs_COMPSOLID );
296       shapeTypes.Add( TopAbs_COMPOUND );
297       break;
298     }
299     return new SMESH_NumberFilter("GEOM", subShapeType, nbSubShapes,
300                                   shapeTypes, GEOM::GEOM_Object::_nil(), closed);
301   }
302
303   //================================================================================
304   /*!
305    * \brief Create a widget for object selection
306     * \param object - initial object
307     * \param filter - selection filter
308     * \retval QWidget* - created widget
309    */
310   //================================================================================
311
312   QWidget* newObjRefParamWdg( SUIT_SelectionFilter* filter,
313                               CORBA::Object_var     object)
314   {
315     StdMeshersGUI_ObjectReferenceParamWdg* w =
316       new StdMeshersGUI_ObjectReferenceParamWdg( filter, 0);
317     w->SetObject( object.in() );
318     return w;
319   }
320
321   //================================================================================
322   /*!
323    * \brief calls deactivateSelection() for StdMeshersGUI_ObjectReferenceParamWdg
324     * \param widgetList - list of widgets
325    */
326   //================================================================================
327
328   void deactivateObjRefParamWdg( QList<QWidget*>* widgetList )
329   {
330     StdMeshersGUI_ObjectReferenceParamWdg* w = 0;
331     QList<QWidget*>::iterator anIt  = widgetList->begin();
332     QList<QWidget*>::iterator aLast = widgetList->end();
333     for ( ; anIt != aLast; anIt++ ) {
334       if ( (*anIt) && (*anIt)->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
335       {
336         w = (StdMeshersGUI_ObjectReferenceParamWdg* )( *anIt );
337         w->deactivateSelection();
338       }
339     }
340   }
341 }
342
343 //================================================================================
344 /*!
345  * \brief Check parameter values before accept()
346   * \retval bool - true if OK
347  */
348 //================================================================================
349
350 bool StdMeshersGUI_StdHypothesisCreator::checkParams( QString& msg ) const
351 {
352   if( !SMESHGUI_GenericHypothesisCreator::checkParams( msg ) )
353     return false;
354
355   // check if object reference parameter is set, as it has no default value
356   bool ok = true;
357   if ( hypType().startsWith("ProjectionSource" ))
358   {
359     StdMeshersGUI_ObjectReferenceParamWdg* w =
360       widget< StdMeshersGUI_ObjectReferenceParamWdg >( 0 );
361     ok = ( w->IsObjectSelected() );
362     if ( !ok ) w->SetObject( CORBA::Object::_nil() );
363     int nbAssocVert = ( hypType() == "ProjectionSource1D" ? 1 : 2 );
364     for ( int i = 0; ok && i < nbAssocVert; i += 2)
365     {
366       QString srcV, tgtV;
367       StdMeshersGUI_ObjectReferenceParamWdg* w1 =
368         widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+2 );
369       StdMeshersGUI_ObjectReferenceParamWdg* w2 =
370         widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+3 );
371       srcV = w1->GetValue();
372       tgtV = w2->GetValue();
373       ok = (( srcV.isEmpty()  && tgtV.isEmpty() ) ||
374             ( !srcV.isEmpty() && !tgtV.isEmpty() && srcV != tgtV ));
375       if ( !ok ) {
376         w1->SetObject( CORBA::Object::_nil() );
377         w2->SetObject( CORBA::Object::_nil() );
378       }
379     }
380
381     // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
382     if ( ok )
383       deactivateObjRefParamWdg( customWidgets() );
384   }
385   else if ( hypType() == "LayerDistribution" || hypType() == "LayerDistribution2D" )
386   {
387     StdMeshersGUI_LayerDistributionParamWdg* w = 
388       widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
389     ok = ( w && w->IsOk() );
390   }
391   else if ( hypType() == "QuadrangleParams" )
392   {
393     //StdMeshersGUI_SubShapeSelectorWdg* w =
394     //  widget< StdMeshersGUI_SubShapeSelectorWdg >( 0 );
395     //ok = ( w->GetListSize() > 0 );
396     //StdMeshersGUI_QuadrangleParamWdg* w =
397     //  widget< StdMeshersGUI_QuadrangleParamWdg >( 1 );
398   }
399   return ok;
400 }
401
402 //================================================================================
403 /*!
404  * \brief Store params from GUI controls to a hypothesis
405   * \retval QString - text representation of parameters
406  */
407 //================================================================================
408
409 QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
410 {
411   ListOfStdParams params;
412   bool res = getStdParamFromDlg( params );
413   if( isCreation() )
414   {
415     SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().toLatin1().data() );
416     params.erase( params.begin() );
417   }
418
419   QString valueStr = stdParamValues( params );
420   QStringList aVariablesList = getVariablesFromDlg();
421
422   if( res && !params.isEmpty() )
423   {
424     if( hypType()=="LocalLength" )
425     {
426       StdMeshers::StdMeshers_LocalLength_var h =
427         StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
428
429       h->SetLength( params[0].myValue.toDouble() );
430       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
431       h->SetPrecision( params[1].myValue.toDouble() );
432       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
433     }
434     else if( hypType()=="MaxLength" )
435     {
436       StdMeshers::StdMeshers_MaxLength_var h =
437         StdMeshers::StdMeshers_MaxLength::_narrow( hypothesis() );
438
439       h->SetLength( params[0].myValue.toDouble() );
440       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
441       h->SetUsePreestimatedLength( widget< QCheckBox >( 1 )->isChecked() );
442       if ( !h->HavePreestimatedLength() && !h->_is_equivalent( initParamsHypothesis() )) {
443         StdMeshers::StdMeshers_MaxLength_var hInit =
444           StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis() );
445         h->SetPreestimatedLength( hInit->GetPreestimatedLength() );
446       }
447     }
448     else if( hypType()=="SegmentLengthAroundVertex" )
449     {
450       StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
451         StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hypothesis() );
452
453       h->SetLength( params[0].myValue.toDouble() );
454       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
455     }
456     else if( hypType()=="Arithmetic1D" )
457     {
458       StdMeshers::StdMeshers_Arithmetic1D_var h =
459         StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
460
461       StdMeshersGUI_SubShapeSelectorWdg* w = 
462         widget< StdMeshersGUI_SubShapeSelectorWdg >( 2 );
463
464       h->SetStartLength( params[0].myValue.toDouble() );
465       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
466       h->SetEndLength( params[1].myValue.toDouble() );
467       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
468       if (w) {
469         h->SetReversedEdges( w->GetListOfIDs() );
470         h->SetObjectEntry( w->GetMainShapeEntry() );
471       }
472     }
473     else if( hypType()=="FixedPoints1D" )
474     {
475       StdMeshers::StdMeshers_FixedPoints1D_var h =
476         StdMeshers::StdMeshers_FixedPoints1D::_narrow( hypothesis() );
477
478       StdMeshersGUI_FixedPointsParamWdg* w1 = 
479         widget< StdMeshersGUI_FixedPointsParamWdg >( 0 );
480
481       StdMeshersGUI_SubShapeSelectorWdg* w2 = 
482         widget< StdMeshersGUI_SubShapeSelectorWdg >( 1 );
483
484       if (w1) {
485         h->SetParameters(aVariablesList.join(":").toLatin1().constData());
486         h->SetPoints( w1->GetListOfPoints() );
487         h->SetNbSegments( w1->GetListOfSegments() );
488       }
489       if (w2) {
490         h->SetReversedEdges( w2->GetListOfIDs() );
491         h->SetObjectEntry( w2->GetMainShapeEntry() );
492       }
493     }
494     else if( hypType()=="MaxElementArea" )
495     {
496       StdMeshers::StdMeshers_MaxElementArea_var h =
497         StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
498       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
499       h->SetMaxElementArea( params[0].myValue.toDouble() );
500     }
501     else if( hypType()=="MaxElementVolume" )
502     {
503       StdMeshers::StdMeshers_MaxElementVolume_var h =
504         StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
505
506       h->SetMaxElementVolume( params[0].myValue.toDouble() );
507       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
508     }
509     else if( hypType()=="StartEndLength" )
510     {
511       StdMeshers::StdMeshers_StartEndLength_var h =
512         StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
513
514       StdMeshersGUI_SubShapeSelectorWdg* w = 
515         widget< StdMeshersGUI_SubShapeSelectorWdg >( 2 );
516
517       h->SetStartLength( params[0].myValue.toDouble() );
518       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
519       h->SetEndLength( params[1].myValue.toDouble() );
520       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
521       if (w) {
522         h->SetReversedEdges( w->GetListOfIDs() );
523         h->SetObjectEntry( w->GetMainShapeEntry() );
524       }
525     }
526     else if( hypType()=="Deflection1D" )
527     {
528       StdMeshers::StdMeshers_Deflection1D_var h =
529         StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
530       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
531       h->SetDeflection( params[0].myValue.toDouble() );
532     }
533     else if( hypType()=="AutomaticLength" )
534     {
535       StdMeshers::StdMeshers_AutomaticLength_var h =
536         StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() );
537
538       h->SetFineness( params[0].myValue.toDouble() );
539     }
540     else if( hypType()=="NumberOfLayers" )
541     {
542       StdMeshers::StdMeshers_NumberOfLayers_var h =
543         StdMeshers::StdMeshers_NumberOfLayers::_narrow( hypothesis() );
544
545       h->SetNumberOfLayers( params[0].myValue.toInt() );
546       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
547     }
548     else if( hypType()=="LayerDistribution" )
549     {
550       StdMeshers::StdMeshers_LayerDistribution_var h =
551         StdMeshers::StdMeshers_LayerDistribution::_narrow( hypothesis() );
552       StdMeshersGUI_LayerDistributionParamWdg* w = 
553         widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
554       
555       h->SetLayerDistribution( w->GetHypothesis() );
556       h->SetParameters(w->GetHypothesis()->GetParameters());
557       w->GetHypothesis()->ClearParameters();
558     }
559     else if( hypType()=="NumberOfLayers2D" )
560     {
561       StdMeshers::StdMeshers_NumberOfLayers2D_var h =
562         StdMeshers::StdMeshers_NumberOfLayers2D::_narrow( hypothesis() );
563
564       h->SetNumberOfLayers( params[0].myValue.toInt() );
565       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
566     }
567     else if( hypType()=="LayerDistribution2D" )
568     {
569       StdMeshers::StdMeshers_LayerDistribution2D_var h =
570         StdMeshers::StdMeshers_LayerDistribution2D::_narrow( hypothesis() );
571       StdMeshersGUI_LayerDistributionParamWdg* w = 
572         widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
573       
574       h->SetLayerDistribution( w->GetHypothesis() );
575       h->SetParameters(w->GetHypothesis()->GetParameters());
576       w->GetHypothesis()->ClearParameters();
577     }
578     else if( hypType()=="ProjectionSource1D" )
579     {
580       StdMeshers::StdMeshers_ProjectionSource1D_var h =
581         StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hypothesis() );
582
583       h->SetSourceEdge       ( geomFromWdg ( getWidgetForParam( 0 )));
584       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
585       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )),
586                                geomFromWdg ( getWidgetForParam( 3 )));
587     }
588     else if( hypType()=="ProjectionSource2D" )
589     {
590       StdMeshers::StdMeshers_ProjectionSource2D_var h =
591         StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hypothesis() );
592
593       h->SetSourceFace       ( geomFromWdg ( getWidgetForParam( 0 )));
594       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
595       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
596                                geomFromWdg ( getWidgetForParam( 4 )), // src2
597                                geomFromWdg ( getWidgetForParam( 3 )), // tgt1
598                                geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
599     }
600     else if( hypType()=="ProjectionSource3D" )
601     {
602       StdMeshers::StdMeshers_ProjectionSource3D_var h =
603         StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hypothesis() );
604
605       h->SetSource3DShape    ( geomFromWdg ( getWidgetForParam( 0 )));
606       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
607       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
608                                geomFromWdg ( getWidgetForParam( 4 )), // src2
609                                geomFromWdg ( getWidgetForParam( 3 )), // tgt1
610                                geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
611     }
612     else if( hypType()=="QuadrangleParams" )
613     {
614       StdMeshers::StdMeshers_QuadrangleParams_var h =
615         StdMeshers::StdMeshers_QuadrangleParams::_narrow( hypothesis() );
616       StdMeshersGUI_SubShapeSelectorWdg* w1 =
617         widget< StdMeshersGUI_SubShapeSelectorWdg >( 0 );
618       StdMeshersGUI_QuadrangleParamWdg* w2 =
619         widget< StdMeshersGUI_QuadrangleParamWdg >( 1 );
620       if (w1 && w2) {
621         if (w1->GetListSize() > 0) {
622           h->SetTriaVertex(w1->GetListOfIDs()[0]); // getlist must be called once
623           const char * entry = w1->GetMainShapeEntry();
624           h->SetObjectEntry(entry);
625         }
626         h->SetQuadType(StdMeshers::QuadType(w2->GetType()));
627       }
628     }
629   }
630   return valueStr;
631 }
632
633 //================================================================================
634 /*!
635  * \brief Return parameter values as SMESHGUI_GenericHypothesisCreator::StdParam
636   * \param p - list of parameters
637   * \retval bool - success flag
638   *
639   * Is called from SMESHGUI_GenericHypothesisCreator::buildStdFrame().
640   * Parameters will be shown using "standard" controls:
641   *   Int by QtxIntSpinBox
642   *   Double by SMESHGUI_SpinBox
643   *   String by QLineEdit
644   * getCustomWidget() allows to redefine control for a parameter
645  */
646 //================================================================================
647
648 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
649 {
650   bool res = true;
651   SMESHGUI_GenericHypothesisCreator::StdParam item;
652
653   p.clear();
654   customWidgets()->clear();
655   if( isCreation() )
656   {
657     HypothesisData* data = SMESH::GetHypothesisData( hypType() );
658     item.myName = tr( "SMESH_NAME" );
659     item.myValue = data ? hypName() : QString();
660     p.append( item );
661     customWidgets()->append(0);
662   }
663   
664   SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
665   SMESH::ListOfParameters_var aParameters = hyp->GetLastParameters();
666
667   if( hypType()=="LocalLength" )
668   {
669     StdMeshers::StdMeshers_LocalLength_var h =
670       StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
671     
672     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
673     if(!initVariableName(aParameters,item,0))
674       item.myValue = h->GetLength();
675     p.append( item );     
676     
677     item.myName = tr("SMESH_LOCAL_LENGTH_PRECISION");
678     if(!initVariableName(aParameters,item,1))
679       item.myValue = h->GetPrecision(); 
680     p.append( item );
681     
682   }
683   else if( hypType()=="MaxLength" )
684   {
685     StdMeshers::StdMeshers_MaxLength_var h =
686       StdMeshers::StdMeshers_MaxLength::_narrow( hyp );
687     // try to set a right preestimated length to edited hypothesis
688     bool noPreestimatedAtEdition = false;
689     if ( !isCreation() ) {
690       StdMeshers::StdMeshers_MaxLength_var initHyp =
691         StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis(true) );
692       noPreestimatedAtEdition =
693         ( initHyp->_is_nil() || !initHyp->HavePreestimatedLength() );
694       if ( !noPreestimatedAtEdition )
695         h->SetPreestimatedLength( initHyp->GetPreestimatedLength() );
696     }
697
698     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
699     if(!initVariableName(aParameters,item,0))
700       item.myValue = h->GetLength();
701     p.append( item );
702     customWidgets()->append(0);
703
704     item.myName = tr("SMESH_USE_PREESTIMATED_LENGTH");
705     p.append( item );
706     QCheckBox* aQCheckBox = new QCheckBox(dlg());
707     if ( !noPreestimatedAtEdition && h->HavePreestimatedLength() ) {
708       aQCheckBox->setChecked( h->GetUsePreestimatedLength() );
709       connect( aQCheckBox, SIGNAL(  stateChanged(int) ), this, SLOT( onValueChanged() ) );
710     }
711     else {
712       aQCheckBox->setChecked( false );
713       aQCheckBox->setEnabled( false );
714     }
715     customWidgets()->append( aQCheckBox );
716   }
717   else if( hypType()=="SegmentLengthAroundVertex" )
718   {
719     StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
720       StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hyp );
721
722     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
723     if(!initVariableName(aParameters,item,0))
724       item.myValue = h->GetLength();
725     
726     p.append( item );
727   }
728   else if( hypType()=="Arithmetic1D" )
729   {
730     StdMeshers::StdMeshers_Arithmetic1D_var h =
731       StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
732
733     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
734     if(!initVariableName(aParameters,item,0))
735       item.myValue = h->GetLength( true );
736     p.append( item );
737
738     customWidgets()->append (0);
739
740     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
741     if(!initVariableName(aParameters,item,1))
742       item.myValue = h->GetLength( false );
743     p.append( item );
744
745     customWidgets()->append (0);
746
747     item.myName = tr( "SMESH_REVERSED_EDGES" );
748     p.append( item );
749
750     StdMeshersGUI_SubShapeSelectorWdg* aDirectionWidget =
751       new StdMeshersGUI_SubShapeSelectorWdg();
752     QString aGeomEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
753     QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
754     if ( aGeomEntry == "" )
755       aGeomEntry = h->GetObjectEntry();
756
757     aDirectionWidget->SetGeomShapeEntry( aGeomEntry );
758     aDirectionWidget->SetMainShapeEntry( aMainEntry );
759     aDirectionWidget->SetListOfIDs( h->GetReversedEdges() );
760     aDirectionWidget->showPreview( true );
761     customWidgets()->append ( aDirectionWidget );
762   }
763
764
765   else if( hypType()=="FixedPoints1D" )
766   {
767     StdMeshers::StdMeshers_FixedPoints1D_var h =
768       StdMeshers::StdMeshers_FixedPoints1D::_narrow( hyp );
769
770     item.myName = tr( "SMESH_FIXED_POINTS" );
771     p.append( item );
772
773     StdMeshersGUI_FixedPointsParamWdg* aFixedPointsWidget =
774       new StdMeshersGUI_FixedPointsParamWdg();
775
776     if ( !isCreation() ) {
777       aFixedPointsWidget->SetListOfPoints( h->GetPoints() );
778       aFixedPointsWidget->SetListOfSegments( h->GetNbSegments() );
779     }
780     customWidgets()->append( aFixedPointsWidget );
781
782     item.myName = tr( "SMESH_REVERSED_EDGES" );
783     p.append( item );
784
785     StdMeshersGUI_SubShapeSelectorWdg* aDirectionWidget =
786       new StdMeshersGUI_SubShapeSelectorWdg();
787     QString anEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
788     QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
789     if ( anEntry == "" )
790       anEntry = h->GetObjectEntry();
791     aDirectionWidget->SetGeomShapeEntry( anEntry );
792     aDirectionWidget->SetMainShapeEntry( aMainEntry );
793     aDirectionWidget->SetListOfIDs( h->GetReversedEdges() );
794     aDirectionWidget->showPreview( true );
795     customWidgets()->append ( aDirectionWidget );
796   }
797
798
799   else if( hypType()=="MaxElementArea" )
800   {
801     StdMeshers::StdMeshers_MaxElementArea_var h =
802       StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
803
804     item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
805     if(!initVariableName(aParameters,item,0))
806       item.myValue = h->GetMaxElementArea();
807     p.append( item );
808     
809   }
810   else if( hypType()=="MaxElementVolume" )
811   {
812     StdMeshers::StdMeshers_MaxElementVolume_var h =
813       StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
814
815     item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
816     if(!initVariableName(aParameters,item,0))
817       item.myValue = h->GetMaxElementVolume();
818     p.append( item );
819   }
820   else if( hypType()=="StartEndLength" )
821   {
822     StdMeshers::StdMeshers_StartEndLength_var h =
823       StdMeshers::StdMeshers_StartEndLength::_narrow( hyp );
824
825     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
826
827     if(!initVariableName(aParameters,item,0)) 
828       item.myValue = h->GetLength( true );
829     p.append( item );
830     customWidgets()->append(0);
831
832     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
833     if(!initVariableName(aParameters,item,1)) 
834       item.myValue = h->GetLength( false );
835     p.append( item );
836     customWidgets()->append(0);
837
838     item.myName = tr( "SMESH_REVERSED_EDGES" );
839     p.append( item );
840
841     StdMeshersGUI_SubShapeSelectorWdg* aDirectionWidget =
842       new StdMeshersGUI_SubShapeSelectorWdg();
843     QString anEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
844     QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
845     if ( anEntry == "" )
846       anEntry = h->GetObjectEntry();
847     aDirectionWidget->SetGeomShapeEntry( anEntry );
848     aDirectionWidget->SetMainShapeEntry( aMainEntry );
849     aDirectionWidget->SetListOfIDs( h->GetReversedEdges() );
850     aDirectionWidget->showPreview( true );
851     customWidgets()->append ( aDirectionWidget );
852   }
853   else if( hypType()=="Deflection1D" )
854   {
855     StdMeshers::StdMeshers_Deflection1D_var h =
856       StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
857     
858     item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
859     if(!initVariableName(aParameters,item,0)) 
860       item.myValue = h->GetDeflection();
861     p.append( item );
862   }
863   else if( hypType()=="AutomaticLength" )
864   {
865     StdMeshers::StdMeshers_AutomaticLength_var h =
866       StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
867
868     item.myName = tr( "SMESH_FINENESS_PARAM" );
869     //item.myValue = h->GetFineness();
870     p.append( item );
871     SMESHGUI_SpinBox* _autoLengthSpinBox = new SMESHGUI_SpinBox(dlg());
872     _autoLengthSpinBox->RangeStepAndValidator(0, 1, 0.01, "length_precision");
873     _autoLengthSpinBox->SetValue(h->GetFineness());
874     customWidgets()->append( _autoLengthSpinBox);
875   }
876   else if( hypType()=="NumberOfLayers" )
877   {
878     StdMeshers::StdMeshers_NumberOfLayers_var h =
879       StdMeshers::StdMeshers_NumberOfLayers::_narrow( hyp );
880
881     item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
882     if(!initVariableName(aParameters,item,0))     
883       item.myValue = (int) h->GetNumberOfLayers();
884     p.append( item );
885   }
886   else if( hypType()=="LayerDistribution" ) {
887     StdMeshers::StdMeshers_LayerDistribution_var h =
888       StdMeshers::StdMeshers_LayerDistribution::_narrow( hyp );
889     
890     item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
891     
892     //Set into not published hypo last variables
893     QStringList aLastVarsList;
894     for(int i = 0;i<aParameters->length();i++) 
895       aLastVarsList.append(QString(aParameters[i].in()));
896
897     if(!aLastVarsList.isEmpty())
898       h->GetLayerDistribution()->SetLastParameters(aLastVarsList.join(":").toLatin1().constData());
899     
900     customWidgets()->append
901       ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
902   }
903   else if( hypType()=="NumberOfLayers2D" ) {
904     StdMeshers::StdMeshers_NumberOfLayers2D_var h =
905       StdMeshers::StdMeshers_NumberOfLayers2D::_narrow( hyp );
906     
907     item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
908     if(!initVariableName(aParameters,item,0))     
909       item.myValue = (int) h->GetNumberOfLayers();
910     p.append( item );
911   }
912   else if( hypType()=="LayerDistribution2D" ) {
913     StdMeshers::StdMeshers_LayerDistribution2D_var h =
914       StdMeshers::StdMeshers_LayerDistribution2D::_narrow( hyp );
915
916     item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
917     
918     //Set into not published hypo last variables
919     QStringList aLastVarsList;
920     for(int i = 0;i<aParameters->length();i++) 
921       aLastVarsList.append(QString(aParameters[i].in()));
922
923     if(!aLastVarsList.isEmpty())
924       h->GetLayerDistribution()->SetLastParameters(aLastVarsList.join(":").toLatin1().constData());
925     
926     customWidgets()->append
927       ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
928   }
929   else if( hypType()=="ProjectionSource1D" )
930   {
931     StdMeshers::StdMeshers_ProjectionSource1D_var h =
932       StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hyp );
933
934     item.myName = tr( "SMESH_SOURCE_EDGE" ); p.append( item );
935     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 1 ),
936                                                h->GetSourceEdge()));
937     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
938     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
939                                                h->GetSourceMesh()));
940     item.myName = tr( "SMESH_SOURCE_VERTEX" ); p.append( item );
941     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
942                                                h->GetSourceVertex()));
943     item.myName = tr( "SMESH_TARGET_VERTEX" ); p.append( item );
944     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
945                                                h->GetTargetVertex()));
946   }
947   else if( hypType()=="ProjectionSource2D" )
948   {
949     StdMeshers::StdMeshers_ProjectionSource2D_var h =
950       StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hyp );
951
952     item.myName = tr( "SMESH_SOURCE_FACE" ); p.append( item );
953     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 2 ),
954                                                h->GetSourceFace()));
955     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
956     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
957                                                h->GetSourceMesh()));
958     item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
959     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
960                                                h->GetSourceVertex( 1 )));
961     item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
962     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
963                                                h->GetTargetVertex( 1 )));
964     item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
965     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
966                                                h->GetSourceVertex( 2 )));
967     item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
968     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
969                                                h->GetTargetVertex( 2 )));
970   }
971   else if( hypType()=="ProjectionSource3D" )
972   {
973     StdMeshers::StdMeshers_ProjectionSource3D_var h =
974       StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hyp );
975
976     item.myName = tr( "SMESH_SOURCE_3DSHAPE" ); p.append( item );
977     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 3, TopAbs_FACE, 6, true ),
978                                                h->GetSource3DShape()));
979     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
980     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
981                                                h->GetSourceMesh()));
982     item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
983     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
984                                                h->GetSourceVertex( 1 )));
985     item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
986     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
987                                                h->GetTargetVertex( 1 )));
988     item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
989     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
990                                                h->GetSourceVertex( 2 )));
991     item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
992     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
993                                                h->GetTargetVertex( 2 )));
994   }
995   else if (hypType() == "QuadrangleParams")
996   {
997     StdMeshers::StdMeshers_QuadrangleParams_var h =
998       StdMeshers::StdMeshers_QuadrangleParams::_narrow(hyp);
999
1000     item.myName = tr("SMESH_BASE_VERTEX");
1001     p.append(item);
1002
1003     StdMeshersGUI_SubShapeSelectorWdg* aDirectionWidget =
1004       new StdMeshersGUI_SubShapeSelectorWdg();
1005     aDirectionWidget->SetMaxSize(1);
1006     aDirectionWidget->SetSubShType(TopAbs_VERTEX);
1007     QString anEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
1008     QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
1009     if (anEntry == "")
1010       anEntry = h->GetObjectEntry();
1011     aDirectionWidget->SetGeomShapeEntry(anEntry);
1012     aDirectionWidget->SetMainShapeEntry(aMainEntry);
1013     if (!isCreation()) {
1014       SMESH::long_array_var aVec = new SMESH::long_array;
1015       int vertID = h->GetTriaVertex();
1016       if (vertID > 0) {
1017         aVec->length(1);
1018         aVec[0] = vertID;
1019         aDirectionWidget->SetListOfIDs(aVec);
1020       }
1021     }
1022     aDirectionWidget->showPreview(true);
1023
1024     item.myName = tr("SMESH_QUAD_TYPE");
1025     p.append(item);
1026
1027     StdMeshersGUI_QuadrangleParamWdg* aTypeWidget =
1028       new StdMeshersGUI_QuadrangleParamWdg();
1029     if (!isCreation()) {
1030       aTypeWidget->SetType(int(h->GetQuadType()));
1031     }
1032
1033     customWidgets()->append(aDirectionWidget);
1034     customWidgets()->append(aTypeWidget);
1035   }
1036   else
1037     res = false;
1038   return res;
1039 }
1040
1041 //================================================================================
1042 /*!
1043  * \brief tune "standard" control
1044   * \param w - control widget
1045   * \param int - parameter index
1046  */
1047 //================================================================================
1048
1049 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget (QWidget* w, const int) const
1050 {
1051   SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
1052   if( hypType()=="LocalLength" &&  sb )
1053   {
1054     if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PARAM"))
1055       sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "length_precision" );
1056     else if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PRECISION"))
1057       sb->RangeStepAndValidator( 0.0, 1.0, 0.05, "len_tol_precision" );
1058   }
1059   else if( hypType()=="Arithmetic1D" && sb )
1060   {
1061     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "parametric_precision" );
1062   }
1063   else if( hypType()=="MaxLength" && sb )
1064   {
1065     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "length_precision" );
1066     sb->setEnabled( !widget< QCheckBox >( 1 )->isChecked() );
1067   }
1068   else if( hypType()=="MaxElementArea" && sb )
1069   {
1070     sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, "area_precision" );
1071   }
1072   else if( hypType()=="MaxElementVolume" && sb )
1073   {
1074     sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, "vol_precision" );
1075   }
1076   else if( hypType()=="StartEndLength" && sb )
1077   {
1078     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "length_precision" );
1079   }
1080   else if( hypType()=="Deflection1D" && sb )
1081   {
1082     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "parametric_precision" );
1083   }
1084   else if ( sb ) // default validator for possible ancestors
1085   {
1086     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "length_precision" );
1087   }
1088 }
1089
1090 //================================================================================
1091 /*!
1092  * \brief Return dlg title
1093   * \retval QString - title string
1094  */
1095 //================================================================================
1096
1097 QString StdMeshersGUI_StdHypothesisCreator::caption() const
1098 {
1099   return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
1100 }
1101
1102 //================================================================================
1103 /*!
1104  * \brief return pixmap for dlg icon
1105   * \retval QPixmap - 
1106  */
1107 //================================================================================
1108
1109 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
1110 {
1111   QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
1112   return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
1113 }
1114
1115 //================================================================================
1116 /*!
1117  * \brief Return hypothesis type name to show in dlg
1118   * \retval QString - 
1119  */
1120 //================================================================================
1121
1122 QString StdMeshersGUI_StdHypothesisCreator::type() const
1123 {
1124   return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
1125 }
1126
1127 //================================================================================
1128 /*!
1129  * \brief String to insert in "SMESH_%1_HYPOTHESIS" to get hypothesis type name
1130  * from message resouce file
1131   * \param t - hypothesis type
1132   * \retval QString - result string
1133  */
1134 //================================================================================
1135
1136 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
1137 {
1138   static QMap<QString,QString>  types;
1139   if( types.isEmpty() )
1140   {
1141     types.insert( "LocalLength", "LOCAL_LENGTH" );
1142     types.insert( "NumberOfSegments", "NB_SEGMENTS" );
1143     types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
1144     types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
1145     types.insert( "StartEndLength", "START_END_LENGTH" );
1146     types.insert( "Deflection1D", "DEFLECTION1D" );
1147     types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
1148     types.insert( "FixedPoints1D", "FIXED_POINTS_1D" );
1149     types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
1150     types.insert( "ProjectionSource1D", "PROJECTION_SOURCE_1D" );
1151     types.insert( "ProjectionSource2D", "PROJECTION_SOURCE_2D" );
1152     types.insert( "ProjectionSource3D", "PROJECTION_SOURCE_3D" );
1153     types.insert( "NumberOfLayers", "NUMBER_OF_LAYERS" );
1154     types.insert( "LayerDistribution", "LAYER_DISTRIBUTION" );
1155     types.insert( "NumberOfLayers2D", "NUMBER_OF_LAYERS_2D" );
1156     types.insert( "LayerDistribution2D", "LAYER_DISTRIBUTION" );
1157     types.insert( "SegmentLengthAroundVertex", "SEGMENT_LENGTH_AROUND_VERTEX" );
1158     types.insert( "MaxLength", "MAX_LENGTH" );
1159     types.insert( "QuadrangleParams", "QUADRANGLE_PARAMS" );
1160   }
1161
1162   QString res;
1163   if( types.contains( t ) )
1164     res = types[ t ];
1165
1166   return res;
1167 }
1168
1169
1170 //=======================================================================
1171 //function : getCustomWidget
1172 //purpose  : is called from buildStdFrame()
1173 //=======================================================================
1174
1175 QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
1176                                                               QWidget*         parent,
1177                                                               const int        index) const
1178 {
1179   QWidget* w = 0;
1180   if ( index < customWidgets()->count() ) {
1181     w = customWidgets()->at( index );
1182     if ( w ) {
1183       w->setParent( parent );
1184       w->move( QPoint( 0, 0 ) );
1185     }
1186   }
1187   return w;
1188 }
1189
1190 //================================================================================
1191 /*!
1192  * \brief Set param value taken from a custom widget
1193   * \param param - SMESHGUI_GenericHypothesisCreator::StdParam structure
1194   * \param widget - widget presenting param
1195   * \retval bool - success flag
1196  * 
1197  * this method is called from getStdParamFromDlg()
1198  */
1199 //================================================================================
1200
1201 bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
1202                                                                    QWidget*   widget) const
1203 {
1204   if ( hypType()=="AutomaticLength" ) {
1205     SMESHGUI_SpinBox* w = dynamic_cast<SMESHGUI_SpinBox*>( widget );
1206     if ( w ) {
1207       param.myValue = w->GetValue();
1208       return true;
1209     }
1210   }
1211   if ( hypType() == "MaxLength" ) {
1212     param.myValue = "";
1213     return true;
1214   }
1215   if ( widget->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
1216   {
1217     // show only 1st reference value
1218     if ( true /*widget == getWidgetForParam( 0 )*/) {
1219       const StdMeshersGUI_ObjectReferenceParamWdg * w =
1220         static_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( widget );
1221       param.myValue = w->GetValue();
1222     }
1223     return true;
1224   }
1225   if ( widget->inherits( "StdMeshersGUI_LayerDistributionParamWdg" ))
1226   {
1227     const StdMeshersGUI_LayerDistributionParamWdg * w =
1228       static_cast<const StdMeshersGUI_LayerDistributionParamWdg*>( widget );
1229     param.myValue = w->GetValue();
1230     return true;
1231   }
1232   if ( widget->inherits( "StdMeshersGUI_SubShapeSelectorWdg" ))
1233   {
1234     const StdMeshersGUI_SubShapeSelectorWdg * w =
1235       static_cast<const StdMeshersGUI_SubShapeSelectorWdg*>( widget );
1236     param.myValue = w->GetValue();
1237     return true;
1238   }
1239   if ( widget->inherits( "StdMeshersGUI_QuadrangleParamWdg" ))
1240   {
1241     //const StdMeshersGUI_QuadrangleParamWdg * w =
1242     //  static_cast<const StdMeshersGUI_QuadrangleParamWdg*>( widget );
1243     param.myValue = "QuadType";
1244     return true;
1245   }
1246   if ( widget->inherits( "StdMeshersGUI_FixedPointsParamWdg" ))
1247   {
1248     const StdMeshersGUI_FixedPointsParamWdg * w =
1249       static_cast<const StdMeshersGUI_FixedPointsParamWdg*>( widget );
1250     param.myValue = w->GetValue();
1251     return true;
1252   }
1253   return false;
1254 }
1255
1256 //================================================================================
1257 /*!
1258  * \brief called when operation cancelled
1259  */
1260 //================================================================================
1261
1262 void StdMeshersGUI_StdHypothesisCreator::onReject()
1263 {
1264   if ( hypType().startsWith("ProjectionSource" ))
1265   {
1266     // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
1267     deactivateObjRefParamWdg( customWidgets() );
1268   }
1269 }
1270
1271 //================================================================================
1272 /*!
1273  * \brief 
1274  */
1275 //================================================================================
1276
1277 void StdMeshersGUI_StdHypothesisCreator::valueChanged( QWidget* paramWidget)
1278 {
1279   if ( hypType() == "MaxLength" && paramWidget == getWidgetForParam(1) ) {
1280     getWidgetForParam(0)->setEnabled( !widget< QCheckBox >( 1 )->isChecked() );
1281     if ( !getWidgetForParam(0)->isEnabled() ) {
1282       StdMeshers::StdMeshers_MaxLength_var h =
1283         StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis() );
1284       widget< QtxDoubleSpinBox >( 0 )->setValue( h->GetPreestimatedLength() );
1285     }
1286   }
1287 }
1288
1289 //================================================================================
1290 /*!
1291  *
1292  */
1293 //================================================================================
1294
1295 bool StdMeshersGUI_StdHypothesisCreator::initVariableName(SMESH::ListOfParameters_var theParameters, 
1296                                                           StdParam &theParams, 
1297                                                           int order) const
1298 {
1299   QString aVaribaleName = (theParameters->length() > order) ? QString(theParameters[order].in()) : QString("");
1300   theParams.isVariable = !aVaribaleName.isEmpty();
1301   if(theParams.isVariable) 
1302     theParams.myValue = aVaribaleName;
1303
1304   return theParams.isVariable;
1305 }