r5378 - trunk/eda/fped

werner at docs.openmoko.org werner at docs.openmoko.org
Mon Aug 3 23:52:21 CEST 2009


Author: werner
Date: 2009-08-03 23:52:21 +0200 (Mon, 03 Aug 2009)
New Revision: 5378

Modified:
   trunk/eda/fped/README
   trunk/eda/fped/gui_canvas.c
   trunk/eda/fped/gui_status.c
   trunk/eda/fped/inst.c
   trunk/eda/fped/inst.h
Log:
- don't crash when editing a NULL expression (e.g., default width)
- bounding boxes of silk objects now include the width
- # zooms and centers to currently active frame instance



Modified: trunk/eda/fped/README
===================================================================
--- trunk/eda/fped/README	2009-08-03 21:10:49 UTC (rev 5377)
+++ trunk/eda/fped/README	2009-08-03 21:52:21 UTC (rev 5378)
@@ -349,3 +349,4 @@
 -	zoom out (like mouse wheel backward)
 .	cursor position to screen center (like middle click)
 *	zoom and center to extents
+#	zoom and center to currently active frame instance

Modified: trunk/eda/fped/gui_canvas.c
===================================================================
--- trunk/eda/fped/gui_canvas.c	2009-08-03 21:10:49 UTC (rev 5377)
+++ trunk/eda/fped/gui_canvas.c	2009-08-03 21:52:21 UTC (rev 5378)
@@ -49,24 +49,24 @@
 /* ----- coordinate system ------------------------------------------------- */
 
 
-static void center(void)
+static void center(const struct bbox *this_bbox)
 {
 	struct bbox bbox;
 
-	bbox = inst_get_bbox();
+	bbox = this_bbox ? *this_bbox : inst_get_bbox();
 	ctx.center.x = (bbox.min.x+bbox.max.x)/2;
 	ctx.center.y = (bbox.min.y+bbox.max.y)/2;
 }
 
 
-static void auto_scale(void)
+static void auto_scale(const struct bbox *this_bbox)
 {
 	struct bbox bbox;
 	unit_type h, w;
 	int sx, sy;
 	float aw, ah;
 
-	bbox = inst_get_bbox();
+	bbox = this_bbox ? *this_bbox : inst_get_bbox();
 	aw = ctx.widget->allocation.width;
 	ah = ctx.widget->allocation.height;
 	h = bbox.max.x-bbox.min.x;
@@ -236,9 +236,15 @@
 		zoom_out(pos);
 		break;
 	case '*':
-		center();
-		auto_scale();
+		center(NULL);
+		auto_scale(NULL);
 		redraw();
+		break;
+	case '#':
+		center(&active_frame_bbox);
+		auto_scale(&active_frame_bbox);
+		redraw();
+		break;
 	case '.':
 		ctx.center = pos;
 		redraw();
@@ -293,8 +299,8 @@
 
 void init_canvas(void)
 {
-	center();
-	auto_scale();
+	center(NULL);
+	auto_scale(NULL);
 }
 
 

Modified: trunk/eda/fped/gui_status.c
===================================================================
--- trunk/eda/fped/gui_status.c	2009-08-03 21:10:49 UTC (rev 5377)
+++ trunk/eda/fped/gui_status.c	2009-08-03 21:52:21 UTC (rev 5378)
@@ -310,7 +310,8 @@
 	expr = try_parse_expr(s);
 	if (!expr)
 		return 0;
-	free_expr(*anchor);
+	if (*anchor)
+		free_expr(*anchor);
 	*anchor = expr;
 	entry_color(COLOR_EDIT_ASIS);
 	return 1;

Modified: trunk/eda/fped/inst.c
===================================================================
--- trunk/eda/fped/inst.c	2009-08-03 21:10:49 UTC (rev 5377)
+++ trunk/eda/fped/inst.c	2009-08-03 21:52:21 UTC (rev 5378)
@@ -62,6 +62,7 @@
 
 
 struct inst *selected_inst = NULL;
+struct bbox active_frame_bbox;
 
 static struct inst *curr_frame = NULL;
 static struct inst *insts[ip_n], **next_inst[ip_n];
@@ -224,6 +225,16 @@
 	update_bbox(&curr_frame->bbox, inst->bbox.max);
 }
 
+
+static void grow_bbox_by_width(struct bbox *bbox, unit_type width)
+{
+	bbox->min.x -= width/2;
+	bbox->min.y -= width/2;
+	bbox->max.x += width/2;
+	bbox->max.y += width/2;
+}
+
+
 static struct inst *add_inst(const struct inst_ops *ops, enum inst_prio prio,
     struct coord base)
 {
@@ -331,6 +342,7 @@
 	inst->u.rect.end = b;
 	inst->u.rect.width = width;
 	update_bbox(&inst->bbox, b);
+	grow_bbox_by_width(&inst->bbox, width);
 	propagate_bbox(inst);
 	return 1;
 }
@@ -371,6 +383,7 @@
 	inst->u.rect.end = b;
 	inst->u.rect.width = width;
 	update_bbox(&inst->bbox, b);
+	grow_bbox_by_width(&inst->bbox, width);
 	propagate_bbox(inst);
 	return 1;
 }
@@ -482,6 +495,7 @@
 	inst->bbox.max.x = center.x+r;
 	inst->bbox.min.y = center.y-r;
 	inst->bbox.max.y = center.y+r;
+	grow_bbox_by_width(&inst->bbox, width);
 	propagate_bbox(inst);
 	return 1;
 }
@@ -581,6 +595,8 @@
 	curr_frame = curr_frame->outer;
 	if (curr_frame)
 		propagate_bbox(inst);
+	if (inst->active && frame == active_frame)
+		active_frame_bbox = inst->bbox;
 }
 
 
@@ -609,8 +625,10 @@
 
 void inst_start(void)
 {
+	static struct bbox bbox_zero = { { 0, 0 }, { 0, 0 }};
 	enum inst_prio prio;
 
+	active_frame_bbox = bbox_zero;
 	FOR_INST_PRIOS_UP(prio) {
 		prev_insts[prio] = insts[prio];
 		insts[prio] = NULL;

Modified: trunk/eda/fped/inst.h
===================================================================
--- trunk/eda/fped/inst.h	2009-08-03 21:10:49 UTC (rev 5377)
+++ trunk/eda/fped/inst.h	2009-08-03 21:52:21 UTC (rev 5378)
@@ -71,6 +71,7 @@
 
 
 extern struct inst *selected_inst;
+extern struct bbox active_frame_bbox;
 
 
 void inst_select_outside(void *item, void (*deselect)(void *item));




More information about the commitlog mailing list