Index: trunk/src/board.c =================================================================== --- trunk/src/board.c (revision 28922) +++ trunk/src/board.c (revision 28923) @@ -370,6 +370,44 @@ return chg; } +pcb_coord_t pcb_board_thickness(pcb_board_t *pcb, const char *namespace, pcb_board_thickness_flags_t flags) +{ + pcb_layergrp_id_t gid; + pcb_layergrp_t *grp; + pcb_coord_t curr, total = 0; + + for(gid = 0, grp = pcb->LayerGroups.grp; gid < pcb->LayerGroups.len; gid++,grp++) { + const char *s; + + if (!(grp->ltype & PCB_LYT_COPPER) && !(grp->ltype & PCB_LYT_SUBSTRATE)) + continue; + + if (namespace != NULL) + s = pcb_attribute_get_namespace(&grp->Attributes, namespace, "thickness"); + else + s = pcb_attribute_get(&grp->Attributes, "thickness"); + curr = 0; + if (s != NULL) + curr = pcb_get_value(s, NULL, NULL, NULL); + if (curr <= 0) { + if (grp->ltype & PCB_LYT_SUBSTRATE) { + if (flags & PCB_BRDTHICK_PRINT_ERROR) { + if (namespace != NULL) + pcb_message(PCB_MSG_ERROR, "%s: ", namespace); + pcb_message(PCB_MSG_ERROR, "can not determine substrate thickness on layer group %ld - total board thickness is probably wrong\n", (long)gid); + } + if (flags & PCB_BRDTHICK_TOLERANT) + continue; + return -1; + } + else + continue; + } + total += curr; + } + return total; +} + pcb_pixmap_t *pcb_pixmap_insert_or_free(pcb_board_t *pcb, pcb_pixmap_t *pm) { return NULL; Index: trunk/src/board.h =================================================================== --- trunk/src/board.h (revision 28922) +++ trunk/src/board.h (revision 28923) @@ -176,6 +176,16 @@ board is not a subc, this call is a NOP; implemented in obj_subc.c */ void pcb_subc_as_board_update(pcb_board_t *pcb); +/*** thickness ***/ +typedef enum pcb_board_thickness_flags_e { /* bitfield */ + PCB_BRDTHICK_TOLERANT = 1, /* return -1 if any substrate layer lacks thickness */ + PCB_BRDTHICK_PRINT_ERROR = 2 /* print an error message for missing thickness attributes */ +} pcb_board_thickness_flags_t; + +/* Return the board thickness or -1 on error */ +pcb_coord_t pcb_board_thickness(pcb_board_t *pcb, const char *namespace, pcb_board_thickness_flags_t flags); + + #define PCB_ACT_BOARD ((pcb_board_t *)argv[0].val.argv0.user_call_ctx) #endif Index: trunk/src_plugins/export_gcode/gcode.c =================================================================== --- trunk/src_plugins/export_gcode/gcode.c (revision 28922) +++ trunk/src_plugins/export_gcode/gcode.c (revision 28923) @@ -148,34 +148,7 @@ } -static pcb_coord_t pcb_board_thickness(pcb_board_t *pcb) -{ - pcb_layergrp_id_t gid; - pcb_layergrp_t *grp; - pcb_coord_t curr, total = 0; - for(gid = 0, grp = pcb->LayerGroups.grp; gid < pcb->LayerGroups.len; gid++,grp++) { - const char *s; - - if (!(grp->ltype & PCB_LYT_COPPER) && !(grp->ltype & PCB_LYT_SUBSTRATE)) - continue; - s = pcb_attribute_get(&grp->Attributes, "gcode::thickness"); - if (s == NULL) - s = pcb_attribute_get(&grp->Attributes, "thickness"); - - curr = 0; - if (s != NULL) - curr = pcb_get_value(s, NULL, NULL, NULL); - if (curr <= 0) { - if (grp->ltype & PCB_LYT_SUBSTRATE) - pcb_message(PCB_MSG_ERROR, "gcode: can not determine substrate thickness on layer group %ld - total board thickness is probably wrong\n", (long)gid); - continue; - } - total += curr; - } - return curr; -} - #define thru_start_depth 102 static void gcode_print_header(void) @@ -197,7 +170,7 @@ if (total == 0) { - total = pcb_board_thickness(gctx.pcb); + total = pcb_board_thickness(gctx.pcb, "gcode", PCB_BRDTHICK_PRINT_ERROR); if (total == 0) { pcb_message(PCB_MSG_ERROR, "export_gcode: can't determine board thickness - not exporting thru-cut layer\n"); return; Index: trunk/src_plugins/export_stl/export_stl.c =================================================================== --- trunk/src_plugins/export_stl/export_stl.c (revision 28922) +++ trunk/src_plugins/export_stl/export_stl.c (revision 28923) @@ -181,36 +181,6 @@ return 0; } -TODO("this is the same code as in g-code and probably openscad has a version too - centralize"); -static pcb_coord_t pcb_board_thickness(pcb_board_t *pcb) -{ - pcb_layergrp_id_t gid; - pcb_layergrp_t *grp; - pcb_coord_t curr, total = 0; - - for(gid = 0, grp = pcb->LayerGroups.grp; gid < pcb->LayerGroups.len; gid++,grp++) { - const char *s; - - if (!(grp->ltype & PCB_LYT_COPPER) && !(grp->ltype & PCB_LYT_SUBSTRATE)) - continue; - s = pcb_attribute_get(&grp->Attributes, "stl::thickness"); - if (s == NULL) - s = pcb_attribute_get(&grp->Attributes, "thickness"); - - curr = 0; - if (s != NULL) - curr = pcb_get_value(s, NULL, NULL, NULL); - if (curr <= 0) { - if (grp->ltype & PCB_LYT_SUBSTRATE) - pcb_message(PCB_MSG_ERROR, "stl: can not determine substrate thickness on layer group %ld - total board thickness is probably wrong\n", (long)gid); - continue; - } - total += curr; - } - return curr; -} - - static void stl_do_export(pcb_hid_t *hid, pcb_hid_attr_val_t *options) { const char *filename; @@ -240,7 +210,7 @@ /* determine sheet thickness */ if (options[HA_ovrthick].crd > 0) thick = options[HA_ovrthick].crd; - else thick = pcb_board_thickness(PCB); + else thick = pcb_board_thickness(PCB, "stl", PCB_BRDTHICK_PRINT_ERROR); if (thick <= 0) { pcb_message(PCB_MSG_WARNING, "STL: can not determine board thickness - falling back to hardwired 1.6mm\n"); thick = PCB_MM_TO_COORD(1.6);