star-cad

Geometric operators for computer-aided design
git clone git://git.meso-star.fr/star-cad.git
Log | Files | Refs | README | LICENSE

commit 42bea5112b3e8f089ac4fa7a1f5083e3bc612a91
parent 9825cb980cf9ce9177572e285083a9d1f29ee89a
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Thu,  8 Sep 2022 18:38:37 +0200

Improve error messages

Diffstat:
Msrc/scad.c | 6+++---
Msrc/scad_device.c | 58+++++++++++++++++++++++++++++++++++-----------------------
Msrc/scad_device.h | 2+-
Msrc/scad_geometry.c | 38+++++++++++++++++++-------------------
4 files changed, 58 insertions(+), 46 deletions(-)

diff --git a/src/scad.c b/src/scad.c @@ -269,7 +269,7 @@ scad_stl_export goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); if(get_device()->need_synchro) { ERR(scad_synchronize()); @@ -423,7 +423,7 @@ scad_stl_export_split goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); if(get_device()->need_synchro) { ERR(scad_synchronize()); @@ -505,7 +505,7 @@ scad_scene_mesh int ierr = 0; res_T res = RES_OK; - ERR(check_device()); + ERR(check_device(FUNC_NAME)); if(get_device()->need_synchro) { ERR(scad_synchronize()); diff --git a/src/scad_device.c b/src/scad_device.c @@ -100,11 +100,16 @@ static struct scad_device* g_device = NULL; ******************************************************************************/ res_T check_device - (void) + (const char* function_name) { res_T res = RES_OK; + ASSERT(function_name); if(!g_device) { + /* No logger available for a message */ + fprintf(stderr, + "%s: cannot call API functions if star-cad in not initialized.\n", + function_name); res = RES_BAD_ARG; goto error; } @@ -274,7 +279,7 @@ scad_finalize res_T res = RES_OK; int ierr; - ERR(check_device()); + ERR(check_device(FUNC_NAME)); device_release(g_device); g_device = NULL; @@ -287,6 +292,15 @@ error: goto exit; } +#define SET_GMSH_OPTION_DOUBLE(Option) \ + gmshOptionSetNumber((#Option), (actual_options->Option), &ierr);\ + if(ierr) {\ + log_error(dev, "Could not set option %s to %g.\n",\ + (#Option), (actual_options->Option));\ + res = RES_BAD_ARG;\ + goto error;\ + } + res_T scad_set_options (const struct scad_options* options) @@ -296,34 +310,32 @@ scad_set_options = options ? options : &SCAD_DEFAULT_OPTIONS; int ierr = 0; struct scad_options keep; + struct scad_device* dev = NULL; - ERR(check_device()); + ERR(check_device(FUNC_NAME)); - keep = get_device()->options; + dev = get_device(); + keep = dev->options; - gmshOptionSetNumber("Mesh.StlOneSolidPerSurface", - actual_options->Mesh.StlOneSolidPerSurface, &ierr); - ERR(gmsh_err_to_res_T(ierr)); - gmshOptionSetNumber("Mesh.MeshSizeFromPoints", - actual_options->Mesh.MeshSizeFromPoints, &ierr); - ERR(gmsh_err_to_res_T(ierr)); - gmshOptionSetNumber("Mesh.MeshSizeFromCurvature", - actual_options->Mesh.MeshSizeFromCurvature, &ierr); - ERR(gmsh_err_to_res_T(ierr)); - gmshOptionSetNumber("Mesh.MinimumElementsPerTwoPi", - actual_options->Mesh.MinimumElementsPerTwoPi, &ierr); - ERR(gmsh_err_to_res_T(ierr)); - gmshOptionSetNumber("Mesh.MeshSizeExtendFromBoundary", - actual_options->Mesh.MeshSizeExtendFromBoundary, &ierr); - ERR(gmsh_err_to_res_T(ierr)); + SET_GMSH_OPTION_DOUBLE(Mesh.StlOneSolidPerSurface); + SET_GMSH_OPTION_DOUBLE(Mesh.MeshSizeFromPoints); + SET_GMSH_OPTION_DOUBLE(Mesh.MeshSizeFromCurvature); + SET_GMSH_OPTION_DOUBLE(Mesh.MinimumElementsPerTwoPi); + SET_GMSH_OPTION_DOUBLE(Mesh.MeshSizeExtendFromBoundary); - get_device()->options = *actual_options; + if(options) { + /* Check non-gmsh option validity if user-provided */ + (void)actual_options->Misc.Step; /* int boolean: always OK */ + (void)actual_options->Misc.SynchronizeOnRunUI; /* int boolean: always OK */ + } + + dev->options = *actual_options; exit: return res; error: - fprintf(stderr, "%s: can't initialize gmsh -- %s\n", - FUNC_NAME, res_to_cstr(res)); - if(get_device()) get_device()->options = keep; + if(dev) dev->options = keep; goto exit; } + +#undef SET_GMSH_OPTION_DOUBLE diff --git a/src/scad_device.h b/src/scad_device.h @@ -133,7 +133,7 @@ log_msg ******************************************************************************/ LOCAL_SYM res_T check_device - (void); + (const char* function_name); LOCAL_SYM struct scad_device* get_device diff --git a/src/scad_geometry.c b/src/scad_geometry.c @@ -152,7 +152,7 @@ scad_geometries_partition_core goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); if(get_device()->need_synchro) { ERR(scad_synchronize()); } @@ -264,7 +264,7 @@ scad_geometry_delete goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); ERR(geometry_release(geom)); @@ -281,7 +281,7 @@ scad_scene_clear res_T res = RES_OK; int ierr; - ERR(check_device()); + ERR(check_device(FUNC_NAME)); /* FIXME: not sure remove is needed. */ gmshModelRemove(&ierr); @@ -304,7 +304,7 @@ scad_geometry_get_count if(!geom || !count) goto error; - ERR(check_device()); + ERR(check_device(FUNC_NAME)); ASSERT(geom->gmsh_dimTags_n % 2 == 0); *count = geom->gmsh_dimTags_n / 2; @@ -333,7 +333,7 @@ scad_add_rectangle goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); gmsh_ID = gmshModelOccAddRectangle(SPLIT3(xyz), SPLIT2(dxdy), -1, 0, &ierr); ERR(gmsh_err_to_res_T(ierr)); @@ -376,7 +376,7 @@ scad_add_disk goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); gmsh_ID = gmshModelOccAddDisk(SPLIT3(xyz), radius, radius, -1, &ierr); ERR(gmsh_err_to_res_T(ierr)); @@ -425,7 +425,7 @@ scad_add_polygon goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); points = malloc(count * sizeof(int)); for (i=0; i<count; ++i) { @@ -488,7 +488,7 @@ scad_add_box goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); gmsh_ID = gmshModelOccAddBox(SPLIT3(xyz), SPLIT3(dxdydz), -1, &ierr); ERR(gmsh_err_to_res_T(ierr)); @@ -533,7 +533,7 @@ scad_add_cylinder goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); gmsh_ID = gmshModelOccAddCylinder(SPLIT3(xyz), SPLIT3(axis), rad, -1, angle, &ierr); @@ -577,7 +577,7 @@ scad_add_sphere goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); gmsh_ID = gmshModelOccAddSphere(SPLIT3(xyz), rad, -1, -PI/2, PI/2, 2*PI, &ierr); ERR(gmsh_err_to_res_T(ierr)); @@ -628,7 +628,7 @@ scad_fuse_geometries goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); if(get_device()->need_synchro) { ERR(scad_synchronize()); } @@ -690,7 +690,7 @@ scad_cut_geometries goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); if(get_device()->need_synchro) { ERR(scad_synchronize()); } @@ -752,7 +752,7 @@ scad_intersect_geometries goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); if(get_device()->need_synchro) { ERR(scad_synchronize()); } @@ -817,7 +817,7 @@ scad_geometries_common_boundaries goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); if(get_device()->need_synchro) { ERR(scad_synchronize()); } @@ -878,7 +878,7 @@ scad_geometry_rotate goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); if(get_device()->need_synchro) { ERR(scad_synchronize()); } @@ -917,7 +917,7 @@ scad_geometry_extrude goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); if(get_device()->need_synchro) { ERR(scad_synchronize()); } @@ -977,7 +977,7 @@ scad_geometry_copy goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); if(get_device()->need_synchro) { ERR(scad_synchronize()); } @@ -1014,7 +1014,7 @@ scad_geometry_translate goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); if(get_device()->need_synchro) { ERR(scad_synchronize()); } @@ -1128,7 +1128,7 @@ scad_step_import goto error; } - ERR(check_device()); + ERR(check_device(FUNC_NAME)); if(get_device()->need_synchro) { ERR(scad_synchronize()); }