X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FStdMeshersGUI%2FStdMeshersGUI_DistrPreview.cxx;h=fc3787b9e5ced9b857475817e641d1e99d7d3348;hp=e58be313b07e36bafe76793c031bc1e4c1465789;hb=3f36c66f5af4129d370f7b2b289954ca0314f301;hpb=4ff5bd61540272713e48de1eee75625028c32155 diff --git a/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx b/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx index e58be313b..fc3787b9e 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx @@ -1,10 +1,50 @@ - +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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. +// +// 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. +// +// 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 #include "StdMeshersGUI_DistrPreview.h" -#include "CASCatch.hxx" +// Qwt includes +#include +#include +#include +#include +#include + +// OCCT includes #include #include +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#define NO_CAS_CATCH +#endif + +#include + +#ifdef NO_CAS_CATCH +#include +#endif + StdMeshersGUI_DistrPreview::StdMeshersGUI_DistrPreview( QWidget* p, StdMeshers::StdMeshers_NumberOfSegments_ptr h ) : QwtPlot( p ), myPoints( 50 ), @@ -17,25 +57,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() @@ -156,7 +215,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; @@ -172,7 +231,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]; @@ -199,9 +262,9 @@ 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(), std::min( 0.0, min_y ), std::max( 0.0, max_y ) ); + myDensity->setData( x, y, size ); if( x ) delete[] x; if( y ) @@ -216,28 +279,30 @@ 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; - CASCatch_TRY - { + try { +#ifdef NO_CAS_CATCH + OCC_CATCH_SIGNALS; +#endif replot(); - } - CASCatch_CATCH(Standard_Failure) - { + } catch(Standard_Failure) { Handle(Standard_Failure) aFail = Standard_Failure::Caught(); } } 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(); } @@ -266,13 +331,13 @@ bool isCorrectArg( const Handle( Expr_GeneralExpression )& expr ) bool StdMeshersGUI_DistrPreview::init( const QString& str ) { bool parsed_ok = true; - CASCatch_TRY - { + try { +#ifdef NO_CAS_CATCH + OCC_CATCH_SIGNALS; +#endif myExpr = ExprIntrp_GenExp::Create(); - myExpr->Process( ( Standard_CString ) str.latin1() ); - } - CASCatch_CATCH(Standard_Failure) - { + myExpr->Process( ( Standard_CString ) str.toLatin1().data() ); + } catch(Standard_Failure) { Handle(Standard_Failure) aFail = Standard_Failure::Caught(); parsed_ok = false; } @@ -308,10 +373,12 @@ double StdMeshersGUI_DistrPreview::calc( bool& ok ) double res = 0.0; ok = true; - CASCatch_TRY { + try { +#ifdef NO_CAS_CATCH + OCC_CATCH_SIGNALS; +#endif res = myExpr->Expression()->Evaluate( myVars, myValues ); - } - CASCatch_CATCH(Standard_Failure) { + } catch(Standard_Failure) { Handle(Standard_Failure) aFail = Standard_Failure::Caught(); ok = false; res = 0.0; @@ -332,16 +399,16 @@ bool StdMeshersGUI_DistrPreview::convert( double& v ) const { case EXPONENT: { - CASCatch_TRY - { + try { +#ifdef NO_CAS_CATCH + OCC_CATCH_SIGNALS; +#endif // in StdMeshers_NumberOfSegments.cc // const double PRECISION = 1e-7; // if(v < -7) v = -7.0; v = pow( 10.0, v ); - } - CASCatch_CATCH(Standard_Failure) - { + } catch(Standard_Failure) { Handle(Standard_Failure) aFail = Standard_Failure::Caught(); v = 0.0; ok = false;