Salome HOME
0020206: EDF SMESH 987: Netgen1D2D3D +submesh
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_DistrPreview.cxx
index f763fbd9c27b032f4e0099c6eb16da0a9bddd268..79f8b15b01fba9ac9e66d61db26c0770d7fa8927 100644 (file)
@@ -1,11 +1,44 @@
-
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  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
+//
 #include "StdMeshersGUI_DistrPreview.h"
+
 #include <Expr_NamedUnknown.hxx>
 #include <Expr_GeneralExpression.hxx>
-#include <CASCatch_CatchSignals.hxx>
-#include <CASCatch_Failure.hxx> 
-#include <CASCatch_ErrorHandler.hxx>
-#include <OSD.hxx>
+
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#define NO_CAS_CATCH
+#endif
+
+#include <Standard_Failure.hxx>
+
+#ifdef NO_CAS_CATCH
+#include <Standard_ErrorHandler.hxx>
+#endif
+
+#ifdef WIN32
+# include <algorithm>
+#else
+ using namespace std;
+#endif
 
 StdMeshersGUI_DistrPreview::StdMeshersGUI_DistrPreview( QWidget* p, StdMeshers::StdMeshers_NumberOfSegments_ptr h )
 : QwtPlot( p ),
@@ -19,8 +52,8 @@ StdMeshersGUI_DistrPreview::StdMeshersGUI_DistrPreview( QWidget* p, StdMeshers::
 {
   myHypo = StdMeshers::StdMeshers_NumberOfSegments::_duplicate( h );
   myVars.ChangeValue( 1 ) = new Expr_NamedUnknown( "t" );
-  myCurve1 = insertCurve( QString() );
-  myCurve2 = insertCurve( QString() );
+  myDensity = insertCurve( QString() );
+  myDistr = insertCurve( QString() );
   myMsg = insertMarker( new QwtPlotMarker( this ) );
   setMarkerPos( myMsg, 0.5, 0.5 );
   setMarkerLabelPen( myMsg, QPen( Qt::red, 1 ) );
@@ -28,11 +61,16 @@ StdMeshersGUI_DistrPreview::StdMeshersGUI_DistrPreview( QWidget* p, StdMeshers::
   f.setPointSize( 14 );
   f.setBold( true );
   setMarkerFont( myMsg, f );
-  setCurvePen( myCurve1, QPen( Qt::red, 1 ) );
+  setCurvePen( myDensity, QPen( Qt::red, 1 ) );
 
   QColor dc = Qt::blue;
-  setCurvePen( myCurve2, QPen( dc, 1 ) );
-  setCurveSymbol( myCurve2, QwtSymbol( QwtSymbol::XCross, QBrush( dc ), QPen( dc ), QSize( 5, 5 ) ) );
+  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" ) );
 }
 
 StdMeshersGUI_DistrPreview::~StdMeshersGUI_DistrPreview()
@@ -196,9 +234,9 @@ void StdMeshersGUI_DistrPreview::update()
       max_x = x[i];
   }
 
-  setAxisScale( curveXAxis( myCurve1 ), min_x, max_x );
-  setAxisScale( curveYAxis( myCurve1 ), min( 0.0, min_y ), max( 0.0, max_y ) );
-  setCurveData( myCurve1, x, y, size );
+  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 );
   if( x )
     delete[] x;
   if( y )
@@ -213,19 +251,27 @@ void StdMeshersGUI_DistrPreview::update()
     x[i] = distr[i];
     y[i] = 0;
   }
-  setCurveData( myCurve2, x, y, size );
+  setCurveData( myDistr, x, y, size );
   delete[] x;
   delete[] y;
   x = y = 0;
-  replot();
+
+  try {   
+#ifdef NO_CAS_CATCH
+    OCC_CATCH_SIGNALS;
+#endif
+    replot();
+  } catch(Standard_Failure) {
+    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+  }
 }
 
 void StdMeshersGUI_DistrPreview::showError()
 {
-  setAxisScale( curveXAxis( myCurve1 ), 0.0, 1.0 );
-  setAxisScale( curveYAxis( myCurve1 ), 0.0, 1.0 );
-  setCurveData( myCurve1, 0, 0, 0 );
-  setCurveData( myCurve2, 0, 0, 0 );
+  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" ) );
   replot();
 }
@@ -254,22 +300,17 @@ bool isCorrectArg( const Handle( Expr_GeneralExpression )& expr )
 
 bool StdMeshersGUI_DistrPreview::init( const QString& str )
 {
-  CASCatch_CatchSignals aCatchSignals;
-  aCatchSignals.Activate();
-
   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(CASCatch_Failure)
-  {
-    aCatchSignals.Deactivate();
-    Handle(CASCatch_Failure) aFail = CASCatch_Failure::Caught();
+  } catch(Standard_Failure) {
+    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
     parsed_ok = false;
   }
-  aCatchSignals.Deactivate();
 
   bool syntax = false, args = false;
   if( parsed_ok && myExpr->IsDone() )
@@ -299,23 +340,20 @@ double StdMeshersGUI_DistrPreview::funcValue( const double t, bool& ok )
 
 double StdMeshersGUI_DistrPreview::calc( bool& ok )
 {
-  OSD::SetSignal( true );
   double res = 0.0;
 
-  CASCatch_CatchSignals aCatchSignals;
-  aCatchSignals.Activate();
-
   ok = true;
-  CASCatch_TRY {   
+  try {   
+#ifdef NO_CAS_CATCH
+    OCC_CATCH_SIGNALS;
+#endif
     res = myExpr->Expression()->Evaluate( myVars, myValues );
-  }
-  CASCatch_CATCH(CASCatch_Failure) {
-    aCatchSignals.Deactivate();
-    Handle(CASCatch_Failure) aFail = CASCatch_Failure::Caught();
+  } catch(Standard_Failure) {
+    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
     ok = false;
     res = 0.0;
   }
-  aCatchSignals.Deactivate();
+
   return res;
 }
 
@@ -326,22 +364,22 @@ bool StdMeshersGUI_DistrPreview::isDone() const
 
 bool StdMeshersGUI_DistrPreview::convert( double& v ) const
 {
-  CASCatch_CatchSignals aCatchSignals;
-  aCatchSignals.Activate();
-
   bool ok = true;
   switch( myConv )
   {
   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(CASCatch_Failure)
-      {
-       aCatchSignals.Deactivate();
-       Handle(CASCatch_Failure) aFail = CASCatch_Failure::Caught();
+      } catch(Standard_Failure) {
+       Handle(Standard_Failure) aFail = Standard_Failure::Caught();
        v = 0.0;
        ok = false;
       }
@@ -353,6 +391,6 @@ bool StdMeshersGUI_DistrPreview::convert( double& v ) const
       v = 0;
     break;
   }
-  aCatchSignals.Deactivate();
+
   return ok;
 }