1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-30 07:11:52 +02:00

sch2fig/lib.c (draw_pin): split off pin name and number output

Function got a bit "heavy" ...
This commit is contained in:
Werner Almesberger 2016-07-26 13:10:34 -03:00
parent f9c32d4e1e
commit 93ba849a19

View File

@ -198,12 +198,86 @@ static void draw_arc(const struct arc_obj *arc, int m[6])
} }
static void draw_pin_name(const struct comp *comp, const struct pin_obj *pin,
int m[6], int dx, int dy, int rot, enum text_align hor)
{
int ox, oy;
ox = dx * (pin->length + comp->name_offset);
oy = dy * (pin->length + comp->name_offset);
struct text txt = {
.s = pin->name,
.x = mx(pin->x + ox, pin->y + oy, m),
.y = my(pin->x + ox, pin->y + oy, m),
.size = pin->name_size,
.rot = rot,
.hor = hor,
.vert = text_mid,
};
text_rot(&txt, matrix_to_angle(m));
if (matrix_is_mirrored(m)) {
if ((txt.rot % 180) == 0)
txt.hor = text_flip(txt.hor);
else
txt.vert = text_flip(txt.vert);
}
switch (txt.rot) {
case 180:
text_flip_x(&txt);
break;
default:
break;
}
text_fig(&txt, COLOR_PIN_NAME, LAYER_PIN_NAME);
}
static void draw_pin_num(const struct comp *comp, const struct pin_obj *pin,
int m[6], int dx, int dy, int rot, enum text_align hor)
{
int ox, oy, sx, sy;
ox = dx * pin->length / 2;
oy = dy * pin->length / 2;
sx = mxr(-dy * PIN_NUM_OFFSET, dx * PIN_NUM_OFFSET, m);
sy = myr(-dy * PIN_NUM_OFFSET, dx * PIN_NUM_OFFSET, m);
if (sx > 0)
sx = -sx;
if (sy > 0)
sy = -sy;
struct text txt = {
.s = pin->number,
.x = mx(pin->x + ox, pin->y + oy, m) + sx,
.y = my(pin->x + ox, pin->y + oy, m) + sy,
.size = pin->number_size,
.rot = rot,
.hor = text_mid,
.vert = text_min,
};
text_rot(&txt, matrix_to_angle(m) % 180);
if (matrix_is_mirrored(m)) {
if ((txt.rot % 180) == 0)
txt.hor = text_flip(txt.hor);
else
txt.vert = text_flip(txt.vert);
}
text_fig(&txt, COLOR_PIN_NUMBER, LAYER_PIN_NUMBER);
}
static void draw_pin(const struct comp *comp, const struct pin_obj *pin, static void draw_pin(const struct comp *comp, const struct pin_obj *pin,
int m[6]) int m[6])
{ {
int x[2], y[2]; int x[2], y[2];
int dx = 0, dy = 0; int dx = 0, dy = 0;
int ox, oy, sx, sy;
int rot; int rot;
enum text_align hor; enum text_align hor;
@ -237,68 +311,11 @@ static void draw_pin(const struct comp *comp, const struct pin_obj *pin,
y[1] = my(pin->x + dx * pin->length, pin->y + dy * pin->length, m); y[1] = my(pin->x + dx * pin->length, pin->y + dy * pin->length, m);
fig_poly(2, x, y, COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG); fig_poly(2, x, y, COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
ox = dx * (pin->length + comp->name_offset);
oy = dy * (pin->length + comp->name_offset);
struct text name_txt = {
.s = pin->name,
.x = mx(pin->x + ox, pin->y + oy, m),
.y = my(pin->x + ox, pin->y + oy, m),
.size = pin->name_size,
.rot = rot,
.hor = hor,
.vert = text_mid,
};
text_rot(&name_txt, matrix_to_angle(m));
if (matrix_is_mirrored(m)) {
if ((name_txt.rot % 180) == 0)
name_txt.hor = text_flip(name_txt.hor);
else
name_txt.vert = text_flip(name_txt.vert);
}
switch (name_txt.rot) {
case 180:
text_flip_x(&name_txt);
break;
default:
break;
}
if (comp->show_pin_name) if (comp->show_pin_name)
text_fig(&name_txt, COLOR_PIN_NAME, LAYER_PIN_NAME); draw_pin_name(comp, pin, m, dx, dy, rot, hor);
ox = dx * pin->length / 2;
oy = dy * pin->length / 2;
sx = mxr(-dy * PIN_NUM_OFFSET, dx * PIN_NUM_OFFSET, m);
sy = myr(-dy * PIN_NUM_OFFSET, dx * PIN_NUM_OFFSET, m);
if (sx > 0)
sx = -sx;
if (sy > 0)
sy = -sy;
struct text num_txt = {
.s = pin->number,
.x = mx(pin->x + ox, pin->y + oy, m) + sx,
.y = my(pin->x + ox, pin->y + oy, m) + sy,
.size = pin->number_size,
.rot = rot,
.hor = text_mid,
.vert = text_min,
};
text_rot(&num_txt, matrix_to_angle(m) % 180);
if (matrix_is_mirrored(m)) {
if ((num_txt.rot % 180) == 0)
num_txt.hor = text_flip(num_txt.hor);
else
num_txt.vert = text_flip(num_txt.vert);
}
if (comp->show_pin_num) if (comp->show_pin_num)
text_fig(&num_txt, COLOR_PIN_NUMBER, LAYER_PIN_NUMBER); draw_pin_num(comp, pin, m, dx, dy, rot, hor);
} }