1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-12-24 01:36:27 +02:00

sch2fig/fig.c: make glabels work when rotated by 180 degrees

This commit is contained in:
Werner Almesberger 2016-07-24 22:30:38 -03:00
parent e3a0229946
commit 1aaf1f8fb2

View File

@ -11,6 +11,7 @@
*/
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
@ -85,6 +86,31 @@ void fig_poly(int points, int x[points], int y[points],
/* ----- Schematics items -------------------------------------------------- */
enum box_type { // ___
box_simple, // [___]
box_left, // <___]
box_right, // [___>
box_both, // <___>
};
static enum box_type flip_box(enum box_type box)
{
switch (box) {
case box_simple:
return box_simple;
case box_left:
return box_right;
case box_right:
return box_left;
case box_both:
return box_both;
default:
abort();
}
}
void fig_glabel(int x, int y, const char *s, int dir, int dim,
enum fig_shape shape)
{
@ -101,19 +127,48 @@ void fig_glabel(int x, int y, const char *s, int dir, int dim,
int vx[7];
int vy[7];
int half = (dim >> 1) + GLABEL_OFFSET;
enum box_type box;
int dx, shift_flat, shift_tip;
bool anchor_right = 1;
switch (dir) {
case 0:
txt.rot = 0;
txt.hor = text_max;
switch (shape) {
case fig_in:
box = box_right;
break;
case fig_out:
box = box_left;
break;
case fig_bidir:
box = box_both;
break;
default:
assert(0);
}
switch (shape) {
case fig_in:
text_shift(&txt, txt.hor, text_mid, -GLABEL_OFFSET - half, 0);
switch (dir) {
case 0:
txt.rot = 0;
txt.hor = text_max;
dx = -1;
break;
case 2:
txt.rot = 0;
txt.hor = text_min;
dx = 1;
box = flip_box(box);
anchor_right = !anchor_right;
break;
default:
assert(0);
}
shift_flat = dx * GLABEL_OFFSET;
shift_tip = dx * (GLABEL_OFFSET + half);
switch (box) {
case box_right:
text_shift(&txt, txt.hor, text_mid,
anchor_right ? shift_tip : shift_flat, 0);
text_rel(&txt, text_min, text_min,
-GLABEL_OFFSET, GLABEL_OFFSET, vx + 1, vy + 1);
text_rel(&txt, text_max, text_min,
@ -125,8 +180,9 @@ void fig_glabel(int x, int y, const char *s, int dir, int dim,
text_rel(&txt, text_min, text_max,
-GLABEL_OFFSET, -GLABEL_OFFSET, vx + 5, vy + 5);
break;
case fig_out:
text_shift(&txt, txt.hor, text_mid, -GLABEL_OFFSET, 0);
case box_left:
text_shift(&txt, txt.hor, text_mid,
anchor_right ? shift_flat : shift_tip, 0);
text_rel(&txt, text_min, text_min,
-GLABEL_OFFSET, GLABEL_OFFSET, vx + 1, vy + 1);
text_rel(&txt, text_max, text_min,
@ -138,9 +194,9 @@ void fig_glabel(int x, int y, const char *s, int dir, int dim,
text_rel(&txt, text_min, text_mid, -GLABEL_OFFSET- half, 0,
vx + 5, vy + 5);
break;
case fig_bidir:
text_shift(&txt, txt.hor, text_mid, -GLABEL_OFFSET - half, 0);
case box_both:
n = 7;
text_shift(&txt, txt.hor, text_mid, shift_tip, 0);
text_rel(&txt, text_min, text_min,
-GLABEL_OFFSET, GLABEL_OFFSET, vx + 1, vy + 1);
text_rel(&txt, text_max, text_min,