r5342 - developers/werner/fped

werner at docs.openmoko.org werner at docs.openmoko.org
Thu Jul 30 22:24:38 CEST 2009


Author: werner
Date: 2009-07-30 22:24:37 +0200 (Thu, 30 Jul 2009)
New Revision: 5342

Modified:
   developers/werner/fped/TODO
   developers/werner/fped/coord.c
   developers/werner/fped/gui.c
   developers/werner/fped/gui_canvas.c
   developers/werner/fped/gui_canvas.h
   developers/werner/fped/gui_status.c
   developers/werner/fped/gui_status.h
   developers/werner/fped/gui_style.c
   developers/werner/fped/inst.c
   developers/werner/fped/inst.h
   developers/werner/fped/obj.c
   developers/werner/fped/obj.h
Log:
- added commit/revert logic for instantiation
- obj.c: renamed "res" to more specific "ok"
- display parameters of selected object
- converted frame list from GtkTreeView to GtkScrolledWindow with vbox
- corrected logic of setting an instance active
- adjusted colors for better contrast
- implemented frame selection (on-going)



Modified: developers/werner/fped/TODO
===================================================================
--- developers/werner/fped/TODO	2009-07-30 14:11:24 UTC (rev 5341)
+++ developers/werner/fped/TODO	2009-07-30 20:24:37 UTC (rev 5342)
@@ -2,7 +2,7 @@
 - add table/var/loop representation
 - Q: should loop be (start, last) or (start, iterations) ?
 - add row selection
-- change vector circle color (also, highlight on hover ?)
+- change vector circle color ? (also, highlight on hover ?)
 - stack elements (1): frames, pads, silk, vecs
 - stack elements (2): all unselected below all selected
 - stack elements (3): circle on top of vec
@@ -26,3 +26,5 @@
 - Q: how do we handle stacks of objects ?
 - consider using cairo instead of gdk
 - Q: add frame arguments ? (e.g., .frame pad(pin_num_offset) ...)
+- Q: should we make it a requirement to generate objects only once ?
+- convert status display to table

Modified: developers/werner/fped/coord.c
===================================================================
--- developers/werner/fped/coord.c	2009-07-30 14:11:24 UTC (rev 5341)
+++ developers/werner/fped/coord.c	2009-07-30 20:24:37 UTC (rev 5342)
@@ -87,7 +87,7 @@
 	return hypot(a.x-b.x, a.y-b.y);
 }
 
