Index: trunk/scconfig/Rev.h =================================================================== --- trunk/scconfig/Rev.h (revision 28609) +++ trunk/scconfig/Rev.h (revision 28610) @@ -1 +1 @@ -static const int myrev = 28441; +static const int myrev = 28609; Index: trunk/scconfig/Rev.tab =================================================================== --- trunk/scconfig/Rev.tab (revision 28609) +++ trunk/scconfig/Rev.tab (revision 28610) @@ -1,3 +1,4 @@ +28609 configure layer code split (layer_addr.[ch]) 28441 configure remove old gcode plugin 28114 distclean puplug bug blocked loading script pups 27952 configure removing dolists.h to simplify action declaration Index: trunk/src/Makefile.in =================================================================== --- trunk/src/Makefile.in (revision 28609) +++ trunk/src/Makefile.in (revision 28610) @@ -174,6 +174,7 @@ insert.o intersect.o layer.o + layer_addr.o layer_grp.o layer_ui.o layer_vis.o Index: trunk/src/actions_pcb.c =================================================================== --- trunk/src/actions_pcb.c (revision 28609) +++ trunk/src/actions_pcb.c (revision 28610) @@ -37,6 +37,7 @@ #include "data.h" #include "compat_misc.h" #include "layer.h" +#include "layer_addr.h" #include "pcb-printf.h" #include "conf_core.h" Index: trunk/src/hid_cam.c =================================================================== --- trunk/src/hid_cam.c (revision 28609) +++ trunk/src/hid_cam.c (revision 28610) @@ -38,6 +38,7 @@ #include "hid_cam.h" #include "hid_attrib.h" #include "compat_misc.h" +#include "layer_addr.h" #include "layer_vis.h" #include "plug_io.h" @@ -228,41 +229,6 @@ cam->pcb->Data->Layer[n].meta.real.vis = cam->orig_vis[n]; } -static int parse_layer_type(char *type, pcb_layer_type_t *lyt, int *offs, int *has_offs) -{ - char *soffs, *end, *nxt, *cur; - pcb_layer_type_t l; - - *lyt = 0; - *offs = *has_offs = 0; - - soffs = strchr(type, ':'); - if (soffs != NULL) { - *soffs = '\0'; - *offs = strtol(soffs+1, &end, 10); - if (*end != '\0') { - pcb_message(PCB_MSG_ERROR, "CAM rule: invalid offset '%s'\n", soffs); - return 1; - } - *has_offs = 1; - } - - for(cur = type; cur != NULL; cur = nxt) { - nxt = strchr(cur, '-'); - if (nxt != NULL) { - *nxt = '\0'; - nxt++; - } - l = pcb_layer_type_str2bit(cur); - if (l == 0) { - pcb_message(PCB_MSG_ERROR, "CAM rule: invalid layer type '%s'\n", cur); - return 1; - } - (*lyt) |= l; - } - return 0; -} - static char *lp_err = ""; /* Parse a layer directive: split at comma, curr will end up holding the @@ -325,42 +291,6 @@ return NULL; /* no more layers */ } - -static void parse_layer_supplements(char **spk, char **spv, int spc, char **purpose, pcb_xform_t **xf, pcb_xform_t *xf_) -{ - int n; - - *purpose = NULL; - memset(xf_, 0, sizeof(pcb_xform_t)); - - for(n = 0; n < spc; n++) { - char *key = spk[n], *val = spv[n]; - - if (strcmp(key, "purpose") == 0) - *purpose = val; - else if (strcmp(key, "bloat") == 0) { - pcb_bool succ; - double v = pcb_get_value(val, NULL, NULL, &succ); - if (succ) { - xf_->bloat = v; - *xf = xf_; - } - else - pcb_message(PCB_MSG_ERROR, "CAM: ignoring invalid layer supplement value '%s' for bloat\n", val); - } - else if (strcmp(key, "partial") == 0) { - xf_->partial_export = 1; - *xf = xf_; - } - else if (strcmp(key, "faded") == 0) { - xf_->layer_faded = 1; - *xf = xf_; - } - else - pcb_message(PCB_MSG_ERROR, "CAM: ignoring unknown layer supplement key '%s'\n", key); - } -} - static void cam_xform_init(pcb_xform_t *dst_xform) { memset(dst_xform, 0, sizeof(pcb_xform_t)); @@ -405,86 +335,6 @@ } } -int pcb_layergrp_list_by_addr(pcb_board_t *pcb, char *curr, pcb_layergrp_id_t gids[PCB_MAX_LAYERGRP], char **spk, char **spv, int spc, int *vid, pcb_xform_t **xf, pcb_xform_t *xf_in, const char *err_prefix) -{ - pcb_layergrp_id_t gid, lgids[PCB_MAX_LAYERGRP]; - int gids_max = PCB_MAX_LAYERGRP; - char *purpose; - - if (vid != NULL) - *vid = -1; - - if (*curr == '@') { - /* named layer group */ - curr++; - gid = pcb_layergrp_by_name(pcb, curr); - if (gid < 0) { - if (vid != NULL) { - const pcb_virt_layer_t *v; - int n; - parse_layer_supplements(spk, spv, spc, &purpose, xf, xf_in); - for(n = 0, v = pcb_virt_layers; v->name != NULL; n++,v++) { - if (strcmp(v->name, curr) == 0) { - *vid = n; - return 0; - } - } - } - return 0; - } - if (gid < 0) { - if (err_prefix != NULL) - pcb_message(PCB_MSG_ERROR, "%sno such layer group '%s'\n", curr, err_prefix); - return -1; - } - if (pcb->LayerGroups.grp[gid].len <= 0) - return 0; - pcb_layervis_change_group_vis(&pcb->hidlib, pcb->LayerGroups.grp[gid].lid[0], 1, 0); - parse_layer_supplements(spk, spv, spc, &purpose, xf, xf_in); - gids[0] = gid; - return 1; - } - else { - /* by layer type */ - int offs, has_offs; - pcb_layer_type_t lyt; - const pcb_virt_layer_t *vl; - - if (parse_layer_type(curr, &lyt, &offs, &has_offs) != 0) - return -1; - - parse_layer_supplements(spk, spv, spc, &purpose, xf, xf_in); - - vl = pcb_vlayer_get_first(lyt, purpose, -1); - if ((lyt & PCB_LYT_VIRTUAL) && (vl == NULL)) { - if (err_prefix != NULL) - pcb_message(PCB_MSG_ERROR, "%sno virtual layer with purpose '%s'\n", err_prefix, purpose); - return -1; - } - if (vl == NULL) { - if (has_offs) { - int len = pcb_layergrp_listp(pcb, lyt, lgids, sizeof(lgids)/sizeof(lgids[0]), -1, purpose); - if (offs < 0) - offs = len + offs; - else - offs--; - if ((offs >= 0) && (offs < len)) { - gids[0] = lgids[offs]; - return 1; - } - } - else { - return pcb_layergrp_listp(pcb, lyt, gids, gids_max, -1, purpose); - } - } - else { - if (vid != NULL) - *vid = vl->new_id - PCB_LYT_VIRTUAL - 1; - } - } - return 0; -} - int pcb_cam_begin(pcb_board_t *pcb, pcb_cam_t *dst, pcb_xform_t *dst_xform, const char *src, const pcb_export_opt_t *attr_tbl, int numa, pcb_hid_attr_val_t *options) { char *curr, *next; @@ -614,7 +464,7 @@ end = parse_layer(start, spk, spv, &spc); if ((end != NULL) && (*end != '\0')) pcb_message(PCB_MSG_ERROR, "global exporter --cam takes only one set of global supplements\n"); - parse_layer_supplements(spk, spv, spc, &purpose, &dummy, dst_xform); + pcb_parse_layer_supplements(spk, spv, spc, &purpose, &dummy, dst_xform); if (purpose != NULL) pcb_message(PCB_MSG_ERROR, "global exporter --cam ignores layer purpose\n"); free(tmp); Index: trunk/src/layer.c =================================================================== --- trunk/src/layer.c (revision 28609) +++ trunk/src/layer.c (revision 28610) @@ -786,20 +786,6 @@ return NULL; } -pcb_layer_id_t pcb_layer_str2id(pcb_data_t *data, const char *str) -{ - char *end; - pcb_layer_id_t id; - if (*str == '#') { - id = strtol(str+1, &end, 10); - if ((*end == '\0') && (id >= 0) && (id < data->LayerN)) - return id; - } -TODO("layer: do the same that cam does; test with propedit"); - return -1; -} - - void pcb_layer_link_trees(pcb_layer_t *dst, pcb_layer_t *src) { /* we can't link non-existing trees - make sure src does have the trees initialized */ Index: trunk/src/layer.h =================================================================== --- trunk/src/layer.h (revision 28609) +++ trunk/src/layer.h (revision 28610) @@ -324,10 +324,6 @@ /* Open the attribute editor for a layer */ void pcb_layer_edit_attrib(pcb_layer_t *layer); -/* Convert a textual layer reference into a layer ID. The text is either - #id or a layer name. */ -pcb_layer_id_t pcb_layer_str2id(pcb_data_t *data, const char *str); - /* How deep subcs can be nested */ #define PCB_MAX_BOUND_LAYER_RECURSION 128 Index: trunk/src/layer_addr.c =================================================================== --- trunk/src/layer_addr.c (nonexistent) +++ trunk/src/layer_addr.c (revision 28610) @@ -0,0 +1,209 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * Copyright (C) 2019 Tibor 'Igor2' Palinkas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Contact: + * Project page: http://repo.hu/projects/pcb-rnd + * lead developer: http://repo.hu/projects/pcb-rnd/contact.html + * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") + */ + +#include "config.h" + +#include "board.h" +#include "data.h" +#include "error.h" + +#include "layer_addr.h" + +static int parse_layer_type(char *type, pcb_layer_type_t *lyt, int *offs, int *has_offs) +{ + char *soffs, *end, *nxt, *cur; + pcb_layer_type_t l; + + *lyt = 0; + *offs = *has_offs = 0; + + soffs = strchr(type, ':'); + if (soffs != NULL) { + *soffs = '\0'; + *offs = strtol(soffs+1, &end, 10); + if (*end != '\0') { + pcb_message(PCB_MSG_ERROR, "CAM rule: invalid offset '%s'\n", soffs); + return 1; + } + *has_offs = 1; + } + + for(cur = type; cur != NULL; cur = nxt) { + nxt = strchr(cur, '-'); + if (nxt != NULL) { + *nxt = '\0'; + nxt++; + } + l = pcb_layer_type_str2bit(cur); + if (l == 0) { + pcb_message(PCB_MSG_ERROR, "CAM rule: invalid layer type '%s'\n", cur); + return 1; + } + (*lyt) |= l; + } + return 0; +} + +void pcb_parse_layer_supplements(char **spk, char **spv, int spc, char **purpose, pcb_xform_t **xf, pcb_xform_t *xf_) +{ + int n; + + *purpose = NULL; + memset(xf_, 0, sizeof(pcb_xform_t)); + + for(n = 0; n < spc; n++) { + char *key = spk[n], *val = spv[n]; + + if (strcmp(key, "purpose") == 0) + *purpose = val; + else if (strcmp(key, "bloat") == 0) { + pcb_bool succ; + double v = pcb_get_value(val, NULL, NULL, &succ); + if (succ) { + xf_->bloat = v; + *xf = xf_; + } + else + pcb_message(PCB_MSG_ERROR, "CAM: ignoring invalid layer supplement value '%s' for bloat\n", val); + } + else if (strcmp(key, "partial") == 0) { + xf_->partial_export = 1; + *xf = xf_; + } + else if (strcmp(key, "faded") == 0) { + xf_->layer_faded = 1; + *xf = xf_; + } + else + pcb_message(PCB_MSG_ERROR, "CAM: ignoring unknown layer supplement key '%s'\n", key); + } +} + + +int pcb_layergrp_list_by_addr(pcb_board_t *pcb, char *curr, pcb_layergrp_id_t gids[PCB_MAX_LAYERGRP], char **spk, char **spv, int spc, int *vid, pcb_xform_t **xf, pcb_xform_t *xf_in, const char *err_prefix) +{ + pcb_layergrp_id_t gid, lgids[PCB_MAX_LAYERGRP]; + int gids_max = PCB_MAX_LAYERGRP; + char *purpose; + + if (vid != NULL) + *vid = -1; + + if (*curr == '@') { + /* named layer group */ + curr++; + gid = pcb_layergrp_by_name(pcb, curr); + if (gid < 0) { + if (vid != NULL) { + const pcb_virt_layer_t *v; + int n; + pcb_parse_layer_supplements(spk, spv, spc, &purpose, xf, xf_in); + for(n = 0, v = pcb_virt_layers; v->name != NULL; n++,v++) { + if (strcmp(v->name, curr) == 0) { + *vid = n; + return 0; + } + } + } + return 0; + } + if (gid < 0) { + if (err_prefix != NULL) + pcb_message(PCB_MSG_ERROR, "%sno such layer group '%s'\n", curr, err_prefix); + return -1; + } + if (pcb->LayerGroups.grp[gid].len <= 0) + return 0; + pcb_parse_layer_supplements(spk, spv, spc, &purpose, xf, xf_in); + gids[0] = gid; + return 1; + } + else { + /* by layer type */ + int offs, has_offs; + pcb_layer_type_t lyt; + const pcb_virt_layer_t *vl; + + if (parse_layer_type(curr, &lyt, &offs, &has_offs) != 0) + return -1; + + pcb_parse_layer_supplements(spk, spv, spc, &purpose, xf, xf_in); + + vl = pcb_vlayer_get_first(lyt, purpose, -1); + if ((lyt & PCB_LYT_VIRTUAL) && (vl == NULL)) { + if (err_prefix != NULL) + pcb_message(PCB_MSG_ERROR, "%sno virtual layer with purpose '%s'\n", err_prefix, purpose); + return -1; + } + if (vl == NULL) { + if (has_offs) { + int len = pcb_layergrp_listp(pcb, lyt, lgids, sizeof(lgids)/sizeof(lgids[0]), -1, purpose); + if (offs < 0) + offs = len + offs; + else + offs--; + if ((offs >= 0) && (offs < len)) { + gids[0] = lgids[offs]; + return 1; + } + } + else { + return pcb_layergrp_listp(pcb, lyt, gids, gids_max, -1, purpose); + } + } + else { + if (vid != NULL) + *vid = vl->new_id - PCB_LYT_VIRTUAL - 1; + } + } + return 0; +} + +pcb_layer_id_t pcb_layer_str2id(pcb_data_t *data, const char *str) +{ + char *end; + pcb_layer_id_t id; + if (*str == '#') { + id = strtol(str+1, &end, 10); + if ((*end == '\0') && (id >= 0) && (id < data->LayerN)) + return id; + } +TODO("layer: do the same that cam does; test with propedit"); + return -1; +} + +pcb_layergrp_id_t pcb_layergrp_str2id(pcb_board_t *pcb, const char *str) +{ + char *end; + pcb_layer_id_t id; + if (*str == '#') { + id = strtol(str+1, &end, 10); + if ((*end == '\0') && (id >= 0) && (id < pcb->LayerGroups.len)) + return id; + } +TODO("layer: do the same that cam does; test with propedit"); + return -1; +} Index: trunk/src/layer_addr.h =================================================================== --- trunk/src/layer_addr.h (nonexistent) +++ trunk/src/layer_addr.h (revision 28610) @@ -0,0 +1,19 @@ +#ifndef PCB_LAYER_ADDR_H +#define PCB_LAYER_ADDR_H + +#include "layer.h" +#include "layer_grp.h" + +/*** main API ***/ + +/* Convert a textual layer(grp) reference into a layer ID. The text is either + #id or a layer name. */ +pcb_layer_id_t pcb_layer_str2id(pcb_data_t *data, const char *str); +pcb_layergrp_id_t pcb_layergrp_str2id(pcb_board_t *pcb, const char *str); + +/*** for internal use ***/ + +void pcb_parse_layer_supplements(char **spk, char **spv, int spc, char **purpose, pcb_xform_t **xf, pcb_xform_t *xf_); +int pcb_layergrp_list_by_addr(pcb_board_t *pcb, char *curr, pcb_layergrp_id_t gids[PCB_MAX_LAYERGRP], char **spk, char **spv, int spc, int *vid, pcb_xform_t **xf, pcb_xform_t *xf_in, const char *err_prefix); + +#endif Index: trunk/src/layer_grp.c =================================================================== --- trunk/src/layer_grp.c (revision 28609) +++ trunk/src/layer_grp.c (revision 28610) @@ -1340,20 +1340,6 @@ st->cache.copper_valid = 1; } - -pcb_layergrp_id_t pcb_layergrp_str2id(pcb_board_t *pcb, const char *str) -{ - char *end; - pcb_layer_id_t id; - if (*str == '#') { - id = strtol(str+1, &end, 10); - if ((*end == '\0') && (id >= 0) && (id < pcb->LayerGroups.len)) - return id; - } -TODO("layer: do the same that cam does; test with propedit"); - return -1; -} - pcb_bool pcb_has_explicit_outline(pcb_board_t *pcb) { int i; Index: trunk/src/layer_grp.h =================================================================== --- trunk/src/layer_grp.h (revision 28609) +++ trunk/src/layer_grp.h (revision 28610) @@ -300,8 +300,6 @@ a layer in the group */ void pcb_layergrp_set_dflgly(pcb_board_t *pcb, pcb_layergrp_t *grp, const pcb_dflgmap_t *src, const char *grname, const char *lyname); -pcb_layergrp_id_t pcb_layergrp_str2id(pcb_board_t *pcb, const char *str); - /* Return true if the board has an outline layer with at least one object on it */ pcb_bool pcb_has_explicit_outline(pcb_board_t *pcb); Index: trunk/src_plugins/export_ps/ps.c =================================================================== --- trunk/src_plugins/export_ps/ps.c (revision 28609) +++ trunk/src_plugins/export_ps/ps.c (revision 28610) @@ -760,8 +760,8 @@ global.pagecount++; lastgroup = group; fprintf(global.f, "(%d.) tocp\n", global.single_page ? 2 : global.pagecount); + fprintf(global.f, "(%s) toc\n", name); } - fprintf(global.f, "(%s) toc\n", name); gds_uninit(&tmp_ln); return 0; } Index: trunk/src_plugins/propedit/propedit.c =================================================================== --- trunk/src_plugins/propedit/propedit.c (revision 28609) +++ trunk/src_plugins/propedit/propedit.c (revision 28610) @@ -36,6 +36,7 @@ #include "pcb-printf.h" #include "error.h" #include "layer.h" +#include "layer_addr.h" #include "layer_grp.h" #include "search.h" #include "crosshair.h"