1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-27 03:20:36 +02:00

sch2fig/: pin names and fields (WIP)

This commit is contained in:
Werner Almesberger 2016-07-23 22:52:15 -03:00
parent 1bab610e9e
commit 07433fd295
5 changed files with 74 additions and 16 deletions

View File

@ -86,6 +86,7 @@ struct obj {
struct comp { struct comp {
const char *name; const char *name;
unsigned visible; /* visible fields, bit mask */
struct obj *objs; struct obj *objs;
struct comp *next; struct comp *next;
}; };
@ -95,6 +96,7 @@ struct comp {
static struct comp *comps = NULL; static struct comp *comps = NULL;
static struct comp *comp; /* current component */
static struct comp **next_comp = &comps; static struct comp **next_comp = &comps;
static struct obj **next_obj; static struct obj **next_obj;
@ -118,19 +120,29 @@ static void draw_pin(const struct pin_obj *pin, int m[6])
{ {
int x[2], y[2]; int x[2], y[2];
int dx = 0, dy = 0; int dx = 0, dy = 0;
int rot;
enum text_align hor, vert;
switch (pin->orient) { switch (pin->orient) {
case 'U': case 'U':
dy = pin->length; dy = pin->length;
rot = 90;
hor = text_min;
break; break;
case 'D': case 'D':
dy = -pin->length; dy = -pin->length;
rot = 90;
hor = text_max;
break; break;
case 'R': case 'R':
dx = pin->length; dx = pin->length;
rot = 0;
hor = text_min;
break; break;
case 'L': case 'L':
dx = -pin->length; dx = -pin->length;
rot = 0;
hor = text_max;
break; break;
default: default:
abort(); abort();
@ -140,6 +152,18 @@ static void draw_pin(const struct pin_obj *pin, int m[6])
x[1] = mx(pin->x + dx, pin->y + dy, m); x[1] = mx(pin->x + dx, pin->y + dy, m);
y[1] = my(pin->x + dx, pin->y + dy, m); y[1] = my(pin->x + dx, pin->y + dy, m);
fig_poly(2, x, y); fig_poly(2, x, y);
struct text txt = {
.s = pin->name,
.x = mx(pin->x + dx + PIN_NAME_OFFSET, pin->y + dy, m),
.y = my(pin->x + dx + PIN_NAME_OFFSET, pin->y + dy, m),
.size = pin->name_size,
.rot = rot,
.hor = hor,
.vert = text_mid,
};
text_rot(&txt, matrix_to_angle(m));
text_fig(&txt, COLOR_PIN_NAME, LAYER_PIN_NAME);
} }
@ -189,18 +213,28 @@ static void draw(const struct obj *obj, int m[6])
} }
void lib_exec(const char *name, unsigned unit, int m[4]) const struct comp *lib_find(const char *name)
{ {
const struct comp *comp; const struct comp *comp;
const struct obj *obj;
for (comp = comps; comp; comp = comp->next) for (comp = comps; comp; comp = comp->next)
if (!strcmp(comp->name, name)) if (!strcmp(comp->name, name))
goto found; return comp;
fprintf(stderr, "\"%s\" not found\n", name); fprintf(stderr, "\"%s\" not found\n", name);
exit(1); exit(1);
}
bool lib_field_visible(const struct comp *comp, int n)
{
return (comp->visible >> n) & 1;
}
void lib_exec(const struct comp *comp, unsigned unit, int m[4])
{
const struct obj *obj;
found:
for (obj = comp->objs; obj; obj = obj->next) { for (obj = comp->objs; obj; obj = obj->next) {
if (obj->unit && obj->unit != unit) if (obj->unit && obj->unit != unit)
continue; continue;
@ -250,10 +284,10 @@ bool lib_parse(struct lib_ctx *ctx, const char *line)
int n = 0; int n = 0;
char *s; char *s;
unsigned points; unsigned points;
struct comp *comp;
struct obj *obj; struct obj *obj;
char *style; char *style;
unsigned zero1, zero2; unsigned zero1, zero2;
char vis;
ctx->lineno++; ctx->lineno++;
@ -265,6 +299,7 @@ bool lib_parse(struct lib_ctx *ctx, const char *line)
if (*s == '~') if (*s == '~')
s++; s++;
comp->name = s; comp->name = s;
comp->visible = 0;
comp->objs = NULL; comp->objs = NULL;
comp->next = NULL; comp->next = NULL;
*next_comp = comp; *next_comp = comp;
@ -278,6 +313,14 @@ bool lib_parse(struct lib_ctx *ctx, const char *line)
ctx->state = lib_draw; ctx->state = lib_draw;
return 1; return 1;
} }
if (sscanf(line, "F%d \"\" %*d %*d %*d %*c %c", &n, &vis) == 2
|| sscanf(line, "F%d \"%*[^\"]\" %*d %*d %*d %*c %c",
&n, &vis) == 2) {
if (vis == 'V')
comp->visible |= 1 << n;
return 1;
}
/* @@@ explicitly ignore FPLIST */
return 1; return 1;
case lib_draw: case lib_draw:
if (sscanf(line, "ENDDRAW%n", &n) == 0 && n) { if (sscanf(line, "ENDDRAW%n", &n) == 0 && n) {

View File

@ -28,8 +28,12 @@ struct lib_ctx {
unsigned lineno; unsigned lineno;
}; };
struct comp;
void lib_exec(const char *name, unsigned unit, int m[6]);
const struct comp *lib_find(const char *name);
bool lib_field_visible(const struct comp *comp, int n);
void lib_exec(const struct comp *comp, unsigned unit, int m[6]);
bool lib_parse(struct lib_ctx *ctx, const char *line); bool lib_parse(struct lib_ctx *ctx, const char *line);
void lib_init(struct lib_ctx *ctx); void lib_init(struct lib_ctx *ctx);

View File

@ -74,6 +74,7 @@ struct sch_field {
static bool parse_field(struct sch_ctx *ctx, const char *line) static bool parse_field(struct sch_ctx *ctx, const char *line)
{ {
int n;
unsigned flags; unsigned flags;
char hv, hor, vert, italic, bold; char hv, hor, vert, italic, bold;
struct sch_field *field; struct sch_field *field;
@ -82,18 +83,18 @@ static bool parse_field(struct sch_ctx *ctx, const char *line)
field = alloc_type(struct sch_field); field = alloc_type(struct sch_field);
txt = &field->txt; txt = &field->txt;
if (sscanf(line, "F %*d \"\" %c %d %d %u %u %c %c%c%c", if (sscanf(line, "F %d \"\" %c %d %d %u %u %c %c%c%c",
&hv, &txt->x, &txt->y, &txt->size, &flags, &hor, &vert, &n, &hv, &txt->x, &txt->y, &txt->size, &flags, &hor, &vert,
&italic, &bold) == 9) { &italic, &bold) == 10) {
free(field); free(field);
return 1; return 1;
} }
if (sscanf(line, "F %*d \"%m[^\"]\" %c %d %d %u %u %c %c%c%c", if (sscanf(line, "F %d \"%m[^\"]\" %c %d %d %u %u %c %c%c%c",
&txt->s, &hv, &txt->x, &txt->y, &txt->size, &flags, &hor, &vert, &n, &txt->s, &hv, &txt->x, &txt->y, &txt->size, &flags,
&italic, &bold) != 10) &hor, &vert, &italic, &bold) != 11)
return 0; return 0;
if (flags) { if (flags || !lib_field_visible(ctx->comp, n)) {
free(field); free(field);
return 1; return 1;
} }
@ -292,12 +293,14 @@ bool sch_parse(struct sch_ctx *ctx, const char *line)
case sch_comp: case sch_comp:
if (sscanf(line, "$EndComp%n", &n) == 0 && n) { if (sscanf(line, "$EndComp%n", &n) == 0 && n) {
ctx->state = sch_basic; ctx->state = sch_basic;
free(ctx->comp);
ctx->comp = NULL; ctx->comp = NULL;
return 1; return 1;
} }
if (sscanf(line, "L %ms", &ctx->comp) == 1) if (sscanf(line, "L %ms", &s) == 1) {
ctx->comp = lib_find(s);
free(s);
return 1; return 1;
}
if (sscanf(line, "U %u", &ctx->unit) == 1) if (sscanf(line, "U %u", &ctx->unit) == 1)
return 1; return 1;
if (sscanf(line, "P %d %d", &ctx->x, &ctx->y) == 2) if (sscanf(line, "P %d %d", &ctx->x, &ctx->y) == 2)

View File

@ -16,6 +16,8 @@
#include <stdbool.h> #include <stdbool.h>
#include "lib.h"
enum sch_state { enum sch_state {
sch_basic, /* basic state */ sch_basic, /* basic state */
@ -44,7 +46,7 @@ struct sch_ctx {
/* component */ /* component */
char *comp; /* current component */ const struct comp *comp; /* current component */
unsigned unit; /* unit of current component */ unsigned unit; /* unit of current component */
struct sch_field *fields; struct sch_field *fields;

View File

@ -26,6 +26,8 @@
#define COLOR_WIRE COLOR_GREEN4 #define COLOR_WIRE COLOR_GREEN4
#define COLOR_GLABEL COLOR_RED4 #define COLOR_GLABEL COLOR_RED4
#define COLOR_FIELD COLOR_CYAN3 #define COLOR_FIELD COLOR_CYAN3
#define COLOR_PIN_NAME COLOR_FIELD
#define COLOR_PIN_NUMBER COLOR_FIELD
#define FONT_HELVETICA_BOLD 18 #define FONT_HELVETICA_BOLD 18
@ -33,6 +35,8 @@
#define LAYER_TEXT 30 #define LAYER_TEXT 30
#define LAYER_WIRES 50 #define LAYER_WIRES 50
#define LAYER_FIELD 60 #define LAYER_FIELD 60
#define LAYER_PIN_NAME LAYER_FIELD
#define LAYER_PIN_NUMBER LAYER_FIELD
#define LAYER_LINES 100 #define LAYER_LINES 100
#define LAYER_COMP_DWG 120 #define LAYER_COMP_DWG 120
@ -44,4 +48,6 @@
#define GLABEL_OFFSET 20 #define GLABEL_OFFSET 20
#define PIN_NAME_OFFSET 40
#endif /* !STYLE_H */ #endif /* !STYLE_H */