From 93ba849a198251e2e0a0189146edc200f650d9ad Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 26 Jul 2016 13:10:34 -0300 Subject: [PATCH] sch2fig/lib.c (draw_pin): split off pin name and number output Function got a bit "heavy" ... --- sch2fig/lib.c | 137 ++++++++++++++++++++++++++++---------------------- 1 file changed, 77 insertions(+), 60 deletions(-) diff --git a/sch2fig/lib.c b/sch2fig/lib.c index 2c7b0fc..3b2a940 100644 --- a/sch2fig/lib.c +++ b/sch2fig/lib.c @@ -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, int m[6]) { int x[2], y[2]; int dx = 0, dy = 0; - int ox, oy, sx, sy; int rot; 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); 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) - text_fig(&name_txt, COLOR_PIN_NAME, LAYER_PIN_NAME); - - 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); - } + draw_pin_name(comp, pin, m, dx, dy, rot, hor); 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); }