FreeCalypso > hg > ueda-linux
changeset 40:1c37bec20596
pads2gpcb: slowly working on the decal processing logic
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 11 Jan 2016 08:12:40 +0000 |
parents | 242f73e61ef0 |
children | a2d304ec3817 |
files | pads2gpcb/Makefile pads2gpcb/decals.c pads2gpcb/struct.h |
diffstat | 3 files changed, 235 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/pads2gpcb/Makefile Mon Jan 11 05:09:25 2016 +0000 +++ b/pads2gpcb/Makefile Mon Jan 11 08:12:40 2016 +0000 @@ -1,6 +1,7 @@ CC= gcc CFLAGS= -O2 OBJS= globals.o main.o rdunits.o readpads.o +HDRS= globals.h struct.h PROG= pads2gpcb BINDIR= /usr/local/bin @@ -9,6 +10,8 @@ ${PROG}: ${OBJS} ${CC} -o $@ ${OBJS} +${OBJS}: ${HDRS} + install: install -c -o bin -g bin -m 755 ${PROG} ${BINDIR}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pads2gpcb/decals.c Mon Jan 11 08:12:40 2016 +0000 @@ -0,0 +1,220 @@ +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include <strings.h> +#include "globals.h" +#include "struct.h" + +extern long convert_input_dim(); + +static struct part_decal *current_decal; +static struct footprint_body fpbody; +static struct footprint_pad *pins_array; +static int num_drawing_pieces, num_padstack_defs; +static int num_text_items, num_attr_labels; + +static void +enter_decal() +{ + struct part_decal *p, **pp; + char *name = input_line_fields[0]; + + for (pp = &part_decal_list; p = *pp; pp = &p->next) + if (!strcmp(p->name, name)) { + fprintf(stderr, + "%s line %d: decal name \"%s\" already defined\n", + input_filename, input_lineno, name); + exit(1); + } + p = malloc(sizeof(struct part_decal) + strlen(name) + 1); + if (!p) { + perror("malloc of struct part_decal"); + exit(1); + } + p->name = (char *)(p + 1); + strcpy(p->name, name); + p->body = 0; + p->next = 0; + **pp = p; + current_decal = p; +} + +static void +get_line_internal() +{ + if (!get_input_line()) { + fprintf(stderr, + "error: EOF in the middle of a part decal definition\n"); + exit(1); + } +} + +static void +one_drawing_piece() +{ + int ncoord, i; + + /* just skip it for now */ + get_line_internal(); + parse_input_line_fields(); + if (input_line_nfields < 2) { + fprintf(stderr, + "%s line %d: expected piece header line giving # of coords\n", + input_filename, input_lineno); + exit(1); + } + ncoord = atoi(input_line_fields[1]); + for (i = 0; i < ncoord; i++) + get_line_internal(); +} + +static void +one_text_item() +{ + /* just skip it for now */ + get_line_internal(); + get_line_internal(); + get_line_internal(); +} + +static void +one_attr_label() +{ + /* just skip it for now */ + get_line_internal(); + get_line_internal(); + get_line_internal(); +} + +static void +read_pindef_line(idx) +{ + get_line_internal(); + if (input_line_buf[0] != 'T') { + fprintf(stderr, "%s line %d: 'T' line expected\n", + input_filename, input_lineno); + exit(1); + } + parse_input_line_fields(); + if (input_line_nfields != 5) { + fprintf(stderr, "%s line %d: expected 5 fields in 'T' line\n", + input_filename, input_lineno); + exit(1); + } + input_line_fields[0]++; + + if (atoi(input_line_fields[4]) != i + 1) { + fprintf(stderr, + "%s line %d: expected %d in the pin number field\n", + input_filename, input_lineno); + exit(1); + } + pins_array[i].x1 = convert_input_dim(input_line_fields[0]); + pins_array[i].y1 = -convert_input_dim(input_line_fields[1]); +} + +static void +one_padstack_def() +{ + + +} + +static void +process_one_decal() +{ + int i; + + if (input_line_nfields < 7 || input_line_nfields > 9) { + fprintf(stderr, +"%s line %d: expected beginning of part decal definition, wrong # of fields\n", + input_filename, input_lineno); + exit(1); + } + enter_decal(); + bzero(&fpbody, sizeof fpbody); + if (input_line_fields[1][0] != 'I' && input_line_fields[1][0] != 'M' + || input_line_fields[1][1]) { + fprintf(stderr, "%s line %d: expected 'I' or 'M' in field 1\n", + input_filename, input_lineno); + exit(1); + } + fpbody.src_units = input_line_fields[1][0]; + if (input_units_global == 'B') + input_units_current = 'B'; + else + input_units_current = fpbody.src_units; + fpbody.mark_x = convert_input_dim(input_line_fields[2]); + fpbody.mark_y = -convert_input_dim(input_line_fields[3]); + num_drawing_pieces = atoi(input_line_fields[4]); + fpbody.npins = atoi(input_line_fields[5]); + num_padstack_defs = atoi(input_line_fields[6]); + if (input_line_nfields > 7) + num_text_items = atoi(input_line_fields[7]); + else + num_text_items = 0; + if (input_line_nfields > 8) + num_attr_labels = atoi(input_line_fields[8]); + else + num_attr_labels = 0; + + /* sanity checks */ + if (fpbody.npins < 1) { + fprintf(stderr, "%s line %d: # of terminals %d < 1\n", + input_filename, input_lineno, fpbody.npins); + exit(1); + } + if (num_padstack_defs < 1) { + fprintf(stderr, "%s line %d: # of pad stack defs %d < 1\n", + input_filename, input_lineno, num_padstack_defs); + exit(1); + } + + /* done parsing the header line, initialize some misc */ + fpbody.refdes_scale = 100; + + /* read and process the miscellany */ + for (i = 0; i < num_drawing_pieces; i++) + one_drawing_piece(); + for (i = 0; i < num_text_items; i++) + one_text_item(); + for (i = 0; i < num_attr_labels; i++) + one_attr_label(); + + /* the meat: allocate and fill the pins array */ + pins_array = malloc(sizeof(struct footprint_pad) * fpbody.npins); + if (!pins_array) { + perror("malloc of the pins array"); + exit(1); + } + fpbody.pins = pins_array; + bzero(pins_array, sizeof(struct footprint_pad) * fpbody.npins); + for (i = 0; i < fpbody.npins; i++) + read_pindef_line(i); + /* read and process the pad stack definitions */ + for (i = 0; i < num_padstack_defs; i++) + one_padstack_def(); + + +} + +process_partdecal_section() +{ + for (;;) { + if (!get_input_line()) { + fprintf(stderr, "error: EOF in PARTDECAL section\n"); + exit(1); + } + if (input_line_buf[0] == '*') { + parse_starline(); + if (strcmp(input_line_starkw, "REMARK")) + break; + else + continue; + } + parse_input_line_fields(); + if (input_line_nfields) + process_one_decal(); + } +}
--- a/pads2gpcb/struct.h Mon Jan 11 05:09:25 2016 +0000 +++ b/pads2gpcb/struct.h Mon Jan 11 08:12:40 2016 +0000 @@ -1,3 +1,12 @@ +struct pad_shape_info { + int valid; + int rounded; + int elongated; + long short_dim; + long long_dim; + int angle; +}; + struct footprint_pad { long x1; long y1; @@ -6,14 +15,14 @@ long thickness; long clearance; long mask; - int is_square; + struct pad_shape_info shape; }; struct footprint_body { - size_t copysize; int src_units; int npins; struct footprint_pad *pins; + struct pad_shape_info default_pad; long mark_x; long mark_y; long refdes_x; @@ -24,7 +33,7 @@ struct part_decal { char *name; - struct footprint_body *fpbody; + struct footprint_body *body; struct part_decal *next; };