/* * 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 #include #include #include "style.h" #include "text.h" #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; } static inline float pt(int x) { return cx(x) * 72 * 1.5 / 1200.0; } /* ----- Library items ----------------------------------------------------- */ 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_COMP_DWG, 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], unsigned color, unsigned layer) { 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, layer, points); for (i = 0; i != points; i++) { printf("%c%d %d", ch, cx(x[i]), cy(y[i])); ch = ' '; } printf("\n"); } /* ----- Schematics items -------------------------------------------------- */ void fig_glabel(int x, int y, const char *s, int dir, int dim, enum fig_shape shape) { struct text txt = { .s = s, .size = dim, .x = x, .y = y, .rot = 0, .hor = 0, .vert = text_mid, }; int n = 6; int vx[5]; int vy[5]; int half = (dim >> 1) + GLABEL_OFFSET; switch (dir) { case 0: txt.rot = 0; txt.hor = text_max; break; default: abort(); } switch (shape) { case fig_in: text_shift(&txt, txt.hor, text_mid, -GLABEL_OFFSET - half, 0); text_rel(&txt, text_min, text_min, -GLABEL_OFFSET, GLABEL_OFFSET, vx + 1, vy + 1); text_rel(&txt, text_max, text_min, GLABEL_OFFSET, GLABEL_OFFSET, vx + 2, vy + 2); text_rel(&txt, text_max, text_mid, GLABEL_OFFSET + half, 0, vx + 3, vy + 3); text_rel(&txt, text_max, text_max, GLABEL_OFFSET, -GLABEL_OFFSET, vx + 4, vy + 4); text_rel(&txt, text_min, text_max, -GLABEL_OFFSET, -GLABEL_OFFSET, vx + 5, vy + 5); break; case fig_out: text_shift(&txt, txt.hor, text_mid, -GLABEL_OFFSET, 0); text_rel(&txt, text_min, text_min, -GLABEL_OFFSET, GLABEL_OFFSET, vx + 1, vy + 1); text_rel(&txt, text_max, text_min, GLABEL_OFFSET, GLABEL_OFFSET, vx + 2, vy + 2); text_rel(&txt, text_max, text_max, GLABEL_OFFSET, -GLABEL_OFFSET, vx + 3, vy + 3); text_rel(&txt, text_min, text_max, -GLABEL_OFFSET, -GLABEL_OFFSET, vx + 4, vy + 4); text_rel(&txt, text_min, text_mid, -GLABEL_OFFSET- half, 0, vx + 5, vy + 5); break; default: abort(); } text_fig(&txt, COLOR_GLABEL, LAYER_GLABEL); vx[0] = vx[n - 1]; vy[0] = vy[n - 1]; fig_poly(n, vx, vy, COLOR_GLABEL, LAYER_GLABEL); } 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_WIRE, 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_WIRE, 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 2 %d %d 7 %d -1 -1 3.0 1 1 -1 0 0 2\n", WIDTH_LINE, COLOR_SHEET_DWG, LAYER_LINES); printf("\t%d %d %d %d\n", cx(sx), cy(sy), cx(ex), cy(ey)); } /* ----- General items ----------------------------------------------------- */ 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 / 180.0 * M_PI, cx(x), cy(y), s); } /* ----- FIG file header --------------------------------------------------- */ void fig_init(void) { printf("#FIG 3.2\n"); printf("Landscape\n"); printf("Center\n"); printf("Metric\n"); printf("A4\n"); printf("100.00\n"); printf("Single\n"); printf("-2\n"); printf("1200 2\n"); }