view pads2gpcb/writeelem.c @ 120:6ea9f0b2dbd2

m4-fp/btb.inc: Harwin M402M connector family added
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 05 Jul 2020 05:24:33 +0000
parents be1fe110b6ab
children
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>
#include "globals.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 + output_x_offset, mx_buf);
	my_str = output_gpcb_dimension(-body->mark_y + output_y_offset, 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->end1.x, x1_buf);
	y1_str = output_gpcb_dimension(-pad->end1.y, y1_buf);
	x2_str = output_gpcb_dimension(pad->end2.x, x2_buf);
	y2_str = output_gpcb_dimension(-pad->end2.y, 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);
}

static void
emit_elementline_obj(outf, obj)
	FILE *outf;
	struct element_line *obj;
{
	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;

	x1_str = output_gpcb_dimension(obj->end1.x, x1_buf);
	y1_str = output_gpcb_dimension(-obj->end1.y, y1_buf);
	x2_str = output_gpcb_dimension(obj->end2.x, x2_buf);
	y2_str = output_gpcb_dimension(-obj->end2.y, y2_buf);
	thickness_str = output_gpcb_dimension(obj->thickness, thickness_buf);

	fprintf(outf, "\tElementLine[%s %s %s %s %s]\n",
		x1_str, y1_str, x2_str, y2_str, thickness_str);
}

static void
emit_elementarc_obj(outf, obj)
	FILE *outf;
	struct element_arc *obj;
{
	char centrex_buf[DIM_OUT_BUFSIZE], *centrex_str;
	char centrey_buf[DIM_OUT_BUFSIZE], *centrey_str;
	char width_buf[DIM_OUT_BUFSIZE], *width_str;
	char height_buf[DIM_OUT_BUFSIZE], *height_str;
	char thickness_buf[DIM_OUT_BUFSIZE], *thickness_str;

	centrex_str = output_gpcb_dimension(obj->centre.x, centrex_buf);
	centrey_str = output_gpcb_dimension(-obj->centre.y, centrey_buf);
	width_str = output_gpcb_dimension(obj->width, width_buf);
	height_str = output_gpcb_dimension(obj->height, height_buf);
	thickness_str = output_gpcb_dimension(obj->thickness, thickness_buf);

	fprintf(outf, "\tElementArc[%s %s %s %s %d %d %s]\n",
		centrex_str, centrey_str, width_str, height_str,
		obj->start_angle, obj->delta_angle, thickness_str);
}

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);
	}
	for (i = 0; i < body->num_silk_lines; i++)
		emit_elementline_obj(outf, body->silk_lines + i);
	for (i = 0; i < body->num_silk_arcs; i++)
		emit_elementarc_obj(outf, body->silk_arcs + i);
	fputs(")\n", outf);
	return(0);
}