2016-07-22 06:04:42 +03:00
|
|
|
/*
|
|
|
|
* fig.c - Generate FIG output for Eeschema items
|
|
|
|
*
|
|
|
|
* Written 2016 by Werner Almesberger
|
|
|
|
* Copyright 2016 by Werner Almesberger
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2016-07-22 05:54:32 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2016-07-23 06:48:59 +03:00
|
|
|
#include "style.h"
|
|
|
|
#include "text.h"
|
2016-07-22 05:54:32 +03:00
|
|
|
#include "fig.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIG works with 1/1200 in
|
|
|
|
* KiCad works with mil
|
|
|
|
* 1 point = 1/72 in
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
static inline int cx(int x)
|
|
|
|
{
|
|
|
|
return x * 1200 / 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int cy(int y)
|
|
|
|
{
|
|
|
|
return y * 1200 / 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-23 06:48:59 +03:00
|
|
|
static inline float pt(int x)
|
2016-07-22 05:54:32 +03:00
|
|
|
{
|
2016-07-23 06:48:59 +03:00
|
|
|
return cx(x) * 72 * 1.5 / 1200.0;
|
2016-07-22 05:54:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void fig_rect(int sx, int sy, int ex, int ey)
|
|
|
|
{
|
|
|
|
// Type Thick Depth StyleV Rad
|
|
|
|
// SubTy Color Pen Join FwdAr
|
|
|
|
// Style FillCol AreaFil Cap BwdAr
|
|
|
|
printf("2 2 0 %d %d 7 %d -1 -1 0.0 1 1 -1 0 0 5\n",
|
2016-07-23 06:48:59 +03:00
|
|
|
WIDTH_COMP_DWG, COLOR_COMP_DWG, LAYER_COMP_DWG);
|
2016-07-22 05:54:32 +03:00
|
|
|
printf("\t%d %d %d %d %d %d %d %d %d %d\n",
|
|
|
|
cx(sx), cy(sy), cx(ex), cy(sy), cx(ex), cy(ey), cx(sx), cy(ey),
|
|
|
|
cx(sx), cy(sy));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void fig_poly(int points, int x[points], int y[points])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char ch = '\t';
|
|
|
|
|
|
|
|
// Type Thick Depth StyleV Rad
|
|
|
|
// SubTy Color Pen Join FwdAr
|
|
|
|
// Style FillCol AreaFil Cap BwdAr
|
|
|
|
printf("2 1 0 %d %d 7 %d -1 -1 0.0 1 1 -1 0 0 %d\n",
|
2016-07-23 06:48:59 +03:00
|
|
|
WIDTH_COMP_DWG, COLOR_COMP_DWG, LAYER_COMP_DWG, points);
|
2016-07-22 05:54:32 +03:00
|
|
|
for (i = 0; i != points; i++) {
|
|
|
|
printf("%c%d %d", ch, cx(x[i]), cy(y[i]));
|
|
|
|
ch = ' ';
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void fig_glabel(int x, int y, const char *s, int dir, int dim,
|
|
|
|
enum fig_shape shape)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void fig_junction(int x, int y)
|
|
|
|
{
|
|
|
|
// Type Thick Depth StyleV Cx Rx Sx Ex
|
|
|
|
// SubTy Color Pen Dir Cy Ry Sy Ey
|
|
|
|
// Style FillCol AreaFil Angle
|
|
|
|
printf("1 3 0 0 -1 %d %d -1 20 0.0 1 0.0 %d %d %d %d %d %d %d %d\n",
|
2016-07-23 06:48:59 +03:00
|
|
|
COLOR_WIRE, LAYER_WIRES, cx(x), cy(y), JUNCTION_R, JUNCTION_R,
|
2016-07-22 05:54:32 +03:00
|
|
|
cx(x), cy(y), cx(x) + JUNCTION_R, cy(y));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void fig_wire(int sx, int sy, int ex, int ey)
|
|
|
|
{
|
|
|
|
// TypeStyle FillCol AreaFil Cap FwdAr
|
|
|
|
// SubTy Color Pen StyleV Rad BwdAr
|
|
|
|
// Thick Depth Join Points
|
|
|
|
printf("2 1 0 %d %d 7 %d -1 -1 0.0 1 1 -1 0 0 2\n",
|
2016-07-23 06:48:59 +03:00
|
|
|
WIDTH_WIRE, COLOR_WIRE, LAYER_WIRES);
|
2016-07-22 05:54:32 +03:00
|
|
|
printf("\t%d %d %d %d\n", cx(sx), cy(sy), cx(ex), cy(ey));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void fig_line(int sx, int sy, int ex, int ey)
|
|
|
|
{
|
|
|
|
// TypeStyle FillCol AreaFil Cap FwdAr
|
|
|
|
// SubTy Color Pen StyleV Rad BwdAr
|
|
|
|
// Thick Depth Join Points
|
2016-07-23 06:48:59 +03:00
|
|
|
printf("2 1 2 %d %d 7 %d -1 -1 3.0 1 1 -1 0 0 2\n",
|
|
|
|
WIDTH_LINE, COLOR_SHEET_DWG, LAYER_LINES);
|
2016-07-22 05:54:32 +03:00
|
|
|
printf("\t%d %d %d %d\n", cx(sx), cy(sy), cx(ex), cy(ey));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-23 06:48:59 +03:00
|
|
|
void fig_text(int x, int y, const char *s, unsigned size,
|
|
|
|
enum text_align align, int rot, unsigned color, unsigned layer)
|
|
|
|
{
|
|
|
|
// Type Depth FontSiz Height
|
|
|
|
// Just Pen Angle Length
|
|
|
|
// Color Font Flags X Y
|
|
|
|
printf("4 %u %d %d -1 %d %f %f 4 0.0 0.0 %d %d %s\\001\n",
|
|
|
|
align, color, layer, FONT_HELVETICA_BOLD,
|
|
|
|
pt(size), rot / 3.1415926 * 180, cx(x), cy(y), s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-22 05:54:32 +03:00
|
|
|
void fig_init(void)
|
|
|
|
{
|
|
|
|
printf("#FIG 3.2\n");
|
|
|
|
printf("Landscape\n");
|
|
|
|
printf("Center\n");
|
|
|
|
printf("Metric\n");
|
|
|
|
printf("A4\n");
|
2016-07-23 06:48:59 +03:00
|
|
|
printf("100.00\n");
|
2016-07-22 05:54:32 +03:00
|
|
|
printf("Single\n");
|
|
|
|
printf("-2\n");
|
|
|
|
printf("1200 2\n");
|
|
|
|
}
|