Salome HOME
Merge from OCC_development_generic_2006
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_StdHypothesisCreator.cxx
index d39c223c1916ae4eb2bcd44a3d0e7cbe52974cdb..33abb069897bd290f7f5810b5814199a8e352e07 100644 (file)
@@ -39,6 +39,9 @@
 #include CORBA_SERVER_HEADER(SMESH_Mesh)
 
 #include <qpixmap.h>
+#include <qhbox.h>
+#include <qslider.h>
+#include <qlabel.h>
 
 
 const double VALUE_MAX = 1.0e+15, // COORD_MAX
@@ -72,7 +75,7 @@ void StdMeshersGUI_StdHypothesisCreator::retrieveParams() const
   //here this method must be empty because buildStdParam sets values itself
 }
 
-void StdMeshersGUI_StdHypothesisCreator::storeParams() const
+QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
 {
   ListOfStdParams params;
   bool res = getStdParamFromDlg( params );
@@ -82,6 +85,8 @@ void StdMeshersGUI_StdHypothesisCreator::storeParams() const
     params.remove( params.begin() );
   }
 
+  QString valueStr = stdParamValues( params );
+
   if( res && !params.isEmpty() )
   {
     if( hypType()=="LocalLength" )
@@ -128,7 +133,15 @@ void StdMeshersGUI_StdHypothesisCreator::storeParams() const
 
       h->SetDeflection( params[0].myValue.toDouble() );
     }
+    else if( hypType()=="AutomaticLength" )
+    {
+      StdMeshers::StdMeshers_AutomaticLength_var h =
+       StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() );
+
+      h->SetFineness( params[0].myValue.toDouble() );
+    }
   }
+  return valueStr;
 }
 
 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
@@ -145,64 +158,75 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
     p.append( item );
   }
 
+  SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
+
   if( hypType()=="LocalLength" )
   {
     StdMeshers::StdMeshers_LocalLength_var h =
-      StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
+      StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
 
     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
-    item.myValue = isCreation() ? 1.0 : h->GetLength();
+    item.myValue = h->GetLength();
     p.append( item );
   }
   else if( hypType()=="Arithmetic1D" )
   {
     StdMeshers::StdMeshers_Arithmetic1D_var h =
-      StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
+      StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
 
     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
-    item.myValue = isCreation() ? 1.0 : h->GetLength( true );
+    item.myValue = h->GetLength( true );
     p.append( item );
     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
-    item.myValue = isCreation() ? 10.0 : h->GetLength( false );
+    item.myValue = h->GetLength( false );
     p.append( item );
   }
   else if( hypType()=="MaxElementArea" )
   {
     StdMeshers::StdMeshers_MaxElementArea_var h =
-      StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
+      StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
 
     item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
-    item.myValue = isCreation() ? 1.0 : h->GetMaxElementArea();
+    item.myValue = h->GetMaxElementArea();
     p.append( item );
   }
   else if( hypType()=="MaxElementVolume" )
   {
     StdMeshers::StdMeshers_MaxElementVolume_var h =
-      StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
+      StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
 
     item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
-    item.myValue = isCreation() ? 1.0 : h->GetMaxElementVolume();
+    item.myValue = h->GetMaxElementVolume();
     p.append( item );
   }
   else if( hypType()=="StartEndLength" )
   {
     StdMeshers::StdMeshers_StartEndLength_var h =
-      StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
+      StdMeshers::StdMeshers_StartEndLength::_narrow( hyp );
 
     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
-    item.myValue = isCreation() ? 1.0 : h->GetLength( true );
+    item.myValue = h->GetLength( true );
     p.append( item );
     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
-    item.myValue = isCreation() ? 10.0 : h->GetLength( false );
+    item.myValue = h->GetLength( false );
     p.append( item );
   }
   else if( hypType()=="Deflection1D" )
   {
     StdMeshers::StdMeshers_Deflection1D_var h =
-      StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
+      StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
 
     item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
-    item.myValue = isCreation() ? 1.0 : h->GetDeflection();
+    item.myValue = h->GetDeflection();
+    p.append( item );
+  }
+  else if( hypType()=="AutomaticLength" )
+  {
+    StdMeshers::StdMeshers_AutomaticLength_var h =
+      StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
+
+    item.myName = tr( "SMESH_FINENESS_PARAM" );
+    item.myValue = h->GetFineness();
     p.append( item );
   }
   else
@@ -267,6 +291,7 @@ QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) cons
     types.insert( "StartEndLength", "START_END_LENGTH" );
     types.insert( "Deflection1D", "DEFLECTION1D" );
     types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
+    types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
   }
 
   QString res;
@@ -275,3 +300,65 @@ QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) cons
 
   return res;
 }
+
+//================================================================================
+/*!
+ * \brief Widget: slider with left and right labels
+ */
+//================================================================================
+
+class TDoubleSliderWith2Lables: public QHBox
+{
+public:
+  TDoubleSliderWith2Lables( const QString& leftLabel, const QString& rightLabel,
+                            const double   initValue, const double   bottom,
+                            const double   top      , const double   precision,
+                            QWidget *      parent=0 , const char *   name=0 )
+    :QHBox(parent,name), _bottom(bottom), _precision(precision)
+  {
+    if ( !leftLabel.isEmpty() ) (new QLabel( this ))->setText( leftLabel );
+    _slider = new QSlider( Horizontal, this );
+    _slider->setRange( 0, toInt( top ));
+    _slider->setValue( toInt( initValue ));
+    if ( !rightLabel.isEmpty() ) (new QLabel( this ))->setText( rightLabel );
+  }
+  double value() const { return _bottom + _slider->value() * _precision; }
+  QSlider * getSlider() const { return _slider; }
+  int toInt( double val ) const { return (int) ceil(( val - _bottom ) / _precision ); }
+private:
+  double _bottom, _precision;
+  QSlider * _slider;
+};
+
+//=======================================================================
+//function : getCustomWidget
+//purpose  : 
+//=======================================================================
+
+QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
+                                                              QWidget*         parent) const
+{
+  if ( hypType()=="AutomaticLength" && param.myValue.type() == QVariant::Double )
+    return new TDoubleSliderWith2Lables( "0 ", " 1", param.myValue.toDouble(),
+                                         0, 1, 0.01, parent );
+
+  return 0;
+}
+
+//=======================================================================
+//function : getParamFromCustomWidget
+//purpose  : 
+//=======================================================================
+
+bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
+                                                                   QWidget*   widget) const
+{
+  if ( hypType()=="AutomaticLength" ) {
+    TDoubleSliderWith2Lables* w = dynamic_cast<TDoubleSliderWith2Lables*>( widget );
+    if ( w ) {
+      param.myValue = w->value();
+      return true;
+    }
+  }
+  return false;
+}