1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-09-18 01:45:52 +03:00
eda-tools/sch2fig/fig.c

158 lines
3.6 KiB
C

/*
* 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.
*/
#include <stdio.h>
#include "fig.h"
#define COLOR_BLACK 0
#define COLOR_BLUE 1
#define COLOR_GREEN4 12
#define COLOR_RED4 18
#define COLOR_RED3 19
#define FONT_HELVETICA_BOLD 18
#define LAYER_TEXT 30
#define LAYER_WIRES 50
#define LAYER_LINES 60
#define LAYER_COMP_DWG 70
#define WIDTH_WIRE 2
#define WIDTH_LINE 2
#define WIDTH_COMP_DWG 2
#define JUNCTION_R 50
/*
* 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;
}
static inline int pt(int x)
{
return cx(x) * 72 * 1.5 / 1200;
}
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",
WIDTH_COMP_DWG, COLOR_RED4, LAYER_COMP_DWG);
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",
WIDTH_COMP_DWG, COLOR_RED4, LAYER_COMP_DWG, points);
for (i = 0; i != points; i++) {
printf("%c%d %d", ch, cx(x[i]), cy(y[i]));
ch = ' ';
}
printf("\n");
}
void fig_text(int x, int y, const char *s, int dir, int dim,
enum fig_shape shape)
{
// Type Depth FontSiz Height
// Just Pen Angle Length
// Color Font Flags X Y
printf("4 0 %d %d -1 %d %d %d 4 0.0 0.0 %d %d %s\\001\n",
COLOR_BLACK, LAYER_TEXT, FONT_HELVETICA_BOLD,
pt(dim), 0, cx(x), cy(y), s);
}
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",
COLOR_GREEN4, LAYER_WIRES, cx(x), cy(y), JUNCTION_R, JUNCTION_R,
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",
WIDTH_WIRE, COLOR_GREEN4, LAYER_WIRES);
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
printf("2 1 0 %d %d 7 %d -1 -1 0.0 1 1 -1 0 0 2\n",
WIDTH_LINE, COLOR_BLUE, LAYER_LINES);
printf("\t%d %d %d %d\n", cx(sx), cy(sy), cx(ex), cy(ey));
}
void fig_init(void)
{
printf("#FIG 3.2\n");
printf("Landscape\n");
printf("Center\n");
printf("Metric\n");
printf("A4\n");
printf("10.00\n");
printf("Single\n");
printf("-2\n");
printf("1200 2\n");
}