mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-23 05:48:06 +02:00
sch2fig/: pin names and fields (WIP)
This commit is contained in:
parent
1bab610e9e
commit
07433fd295
@ -86,6 +86,7 @@ struct obj {
|
||||
|
||||
struct comp {
|
||||
const char *name;
|
||||
unsigned visible; /* visible fields, bit mask */
|
||||
struct obj *objs;
|
||||
struct comp *next;
|
||||
};
|
||||
@ -95,6 +96,7 @@ struct comp {
|
||||
|
||||
|
||||
static struct comp *comps = NULL;
|
||||
static struct comp *comp; /* current component */
|
||||
static struct comp **next_comp = &comps;
|
||||
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 dx = 0, dy = 0;
|
||||
int rot;
|
||||
enum text_align hor, vert;
|
||||
|
||||
switch (pin->orient) {
|
||||
case 'U':
|
||||
dy = pin->length;
|
||||
rot = 90;
|
||||
hor = text_min;
|
||||
break;
|
||||
case 'D':
|
||||
dy = -pin->length;
|
||||
rot = 90;
|
||||
hor = text_max;
|
||||
break;
|
||||
case 'R':
|
||||
dx = pin->length;
|
||||
rot = 0;
|
||||
hor = text_min;
|
||||
break;
|
||||
case 'L':
|
||||
dx = -pin->length;
|
||||
rot = 0;
|
||||
hor = text_max;
|
||||
break;
|
||||
default:
|
||||
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);
|
||||
y[1] = my(pin->x + dx, pin->y + dy, m);
|
||||
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 obj *obj;
|
||||
|
||||
for (comp = comps; comp; comp = comp->next)
|
||||
if (!strcmp(comp->name, name))
|
||||
goto found;
|
||||
return comp;
|
||||
fprintf(stderr, "\"%s\" not found\n", name);
|
||||
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) {
|
||||
if (obj->unit && obj->unit != unit)
|
||||
continue;
|
||||
@ -250,10 +284,10 @@ bool lib_parse(struct lib_ctx *ctx, const char *line)
|
||||
int n = 0;
|
||||
char *s;
|
||||
unsigned points;
|
||||
struct comp *comp;
|
||||
struct obj *obj;
|
||||
char *style;
|
||||
unsigned zero1, zero2;
|
||||
char vis;
|
||||
|
||||
ctx->lineno++;
|
||||
|
||||
@ -265,6 +299,7 @@ bool lib_parse(struct lib_ctx *ctx, const char *line)
|
||||
if (*s == '~')
|
||||
s++;
|
||||
comp->name = s;
|
||||
comp->visible = 0;
|
||||
comp->objs = NULL;
|
||||
comp->next = NULL;
|
||||
*next_comp = comp;
|
||||
@ -278,6 +313,14 @@ bool lib_parse(struct lib_ctx *ctx, const char *line)
|
||||
ctx->state = lib_draw;
|
||||
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;
|
||||
case lib_draw:
|
||||
if (sscanf(line, "ENDDRAW%n", &n) == 0 && n) {
|
||||
|
@ -28,8 +28,12 @@ struct lib_ctx {
|
||||
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);
|
||||
void lib_init(struct lib_ctx *ctx);
|
||||
|
@ -74,6 +74,7 @@ struct sch_field {
|
||||
|
||||
static bool parse_field(struct sch_ctx *ctx, const char *line)
|
||||
{
|
||||
int n;
|
||||
unsigned flags;
|
||||
char hv, hor, vert, italic, bold;
|
||||
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);
|
||||
txt = &field->txt;
|
||||
|
||||
if (sscanf(line, "F %*d \"\" %c %d %d %u %u %c %c%c%c",
|
||||
&hv, &txt->x, &txt->y, &txt->size, &flags, &hor, &vert,
|
||||
&italic, &bold) == 9) {
|
||||
if (sscanf(line, "F %d \"\" %c %d %d %u %u %c %c%c%c",
|
||||
&n, &hv, &txt->x, &txt->y, &txt->size, &flags, &hor, &vert,
|
||||
&italic, &bold) == 10) {
|
||||
free(field);
|
||||
return 1;
|
||||
}
|
||||
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,
|
||||
&italic, &bold) != 10)
|
||||
if (sscanf(line, "F %d \"%m[^\"]\" %c %d %d %u %u %c %c%c%c",
|
||||
&n, &txt->s, &hv, &txt->x, &txt->y, &txt->size, &flags,
|
||||
&hor, &vert, &italic, &bold) != 11)
|
||||
return 0;
|
||||
|
||||
if (flags) {
|
||||
if (flags || !lib_field_visible(ctx->comp, n)) {
|
||||
free(field);
|
||||
return 1;
|
||||
}
|
||||
@ -292,12 +293,14 @@ bool sch_parse(struct sch_ctx *ctx, const char *line)
|
||||
case sch_comp:
|
||||
if (sscanf(line, "$EndComp%n", &n) == 0 && n) {
|
||||
ctx->state = sch_basic;
|
||||
free(ctx->comp);
|
||||
ctx->comp = NULL;
|
||||
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;
|
||||
}
|
||||
if (sscanf(line, "U %u", &ctx->unit) == 1)
|
||||
return 1;
|
||||
if (sscanf(line, "P %d %d", &ctx->x, &ctx->y) == 2)
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "lib.h"
|
||||
|
||||
|
||||
enum sch_state {
|
||||
sch_basic, /* basic state */
|
||||
@ -44,7 +46,7 @@ struct sch_ctx {
|
||||
|
||||
/* component */
|
||||
|
||||
char *comp; /* current component */
|
||||
const struct comp *comp; /* current component */
|
||||
unsigned unit; /* unit of current component */
|
||||
struct sch_field *fields;
|
||||
|
||||
|
@ -26,6 +26,8 @@
|
||||
#define COLOR_WIRE COLOR_GREEN4
|
||||
#define COLOR_GLABEL COLOR_RED4
|
||||
#define COLOR_FIELD COLOR_CYAN3
|
||||
#define COLOR_PIN_NAME COLOR_FIELD
|
||||
#define COLOR_PIN_NUMBER COLOR_FIELD
|
||||
|
||||
#define FONT_HELVETICA_BOLD 18
|
||||
|
||||
@ -33,6 +35,8 @@
|
||||
#define LAYER_TEXT 30
|
||||
#define LAYER_WIRES 50
|
||||
#define LAYER_FIELD 60
|
||||
#define LAYER_PIN_NAME LAYER_FIELD
|
||||
#define LAYER_PIN_NUMBER LAYER_FIELD
|
||||
#define LAYER_LINES 100
|
||||
#define LAYER_COMP_DWG 120
|
||||
|
||||
@ -44,4 +48,6 @@
|
||||
|
||||
#define GLABEL_OFFSET 20
|
||||
|
||||
#define PIN_NAME_OFFSET 40
|
||||
|
||||
#endif /* !STYLE_H */
|
||||
|
Loading…
Reference in New Issue
Block a user