Salome HOME
56e31b5a6deae6b463b7a12a4269b2d57110474e
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_StdHypothesisCreator.cxx
1 //  Copyright (C) 2007-2008  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 <SMESH_TypeFilter.hxx>
33 #include <SMESH_NumberFilter.hxx>
34 #include <StdMeshersGUI_ObjectReferenceParamWdg.h>
35 #include <StdMeshersGUI_LayerDistributionParamWdg.h>
36 #include <SALOMEDSClient_Study.hxx>
37
38 // SALOME GUI includes
39 #include <SUIT_ResourceMgr.h>
40
41 // IDL includes
42 #include <SALOMEconfig.h>
43 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
44 #include CORBA_SERVER_HEADER(SMESH_Mesh)
45
46 // Qt includes
47 #include <QHBoxLayout>
48 #include <QSlider>
49 #include <QLabel>
50 #include <QCheckBox>
51
52 const double VALUE_MAX = 1.0e+15, // COORD_MAX
53              VALUE_MAX_2  = VALUE_MAX * VALUE_MAX,
54              VALUE_MAX_3  = VALUE_MAX_2 * VALUE_MAX,
55              VALUE_SMALL = 1.0e-15,
56              VALUE_SMALL_2 = VALUE_SMALL * VALUE_SMALL,
57              VALUE_SMALL_3 = VALUE_SMALL_2 * VALUE_SMALL;
58
59 //================================================================================
60 /*!
61  * \brief Constructor
62   * \param type - hypothesis type
63  */
64 //================================================================================
65
66 StdMeshersGUI_StdHypothesisCreator::StdMeshersGUI_StdHypothesisCreator( const QString& type )
67 : SMESHGUI_GenericHypothesisCreator( type )
68 {
69 }
70
71 //================================================================================
72 /*!
73  * \brief Destructor
74  */
75 //================================================================================
76
77 StdMeshersGUI_StdHypothesisCreator::~StdMeshersGUI_StdHypothesisCreator()
78 {
79 }
80
81 //================================================================================
82 /*!
83  * \brief Return widget for i-th hypothesis parameter (got from myParamWidgets)
84   * \param i - index of hypothesis parameter
85   * \retval QWidget* - found widget
86  */
87 //================================================================================
88
89 QWidget* StdMeshersGUI_StdHypothesisCreator::getWidgetForParam( int i ) const
90 {
91   QWidget* w = 0;
92   if ( isCreation() ) ++i; // skip widget of 'name' parameter
93
94   if ( i < myCustomWidgets.count() ) {
95     QList<QWidget*>::const_iterator anIt  = myCustomWidgets.begin();
96     QList<QWidget*>::const_iterator aLast = myCustomWidgets.end();
97     for ( int j = 0 ; !w && anIt != aLast; ++anIt, ++j )
98       if ( i == j )
99         w = *anIt;
100   }
101   if ( !w ) {
102     // list has no at() const, so we iterate
103     QList<QWidget*>::const_iterator anIt  = widgets().begin();
104     QList<QWidget*>::const_iterator aLast = widgets().end();
105     for( int j = 0; !w && anIt!=aLast; anIt++, ++j ) {
106       if ( i == j )
107         w = *anIt;
108     }
109   }
110   return w;
111 }
112
113 //================================================================================
114 /*!
115  * \brief Allow modifing myCustomWidgets in const methods
116   * \retval ListOfWidgets* - non-const pointer to myCustomWidgets
117  */
118 //================================================================================
119
120 StdMeshersGUI_StdHypothesisCreator::ListOfWidgets*
121 StdMeshersGUI_StdHypothesisCreator::customWidgets() const
122 {
123   return const_cast< ListOfWidgets* >( & myCustomWidgets );
124 }
125
126 //================================================================================
127 /*!
128  * \brief Builds dlg layout
129   * \retval QFrame* - the built widget
130  */
131 //================================================================================
132
133 QFrame* StdMeshersGUI_StdHypothesisCreator::buildFrame()
134 {
135   return buildStdFrame();
136 }
137
138 //================================================================================
139 /*!
140  * \brief Initialise parameter values in controls
141  */
142 //================================================================================
143
144 void StdMeshersGUI_StdHypothesisCreator::retrieveParams() const
145 {
146   // buildStdFrame() sets values itself calling stdParams()
147
148   if ( hypType().startsWith("ProjectionSource" ))
149   {
150     // we use this method to connect depending custom widgets
151     StdMeshersGUI_ObjectReferenceParamWdg* widgetToActivate = 0;
152     ListOfWidgets::const_iterator anIt = myCustomWidgets.begin();
153     for ( ; anIt != myCustomWidgets.end(); anIt++)
154     {
155       if ( *anIt && (*anIt)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
156       {
157         StdMeshersGUI_ObjectReferenceParamWdg * w1 =
158           ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
159         ListOfWidgets::const_iterator anIt2 = anIt;
160         for ( ++anIt2; anIt2 != myCustomWidgets.end(); anIt2++)
161           if ( *anIt2 && (*anIt2)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
162           {
163             StdMeshersGUI_ObjectReferenceParamWdg * w2 =
164               ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt2 );
165             w1->AvoidSimultaneousSelection( w2 );
166           }
167         if ( !widgetToActivate )
168           widgetToActivate = w1;
169       }
170     }
171     if ( widgetToActivate )
172       widgetToActivate->activateSelection();
173   }
174
175   if ( dlg() )
176     dlg()->setMinimumSize( dlg()->minimumSizeHint().width(), dlg()->minimumSizeHint().height() );
177 }
178
179 namespace {
180
181   //================================================================================
182   /*!
183    * \brief Widget: slider with left and right labels
184    */
185   //================================================================================
186
187   class TDoubleSliderWith2Lables: public QWidget
188   {
189   public:
190     TDoubleSliderWith2Lables( const QString& leftLabel, const QString& rightLabel,
191                               const double   initValue, const double   bottom,
192                               const double   top      , const double   precision,
193                               QWidget *      parent=0 , const char *   name=0 )
194       :QWidget(parent), _bottom(bottom), _precision(precision)
195     {
196       setObjectName(name);
197
198       QHBoxLayout* aHBoxL = new QHBoxLayout(this);
199       
200       if ( !leftLabel.isEmpty() ) {
201         QLabel* aLeftLabel = new QLabel( this );
202         aLeftLabel->setText( leftLabel );
203         aHBoxL->addWidget( aLeftLabel );
204       }
205
206       _slider = new QSlider( Qt::Horizontal, this );
207       _slider->setRange( 0, toInt( top ));
208       _slider->setValue( toInt( initValue ));
209       aHBoxL->addWidget( _slider );
210
211       if ( !rightLabel.isEmpty() ) {
212         QLabel* aRightLabel = new QLabel( this );
213         aRightLabel->setText( rightLabel );
214         aHBoxL->addWidget( aRightLabel );
215       }
216
217       setLayout( aHBoxL );
218     }
219     double value() const { return _bottom + _slider->value() * _precision; }
220     QSlider * getSlider() const { return _slider; }
221     int toInt( double val ) const { return (int) ceil(( val - _bottom ) / _precision ); }
222   private:
223     double _bottom, _precision;
224     QSlider * _slider;
225   };
226
227   //================================================================================
228   /*!
229    * \brief Retrieve GEOM_Object held by widget
230    */
231   //================================================================================
232
233   inline GEOM::GEOM_Object_var geomFromWdg(const QWidget* wdg)
234   {
235     const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
236       dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
237     if ( objRefWdg )
238       return objRefWdg->GetObject< GEOM::GEOM_Object >();
239
240     return GEOM::GEOM_Object::_nil();
241   }
242   //================================================================================
243   /*!
244    * \brief Retrieve SMESH_Mesh held by widget
245    */
246   //================================================================================
247
248   inline SMESH::SMESH_Mesh_var meshFromWdg(const QWidget* wdg)
249   {
250     const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
251       dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
252     if ( objRefWdg )
253       return objRefWdg->GetObject< SMESH::SMESH_Mesh >();
254
255     return SMESH::SMESH_Mesh::_nil();
256   }
257   //================================================================================
258   /*!
259    * \brief creates a filter for selection of shapes of given dimension
260     * \param dim - dimension
261     * \param subShapeType - required type of subshapes, number of which must be \a nbSubShapes
262     * \param nbSubShapes - number of subshapes of given type
263     * \param closed - required closeness flag of a shape
264     * \retval SUIT_SelectionFilter* - created filter
265    */
266   //================================================================================
267
268   SUIT_SelectionFilter* filterForShapeOfDim(const int        dim,
269                                             TopAbs_ShapeEnum subShapeType = TopAbs_SHAPE,
270                                             const int        nbSubShapes = 0,
271                                             bool             closed = false)
272   {
273     TColStd_MapOfInteger shapeTypes;
274     switch ( dim ) {
275     case 0: shapeTypes.Add( TopAbs_VERTEX ); break;
276     case 1:
277       if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_EDGE;
278       shapeTypes.Add( TopAbs_EDGE );
279       shapeTypes.Add( TopAbs_COMPOUND ); // for a group
280       break;
281     case 2:
282       if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_FACE;
283       shapeTypes.Add( TopAbs_FACE );
284       shapeTypes.Add( TopAbs_COMPOUND ); // for a group
285       break;
286     case 3:
287       shapeTypes.Add( TopAbs_SHELL );
288       shapeTypes.Add( TopAbs_SOLID );
289       shapeTypes.Add( TopAbs_COMPSOLID );
290       shapeTypes.Add( TopAbs_COMPOUND );
291       break;
292     }
293     return new SMESH_NumberFilter("GEOM", subShapeType, nbSubShapes,
294                                   shapeTypes, GEOM::GEOM_Object::_nil(), closed);
295   }
296
297   //================================================================================
298   /*!
299    * \brief Create a widget for object selection
300     * \param object - initial object
301     * \param filter - selection filter
302     * \retval QWidget* - created widget
303    */
304   //================================================================================
305
306   QWidget* newObjRefParamWdg( SUIT_SelectionFilter* filter,
307                               CORBA::Object_var     object)
308   {
309     StdMeshersGUI_ObjectReferenceParamWdg* w =
310       new StdMeshersGUI_ObjectReferenceParamWdg( filter, 0);
311     w->SetObject( object.in() );
312     return w;
313   }
314
315   //================================================================================
316   /*!
317    * \brief calls deactivateSelection() for StdMeshersGUI_ObjectReferenceParamWdg
318     * \param widgetList - list of widgets
319    */
320   //================================================================================
321
322   void deactivateObjRefParamWdg( QList<QWidget*>* widgetList )
323   {
324     StdMeshersGUI_ObjectReferenceParamWdg* w = 0;
325     QList<QWidget*>::iterator anIt  = widgetList->begin();
326     QList<QWidget*>::iterator aLast = widgetList->end();
327     for ( ; anIt != aLast; anIt++ ) {
328       if ( (*anIt) && (*anIt)->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
329       {
330         w = (StdMeshersGUI_ObjectReferenceParamWdg* )( *anIt );
331         w->deactivateSelection();
332       }
333     }
334   }
335 }
336
337 //================================================================================
338 /*!
339  * \brief Check parameter values before accept()
340   * \retval bool - true if OK
341  */
342 //================================================================================
343
344 bool StdMeshersGUI_StdHypothesisCreator::checkParams( QString& msg ) const
345 {
346   if( !SMESHGUI_GenericHypothesisCreator::checkParams( msg ) )
347     return false;
348
349   // check if object reference parameter is set, as it has no default value
350   bool ok = true;
351   if ( hypType().startsWith("ProjectionSource" ))
352   {
353     StdMeshersGUI_ObjectReferenceParamWdg* w =
354       widget< StdMeshersGUI_ObjectReferenceParamWdg >( 0 );
355     ok = ( w->IsObjectSelected() );
356     if ( !ok ) w->SetObject( CORBA::Object::_nil() );
357     int nbAssocVert = ( hypType() == "ProjectionSource1D" ? 1 : 2 );
358     for ( int i = 0; ok && i < nbAssocVert; i += 2)
359     {
360       QString srcV, tgtV;
361       StdMeshersGUI_ObjectReferenceParamWdg* w1 =
362         widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+2 );
363       StdMeshersGUI_ObjectReferenceParamWdg* w2 =
364         widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+3 );
365       srcV = w1->GetValue();
366       tgtV = w2->GetValue();
367       ok = (( srcV.isEmpty()  && tgtV.isEmpty() ) ||
368             ( !srcV.isEmpty() && !tgtV.isEmpty() && srcV != tgtV ));
369       if ( !ok ) {
370         w1->SetObject( CORBA::Object::_nil() );
371         w2->SetObject( CORBA::Object::_nil() );
372       }
373     }
374
375     // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
376     if ( ok )
377       deactivateObjRefParamWdg( customWidgets() );
378   }
379   else if ( hypType() == "LayerDistribution" )
380   {
381     StdMeshersGUI_LayerDistributionParamWdg* w = 
382       widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
383     ok = ( w && w->IsOk() );
384   }
385   return ok;
386 }
387
388 //================================================================================
389 /*!
390  * \brief Store params from GUI controls to a hypothesis
391   * \retval QString - text representation of parameters
392  */
393 //================================================================================
394
395 QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
396 {
397   ListOfStdParams params;
398   bool res = getStdParamFromDlg( params );
399   if( isCreation() )
400   {
401     SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().toLatin1().data() );
402     params.erase( params.begin() );
403   }
404
405   QString valueStr = stdParamValues( params );
406   QStringList aVariablesList = getVariablesFromDlg();
407
408   if( res && !params.isEmpty() )
409   {
410     if( hypType()=="LocalLength" )
411     {
412       StdMeshers::StdMeshers_LocalLength_var h =
413         StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
414
415       h->SetLength( params[0].myValue.toDouble() );
416       h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
417       h->SetPrecision( params[1].myValue.toDouble() );
418       h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
419     }
420     else if( hypType()=="MaxLength" )
421     {
422       StdMeshers::StdMeshers_MaxLength_var h =
423         StdMeshers::StdMeshers_MaxLength::_narrow( hypothesis() );
424
425       h->SetLength( params[0].myValue.toDouble() );
426       h->SetUsePreestimatedLength( widget< QCheckBox >( 1 )->isChecked() );
427       if ( !h->HavePreestimatedLength() && !h->_is_equivalent( initParamsHypothesis() )) {
428         StdMeshers::StdMeshers_MaxLength_var hInit =
429           StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis() );
430         h->SetPreestimatedLength( hInit->GetPreestimatedLength() );
431       }
432     }
433     else if( hypType()=="SegmentLengthAroundVertex" )
434     {
435       StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
436         StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hypothesis() );
437
438       h->SetLength( params[0].myValue.toDouble() );
439       h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
440     }
441     else if( hypType()=="Arithmetic1D" )
442     {
443       StdMeshers::StdMeshers_Arithmetic1D_var h =
444         StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
445
446       h->SetLength( params[0].myValue.toDouble(), true );
447       h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
448       h->SetLength( params[1].myValue.toDouble(), false );
449       h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
450     }
451     else if( hypType()=="MaxElementArea" )
452     {
453       StdMeshers::StdMeshers_MaxElementArea_var h =
454         StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
455       h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
456       h->SetMaxElementArea( params[0].myValue.toDouble() );
457     }
458     else if( hypType()=="MaxElementVolume" )
459     {
460       StdMeshers::StdMeshers_MaxElementVolume_var h =
461         StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
462
463       h->SetMaxElementVolume( params[0].myValue.toDouble() );
464       h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
465     }
466     else if( hypType()=="StartEndLength" )
467     {
468       StdMeshers::StdMeshers_StartEndLength_var h =
469         StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
470
471       h->SetLength( params[0].myValue.toDouble(), true );
472       h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
473       h->SetLength( params[1].myValue.toDouble(), false );
474       h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
475     }
476     else if( hypType()=="Deflection1D" )
477     {
478       StdMeshers::StdMeshers_Deflection1D_var h =
479         StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
480       h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
481       h->SetDeflection( params[0].myValue.toDouble() );
482     }
483     else if( hypType()=="AutomaticLength" )
484     {
485       StdMeshers::StdMeshers_AutomaticLength_var h =
486         StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() );
487
488       h->SetFineness( params[0].myValue.toDouble() );
489     }
490     else if( hypType()=="NumberOfLayers" )
491     {
492       StdMeshers::StdMeshers_NumberOfLayers_var h =
493         StdMeshers::StdMeshers_NumberOfLayers::_narrow( hypothesis() );
494
495       h->SetNumberOfLayers( params[0].myValue.toInt() );
496       h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
497     }
498     else if( hypType()=="LayerDistribution" )
499     {
500       StdMeshers::StdMeshers_LayerDistribution_var h =
501         StdMeshers::StdMeshers_LayerDistribution::_narrow( hypothesis() );
502       StdMeshersGUI_LayerDistributionParamWdg* w = 
503         widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
504       
505       h->SetLayerDistribution( w->GetHypothesis() );
506       h->SetParameters(w->GetHypothesis()->GetParameters());
507       w->GetHypothesis()->ClearParameters();
508     }
509     else if( hypType()=="ProjectionSource1D" )
510     {
511       StdMeshers::StdMeshers_ProjectionSource1D_var h =
512         StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hypothesis() );
513
514       h->SetSourceEdge       ( geomFromWdg ( getWidgetForParam( 0 )));
515       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
516       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )),
517                                geomFromWdg ( getWidgetForParam( 3 )));
518     }
519     else if( hypType()=="ProjectionSource2D" )
520     {
521       StdMeshers::StdMeshers_ProjectionSource2D_var h =
522         StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hypothesis() );
523
524       h->SetSourceFace       ( geomFromWdg ( getWidgetForParam( 0 )));
525       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
526       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
527                                geomFromWdg ( getWidgetForParam( 4 )), // src2
528                                geomFromWdg ( getWidgetForParam( 3 )), // tgt1
529                                geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
530     }
531     else if( hypType()=="ProjectionSource3D" )
532     {
533       StdMeshers::StdMeshers_ProjectionSource3D_var h =
534         StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hypothesis() );
535
536       h->SetSource3DShape    ( geomFromWdg ( getWidgetForParam( 0 )));
537       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
538       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
539                                geomFromWdg ( getWidgetForParam( 4 )), // src2
540                                geomFromWdg ( getWidgetForParam( 3 )), // tgt1
541                                geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
542     }
543   }
544   return valueStr;
545 }
546
547 //================================================================================
548 /*!
549  * \brief Return parameter values as SMESHGUI_GenericHypothesisCreator::StdParam
550   * \param p - list of parameters
551   * \retval bool - success flag
552   *
553   * Is called from SMESHGUI_GenericHypothesisCreator::buildStdFrame().
554   * Parameters will be shown using "standard" controls:
555   *   Int by QtxIntSpinBox
556   *   Double by SMESHGUI_SpinBox
557   *   String by QLineEdit
558   * getCustomWidget() allows to redefine control for a parameter
559  */
560 //================================================================================
561
562 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
563 {
564   bool res = true;
565   SMESHGUI_GenericHypothesisCreator::StdParam item;
566
567   p.clear();
568   customWidgets()->clear();
569   if( isCreation() )
570   {
571     HypothesisData* data = SMESH::GetHypothesisData( hypType() );
572     item.myName = tr( "SMESH_NAME" );
573     item.myValue = data ? hypName() : QString();
574     p.append( item );
575     customWidgets()->append(0);
576   }
577   
578   SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
579   SMESH::ListOfParameters_var aParameters = hyp->GetLastParameters();
580
581   if( hypType()=="LocalLength" )
582   {
583     StdMeshers::StdMeshers_LocalLength_var h =
584       StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
585     
586     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
587     if(!initVariableName(aParameters,item,0))
588       item.myValue = h->GetLength();
589     p.append( item );     
590     
591     item.myName = tr("SMESH_LOCAL_LENGTH_PRECISION");
592     if(!initVariableName(aParameters,item,1))
593       item.myValue = h->GetPrecision(); 
594     p.append( item );
595     
596   }
597   else if( hypType()=="MaxLength" )
598   {
599     StdMeshers::StdMeshers_MaxLength_var h =
600       StdMeshers::StdMeshers_MaxLength::_narrow( hyp );
601     // try to set a right preestimated length to edited hypothesis
602     bool noPreestimatedAtEdition = false;
603     if ( !isCreation() ) {
604       StdMeshers::StdMeshers_MaxLength_var initHyp =
605         StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis(true) );
606       noPreestimatedAtEdition =
607         ( initHyp->_is_nil() || !initHyp->HavePreestimatedLength() );
608       if ( !noPreestimatedAtEdition )
609         h->SetPreestimatedLength( initHyp->GetPreestimatedLength() );
610     }
611
612     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
613     item.myValue = h->GetLength();
614     p.append( item );
615     customWidgets()->append(0);
616
617     item.myName = tr("SMESH_USE_PREESTIMATED_LENGTH");
618     p.append( item );
619     QCheckBox* aQCheckBox = new QCheckBox(dlg());
620     if ( !noPreestimatedAtEdition && h->HavePreestimatedLength() ) {
621       aQCheckBox->setChecked( h->GetUsePreestimatedLength() );
622       connect( aQCheckBox, SIGNAL(  stateChanged(int) ), this, SLOT( onValueChanged() ) );
623     }
624     else {
625       aQCheckBox->setChecked( false );
626       aQCheckBox->setEnabled( false );
627     }
628     customWidgets()->append( aQCheckBox );
629   }
630   else if( hypType()=="SegmentLengthAroundVertex" )
631   {
632     StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
633       StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hyp );
634
635     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
636     if(!initVariableName(aParameters,item,0))
637       item.myValue = h->GetLength();
638     
639     p.append( item );
640   }
641   else if( hypType()=="Arithmetic1D" )
642   {
643     StdMeshers::StdMeshers_Arithmetic1D_var h =
644       StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
645
646     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
647     if(!initVariableName(aParameters,item,0))
648       item.myValue = h->GetLength( true );
649     p.append( item );
650
651     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
652     if(!initVariableName(aParameters,item,1))
653       item.myValue = h->GetLength( false );
654     p.append( item );
655   }
656   else if( hypType()=="MaxElementArea" )
657   {
658     StdMeshers::StdMeshers_MaxElementArea_var h =
659       StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
660
661     item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
662     if(!initVariableName(aParameters,item,0))
663       item.myValue = h->GetMaxElementArea();
664     p.append( item );
665     
666   }
667   else if( hypType()=="MaxElementVolume" )
668   {
669     StdMeshers::StdMeshers_MaxElementVolume_var h =
670       StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
671
672     item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
673     if(!initVariableName(aParameters,item,0))
674       item.myValue = h->GetMaxElementVolume();
675     p.append( item );
676   }
677   else if( hypType()=="StartEndLength" )
678   {
679     StdMeshers::StdMeshers_StartEndLength_var h =
680       StdMeshers::StdMeshers_StartEndLength::_narrow( hyp );
681
682     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
683
684     if(!initVariableName(aParameters,item,0)) 
685       item.myValue = h->GetLength( true );
686     p.append( item );
687
688     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
689     if(!initVariableName(aParameters,item,1)) 
690       item.myValue = h->GetLength( false );
691     p.append( item );
692     
693   }
694   else if( hypType()=="Deflection1D" )
695   {
696     StdMeshers::StdMeshers_Deflection1D_var h =
697       StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
698     
699     item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
700     if(!initVariableName(aParameters,item,0)) 
701       item.myValue = h->GetDeflection();
702     p.append( item );
703   }
704   else if( hypType()=="AutomaticLength" )
705   {
706     StdMeshers::StdMeshers_AutomaticLength_var h =
707       StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
708
709     item.myName = tr( "SMESH_FINENESS_PARAM" );
710     //item.myValue = h->GetFineness();
711     p.append( item );
712     customWidgets()->append
713       ( new TDoubleSliderWith2Lables( "0 ", " 1", h->GetFineness(), 0, 1, 0.01, 0 ));
714   }
715   else if( hypType()=="NumberOfLayers" )
716   {
717     StdMeshers::StdMeshers_NumberOfLayers_var h =
718       StdMeshers::StdMeshers_NumberOfLayers::_narrow( hyp );
719
720     item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
721     if(!initVariableName(aParameters,item,0))     
722       item.myValue = (int) h->GetNumberOfLayers();
723     p.append( item );
724   }
725   else if( hypType()=="LayerDistribution" )
726     {
727       StdMeshers::StdMeshers_LayerDistribution_var h =
728       StdMeshers::StdMeshers_LayerDistribution::_narrow( hyp );
729
730     item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
731     
732     //Set into not published hypo last variables
733     QStringList aLastVarsList;
734     for(int i = 0;i<aParameters->length();i++) 
735       aLastVarsList.append(QString(aParameters[i].in()));
736
737     if(!aLastVarsList.isEmpty())
738       h->GetLayerDistribution()->SetLastParameters(SMESHGUI::JoinObjectParameters(aLastVarsList));
739     
740     customWidgets()->append
741       ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
742   }
743   else if( hypType()=="ProjectionSource1D" )
744   {
745     StdMeshers::StdMeshers_ProjectionSource1D_var h =
746       StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hyp );
747
748     item.myName = tr( "SMESH_SOURCE_EDGE" ); p.append( item );
749     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 1 ),
750                                                h->GetSourceEdge()));
751     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
752     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
753                                                h->GetSourceMesh()));
754     item.myName = tr( "SMESH_SOURCE_VERTEX" ); p.append( item );
755     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
756                                                h->GetSourceVertex()));
757     item.myName = tr( "SMESH_TARGET_VERTEX" ); p.append( item );
758     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
759                                                h->GetTargetVertex()));
760   }
761   else if( hypType()=="ProjectionSource2D" )
762   {
763     StdMeshers::StdMeshers_ProjectionSource2D_var h =
764       StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hyp );
765
766     item.myName = tr( "SMESH_SOURCE_FACE" ); p.append( item );
767     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 2 ),
768                                                h->GetSourceFace()));
769     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
770     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
771                                                h->GetSourceMesh()));
772     item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
773     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
774                                                h->GetSourceVertex( 1 )));
775     item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
776     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
777                                                h->GetTargetVertex( 1 )));
778     item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
779     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
780                                                h->GetSourceVertex( 2 )));
781     item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
782     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
783                                                h->GetTargetVertex( 2 )));
784   }
785   else if( hypType()=="ProjectionSource3D" )
786   {
787     StdMeshers::StdMeshers_ProjectionSource3D_var h =
788       StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hyp );
789
790     item.myName = tr( "SMESH_SOURCE_3DSHAPE" ); p.append( item );
791     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 3, TopAbs_FACE, 6, true ),
792                                                h->GetSource3DShape()));
793     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
794     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
795                                                h->GetSourceMesh()));
796     item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
797     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
798                                                h->GetSourceVertex( 1 )));
799     item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
800     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
801                                                h->GetTargetVertex( 1 )));
802     item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
803     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
804                                                h->GetSourceVertex( 2 )));
805     item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
806     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
807                                                h->GetTargetVertex( 2 )));
808   }
809   else
810     res = false;
811   return res;
812 }
813
814 //================================================================================
815 /*!
816  * \brief tune "standard" control
817   * \param w - control widget
818   * \param int - parameter index
819  */
820 //================================================================================
821
822 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget (QWidget* w, const int) const
823 {
824   SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
825   if( hypType()=="LocalLength" &&  sb )
826   {
827     if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PARAM"))
828       sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
829     else if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PRECISION"))
830       sb->RangeStepAndValidator( 0.0, 1.0, 0.05, 7 );
831   }
832   else if( hypType()=="Arithmetic1D" && sb )
833   {
834     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
835   }
836   else if( hypType()=="MaxLength" && sb )
837   {
838     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
839     sb->setEnabled( !widget< QCheckBox >( 1 )->isChecked() );
840   }
841   else if( hypType()=="MaxElementArea" && sb )
842   {
843     sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6 );
844   }
845   else if( hypType()=="MaxElementVolume" && sb )
846   {
847     sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6 );
848   }
849   else if( hypType()=="StartEndLength" && sb )
850   {
851     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
852   }
853   else if( hypType()=="Deflection1D" && sb )
854   {
855     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
856   }
857   else if ( sb ) // default validator for possible ancestors
858   {
859     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
860   }
861 }
862
863 //================================================================================
864 /*!
865  * \brief Return dlg title
866   * \retval QString - title string
867  */
868 //================================================================================
869
870 QString StdMeshersGUI_StdHypothesisCreator::caption() const
871 {
872   return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
873 }
874
875 //================================================================================
876 /*!
877  * \brief return pixmap for dlg icon
878   * \retval QPixmap - 
879  */
880 //================================================================================
881
882 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
883 {
884   QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
885   return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
886 }
887
888 //================================================================================
889 /*!
890  * \brief Return hypothesis type name to show in dlg
891   * \retval QString - 
892  */
893 //================================================================================
894
895 QString StdMeshersGUI_StdHypothesisCreator::type() const
896 {
897   return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
898 }
899
900 //================================================================================
901 /*!
902  * \brief String to insert in "SMESH_%1_HYPOTHESIS" to get hypothesis type name
903  * from message resouce file
904   * \param t - hypothesis type
905   * \retval QString - result string
906  */
907 //================================================================================
908
909 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
910 {
911   static QMap<QString,QString>  types;
912   if( types.isEmpty() )
913   {
914     types.insert( "LocalLength", "LOCAL_LENGTH" );
915     types.insert( "NumberOfSegments", "NB_SEGMENTS" );
916     types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
917     types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
918     types.insert( "StartEndLength", "START_END_LENGTH" );
919     types.insert( "Deflection1D", "DEFLECTION1D" );
920     types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
921     types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
922     types.insert( "ProjectionSource1D", "PROJECTION_SOURCE_1D" );
923     types.insert( "ProjectionSource2D", "PROJECTION_SOURCE_2D" );
924     types.insert( "ProjectionSource3D", "PROJECTION_SOURCE_3D" );
925     types.insert( "NumberOfLayers", "NUMBER_OF_LAYERS" );
926     types.insert( "LayerDistribution", "LAYER_DISTRIBUTION" );
927     types.insert( "SegmentLengthAroundVertex", "SEGMENT_LENGTH_AROUND_VERTEX" );
928     types.insert( "MaxLength", "MAX_LENGTH" );
929   }
930
931   QString res;
932   if( types.contains( t ) )
933     res = types[ t ];
934
935   return res;
936 }
937
938
939 //=======================================================================
940 //function : getCustomWidget
941 //purpose  : is called from buildStdFrame()
942 //=======================================================================
943
944 QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
945                                                               QWidget*         parent,
946                                                               const int        index) const
947 {
948   QWidget* w = 0;
949   if ( index < customWidgets()->count() ) {
950     w = customWidgets()->at( index );
951     if ( w ) {
952       w->setParent( parent );
953       w->move( QPoint( 0, 0 ) );
954     }
955   }
956   return w;
957 }
958
959 //================================================================================
960 /*!
961  * \brief Set param value taken from a custom widget
962   * \param param - SMESHGUI_GenericHypothesisCreator::StdParam structure
963   * \param widget - widget presenting param
964   * \retval bool - success flag
965  * 
966  * this method is called from getStdParamFromDlg()
967  */
968 //================================================================================
969
970 bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
971                                                                    QWidget*   widget) const
972 {
973   if ( hypType()=="AutomaticLength" ) {
974     TDoubleSliderWith2Lables* w = dynamic_cast<TDoubleSliderWith2Lables*>( widget );
975     if ( w ) {
976       param.myValue = w->value();
977       return true;
978     }
979   }
980   if ( hypType() == "MaxLength" ) {
981     param.myValue = "";
982     return true;
983   }
984   if ( widget->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
985   {
986     // show only 1st reference value
987     if ( true /*widget == getWidgetForParam( 0 )*/) {
988       const StdMeshersGUI_ObjectReferenceParamWdg * w =
989         static_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( widget );
990       param.myValue = w->GetValue();
991     }
992     return true;
993   }
994   if ( widget->inherits( "StdMeshersGUI_LayerDistributionParamWdg" ))
995   {
996     const StdMeshersGUI_LayerDistributionParamWdg * w =
997       static_cast<const StdMeshersGUI_LayerDistributionParamWdg*>( widget );
998     param.myValue = w->GetValue();
999     return true;
1000   }
1001   return false;
1002 }
1003
1004 //================================================================================
1005 /*!
1006  * \brief called when operation cancelled
1007  */
1008 //================================================================================
1009
1010 void StdMeshersGUI_StdHypothesisCreator::onReject()
1011 {
1012   if ( hypType().startsWith("ProjectionSource" ))
1013   {
1014     // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
1015     deactivateObjRefParamWdg( customWidgets() );
1016   }
1017 }
1018
1019 //================================================================================
1020 /*!
1021  * \brief 
1022  */
1023 //================================================================================
1024
1025 void StdMeshersGUI_StdHypothesisCreator::valueChanged( QWidget* paramWidget)
1026 {
1027   if ( hypType() == "MaxLength" && paramWidget == getWidgetForParam(1) ) {
1028     getWidgetForParam(0)->setEnabled( !widget< QCheckBox >( 1 )->isChecked() );
1029     if ( !getWidgetForParam(0)->isEnabled() ) {
1030       StdMeshers::StdMeshers_MaxLength_var h =
1031         StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis() );
1032       widget< QtxDoubleSpinBox >( 0 )->setValue( h->GetPreestimatedLength() );
1033     }
1034   }
1035 }
1036
1037 //================================================================================
1038 /*!
1039  *
1040  */
1041 //================================================================================
1042
1043 bool StdMeshersGUI_StdHypothesisCreator::initVariableName(SMESH::ListOfParameters_var theParameters, 
1044                                                           StdParam &theParams, 
1045                                                           int order) const
1046 {
1047   QString aVaribaleName = (theParameters->length() > order) ? QString(theParameters[order].in()) : QString("");
1048   theParams.isVariable = !aVaribaleName.isEmpty();
1049   if(theParams.isVariable) 
1050     theParams.myValue = aVaribaleName;
1051
1052   return theParams.isVariable;
1053 }