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