From d6b73479ad76c704bb1275f2f348f71647285e3a Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 24 Jul 2016 22:57:52 -0300 Subject: [PATCH] sch2fig/: add filling of boxes and polygons --- sch2fig/fig.c | 76 ++++++++++++++++++++++++------------------------- sch2fig/fig.h | 8 ++---- sch2fig/lib.c | 58 ++++++++++++++++++++++++++++++------- sch2fig/style.h | 4 +++ 4 files changed, 93 insertions(+), 53 deletions(-) diff --git a/sch2fig/fig.c b/sch2fig/fig.c index d4c51b1..03de122 100644 --- a/sch2fig/fig.c +++ b/sch2fig/fig.c @@ -48,41 +48,6 @@ static inline float pt(int x) } -/* ----- Library items ----------------------------------------------------- */ - - -void fig_rect(int sx, int sy, int ex, int ey) -{ - // Type Thick Depth StyleV Rad - // SubTy Color Pen Join FwdAr - // Style FillCol AreaFil Cap BwdAr - printf("2 2 0 %d %d 7 %d -1 -1 0.0 1 1 -1 0 0 5\n", - WIDTH_COMP_DWG, COLOR_COMP_DWG, LAYER_COMP_DWG); - printf("\t%d %d %d %d %d %d %d %d %d %d\n", - cx(sx), cy(sy), cx(ex), cy(sy), cx(ex), cy(ey), cx(sx), cy(ey), - cx(sx), cy(sy)); -} - - -void fig_poly(int points, int x[points], int y[points], - unsigned color, unsigned layer) -{ - int i; - char ch = '\t'; - - // Type Thick Depth StyleV Rad - // 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, layer, points); - for (i = 0; i != points; i++) { - printf("%c%d %d", ch, cx(x[i]), cy(y[i])); - ch = ' '; - } - printf("\n"); -} - - /* ----- Schematics items -------------------------------------------------- */ @@ -218,7 +183,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, COLOR_GLABEL, LAYER_GLABEL); + fig_poly(n, vx, vy, COLOR_GLABEL, COLOR_NONE, LAYER_GLABEL); } @@ -238,9 +203,9 @@ void fig_noconn(int x, int y) int vx[2] = { x - NOCONN_LEN, x + NOCONN_LEN }; int vy[2] = { y - NOCONN_LEN, y + NOCONN_LEN }; - fig_poly(2, vx, vy, COLOR_NOCONN, LAYER_NOCONN); + fig_poly(2, vx, vy, COLOR_NOCONN, COLOR_NONE, LAYER_NOCONN); swap(vy[0], vy[1]); - fig_poly(2, vx, vy, COLOR_NOCONN, LAYER_NOCONN); + fig_poly(2, vx, vy, COLOR_NOCONN, COLOR_NONE, LAYER_NOCONN); } @@ -269,6 +234,41 @@ void fig_line(int sx, int sy, int ex, int ey) /* ----- General items ----------------------------------------------------- */ +void fig_rect(int sx, int sy, int ex, int ey, + int color, int fill_color, unsigned layer) +{ + // Type Thick Depth StyleV Rad + // SubTy Color Pen Join FwdAr + // Style FillCol AreaFil Cap BwdAr + printf("2 2 0 %d %d %d %d -1 %d 0.0 1 1 -1 0 0 5\n", + color == -1 ? 0 : WIDTH_COMP_DWG, color, fill_color, layer, + fill_color == -1 ? -1 : 20); + printf("\t%d %d %d %d %d %d %d %d %d %d\n", + cx(sx), cy(sy), cx(ex), cy(sy), cx(ex), cy(ey), cx(sx), cy(ey), + cx(sx), cy(sy)); +} + + +void fig_poly(int points, int x[points], int y[points], + int color, int fill_color, unsigned layer) +{ + int i; + char ch = '\t'; + + // Type Thick Depth StyleV Rad + // SubTy Color Pen Join FwdAr + // Style FillCol AreaFil Cap BwdAr + printf("2 1 0 %d %d %d %d -1 %d 0.0 1 1 -1 0 0 %d\n", + color == -1 ? 0 : WIDTH_COMP_DWG, color, fill_color, layer, + fill_color == -1 ? -1 : 20, points); + for (i = 0; i != points; i++) { + printf("%c%d %d", ch, cx(x[i]), cy(y[i])); + ch = ' '; + } + printf("\n"); +} + + void fig_text(int x, int y, const char *s, unsigned size, enum text_align align, int rot, unsigned color, unsigned layer) { diff --git a/sch2fig/fig.h b/sch2fig/fig.h index 006f14e..897be18 100644 --- a/sch2fig/fig.h +++ b/sch2fig/fig.h @@ -26,10 +26,6 @@ enum fig_shape { }; -/* libraries */ - -void fig_rect(int sx, int sy, int ex, int ey); - /* schematics */ void fig_glabel(int x, int y, const char *s, int dir, int dim, @@ -43,8 +39,10 @@ void fig_line(int sx, int sy, int ex, int ey); /* general */ +void fig_rect(int sx, int sy, int ex, int ey, + int color, int fill_color, unsigned layer); void fig_poly(int points, int x[points], int y[points], - unsigned color, unsigned layer); + int color, int fill_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); diff --git a/sch2fig/lib.c b/sch2fig/lib.c index a1cdaae..9d424e1 100644 --- a/sch2fig/lib.c +++ b/sch2fig/lib.c @@ -40,14 +40,14 @@ struct obj { unsigned unit; unsigned convert; union { - struct poly { + struct poly_obj { int thick; char fill; int points; int *x; int *y; } poly; - struct { + struct rect_obj { int thick; char fill; int sx, sy; @@ -106,7 +106,7 @@ static struct comp **next_comp = &comps; static struct obj **next_obj; -static void draw_poly(const struct poly *poly, int m[6]) +static void draw_poly(const struct poly_obj *poly, int m[6]) { int n = poly->points; int x[n]; @@ -117,7 +117,49 @@ 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, COLOR_COMP_DWG, LAYER_COMP_DWG); + + fig_poly(n, x, y, COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG); + + switch (poly->fill) { + case 'N': + break; + case 'F': + fig_poly(n, x, y, COLOR_NONE, COLOR_COMP_DWG, + LAYER_COMP_DWG_BG); + break; + case 'f': + fig_poly(n, x, y, COLOR_NONE, COLOR_COMP_DWG_BG, + LAYER_COMP_DWG_BG); + break; + default: + abort(); + } +} + + +static void draw_rect(const struct rect_obj *rect, int m[6]) +{ + int sx = mx(rect->sx, rect->sy, m); + int sy = my(rect->sx, rect->sy, m); + int ex = mx(rect->ex, rect->ey, m); + int ey = my(rect->ex, rect->ey, m); + + fig_rect(sx, sy, ex, ey, COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG); + + switch (rect->fill) { + case 'N': + break; + case 'F': + fig_rect(sx, sy, ex, ey, COLOR_NONE, COLOR_COMP_DWG, + LAYER_COMP_DWG_BG); + break; + case 'f': + fig_rect(sx, sy, ex, ey, COLOR_NONE, COLOR_COMP_DWG_BG, + LAYER_COMP_DWG_BG); + break; + default: + abort(); + } } @@ -157,7 +199,7 @@ static void draw_pin(const struct comp *comp, const struct pin_obj *pin, y[0] = my(pin->x, pin->y, m); x[1] = mx(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, LAYER_COMP_DWG); + fig_poly(2, x, y, COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG); dx *= pin->length + comp->name_offset; dy *= pin->length + comp->name_offset; @@ -201,11 +243,7 @@ static void draw(const struct comp *comp, const struct obj *obj, int m[6]) draw_poly(&obj->u.poly, m); break; case obj_rect: - fig_rect(mx(obj->u.rect.sx, obj->u.rect.sy, m), - my(obj->u.rect.sx, obj->u.rect.sy, m), - mx(obj->u.rect.ex, obj->u.rect.ey, m), - my(obj->u.rect.ex, obj->u.rect.ey, m)); - // @@@ + draw_rect(&obj->u.rect, m); break; case obj_circ: unsupported("circle"); diff --git a/sch2fig/style.h b/sch2fig/style.h index 5c6c6c6..e52dd34 100644 --- a/sch2fig/style.h +++ b/sch2fig/style.h @@ -13,14 +13,17 @@ #ifndef STYLE_H #define STYLE_H +#define COLOR_NONE -1 #define COLOR_BLACK 0 #define COLOR_BLUE 1 +#define COLOR_YELLOW 6 #define COLOR_GREEN4 12 #define COLOR_CYAN3 16 #define COLOR_RED4 18 #define COLOR_RED3 19 #define COLOR_COMP_DWG COLOR_RED4 +#define COLOR_COMP_DWG_BG COLOR_YELLOW #define COLOR_SHEET_DWG COLOR_BLUE #define COLOR_TEXT COLOR_BLUE #define COLOR_WIRE COLOR_GREEN4 @@ -41,6 +44,7 @@ #define LAYER_PIN_NUMBER LAYER_FIELD #define LAYER_LINES 100 #define LAYER_COMP_DWG 120 +#define LAYER_COMP_DWG_BG 200 #define WIDTH_WIRE 2 #define WIDTH_LINE 2