From b08df744008ade292818b23499c367aed057507b Mon Sep 17 00:00:00 2001 From: eap Date: Thu, 17 Apr 2008 07:53:57 +0000 Subject: [PATCH] catch exceptions in BLSURF, report errors to GUI --- src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx | 55 +++++++++++++++++++++--- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx index 51df496..393f25c 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx @@ -48,6 +48,7 @@ using namespace std; #include #include #include +#include extern "C"{ #include @@ -204,6 +205,7 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp, blsu status_t curv_fun(real t, real *uv, real *dt, real *dtt, void *user_data); status_t surf_fun(real *uv, real *xyz, real*du, real *dv, real *duu, real *duv, real *dvv, void *user_data); +status_t message_callback(message_t *msg, void *user_data); //============================================================================= /*! @@ -223,8 +225,10 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) }; context_t *ctx = context_new(); - cad_t *c = cad_new(ctx); + context_set_message_callback(ctx, message_callback, &_comment); + cad_t *c = cad_new(ctx); + TopTools_IndexedMapOfShape fmap; TopTools_IndexedMapOfShape emap; TopTools_IndexedMapOfShape pmap; @@ -297,7 +301,7 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) } } // for edge } //for face - + @@ -310,12 +314,37 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) cout << "Beginning of Surface Mesh generation" << endl; cout << endl; - if (blsurf_compute_mesh(bls) != STATUS_OK){ + status_t status = STATUS_ERROR; + + try { + OCC_CATCH_SIGNALS; + status = blsurf_compute_mesh(bls); + } + catch ( std::exception& exc ) { +// if ( !_comment.empty() ) +// _comment += "\n"; + _comment += exc.what(); + } + catch (Standard_Failure& ex) { +// if ( !_comment.empty() ) +// _comment += "\n"; + _comment += ex.DynamicType()->Name(); + if ( ex.GetMessageString() && strlen( ex.GetMessageString() )) { + _comment += ": "; + _comment += ex.GetMessageString(); + } + } + catch (...) { + if ( _comment.empty() ) + _comment = "Exception in blsurf_compute_mesh()"; + } + if ( status != STATUS_OK) { blsurf_session_delete(bls); cad_delete(c); context_delete(ctx); - return false; + return error(_comment); + //return false; } cout << endl; @@ -329,7 +358,8 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) cad_delete(c); context_delete(ctx); - return false; + return error(_comment); + //return false; } integer nv, ne, nt, nq, vtx[4], tag; @@ -533,3 +563,18 @@ status_t surf_fun(real *uv, real *xyz, real*du, real *dv, return 0; } + +status_t message_callback(message_t *msg, void *user_data) +{ + integer errnumber = 0; + message_get_number(msg, &errnumber); + if ( errnumber < 0 ) { + char *desc; + string * error = (string*)user_data; + message_get_description(msg, &desc); +// if ( !error->empty() ) +// *error += "\n"; + *error += desc; + } + return STATUS_OK; +} -- 2.39.2