1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-26 21:10:38 +02:00

sch2fig/: add partial support for (local) labels

This commit is contained in:
Werner Almesberger 2016-07-25 00:16:09 -03:00
parent 6f7463c299
commit 817befc29f
7 changed files with 56 additions and 8 deletions

View File

@ -76,6 +76,40 @@ static enum box_type flip_box(enum box_type box)
}
void fig_label(int x, int y, const char *s, int dir, int dim,
enum fig_shape shape)
{
struct text txt = {
.s = s,
.size = dim,
.x = x,
.y = y,
.rot = 0,
.hor = 0,
.vert = text_min,
};
int dy;
switch (dir) {
case 0:
txt.rot = 0;
txt.hor = text_min;
dy = 1;
break;
case 2:
txt.rot = 0;
txt.hor = text_max;
dy = 1;
break;
default:
assert(0);
}
txt.y -= dy * LABEL_OFFSET;
text_fig(&txt, COLOR_LABEL, LAYER_LABEL);
}
void fig_glabel(int x, int y, const char *s, int dir, int dim,
enum fig_shape shape)
{

View File

@ -28,6 +28,8 @@ enum fig_shape {
/* schematics */
void fig_label(int x, int y, const char *s, int dir, int dim,
enum fig_shape shape);
void fig_glabel(int x, int y, const char *s, int dir, int dim,
enum fig_shape shape);

View File

@ -36,3 +36,13 @@ unsigned matrix_to_angle(int m[6])
m[1], m[2], m[4], m[5]);
exit(1);
}
int angle_add(int a, int b)
{
a += b;
while (a < 0)
a += 360;
return a % 360;
}

View File

@ -42,5 +42,6 @@ static inline int my(int x, int y, int m[6])
unsigned matrix_to_angle(int m[6]);
int angle_add(int a, int b);
#endif /* !MISC_H */

View File

@ -238,10 +238,10 @@ bool sch_parse(struct sch_ctx *ctx, const char *line)
ctx->text = NULL;
return 1;
}
if (sscanf(line, "Text Label%n", &n) == 0 && n) {
if (sscanf(line, "Text Label %d %d %d %d",
&ctx->x, &ctx->y, &ctx->dir, &ctx->dim) == 4) {
ctx->state = sch_text;
unsupported("Text Label");
ctx->text = NULL;
ctx->text = fig_label;
return 1;
}

View File

@ -29,6 +29,7 @@
#define COLOR_WIRE COLOR_GREEN4
#define COLOR_NOCONN COLOR_BLUE
#define COLOR_GLABEL COLOR_RED4
#define COLOR_LABEL COLOR_BLACK
#define COLOR_FIELD COLOR_CYAN3
#define COLOR_PIN_NAME COLOR_FIELD
#define COLOR_PIN_NUMBER COLOR_RED4
@ -36,6 +37,7 @@
#define FONT_HELVETICA_BOLD 18
#define LAYER_GLABEL 20
#define LAYER_LABEL LAYER_GLABEL
#define LAYER_TEXT 30
#define LAYER_NOCONN 40
#define LAYER_WIRES 50
@ -54,7 +56,8 @@
#define NOCONN_LEN 25
#define LABEL_OFFSET 15 // eeschema has more like 10
#define GLABEL_OFFSET 20
#define PIN_NUM_OFFSET 15
#define PIN_NUM_OFFSET 15 // eeschema has more like 10
#endif /* !STYLE_H */

View File

@ -18,6 +18,7 @@
#include <math.h>
#include "util.h"
#include "misc.h"
#include "fig.h"
#include "text.h"
@ -49,10 +50,7 @@ void text_set(struct text *txt, const char *s)
void text_rot(struct text *txt, int deg)
{
txt->rot += deg;
while (txt->rot < 0)
txt->rot += 360;
txt->rot %= 360;
txt->rot = angle_add(txt->rot, deg);
}