Salome HOME
Merging with WPdev
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_StdHypothesisCreator.cxx
1 //  SMESH StdMeshersGUI : GUI for plugged-in meshers
2 //
3 //  Copyright (C) 2003  CEA
4 // 
5 //  This library is free software; you can redistribute it and/or 
6 //  modify it under the terms of the GNU Lesser General Public 
7 //  License as published by the Free Software Foundation; either 
8 //  version 2.1 of the License. 
9 // 
10 //  This library is distributed in the hope that it will be useful, 
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 //  Lesser General Public License for more details. 
14 // 
15 //  You should have received a copy of the GNU Lesser General Public 
16 //  License along with this library; if not, write to the Free Software 
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
18 // 
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 //
22 //
23 //  File   : StdMeshersGUI_StdHypothesisCreator.cxx
24 //  Author : Alexander SOLOVYOV
25 //  Module : SMESH
26 //  $Header: /home/server/cvs/SMESH/SMESH_SRC/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx
27
28 #include "StdMeshersGUI_StdHypothesisCreator.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_SpinBox.h"
32 #include "SMESHGUI_HypothesesUtils.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESH_TypeFilter.hxx"
35 #include "SMESH_NumberFilter.hxx"
36 #include "StdMeshersGUI_ObjectReferenceParamWdg.h"
37 #include "StdMeshersGUI_LayerDistributionParamWdg.h"
38
39 #include "SUIT_ResourceMgr.h"
40
41 #include <SALOMEconfig.h>
42 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
43 #include CORBA_SERVER_HEADER(SMESH_Mesh)
44
45 #include <qpixmap.h>
46 #include <qhbox.h>
47 #include <qslider.h>
48 #include <qlabel.h>
49
50
51 const double VALUE_MAX = 1.0e+15, // COORD_MAX
52              VALUE_MAX_2  = VALUE_MAX * VALUE_MAX,
53              VALUE_MAX_3  = VALUE_MAX_2 * VALUE_MAX,
54              VALUE_SMALL = 1.0e-15,
55              VALUE_SMALL_2 = VALUE_SMALL * VALUE_SMALL,
56              VALUE_SMALL_3 = VALUE_SMALL_2 * VALUE_SMALL;
57
58 //================================================================================
59 /*!
60  * \brief Constructor
61   * \param type - hypothesis type
62  */
63 //================================================================================
64
65 StdMeshersGUI_StdHypothesisCreator::StdMeshersGUI_StdHypothesisCreator( const QString& type )
66 : SMESHGUI_GenericHypothesisCreator( type )
67 {
68 }
69
70 //================================================================================
71 /*!
72  * \brief Destructor
73  */
74 //================================================================================
75
76 StdMeshersGUI_StdHypothesisCreator::~StdMeshersGUI_StdHypothesisCreator()
77 {
78 }
79
80 //================================================================================
81 /*!
82  * \brief Return widget for i-th hypothesis parameter (got from myParamWidgets)
83   * \param i - index of hypothesis parameter
84   * \retval QWidget* - found widget
85  */
86 //================================================================================
87
88 QWidget* StdMeshersGUI_StdHypothesisCreator::getWidgetForParam( int i ) const
89 {
90   QWidget* w = 0;
91   if ( isCreation() ) ++i; // skip widget of 'name' parameter
92
93   if ( i < myCustomWidgets.count() ) {
94     QPtrList<QWidget>::const_iterator anIt  = myCustomWidgets.begin();
95     QPtrList<QWidget>::const_iterator aLast = myCustomWidgets.end();
96     for ( int j = 0 ; !w && anIt != aLast; ++anIt )
97       if ( i == j )
98         w = *anIt;
99   }
100   if ( !w ) {
101     // list has no at() const, so we iterate
102     QPtrList<QWidget>::const_iterator anIt  = widgets().begin();
103     QPtrList<QWidget>::const_iterator aLast = widgets().end();
104     for( int j = 0; !w && anIt!=aLast; anIt++, ++j ) {
105       if ( i == j )
106         w = *anIt;
107     }
108   }
109   return w;
110 }
111
112 //================================================================================
113 /*!
114  * \brief Allow modifing myCustomWidgets in const methods
115   * \retval ListOfWidgets* - non-const pointer to myCustomWidgets
116  */
117 //================================================================================
118
119 StdMeshersGUI_StdHypothesisCreator::ListOfWidgets*
120 StdMeshersGUI_StdHypothesisCreator::customWidgets() const
121 {
122   return const_cast< ListOfWidgets* >( & myCustomWidgets );
123 }
124
125 //================================================================================
126 /*!
127  * \brief Builds dlg layout
128   * \retval QFrame* - the built widget
129  */
130 //================================================================================
131
132 QFrame* StdMeshersGUI_StdHypothesisCreator::buildFrame()
133 {
134   return buildStdFrame();
135 }
136
137 //================================================================================
138 /*!
139  * \brief Initialise parameter values in controls
140  */
141 //================================================================================
142
143 void StdMeshersGUI_StdHypothesisCreator::retrieveParams() const
144 {
145   // buildStdFrame() sets values itself calling stdParams()
146
147   if ( hypType().startsWith("ProjectionSource" ))
148   {
149     // we use this method to connect depending custom widgets
150     StdMeshersGUI_ObjectReferenceParamWdg* widgetToActivate = 0;
151     ListOfWidgets::const_iterator anIt = myCustomWidgets.begin();
152     for ( ; anIt != myCustomWidgets.end(); anIt++)
153     {
154       if ( *anIt && (*anIt)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
155       {
156         StdMeshersGUI_ObjectReferenceParamWdg * w1 =
157           ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
158         ListOfWidgets::const_iterator anIt2 = anIt;
159         for ( ++anIt2; anIt2 != myCustomWidgets.end(); anIt2++)
160           if ( *anIt2 && (*anIt2)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
161           {
162             StdMeshersGUI_ObjectReferenceParamWdg * w2 =
163               ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt2 );
164             w1->AvoidSimultaneousSelection( w2 );
165           }
166         if ( !widgetToActivate )
167           widgetToActivate = w1;
168       }
169     }
170     if ( widgetToActivate )
171       widgetToActivate->activateSelection();
172   }
173 }
174
175 //================================================================================
176 /*!
177  * \brief Widget: slider with left and right labels
178  */
179 //================================================================================
180
181 class TDoubleSliderWith2Lables: public QHBox
182 {
183 public:
184   TDoubleSliderWith2Lables( const QString& leftLabel, const QString& rightLabel,
185                             const double   initValue, const double   bottom,
186                             const double   top      , const double   precision,
187                             QWidget *      parent=0 , const char *   name=0 )
188     :QHBox(parent,name), _bottom(bottom), _precision(precision)
189   {
190     if ( !leftLabel.isEmpty() ) (new QLabel( this ))->setText( leftLabel );
191     _slider = new QSlider( Horizontal, this );
192     _slider->setRange( 0, toInt( top ));
193     _slider->setValue( toInt( initValue ));
194     if ( !rightLabel.isEmpty() ) (new QLabel( this ))->setText( rightLabel );
195   }
196   double value() const { return _bottom + _slider->value() * _precision; }
197   QSlider * getSlider() const { return _slider; }
198   int toInt( double val ) const { return (int) ceil(( val - _bottom ) / _precision ); }
199 private:
200   double _bottom, _precision;
201   QSlider * _slider;
202 };
203
204 namespace {
205
206   //================================================================================
207   /*!
208    * \brief Retrieve GEOM_Object held by widget
209    */
210   //================================================================================
211
212   inline GEOM::GEOM_Object_var geomFromWdg(const QWidget* wdg)
213   {
214     const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
215       dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
216     if ( objRefWdg )
217       return objRefWdg->GetObject< GEOM::GEOM_Object >();
218
219     return GEOM::GEOM_Object::_nil();
220   }
221   //================================================================================
222   /*!
223    * \brief Retrieve SMESH_Mesh held by widget
224    */
225   //================================================================================
226
227   inline SMESH::SMESH_Mesh_var meshFromWdg(const QWidget* wdg)
228   {
229     const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
230       dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
231     if ( objRefWdg )
232       return objRefWdg->GetObject< SMESH::SMESH_Mesh >();
233
234     return SMESH::SMESH_Mesh::_nil();
235   }
236   //================================================================================
237   /*!
238    * \brief creates a filter for selection of shapes of given dimension
239     * \param dim - dimension
240     * \param subShapeType - required type of subshapes, number of which must be \a nbSubShapes
241     * \param nbSubShapes - number of subshapes of given type
242     * \param closed - required closeness flag of a shape
243     * \retval SUIT_SelectionFilter* - created filter
244    */
245   //================================================================================
246
247   SUIT_SelectionFilter* filterForShapeOfDim(const int              dim,
248                                             const int              nbSubShapes = 0,
249                                             const TopAbs_ShapeEnum subShapeType = TopAbs_SHAPE,
250                                             const bool             closed = false)
251   {
252     TColStd_MapOfInteger shapeTypes;
253     switch ( dim ) {
254     case 0: shapeTypes.Add( TopAbs_VERTEX ); break;
255     case 1: shapeTypes.Add( TopAbs_EDGE ); break;
256     case 2: shapeTypes.Add( TopAbs_FACE ); break;
257     case 3:
258       shapeTypes.Add( TopAbs_SHELL );
259       shapeTypes.Add( TopAbs_SOLID );
260       shapeTypes.Add( TopAbs_COMPSOLID );
261       shapeTypes.Add( TopAbs_COMPOUND );
262       break;
263     }
264     return new SMESH_NumberFilter("GEOM", subShapeType, nbSubShapes,
265                                   shapeTypes, GEOM::GEOM_Object::_nil(), closed);
266   }
267
268   //================================================================================
269   /*!
270    * \brief Create a widget for object selection
271     * \param object - initial object
272     * \param filter - selection filter
273     * \retval QWidget* - created widget
274    */
275   //================================================================================
276
277   QWidget* newObjRefParamWdg( SUIT_SelectionFilter* filter,
278                               CORBA::Object_var     object)
279   {
280     StdMeshersGUI_ObjectReferenceParamWdg* w =
281       new StdMeshersGUI_ObjectReferenceParamWdg( filter, 0);
282     w->SetObject( object.in() );
283     return w;
284   }
285
286   //================================================================================
287   /*!
288    * \brief calls deactivateSelection() for StdMeshersGUI_ObjectReferenceParamWdg
289     * \param widgetList - list of widgets
290    */
291   //================================================================================
292
293   void deactivateObjRefParamWdg( QPtrList<QWidget>* widgetList )
294   {
295     StdMeshersGUI_ObjectReferenceParamWdg* w = 0;
296     QPtrList<QWidget>::iterator anIt  = widgetList->begin();
297     QPtrList<QWidget>::iterator aLast = widgetList->end();
298     for ( ; anIt != aLast; anIt++ ) {
299       if ( (*anIt) && (*anIt)->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
300       {
301         w = (StdMeshersGUI_ObjectReferenceParamWdg* )( *anIt );
302         w->deactivateSelection();
303       }
304     }
305   }
306 }
307
308 //================================================================================
309 /*!
310  * \brief Check parameter values before accept()
311   * \retval bool - true if OK
312  */
313 //================================================================================
314
315 bool StdMeshersGUI_StdHypothesisCreator::checkParams() const
316 {
317   // check if object reference parameter is set, as it has no default value
318   bool ok = true;
319   if ( hypType().startsWith("ProjectionSource" ))
320   {
321     StdMeshersGUI_ObjectReferenceParamWdg* w =
322       widget< StdMeshersGUI_ObjectReferenceParamWdg >( 0 );
323     ok = ( w->IsObjectSelected() );
324     if ( !ok ) w->SetObject( CORBA::Object::_nil() );
325     int nbAssocVert = ( hypType() == "ProjectionSource1D" ? 1 : 2 );
326     for ( int i = 0; ok && i < nbAssocVert; i += 2)
327     {
328       QString srcV, tgtV;
329       StdMeshersGUI_ObjectReferenceParamWdg* w1 =
330         widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+2 );
331       StdMeshersGUI_ObjectReferenceParamWdg* w2 =
332         widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+3 );
333       srcV = w1->GetValue();
334       tgtV = w2->GetValue();
335       ok = (( srcV.isEmpty()  && tgtV.isEmpty() ) ||
336             ( !srcV.isEmpty() && !tgtV.isEmpty() && srcV != tgtV ));
337       if ( !ok ) {
338         w1->SetObject( CORBA::Object::_nil() );
339         w2->SetObject( CORBA::Object::_nil() );
340       }
341     }
342
343     // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
344     if ( ok )
345       deactivateObjRefParamWdg( customWidgets() );
346   }
347   else if ( hypType() == "LayerDistribution" )
348   {
349     StdMeshersGUI_LayerDistributionParamWdg* w = 
350       widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
351     ok = ( w && w->IsOk() );
352   }
353   return ok;
354 }
355
356 //================================================================================
357 /*!
358  * \brief Store params from GUI controls to a hypothesis
359   * \retval QString - text representation of parameters
360  */
361 //================================================================================
362
363 QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
364 {
365   ListOfStdParams params;
366   bool res = getStdParamFromDlg( params );
367   if( isCreation() )
368   {
369     SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().latin1() );
370     params.remove( params.begin() );
371   }
372
373   QString valueStr = stdParamValues( params );
374
375   if( res && !params.isEmpty() )
376   {
377     if( hypType()=="LocalLength" )
378     {
379       StdMeshers::StdMeshers_LocalLength_var h =
380         StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
381
382       h->SetLength( params[0].myValue.toDouble() );
383     }
384     else if( hypType()=="Arithmetic1D" )
385     {
386       StdMeshers::StdMeshers_Arithmetic1D_var h =
387         StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
388
389       h->SetLength( params[0].myValue.toDouble(), true );
390       h->SetLength( params[1].myValue.toDouble(), false );
391     }
392     else if( hypType()=="MaxElementArea" )
393     {
394       StdMeshers::StdMeshers_MaxElementArea_var h =
395         StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
396
397       h->SetMaxElementArea( params[0].myValue.toDouble() );
398     }
399     else if( hypType()=="MaxElementVolume" )
400     {
401       StdMeshers::StdMeshers_MaxElementVolume_var h =
402         StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
403
404       h->SetMaxElementVolume( params[0].myValue.toDouble() );
405     }
406     else if( hypType()=="StartEndLength" )
407     {
408       StdMeshers::StdMeshers_StartEndLength_var h =
409         StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
410
411       h->SetLength( params[0].myValue.toDouble(), true );
412       h->SetLength( params[1].myValue.toDouble(), false );
413     }
414     else if( hypType()=="Deflection1D" )
415     {
416       StdMeshers::StdMeshers_Deflection1D_var h =
417         StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
418
419       h->SetDeflection( params[0].myValue.toDouble() );
420     }
421     else if( hypType()=="AutomaticLength" )
422     {
423       StdMeshers::StdMeshers_AutomaticLength_var h =
424         StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() );
425
426       h->SetFineness( params[0].myValue.toDouble() );
427     }
428     else if( hypType()=="NumberOfLayers" )
429     {
430       StdMeshers::StdMeshers_NumberOfLayers_var h =
431         StdMeshers::StdMeshers_NumberOfLayers::_narrow( hypothesis() );
432
433       h->SetNumberOfLayers( params[0].myValue.toInt() );
434     }
435     else if( hypType()=="LayerDistribution" )
436     {
437       StdMeshers::StdMeshers_LayerDistribution_var h =
438         StdMeshers::StdMeshers_LayerDistribution::_narrow( hypothesis() );
439       StdMeshersGUI_LayerDistributionParamWdg* w = 
440         widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
441
442       h->SetLayerDistribution( w->GetHypothesis() );
443     }
444     else if( hypType()=="ProjectionSource1D" )
445     {
446       StdMeshers::StdMeshers_ProjectionSource1D_var h =
447         StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hypothesis() );
448
449       h->SetSourceEdge       ( geomFromWdg ( getWidgetForParam( 0 )));
450       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
451       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )),
452                                geomFromWdg ( getWidgetForParam( 3 )));
453     }
454     else if( hypType()=="ProjectionSource2D" )
455     {
456       StdMeshers::StdMeshers_ProjectionSource2D_var h =
457         StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hypothesis() );
458
459       h->SetSourceFace       ( geomFromWdg ( getWidgetForParam( 0 )));
460       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
461       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
462                                geomFromWdg ( getWidgetForParam( 4 )), // src2
463                                geomFromWdg ( getWidgetForParam( 3 )), // tgt1
464                                geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
465     }
466     else if( hypType()=="ProjectionSource3D" )
467     {
468       StdMeshers::StdMeshers_ProjectionSource3D_var h =
469         StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hypothesis() );
470
471       h->SetSource3DShape    ( geomFromWdg ( getWidgetForParam( 0 )));
472       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
473       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
474                                geomFromWdg ( getWidgetForParam( 4 )), // src2
475                                geomFromWdg ( getWidgetForParam( 3 )), // tgt1
476                                geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
477     }
478   }
479   return valueStr;
480 }
481
482 //================================================================================
483 /*!
484  * \brief Return parameter values as SMESHGUI_GenericHypothesisCreator::StdParam
485   * \param p - list of parameters
486   * \retval bool - success flag
487   *
488   * Is called from SMESHGUI_GenericHypothesisCreator::buildStdFrame().
489   * Parameters will be shown using "standard" controls:
490   *   Int by QtxIntSpinBox
491   *   Double by SMESHGUI_SpinBox
492   *   String by QLineEdit
493   * getCustomWidget() allows to redefine control for a parameter
494  */
495 //================================================================================
496
497 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
498 {
499   bool res = true;
500   SMESHGUI_GenericHypothesisCreator::StdParam item;
501
502   p.clear();
503   customWidgets()->clear();
504   if( isCreation() )
505   {
506     HypothesisData* data = SMESH::GetHypothesisData( hypType() );
507     item.myName = tr( "SMESH_NAME" );
508     item.myValue = data ? data->Label : QString();
509     p.append( item );
510     customWidgets()->append(0);
511   }
512
513   SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
514
515   if( hypType()=="LocalLength" )
516   {
517     StdMeshers::StdMeshers_LocalLength_var h =
518       StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
519
520     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
521     item.myValue = h->GetLength();
522     p.append( item );
523   }
524   else if( hypType()=="Arithmetic1D" )
525   {
526     StdMeshers::StdMeshers_Arithmetic1D_var h =
527       StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
528
529     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
530     item.myValue = h->GetLength( true );
531     p.append( item );
532     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
533     item.myValue = h->GetLength( false );
534     p.append( item );
535   }
536   else if( hypType()=="MaxElementArea" )
537   {
538     StdMeshers::StdMeshers_MaxElementArea_var h =
539       StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
540
541     item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
542     item.myValue = h->GetMaxElementArea();
543     p.append( item );
544   }
545   else if( hypType()=="MaxElementVolume" )
546   {
547     StdMeshers::StdMeshers_MaxElementVolume_var h =
548       StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
549
550     item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
551     item.myValue = h->GetMaxElementVolume();
552     p.append( item );
553   }
554   else if( hypType()=="StartEndLength" )
555   {
556     StdMeshers::StdMeshers_StartEndLength_var h =
557       StdMeshers::StdMeshers_StartEndLength::_narrow( hyp );
558
559     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
560     item.myValue = h->GetLength( true );
561     p.append( item );
562     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
563     item.myValue = h->GetLength( false );
564     p.append( item );
565   }
566   else if( hypType()=="Deflection1D" )
567   {
568     StdMeshers::StdMeshers_Deflection1D_var h =
569       StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
570
571     item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
572     item.myValue = h->GetDeflection();
573     p.append( item );
574   }
575   else if( hypType()=="AutomaticLength" )
576   {
577     StdMeshers::StdMeshers_AutomaticLength_var h =
578       StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
579
580     item.myName = tr( "SMESH_FINENESS_PARAM" );
581     //item.myValue = h->GetFineness();
582     p.append( item );
583     customWidgets()->append
584       ( new TDoubleSliderWith2Lables( "0 ", " 1", h->GetFineness(), 0, 1, 0.01, 0 ));
585   }
586   else if( hypType()=="NumberOfLayers" )
587   {
588     StdMeshers::StdMeshers_NumberOfLayers_var h =
589       StdMeshers::StdMeshers_NumberOfLayers::_narrow( hyp );
590
591     item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
592     item.myValue = (int) h->GetNumberOfLayers();
593     p.append( item );
594   }
595   else if( hypType()=="LayerDistribution" )
596   {
597     StdMeshers::StdMeshers_LayerDistribution_var h =
598       StdMeshers::StdMeshers_LayerDistribution::_narrow( hyp );
599
600     item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
601     customWidgets()->append
602       ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), dlg()));
603   }
604   else if( hypType()=="ProjectionSource1D" )
605   {
606     StdMeshers::StdMeshers_ProjectionSource1D_var h =
607       StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hyp );
608
609     item.myName = tr( "SMESH_SOURCE_EDGE" ); p.append( item );
610     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 1 ),
611                                                h->GetSourceEdge()));
612     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
613     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
614                                                h->GetSourceMesh()));
615     item.myName = tr( "SMESH_SOURCE_VERTEX" ); p.append( item );
616     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
617                                                h->GetSourceVertex()));
618     item.myName = tr( "SMESH_TARGET_VERTEX" ); p.append( item );
619     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
620                                                h->GetTargetVertex()));
621   }
622   else if( hypType()=="ProjectionSource2D" )
623   {
624     StdMeshers::StdMeshers_ProjectionSource2D_var h =
625       StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hyp );
626
627     item.myName = tr( "SMESH_SOURCE_FACE" ); p.append( item );
628     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 2 ),
629                                                h->GetSourceFace()));
630     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
631     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
632                                                h->GetSourceMesh()));
633     item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
634     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
635                                                h->GetSourceVertex( 1 )));
636     item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
637     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
638                                                h->GetTargetVertex( 1 )));
639     item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
640     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
641                                                h->GetSourceVertex( 2 )));
642     item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
643     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
644                                                h->GetTargetVertex( 2 )));
645   }
646   else if( hypType()=="ProjectionSource3D" )
647   {
648     StdMeshers::StdMeshers_ProjectionSource3D_var h =
649       StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hyp );
650
651     item.myName = tr( "SMESH_SOURCE_3DSHAPE" ); p.append( item );
652     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 3 , 6, TopAbs_FACE, true ),
653                                                h->GetSource3DShape()));
654     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
655     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
656                                                h->GetSourceMesh()));
657     item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
658     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
659                                                h->GetSourceVertex( 1 )));
660     item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
661     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
662                                                h->GetTargetVertex( 1 )));
663     item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
664     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
665                                                h->GetSourceVertex( 2 )));
666     item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
667     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
668                                                h->GetTargetVertex( 2 )));
669   }
670   else
671     res = false;
672   return res;
673 }
674
675 //================================================================================
676 /*!
677  * \brief tune "standard" control
678   * \param w - control widget
679   * \param int - parameter index
680  */
681 //================================================================================
682
683 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget( QWidget* w, const int ) const
684 {
685   SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
686   if( hypType()=="LocalLength" &&  sb )
687   {
688     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
689   }
690   else if( hypType()=="Arithmetic1D" && sb )
691   {
692     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
693   }
694   else if( hypType()=="MaxElementArea" && sb )
695   {
696     sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6 );
697   }
698   else if( hypType()=="MaxElementVolume" && sb )
699   {
700     sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6 );
701   }
702   else if( hypType()=="StartEndLength" && sb )
703   {
704     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
705   }
706   else if( hypType()=="Deflection1D" && sb )
707   {
708     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
709   }
710   else if ( sb ) // default validator for possible ancestors
711   {
712     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
713   }
714 }
715
716 //================================================================================
717 /*!
718  * \brief Return dlg title
719   * \retval QString - title string
720  */
721 //================================================================================
722
723 QString StdMeshersGUI_StdHypothesisCreator::caption() const
724 {
725   return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ) );
726 }
727
728 //================================================================================
729 /*!
730  * \brief return pixmap for dlg icon
731   * \retval QPixmap - 
732  */
733 //================================================================================
734
735 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
736 {
737   QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ) );
738   return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
739 }
740
741 //================================================================================
742 /*!
743  * \brief Return hypothesis type name to show in dlg
744   * \retval QString - 
745  */
746 //================================================================================
747
748 QString StdMeshersGUI_StdHypothesisCreator::type() const
749 {
750   return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ) );
751 }
752
753 //================================================================================
754 /*!
755  * \brief String to insert in "SMESH_%1_HYPOTHESIS" to get hypothesis type name
756  * from message resouce file
757   * \param t - hypothesis type
758   * \retval QString - result string
759  */
760 //================================================================================
761
762 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
763 {
764   static QMap<QString,QString>  types;
765   if( types.isEmpty() )
766   {
767     types.insert( "LocalLength", "LOCAL_LENGTH" );
768     types.insert( "NumberOfSegments", "NB_SEGMENTS" );
769     types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
770     types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
771     types.insert( "StartEndLength", "START_END_LENGTH" );
772     types.insert( "Deflection1D", "DEFLECTION1D" );
773     types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
774     types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
775     types.insert( "ProjectionSource1D", "PROJECTION_SOURCE_1D" );
776     types.insert( "ProjectionSource2D", "PROJECTION_SOURCE_2D" );
777     types.insert( "ProjectionSource3D", "PROJECTION_SOURCE_3D" );
778     types.insert( "NumberOfLayers", "NUMBER_OF_LAYERS" );
779     types.insert( "LayerDistribution", "LAYER_DISTRIBUTION" );
780   }
781
782   QString res;
783   if( types.contains( t ) )
784     res = types[ t ];
785
786   return res;
787 }
788
789
790 //=======================================================================
791 //function : getCustomWidget
792 //purpose  : is called from buildStdFrame()
793 //=======================================================================
794
795 QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
796                                                               QWidget*         parent,
797                                                               const int        index) const
798 {
799   QWidget* w = 0;
800   if ( index < customWidgets()->count() ) {
801     w = customWidgets()->at( index );
802     if ( w )
803       w->reparent( parent, QPoint( 0, 0 ));
804   }
805   return w;
806 }
807
808 //================================================================================
809 /*!
810  * \brief Set param value taken from a custom widget
811   * \param param - SMESHGUI_GenericHypothesisCreator::StdParam structure
812   * \param widget - widget presenting param
813   * \retval bool - success flag
814  * 
815  * this method is called from getStdParamFromDlg()
816  */
817 //================================================================================
818
819 bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
820                                                                    QWidget*   widget) const
821 {
822   if ( hypType()=="AutomaticLength" ) {
823     TDoubleSliderWith2Lables* w = dynamic_cast<TDoubleSliderWith2Lables*>( widget );
824     if ( w ) {
825       param.myValue = w->value();
826       return true;
827     }
828   }
829   if ( widget->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
830   {
831     // show only 1st reference value
832     if ( true /*widget == getWidgetForParam( 0 )*/) {
833       const StdMeshersGUI_ObjectReferenceParamWdg * w =
834         static_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( widget );
835       param.myValue = w->GetValue();
836     }
837     return true;
838   }
839   if ( widget->inherits( "StdMeshersGUI_LayerDistributionParamWdg" ))
840   {
841     const StdMeshersGUI_LayerDistributionParamWdg * w =
842       static_cast<const StdMeshersGUI_LayerDistributionParamWdg*>( widget );
843     param.myValue = w->GetValue();
844     return true;
845   }
846   return false;
847 }
848
849 //================================================================================
850 /*!
851  * \brief called when operation cancelled
852  */
853 //================================================================================
854
855 void StdMeshersGUI_StdHypothesisCreator::onReject()
856 {
857   if ( hypType().startsWith("ProjectionSource" ))
858   {
859     // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
860     deactivateObjRefParamWdg( customWidgets() );
861   }
862 }