r5381 - trunk/eda/fped

werner at docs.openmoko.org werner at docs.openmoko.org
Tue Aug 4 02:23:10 CEST 2009


Author: werner
Date: 2009-08-04 02:23:10 +0200 (Tue, 04 Aug 2009)
New Revision: 5381

Modified:
   trunk/eda/fped/TODO
   trunk/eda/fped/expr.c
   trunk/eda/fped/gui.c
   trunk/eda/fped/gui_canvas.c
   trunk/eda/fped/gui_status.c
   trunk/eda/fped/gui_status.h
   trunk/eda/fped/inst.c
Log:
- fixed stupid realloc(..., len) error
- rearranged input area and added vector component edit capability



Modified: trunk/eda/fped/TODO
===================================================================
--- trunk/eda/fped/TODO	2009-08-03 23:23:00 UTC (rev 5380)
+++ trunk/eda/fped/TODO	2009-08-04 00:23:10 UTC (rev 5381)
@@ -1,7 +1,5 @@
 Missing features:
 - populate input area (still needed: mm/mil, rezoom)
-- add vec editor (need to be able to edit name, x, and y)
-- add obj editor
 - add table/var/loop editor (missing: add col/row, add/del var/table/loop)
 - add default unit (combine with grid unit selection ?)
 - consider adding auto/mm/mil selection for each dimension
@@ -16,6 +14,7 @@
 
 Style:
 - make column of entry field greedily consume all unallocated space
+- status area looks awful
 
 Bugs:
 - default silk width has no business being hard-coded in obj.c

Modified: trunk/eda/fped/expr.c
===================================================================
--- trunk/eda/fped/expr.c	2009-08-03 23:23:00 UTC (rev 5380)
+++ trunk/eda/fped/expr.c	2009-08-04 00:23:10 UTC (rev 5381)
@@ -365,7 +365,7 @@
 		value_len = snprintf(num_buf, sizeof(num_buf), "%lg%s",
 		    value.n, str_unit(value));
 		len += value_len;
-		buf = realloc(buf, len);
+		buf = realloc(buf, len+1);
 		if (!buf)
 			abort();
 		strcpy(buf+i, num_buf);

Modified: trunk/eda/fped/gui.c
===================================================================
--- trunk/eda/fped/gui.c	2009-08-03 23:23:00 UTC (rev 5380)
+++ trunk/eda/fped/gui.c	2009-08-04 00:23:10 UTC (rev 5381)
@@ -114,6 +114,7 @@
 {
 	inst_select_outside(var, unselect_var);
         label_in_box_bg(var->widget, COLOR_VAR_EDITING);
+	status_set_type_entry("name =");
 	status_set_name(var->name);
 	edit_unique(&var->name, validate_var_name, var);
 }
@@ -491,6 +492,7 @@
 {
 	inst_select_outside(frame, unselect_frame);
 	label_in_box_bg(frame->label, COLOR_FRAME_EDITING);
+	status_set_type_entry("name =");
 	status_set_name(frame->name);
 	edit_unique(&frame->name, validate_frame_name, frame);
 }

Modified: trunk/eda/fped/gui_canvas.c
===================================================================
--- trunk/eda/fped/gui_canvas.c	2009-08-03 23:23:00 UTC (rev 5380)
+++ trunk/eda/fped/gui_canvas.c	2009-08-04 00:23:10 UTC (rev 5381)
@@ -39,10 +39,10 @@
 
 static void update_pos(struct coord pos)
 {
-	status_set_sys_pos("X %5.2lf  Y %5.2lf mm",
-	    units_to_mm(pos.x), units_to_mm(pos.y));
-	status_set_user_pos("x %5.2lf  y  %5.2lf mm",
-	    units_to_mm(pos.x-user_origin.x), units_to_mm(pos.y-user_origin.y));
+	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));
 }
 
 

Modified: trunk/eda/fped/gui_status.c
===================================================================
--- trunk/eda/fped/gui_status.c	2009-08-03 23:23:00 UTC (rev 5380)
+++ trunk/eda/fped/gui_status.c	2009-08-04 00:23:10 UTC (rev 5381)
@@ -32,17 +32,17 @@
 	int (*activate)(GtkWidget *widget, const char *s, void *ctx);
 };
 
-static struct edit_ops *edit_ops = NULL;
-static void *edit_ctx;
 
-
 /* ----- setter functions -------------------------------------------------- */
 
 
 static GtkWidget *status_name, *status_entry;
