Index: trunk/scconfig/Rev.h =================================================================== --- trunk/scconfig/Rev.h (revision 23601) +++ trunk/scconfig/Rev.h (revision 23602) @@ -1 +1 @@ -static const int myrev = 23589; +static const int myrev = 23602; Index: trunk/scconfig/Rev.tab =================================================================== --- trunk/scconfig/Rev.tab (revision 23601) +++ trunk/scconfig/Rev.tab (revision 23602) @@ -1,3 +1,4 @@ +23602 configure io_tedax namespace cleanup 23589 configure removing the old netlist dialog leftover from gtk 23585 configure removing the mincut stub (switched over to the event API) 23579 configure removing old netlist Index: trunk/src/Makefile.dep =================================================================== --- trunk/src/Makefile.dep (revision 23601) +++ trunk/src/Makefile.dep (revision 23602) @@ -3500,7 +3500,7 @@ ../src_plugins/io_tedax/tlayer.h layer.h \ ../src_plugins/io_tedax/tboard.h ../src_plugins/io_tedax/tdrc.h \ dolists.h -../src_plugins/io_tedax/netlist.o: ../src_plugins/io_tedax/netlist.c \ +../src_plugins/io_tedax/tnetlist.o: ../src_plugins/io_tedax/tnetlist.c \ ../config.h ../src_3rd/genht/htsp.h ../src_3rd/genht/ht.h \ ../src_3rd/genht/hash.h board.h global_typedefs.h pcb_bool.h unit.h \ vtroutestyle.h attrib.h ../src_3rd/genvector/genvector_impl.h \ Index: trunk/src_plugins/io_tedax/netlist.c =================================================================== --- trunk/src_plugins/io_tedax/netlist.c (revision 23601) +++ trunk/src_plugins/io_tedax/netlist.c (nonexistent) @@ -1,217 +0,0 @@ -/* - * COPYRIGHT - * - * pcb-rnd, interactive printed circuit board design - * - * tedax IO plugin - netlist import - * pcb-rnd Copyright (C) 2017 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 -#include - -#include "board.h" -#include "data.h" -#include "error.h" -#include "pcb-printf.h" -#include "compat_misc.h" -#include "actions.h" -#include "safe_fs.h" -#include "obj_subc.h" -#include "netlist2.h" - -#include "parse.h" - -typedef struct { - char *value; - char *footprint; -} fp_t; - -static void *htsp_get2(htsp_t *ht, const char *key, size_t size) -{ - void *res = htsp_get(ht, key); - if (res == NULL) { - res = calloc(size, 1); - htsp_set(ht, pcb_strdup(key), res); - } - return res; -} - -int tedax_net_fload(FILE *fn, int import_fp, const char *blk_id, int silent) -{ - char line[520]; - char *argv[16]; - int argc; - htsp_t fps; - htsp_entry_t *e; - - if (tedax_seek_hdr(fn, line, sizeof(line), argv, sizeof(argv)/sizeof(argv[0])) < 0) - return -1; - - if (tedax_seek_block(fn, "netlist", "v1", blk_id, silent, line, sizeof(line), argv, sizeof(argv)/sizeof(argv[0])) < 0) - return -1; - - htsp_init(&fps, strhash, strkeyeq); - - pcb_actionl("Netlist", "Freeze", NULL); - pcb_actionl("Netlist", "Clear", NULL); - - while((argc = tedax_getline(fn, line, sizeof(line), argv, sizeof(argv)/sizeof(argv[0]))) >= 0) { - if ((argc == 3) && (strcmp(argv[0], "footprint") == 0)) { - fp_t *fp = htsp_get2(&fps, argv[1], sizeof(fp_t)); - fp->footprint = pcb_strdup(argv[2]); - } - else if ((argc == 3) && (strcmp(argv[0], "value") == 0)) { - fp_t *fp = htsp_get2(&fps, argv[1], sizeof(fp_t)); - fp->value = pcb_strdup(argv[2]); - } - else if ((argc == 4) && (strcmp(argv[0], "conn") == 0)) { - char id[512]; - sprintf(id, "%s-%s", argv[2], argv[3]); - pcb_actionl("Netlist", "Add", argv[1], id, NULL); - } - else if ((argc == 2) && (strcmp(argv[0], "end") == 0) && (strcmp(argv[1], "netlist") == 0)) - break; - } - - pcb_actionl("Netlist", "Sort", NULL); - pcb_actionl("Netlist", "Thaw", NULL); - - if (import_fp) { - pcb_actionl("ElementList", "start", NULL); - for (e = htsp_first(&fps); e; e = htsp_next(&fps, e)) { - fp_t *fp = e->value; - -/* pcb_trace("tedax fp: refdes=%s val=%s fp=%s\n", e->key, fp->value, fp->footprint);*/ - if (fp->footprint == NULL) - pcb_message(PCB_MSG_ERROR, "tedax: not importing refdes=%s: no footprint specified\n", e->key); - else - pcb_actionl("ElementList", "Need", null_empty(e->key), null_empty(fp->footprint), null_empty(fp->value), NULL); - - free(e->key); - free(fp->value); - free(fp->footprint); - free(fp); - } - pcb_actionl("ElementList", "Done", NULL); - } - - htsp_uninit(&fps); - - return 0; -} - - -int tedax_net_load(const char *fname_net, int import_fp, const char *blk_id, int silent) -{ - FILE *fn; - int ret = 0; - - fn = pcb_fopen(fname_net, "r"); - if (fn == NULL) { - pcb_message(PCB_MSG_ERROR, "can't open file '%s' for read\n", fname_net); - return -1; - } - - ret = tedax_net_fload(fn, import_fp, blk_id, silent); - - fclose(fn); - return ret; -} - -int tedax_net_fsave(pcb_board_t *pcb, const char *netlistid, FILE *f) -{ - pcb_cardinal_t n; - htsp_entry_t *e; - pcb_netlist_t *nl = &pcb->netlist[PCB_NETLIST_EDITED]; - - fprintf(f, "begin netlist v1 "); - tedax_fprint_escape(f, netlistid); - fputc('\n', f); - - - for(e = htsp_first(nl); e != NULL; e = htsp_next(nl, e)) { - pcb_net_term_t *t; - pcb_net_t *net = e->value; - - for(t = pcb_termlist_first(&net->conns); t != NULL; t = pcb_termlist_next(t)) - fprintf(f, " conn %s %s %s\n", net->name, t->refdes, t->term); - } - - PCB_SUBC_LOOP(pcb->Data) { - pcb_attribute_t *a; - - if ((subc->refdes == NULL) || (*subc->refdes == '\0') || PCB_FLAG_TEST(PCB_FLAG_NONETLIST, subc)) - continue; - - for(n = 0, a = subc->Attributes.List; n < subc->Attributes.Number; n++,a++) { - if (strcmp(a->name, "refdes") == 0) - continue; - if (strcmp(a->name, "footprint") == 0) { - fprintf(f, " footprint %s ", subc->refdes); - tedax_fprint_escape(f, a->value); - fputc('\n', f); - continue; - } - if (strcmp(a->name, "value") == 0) { - fprintf(f, " value %s ", subc->refdes); - tedax_fprint_escape(f, a->value); - fputc('\n', f); - continue; - } - if (strcmp(a->name, "device") == 0) { - fprintf(f, " device %s ", subc->refdes); - tedax_fprint_escape(f, a->value); - fputc('\n', f); - continue; - } - pcb_fprintf(f, " comptag %s ", subc->refdes); - tedax_fprint_escape(f, a->name); - fputc(' ', f); - tedax_fprint_escape(f, a->value); - fputc('\n', f); - } - } PCB_END_LOOP; - - fprintf(f, "end netlist\n"); - return 0; -} - - -int tedax_net_save(pcb_board_t *pcb, const char *netlistid, const char *fn) -{ - int res; - FILE *f; - - f = pcb_fopen(fn, "w"); - if (f == NULL) { - pcb_message(PCB_MSG_ERROR, "tedax_net_save(): can't open %s for writing\n", fn); - return -1; - } - fprintf(f, "tEDAx v1\n"); - res = tedax_net_fsave(pcb, netlistid, f); - fclose(f); - return res; -} - Index: trunk/src_plugins/io_tedax/netlist.h =================================================================== --- trunk/src_plugins/io_tedax/netlist.h (revision 23601) +++ trunk/src_plugins/io_tedax/netlist.h (nonexistent) @@ -1,5 +0,0 @@ -int tedax_net_load(const char *fname_net, int import_fp, const char *blk_id, int silent); -int tedax_net_fload(FILE *f, int import_fp, const char *blk_id, int silent); - -int tedax_net_save(pcb_board_t *pcb, const char *netlistid, const char *fn); -int tedax_net_fsave(pcb_board_t *pcb, const char *netlistid, FILE *f); Index: trunk/src_plugins/io_tedax/Plug.tmpasm =================================================================== --- trunk/src_plugins/io_tedax/Plug.tmpasm (revision 23601) +++ trunk/src_plugins/io_tedax/Plug.tmpasm (revision 23602) @@ -1,7 +1,7 @@ put /local/pcb/mod {io_tedax} put /local/pcb/mod/OBJS [@ $(PLUGDIR)/io_tedax/io_tedax.o - $(PLUGDIR)/io_tedax/netlist.o + $(PLUGDIR)/io_tedax/tnetlist.o $(PLUGDIR)/io_tedax/footprint.o $(PLUGDIR)/io_tedax/stackup.o $(PLUGDIR)/io_tedax/tlayer.o Index: trunk/src_plugins/io_tedax/io_tedax.c =================================================================== --- trunk/src_plugins/io_tedax/io_tedax.c (revision 23601) +++ trunk/src_plugins/io_tedax/io_tedax.c (revision 23602) @@ -46,8 +46,8 @@ #include "tlayer.h" #include "tboard.h" #include "tdrc.h" +#include "tnetlist.h" - static const char *tedax_cookie = "tEDAx IO"; static pcb_plug_io_t io_tedax; Index: trunk/src_plugins/io_tedax/tnetlist.c =================================================================== --- trunk/src_plugins/io_tedax/tnetlist.c (nonexistent) +++ trunk/src_plugins/io_tedax/tnetlist.c (revision 23602) @@ -0,0 +1,218 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * + * tedax IO plugin - netlist import + * pcb-rnd Copyright (C) 2017 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 +#include + +#include "board.h" +#include "data.h" +#include "error.h" +#include "pcb-printf.h" +#include "compat_misc.h" +#include "actions.h" +#include "safe_fs.h" +#include "obj_subc.h" +#include "netlist2.h" + +#include "tnetlist.h" +#include "parse.h" + +typedef struct { + char *value; + char *footprint; +} fp_t; + +static void *htsp_get2(htsp_t *ht, const char *key, size_t size) +{ + void *res = htsp_get(ht, key); + if (res == NULL) { + res = calloc(size, 1); + htsp_set(ht, pcb_strdup(key), res); + } + return res; +} + +int tedax_net_fload(FILE *fn, int import_fp, const char *blk_id, int silent) +{ + char line[520]; + char *argv[16]; + int argc; + htsp_t fps; + htsp_entry_t *e; + + if (tedax_seek_hdr(fn, line, sizeof(line), argv, sizeof(argv)/sizeof(argv[0])) < 0) + return -1; + + if (tedax_seek_block(fn, "netlist", "v1", blk_id, silent, line, sizeof(line), argv, sizeof(argv)/sizeof(argv[0])) < 0) + return -1; + + htsp_init(&fps, strhash, strkeyeq); + + pcb_actionl("Netlist", "Freeze", NULL); + pcb_actionl("Netlist", "Clear", NULL); + + while((argc = tedax_getline(fn, line, sizeof(line), argv, sizeof(argv)/sizeof(argv[0]))) >= 0) { + if ((argc == 3) && (strcmp(argv[0], "footprint") == 0)) { + fp_t *fp = htsp_get2(&fps, argv[1], sizeof(fp_t)); + fp->footprint = pcb_strdup(argv[2]); + } + else if ((argc == 3) && (strcmp(argv[0], "value") == 0)) { + fp_t *fp = htsp_get2(&fps, argv[1], sizeof(fp_t)); + fp->value = pcb_strdup(argv[2]); + } + else if ((argc == 4) && (strcmp(argv[0], "conn") == 0)) { + char id[512]; + sprintf(id, "%s-%s", argv[2], argv[3]); + pcb_actionl("Netlist", "Add", argv[1], id, NULL); + } + else if ((argc == 2) && (strcmp(argv[0], "end") == 0) && (strcmp(argv[1], "netlist") == 0)) + break; + } + + pcb_actionl("Netlist", "Sort", NULL); + pcb_actionl("Netlist", "Thaw", NULL); + + if (import_fp) { + pcb_actionl("ElementList", "start", NULL); + for (e = htsp_first(&fps); e; e = htsp_next(&fps, e)) { + fp_t *fp = e->value; + +/* pcb_trace("tedax fp: refdes=%s val=%s fp=%s\n", e->key, fp->value, fp->footprint);*/ + if (fp->footprint == NULL) + pcb_message(PCB_MSG_ERROR, "tedax: not importing refdes=%s: no footprint specified\n", e->key); + else + pcb_actionl("ElementList", "Need", null_empty(e->key), null_empty(fp->footprint), null_empty(fp->value), NULL); + + free(e->key); + free(fp->value); + free(fp->footprint); + free(fp); + } + pcb_actionl("ElementList", "Done", NULL); + } + + htsp_uninit(&fps); + + return 0; +} + + +int tedax_net_load(const char *fname_net, int import_fp, const char *blk_id, int silent) +{ + FILE *fn; + int ret = 0; + + fn = pcb_fopen(fname_net, "r"); + if (fn == NULL) { + pcb_message(PCB_MSG_ERROR, "can't open file '%s' for read\n", fname_net); + return -1; + } + + ret = tedax_net_fload(fn, import_fp, blk_id, silent); + + fclose(fn); + return ret; +} + +int tedax_net_fsave(pcb_board_t *pcb, const char *netlistid, FILE *f) +{ + pcb_cardinal_t n; + htsp_entry_t *e; + pcb_netlist_t *nl = &pcb->netlist[PCB_NETLIST_EDITED]; + + fprintf(f, "begin netlist v1 "); + tedax_fprint_escape(f, netlistid); + fputc('\n', f); + + + for(e = htsp_first(nl); e != NULL; e = htsp_next(nl, e)) { + pcb_net_term_t *t; + pcb_net_t *net = e->value; + + for(t = pcb_termlist_first(&net->conns); t != NULL; t = pcb_termlist_next(t)) + fprintf(f, " conn %s %s %s\n", net->name, t->refdes, t->term); + } + + PCB_SUBC_LOOP(pcb->Data) { + pcb_attribute_t *a; + + if ((subc->refdes == NULL) || (*subc->refdes == '\0') || PCB_FLAG_TEST(PCB_FLAG_NONETLIST, subc)) + continue; + + for(n = 0, a = subc->Attributes.List; n < subc->Attributes.Number; n++,a++) { + if (strcmp(a->name, "refdes") == 0) + continue; + if (strcmp(a->name, "footprint") == 0) { + fprintf(f, " footprint %s ", subc->refdes); + tedax_fprint_escape(f, a->value); + fputc('\n', f); + continue; + } + if (strcmp(a->name, "value") == 0) { + fprintf(f, " value %s ", subc->refdes); + tedax_fprint_escape(f, a->value); + fputc('\n', f); + continue; + } + if (strcmp(a->name, "device") == 0) { + fprintf(f, " device %s ", subc->refdes); + tedax_fprint_escape(f, a->value); + fputc('\n', f); + continue; + } + pcb_fprintf(f, " comptag %s ", subc->refdes); + tedax_fprint_escape(f, a->name); + fputc(' ', f); + tedax_fprint_escape(f, a->value); + fputc('\n', f); + } + } PCB_END_LOOP; + + fprintf(f, "end netlist\n"); + return 0; +} + + +int tedax_net_save(pcb_board_t *pcb, const char *netlistid, const char *fn) +{ + int res; + FILE *f; + + f = pcb_fopen(fn, "w"); + if (f == NULL) { + pcb_message(PCB_MSG_ERROR, "tedax_net_save(): can't open %s for writing\n", fn); + return -1; + } + fprintf(f, "tEDAx v1\n"); + res = tedax_net_fsave(pcb, netlistid, f); + fclose(f); + return res; +} + Index: trunk/src_plugins/io_tedax/tnetlist.h =================================================================== --- trunk/src_plugins/io_tedax/tnetlist.h (nonexistent) +++ trunk/src_plugins/io_tedax/tnetlist.h (revision 23602) @@ -0,0 +1,5 @@ +int tedax_net_load(const char *fname_net, int import_fp, const char *blk_id, int silent); +int tedax_net_fload(FILE *f, int import_fp, const char *blk_id, int silent); + +int tedax_net_save(pcb_board_t *pcb, const char *netlistid, const char *fn); +int tedax_net_fsave(pcb_board_t *pcb, const char *netlistid, FILE *f);