r5626 - trunk/eda/fped

werner at docs.openmoko.org werner at docs.openmoko.org
Fri Sep 11 01:40:04 CEST 2009


Author: werner
Date: 2009-09-11 01:40:03 +0200 (Fri, 11 Sep 2009)
New Revision: 5626

Modified:
   trunk/eda/fped/gui_inst.c
   trunk/eda/fped/gui_style.c
   trunk/eda/fped/gui_style.h
   trunk/eda/fped/inst.c
   trunk/eda/fped/inst.h
   trunk/eda/fped/kicad.c
   trunk/eda/fped/postscript.c
Log:
- 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)



Modified: trunk/eda/fped/gui_inst.c
===================================================================
--- trunk/eda/fped/gui_inst.c	2009-09-10 23:12:45 UTC (rev 5625)
+++ trunk/eda/fped/gui_inst.c	2009-09-10 23:40:03 UTC (rev 5626)
@@ -263,7 +263,8 @@
 	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 @@
 	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;

Modified: trunk/eda/fped/gui_style.c
===================================================================
--- trunk/eda/fped/gui_style.c	2009-09-10 23:12:45 UTC (rev 5625)
+++ trunk/eda/fped/gui_style.c	2009-09-10 23:40:03 UTC (rev 5626)
@@ -25,6 +25,7 @@
 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 @@
 	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);

Modified: trunk/eda/fped/gui_style.h
===================================================================
--- trunk/eda/fped/gui_style.h	2009-09-10 23:12:45 UTC (rev 5625)
+++ trunk/eda/fped/gui_style.h	2009-09-10 23:40:03 UTC (rev 5626)
@@ -109,6 +109,7 @@
 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];

Modified: trunk/eda/fped/inst.c
===================================================================
--- trunk/eda/fped/inst.c	2009-09-10 23:12:45 UTC (rev 5625)
+++ trunk/eda/fped/inst.c	2009-09-10 23:40:03 UTC (rev 5626)
@@ -796,7 +796,8 @@
 {
 	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;

Modified: trunk/eda/fped/inst.h
===================================================================
--- trunk/eda/fped/inst.h	2009-09-10 23:12:45 UTC (rev 5625)
+++ trunk/eda/fped/inst.h	2009-09-10 23:40:03 UTC (rev 5626)
@@ -37,7 +37,8 @@
 
 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 */

Modified: trunk/eda/fped/kicad.c
===================================================================
--- trunk/eda/fped/kicad.c	2009-09-10 23:12:45 UTC (rev 5625)
+++ trunk/eda/fped/kicad.c	2009-09-10 23:40:03 UTC (rev 5626)
@@ -197,6 +197,7 @@
 {
 	switch (prio) {
 	case ip_pad:
+	case ip_pad_bare:
 		kicad_pad(file, inst);
 		break;
 	case ip_line:

Modified: trunk/eda/fped/postscript.c
===================================================================
--- trunk/eda/fped/postscript.c	2009-09-10 23:12:45 UTC (rev 5625)
+++ trunk/eda/fped/postscript.c	2009-09-10 23:40:03 UTC (rev 5626)
@@ -76,11 +76,14 @@
 #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,
 	.show_stuff	= 0,
@@ -359,12 +362,23 @@
 }
 
 
+/* ----- 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 @@
 
 	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_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 @@
 		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 @@
 	}
 	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 @@
 	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");
 }




More information about the commitlog mailing list