r5525 - trunk/eda/fped

werner at docs.openmoko.org werner at docs.openmoko.org
Sat Aug 22 17:58:58 CEST 2009


Author: werner
Date: 2009-08-22 17:58:58 +0200 (Sat, 22 Aug 2009)
New Revision: 5525

Modified:
   trunk/eda/fped/Makefile
   trunk/eda/fped/README
   trunk/eda/fped/dump.c
   trunk/eda/fped/fpd.l
   trunk/eda/fped/fpd.y
   trunk/eda/fped/gui_inst.c
   trunk/eda/fped/gui_status.c
   trunk/eda/fped/gui_tool.c
   trunk/eda/fped/inst.c
   trunk/eda/fped/postscript.c
Log:
Made life in mil-land a little less painful.

- .fpd file format: new directive "unit" to set the default unit
- new selection was too aggressive - make it only rearrange settings if we also
  fail the second vector search
- gui_draw_pad_text: calculation of height vs. width lost too much precision,
  causing pad text to be rotated arbitrarily
- drag_new_vec: display distance in mil if unit is mil
- end_new_raw_vec: store distance in mil if unit is mil
- gridify: use a 10 mil grid if unit is mil
- ps_hline: corrected gsave/grestore mismatch
- Makefile: made "all" a prerequisite of "install"
- Postscript output now mentions the default unit (if set)
- ps_package: height and width were swapped, oopsie !



Modified: trunk/eda/fped/Makefile
===================================================================
--- trunk/eda/fped/Makefile	2009-08-22 14:29:48 UTC (rev 5524)
+++ trunk/eda/fped/Makefile	2009-08-22 15:58:58 UTC (rev 5525)
@@ -118,7 +118,7 @@
 
 # ----- Install / uninstall ---------------------------------------------------
 
-install:
+install:	all
 		install -m 755 fped $(PREFIX)/bin/
 
 uninstall:

Modified: trunk/eda/fped/README
===================================================================
--- trunk/eda/fped/README	2009-08-22 14:29:48 UTC (rev 5524)
+++ trunk/eda/fped/README	2009-08-22 15:58:58 UTC (rev 5525)
@@ -90,6 +90,7 @@
 frame definitions
 ...
 package name
+unit
 objects
 ...
 
@@ -125,7 +126,16 @@
 
 All values used as dimensions must be either mm or mil.
 
+The default unit can be set with one of the following directives:
 
+unit mm
+unit mil
+unit auto
+
+When saving a footprint definition, the default unit is set to the
+unit set in the GUI.
+
+
 Vectors
 - - - -
 

Modified: trunk/eda/fped/dump.c
===================================================================
--- trunk/eda/fped/dump.c	2009-08-22 14:29:48 UTC (rev 5524)
+++ trunk/eda/fped/dump.c	2009-08-22 15:58:58 UTC (rev 5525)
@@ -17,6 +17,7 @@
 #include "util.h"
 #include "unparse.h"
 #include "obj.h"
+#include "gui_status.h"
 #include "dump.h"
 
 
@@ -491,6 +492,24 @@
 /* ----- file -------------------------------------------------------------- */
 
 