+static GtkWidget *status_type_x, *status_type_y, *status_type_entry;
+static GtkWidget *status_entry_x, *status_entry_y;
 static GtkWidget *status_x, *status_y;
 static GtkWidget *status_r, *status_angle;
-static GtkWidget *status_sys_pos, *status_user_pos;
+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_msg;
 
@@ -67,13 +67,18 @@
 		va_end(ap);				\
 	}
 
+SETTER(type_x)
+SETTER(type_y)
+SETTER(type_entry)
 SETTER(name)
 SETTER(x)
 SETTER(y)
 SETTER(r)
 SETTER(angle)
-SETTER(sys_pos)
-SETTER(user_pos)
+SETTER(sys_x)
+SETTER(sys_y)
+SETTER(user_x)
+SETTER(user_y)
 SETTER(zoom)
 SETTER(grid)
 
@@ -83,21 +88,38 @@
 
 void status_set_xy(struct coord coord)
 {
-	status_set_x("x = %5.2f mm", units_to_mm(coord.x));
-	status_set_y("y = %5.2f mm", units_to_mm(coord.y));
+	/* do dX/dY etc. stuff later */
+	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));
 }
 
 
-static void entry_color(const char *color)
+static void entry_color(GtkWidget *widget, const char *color)
 {
 	GdkColor col;
 
 	col = get_color(color);
-	gtk_widget_modify_base(GTK_WIDGET(status_entry),
-	    GTK_STATE_NORMAL, &col);
+	gtk_widget_modify_base(widget, GTK_STATE_NORMAL, &col);
 }
 
 
+/* ----- helper functions -------------------------------------------------- */
+
+
+static void setup_edit(GtkWidget *widget, const char *s,
+    struct edit_ops *ops, void *ctx)
+{
+	gtk_entry_set_text(GTK_ENTRY(widget), s);
+	entry_color(widget, COLOR_EDIT_ASIS);
+	gtk_widget_show(widget);
+	gtk_object_set_data(GTK_OBJECT(widget), "edit-ops", ops);
+	gtk_object_set_data(GTK_OBJECT(widget), "edit-ctx", ctx);
+}
+
+
 /* ----- identifier fields ------------------------------------------------- */
 
 
@@ -114,11 +136,11 @@
 	int ok;
 
 	if (!strcmp(s, *unique_ctx->s)) {
-		entry_color(COLOR_EDIT_ASIS);
+		entry_color(widget, COLOR_EDIT_ASIS);
 		return 1;
 	}
 	ok = !unique_ctx->validate || unique_ctx->validate(s, unique_ctx->ctx);
-	entry_color(ok ? COLOR_EDIT_GOOD : COLOR_EDIT_BAD);
+	entry_color(widget, ok ? COLOR_EDIT_GOOD : COLOR_EDIT_BAD);
 	return ok;
 }
 
@@ -131,7 +153,7 @@
 	     unique_ctx->validate && !unique_ctx->validate(s, unique_ctx->ctx))
 		return 0;
 	*unique_ctx->s = unique(s);
-	entry_color(COLOR_EDIT_ASIS);
+	entry_color(widget, COLOR_EDIT_ASIS);
 	return 1;
 }
 
@@ -150,11 +172,7 @@
 	unique_ctx.s = s;
 	unique_ctx.validate = validate;
 	unique_ctx.ctx = ctx;
-	edit_ops = &edit_ops_unique;
-	edit_ctx = &unique_ctx;
-	gtk_entry_set_text(GTK_ENTRY(status_entry), *s);
-	entry_color(COLOR_EDIT_ASIS);
-	gtk_widget_show(status_entry);
+	setup_edit(status_entry, *s, &edit_ops_unique, &unique_ctx);
 }
 
 
@@ -167,14 +185,14 @@
 	int ok;
 
 	if (!strcmp(s, *unique_ctx->s ? *unique_ctx->s : "")) {
-		entry_color(COLOR_EDIT_ASIS);
+		entry_color(widget, COLOR_EDIT_ASIS);
 		return 1;
 	}
 	ok = !*s;
 	if (!ok)
 		ok = !unique_ctx->validate ||
 		     unique_ctx->validate(s, unique_ctx->ctx);
-	entry_color(ok ? COLOR_EDIT_GOOD : COLOR_EDIT_BAD);
+	entry_color(widget, ok ? COLOR_EDIT_GOOD : COLOR_EDIT_BAD);
 	return ok;
 }
 
