changeset 46:c81aba92cb5e

pads2gpcb: generic element writing implemented
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Sat, 30 Jan 2016 07:56:18 +0000
parents 3bdb1b5ff3d0
children 8fa304e2b7e1
files pads2gpcb/Makefile pads2gpcb/gpcbout.h pads2gpcb/struct.h pads2gpcb/writeelem.c
diffstat 4 files changed, 98 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/pads2gpcb/Makefile	Sat Jan 30 07:15:31 2016 +0000
+++ b/pads2gpcb/Makefile	Sat Jan 30 07:56:18 2016 +0000
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-OBJS=	decals.o globals.o gpcbout.o main.o rdunits.o readpads.o
+OBJS=	decals.o globals.o gpcbout.o main.o rdunits.o readpads.o writeelem.o
 HDRS=	globals.h gpcbout.h struct.h
 PROG=	pads2gpcb
 BINDIR=	/usr/local/bin
--- a/pads2gpcb/gpcbout.h	Sat Jan 30 07:15:31 2016 +0000
+++ b/pads2gpcb/gpcbout.h	Sat Jan 30 07:56:18 2016 +0000
@@ -1,1 +1,3 @@
 #define	DIM_OUT_BUFSIZE	16
+
+extern char *output_gpcb_dimension();
--- a/pads2gpcb/struct.h	Sat Jan 30 07:15:31 2016 +0000
+++ b/pads2gpcb/struct.h	Sat Jan 30 07:56:18 2016 +0000
@@ -28,8 +28,8 @@
 	long	mark_y;
 	long	refdes_x;
 	long	refdes_y;
-	long	refdes_dir;
-	long	refdes_scale;
+	int	refdes_dir;
+	int	refdes_scale;
 };
 
 struct part_decal {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pads2gpcb/writeelem.c	Sat Jan 30 07:56:18 2016 +0000
@@ -0,0 +1,93 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "struct.h"
+#include "gpcbout.h"
+
+static void
+emit_element_line(outf, body, strdesc, strname, strvalue, onbottom)
+	FILE *outf;
+	struct footprint_body *body;
+	char *strdesc, *strname, *strvalue;
+	int onbottom;
+{
+	char mx_buf[DIM_OUT_BUFSIZE], *mx_str;
+	char my_buf[DIM_OUT_BUFSIZE], *my_str;
+	char tx_buf[DIM_OUT_BUFSIZE], *tx_str;
+	char ty_buf[DIM_OUT_BUFSIZE], *ty_str;
+	char *flagstr;
+
+	mx_str = output_gpcb_dimension(body->mark_x, mx_buf);
+	my_str = output_gpcb_dimension(body->mark_y, my_buf);
+	tx_str = output_gpcb_dimension(body->refdes_x, tx_buf);
+	ty_str = output_gpcb_dimension(body->refdes_y, ty_buf);
+	flagstr = onbottom ? "onsolder" : "";
+
+	fprintf(outf,
+	"Element[\"%s\" \"%s\" \"%s\" \"%s\" %s %s %s %s %d %d \"%s\"]\n",
+		flagstr, strdesc, strname, strvalue, mx_str, my_str,
+		tx_str, ty_str, body->refdes_dir, body->refdes_scale, flagstr);
+}
+
+static void
+emit_pad_line(outf, pad, pinname, pinnumber, onbottom)
+	FILE *outf;
+	struct footprint_pad *pad;
+	char *pinname, *pinnumber;
+	int onbottom;
+{
+	char x1_buf[DIM_OUT_BUFSIZE], *x1_str;
+	char y1_buf[DIM_OUT_BUFSIZE], *y1_str;
+	char x2_buf[DIM_OUT_BUFSIZE], *x2_str;
+	char y2_buf[DIM_OUT_BUFSIZE], *y2_str;
+	char thickness_buf[DIM_OUT_BUFSIZE], *thickness_str;
+	char clearance_buf[DIM_OUT_BUFSIZE], *clearance_str;
+	char mask_buf[DIM_OUT_BUFSIZE], *mask_str;
+	char *flagstr;
+
+	x1_str = output_gpcb_dimension(pad->x1, x1_buf);
+	y1_str = output_gpcb_dimension(pad->y1, y1_buf);
+	x2_str = output_gpcb_dimension(pad->x2, x2_buf);
+	y2_str = output_gpcb_dimension(pad->y2, y2_buf);
+	thickness_str = output_gpcb_dimension(pad->thickness, thickness_buf);
+	clearance_str = output_gpcb_dimension(pad->clearance, clearance_buf);
+	mask_str = output_gpcb_dimension(pad->mask, mask_buf);
+
+	if (onbottom && !pad->shape.rounded)
+		flagstr = "onsolder,square";
+	else if (onbottom)
+		flagstr = "onsolder";
+	else if (!pad->shape.rounded)
+		flagstr = "square";
+	else
+		flagstr = "";
+
+	fprintf(outf, "\tPad[%s %s %s %s %s %s %s \"%s\" \"%s\" \"%s\"]\n",
+		x1_str, y1_str, x2_str, y2_str,
+		thickness_str, clearance_str, mask_str,
+		pinname, pinnumber, flagstr);
+}
+
+write_gpcb_element(outf, body, alpha_pins, strdesc, strname, strvalue, onbottom)
+	FILE *outf;
+	struct footprint_body *body;
+	char **alpha_pins;
+	char *strdesc, *strname, *strvalue;
+	int onbottom;
+{
+	int i;
+	char pinnum_buf[16], *pinnum_str;
+
+	emit_element_line(outf, body, strdesc, strname, strvalue, onbottom);
+	fputs("(\n", outf);
+	for (i = 0; i < body->npins; i++) {
+		if (alpha_pins)
+			pinnum_str = alpha_pins[i];
+		else {
+			sprintf(pinnum_buf, "%d", i + 1);
+			pinnum_str = pinnum_buf;
+		}
+		emit_pad_line(outf, body->pins + i, "", pinnum_str, onbottom);
+	}
+	fputs(")\n", outf);
+	return(0);
+}