+static void dump_unit(FILE *file)
+{
+	switch (curr_unit) {
+	case curr_unit_mm:
+		fprintf(file, "unit mm\n");
+		break;
+	case curr_unit_mil:
+		fprintf(file, "unit mil\n");
+		break;
+	case curr_unit_auto:
+		fprintf(file, "unit auto\n");
+		break;
+	default:
+		abort();
+	}
+}
+
+
 int dump(FILE *file)
 {
 	struct frame *frame;
@@ -501,6 +520,7 @@
 	for (frame = frames; frame; frame = frame->next) {
 		if (!frame->name) {
 			fprintf(file, "package \"%s\"\n", pkg_name);
+			dump_unit(file);
 			dump_frame(file, frame, "");
 		} else {
 			dump_frame(file, frame, "\t");

Modified: trunk/eda/fped/fpd.l
===================================================================
--- trunk/eda/fped/fpd.l	2009-08-22 14:29:48 UTC (rev 5524)
+++ trunk/eda/fped/fpd.l	2009-08-22 15:58:58 UTC (rev 5525)
@@ -118,6 +118,8 @@
 				  return TOK_MEASX; }
 <INITIAL>"measy"		{ BEGIN(NOKEYWORD);
 				  return TOK_MEASY; }
+<INITIAL>"unit"			{ BEGIN(NOKEYWORD);
+				  return TOK_UNIT; }
 
 <INITIAL>[a-zA-Z_][a-zA-Z_0-9]*: { *strchr(yytext, ':') = 0;
 				  yylval.id = unique(yytext);

Modified: trunk/eda/fped/fpd.y
===================================================================
--- trunk/eda/fped/fpd.y	2009-08-22 14:29:48 UTC (rev 5524)
+++ trunk/eda/fped/fpd.y	2009-08-22 15:58:58 UTC (rev 5525)
@@ -19,6 +19,7 @@
 #include "expr.h"
 #include "obj.h"
 #include "meas.h"
+#include "gui_status.h"
 #include "fpd.h"
 
 
@@ -156,7 +157,7 @@
 %token		START_FPD START_EXPR START_VAR START_VALUES
 %token		TOK_SET TOK_LOOP TOK_PACKAGE TOK_FRAME TOK_TABLE TOK_VEC
 %token		TOK_PAD TOK_RPAD TOK_RECT TOK_LINE TOK_CIRC TOK_ARC
-%token		TOK_MEAS TOK_MEASX TOK_MEASY
+%token		TOK_MEAS TOK_MEASX TOK_MEASY TOK_UNIT
 %token		TOK_NEXT TOK_NEXT_INVERTED TOK_MAX TOK_MAX_INVERTED
 
 %token	<num>	NUMBER
@@ -206,7 +207,7 @@
 	;
 
 fpd:
-	| frame_defs part_name frame_items
+	| frame_defs part_name opt_unit frame_items
 	;
 
 part_name:
@@ -227,6 +228,22 @@
 		}
 	;
 
+opt_unit:
+	| TOK_UNIT ID
+		{
+			if (!strcmp($2, "mm"))
+				curr_unit = curr_unit_mm;
+			else if (!strcmp($2, "mil"))
+				curr_unit = curr_unit_mil;
+			else if (!strcmp($2, "auto"))
+				curr_unit = curr_unit_auto;
+			else {
+				yyerrorf("unrecognized unit \"%s\"", $2);
+				YYABORT;
+			}
+		}
+	;
+
 frame_defs:
 	| frame_defs frame_def
 	;

Modified: trunk/eda/fped/gui_inst.c
===================================================================
--- trunk/eda/fped/gui_inst.c	2009-08-22 14:29:48 UTC (rev 5524)
+++ trunk/eda/fped/gui_inst.c	2009-08-22 15:58:58 UTC (rev 5525)
@@ -241,13 +241,17 @@
 	GdkGC *gc;
 	struct coord c;
 	unit_type h, w;
+	int rot;
 
+	w = self->bbox.max.x-self->bbox.min.x;
+	h = self->bbox.max.y-self->bbox.min.y;
+	rot = w/1.1 < h;
 	gc = gc_ptext[get_mode(self)];
 	sort_coord(&min, &max);
 	c = add_vec(min, max);
 	h = max.y-min.y;
 	w = max.x-min.x;
-	render_text(DA, gc, c.x/2, c.y/2, w <= h*1.1 ? 0 : 90,
+	render_text(DA, gc, c.x/2, c.y/2, rot ? 0 : 90,
 	    self->u.pad.name, PAD_FONT, 0.5, 0.5,
 	    w-2*PAD_BORDER, h-2*PAD_BORDER);
 }

Modified: trunk/eda/fped/gui_status.c
===================================================================
--- trunk/eda/fped/gui_status.c	2009-08-22 14:29:48 UTC (rev 5524)
+++ trunk/eda/fped/gui_status.c	2009-08-22 15:58:58 UTC (rev 5525)
@@ -736,25 +736,31 @@
 /* ----- unit selection ---------------------------------------------------- */
 
 
+static void show_curr_unit(void)
+{
+	switch (curr_unit) {
+	case curr_unit_mm:
+		status_set_unit("mm");
+		break;
+	case curr_unit_mil:
+		status_set_unit("mil");
+		break;
+	case curr_unit_auto:
+		status_set_unit("auto");
+		break;
+	default:
+		abort();
+	}
+}
+
+
 static gboolean unit_button_press_event(GtkWidget *widget,
     GdkEventButton *event, gpointer data)
 {
 	switch (event->button) {
 	case 1:
 		curr_unit = (curr_unit+1) % curr_unit_n;
-		switch (curr_unit) {
-		case curr_unit_mm:
-			status_set_unit("mm");
-			break;
-		case curr_unit_mil:
-			status_set_unit("mil");
-			break;
-		case curr_unit_auto:
-			status_set_unit("auto");
-			break;
-		default:
-			abort();
-		}
+		show_curr_unit();
 		break;
 	}
 	refresh_pos();
@@ -859,7 +865,7 @@
 	/* unit selection */
 
 	label_in_box_bg(status_unit, COLOR_UNIT_SELECTOR);
-	status_set_unit("mm");
+	show_curr_unit();
 	g_signal_connect(G_OBJECT(box_of_label(status_unit)),
 	    "button_press_event", G_CALLBACK(unit_button_press_event), NULL);
 

Modified: trunk/eda/fped/gui_tool.c
===================================================================
--- trunk/eda/fped/gui_tool.c	2009-08-22 14:29:48 UTC (rev 5524)
+++ trunk/eda/fped/gui_tool.c	2009-08-22 15:58:58 UTC (rev 5525)
@@ -215,8 +215,19 @@
 static struct coord gridify(struct coord base, struct coord pos)
 {
 	struct coord new;
-	unit_type unit = mm_to_units(0.1);
+	unit_type unit;
 
+	switch (curr_unit) {
+	case curr_unit_mm:
+	case curr_unit_auto:
+		unit = mm_to_units(0.1);
+		break;
+	case curr_unit_mil:
+		unit = mil_to_units(10);
+		break;
+	default:
+		abort();
+	}
 	new.x = pos.x-((pos.x-base.x) % unit);
 	new.y = pos.y-((pos.y-base.y) % unit);
 	if (new.x != base.x || new.y != base.y)
@@ -238,8 +249,20 @@
 	to = gridify(pos, to);
 	status_set_type_x("dX =");
 	status_set_type_y("dX =");
-	status_set_x("%lg mm", units_to_mm(to.x-pos.x));
-	status_set_y("%lg mm", units_to_mm(to.y-pos.y));
+	/* @@@ use status_set_xy */
+	switch (curr_unit) {
+	case curr_unit_mm:
+	case curr_unit_auto:
+		status_set_x("%lg mm", units_to_mm(to.x-pos.x));
+		status_set_y("%lg mm", units_to_mm(to.y-pos.y));
+		break;
+	case curr_unit_mil:
+		status_set_x("%lg mil", units_to_mil(to.x-pos.x));
+		status_set_y("%lg mil", units_to_mil(to.y-pos.y));
+		break;
+	default:
+		abort();
+	}
 	pos = translate(pos);
 	to = translate(to);
 	buf = save_pix_buf(DA, pos.x, pos.y, to.x, to.y, 1);
@@ -270,8 +293,19 @@
 	vec = new_vec(from);
 	pos = inst_get_point(from);
 	to = gridify(pos, to);
-	vec->x = new_num(make_mm(units_to_mm(to.x-pos.x)));
-	vec->y = new_num(make_mm(units_to_mm(to.y-pos.y)));
+	switch (curr_unit) {
+	case curr_unit_mm:
+	case curr_unit_auto:
+		vec->x = new_num(make_mm(units_to_mm(to.x-pos.x)));
+		vec->y = new_num(make_mm(units_to_mm(to.y-pos.y)));
+		break;
+	case curr_unit_mil:
+		vec->x = new_num(make_mil(units_to_mil(to.x-pos.x)));
+		vec->y = new_num(make_mil(units_to_mil(to.y-pos.y)));
+		break;
+	default:
+		abort();
+	}
 	return 1;
 }
 

Modified: trunk/eda/fped/inst.c
===================================================================
--- trunk/eda/fped/inst.c	2009-08-22 14:29:48 UTC (rev 5524)
+++ trunk/eda/fped/inst.c	2009-08-22 15:58:58 UTC (rev 5525)
@@ -208,6 +208,26 @@
 		if (selected_inst)
 			goto selected;
 	}
+
+	/* give vectors a second chance */
+
+	if (show_stuff) {
+		FOR_ALL_INSTS(i, ip_vec, inst) {
+			if (!inst->active)
+				continue;
+			if (!inst_connected(inst))
+				continue;
+			dist = gui_dist_vec_fallback(inst, pos, draw_ctx.scale);
+			if (dist >= 0 && (!selected_inst || best_dist > dist)) {
+				selected_inst = inst;
+				best_dist = dist;
+			}
+		}
+	
+		if (selected_inst)
+			goto selected;
+	}
+
 	if (any_same_frame) {
 		if (activate_item(any_same_frame))
 			return inst_select(pos);
@@ -220,26 +240,8 @@
 		}
 	}
 
-	if (!show_stuff)
-		return 0;
+	return 0;
 
-	/* give vectors a second chance */
-
-	FOR_ALL_INSTS(i, ip_vec, inst) {
-		if (!inst->active)
-			continue;
-		if (!inst_connected(inst))
-			continue;
-		dist = gui_dist_vec_fallback(inst, pos, draw_ctx.scale);
-		if (dist >= 0 && (!selected_inst || best_dist > dist)) {
-			selected_inst = inst;
-			best_dist = dist;
-		}
-	}
-	
-	if (!selected_inst)
-		return 0;
-
 selected:
 	inst_select_inst(selected_inst);
 	return 1;

Modified: trunk/eda/fped/postscript.c
===================================================================
--- trunk/eda/fped/postscript.c	2009-08-22 14:29:48 UTC (rev 5524)
+++ trunk/eda/fped/postscript.c	2009-08-22 15:58:58 UTC (rev 5525)
@@ -53,6 +53,8 @@
 #define	PS_DIVIDER_BORDER	mm_to_units(2)
 #define	PS_DIVIDER_WIDTH	mm_to_units(0.5)
 
+#define	PS_MISC_TEXT_HEIGHT	mm_to_units(3)
+
 #define	PS_DOT_DIST		mm_to_units(0.03)
 #define	PS_DOT_DIAM		mm_to_units(0.01)
 #define	PS_HATCH		mm_to_units(0.1)
@@ -454,7 +456,7 @@
 {
 	fprintf(file, "gsave %d setlinewidth\n", PS_DIVIDER_WIDTH);
 	fprintf(file, "    %d %d moveto\n", -PAGE_HALF_WIDTH, y);
-	fprintf(file, "    %d 0 rlineto stroke gsave\n", PAGE_HALF_WIDTH*2);
+	fprintf(file, "    %d 0 rlineto stroke grestore\n", PAGE_HALF_WIDTH*2);
 }
 
 
@@ -488,6 +490,32 @@
 }
 
 