-#include <stdio.h>
+
 static unit_type dist_line_xy(unit_type px, unit_type py,
     unit_type ax, unit_type ay, unit_type bx, unit_type by)
 {
@@ -101,7 +101,7 @@
 	if (ax != bx || ay != by) {
 		/*
 		 * We make a the line vector from point B and b the vector from
-		 * B to point P. The we calculate the projection of b on a.
+		 * B to point P. Then we calculate the projection of b on a.
 		 */
 		ax -= bx;
 		ay -= by;

Modified: developers/werner/fped/gui.c
===================================================================
--- developers/werner/fped/gui.c	2009-07-30 14:11:24 UTC (rev 5341)
+++ developers/werner/fped/gui.c	2009-07-30 20:24:37 UTC (rev 5342)
@@ -15,6 +15,7 @@
 #include <math.h>
 #include <gtk/gtk.h>
 
+#include "inst.h"
 #include "obj.h"
 #include "unparse.h"
 #include "gui_util.h"
@@ -28,6 +29,8 @@
 static GtkWidget *vars_box;
 
 
+static void build_vars(GtkWidget *vbox, struct frame *frame);
+
 static void make_menu_bar(GtkWidget *vbox)
 {
 	GtkWidget *bar;
@@ -50,28 +53,33 @@
 }
 
 
-static void add_frame(GtkListStore  *list, const char *name)
+static gboolean frame_select_event(GtkWidget *widget, GdkEventButton *event,
+     gpointer data)
 {
-	GtkTreeIter iter;
-
-	gtk_list_store_append(list, &iter);
-	gtk_list_store_set(list, &iter, 0, name, -1);
+	inst_deselect();
+	active_frame = data;
+	instantiate();
+	build_vars(vars_box, active_frame);
+	redraw();
+	return TRUE;
 }
 
 
-static void show_frames(GtkWidget *frame_list)
+static void show_frames(GtkWidget *vbox)
 {
-	GtkListStore *list;
 	struct frame *f;
+	GtkWidget *label;
 
-	list = gtk_list_store_new(1, G_TYPE_STRING);
+	for (f = frames; f; f = f->next) {
+		label = label_in_box_new(f->name ? f->name : "(root)");
+		gtk_box_pack_start(GTK_BOX(vbox), box_of_label(label),
+		    FALSE, TRUE, 0);
+		gtk_misc_set_padding(GTK_MISC(label), 2, 2);
+		gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
 
-	for (f = frames; f; f = f->next)
-		add_frame(list, f->name ? f->name : "(root)");
-
-	gtk_tree_view_set_model(GTK_TREE_VIEW(frame_list),
-	    GTK_TREE_MODEL(list));
-	g_object_unref(list);
+		g_signal_connect(G_OBJECT(box_of_label(label)),
+		    "button_press_event", G_CALLBACK(frame_select_event), f);
+	}
 }
 
 
@@ -208,22 +216,23 @@
 {
 	GtkWidget *hbox, *vars, *paned;
 	GtkWidget *frame_list;
-	GtkTreeSelection *sel;
+	GtkWidget *v2box;
 
 	hbox = gtk_hbox_new(FALSE, 0);
 	gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
 
 	/* Frame list */
 
-	frame_list = gtk_tree_view_new();
+	frame_list = gtk_scrolled_window_new(NULL, NULL);
 	gtk_box_pack_start(GTK_BOX(hbox), frame_list, FALSE, TRUE, 0);
+	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(frame_list),
+	    GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
 
-	sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(frame_list));
-	gtk_tree_selection_set_mode(sel, GTK_SELECTION_BROWSE);
-	gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(frame_list),
-	    -1, "Frame", gtk_cell_renderer_text_new(), "text", 0, NULL);
+	v2box = gtk_vbox_new(FALSE, 0);
+	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(frame_list),
+	    v2box);
 
-	show_frames(frame_list);
+	show_frames(v2box);
 
 	add_sep(hbox, 2);
 
@@ -286,7 +295,6 @@
 
 	gtk_widget_show_all(root);
 
-
 	gtk_main();
 
 	return 0;

Modified: developers/werner/fped/gui_canvas.c
===================================================================
--- developers/werner/fped/gui_canvas.c	2009-07-30 14:11:24 UTC (rev 5341)
+++ developers/werner/fped/gui_canvas.c	2009-07-30 20:24:37 UTC (rev 5342)
@@ -88,7 +88,7 @@
 /* ----- drawing ----------------------------------------------------------- */
 
 
