Index: trunk/src/obj_subc.c =================================================================== --- trunk/src/obj_subc.c (revision 9128) +++ trunk/src/obj_subc.c (revision 9129) @@ -31,6 +31,7 @@ #include "data.h" #include "error.h" #include "obj_subc.h" +#include "obj_subc_op.h" pcb_subc_t *pcb_subc_alloc(void) { @@ -149,3 +150,66 @@ pcb_gui->draw_line(pcb_crosshair.GC, DX - PCB_EMARK_SIZE, DY, DX, DY + PCB_EMARK_SIZE); pcb_gui->draw_line(pcb_crosshair.GC, DX + PCB_EMARK_SIZE, DY, DX, DY + PCB_EMARK_SIZE); } + + +pcb_subc_t *pcb_subc_dup(pcb_board_t *pcb, pcb_data_t *dst, pcb_subc_t *src) +{ + int n; + pcb_subc_t *sc = pcb_subc_alloc(); + PCB_SET_PARENT(sc->data, data, dst); + pcb_subclist_append(&dst->subc, sc); + + /* make a copy */ + for(n = 0; n < src->data->LayerN; n++) { + pcb_layer_t *sl = src->data->Layer + n; + pcb_layer_t *dl = sc->data->Layer + n; + pcb_line_t *line, *nline; + pcb_text_t *text; + pcb_polygon_t *poly; + pcb_arc_t *arc, *narc; + + memcpy(&dl->meta.bound, &sl->meta.bound, sizeof(sl->meta.bound)); + dl->meta.bound.real = NULL; + + while((line = linelist_first(&sl->Line)) != NULL) { + nline = pcb_line_dup(dl, line); + if (nline != NULL) + PCB_SET_PARENT(nline, layer, dl); + } + + while((arc = arclist_first(&sl->Arc)) != NULL) { + narc = pcb_arc_dup(dl, arc); + if (narc != NULL) + PCB_SET_PARENT(arc, layer, dl); + } + + while((text = textlist_first(&sl->Text)) != NULL) { +/* PCB_SET_PARENT(text, layer, dl);*/ + } + + while((poly = polylist_first(&sl->Polygon)) != NULL) { +/* PCB_SET_PARENT(poly, layer, dl);*/ + } + + } + + /* bind layers to the stack provided by pcb/dst */ + if (pcb != NULL) { + + } +} + +/* copies a subcircuit onto the PCB. Then does a draw. */ +void *CopySubc(pcb_opctx_t *ctx, pcb_subc_t *src) +{ + pcb_subc_t *sc; + + sc = pcb_subc_dup(PCB, PCB->Data, src); + + /* this call clears the polygons */ +/* pcb_undo_add_obj_to_create(PCB_TYPE_ELEMENT, element, element, element);*/ + +/* DrawElementPinsAndPads(element);*/ + return (sc); +} + Index: trunk/src/obj_subc_op.h =================================================================== --- trunk/src/obj_subc_op.h (nonexistent) +++ trunk/src/obj_subc_op.h (revision 9129) @@ -0,0 +1,34 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * Copyright (C) 2017 Tibor 'Igor2' Palinkas + * + * This module, rats.c, was written and is Copyright (C) 1997 by harry eaton + * this module is also subject to the GNU GPL as described below + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifndef PCB_OBJ_SUBC_OP_H +#define PCB_OBJ_SUBC_OP_H + +#include "operation.h" + +void *CopySubc(pcb_opctx_t *ctx, pcb_subc_t *src); + + +#endif