+static void ps_unit(FILE *file,
+    unit_type x, unit_type y, unit_type w, unit_type h)
+{
+	const char *s;
+
+	switch (curr_unit) {
+	case curr_unit_mm:
+		s = "Dimensions in mm";
+		break;
+	case curr_unit_mil:
+		s = "Dimensions in mil";
+		break;
+	case curr_unit_auto:
+		return;
+	default:
+		abort();
+	}
+
+	fprintf(file, "gsave %d %d moveto\n", x, y);
+	fprintf(file, "    /Helvetica findfont dup\n");
+	fprintf(file, "    (%s) %d %d\n", s, w, h);
+	fprintf(file, "    4 copy 1000 maxfont maxfont scalefont setfont\n");
+	fprintf(file, "    (%s) show grestore\n", s);
+}
+
+
 static void ps_package(FILE *file, const struct pkg *pkg, int page)
 {
 	struct bbox bbox;
@@ -504,8 +532,8 @@
 	y = PAGE_HALF_HEIGHT-PS_HEADER_HEIGHT-3*PS_DIVIDER_BORDER;
 
 	bbox = inst_get_bbox();
-	w = 2*(-bbox.min.y > bbox.max.y ? -bbox.min.y : bbox.max.y);
-	h = 2*(-bbox.min.x > bbox.max.x ? -bbox.min.x : bbox.max.x);
+	w = 2*(-bbox.min.x > bbox.max.x ? -bbox.min.x : bbox.max.x);
+	h = 2*(-bbox.min.y > bbox.max.y ? -bbox.min.y : bbox.max.y);
 
 	/*
 	 * Zoom such that we can fit at least one drawing
@@ -574,6 +602,8 @@
 	}
 	fprintf(file, "grestore\n");
 
+	ps_unit(file, -PAGE_HALF_WIDTH, PS_DIVIDER_BORDER, PAGE_HALF_WIDTH,
+	    PS_MISC_TEXT_HEIGHT);
 	ps_hline(file, 0);
 
 	/*




More information about the commitlog mailing list