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