r5454 - trunk/eda/fped

werner at docs.openmoko.org werner at docs.openmoko.org
Sat Aug 15 22:52:09 CEST 2009


Author: werner
Date: 2009-08-15 22:52:08 +0200 (Sat, 15 Aug 2009)
New Revision: 5454

Modified:
   trunk/eda/fped/Makefile
   trunk/eda/fped/TODO
   trunk/eda/fped/coord.c
   trunk/eda/fped/coord.h
   trunk/eda/fped/gui_canvas.c
   trunk/eda/fped/gui_status.c
   trunk/eda/fped/gui_status.h
   trunk/eda/fped/inst.c
Log:
- added -std=gnu99 so that we can use "round" and M_PI
- added unit status and selection (in lower right corner)
- added automatic unit selection
- pointer coordinates are now shown with their unit
- updated display of X, Y, width, offset, and radius for unit selection



Modified: trunk/eda/fped/Makefile
===================================================================
--- trunk/eda/fped/Makefile	2009-08-15 19:37:13 UTC (rev 5453)
+++ trunk/eda/fped/Makefile	2009-08-15 20:52:08 UTC (rev 5454)
@@ -27,7 +27,7 @@
 
 CFLAGS_WARN=-Wall -Wshadow -Wmissing-prototypes \
             -Wmissing-declarations
-CFLAGS=-g $(CFLAGS_GTK) -DCPP='"cpp"' $(CFLAGS_WARN)
+CFLAGS=-g -std=gnu99 $(CFLAGS_GTK) -DCPP='"cpp"' $(CFLAGS_WARN)
 SLOPPY=-Wno-unused -Wno-implicit-function-declaration -Wno-missing-prototypes \
        -Wno-missing-declarations
 LDLIBS = -lm -lfl $(LIBS_GTK)

Modified: trunk/eda/fped/TODO
===================================================================
--- trunk/eda/fped/TODO	2009-08-15 19:37:13 UTC (rev 5453)
+++ trunk/eda/fped/TODO	2009-08-15 20:52:08 UTC (rev 5454)
@@ -1,7 +1,5 @@
 Major missing features:
 - populate input area (still needed: mm/mil, rezoom)
-- add default unit (combine with grid unit selection ?)
-- consider adding auto/mm/mil selection for each dimension
 - add postscript output (partially done)
 - add option to include/omit helper vecs and frames (done for display, still
   need postscript). Better idea: in PS, print the component 10x, 1x, and then

Modified: trunk/eda/fped/coord.c
===================================================================
--- trunk/eda/fped/coord.c	2009-08-15 19:37:13 UTC (rev 5453)
+++ trunk/eda/fped/coord.c	2009-08-15 20:52:08 UTC (rev 5454)
@@ -30,6 +30,44 @@
 	return mil*pow(MIL_IN_MM, exponent);
 }
 
+
+/* ----- convert internal units to best external unit ---------------------- */
+
+
+double units_to_best(unit_type u, int *mm)
+{
+	/*
+	 * For finding the best choice, we work with deci-micrometers and
+	 * micro-inches. The conversion to "dum" is actually a no-op, but that
+	 * may change if we ever pick a different internal unit than 0.1 um.
+	 */
+
+	long dum = round(units_to_mm(u)*10000.0);
+	long uin = round(units_to_mil(u)*1000.0);
+
+	/* remove trailing zeroes */
+
+	while (dum && !(dum % 10))
+		dum /= 10;
+	while (uin && !(uin % 10))
+		uin /= 10;
+
+	/* ceil(log10(dum)) <= ceil(log10(uin)) ? */
+
+	while (dum && uin) {
+		dum /= 10;
+		uin /= 10;
+	}
+	if (!dum) {
+		*mm = 1;
+		return units_to_mm(u);
+	} else {
+		*mm = 0;
+		return units_to_mil(u);
+	}
+}
+
+
 /* ----- vector operations ------------------------------------------------- */
 
 

Modified: trunk/eda/fped/coord.h
===================================================================
--- trunk/eda/fped/coord.h	2009-08-15 19:37:13 UTC (rev 5453)
+++ trunk/eda/fped/coord.h	2009-08-15 20:52:08 UTC (rev 5454)
@@ -54,6 +54,12 @@
 }
 
 
