1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-27 01:53:44 +02:00

sch2fig/: sheet 1 almost works (A and especially K are off)

This commit is contained in:
Werner Almesberger 2016-07-23 23:12:56 -03:00
parent 07433fd295
commit 97f8969716
4 changed files with 58 additions and 27 deletions

View File

@ -61,7 +61,8 @@ void fig_rect(int sx, int sy, int ex, int ey)
}
void fig_poly(int points, int x[points], int y[points])
void fig_poly(int points, int x[points], int y[points],
unsigned color, unsigned layer)
{
int i;
char ch = '\t';
@ -70,7 +71,7 @@ void fig_poly(int points, int x[points], int y[points])
// 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_COMP_DWG, LAYER_COMP_DWG, points);
WIDTH_COMP_DWG, color, layer, points);
for (i = 0; i != points; i++) {
printf("%c%d %d", ch, cx(x[i]), cy(y[i]));
ch = ' ';
@ -143,7 +144,7 @@ void fig_glabel(int x, int y, const char *s, int dir, int dim,
vx[0] = vx[n - 1];
vy[0] = vy[n - 1];
fig_poly(n, vx, vy);
fig_poly(n, vx, vy, COLOR_GLABEL, LAYER_GLABEL);
}

View File

@ -28,7 +28,6 @@ enum fig_shape {
/* libraries */
void fig_rect(int sx, int sy, int ex, int ey);
void fig_poly(int points, int x[points], int y[points]);
/* schematics */
@ -42,6 +41,8 @@ void fig_line(int sx, int sy, int ex, int ey);
/* general */
void fig_poly(int points, int x[points], int y[points],
unsigned color, unsigned layer);
void fig_text(int x, int y, const char *s, unsigned size,
enum text_align align, int rot, unsigned color, unsigned layer);

View File

@ -86,7 +86,12 @@ struct obj {
struct comp {
const char *name;
unsigned visible; /* visible fields, bit mask */
bool show_pin_name;
bool show_pin_num;
unsigned name_offset;
struct obj *objs;
struct comp *next;
};
@ -112,11 +117,12 @@ static void draw_poly(const struct poly *poly, int m[6])
x[i] = mx(poly->x[i], poly->y[i], m);
y[i] = my(poly->x[i], poly->y[i], m);
}
fig_poly(n, x, y);
fig_poly(n, x, y, COLOR_COMP_DWG, LAYER_COMP_DWG);
}
static void draw_pin(const struct pin_obj *pin, int m[6])
static void draw_pin(const struct comp *comp, const struct pin_obj *pin,
int m[6])
{
int x[2], y[2];
int dx = 0, dy = 0;
@ -151,19 +157,21 @@ static void draw_pin(const struct pin_obj *pin, int m[6])
y[0] = my(pin->x, pin->y, m);
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);
fig_poly(2, x, y, COLOR_COMP_DWG, LAYER_COMP_DWG);
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),
.x = mx(pin->x + dx + comp->name_offset, pin->y + dy, m),
.y = my(pin->x + dx + comp->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);
if (comp->show_pin_name)
text_fig(&txt, COLOR_PIN_NAME, LAYER_PIN_NAME);
}
@ -182,7 +190,7 @@ static void draw_text(const struct text_obj *text, int m[6])
}
static void draw(const struct obj *obj, int m[6])
static void draw(const struct comp *comp, const struct obj *obj, int m[6])
{
switch (obj->type) {
case obj_poly:
@ -205,7 +213,7 @@ static void draw(const struct obj *obj, int m[6])
draw_text(&obj->u.text, m);
break;
case obj_pin:
draw_pin(&obj->u.pin, m);
draw_pin(comp, &obj->u.pin, m);
break;
default:
abort();
@ -238,7 +246,7 @@ void lib_exec(const struct comp *comp, unsigned unit, int m[4])
for (obj = comp->objs; obj; obj = obj->next) {
if (obj->unit && obj->unit != unit)
continue;
draw(obj, m);
draw(comp, obj, m);
}
}
@ -276,13 +284,46 @@ static bool parse_poly(struct obj *obj, const char *line, int points)
}
/* ----- Definitions ------------------------------------------------------- */
static bool parse_def(const char *line)
{
char *s;
char draw_num, draw_name;
unsigned name_offset;
if (sscanf(line, "DEF %ms %*s %*d %u %c %c",
&s, &name_offset, &draw_num, &draw_name) != 4)
return 0;
comp = alloc_type(struct comp);
if (*s == '~')
s++;
comp->name = s;
comp->visible = 0;
comp->show_pin_name = draw_name == 'Y';
comp->show_pin_num = draw_num == 'Y';
comp->name_offset = name_offset;
comp->objs = NULL;
next_obj = &comp->objs;
comp->next = NULL;
*next_comp = comp;
next_comp = &comp->next;
return 1;
}
/* ----- Library parser ---------------------------------------------------- */
bool lib_parse(struct lib_ctx *ctx, const char *line)
{
int n = 0;
char *s;
unsigned points;
struct obj *obj;
char *style;
@ -293,18 +334,8 @@ bool lib_parse(struct lib_ctx *ctx, const char *line)
switch (ctx->state) {
case lib_skip:
if (sscanf(line, "DEF %ms", &s) == 1) {
if (parse_def(line)) {
ctx->state = lib_def;
comp = alloc_type(struct comp);
if (*s == '~')
s++;
comp->name = s;
comp->visible = 0;
comp->objs = NULL;
comp->next = NULL;
*next_comp = comp;
next_comp = &comp->next;
next_obj = &comp->objs;
return 1;
}
return 1;

View File

@ -48,6 +48,4 @@
#define GLABEL_OFFSET 20
#define PIN_NAME_OFFSET 40
#endif /* !STYLE_H */