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