commit 778d84ab930c3d0f1efbab203c33babaefe5464a
parent 4ad55a64d3bef13a776779bc1ba39a3d6c56a295
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Thu, 18 Apr 2024 16:14:29 +0200
Add a scad_dump_geometry() API call
It allows to dump information on a given geometry
Diffstat:
2 files changed, 49 insertions(+), 14 deletions(-)
diff --git a/src/scad.h b/src/scad.h
@@ -577,6 +577,15 @@ scad_get_dimtag_refcount
(const int dim,
const int tag);
+/* Dump geometry `geom' with address/name, ref count and tags.
+ * To use it from gdb:
+ * (gdb) call scad_dump_geometry( <geom_ptr> )
+ */
+SCAD_API res_T
+scad_dump_geometry
+ (const struct scad_geometry* geom);
+END_DECLS
+
/* Dump all the geometries with address/name, ref count and tags.
* To use it from gdb:
* (gdb) call scad_dump_geometries()
diff --git a/src/scad_device.c b/src/scad_device.c
@@ -256,6 +256,45 @@ device_get_description
return desc;
}
+res_T
+scad_dump_geometry
+ (const struct scad_geometry* geom)
+{
+ res_T res = RES_OK;
+ struct scad_device* dev = get_device();
+ size_t i;
+
+ if(!geom) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ ERR(check_device(FUNC_NAME));
+ if(htable_geometries_is_empty(&dev->allgeom)) {
+ printf("No geometry defined.\n");
+ return res;
+ }
+
+ if(str_is_empty(&geom->name)) {
+ printf("Unnamed geometry %p (count is %lu), tags: ",
+ (void*)geom, (long unsigned)geom->ref);
+ } else {
+ printf("Geometry '%s' (%p, count is %lu), tags: ",
+ str_cget(&geom->name), (void*)geom, (long unsigned)geom->ref);
+ }
+ for(i = 0; i < geom->gmsh_dimTags_n; i += 2) {
+ int dim = geom->gmsh_dimTags[i];
+ int tag = geom->gmsh_dimTags[i+1];
+ printf((i ? ", %d.%d" : "%d.%d"), dim, tag);
+ }
+ printf(".\n");
+
+exit:
+ return res;
+error:
+ goto exit;
+}
+
void
scad_dump_geometries
(void)
@@ -275,21 +314,8 @@ scad_dump_geometries
htable_geometries_end(&dev->allgeom, &end);
while(!htable_geometries_iterator_eq(&it, &end)) {
struct scad_geometry* geom = *htable_geometries_iterator_key_get(&it);
- size_t i;
+ SCAD(dump_geometry(geom));
htable_geometries_iterator_next(&it);
- if(str_is_empty(&geom->name)) {
- printf("Unnamed geometry %p (count is %lu), tags: ",
- (void*)geom, (long unsigned)geom->ref);
- } else {
- printf("Geometry '%s' (%p, count is %lu), tags: ",
- str_cget(&geom->name), (void*)geom, (long unsigned)geom->ref);
- }
- for(i = 0; i < geom->gmsh_dimTags_n; i += 2) {
- int dim = geom->gmsh_dimTags[i];
- int tag = geom->gmsh_dimTags[i+1];
- printf((i ? ", %d.%d" : "%d.%d"), dim, tag);
- }
- printf(".\n");
}
}