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