-static void redraw(void)
+void redraw(void)
 {
 	float aw, ah;
 

Modified: developers/werner/fped/gui_canvas.h
===================================================================
--- developers/werner/fped/gui_canvas.h	2009-07-30 14:11:24 UTC (rev 5341)
+++ developers/werner/fped/gui_canvas.h	2009-07-30 20:24:37 UTC (rev 5342)
@@ -17,6 +17,8 @@
 #include <gtk/gtk.h>
 
 
+void redraw(void);
+
 GtkWidget *make_canvas(void);
 
 #endif /* !GUI_CANVAS_H */

Modified: developers/werner/fped/gui_status.c
===================================================================
--- developers/werner/fped/gui_status.c	2009-07-30 14:11:24 UTC (rev 5341)
+++ developers/werner/fped/gui_status.c	2009-07-30 20:24:37 UTC (rev 5342)
@@ -15,6 +15,7 @@
 #include <stdio.h>
 #include <gtk/gtk.h>
 
+#include "coord.h"
 #include "gui_util.h"
 #include "gui_status.h"
 
@@ -57,6 +58,18 @@
 SETTER(grid)
 
 
+/* ----- complex status updates -------------------------------------------- */
+
+
+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));
+}
+
+
+/* ----- setup ------------------------------------------------------------- */
+
 void make_status_area(GtkWidget *vbox)
 {
 	GtkWidget *hbox, *v2box;

Modified: developers/werner/fped/gui_status.h
===================================================================
--- developers/werner/fped/gui_status.h	2009-07-30 14:11:24 UTC (rev 5341)
+++ developers/werner/fped/gui_status.h	2009-07-30 20:24:37 UTC (rev 5342)
@@ -14,6 +14,8 @@
 #ifndef GUI_STATUS_H
 #define GUI_STATUS_H
 
+#include "coord.h"
+
 #include <gtk/gtk.h>
 
 
@@ -27,6 +29,8 @@
 void status_set_zoom(const char *fmt, ...);
 void status_set_grid(const char *fmt, ...);
 
+void status_set_xy(struct coord coord);
+
 void make_status_area(GtkWidget *vbox) ;
 
 #endif /* !GUI_STATUS_H */

Modified: developers/werner/fped/gui_style.c
===================================================================
--- developers/werner/fped/gui_style.c	2009-07-30 14:11:24 UTC (rev 5341)
+++ developers/werner/fped/gui_style.c	2009-07-30 20:24:37 UTC (rev 5342)
@@ -52,7 +52,7 @@
 	gc_bg = gc("#000000", 0);
 	/*		inactive   in+path    active     act+path   selected */
 	style(gc_vec,	"#202000", "#404020", "#808040", "#c0c080", "#ffff80");
-	style(gc_obj,	"#003030", INVALID,   "#00e0e0", INVALID,   "#ffff80");
-	style(gc_pad,	"#300000", INVALID,   "#ff0000", INVALID,   "#ffff80");
-	style(gc_frame,	"#003000", "#205020", "#00ff00", INVALID,   INVALID);
+	style(gc_obj,	"#006060", INVALID,   "#00ffff", INVALID,   "#ffff80");
+	style(gc_pad,	"#400000", INVALID,   "#ff0000", INVALID,   "#ffff80");
+	style(gc_frame,	"#004000", "#205020", "#00ff00", INVALID,   INVALID);
 }

Modified: developers/werner/fped/inst.c
===================================================================
--- developers/werner/fped/inst.c	2009-07-30 14:11:24 UTC (rev 5341)
+++ developers/werner/fped/inst.c	2009-07-30 20:24:37 UTC (rev 5342)
@@ -18,17 +18,23 @@
 #include "util.h"
 #include "coord.h"
 #include "obj.h"
+#include "gui_status.h"
 #include "gui_inst.h"
 #include "inst.h"
 
 
-static struct inst *insts = NULL, **next_inst;
 struct inst *curr_frame = NULL;
 struct inst *selected_inst = NULL;
 
-static int active = 0;
+static struct inst *insts = NULL, **next_inst;
+static struct inst *prev_insts;
 
+static unsigned long active_set = 0;
 
+
+#define	IS_ACTIVE	((active_set & 1))
+
+
 /* ----- selection --------------------------------------------------------- */
 
 
@@ -84,6 +90,24 @@
 }
 
 
+static void rect_status(struct coord a, struct coord b)
+{
+	struct coord d = sub_vec(b, a);
+	double angle;
+	
+	status_set_xy(d);
+	if (!d.x && !d.y)
+		status_set_angle("a = 0 deg");
+	else {
+		angle = atan2(d.y, d.x)/M_PI*180.0;
+		if (angle < 0)
+			angle += 360;
+		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)));
+}
+
+
 /* ----- helper functions for instance creation ---------------------------- */
 
 
@@ -114,7 +138,7 @@
 	inst->ops = ops;
 	inst->base = inst->bbox.min = inst->bbox.max = base;
 	inst->outer = curr_frame;
