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