@@ -191,7 +209,7 @@
 			return 0;
 		*unique_ctx->s = unique(s);
 	}
-	entry_color(COLOR_EDIT_ASIS);
+	entry_color(widget, COLOR_EDIT_ASIS);
 	return 1;
 }
 
@@ -210,11 +228,8 @@
 	unique_ctx.s = s;
 	unique_ctx.validate = validate;
 	unique_ctx.ctx = ctx;
-	edit_ops = &edit_ops_null_unique;
-	edit_ctx = &unique_ctx;
-	gtk_entry_set_text(GTK_ENTRY(status_entry), *s ? *s : "");
-	entry_color(COLOR_EDIT_ASIS);
-	gtk_widget_show(status_entry);
+	setup_edit(status_entry, *s ? *s : "",
+	    &edit_ops_null_unique, &unique_ctx);
 }
 
 
@@ -234,11 +249,11 @@
 	int ok;
 
 	if (!strcmp(s, *name_ctx->s)) {
-		entry_color(COLOR_EDIT_ASIS);
+		entry_color(widget, COLOR_EDIT_ASIS);
 		return 1;
 	}
 	ok = !name_ctx->validate || name_ctx->validate(s, name_ctx->ctx);
-	entry_color(ok ? COLOR_EDIT_GOOD : COLOR_EDIT_BAD);
+	entry_color(widget, ok ? COLOR_EDIT_GOOD : COLOR_EDIT_BAD);
 	return ok;
 }
 
@@ -251,7 +266,7 @@
 		return 0;
 	free(*name_ctx->s);
 	*name_ctx->s = stralloc(s);
-	entry_color(COLOR_EDIT_ASIS);
+	entry_color(widget, COLOR_EDIT_ASIS);
 	return 1;
 }
 
@@ -269,11 +284,7 @@
 	name_ctx.s = s;
 	name_ctx.validate = validate;
 	name_ctx.ctx = ctx;
-	edit_ops = &edit_ops_name;
-	edit_ctx = &name_ctx;
-	gtk_entry_set_text(GTK_ENTRY(status_entry), *s);
-	entry_color(COLOR_EDIT_ASIS);
-	gtk_widget_show(status_entry);
+	setup_edit(status_entry, *s, &edit_ops_name, &name_ctx);
 }
 
 
@@ -293,10 +304,10 @@
 
 	expr = try_parse_expr(s);
 	if (!expr) {
-		entry_color(COLOR_EDIT_BAD);
+		entry_color(widget, COLOR_EDIT_BAD);
 		return 0;
 	}
-	entry_color(COLOR_EDIT_GOOD);
+	entry_color(widget, COLOR_EDIT_GOOD);
 	free_expr(expr);
 	return 1;
 }
@@ -313,7 +324,7 @@
 	if (*anchor)
 		free_expr(*anchor);
 	*anchor = expr;
-	entry_color(COLOR_EDIT_ASIS);
+	entry_color(widget, COLOR_EDIT_ASIS);
 	return 1;
 }
 
@@ -324,29 +335,47 @@
 };
 
 
-void edit_expr(struct expr **expr)
+static void edit_any_expr(GtkWidget *widget, struct expr **expr)
 {
 	char *s;
 
-	edit_ops = &edit_ops_expr;
-	edit_ctx = expr;
 	s = unparse(*expr);
-	gtk_entry_set_text(GTK_ENTRY(status_entry), s);
+	setup_edit(widget, s, &edit_ops_expr, expr);
 	free(s);
-	entry_color(COLOR_EDIT_ASIS);
-	gtk_widget_show(status_entry);
 }
 
 
+void edit_expr(struct expr **expr)
+{
+	edit_any_expr(status_entry, expr);
+}
+
+
+void edit_x(struct expr **expr)
+{
+	edit_any_expr(status_entry_x, expr);
+}
+
+
+void edit_y(struct expr **expr)
+{
+	edit_any_expr(status_entry_y, expr);
+}
+
+
 /* ----- text entry -------------------------------------------------------- */
 
 
 static gboolean changed(GtkWidget *widget, GdkEventMotion *event,
      gpointer data)
 {
-	if (edit_ops && edit_ops->changed)
-		edit_ops->changed(widget,
-		    gtk_entry_get_text(GTK_ENTRY(widget)), edit_ctx);
+	struct edit_ops *ops =
+	    gtk_object_get_data(GTK_OBJECT(widget), "edit-ops");
+	void *ctx = gtk_object_get_data(GTK_OBJECT(widget), "edit-ctx");
+
+	if (ops && ops->changed)
+		ops->changed(widget, gtk_entry_get_text(GTK_ENTRY(widget)),
+		    ctx);
 	return TRUE;
 }
 