-	inst->active = active;
+	inst->active = IS_ACTIVE;
 	inst->in_path = 0;
 	inst->next = NULL;
 	*next_inst = inst;
@@ -134,10 +158,18 @@
 }
 
 
+static void vec_op_select(struct inst *self)
+{
+	status_set_name(self->vec->name ? self->vec->name : "");
+	rect_status(self->base, self->u.end);
+}
+
+
 static struct inst_ops vec_ops = {
 	.debug		= vec_op_debug,
 	.draw		= gui_draw_vec,
 	.distance	= gui_dist_vec,
+	.select		= vec_op_select,
 };
 
 
@@ -165,10 +197,17 @@
 }
 
 
+static void line_op_select(struct inst *self)
+{
+	rect_status(self->bbox.min, self->bbox.max);
+}
+
+
 static struct inst_ops line_ops = {
 	.debug		= line_op_debug,
 	.draw		= gui_draw_line,
 	.distance	= gui_dist_line,
+	.select		= line_op_select,
 };
 
 
@@ -196,10 +235,17 @@
 }
 
 
+static void rect_op_select(struct inst *self)
+{
+	rect_status(self->bbox.min, self->bbox.max);
+}
+
+
 static struct inst_ops rect_ops = {
 	.debug		= rect_op_debug,
 	.draw		= gui_draw_rect,
 	.distance	= gui_dist_rect,
+	.select		= rect_op_select,
 };
 
 
@@ -227,10 +273,18 @@
 }
 
 
+static void pad_op_select(struct inst *self)
+{
+	status_set_name(self->u.name);
+	rect_status(self->bbox.min, self->bbox.max);
+}
+
+
 static struct inst_ops pad_ops = {
 	.debug		= pad_op_debug,
 	.draw		= gui_draw_pad,
 	.distance	= gui_dist_pad,
+	.select		= pad_op_select,
 };
 
 
@@ -258,10 +312,21 @@
 }
 
 
+static void arc_op_select(struct inst *self)
+{
+	status_set_xy(self->base);
+	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));
+}
+
+
 static struct inst_ops arc_ops = {
 	.debug		= arc_op_debug,
 	.draw		= gui_draw_arc,
 	.distance	= gui_dist_arc,
+	.select		= arc_op_select,
 };
 
 
@@ -295,15 +360,15 @@
 /* ----- active instance --------------------------------------------------- */
 
 
-void inst_begin_active(void)
+void inst_begin_active(int active)
 {
-	active = 1;
+	active_set = (active_set << 1) | active;
 }
 
 
 void inst_end_active(void)
 {
-	active = 0;
+	active_set >>= 1;
 }
 
 
@@ -324,12 +389,13 @@
 };
 
 
-void inst_begin_frame(const struct frame *frame, struct coord base)
+void inst_begin_frame(const struct frame *frame, struct coord base, int active)
 {
 	struct inst *inst;
 
 	inst = add_inst(&frame_ops, base);
 	inst->u.frame.ref = frame;
+	inst->active = active;
 	curr_frame = inst;
 }
 
@@ -355,25 +421,39 @@
 }
 
 
