Index: trunk/src/data.h =================================================================== --- trunk/src/data.h (revision 6217) +++ trunk/src/data.h (revision 6218) @@ -57,7 +57,7 @@ #define pcb_max_layer (PCB->Data->LayerN+2) /* OBSOLOTE: do not use these 4 */ -#define pcb_max_group (PCB->Data->LayerN) +#define pcb_max_group (PCB->LayerGroups.len) #define pcb_max_copper_layer (PCB->Data->LayerN) #define pcb_solder_silk_layer (pcb_max_copper_layer + PCB_SOLDER_SIDE) #define pcb_component_silk_layer (pcb_max_copper_layer + PCB_COMPONENT_SIDE) Index: trunk/src/globalconst.h =================================================================== --- trunk/src/globalconst.h (revision 6217) +++ trunk/src/globalconst.h (revision 6218) @@ -47,12 +47,8 @@ #define PCB_LARGE_VALUE (COORD_MAX / 2 - 1) /* maximum extent of board and elements */ #define PCB_MAX_LAYER 16 /* max number of layer, check source code for more changes, a *lot* more changes */ -#if 0 /* new array size that allows substrate layers */ -# define PCB_MAX_LAYERGRP ((PCB_MAX_LAYER+4)*2) /* max number of layer groups, a.k.a. physical layers */ -#else -# define PCB_MAX_LAYERGRP PCB_MAX_LAYER /* max number of layer groups, a.k.a. physical layers */ -#endif +# define PCB_MAX_LAYERGRP ((PCB_MAX_LAYER+8)*2) /* max number of layer groups, a.k.a. physical layers: a few extra outer layers per side, pluse one substrate per real layer */ #define PCB_MIN_LINESIZE PCB_MIL_TO_COORD(0.01) /* thickness of lines */ #define PCB_MAX_LINESIZE PCB_LARGE_VALUE #define PCB_MIN_ARCSIZE PCB_MIL_TO_COORD(0.01) Index: trunk/src/layer.h =================================================================== --- trunk/src/layer.h (revision 6217) +++ trunk/src/layer.h (revision 6218) @@ -29,6 +29,7 @@ #define PCB_LAYER_H typedef long int pcb_layer_id_t; +typedef long int pcb_layergrp_id_t; /* Layer type bitfield */ typedef enum { @@ -101,6 +102,7 @@ const char *SelectedColor; pcb_attribute_list_t Attributes; int no_drc; /* whether to ignore the layer when checking the design rules */ +/* pcb_layergrp_id_t grp; the group this layer is in (cross-reference) */ const char *cookie; /* for UI layers: registration cookie; NULL for unused UI layers */ }; Index: trunk/src/layer_grp.c =================================================================== --- trunk/src/layer_grp.c (revision 6217) +++ trunk/src/layer_grp.c (revision 6218) @@ -96,102 +96,95 @@ return pcb_true; } -int pcb_layer_parse_group_string(const char *s, pcb_layer_stack_t *LayerGroup, int LayerN, int oldfmt) +static int flush_item(const char *s, const char *start, pcb_layer_id_t *lids, int *lids_len, pcb_layer_type_t *loc) { - int group, member, layer; - pcb_bool c_set = pcb_false, /* flags for the two special layers to */ - s_set = pcb_false; /* provide a default setting for old formats */ - int groupnum[PCB_MAX_LAYERGRP + 2]; + char *end; + pcb_layer_id_t lid; + switch (*start) { + case 'c': case 'C': case 't': case 'T': *loc = PCB_LYT_TOP; break; + case 's': case 'S': case 'b': case 'B': *loc = PCB_LYT_BOTTOM; break; + default: + lid = strtol(start, &end, 10); + if (end != s) + return -1; + if ((*lids_len) >= PCB_MAX_LAYER) + return -1; + lids[*lids_len] = lid; + (*lids_len)++; + } + return 0; +} - /* clear struct */ - memset(LayerGroup, 0, sizeof(pcb_layer_stack_t)); +static pcb_layer_group_t *get_grp(pcb_layer_stack_t *stack, pcb_layer_type_t loc) +{ + int n; + for(n = 0; n < stack->len; n++) + if ((stack->grp[n].type & loc) && (stack->grp[n].type & PCB_LYT_COPPER)) + return &(stack->grp[n]); +} - /* Clear assignments */ - for (layer = 0; layer < PCB_MAX_LAYER + 2; layer++) - groupnum[layer] = -1; +static pcb_layer_group_t *get_grp_new_intern(pcb_layer_stack_t *stack) +{ + int bl; + for(bl = 0; bl < stack->len; bl++) { + if ((stack->grp[bl].type & PCB_LYT_BOTTOM) && (stack->grp[bl].type & PCB_LYT_COPPER)) { + /* insert a new internal layer here */ + return NULL; + } + } + return NULL; +} - /* loop over all groups */ - for (group = 0; s && *s && group < LayerN; group++) { - while (*s && isspace((int) *s)) - s++; +static void pcb_layer_group_setup_default(pcb_layer_stack_t *newg); +int pcb_layer_parse_group_string(const char *grp_str, pcb_layer_stack_t *LayerGroup, int LayerN, int oldfmt) +{ + const char *s, *start; + pcb_layer_id_t lids[PCB_MAX_LAYER]; + int lids_len = 0; + pcb_layer_type_t loc = PCB_LYT_INTERN; + pcb_layer_group_t *g; + int n; - /* loop over all group members */ - for (member = 0; *s; s++) { - /* ignore white spaces and get layernumber */ - while (*s && isspace((int) *s)) - s++; - switch (*s) { - case 'c': - case 'C': - case 't': - case 'T': - layer = LayerN + PCB_COMPONENT_SIDE; - c_set = pcb_true; - break; + /* clear struct */ + pcb_layer_group_setup_default(LayerGroup); - case 's': - case 'S': - case 'b': - case 'B': - layer = LayerN + PCB_SOLDER_SIDE; - s_set = pcb_true; - break; - - default: - if (!isdigit((int) *s)) + for(start = s = grp_str; ; s++) { + switch(*s) { + case ',': + if (flush_item(s, start, lids, &lids_len, &loc) != 0) goto error; - layer = atoi(s) - 1; + start = s+1; break; - } - if (member >= LayerN + 1) - goto error; - if (oldfmt) { - /* the old format didn't always have the silks */ - if (layer > LayerN + MAX(PCB_SOLDER_SIDE, PCB_COMPONENT_SIDE)) { - /* UGLY HACK: we assume oldfmt is 1 only when called from io_pcb .y */ - PCB->Data->LayerN++; - LayerN++; - } - if (layer > LayerN + MAX(PCB_SOLDER_SIDE, PCB_COMPONENT_SIDE) + 2) + case '\0': + case ':': + if (flush_item(s, start, lids, &lids_len, &loc) != 0) goto error; - } - else { - if (layer > LayerN + MAX(PCB_SOLDER_SIDE, PCB_COMPONENT_SIDE)) - goto error; - } - groupnum[layer] = group; - LayerGroup->grp[group].lid[member++] = layer; - while (*++s && isdigit((int) *s)); + /* finalize group */ + if (loc & PCB_LYT_INTERN) + g = get_grp_new_intern(LayerGroup); + else + g = get_grp(LayerGroup, loc); - /* ignore white spaces and check for separator */ - while (*s && isspace((int) *s)) - s++; - if (!*s || *s == ':') +if (g != NULL) { + for(n = 0; n < lids_len; n++) + g->lid[n] = lids[n]; + g->len = lids_len; +} + /* prepare for next iteration */ + loc = PCB_LYT_INTERN; + start = s+1; break; - if (*s != ',') - goto error; } - LayerGroup->grp[group].len = member; - if (*s == ':') - s++; + if (*s == '\0') + break; } - if (!s_set) - LayerGroup->grp[PCB_SOLDER_SIDE].lid[LayerGroup->grp[PCB_SOLDER_SIDE].len++] = LayerN + PCB_SOLDER_SIDE; - if (!c_set) - LayerGroup->grp[PCB_COMPONENT_SIDE].lid[LayerGroup->grp[PCB_COMPONENT_SIDE].len++] = LayerN + PCB_COMPONENT_SIDE; - for (layer = 0; layer < LayerN && group < LayerN; layer++) - if (groupnum[layer] == -1) { - LayerGroup->grp[group].lid[0] = layer; - LayerGroup->grp[group].len = 1; - group++; - } - return (0); + return 0; /* reset structure on error */ error: memset(LayerGroup, 0, sizeof(pcb_layer_stack_t)); - return (1); + return 1; } int pcb_layer_gui_set_glayer(pcb_layergrp_id_t grp, int is_empty) @@ -292,7 +285,7 @@ #define NEWG(g, flags, gname) \ do { \ - g = &(newg.grp[newg.len]); \ + g = &(newg->grp[newg->len]); \ g->valid = 1; \ if (gname != NULL) \ g->name = pcb_strdup(gname); \ @@ -299,66 +292,26 @@ else \ g->name = NULL; \ g->type = flags; \ - newg.len++; \ + newg->len++; \ } while(0) -#define APPEND_ALL(_grp_, src_grp_id, flags) \ -do { \ - int __n__; \ - pcb_layer_group_t *__s__ = &pcb->LayerGroups.grp[src_grp_id]; \ - for(__n__ = 0; __n__ < (__s__)->len; __n__++) { \ - if (pcb_layer_flags((__s__)->lid[__n__]) & flags) { \ - _grp_->lid[_grp_->len] = __s__->lid[__n__]; \ - _grp_->len++; \ - } \ - } \ -} while(0) - -void pcb_layer_group_from_old(pcb_board_t *pcb) +static void pcb_layer_group_setup_default(pcb_layer_stack_t *newg) { - pcb_layer_stack_t newg; pcb_layer_group_t *g; - int n; - memset(&newg, 0, sizeof(newg)); + memset(newg, 0, sizeof(pcb_layer_stack_t)); NEWG(g, PCB_LYT_TOP | PCB_LYT_PASTE, "top paste"); - NEWG(g, PCB_LYT_TOP | PCB_LYT_SILK, "top silk"); APPEND_ALL(g, 0, PCB_LYT_SILK); + NEWG(g, PCB_LYT_TOP | PCB_LYT_SILK, "top silk"); NEWG(g, PCB_LYT_TOP | PCB_LYT_MASK, "top mask"); - NEWG(g, PCB_LYT_TOP | PCB_LYT_COPPER, "top copper"); APPEND_ALL(g, 0, PCB_LYT_COPPER); + NEWG(g, PCB_LYT_TOP | PCB_LYT_COPPER, "top copper"); NEWG(g, PCB_LYT_INTERN | PCB_LYT_SUBSTRATE, NULL); - for(n = 2; n < PCB->Data->LayerN; n++) { - if (pcb_layergrp_flags(n) & PCB_LYT_COPPER) { - char nm[32]; - sprintf(nm, "internal copper %d", n); - NEWG(g, PCB_LYT_INTERN | PCB_LYT_COPPER, nm); APPEND_ALL(g, n, PCB_LYT_COPPER); - NEWG(g, PCB_LYT_INTERN | PCB_LYT_SUBSTRATE, NULL); - } - } - - NEWG(g, PCB_LYT_BOTTOM | PCB_LYT_COPPER, "bottom copper"); APPEND_ALL(g, 1, PCB_LYT_COPPER); + NEWG(g, PCB_LYT_BOTTOM | PCB_LYT_COPPER, "bottom copper"); NEWG(g, PCB_LYT_BOTTOM | PCB_LYT_MASK, "bottom mask"); - NEWG(g, PCB_LYT_BOTTOM | PCB_LYT_SILK, "bottom silk"); APPEND_ALL(g, 1, PCB_LYT_SILK); + NEWG(g, PCB_LYT_BOTTOM | PCB_LYT_SILK, "bottom silk"); NEWG(g, PCB_LYT_BOTTOM | PCB_LYT_PASTE, "bottom paste"); - /* collect all outline layers in a separate layer group */ - g = NULL; - for(n = 2; n < PCB->Data->LayerN; n++) { - if (pcb_layergrp_flags(n) & PCB_LYT_OUTLINE) { - char nm[32]; - sprintf(nm, "outline", n); - if (g == NULL) - NEWG(g, PCB_LYT_INTERN | PCB_LYT_OUTLINE, nm); - APPEND_ALL(g, n, PCB_LYT_OUTLINE); - } - } - - memcpy(&pcb->LayerGroups, &newg, sizeof(newg)); + NEWG(g, PCB_LYT_INTERN | PCB_LYT_OUTLINE, "outline"); } -void pcb_layer_group_to_old(pcb_board_t *pcb) -{ - -} - Index: trunk/src/layer_grp.h =================================================================== --- trunk/src/layer_grp.h (revision 6217) +++ trunk/src/layer_grp.h (revision 6218) @@ -28,7 +28,6 @@ #ifndef PCB_LAYER_GRP_H #define PCB_LAYER_GRP_H -typedef long int pcb_layergrp_id_t; typedef struct pcb_layer_group_s pcb_layer_group_t; #include "layer.h" Index: trunk/src_plugins/diag/diag.c =================================================================== --- trunk/src_plugins/diag/diag.c (revision 6217) +++ trunk/src_plugins/diag/diag.c (revision 6218) @@ -172,7 +172,7 @@ printf("All %d groups containing copper layers are:\n", used); for(g = 0; g < used; g++) { pcb_layergrp_id_t group_id = garr[g]; - printf(" group %ld\n", group_id); + printf(" group %ld (%d layers)\n", group_id, PCB->LayerGroups.grp[group_id].len); for(n = 0; n < PCB->LayerGroups.grp[group_id].len; n++) { pcb_layer_id_t layer_id = PCB->LayerGroups.grp[group_id].lid[n]; printf(" [%lx] %s\n", layer_id, PCB->Data->Layer[layer_id].Name); Index: trunk/src_plugins/draw_csect/draw_csect.c =================================================================== --- trunk/src_plugins/draw_csect/draw_csect.c (revision 6217) +++ trunk/src_plugins/draw_csect/draw_csect.c (revision 6218) @@ -53,8 +53,6 @@ { pcb_layergrp_id_t gid; -/* pcb_layer_group_from_old(PCB);*/ - for(gid = 0; gid < pcb_max_group; gid++) { int i; const char *type_gfx; @@ -65,7 +63,6 @@ continue; type_gfx = "old"; } - else if (g->type & PCB_LYT_OUTLINE) continue; else if (g->type & PCB_LYT_VIRTUAL) continue; else if (g->type & PCB_LYT_COPPER) type_gfx = "===="; else if (g->type & PCB_LYT_SUBSTRATE) type_gfx = "xxxx"; @@ -73,12 +70,13 @@ else if (g->type & PCB_LYT_MASK) type_gfx = "mask"; else if (g->type & PCB_LYT_PASTE) type_gfx = "pst."; else if (g->type & PCB_LYT_MISC) type_gfx = "misc"; + else if (g->type & PCB_LYT_OUTLINE) type_gfx = "||||"; else type_gfx = "????"; - printf("%s [%ld] %s\n", type_gfx, gid, g->name); + printf("%s {%ld} %s\n", type_gfx, gid, g->name); for(i = 0; i < g->len; i++) { pcb_layer_id_t lid = g->lid[i]; - pcb_layer_t *l = PCB->Data->Layer+lid; + pcb_layer_t *l = &PCB->Data->Layer[lid]; printf(" [%ld] %s\n", lid, l->Name); } }