Index: file.c =================================================================== --- file.c (revision 20868) +++ file.c (revision 20869) @@ -1083,6 +1083,15 @@ return p; } +void io_pcb_preproc_board(pcb_board_t *pcb) +{ + int n; + + /* make postproc able to detect layers with broken link */ + for(n = 0; n < PCB_MAX_LAYER; n++) + PCB->Data->Layer[n].meta.real.grp = -1; +} + void io_pcb_postproc_board(pcb_board_t *pcb) { gdl_iterator_t it; @@ -1097,6 +1106,21 @@ } } + /* check if we have layers that are not present in the group string (broken input) */ + for(n = 0; n < PCB->Data->LayerN; n++) { + if (PCB->Data->Layer[n].meta.real.grp == -1) { + pcb_layergrp_t *grp = pcb_get_grp_new_intern(pcb, -1); + + pcb_message(PCB_MSG_WARNING, "Broken input file: layer group string doesn't contain layer %ld\n(Trying to fix it by introducing a new intern copper layer)\n", n); + if (grp != NULL) { + pcb_layergrp_id_t gid = grp - PCB->LayerGroups.grp; + pcb_layer_move_to_group(pcb, n, gid); + } + else + pcb_message(PCB_MSG_ERROR, "Failed to add a new layer group - the board in memory IS BROKEN.\n"); + } + } + pcb_layergrp_create_missing_substrate(pcb); /* have to rebind all subcircuits because the layer stack was not ready Index: file.h =================================================================== --- file.h (revision 20868) +++ file.h (revision 20869) @@ -86,6 +86,7 @@ pcb_arc_t *io_pcb_element_arc_new(pcb_subc_t *subc, pcb_coord_t X, pcb_coord_t Y, pcb_coord_t Width, pcb_coord_t Height, pcb_angle_t angle, pcb_angle_t delta, pcb_coord_t Thickness); pcb_pstk_t *io_pcb_element_pin_new(pcb_subc_t *subc, pcb_coord_t X, pcb_coord_t Y, pcb_coord_t Thickness, pcb_coord_t Clearance, pcb_coord_t Mask, pcb_coord_t DrillingHole, const char *Name, const char *Number, pcb_flag_t Flags); pcb_pstk_t *io_pcb_element_pad_new(pcb_subc_t *subc, pcb_coord_t X1, pcb_coord_t Y1, pcb_coord_t X2, pcb_coord_t Y2, pcb_coord_t Thickness, pcb_coord_t Clearance, pcb_coord_t Mask, const char *Name, const char *Number, pcb_flag_t Flags); +void io_pcb_preproc_board(pcb_board_t *pcb); void io_pcb_postproc_board(pcb_board_t *pcb); /* This is the version we support. */ Index: parse_l.c =================================================================== --- parse_l.c (revision 20868) +++ parse_l.c (revision 20869) @@ -2525,6 +2525,8 @@ if (settings_dest != CFR_invalid) conf_reset(settings_dest, Filename); + io_pcb_preproc_board(PCB); + retval = Parse(NULL, fcmd, conf_core.rc.file_path, Filename); if ((settings_dest != CFR_invalid) && (retval == 0)) { Index: parse_l.l =================================================================== --- parse_l.l (revision 20868) +++ parse_l.l (revision 20869) @@ -382,6 +382,8 @@ if (settings_dest != CFR_invalid) conf_reset(settings_dest, Filename); + io_pcb_preproc_board(PCB); + retval = Parse(NULL, fcmd, conf_core.rc.file_path, Filename); if ((settings_dest != CFR_invalid) && (retval == 0)) {