Index: Plug.tmpasm =================================================================== --- Plug.tmpasm (revision 35180) +++ Plug.tmpasm (revision 35181) @@ -3,6 +3,7 @@ $(PLUGDIR)/lib_netmap/netmap.o $(PLUGDIR)/lib_netmap/map_2nets.o $(PLUGDIR)/lib_netmap/placement.o + $(PLUGDIR)/lib_netmap/pstklib.o @] switch /local/pcb/lib_netmap/controls Index: pstklib.c =================================================================== --- pstklib.c (nonexistent) +++ pstklib.c (revision 35181) @@ -0,0 +1,59 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * Copyright (C) 2021 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 "pstklib.h" +#include + +void pcb_pstklib_init(pcb_pstklib_t *ctx, pcb_board_t *pcb) +{ + memset(&ctx->protos, 0, sizeof(ctx->protos)); + ctx->pcb = pcb; + ctx->next_id = 1; + htprp_init(&ctx->protos, pcb_pstk_proto_hash, pcb_pstk_proto_eq); +} + +void pcb_pstklib_uninit(pcb_pstklib_t *ctx) +{ + genht_uninit_deep(htprp, &ctx->protos, { + pcb_pstklib_entry_t *pe = htent->value; + if (ctx->on_free_entry != NULL) + ctx->on_free_entry(ctx, pe); + free(pe); + }); +} + +void pcb_pstklib_build_data(pcb_pstklib_t *ctx, pcb_data_t *data) +{ + long n; + for(n = 0; n < data->ps_protos.used; n++) { + pcb_pstk_proto_t *proto = &data->ps_protos.array[n]; + + if (!proto->in_use) continue; + + } +} + Index: pstklib.h =================================================================== --- pstklib.h (nonexistent) +++ pstklib.h (revision 35181) @@ -0,0 +1,31 @@ +#include "board.h" +#include "data.h" +#include "ht_pstk.h" + +/* Build a hash of subcircuit-to-prototype. Effectively a local library + of unique footprint prototypes */ + +typedef struct { + pcb_pstk_proto_t proto; /* copy of a proto */ + long id; /* unique ID counted from 1 by pcb_pstklib_build */ + void *user_data; +} pcb_pstklib_entry_t; + +typedef struct pcb_pstklib_s pcb_pstklib_t; +struct pcb_pstklib_s { + htprp_t protos; /* value is (pcb_pstklib_entry_t *) */ + pcb_board_t *pcb; + long next_id; + + void (*on_free_entry)(pcb_pstklib_t *ctx, pcb_pstklib_entry_t *pe); /* optional: if set, called before freeing an entry on uninit */ + void *user_data; +}; + +void pcb_pstklib_init(pcb_pstklib_t *ctx, pcb_board_t *pcb); +void pcb_pstklib_uninit(pcb_pstklib_t *ctx); + +/* Iterate all padstack prototypes within data and build ctx->protos hash */ +void pcb_pstklib_build_data(pcb_pstklib_t *ctx, pcb_data_t *data); + +/* return proto's prototype or NULL */ +#define pcb_pstklib_get(ctx, proto) htprp_get((ctx)->protos, (proto))