@@ -354,9 +383,13 @@
 static gboolean activate(GtkWidget *widget, GdkEventMotion *event,
      gpointer data)
 {
-	if (edit_ops && edit_ops->activate)
-		if (edit_ops->activate(widget,
-		    gtk_entry_get_text(GTK_ENTRY(widget)), edit_ctx)) {
+	struct edit_ops *ops =
+	    gtk_object_get_data(GTK_OBJECT(widget), "edit-ops");
+	void *ctx = gtk_object_get_data(GTK_OBJECT(widget), "edit-ctx");
+
+	if (ops && ops->activate)
+		if (ops->activate(widget,
+		    gtk_entry_get_text(GTK_ENTRY(widget)), ctx)) {
 			inst_deselect();
 			change_world();
 		}
@@ -366,8 +399,9 @@
 
 void edit_nothing(void)
 {
-	edit_ops = NULL;
 	gtk_widget_hide(status_entry);
+	gtk_widget_hide(status_entry_x);
+	gtk_widget_hide(status_entry_y);
 }
 
 
@@ -418,54 +452,65 @@
 }
 
 
-void make_status_area(GtkWidget *vbox)
+static GtkWidget *add_entry(GtkWidget *tab, int col, int row)
 {
-	GtkWidget *tab, *hbox;
+	GtkWidget *entry;
 
-	tab = gtk_table_new(5, 2, FALSE);
-	gtk_box_pack_start(GTK_BOX(vbox), tab, FALSE, TRUE, 0);
+	entry = gtk_entry_new();
+	gtk_entry_set_has_frame(GTK_ENTRY(entry), FALSE);
+	gtk_table_attach_defaults(GTK_TABLE(tab), entry,
+	    col, col+1, row, row+1);
 
-	/* name and input */
+	g_signal_connect(G_OBJECT(entry), "changed",
+            G_CALLBACK(changed), entry);
+	g_signal_connect(G_OBJECT(entry), "activate",
+            G_CALLBACK(activate), entry);
 
-	status_name = add_label(tab, 0, 0);
+	return entry;
+}
 
-	/*
-	 * @@@ this should make the entry consume all available space. alas, it
-	 * doesn't work like that :-(
-	 */
-	hbox = gtk_hbox_new(TRUE, 0);
-	gtk_table_attach_defaults(GTK_TABLE(tab), hbox,
-	    0, 1, 1, 2);
-	
-	status_entry = gtk_entry_new();
-	gtk_box_pack_start(GTK_BOX(hbox), status_entry, TRUE, TRUE, 0);
 
-	gtk_entry_set_has_frame(GTK_ENTRY(status_entry), FALSE);
+void make_status_area(GtkWidget *vbox)
+{
+	GtkWidget *tab;
 
-	g_signal_connect(G_OBJECT(status_entry), "changed",
-            G_CALLBACK(changed), status_entry);
-	g_signal_connect(G_OBJECT(status_entry), "activate",
-            G_CALLBACK(activate), status_entry);
+	tab = gtk_table_new(6, 3, FALSE);
+	gtk_box_pack_start(GTK_BOX(vbox), tab, FALSE, TRUE, 0);
 
+	/* types */
+
+	status_type_x = add_label(tab, 0, 0);
+	status_type_y = add_label(tab, 0, 1);
+	status_type_entry = add_label(tab, 0, 2);
+
 	/* x / y */
 
 	status_x = add_label(tab, 1, 0);
+	status_entry_x = add_entry(tab, 2, 0);
 	status_y = add_label(tab, 1, 1);
+	status_entry_y = add_entry(tab, 2, 1);
 
-	/* r / angle */
+	/* name and input */
 
-	status_r = add_label(tab, 2, 0);
-	status_angle = add_label(tab, 2, 1);
+	status_name = add_label(tab, 1, 2);
+	status_entry = add_entry(tab, 2, 2);
 
 	/* sys / user pos */
 
-	status_sys_pos = add_label(tab, 3, 0);
-	status_user_pos = add_label(tab, 3, 1);
+	status_sys_x = add_label(tab, 3, 0);
+	status_sys_y = add_label(tab, 3, 1);
+	status_user_x = add_label(tab, 4, 0);
+	status_user_y = add_label(tab, 4, 1);
 
+	/* r / angle */
+
+	status_r = add_label(tab, 3, 2);
+	status_angle = add_label(tab, 4, 2);
+
 	/* zoom / grid */
 
-	status_zoom = add_label(tab, 4, 0);
-	status_grid = add_label(tab, 4, 1);
+	status_zoom = add_label(tab, 5, 0);
+	status_grid = add_label(tab, 5, 1);
 
 	/* message bar */
 

Modified: trunk/eda/fped/gui_status.h
===================================================================
--- trunk/eda/fped/gui_status.h	2009-08-03 23:23:00 UTC (rev 5380)
+++ trunk/eda/fped/gui_status.h	2009-08-04 00:23:10 UTC (rev 5381)
@@ -26,15 +26,22 @@
     void *ctx);
 void edit_name(char **s, int (*validate)(const char *s, void *ctx), void *ctx);
 void edit_expr(struct expr **expr);
+void edit_x(struct expr **expr);
+void edit_y(struct expr **expr);
 void edit_nothing(void);
 
+void status_set_type_x(const char *fmt, ...);
+void status_set_type_y(const char *fmt, ...);
+void status_set_type_entry(const char *fmt, ...);
 void status_set_name(const char *fmt, ...);
 void status_set_x(const char *fmt, ...);
 void status_set_y(const char *fmt, ...);
 void status_set_r(const char *fmt, ...);
 void status_set_angle(const char *fmt, ...);
-void status_set_sys_pos(const char *fmt, ...);
-void status_set_user_pos(const char *fmt, ...);
+void status_set_sys_x(const char *fmt, ...);
+void status_set_sys_y(const char *fmt, ...);
+void status_set_user_x(const char *fmt, ...);
+void status_set_user_y(const char *fmt, ...);
 void status_set_zoom(const char *fmt, ...);
 void status_set_grid(const char *fmt, ...);
 

Modified: trunk/eda/fped/inst.c
===================================================================
--- trunk/eda/fped/inst.c	2009-08-03 23:23:00 UTC (rev 5380)
+++ trunk/eda/fped/inst.c	2009-08-04 00:23:10 UTC (rev 5381)
@@ -173,6 +173,9 @@
 	if (selected_inst)
 		set_path(0);
 	deselect_outside();
+	status_set_type_x("");
+	status_set_type_y("");
+	status_set_type_entry("");
 	status_set_name("");
 	status_set_x("");
 	status_set_y("");
@@ -198,8 +201,10 @@
 		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)));