+static inline double units_to_mil(unit_type u)
+{
+	return (double) u/MIL_UNITS;
+}
+
+
 static inline int units_to_kicad(unit_type u)
 {
 	return (double) u/KICAD_UNIT;
@@ -69,6 +75,8 @@
 double mm_to_mil(double mm, int exponent);
 double mil_to_mm(double mil, int exponent);
 
+double units_to_best(unit_type u, int *mm);
+
 struct coord normalize(struct coord v, unit_type len);
 struct coord rotate(struct coord v, double angle);
 struct coord add_vec(struct coord a, struct coord b);

Modified: trunk/eda/fped/gui_canvas.c
===================================================================
--- trunk/eda/fped/gui_canvas.c	2009-08-15 19:37:13 UTC (rev 5453)
+++ trunk/eda/fped/gui_canvas.c	2009-08-15 20:52:08 UTC (rev 5454)
@@ -55,10 +55,10 @@
 
 static void update_pos(struct coord pos)
 {
-	status_set_sys_x("X %5.2lf" , units_to_mm(pos.x));
-	status_set_sys_y("Y %5.2lf" , units_to_mm(pos.y));
-	status_set_user_x("x %5.2lf", units_to_mm(pos.x-user_origin.x));
-	status_set_user_y("y %5.2lf", units_to_mm(pos.y-user_origin.y));
+	set_with_units(status_set_sys_x, "X ", pos.x);
+	set_with_units(status_set_sys_y, "Y ", pos.x);
+	set_with_units(status_set_user_x, "x ", pos.x-user_origin.x);
+	set_with_units(status_set_user_y, "y ", pos.y-user_origin.y);
 }
 
 

Modified: trunk/eda/fped/gui_status.c
===================================================================
--- trunk/eda/fped/gui_status.c	2009-08-15 19:37:13 UTC (rev 5453)
+++ trunk/eda/fped/gui_status.c	2009-08-15 20:52:08 UTC (rev 5454)
@@ -41,6 +41,15 @@
 	void (*store)(const char *s, void *ctx);
 };
 
+
+static enum curr_unit {
+	unit_mm,
+	unit_mil,
+	unit_auto,
+	unit_n
+} curr_unit = unit_mm;
+
+
 static GtkWidget *open_edits = NULL;
 static GtkWidget *last_edit = NULL;
 
@@ -55,7 +64,7 @@
 static GtkWidget *status_r, *status_angle;
 static GtkWidget *status_sys_x, *status_sys_y;
 static GtkWidget *status_user_x, *status_user_y;
-static GtkWidget *status_zoom, *status_grid;
+static GtkWidget *status_zoom, *status_grid, *status_unit;
 static GtkWidget *status_msg;
 
 
@@ -93,8 +102,43 @@
 SETTER(user_y)
 SETTER(zoom)
 SETTER(grid)
+SETTER(unit)
 
 
+/* ----- set things with units --------------------------------------------- */
+
+
+void set_with_units(void (*set)(const char *fmt, ...), const char *prefix,
+    unit_type u)
+{
+	double n;
+	int mm;
+
+	switch (curr_unit) {
+	case unit_mm:
+		n = units_to_mm(u);
+		mm = 1;
+		break;
+	case unit_mil:
+		n = units_to_mil(u);
+		mm = 0;
+		break;
+	case unit_auto:
+		n = units_to_best(u, &mm);
+		break;
+	default:
+		abort();
+	}
+	if (mm) {
+		/* -NNN.NNN mm */
+		set("%s%8.3f mm", prefix, n);
+	} else {
+		/* -NNNN.N mil */
+		set("%s%7.1f mil", prefix, n);
+	}
+}
+
+
 /* ----- complex status updates -------------------------------------------- */
 
 
@@ -104,8 +148,8 @@
 	status_set_type_x("X =");
 	status_set_type_y("Y =");
 
-	status_set_x("%5.2f mm", units_to_mm(coord.x));
-	status_set_y("%5.2f mm", units_to_mm(coord.y));
+	set_with_units(status_set_x, "", coord.x);
+	set_with_units(status_set_y, "", coord.y);
 }
 
 
@@ -500,12 +544,10 @@
 		return TRUE;
 	for (edit = open_edits; edit;
 	    edit = gtk_object_get_data(GTK_OBJECT(edit), "edit-next"))
-{
 		if (get_status(edit) == es_good) {
 			entry_color(edit, COLOR_EDIT_ASIS);
 			set_edit(edit);
 		}
-}
 	inst_deselect();
 	change_world();
 	return TRUE;
@@ -553,10 +595,38 @@
 }
 
 