-static void inst_free(void)
+static void inst_free(struct inst *list)
 {
 	struct inst *next;
 
-	while (insts) {
-		next = insts->next;
-		free(insts);
-		insts = next;
+	while (list) {
+		next = list->next;
+		free(list);
+		list = next;
 	}
+}
+
+
+void inst_start(void)
+{
+	prev_insts = insts;
+	insts = NULL;
 	next_inst = &insts;
 }
 
 
-void inst_reset(void)
+void inst_commit(void)
 {
-	inst_free();
+	inst_free(prev_insts);
 }
 
 
+void inst_revert(void)
+{
+	inst_free(insts);
+	insts = prev_insts;
+}
+
+
 void inst_draw(struct draw_ctx *ctx)
 {
 	struct inst *walk;

Modified: developers/werner/fped/inst.h
===================================================================
--- developers/werner/fped/inst.h	2009-07-30 14:11:24 UTC (rev 5341)
+++ developers/werner/fped/inst.h	2009-07-30 20:24:37 UTC (rev 5342)
@@ -84,15 +84,18 @@
 int inst_arc(struct obj *obj, struct coord center, struct coord start,
     struct coord stop);
 
-void inst_begin_active(void);
+void inst_begin_active(int active);
 void inst_end_active(void);
 
-void inst_begin_frame(const struct frame *frame, struct coord base); 
+void inst_begin_frame(const struct frame *frame, struct coord base, int active);
 void inst_end_frame(const struct frame *frame);
 
 struct bbox inst_get_bbox(void);
 
-void inst_reset(void);
+void inst_start(void);
+void inst_commit(void);
+void inst_revert(void);
+
 void inst_draw(struct draw_ctx *ctx);
 void inst_debug(void);
 

Modified: developers/werner/fped/obj.c
===================================================================
--- developers/werner/fped/obj.c	2009-07-30 14:11:24 UTC (rev 5341)
+++ developers/werner/fped/obj.c	2009-07-30 20:24:37 UTC (rev 5342)
@@ -23,10 +23,9 @@
 
 #define	MAX_ITERATIONS	1000	/* abort "loop"s at this limit */
 
-#define active_frame frames
 
-
 struct frame *frames = NULL;
+struct frame *active_frame = NULL;
 
 
 static int generate_frame(struct frame *frame, struct coord base,
@@ -138,7 +137,7 @@
 {
 	struct obj *obj;
 	char *name;
-	int res;
+	int ok;
 
 	for (obj = frame->objs; obj; obj = obj->next)
 		switch (obj->type) {
@@ -161,11 +160,11 @@
 			name = expand(obj->u.pad.name, frame);
 			if (!name)
 				return 0;
-			res = inst_pad(obj, name,
+			ok = inst_pad(obj, name,
 			    obj->base ? obj->base->pos : base,
 			    obj->u.pad.other ? obj->u.pad.other->pos : base);
 			free(name);
-			if (!res)
+			if (!ok)
 				return 0;
 			break;
 		case ot_arc:
@@ -183,14 +182,12 @@
 
 static int generate_items(struct frame *frame, struct coord base, int active)
 {
-	int res;
+	int ok;
 
-	if (active)
-		inst_begin_active();
-	res = generate_vecs(frame, base) && generate_objs(frame, base);
-	if (active)
-		inst_end_active();
-	return res;
+	inst_begin_active(active);
+	ok = generate_vecs(frame, base) && generate_objs(frame, base);
+	inst_end_active();
+	return ok;
 }
 
 
@@ -261,23 +258,29 @@
 static int generate_frame(struct frame *frame, struct coord base,
     const struct frame *parent)
 {
-	int res;
+	int ok;
 
 	/*
 	 * We ensure during construction that frames can never recurse.
 	 */
-	inst_begin_frame(frame, base);
+	inst_begin_frame(frame, base, frame == active_frame);
 	frame->curr_parent = parent;
-	res = iterate_tables(frame, frame->tables, base, frame == active_frame);
+	ok = iterate_tables(frame, frame->tables, base, frame == active_frame);
 	inst_end_frame(frame);
-	return res;
+	return ok;
 }
 
 
 int instantiate(void)
 {
 	struct coord zero = { 0, 0 };
+	int ok;
 
-	inst_reset();
-	return generate_frame(frames, zero, NULL);
+	inst_start();
+	ok = generate_frame(frames, zero, NULL);
+	if (ok)
+		inst_commit();
+	else
+		inst_revert();
+	return ok;
 }

Modified: developers/werner/fped/obj.h
===================================================================
--- developers/werner/fped/obj.h	2009-07-30 14:11:24 UTC (rev 5341)
+++ developers/werner/fped/obj.h	2009-07-30 20:24:37 UTC (rev 5342)
@@ -119,6 +119,7 @@
 
 
 struct frame *frames;
+struct frame *active_frame;
 
 
 int instantiate(void);




More information about the commitlog mailing list