Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_DistrPreview.cxx
index 15847d15ad4f528daa47633b0f47382a3b177397..ead8d1c3d72d7dea4eed6032a2de6896501cfebe 100644 (file)
@@ -1,27 +1,38 @@
-// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-// This library is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// Lesser General Public License for more details.
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
 //
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
 //
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File   : StdMeshersGUI_DistrPreview.cxx
+// Author : Open CASCADE S.A.S.
+// SMESH includes
 //
-
-using namespace std;
-
 #include "StdMeshersGUI_DistrPreview.h"
 
+// Qwt includes
+#include <qwt_plot_curve.h>
+#include <qwt_plot_marker.h>
+#include <qwt_plot_grid.h>
+#include <qwt_symbol.h>
+#include <qwt_legend.h>
+
+// OCCT includes
 #include <Expr_NamedUnknown.hxx>
 #include <Expr_GeneralExpression.hxx>
 
@@ -35,6 +46,10 @@ using namespace std;
 #include <Standard_ErrorHandler.hxx>
 #endif
 
+#ifdef WIN32
+# include <algorithm>
+#endif
+
 StdMeshersGUI_DistrPreview::StdMeshersGUI_DistrPreview( QWidget* p, StdMeshers::StdMeshers_NumberOfSegments_ptr h )
 : QwtPlot( p ),
   myPoints( 50 ),
@@ -47,25 +62,44 @@ StdMeshersGUI_DistrPreview::StdMeshersGUI_DistrPreview( QWidget* p, StdMeshers::
 {
   myHypo = StdMeshers::StdMeshers_NumberOfSegments::_duplicate( h );
   myVars.ChangeValue( 1 ) = new Expr_NamedUnknown( "t" );
-  myDensity = insertCurve( QString() );
-  myDistr = insertCurve( QString() );
-  myMsg = insertMarker( new QwtPlotMarker( this ) );
-  setMarkerPos( myMsg, 0.5, 0.5 );
-  setMarkerLabelPen( myMsg, QPen( Qt::red, 1 ) );
-  QFont f = markerFont( myMsg );
-  f.setPointSize( 14 );
-  f.setBold( true );
-  setMarkerFont( myMsg, f );
-  setCurvePen( myDensity, QPen( Qt::red, 1 ) );
+  myDensity = new QwtPlotCurve( QString() );
+  myDensity->attach( this );
+  myDistr = new QwtPlotCurve( QString() );
+  myDistr->attach( this );
+  myMsg = new QwtPlotMarker();
+  myMsg->attach( this );
+  myMsg->setValue( 0.5, 0.5 );
+  QwtText mt = myMsg->label();
+  mt.setBackgroundPen( QPen( Qt::red, 1 ) );
+  QFont f = mt.font();
+  f.setPointSize( 14 ); f.setBold( true );
+  mt.setFont( f );
+  myMsg->setLabel( mt );
+  myDensity->setPen( QPen( Qt::red, 1 ) );
 
   QColor dc = Qt::blue;
-  setCurvePen( myDistr, QPen( dc, 1 ) );
-  setCurveSymbol( myDistr, QwtSymbol( QwtSymbol::XCross, QBrush( dc ), QPen( dc ), QSize( 5, 5 ) ) );
-  setAutoLegend( true );
-  enableLegend( true );
-  setLegendPos( Qwt::Bottom );
-  setCurveTitle( myDensity, tr( "SMESH_DENSITY_FUNC" ) );
-  setCurveTitle( myDistr, tr( "SMESH_DISTR" ) );
+  myDistr->setPen( QPen( dc, 1 ) );
+  myDistr->setSymbol( QwtSymbol( QwtSymbol::XCross, QBrush( dc ), QPen( dc ), QSize( 5, 5 ) ) );
+
+  QwtLegend* l = legend();
+  if ( !l ) {
+    l = new QwtLegend( this );
+    l->setFrameStyle( QFrame::Box | QFrame::Sunken );
+  }
+  insertLegend( l, QwtPlot::BottomLegend );
+
+  myDensity->setTitle( tr( "SMESH_DENSITY_FUNC" ) );
+  myDistr->setTitle( tr( "SMESH_DISTR" ) );
+  
+  QwtPlotGrid* aGrid = new QwtPlotGrid();
+  QPen aMajPen = aGrid->majPen();
+  aMajPen.setStyle( Qt::DashLine );
+  aGrid->setPen( aMajPen );
+
+  aGrid->enableX( true );
+  aGrid->enableY( true );
+
+  aGrid->attach( this );
 }
 
 StdMeshersGUI_DistrPreview::~StdMeshersGUI_DistrPreview()
@@ -186,7 +220,7 @@ void StdMeshersGUI_DistrPreview::update()
       if( isTableFunc() )
        arr = h->BuildDistributionTab( myTableFunc, myNbSeg, ( int )myConv );
       else
-       arr = h->BuildDistributionExpr( myFunction.latin1(), myNbSeg, ( int )myConv );
+       arr = h->BuildDistributionExpr( myFunction.toLatin1().data(), myNbSeg, ( int )myConv );
       if( arr )
       {
        distr = *arr;
@@ -202,7 +236,11 @@ void StdMeshersGUI_DistrPreview::update()
     return;
   }
   else
-    setMarkerLabel( myMsg, QString() );
+  {
+    QwtText mt = myMsg->label();
+    mt.setText( QString() );
+    myMsg->setLabel( mt );
+  }
 
   int size = graph.length()/2;
   double* x = new double[size], *y = new double[size];
@@ -229,9 +267,17 @@ void StdMeshersGUI_DistrPreview::update()
       max_x = x[i];
   }
 
