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