view pads2gpcb/writeelem.c @ 49:b3b7013d9228

pads2gpcb.c/decals.c: allow underscores in written decal file names
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Sat, 30 Jan 2016 17:38:47 +0000
parents c81aba92cb5e
children dbf999b71c53
line wrap: on
line source

#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);
}