Salome HOME
Merge from V5_1_main branch 24/11/2010
[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()=="QuadrangleParams" )
670     {
671       StdMeshers::StdMeshers_QuadrangleParams_var h =
672         StdMeshers::StdMeshers_QuadrangleParams::_narrow( hypothesis() );
673       StdMeshersGUI_SubShapeSelectorWdg* w1 =
674         widget< StdMeshersGUI_SubShapeSelectorWdg >( 0 );
675       StdMeshersGUI_QuadrangleParamWdg* w2 =
676         widget< StdMeshersGUI_QuadrangleParamWdg >( 1 );
677       if (w1 && w2) {
678         if (w1->GetListSize() > 0) {
679           h->SetTriaVertex(w1->GetListOfIDs()[0]); // getlist must be called once
680           const char * entry = w1->GetMainShapeEntry();
681           h->SetObjectEntry(entry);
682         }
683         h->SetQuadType(StdMeshers::QuadType(w2->GetType()));
684       }
685     }
686   }
687   return valueStr;
688 }
689
690 //================================================================================
691 /*!
692  * \brief Return parameter values as SMESHGUI_GenericHypothesisCreator::StdParam
693   * \param p - list of parameters
694   * \retval bool - success flag
695   *
696   * Is called from SMESHGUI_GenericHypothesisCreator::buildStdFrame().
697   * Parameters will be shown using "standard" controls:
698   *   Int by QtxIntSpinBox
699   *   Double by SMESHGUI_SpinBox
700   *   String by QLineEdit
701   * getCustomWidget() allows to redefine control for a parameter
702  */
703 //================================================================================
704
705 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
706 {
707   bool res = true;
708   SMESHGUI_GenericHypothesisCreator::StdParam item;
709
710   p.clear();
711   customWidgets()->clear();
712   if( isCreation() )
713   {
714     HypothesisData* data = SMESH::GetHypothesisData( hypType() );
715     item.myName = tr( "SMESH_NAME" );
716     item.myValue = data ? hypName() : QString();
717     p.append( item );
718     customWidgets()->append(0);
719   }
720   
721   SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
722   SMESH::ListOfParameters_var aParameters = hyp->GetLastParameters();
723
724   if( hypType()=="LocalLength" )
725   {
726     StdMeshers::StdMeshers_LocalLength_var h =
727       StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
728     
729     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
730     if(!initVariableName(aParameters,item,0))
731       item.myValue = h->GetLength();
732     p.append( item );     
733     
734     item.myName = tr("SMESH_LOCAL_LENGTH_PRECISION");
735     if(!initVariableName(aParameters,item,1))
736       item.myValue = h->GetPrecision(); 
737     p.append( item );
738     
739   }
740   else if( hypType()=="MaxLength" )
741   {
742     StdMeshers::StdMeshers_MaxLength_var h =
743       StdMeshers::StdMeshers_MaxLength::_narrow( hyp );
744     // try to set a right preestimated length to edited hypothesis
745     bool noPreestimatedAtEdition = false;
746     if ( !isCreation() ) {
747       StdMeshers::StdMeshers_MaxLength_var initHyp =
748         StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis(true) );
749       noPreestimatedAtEdition =
750         ( initHyp->_is_nil() || !initHyp->HavePreestimatedLength() );
751       if ( !noPreestimatedAtEdition )
752         h->SetPreestimatedLength( initHyp->GetPreestimatedLength() );
753     }
754
755     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
756     if(!initVariableName(aParameters,item,0))
757       item.myValue = h->GetLength();
758     p.append( item );
759     customWidgets()->append(0);
760
761     item.myName = tr("SMESH_USE_PREESTIMATED_LENGTH");
762     p.append( item );
763     QCheckBox* aQCheckBox = new QCheckBox(dlg());
764     if ( !noPreestimatedAtEdition && h->HavePreestimatedLength() ) {
765       aQCheckBox->setChecked( h->GetUsePreestimatedLength() );
766       connect( aQCheckBox, SIGNAL(  stateChanged(int) ), this, SLOT( onValueChanged() ) );
767     }
768     else {
769       aQCheckBox->setChecked( false );
770       aQCheckBox->setEnabled( false );
771     }
772     customWidgets()->append( aQCheckBox );
773   }
774   else if( hypType()=="SegmentLengthAroundVertex" )
775   {
776     StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
777       StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hyp );
778
779     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
780     if(!initVariableName(aParameters,item,0))
781       item.myValue = h->GetLength();
782     
783     p.append( item );
784   }
785   else if( hypType()=="Arithmetic1D" )
786   {
787     StdMeshers::StdMeshers_Arithmetic1D_var h =
788       StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
789
790     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
791     if(!initVariableName(aParameters,item,0))
792       item.myValue = h->GetLength( true );
793     p.append( item );
794
795     customWidgets()->append (0);
796
797     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
798     if(!initVariableName(aParameters,item,1))
799       item.myValue = h->GetLength( false );
800     p.append( item );
801
802     customWidgets()->append (0);
803
804     item.myName = tr( "SMESH_REVERSED_EDGES" );
805     p.append( item );
806
807     StdMeshersGUI_SubShapeSelectorWdg* aDirectionWidget =
808       new StdMeshersGUI_SubShapeSelectorWdg();
809     QString aGeomEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
810     QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
811     if ( aGeomEntry == "" )
812       aGeomEntry = h->GetObjectEntry();
813
814     aDirectionWidget->SetGeomShapeEntry( aGeomEntry );
815     aDirectionWidget->SetMainShapeEntry( aMainEntry );
816     aDirectionWidget->SetListOfIDs( h->GetReversedEdges() );
817     aDirectionWidget->showPreview( true );
818     customWidgets()->append ( aDirectionWidget );
819   }
820
821
822   else if( hypType()=="FixedPoints1D" )
823   {
824     StdMeshers::StdMeshers_FixedPoints1D_var h =
825       StdMeshers::StdMeshers_FixedPoints1D::_narrow( hyp );
826
827     item.myName = tr( "SMESH_FIXED_POINTS" );
828     p.append( item );
829
830     StdMeshersGUI_FixedPointsParamWdg* aFixedPointsWidget =
831       new StdMeshersGUI_FixedPointsParamWdg();
832
833     if ( !isCreation() ) {
834       aFixedPointsWidget->SetListOfPoints( h->GetPoints() );
835       aFixedPointsWidget->SetListOfSegments( h->GetNbSegments() );
836     }
837     customWidgets()->append( aFixedPointsWidget );
838
839     item.myName = tr( "SMESH_REVERSED_EDGES" );
840     p.append( item );
841
842     StdMeshersGUI_SubShapeSelectorWdg* aDirectionWidget =
843       new StdMeshersGUI_SubShapeSelectorWdg();
844     QString anEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
845     QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
846     if ( anEntry == "" )
847       anEntry = h->GetObjectEntry();
848     aDirectionWidget->SetGeomShapeEntry( anEntry );
849     aDirectionWidget->SetMainShapeEntry( aMainEntry );
850     aDirectionWidget->SetListOfIDs( h->GetReversedEdges() );
851     aDirectionWidget->showPreview( true );
852     customWidgets()->append ( aDirectionWidget );
853   }
854
855
856   else if( hypType()=="MaxElementArea" )
857   {
858     StdMeshers::StdMeshers_MaxElementArea_var h =
859       StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
860
861     item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
862     if(!initVariableName(aParameters,item,0))
863       item.myValue = h->GetMaxElementArea();
864     p.append( item );
865     
866   }
867   else if( hypType()=="MaxElementVolume" )
868   {
869     StdMeshers::StdMeshers_MaxElementVolume_var h =
870       StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
871
872     item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
873     if(!initVariableName(aParameters,item,0))
874       item.myValue = h->GetMaxElementVolume();
875     p.append( item );
876   }
877   else if( hypType()=="StartEndLength" )
878   {
879     StdMeshers::StdMeshers_StartEndLength_var h =
880       StdMeshers::StdMeshers_StartEndLength::_narrow( hyp );
881
882     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
883
884     if(!initVariableName(aParameters,item,0)) 
885       item.myValue = h->GetLength( true );
886     p.append( item );
887     customWidgets()->append(0);
888
889     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
890     if(!initVariableName(aParameters,item,1)) 
891       item.myValue = h->GetLength( false );
892     p.append( item );
893     customWidgets()->append(0);
894
895     item.myName = tr( "SMESH_REVERSED_EDGES" );
896     p.append( item );
897
898     StdMeshersGUI_SubShapeSelectorWdg* aDirectionWidget =
899       new StdMeshersGUI_SubShapeSelectorWdg();
900     QString anEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
901     QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
902     if ( anEntry == "" )
903       anEntry = h->GetObjectEntry();
904     aDirectionWidget->SetGeomShapeEntry( anEntry );
905     aDirectionWidget->SetMainShapeEntry( aMainEntry );
906     aDirectionWidget->SetListOfIDs( h->GetReversedEdges() );
907     aDirectionWidget->showPreview( true );
908     customWidgets()->append ( aDirectionWidget );
909   }
910   else if( hypType()=="Deflection1D" )
911   {
912     StdMeshers::StdMeshers_Deflection1D_var h =
913       StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
914     
915     item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
916     if(!initVariableName(aParameters,item,0)) 
917       item.myValue = h->GetDeflection();
918     p.append( item );
919   }
920   else if( hypType()=="AutomaticLength" )
921   {
922     StdMeshers::StdMeshers_AutomaticLength_var h =
923       StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
924
925     item.myName = tr( "SMESH_FINENESS_PARAM" );
926     //item.myValue = h->GetFineness();
927     p.append( item );
928     SMESHGUI_SpinBox* _autoLengthSpinBox = new SMESHGUI_SpinBox(dlg());
929     _autoLengthSpinBox->RangeStepAndValidator(0, 1, 0.01, "length_precision");
930     _autoLengthSpinBox->SetValue(h->GetFineness());
931     customWidgets()->append( _autoLengthSpinBox);
932   }
933   else if( hypType()=="NumberOfLayers" )
934   {
935     StdMeshers::StdMeshers_NumberOfLayers_var h =
936       StdMeshers::StdMeshers_NumberOfLayers::_narrow( hyp );
937
938     item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
939     if(!initVariableName(aParameters,item,0))     
940       item.myValue = (int) h->GetNumberOfLayers();
941     p.append( item );
942   }
943   else if( hypType()=="LayerDistribution" ) {
944     StdMeshers::StdMeshers_LayerDistribution_var h =
945       StdMeshers::StdMeshers_LayerDistribution::_narrow( hyp );
946     
947     item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
948     
949     //Set into not published hypo last variables
950     QStringList aLastVarsList;
951     for(int i = 0;i<aParameters->length();i++) 
952       aLastVarsList.append(QString(aParameters[i].in()));
953
954     if(!aLastVarsList.isEmpty())
955       h->GetLayerDistribution()->SetLastParameters(aLastVarsList.join(":").toLatin1().constData());
956     
957     customWidgets()->append
958       ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
959   }
960   else if( hypType()=="NumberOfLayers2D" ) {
961     StdMeshers::StdMeshers_NumberOfLayers2D_var h =
962       StdMeshers::StdMeshers_NumberOfLayers2D::_narrow( hyp );
963     
964     item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
965     if(!initVariableName(aParameters,item,0))     
966       item.myValue = (int) h->GetNumberOfLayers();
967     p.append( item );
968   }
969   else if( hypType()=="LayerDistribution2D" ) {
970     StdMeshers::StdMeshers_LayerDistribution2D_var h =
971       StdMeshers::StdMeshers_LayerDistribution2D::_narrow( hyp );
972
973     item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
974     
975     //Set into not published hypo last variables
976     QStringList aLastVarsList;
977     for(int i = 0;i<aParameters->length();i++) 
978       aLastVarsList.append(QString(aParameters[i].in()));
979
980     if(!aLastVarsList.isEmpty())
981       h->GetLayerDistribution()->SetLastParameters(aLastVarsList.join(":").toLatin1().constData());
982     
983     customWidgets()->append
984       ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
985   }
986   else if( hypType()=="ProjectionSource1D" )
987   {
988     StdMeshers::StdMeshers_ProjectionSource1D_var h =
989       StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hyp );
990
991     item.myName = tr( "SMESH_SOURCE_EDGE" ); p.append( item );
992     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 1 ),
993                                                h->GetSourceEdge()));
994     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
995     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
996                                                h->GetSourceMesh()));
997     item.myName = tr( "SMESH_SOURCE_VERTEX" ); p.append( item );
998     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
999                                                h->GetSourceVertex()));
1000     item.myName = tr( "SMESH_TARGET_VERTEX" ); p.append( item );
1001     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
1002                                                h->GetTargetVertex()));
1003   }
1004   else if( hypType()=="ProjectionSource2D" )
1005   {
1006     StdMeshers::StdMeshers_ProjectionSource2D_var h =
1007       StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hyp );
1008
1009     item.myName = tr( "SMESH_SOURCE_FACE" ); p.append( item );
1010     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 2 ),
1011                                                h->GetSourceFace()));
1012     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
1013     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
1014                                                h->GetSourceMesh()));
1015     item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
1016     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
1017                                                h->GetSourceVertex( 1 )));
1018     item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
1019     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
1020                                                h->GetTargetVertex( 1 )));
1021     item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
1022     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
1023                                                h->GetSourceVertex( 2 )));
1024     item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
1025     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
1026                                                h->GetTargetVertex( 2 )));
1027   }
1028   else if( hypType()=="ProjectionSource3D" )
1029   {
1030     StdMeshers::StdMeshers_ProjectionSource3D_var h =
1031       StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hyp );
1032
1033     item.myName = tr( "SMESH_SOURCE_3DSHAPE" ); p.append( item );
1034     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 3, TopAbs_FACE, 6, true ),
1035                                                h->GetSource3DShape()));
1036     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
1037     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
1038                                                h->GetSourceMesh()));
1039     item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
1040     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
1041                                                h->GetSourceVertex( 1 )));
1042     item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
1043     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
1044                                                h->GetTargetVertex( 1 )));
1045     item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
1046     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
1047                                                h->GetSourceVertex( 2 )));
1048     item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
1049     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
1050                                                h->GetTargetVertex( 2 )));
1051   }
1052   else if( hypType()=="ImportSource1D" )
1053   {
1054     StdMeshers::StdMeshers_ImportSource1D_var h =
1055       StdMeshers::StdMeshers_ImportSource1D::_narrow( hyp );
1056
1057     SMESH::string_array_var groupEntries = h->GetSourceEdges();
1058     CORBA::Boolean toCopyMesh, toCopyGroups;
1059     h->GetCopySourceMesh(toCopyMesh, toCopyGroups);
1060
1061     item.myName = tr( "SMESH_SOURCE_EDGES" ); p.append( item );
1062     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( GROUP_EDGE ), 
1063                                                 groupEntries));
1064
1065     item.myName = tr( "SMESH_COPY_MESH" ); p.append( item );
1066     QCheckBox* aQCheckBox = new QCheckBox(dlg());
1067     aQCheckBox->setChecked( toCopyMesh );
1068     connect( aQCheckBox, SIGNAL(  stateChanged(int) ), this, SLOT( onValueChanged() ));
1069     customWidgets()->append( aQCheckBox );
1070
1071     item.myName = tr( "SMESH_TO_COPY_GROUPS" ); p.append( item );
1072     aQCheckBox = new QCheckBox(dlg());
1073     aQCheckBox->setChecked( toCopyGroups );
1074     aQCheckBox->setEnabled( toCopyMesh );
1075     customWidgets()->append( aQCheckBox );
1076   }
1077   else if( hypType()=="ImportSource2D" )
1078   {
1079     StdMeshers::StdMeshers_ImportSource2D_var h =
1080       StdMeshers::StdMeshers_ImportSource2D::_narrow( hyp );
1081
1082     SMESH::string_array_var groupEntries = h->GetSourceFaces();
1083     CORBA::Boolean toCopyMesh, toCopyGroups;
1084     h->GetCopySourceMesh(toCopyMesh, toCopyGroups);
1085
1086     item.myName = tr( "SMESH_SOURCE_FACES" ); p.append( item );
1087     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( GROUP_FACE ), 
1088                                                 groupEntries));
1089
1090     item.myName = tr( "SMESH_COPY_MESH" ); p.append( item );
1091     QCheckBox* aQCheckBox = new QCheckBox(dlg());
1092     aQCheckBox->setChecked( toCopyMesh );
1093     connect( aQCheckBox, SIGNAL(  stateChanged(int) ), this, SLOT( onValueChanged() ));
1094     customWidgets()->append( aQCheckBox );
1095
1096     item.myName = tr( "SMESH_COPY_GROUPS" ); p.append( item );
1097     aQCheckBox = new QCheckBox(dlg());
1098     aQCheckBox->setChecked( toCopyGroups );
1099     aQCheckBox->setEnabled( toCopyMesh );
1100     customWidgets()->append( aQCheckBox );
1101   }
1102   else if (hypType() == "QuadrangleParams")
1103   {
1104     StdMeshers::StdMeshers_QuadrangleParams_var h =
1105       StdMeshers::StdMeshers_QuadrangleParams::_narrow(hyp);
1106
1107     item.myName = tr("SMESH_BASE_VERTEX");
1108     p.append(item);
1109
1110     StdMeshersGUI_SubShapeSelectorWdg* aDirectionWidget =
1111       new StdMeshersGUI_SubShapeSelectorWdg();
1112     aDirectionWidget->SetMaxSize(1);
1113     aDirectionWidget->SetSubShType(TopAbs_VERTEX);
1114     QString anEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
1115     QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
1116     if (anEntry == "")
1117       anEntry = h->GetObjectEntry();
1118     aDirectionWidget->SetGeomShapeEntry(anEntry);
1119     aDirectionWidget->SetMainShapeEntry(aMainEntry);
1120     if (!isCreation()) {
1121       SMESH::long_array_var aVec = new SMESH::long_array;
1122       int vertID = h->GetTriaVertex();
1123       if (vertID > 0) {
1124         aVec->length(1);
1125         aVec[0] = vertID;
1126         aDirectionWidget->SetListOfIDs(aVec);
1127       }
1128     }
1129     aDirectionWidget->showPreview(true);
1130
1131     item.myName = tr("SMESH_QUAD_TYPE");
1132     p.append(item);
1133
1134     StdMeshersGUI_QuadrangleParamWdg* aTypeWidget =
1135       new StdMeshersGUI_QuadrangleParamWdg();
1136     if (!isCreation()) {
1137       aTypeWidget->SetType(int(h->GetQuadType()));
1138     }
1139
1140     customWidgets()->append(aDirectionWidget);
1141     customWidgets()->append(aTypeWidget);
1142   }
1143   else
1144     res = false;
1145   return res;
1146 }
1147
1148 //================================================================================
1149 /*!
1150  * \brief tune "standard" control
1151   * \param w - control widget
1152   * \param int - parameter index
1153  */
1154 //================================================================================
1155
1156 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget (QWidget* w, const int) const
1157 {
1158   SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
1159   if( hypType()=="LocalLength" &&  sb )
1160   {
1161     if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PARAM"))
1162       sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "length_precision" );
1163     else if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PRECISION"))
1164       sb->RangeStepAndValidator( 0.0, 1.0, 0.05, "len_tol_precision" );
1165   }
1166   else if( hypType()=="Arithmetic1D" && sb )
1167   {
1168     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "parametric_precision" );
1169   }
1170   else if( hypType()=="MaxLength" && sb )
1171   {
1172     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "length_precision" );
1173     sb->setEnabled( !widget< QCheckBox >( 1 )->isChecked() );
1174   }
1175   else if( hypType()=="MaxElementArea" && sb )
1176   {
1177     sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, "area_precision" );
1178   }
1179   else if( hypType()=="MaxElementVolume" && sb )
1180   {
1181     sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, "vol_precision" );
1182   }
1183   else if( hypType()=="StartEndLength" && sb )
1184   {
1185     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "length_precision" );
1186   }
1187   else if( hypType()=="Deflection1D" && sb )
1188   {
1189     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "parametric_precision" );
1190   }
1191   else if ( sb ) // default validator for possible ancestors
1192   {
1193     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "length_precision" );
1194   }
1195 }
1196
1197 //================================================================================
1198 /*!
1199  * \brief Return dlg title
1200   * \retval QString - title string
1201  */
1202 //================================================================================
1203
1204 QString StdMeshersGUI_StdHypothesisCreator::caption() const
1205 {
1206   return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
1207 }
1208
1209 //================================================================================
1210 /*!
1211  * \brief return pixmap for dlg icon
1212   * \retval QPixmap - 
1213  */
1214 //================================================================================
1215
1216 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
1217 {
1218   QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
1219   return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
1220 }
1221
1222 //================================================================================
1223 /*!
1224  * \brief Return hypothesis type name to show in dlg
1225   * \retval QString - 
1226  */
1227 //================================================================================
1228
1229 QString StdMeshersGUI_StdHypothesisCreator::type() const
1230 {
1231   return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
1232 }
1233
1234 //================================================================================
1235 /*!
1236  * \brief String to insert in "SMESH_%1_HYPOTHESIS" to get hypothesis type name
1237  * from message resouce file
1238   * \param t - hypothesis type
1239   * \retval QString - result string
1240  */
1241 //================================================================================
1242
1243 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
1244 {
1245   static QMap<QString,QString>  types;
1246   if( types.isEmpty() )
1247   {
1248     types.insert( "LocalLength", "LOCAL_LENGTH" );
1249     types.insert( "NumberOfSegments", "NB_SEGMENTS" );
1250     types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
1251     types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
1252     types.insert( "StartEndLength", "START_END_LENGTH" );
1253     types.insert( "Deflection1D", "DEFLECTION1D" );
1254     types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
1255     types.insert( "FixedPoints1D", "FIXED_POINTS_1D" );
1256     types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
1257     types.insert( "ProjectionSource1D", "PROJECTION_SOURCE_1D" );
1258     types.insert( "ProjectionSource2D", "PROJECTION_SOURCE_2D" );
1259     types.insert( "ProjectionSource3D", "PROJECTION_SOURCE_3D" );
1260     types.insert( "ImportSource1D", "IMPORT_SOURCE_1D" );
1261     types.insert( "ImportSource2D", "IMPORT_SOURCE_2D" );
1262     types.insert( "NumberOfLayers", "NUMBER_OF_LAYERS" );
1263     types.insert( "LayerDistribution", "LAYER_DISTRIBUTION" );
1264     types.insert( "NumberOfLayers2D", "NUMBER_OF_LAYERS_2D" );
1265     types.insert( "LayerDistribution2D", "LAYER_DISTRIBUTION" );
1266     types.insert( "SegmentLengthAroundVertex", "SEGMENT_LENGTH_AROUND_VERTEX" );
1267     types.insert( "MaxLength", "MAX_LENGTH" );
1268     types.insert( "QuadrangleParams", "QUADRANGLE_PARAMS" );
1269   }
1270
1271   QString res;
1272   if( types.contains( t ) )
1273     res = types[ t ];
1274
1275   return res;
1276 }
1277
1278
1279 //=======================================================================
1280 //function : getCustomWidget
1281 //purpose  : is called from buildStdFrame()
1282 //=======================================================================
1283
1284 QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
1285                                                               QWidget*         parent,
1286                                                               const int        index) const
1287 {
1288   QWidget* w = 0;
1289   if ( index < customWidgets()->count() ) {
1290     w = customWidgets()->at( index );
1291     if ( w ) {
1292       w->setParent( parent );
1293       w->move( QPoint( 0, 0 ) );
1294     }
1295   }
1296   return w;
1297 }
1298
1299 //================================================================================
1300 /*!
1301  * \brief Set param value taken from a custom widget
1302   * \param param - SMESHGUI_GenericHypothesisCreator::StdParam structure
1303   * \param widget - widget presenting param
1304   * \retval bool - success flag
1305  * 
1306  * this method is called from getStdParamFromDlg()
1307  */
1308 //================================================================================
1309
1310 bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
1311                                                                    QWidget*   widget) const
1312 {
1313   if ( hypType()=="AutomaticLength" ) {
1314     SMESHGUI_SpinBox* w = dynamic_cast<SMESHGUI_SpinBox*>( widget );
1315     if ( w ) {
1316       param.myValue = w->GetValue();
1317       return true;
1318     }
1319   }
1320   if ( hypType() == "MaxLength" ) {
1321     param.myValue = "";
1322     return true;
1323   }
1324   if ( widget->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
1325   {
1326     // show only 1st reference value
1327     if ( true /*widget == getWidgetForParam( 0 )*/) {
1328       const StdMeshersGUI_ObjectReferenceParamWdg * w =
1329         static_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( widget );
1330       param.myValue = w->GetValue();
1331     }
1332     return true;
1333   }
1334   if ( widget->inherits( "StdMeshersGUI_LayerDistributionParamWdg" ))
1335   {
1336     const StdMeshersGUI_LayerDistributionParamWdg * w =
1337       static_cast<const StdMeshersGUI_LayerDistributionParamWdg*>( widget );
1338     param.myValue = w->GetValue();
1339     return true;
1340   }
1341   if ( widget->inherits( "StdMeshersGUI_SubShapeSelectorWdg" ))
1342   {
1343     const StdMeshersGUI_SubShapeSelectorWdg * w =
1344       static_cast<const StdMeshersGUI_SubShapeSelectorWdg*>( widget );
1345     param.myValue = w->GetValue();
1346     return true;
1347   }
1348   if ( widget->inherits( "StdMeshersGUI_QuadrangleParamWdg" ))
1349   {
1350     //const StdMeshersGUI_QuadrangleParamWdg * w =
1351     //  static_cast<const StdMeshersGUI_QuadrangleParamWdg*>( widget );
1352     param.myValue = "QuadType";
1353     return true;
1354   }
1355   if ( widget->inherits( "StdMeshersGUI_FixedPointsParamWdg" ))
1356   {
1357     const StdMeshersGUI_FixedPointsParamWdg * w =
1358       static_cast<const StdMeshersGUI_FixedPointsParamWdg*>( widget );
1359     param.myValue = w->GetValue();
1360     return true;
1361   }
1362   if ( widget->inherits( "QCheckBox" ))
1363   {
1364     //const QCheckBox * w = static_cast<const QCheckBox*>( widget );
1365     //param.myValue = w->isChecked();
1366     return true;
1367   }
1368   return false;
1369 }
1370
1371 //================================================================================
1372 /*!
1373  * \brief called when operation cancelled
1374  */
1375 //================================================================================
1376
1377 void StdMeshersGUI_StdHypothesisCreator::onReject()
1378 {
1379   if ( hypType().startsWith("ProjectionSource" ) ||
1380        hypType().startsWith("ImportSource" ))
1381   {
1382     // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
1383     deactivateObjRefParamWdg( customWidgets() );
1384   }
1385 }
1386
1387 //================================================================================
1388 /*!
1389  * \brief Update widgets dependent on paramWidget
1390  */
1391 //================================================================================
1392
1393 void StdMeshersGUI_StdHypothesisCreator::valueChanged( QWidget* paramWidget)
1394 {
1395   if ( hypType() == "MaxLength" && paramWidget == getWidgetForParam(1) )
1396   {
1397     getWidgetForParam(0)->setEnabled( !widget< QCheckBox >( 1 )->isChecked() );
1398     if ( !getWidgetForParam(0)->isEnabled() ) {
1399       StdMeshers::StdMeshers_MaxLength_var h =
1400         StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis() );
1401       widget< QtxDoubleSpinBox >( 0 )->setValue( h->GetPreestimatedLength() );
1402     }
1403   }
1404   else if ( hypType().startsWith("ImportSource") && paramWidget == getWidgetForParam(1) )
1405   {
1406     QCheckBox* toCopyMesh   = (QCheckBox*) paramWidget;
1407     QCheckBox* toCopyGroups = widget< QCheckBox >( 2 );
1408     if ( !toCopyMesh->isChecked() )
1409     {
1410       toCopyGroups->setChecked( false );
1411       toCopyGroups->setEnabled( false );
1412     }
1413     else
1414     {
1415       toCopyGroups->setEnabled( true );
1416     }
1417   }
1418 }
1419
1420 //================================================================================
1421 /*!
1422  *
1423  */
1424 //================================================================================
1425
1426 bool StdMeshersGUI_StdHypothesisCreator::initVariableName(SMESH::ListOfParameters_var theParameters, 
1427                                                           StdParam &theParams, 
1428                                                           int order) const
1429 {
1430   QString aVaribaleName = (theParameters->length() > order) ? QString(theParameters[order].in()) : QString("");
1431   theParams.isVariable = !aVaribaleName.isEmpty();
1432   if(theParams.isVariable) 
1433     theParams.myValue = aVaribaleName;
1434
1435   return theParams.isVariable;
1436 }