-  setAxisScale( curveXAxis( myDensity ), min_x, max_x );
-  setAxisScale( curveYAxis( myDensity ), min( 0.0, min_y ), max( 0.0, max_y ) );
-  setCurveData( myDensity, x, y, size );
+  setAxisScale( myDensity->xAxis(), min_x, max_x );
+  setAxisScale( myDensity->yAxis(),
+#ifdef WIN32
+    min( 0.0, min_y ),
+    max( 0.0, max_y )
+#else
+    std::min( 0.0, min_y ),
+    std::max( 0.0, max_y )
+#endif
+    );
+  myDensity->setData( x, y, size );
   if( x )
     delete[] x;
   if( y )
@@ -246,7 +292,7 @@ void StdMeshersGUI_DistrPreview::update()
     x[i] = distr[i];
     y[i] = 0;
   }
-  setCurveData( myDistr, x, y, size );
+  myDistr->setData( x, y, size );
   delete[] x;
   delete[] y;
   x = y = 0;
@@ -263,11 +309,13 @@ void StdMeshersGUI_DistrPreview::update()
 
 void StdMeshersGUI_DistrPreview::showError()
 {
-  setAxisScale( curveXAxis( myDensity ), 0.0, 1.0 );
-  setAxisScale( curveYAxis( myDensity ), 0.0, 1.0 );
-  setCurveData( myDensity, 0, 0, 0 );
-  setCurveData( myDistr, 0, 0, 0 );
-  setMarkerLabel( myMsg, tr( "SMESH_INVALID_FUNCTION" ) );
+  setAxisScale( myDensity->xAxis(), 0.0, 1.0 );
+  setAxisScale( myDensity->yAxis(), 0.0, 1.0 );
+  myDensity->setData( 0, 0, 0 );
+  myDistr->setData( 0, 0, 0 );
+  QwtText mt = myMsg->label();
+  mt.setText( tr( "SMESH_INVALID_FUNCTION" ) );
+  myMsg->setLabel( mt );
   replot();
 }
 
@@ -301,7 +349,7 @@ bool StdMeshersGUI_DistrPreview::init( const QString& str )
     OCC_CATCH_SIGNALS;
 #endif
     myExpr = ExprIntrp_GenExp::Create();
-    myExpr->Process( ( Standard_CString ) str.latin1() );
+    myExpr->Process( ( Standard_CString ) str.toLatin1().data() );
   } catch(Standard_Failure) {
     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
     parsed_ok = false;