+/* ----- unit selection ---------------------------------------------------- */
+
+
+static gboolean unit_button_press_event(GtkWidget *widget,
+    GdkEventButton *event, gpointer data)
+{
+	switch (event->button) {
+	case 1:
+		curr_unit = (curr_unit+1) % unit_n;
+		switch (curr_unit) {
+		case unit_mm:
+			status_set_unit("mm");
+			break;
+		case unit_mil:
+			status_set_unit("mil");
+			break;
+		case unit_auto:
+			status_set_unit("auto");
+			break;
+		default:
+			abort();
+		}
+		break;
+	}
+	return TRUE;
+}
+
+
 /* ----- setup ------------------------------------------------------------- */
 
 
-static GtkWidget *add_label(GtkWidget *tab, int col, int row)
+static GtkWidget *add_label_basic(GtkWidget *tab, int col, int row)
 {
 	GtkWidget *label;
 
@@ -565,7 +635,15 @@
 	    col, col+1, row, row+1,
 	    GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 1);
 	    /* 0 , 1 - padding */
+	return label;
+}
 
+
+static GtkWidget *add_label(GtkWidget *tab, int col, int row)
+{
+	GtkWidget *label;
+
+	label = add_label_basic(tab, col, row);
 	gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
 	gtk_label_set_selectable(GTK_LABEL(label), TRUE);
 	return label;
@@ -632,11 +710,18 @@
 	status_r = add_label(tab, 4, 2);
 	status_angle = add_label(tab, 5, 2);
 
-	/* zoom / grid */
+	/* zoom / grid / unit */
 
 	status_zoom = add_label(tab, 6, 0);
 	status_grid = add_label(tab, 6, 1);
+	status_unit = add_label_basic(tab, 6, 2);
 
+	/* unit selection */
+
+	status_set_unit("mm");
+	g_signal_connect(G_OBJECT(box_of_label(status_unit)),
+	    "button_press_event", G_CALLBACK(unit_button_press_event), NULL);
+
 	/* message bar */
 
 	status_msg = gtk_statusbar_new();

Modified: trunk/eda/fped/gui_status.h
===================================================================
--- trunk/eda/fped/gui_status.h	2009-08-15 19:37:13 UTC (rev 5453)
+++ trunk/eda/fped/gui_status.h	2009-08-15 20:52:08 UTC (rev 5454)
@@ -30,6 +30,9 @@
 void edit_y(struct expr **expr);
 void edit_nothing(void);
 
+void set_with_units(void (*set)(const char *fmt, ...), const char *prefix,
+    unit_type u);
+
 void status_set_type_x(const char *fmt, ...);
 void status_set_type_y(const char *fmt, ...);
 void status_set_type_entry(const char *fmt, ...);
@@ -44,6 +47,7 @@
 void status_set_user_y(const char *fmt, ...);
 void status_set_zoom(const char *fmt, ...);
 void status_set_grid(const char *fmt, ...);
+void status_set_unit(const char *fmt, ...);
 
 void status_set_xy(struct coord coord);
 

Modified: trunk/eda/fped/inst.c
===================================================================
--- trunk/eda/fped/inst.c	2009-08-15 19:37:13 UTC (rev 5453)
+++ trunk/eda/fped/inst.c	2009-08-15 20:52:08 UTC (rev 5454)
@@ -389,10 +389,10 @@
 		angle = theta(a, b);
 		status_set_angle("a = %3.1f deg", angle);
 	}
-	status_set_r("r = %5.2f mm", hypot(units_to_mm(d.x), units_to_mm(d.y)));
+	set_with_units(status_set_r, "r = ", hypot(d.x, d.y));
 	if (width != -1) {
 		status_set_type_entry("width =");
-		status_set_name("%5.2f mm", units_to_mm(width));
+		set_with_units(status_set_name, "", width);
 	}
 }
 
@@ -769,9 +769,9 @@
 	status_set_angle("a = %3.1f deg",
 	    self->u.arc.a1 == self->u.arc.a2 ? 360 :
 	    self->u.arc.a2-self->u.arc.a1);
-	status_set_r("r = %5.2f mm", units_to_mm(self->u.arc.r));
+	set_with_units(status_set_r, "r = ", self->u.arc.r);
 	status_set_type_entry("width =");
-	status_set_name("%5.2f mm", units_to_mm(self->u.arc.width));
+	set_with_units(status_set_name, "", self->u.arc.width);
 	obj_arc_edit(self->obj);
 }
 
@@ -845,7 +845,7 @@
 {
 	rect_status(self->bbox.min, self->bbox.max, -1);
 	status_set_type_entry("offset =");
-	status_set_name("%5.2f mm", units_to_mm(self->u.meas.offset));
+	set_with_units(status_set_name, "", self->u.meas.offset);
 	obj_meas_edit(self->obj);
 }
 




More information about the commitlog mailing list