Index: trunk/src/board.c =================================================================== --- trunk/src/board.c (revision 31698) +++ trunk/src/board.c (revision 31699) @@ -409,16 +409,28 @@ return chg; } -rnd_coord_t pcb_board_thickness(pcb_board_t *pcb, const char *namespace, pcb_board_thickness_flags_t flags) +rnd_coord_t pcb_stack_thickness(pcb_board_t *pcb, const char *namespace, pcb_board_thickness_flags_t flags, rnd_layergrp_id_t from, rnd_bool include_from, rnd_layergrp_id_t to, rnd_bool include_to, pcb_layer_type_t accept) { rnd_layergrp_id_t gid; pcb_layergrp_t *grp; rnd_coord_t curr, total = 0; - for(gid = 0, grp = pcb->LayerGroups.grp; gid < pcb->LayerGroups.len; gid++,grp++) { + if (from > to) + rnd_swap(rnd_layergrp_id_t, from, to); + + if (!include_from) + from++; + + if (!include_to) + to--; + + if (to < from) + return -1; + + 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)) + if (!(grp->ltype & accept)) continue; if (namespace != NULL) @@ -446,3 +458,8 @@ } return total; } + +rnd_coord_t pcb_board_thickness(pcb_board_t *pcb, const char *namespace, pcb_board_thickness_flags_t flags) +{ + return pcb_stack_thickness(pcb, namespace, flags, 0, rnd_true, pcb->LayerGroups.len-1, rnd_true, PCB_LYT_COPPER | PCB_LYT_SUBSTRATE); +} Index: trunk/src/board.h =================================================================== --- trunk/src/board.h (revision 31698) +++ trunk/src/board.h (revision 31699) @@ -182,6 +182,12 @@ PCB_BRDTHICK_PRINT_ERROR = 2 /* print an error message for missing thickness attributes */ } pcb_board_thickness_flags_t; +/* Return the total thickness of the stack between groups 'from' and 'to'; + whether the own thickness of 'from' and 'to' are included in the + calculation depends on the corresponding include_ argument. Only groups + with type matching 'accept' will be considered. Return -1 on error. */ +rnd_coord_t pcb_stack_thickness(pcb_board_t *pcb, const char *namespace, pcb_board_thickness_flags_t flags, rnd_layergrp_id_t from, rnd_bool include_from, rnd_layergrp_id_t to, rnd_bool include_to, pcb_layer_type_t accept); + /* Return the board thickness or -1 on error */ rnd_coord_t pcb_board_thickness(pcb_board_t *pcb, const char *namespace, pcb_board_thickness_flags_t flags);