Salome HOME
Start implementation of the notebook in SMESH module.
[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 #include <SALOMEDSClient_Study.hxx>
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( QString& msg ) const
343 {
344   if( !SMESHGUI_GenericHypothesisCreator::checkParams( msg ) )
345     return false;
346
347   // check if object reference parameter is set, as it has no default value
348   bool ok = true;
349   if ( hypType().startsWith("ProjectionSource" ))
350   {
351     StdMeshersGUI_ObjectReferenceParamWdg* w =
352       widget< StdMeshersGUI_ObjectReferenceParamWdg >( 0 );
353     ok = ( w->IsObjectSelected() );
354     if ( !ok ) w->SetObject( CORBA::Object::_nil() );
355     int nbAssocVert = ( hypType() == "ProjectionSource1D" ? 1 : 2 );
356     for ( int i = 0; ok && i < nbAssocVert; i += 2)
357     {
358       QString srcV, tgtV;
359       StdMeshersGUI_ObjectReferenceParamWdg* w1 =
360         widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+2 );
361       StdMeshersGUI_ObjectReferenceParamWdg* w2 =
362         widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+3 );
363       srcV = w1->GetValue();
364       tgtV = w2->GetValue();
365       ok = (( srcV.isEmpty()  && tgtV.isEmpty() ) ||
366             ( !srcV.isEmpty() && !tgtV.isEmpty() && srcV != tgtV ));
367       if ( !ok ) {
368         w1->SetObject( CORBA::Object::_nil() );
369         w2->SetObject( CORBA::Object::_nil() );
370       }
371     }
372
373     // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
374     if ( ok )
375       deactivateObjRefParamWdg( customWidgets() );
376   }
377   else if ( hypType() == "LayerDistribution" )
378   {
379     StdMeshersGUI_LayerDistributionParamWdg* w = 
380       widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
381     ok = ( w && w->IsOk() );
382   }
383   return ok;
384 }
385
386 //================================================================================
387 /*!
388  * \brief Store params from GUI controls to a hypothesis
389   * \retval QString - text representation of parameters
390  */
391 //================================================================================
392
393 QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
394 {
395   ListOfStdParams params;
396   bool res = getStdParamFromDlg( params );
397   if( isCreation() )
398   {
399     SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().toLatin1().data() );
400     params.erase( params.begin() );
401   }
402
403   QString valueStr = stdParamValues( params );
404   QStringList aVariablesList = getVariablesFromDlg();
405
406   if( res && !params.isEmpty() )
407   {
408     if( hypType()=="LocalLength" )
409     {
410       StdMeshers::StdMeshers_LocalLength_var h =
411         StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
412       if(!aVariablesList.isEmpty()) {
413         QString aVariables = aVariablesList.join(":");
414         h->SetParameters(aVariables.toLatin1().constData());
415       }
416       else
417         h->SetParameters("");
418         
419       h->SetLength( params[0].myValue.toDouble() );
420       h->SetPrecision( params[1].myValue.toDouble() );
421     }
422     else if( hypType()=="SegmentLengthAroundVertex" )
423     {
424       StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
425         StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hypothesis() );
426
427       h->SetLength( params[0].myValue.toDouble() );
428     }
429     else if( hypType()=="Arithmetic1D" )
430     {
431       StdMeshers::StdMeshers_Arithmetic1D_var h =
432         StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
433
434       h->SetLength( params[0].myValue.toDouble(), true );
435       h->SetLength( params[1].myValue.toDouble(), false );
436     }
437     else if( hypType()=="MaxElementArea" )
438     {
439       StdMeshers::StdMeshers_MaxElementArea_var h =
440         StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
441
442       h->SetMaxElementArea( params[0].myValue.toDouble() );
443     }
444     else if( hypType()=="MaxElementVolume" )
445     {
446       StdMeshers::StdMeshers_MaxElementVolume_var h =
447         StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
448
449       h->SetMaxElementVolume( params[0].myValue.toDouble() );
450     }
451     else if( hypType()=="StartEndLength" )
452     {
453       StdMeshers::StdMeshers_StartEndLength_var h =
454         StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
455
456       h->SetLength( params[0].myValue.toDouble(), true );
457       h->SetLength( params[1].myValue.toDouble(), false );
458     }
459     else if( hypType()=="Deflection1D" )
460     {
461       StdMeshers::StdMeshers_Deflection1D_var h =
462         StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
463
464       h->SetDeflection( params[0].myValue.toDouble() );
465     }
466     else if( hypType()=="AutomaticLength" )
467     {
468       StdMeshers::StdMeshers_AutomaticLength_var h =
469         StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() );
470
471       h->SetFineness( params[0].myValue.toDouble() );
472     }
473     else if( hypType()=="NumberOfLayers" )
474     {
475       StdMeshers::StdMeshers_NumberOfLayers_var h =
476         StdMeshers::StdMeshers_NumberOfLayers::_narrow( hypothesis() );
477
478       h->SetNumberOfLayers( params[0].myValue.toInt() );
479     }
480     else if( hypType()=="LayerDistribution" )
481     {
482       StdMeshers::StdMeshers_LayerDistribution_var h =
483         StdMeshers::StdMeshers_LayerDistribution::_narrow( hypothesis() );
484       StdMeshersGUI_LayerDistributionParamWdg* w = 
485         widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
486
487       h->SetLayerDistribution( w->GetHypothesis() );
488     }
489     else if( hypType()=="ProjectionSource1D" )
490     {
491       StdMeshers::StdMeshers_ProjectionSource1D_var h =
492         StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hypothesis() );
493
494       h->SetSourceEdge       ( geomFromWdg ( getWidgetForParam( 0 )));
495       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
496       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )),
497                                geomFromWdg ( getWidgetForParam( 3 )));
498     }
499     else if( hypType()=="ProjectionSource2D" )
500     {
501       StdMeshers::StdMeshers_ProjectionSource2D_var h =
502         StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hypothesis() );
503
504       h->SetSourceFace       ( geomFromWdg ( getWidgetForParam( 0 )));
505       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
506       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
507                                geomFromWdg ( getWidgetForParam( 4 )), // src2
508                                geomFromWdg ( getWidgetForParam( 3 )), // tgt1
509                                geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
510     }
511     else if( hypType()=="ProjectionSource3D" )
512     {
513       StdMeshers::StdMeshers_ProjectionSource3D_var h =
514         StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hypothesis() );
515
516       h->SetSource3DShape    ( geomFromWdg ( getWidgetForParam( 0 )));
517       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
518       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
519                                geomFromWdg ( getWidgetForParam( 4 )), // src2
520                                geomFromWdg ( getWidgetForParam( 3 )), // tgt1
521                                geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
522     }
523   }
524   return valueStr;
525 }
526
527 //================================================================================
528 /*!
529  * \brief Return parameter values as SMESHGUI_GenericHypothesisCreator::StdParam
530   * \param p - list of parameters
531   * \retval bool - success flag
532   *
533   * Is called from SMESHGUI_GenericHypothesisCreator::buildStdFrame().
534   * Parameters will be shown using "standard" controls:
535   *   Int by QtxIntSpinBox
536   *   Double by SMESHGUI_SpinBox
537   *   String by QLineEdit
538   * getCustomWidget() allows to redefine control for a parameter
539  */
540 //================================================================================
541
542 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
543 {
544   bool res = true;
545   SMESHGUI_GenericHypothesisCreator::StdParam item;
546
547   p.clear();
548   customWidgets()->clear();
549   if( isCreation() )
550   {
551     HypothesisData* data = SMESH::GetHypothesisData( hypType() );
552     item.myName = tr( "SMESH_NAME" );
553     item.myValue = data ? hypName() : QString();
554     p.append( item );
555     customWidgets()->append(0);
556   }
557   
558   SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
559
560   if( hypType()=="LocalLength" )
561   {
562     StdMeshers::StdMeshers_LocalLength_var h =
563       StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
564
565     QString aParameters(h->GetParameters());
566     QStringList aParametersList;
567     if(aParameters.length())
568       aParametersList = aParameters.split(":");
569
570     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
571     QVariant aVariable = parseParameter(aParametersList,0);
572     if(aVariable.type() != QVariant::Invalid) {
573       item.myValue = aVariable;
574       item.isVariable = true;
575     }
576     else
577       item.myValue = h->GetLength();
578     p.append( item );
579      
580     item.myName = tr("SMESH_LOCAL_LENGTH_PRECISION");
581     aVariable = parseParameter(aParametersList,1);
582     if(aVariable.type() !=  QVariant::Invalid) {
583       item.myValue = aVariable;
584       item.isVariable = true;
585     }
586     else
587       item.myValue = h->GetPrecision();
588     p.append( item );
589     
590   }
591   else if( hypType()=="SegmentLengthAroundVertex" )
592   {
593     StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
594       StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hyp );
595
596     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
597     item.myValue = h->GetLength();
598     p.append( item );
599   }
600   else if( hypType()=="Arithmetic1D" )
601   {
602     StdMeshers::StdMeshers_Arithmetic1D_var h =
603       StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
604
605     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
606     item.myValue = h->GetLength( true );
607     p.append( item );
608     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
609     item.myValue = h->GetLength( false );
610     p.append( item );
611   }
612   else if( hypType()=="MaxElementArea" )
613   {
614     StdMeshers::StdMeshers_MaxElementArea_var h =
615       StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
616
617     item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
618     item.myValue = h->GetMaxElementArea();
619     p.append( item );
620   }
621   else if( hypType()=="MaxElementVolume" )
622   {
623     StdMeshers::StdMeshers_MaxElementVolume_var h =
624       StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
625
626     item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
627     item.myValue = h->GetMaxElementVolume();
628     p.append( item );
629   }
630   else if( hypType()=="StartEndLength" )
631   {
632     StdMeshers::StdMeshers_StartEndLength_var h =
633       StdMeshers::StdMeshers_StartEndLength::_narrow( hyp );
634
635     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
636     item.myValue = h->GetLength( true );
637     p.append( item );
638     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
639     item.myValue = h->GetLength( false );
640     p.append( item );
641   }
642   else if( hypType()=="Deflection1D" )
643   {
644     StdMeshers::StdMeshers_Deflection1D_var h =
645       StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
646
647     item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
648     item.myValue = h->GetDeflection();
649     p.append( item );
650   }
651   else if( hypType()=="AutomaticLength" )
652   {
653     StdMeshers::StdMeshers_AutomaticLength_var h =
654       StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
655
656     item.myName = tr( "SMESH_FINENESS_PARAM" );
657     //item.myValue = h->GetFineness();
658     p.append( item );
659     customWidgets()->append
660       ( new TDoubleSliderWith2Lables( "0 ", " 1", h->GetFineness(), 0, 1, 0.01, 0 ));
661   }
662   else if( hypType()=="NumberOfLayers" )
663   {
664     StdMeshers::StdMeshers_NumberOfLayers_var h =
665       StdMeshers::StdMeshers_NumberOfLayers::_narrow( hyp );
666
667     item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
668     item.myValue = (int) h->GetNumberOfLayers();
669     p.append( item );
670   }
671   else if( hypType()=="LayerDistribution" )
672   {
673     StdMeshers::StdMeshers_LayerDistribution_var h =
674       StdMeshers::StdMeshers_LayerDistribution::_narrow( hyp );
675
676     item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
677     customWidgets()->append
678       ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
679   }
680   else if( hypType()=="ProjectionSource1D" )
681   {
682     StdMeshers::StdMeshers_ProjectionSource1D_var h =
683       StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hyp );
684
685     item.myName = tr( "SMESH_SOURCE_EDGE" ); p.append( item );
686     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 1 ),
687                                                h->GetSourceEdge()));
688     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
689     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
690                                                h->GetSourceMesh()));
691     item.myName = tr( "SMESH_SOURCE_VERTEX" ); p.append( item );
692     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
693                                                h->GetSourceVertex()));
694     item.myName = tr( "SMESH_TARGET_VERTEX" ); p.append( item );
695     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
696                                                h->GetTargetVertex()));
697   }
698   else if( hypType()=="ProjectionSource2D" )
699   {
700     StdMeshers::StdMeshers_ProjectionSource2D_var h =
701       StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hyp );
702
703     item.myName = tr( "SMESH_SOURCE_FACE" ); p.append( item );
704     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 2 ),
705                                                h->GetSourceFace()));
706     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
707     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
708                                                h->GetSourceMesh()));
709     item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
710     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
711                                                h->GetSourceVertex( 1 )));
712     item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
713     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
714                                                h->GetTargetVertex( 1 )));
715     item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
716     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
717                                                h->GetSourceVertex( 2 )));
718     item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
719     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
720                                                h->GetTargetVertex( 2 )));
721   }
722   else if( hypType()=="ProjectionSource3D" )
723   {
724     StdMeshers::StdMeshers_ProjectionSource3D_var h =
725       StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hyp );
726
727     item.myName = tr( "SMESH_SOURCE_3DSHAPE" ); p.append( item );
728     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 3, TopAbs_FACE, 6, true ),
729                                                h->GetSource3DShape()));
730     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
731     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
732                                                h->GetSourceMesh()));
733     item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
734     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
735                                                h->GetSourceVertex( 1 )));
736     item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
737     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
738                                                h->GetTargetVertex( 1 )));
739     item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
740     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
741                                                h->GetSourceVertex( 2 )));
742     item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
743     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
744                                                h->GetTargetVertex( 2 )));
745   }
746   else
747     res = false;
748   return res;
749 }
750
751 //================================================================================
752 /*!
753  * \brief tune "standard" control
754   * \param w - control widget
755   * \param int - parameter index
756  */
757 //================================================================================
758
759 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget (QWidget* w, const int) const
760 {
761   SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
762   if( hypType()=="LocalLength" &&  sb )
763   {
764     if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PARAM"))
765       sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
766     else if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PRECISION"))
767       sb->RangeStepAndValidator( 0.0, 1.0, 0.05, 7 );
768   }
769   else if( hypType()=="Arithmetic1D" && sb )
770   {
771     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
772   }
773   else if( hypType()=="MaxElementArea" && sb )
774   {
775     sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6 );
776   }
777   else if( hypType()=="MaxElementVolume" && sb )
778   {
779     sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6 );
780   }
781   else if( hypType()=="StartEndLength" && sb )
782   {
783     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
784   }
785   else if( hypType()=="Deflection1D" && sb )
786   {
787     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
788   }
789   else if ( sb ) // default validator for possible ancestors
790   {
791     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
792   }
793 }
794
795 //================================================================================
796 /*!
797  * \brief Return dlg title
798   * \retval QString - title string
799  */
800 //================================================================================
801
802 QString StdMeshersGUI_StdHypothesisCreator::caption() const
803 {
804   return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
805 }
806
807 //================================================================================
808 /*!
809  * \brief return pixmap for dlg icon
810   * \retval QPixmap - 
811  */
812 //================================================================================
813
814 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
815 {
816   QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
817   return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
818 }
819
820 //================================================================================
821 /*!
822  * \brief Return hypothesis type name to show in dlg
823   * \retval QString - 
824  */
825 //================================================================================
826
827 QString StdMeshersGUI_StdHypothesisCreator::type() const
828 {
829   return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
830 }
831
832 //================================================================================
833 /*!
834  * \brief String to insert in "SMESH_%1_HYPOTHESIS" to get hypothesis type name
835  * from message resouce file
836   * \param t - hypothesis type
837   * \retval QString - result string
838  */
839 //================================================================================
840
841 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
842 {
843   static QMap<QString,QString>  types;
844   if( types.isEmpty() )
845   {
846     types.insert( "LocalLength", "LOCAL_LENGTH" );
847     types.insert( "NumberOfSegments", "NB_SEGMENTS" );
848     types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
849     types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
850     types.insert( "StartEndLength", "START_END_LENGTH" );
851     types.insert( "Deflection1D", "DEFLECTION1D" );
852     types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
853     types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
854     types.insert( "ProjectionSource1D", "PROJECTION_SOURCE_1D" );
855     types.insert( "ProjectionSource2D", "PROJECTION_SOURCE_2D" );
856     types.insert( "ProjectionSource3D", "PROJECTION_SOURCE_3D" );
857     types.insert( "NumberOfLayers", "NUMBER_OF_LAYERS" );
858     types.insert( "LayerDistribution", "LAYER_DISTRIBUTION" );
859     types.insert( "SegmentLengthAroundVertex", "SEGMENT_LENGTH_AROUND_VERTEX" );
860   }
861
862   QString res;
863   if( types.contains( t ) )
864     res = types[ t ];
865
866   return res;
867 }
868
869
870 //=======================================================================
871 //function : getCustomWidget
872 //purpose  : is called from buildStdFrame()
873 //=======================================================================
874
875 QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
876                                                               QWidget*         parent,
877                                                               const int        index) const
878 {
879   QWidget* w = 0;
880   if ( index < customWidgets()->count() ) {
881     w = customWidgets()->at( index );
882     if ( w ) {
883       w->setParent( parent );
884       w->move( QPoint( 0, 0 ) );
885     }
886   }
887   return w;
888 }
889
890 //================================================================================
891 /*!
892  * \brief Set param value taken from a custom widget
893   * \param param - SMESHGUI_GenericHypothesisCreator::StdParam structure
894   * \param widget - widget presenting param
895   * \retval bool - success flag
896  * 
897  * this method is called from getStdParamFromDlg()
898  */
899 //================================================================================
900
901 bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
902                                                                    QWidget*   widget) const
903 {
904   if ( hypType()=="AutomaticLength" ) {
905     TDoubleSliderWith2Lables* w = dynamic_cast<TDoubleSliderWith2Lables*>( widget );
906     if ( w ) {
907       param.myValue = w->value();
908       return true;
909     }
910   }
911   if ( widget->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
912   {
913     // show only 1st reference value
914     if ( true /*widget == getWidgetForParam( 0 )*/) {
915       const StdMeshersGUI_ObjectReferenceParamWdg * w =
916         static_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( widget );
917       param.myValue = w->GetValue();
918     }
919     return true;
920   }
921   if ( widget->inherits( "StdMeshersGUI_LayerDistributionParamWdg" ))
922   {
923     const StdMeshersGUI_LayerDistributionParamWdg * w =
924       static_cast<const StdMeshersGUI_LayerDistributionParamWdg*>( widget );
925     param.myValue = w->GetValue();
926     return true;
927   }
928   return false;
929 }
930
931 //================================================================================
932 /*!
933  * \brief called when operation cancelled
934  */
935 //================================================================================
936
937 void StdMeshersGUI_StdHypothesisCreator::onReject()
938 {
939   if ( hypType().startsWith("ProjectionSource" ))
940   {
941     // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
942     deactivateObjRefParamWdg( customWidgets() );
943   }
944 }
945
946 //================================================================================
947 /*!
948  * \brief
949  */
950 //================================================================================
951 QVariant StdMeshersGUI_StdHypothesisCreator::
952 parseParameter(const QStringList& theList, int theNbParam) const
953 {
954   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
955   QVariant aResult;
956   if(theList.size() > theNbParam) {
957     QString aParameter =  theList[theNbParam];
958     if(QString::compare(QString(""),aParameter) !=0 ) {
959       if(aStudy->IsVariable(aParameter.toLatin1().constData())) {
960         aResult=aParameter;
961       }
962       else {
963         bool aResult = false;
964         int anIResult = aParameter.toInt(&aResult);
965         if(aResult)
966           aResult = anIResult;
967         else {
968           double aDResult = aParameter.toDouble(&aResult);
969           if(aResult)
970             aResult = aDResult;
971         } 
972       }
973     }
974   }
975   return aResult;
976 }