From 5c37256c09459db34905c692f2464877cd2e1790 Mon Sep 17 00:00:00 2001 From: werner Date: Thu, 10 Sep 2009 23:40:03 +0000 Subject: [PATCH] - bare pads are now drawn in orange, so that one can see if a pad has a special solder mask pattern - postscript.c: don't scale fonts down to nothing to make measurement text fit (in progress) git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5626 99fdad57-331a-0410-800a-d7fa5415bdb3 --- gui_inst.c | 6 ++-- gui_style.c | 16 +++++----- gui_style.h | 1 + inst.c | 3 +- inst.h | 3 +- kicad.c | 1 + postscript.c | 84 +++++++++++++++++++++++++++++++++++++++++----------- 7 files changed, 86 insertions(+), 28 deletions(-) diff --git a/gui_inst.c b/gui_inst.c index 53d20bc..5bb8312 100644 --- a/gui_inst.c +++ b/gui_inst.c @@ -263,7 +263,8 @@ void gui_draw_pad(struct inst *self) struct coord max = translate(self->u.pad.other); GdkGC *gc; - gc = gc_pad[get_mode(self)]; + gc = self->obj->u.pad.type == pt_bare ? + gc_pad_bare[get_mode(self)] : gc_pad[get_mode(self)]; sort_coord(&min, &max); gdk_draw_rectangle(DA, gc, TRUE, min.x, min.y, max.x-min.x, max.y-min.y); @@ -279,7 +280,8 @@ void gui_draw_rpad(struct inst *self) GdkGC *gc; unit_type h, w, r; - gc = gc_pad[get_mode(self)]; + gc = self->obj->u.pad.type == pt_bare ? + gc_pad_bare[get_mode(self)] : gc_pad[get_mode(self)]; sort_coord(&min, &max); h = max.y-min.y; w = max.x-min.x; diff --git a/gui_style.c b/gui_style.c index 5b76a4d..aea7619 100644 --- a/gui_style.c +++ b/gui_style.c @@ -25,6 +25,7 @@ GdkGC *gc_active_frame; GdkGC *gc_vec[mode_n]; GdkGC *gc_obj[mode_n]; GdkGC *gc_pad[mode_n]; +GdkGC *gc_pad_bare[mode_n]; GdkGC *gc_ptext[mode_n]; GdkGC *gc_meas[mode_n]; GdkGC *gc_frame[mode_n]; @@ -59,13 +60,14 @@ void gui_setup_style(GdkDrawable *drawable) gc_bg = gc("#000000", 0); gc_bg_error = gc("#000040", 0); gc_drag = gc("#ffffff", 2); - /* inactive active selected */ - style(gc_vec, "#202000", "#b0b050", "#ffff80"); - style(gc_obj, "#006060", "#00ffff", "#ffff80"); - style(gc_pad, "#400000", "#ff0000", "#ffff80"); - style(gc_ptext, "#404040", "#ffffff", "#ffffff"); - style(gc_meas, "#280040", "#ff00ff", "#ffff80"); - style(gc_frame, "#005000", "#009000", "#ffff80"); + /* inactive active selected */ + style(gc_vec, "#202000", "#b0b050", "#ffff80"); + style(gc_obj, "#006060", "#00ffff", "#ffff80"); + style(gc_pad, "#400000", "#ff0000", "#ffff80"); + style(gc_pad_bare, "#402000", "#ff6000", "#ffff80"); + style(gc_ptext, "#404040", "#ffffff", "#ffffff"); + style(gc_meas, "#280040", "#ff00ff", "#ffff80"); + style(gc_frame, "#005000", "#009000", "#ffff80"); gc_active_frame = gc("#00ff00", 2); // gc_highlight = gc("#ff8020", 2); diff --git a/gui_style.h b/gui_style.h index f3c16d9..aad4107 100644 --- a/gui_style.h +++ b/gui_style.h @@ -109,6 +109,7 @@ extern GdkGC *gc_active_frame; extern GdkGC *gc_vec[mode_n]; extern GdkGC *gc_obj[mode_n]; extern GdkGC *gc_pad[mode_n]; +extern GdkGC *gc_pad_bare[mode_n]; extern GdkGC *gc_ptext[mode_n]; extern GdkGC *gc_meas[mode_n]; extern GdkGC *gc_frame[mode_n]; diff --git a/inst.c b/inst.c index 13a6f35..bee2605 100644 --- a/inst.c +++ b/inst.c @@ -796,7 +796,8 @@ int inst_pad(struct obj *obj, const char *name, struct coord a, struct coord b) { struct inst *inst; - inst = add_inst(obj->u.pad.rounded ? &rpad_ops : &pad_ops, ip_pad, a); + inst = add_inst(obj->u.pad.rounded ? &rpad_ops : &pad_ops, + obj->u.pad.type == pt_bare ? ip_pad_bare : ip_pad, a); inst->obj = obj; inst->u.pad.name = stralloc(name); inst->u.pad.other = b; diff --git a/inst.h b/inst.h index 61c20e3..8b264f1 100644 --- a/inst.h +++ b/inst.h @@ -37,7 +37,8 @@ struct bbox { enum inst_prio { ip_frame, /* frames have their own selection */ - ip_pad, /* pads also accept clicks inside */ + ip_pad_bare, /* pads also accept clicks inside */ + ip_pad, /* pads with solder mask on top of those without */ ip_circ, /* circles don't overlap easily */ ip_arc, /* arc are like circles, just shorter */ ip_rect, /* rectangles have plenty of sides */ diff --git a/kicad.c b/kicad.c index 5e01d71..99c65d4 100644 --- a/kicad.c +++ b/kicad.c @@ -197,6 +197,7 @@ static void kicad_inst(FILE *file, enum inst_prio prio, const struct inst *inst) { switch (prio) { case ip_pad: + case ip_pad_bare: kicad_pad(file, inst); break; case ip_line: diff --git a/postscript.c b/postscript.c index 94d2645..56bf8cc 100644 --- a/postscript.c +++ b/postscript.c @@ -76,10 +76,13 @@ #define PS_MEAS_ARROW_ANGLE 30 #define PS_MEAS_TEXT_HEIGHT mm_to_units(3) /* ~8.5 pt, real mm */ #define PS_MEAS_BASE_OFFSET mm_to_units(0.5) /* real mm */ +#define PS_MEAS_MIN_HEIGHT (PS_MEAS_TEXT_HEIGHT/2) #define PS_CROSS_WIDTH mm_to_units(0.01) #define PS_CROSS_DASH mm_to_units(0.1) +#define TEXT_HEIGHT_FACTOR 1.5 /* height/width of typical text */ + struct postscript_params postscript_params = { .show_pad_names = 1, @@ -359,12 +362,23 @@ static void ps_vec(FILE *file, const struct inst *inst) } +/* ----- Measurements ------------------------------------------------------ */ + + +static unit_type guesstimate_text_height(const char *s, unit_type width, + double zoom) +{ + return width/strlen(s)*TEXT_HEIGHT_FACTOR*zoom; +} + + static void ps_meas(FILE *file, const struct inst *inst, - enum curr_unit unit) + enum curr_unit unit, double zoom) { struct coord a0, b0, a1, b1; struct coord c, d; char *s; + unit_type height, width, offset; a0 = inst->base; b0 = inst->u.meas.end; @@ -384,16 +398,51 @@ static void ps_meas(FILE *file, const struct inst *inst, c = add_vec(a1, b1); d = sub_vec(b1, a1); - fprintf(file, "gsave %d %d moveto\n", c.x/2, c.y/2); - fprintf(file, " /Helvetica-Bold findfont dup\n"); - fprintf(file, " (%s) %d %d realsize\n", s, - (int) (dist_point(a1, b1)-1.5*PS_MEAS_ARROW_LEN), - PS_MEAS_TEXT_HEIGHT); - fprintf(file, " boxfont\n"); - fprintf(file, " %f rotate\n", atan2(d.y, d.x)/M_PI*180); - fprintf(file, " (%s) %d realsize hcenter\n", - s, PS_MEAS_BASE_OFFSET); - fprintf(file, " show grestore\n"); + + /* + * First try: put text between the arrows + */ + width = dist_point(a1, b1)-1.5*PS_MEAS_ARROW_LEN; + offset = PS_MEAS_BASE_OFFSET; + height = 0; + if (guesstimate_text_height(s, width, zoom) < PS_MEAS_MIN_HEIGHT) { +#if 0 +fprintf(stderr, "%s -> width %d height %d vs. %d\n", + s, width, guesstimate_text_height(s, width, zoom), PS_MEAS_MIN_HEIGHT); +#endif + /* + * Second try: push it above the arrows + */ + width = dist_point(a1, b1); + offset += + PS_MEAS_ARROW_LEN*sin(PS_MEAS_ARROW_ANGLE*M_PI/180)*zoom; + + if (guesstimate_text_height(s, width, zoom) < + PS_MEAS_MIN_HEIGHT) { + height = PS_MEAS_MIN_HEIGHT; + width = strlen(s)*height; + } + } + + if (height) { + fprintf(file, "gsave %d %d moveto\n", c.x/2, c.y/2); + fprintf(file, " /Helvetica-Bold findfont dup\n"); + fprintf(file, " (%s) %d realsize %d realsize\n", + s, width, height); + fprintf(file, " boxfont\n"); + fprintf(file, " %f rotate\n", atan2(d.y, d.x)/M_PI*180); + fprintf(file, " (%s) %d realsize hcenter\n", s, offset); + fprintf(file, " show grestore\n"); + } else { + fprintf(file, "gsave %d %d moveto\n", c.x/2, c.y/2); + fprintf(file, " /Helvetica-Bold findfont dup\n"); + fprintf(file, " (%s) %d %d realsize\n", s, width, + PS_MEAS_TEXT_HEIGHT); + fprintf(file, " boxfont\n"); + fprintf(file, " %f rotate\n", atan2(d.y, d.x)/M_PI*180); + fprintf(file, " (%s) %d realsize hcenter\n", s, offset); + fprintf(file, " show grestore\n"); + } free(s); } @@ -422,10 +471,11 @@ static void ps_background(FILE *file, enum inst_prio prio, static void ps_foreground(FILE *file, enum inst_prio prio, - const struct inst *inst) + const struct inst *inst, double zoom) { switch (prio) { case ip_pad: + case ip_pad_bare: if (inst->obj->u.pad.rounded) ps_rpad(file, inst, active_params.show_pad_names); else @@ -441,7 +491,7 @@ static void ps_foreground(FILE *file, enum inst_prio prio, break; case ip_meas: if (active_params.show_meas) - ps_meas(file, inst, curr_unit); + ps_meas(file, inst, curr_unit, zoom); break; default: break; @@ -479,9 +529,9 @@ static void ps_draw_package(FILE *file, const struct pkg *pkg, double zoom) } FOR_INST_PRIOS_UP(prio) { FOR_PKG_INSTS(pkgs, prio, inst) - ps_foreground(file, prio, inst); + ps_foreground(file, prio, inst, zoom); FOR_PKG_INSTS(pkg, prio, inst) - ps_foreground(file, prio, inst); + ps_foreground(file, prio, inst, zoom); } fprintf(file, "grestore\n"); } @@ -509,10 +559,10 @@ static void ps_draw_frame(FILE *file, const struct pkg *pkg, FOR_INST_PRIOS_UP(prio) { FOR_PKG_INSTS(pkgs, prio, inst) if (inst->outer == outer) - ps_foreground(file, prio, inst); + ps_foreground(file, prio, inst, zoom); FOR_PKG_INSTS(pkg, prio, inst) if (inst->outer == outer) - ps_foreground(file, prio, inst); + ps_foreground(file, prio, inst, zoom); } fprintf(file, "grestore\n"); }