-	if (width != -1)
-		status_set_name("width = %5.2f mm", units_to_mm(width));
+	if (width != -1) {
+		status_set_type_entry("width =");
+		status_set_name("%5.2f mm", units_to_mm(width));
+	}
 }
 
 
@@ -280,9 +285,12 @@
 
 static void vec_op_select(struct inst *self)
 {
+	status_set_type_entry("ref =");
 	status_set_name(self->vec->name ? self->vec->name : "");
 	rect_status(self->base, self->u.rect.end, -1);
 	edit_unique_null(&self->vec->name, validate_vec_name, self->vec);
+	edit_x(&self->vec->x);
+	edit_y(&self->vec->y);
 }
 
 
@@ -414,6 +422,7 @@
 
 static void pad_op_select(struct inst *self)
 {
+	status_set_type_entry("label =");
 	status_set_name(self->u.name);
 	rect_status(self->bbox.min, self->bbox.max, -1);
 	edit_name(&self->obj->u.pad.name, validate_pad_name, NULL);
@@ -459,7 +468,8 @@
 	    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));
-	status_set_name("width = %5.2f mm", units_to_mm(self->u.arc.width));
+	status_set_type_entry("width =");
+	status_set_name("%5.2f mm", units_to_mm(self->u.arc.width));
 	edit_expr(&self->obj->u.arc.width);
 }
 
@@ -516,7 +526,8 @@
 static void meas_op_select(struct inst *self)
 {
 	rect_status(self->bbox.min, self->bbox.max, -1);
-	status_set_name("offset = %5.2f mm", units_to_mm(self->u.meas.offset));
+	status_set_type_entry("width =");
+	status_set_name("%5.2f mm", units_to_mm(self->u.meas.offset));
 	edit_expr(&self->obj->u.meas.offset);
 }
 




More information about the commitlog mailing list