1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-12-23 17:07:23 +02:00

sch2fig/: support sheet and file labels in sheet as well

This commit is contained in:
Werner Almesberger 2016-07-29 21:43:27 -03:00
parent 2e68f85914
commit 0dfd3ff7e2
3 changed files with 96 additions and 5 deletions

View File

@ -11,6 +11,7 @@
*/
#define _GNU_SOURCE /* for asprintf */
#include <stddef.h>
#include <stdbool.h>
#include <stdlib.h>
@ -304,13 +305,42 @@ static bool parse_hsheet_field(struct sch_ctx *ctx, const char *line)
unsigned n, dim;
if (sscanf(line, "F%d \"%m[^\"]\" %u", &n, &s, &dim) == 3) {
assert(n < 2);
return 1; /* @@@ later */
switch (n) {
case 0:
ctx->sheet = s;
ctx->sheet_dim = dim;
return 1;
case 1:
ctx->file = s;
ctx->file_dim = dim;
return 1;
default:
assert(0);
}
}
if (sscanf(line, "F%d \"%m[^\"]\" %c %c %d %d %u",
&n, &s, &form, &side, &x, &y, &dim) != 7)
return 0;
assert(n >= 2);
if (side == 'B' || side == 'T') {
/*
* This is beautiful: since there is no indication for rotation
* on the hsheet, or the sheet or file fields, we need to look
* at whether the imported sheet pins go left or right (no
* rotation) or whether they go top or bottom (rotation).
*
* A sheet with no imported pins lacks these hints, and is
* therefore always assumed to be without rotation.
*
* Eeschema is careful to be consistent, and does not allow
* sheets with no imported pins to be rotated. Even better, it
* flips rotated sheets where the last imported pin is deleted
* back.
*/
ctx->rotated = 1;
}
dwg_hlabel(x, y, s, decode_side(side), dim, decode_form(form));
free(s);
@ -318,6 +348,53 @@ static bool parse_hsheet_field(struct sch_ctx *ctx, const char *line)
}
static void do_hsheet_text(struct sch_ctx *ctx)
{
char *s;
assert(ctx->sheet && ctx->file);
struct text sheet_txt = {
.size = ctx->sheet_dim,
.x = ctx->x,
.y = ctx->y,
.rot = 0,
.hor = text_min,
.vert = text_min,
};
asprintf(&s, "Sheet: %s", ctx->sheet);
sheet_txt.s = s; /* work around "const" mismatch */
struct text file_txt = {
.size = ctx->file_dim,
.x = ctx->x,
.y = ctx->y,
.rot = 0,
.hor = text_min,
.vert = text_max,
};
asprintf(&s, "File: %s", ctx->file);
file_txt.s = s; /* work around "const" mismatch */
if (ctx->rotated) {
sheet_txt.rot = file_txt.rot = 90;
sheet_txt.x -= HSHEET_FIELD_OFFSET;
sheet_txt.y += ctx->h;
file_txt.x += ctx->w + HSHEET_FIELD_OFFSET;
file_txt.y += ctx->h;
} else {
sheet_txt.y -= HSHEET_FIELD_OFFSET;
file_txt.y += ctx->h + HSHEET_FIELD_OFFSET;
}
text_fig(&sheet_txt, COLOR_HSHEET_SHEET, LAYER_HSHEET_FIELD);
text_fig(&file_txt, COLOR_HSHEET_FILE, LAYER_HSHEET_FIELD);
free((void *) ctx->sheet);
free((void *) ctx->file);
}
/* ----- Schematics parser ------------------------------------------------- */
@ -339,6 +416,9 @@ bool sch_parse(struct sch_ctx *ctx, const char *line)
}
if (sscanf(line, "$Sheet%n", &n) == 0 && n) {
ctx->state = sch_sheet;
ctx->sheet = NULL;
ctx->file = NULL;
ctx->rotated = 0;
return 1;
}
@ -471,13 +551,14 @@ bool sch_parse(struct sch_ctx *ctx, const char *line)
case sch_sheet:
if (sscanf(line, "$EndSheet%n", &n) == 0 && n) {
ctx->state = sch_basic;
do_hsheet_text(ctx);
return 1;
}
if (sscanf(line, "S %d %d %u %u",
&ctx->x, &ctx->y, &ctx->w, &ctx->h) == 4) {
fig_rect(ctx->x, ctx->y,
ctx->x + ctx->w, ctx->y + ctx->h,
COLOR_HSHEET, COLOR_NONE, LAYER_HSHEET);
COLOR_HSHEET_BOX, COLOR_NONE, LAYER_HSHEET_BOX);
return 1;
}
if (sscanf(line, "U %*x%n", &n) == 0 && n)

View File

@ -54,6 +54,11 @@ struct sch_ctx {
/* subsheet */
unsigned h, w;
const char *sheet;
unsigned sheet_dim;
const char *file;
unsigned file_dim;
bool rotated;
unsigned lineno;
};

View File

@ -22,6 +22,7 @@
#define COLOR_CYAN3 16
#define COLOR_RED4 18
#define COLOR_RED3 19
#define COLOR_MAGENTA4 21
#define COLOR_BROWN2 26
#define COLOR_COMP_DWG COLOR_RED4
@ -32,7 +33,9 @@
#define COLOR_NOCONN COLOR_BLUE
#define COLOR_GLABEL COLOR_RED4
#define COLOR_HLABEL COLOR_BROWN2 /* @@@ */
#define COLOR_HSHEET COLOR_HLABEL
#define COLOR_HSHEET_BOX COLOR_MAGENTA4
#define COLOR_HSHEET_SHEET COLOR_FIELD
#define COLOR_HSHEET_FILE COLOR_HLABEL
#define COLOR_LABEL COLOR_BLACK
#define COLOR_FIELD COLOR_CYAN4
#define COLOR_PIN_NAME COLOR_FIELD
@ -49,7 +52,8 @@
#define LAYER_FIELD 60
#define LAYER_PIN_NAME LAYER_FIELD
#define LAYER_PIN_NUMBER LAYER_FIELD
#define LAYER_HSHEET 70
#define LAYER_HSHEET_FIELD LAYER_FIELD
#define LAYER_HSHEET_BOX 70
#define LAYER_LINES 100
#define LAYER_COMP_DWG 120
#define LAYER_COMP_DWG_BG 200
@ -66,5 +70,6 @@
#define GLABEL_OFFSET 20
#define HLABEL_OFFSET_F 0.4 // * text size
#define PIN_NUM_OFFSET 15 // eeschema has more like 10
#define HSHEET_FIELD_OFFSET 10
#endif /* !STYLE_H */