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