r5522 - trunk/eda/fped

werner at docs.openmoko.org werner at docs.openmoko.org
Sat Aug 22 14:27:48 CEST 2009


Author: werner
Date: 2009-08-22 14:27:47 +0200 (Sat, 22 Aug 2009)
New Revision: 5522

Modified:
   trunk/eda/fped/TODO
   trunk/eda/fped/gui_canvas.c
   trunk/eda/fped/gui_tool.c
   trunk/eda/fped/inst.c
   trunk/eda/fped/inst.h
   trunk/eda/fped/postscript.c
Log:
Selection now tries to help us not to get lost.

- postscript.c: started adding generation of object-level frames (on-going)
- gui_canvas.c: moved call to inst_deselect into inst_select, so that 
  inst_select can keep track of the previous selection (if any)
- inst_select: if clicking on the location of the previous selection, try to 
  select the next matching item
- inst_select: if we can't find an active item, try to see if we can get
  something by changing active references or - if all else fails - by 
  activating a different frame
- end_new_frame: reset the tool after placing the frame



Modified: trunk/eda/fped/TODO
===================================================================
--- trunk/eda/fped/TODO	2009-08-22 11:02:30 UTC (rev 5521)
+++ trunk/eda/fped/TODO	2009-08-22 12:27:47 UTC (rev 5522)
@@ -36,6 +36,7 @@
 - whenever we call parse_* for input parsing, we may leak lots of expressions
 - can't edit measurement labels through the GUI
 - unbalanced parentheses in text throw off Postscript syntax
+- we can't drag points that are at a frame base
 
 Code cleanup:
 - merge edit_unique with edit_name

Modified: trunk/eda/fped/gui_canvas.c
===================================================================
--- trunk/eda/fped/gui_canvas.c	2009-08-22 11:02:30 UTC (rev 5521)
+++ trunk/eda/fped/gui_canvas.c	2009-08-22 12:27:47 UTC (rev 5522)
@@ -200,7 +200,6 @@
 			break;
 		}
 		prev = selected_inst;
-		inst_deselect();
 		inst_select(pos);
 		if (prev != selected_inst)
 			redraw();

Modified: trunk/eda/fped/gui_tool.c
===================================================================
--- trunk/eda/fped/gui_tool.c	2009-08-22 11:02:30 UTC (rev 5521)
+++ trunk/eda/fped/gui_tool.c	2009-08-22 12:27:47 UTC (rev 5522)
@@ -625,6 +625,7 @@
 		locked_frame->active_ref = obj;
 	locked_frame = NULL;
 	tool_frame_update();
+	tool_reset();
 	return 1;
 }
 

Modified: trunk/eda/fped/inst.c
===================================================================
--- trunk/eda/fped/inst.c	2009-08-22 11:02:30 UTC (rev 5521)
+++ trunk/eda/fped/inst.c	2009-08-22 12:27:47 UTC (rev 5522)
@@ -137,37 +137,88 @@
 }
 
 
+static int activate_item(struct inst *inst)
+{
+	if (!inst->outer)
+		return 0;
+	if (inst->outer->u.frame.ref->active_ref == inst->outer->obj)
+		return activate_item(inst->outer);
+	inst->outer->u.frame.ref->active_ref = inst->outer->obj;
+	activate_item(inst->outer);
+	return 1;
+}
+
+
 int inst_select(struct coord pos)
 {
 	enum inst_prio prio;
+	const struct inst *prev;
 	struct inst *inst;
+	struct inst *first = NULL;	/* first active item */
+	struct inst *next = NULL;	/* active item after currently sel. */
+	struct inst *any_first = NULL;	/* first item, active or inactive */
+	struct inst *any_same_frame = NULL; /* first item on active frame */
+	struct frame *frame;
 	int best_dist = 0; /* keep gcc happy */
+	int select_next;
 	int dist, i;
 
+	prev = selected_inst;
 	deselect_outside();
 	edit_nothing();
 	if (selected_inst) {
 		gui_frame_deselect_inst(selected_inst);
 		tool_selected_inst(NULL);
 	}
-	selected_inst = NULL;
+	inst_deselect();
+	select_next = 0;
 	FOR_INST_PRIOS_DOWN(prio) {
 		if (!show(prio))
 			continue;
 		FOR_ALL_INSTS(i, prio, inst) {
-			if (!inst->active || !inst->ops->distance)
+			if (!inst->ops->distance)
 				continue;
 			if (!inst_connected(inst))
 				continue;
 			dist = inst->ops->distance(inst, pos, draw_ctx.scale);
-			if (dist >= 0 && (!selected_inst || best_dist > dist)) {
-				selected_inst = inst;
-				best_dist = dist;
+			if (dist >= 0) {
+				if (!any_first)
+					any_first = inst;
+				if (!any_same_frame && inst->outer &&
+				    inst->outer->u.frame.ref == active_frame)
+					any_same_frame = inst;
+				if (!inst->active)
+					continue;
+				if (!first)
+					first = inst;
+				if (!next && select_next)
+					next = inst;
+				if (inst == prev)
+					select_next = 1;
+				if (!selected_inst || best_dist > dist) {
+					selected_inst = inst;
+					best_dist = dist;
+				}
 			}
 		}
+		if (select_next) {
+			selected_inst = next ? next : first;
+			goto selected;
+		}
 		if (selected_inst)
 			goto selected;
 	}
+	if (any_same_frame) {
+		if (activate_item(any_same_frame))
+			return inst_select(pos);
+	}
+	if (any_first) {
+		frame = any_first->outer ? any_first->outer->u.frame.ref : NULL;
+		if (frame != active_frame) {
+			select_frame(frame);
+			return inst_select(pos);
+		}
+	}
 
 	if (!show_stuff)
 		return 0;
@@ -958,7 +1009,7 @@
 };
 
 
-void inst_begin_frame(struct obj *obj, const struct frame *frame,
+void inst_begin_frame(struct obj *obj, struct frame *frame,
     struct coord base, int active, int is_active_frame)
 {
 	struct inst *inst;
@@ -1061,6 +1112,7 @@
 	pkgs = NULL;
 	inst_select_pkg(NULL);
 	curr_pkg = pkgs;
+	curr_frame = NULL;
 }
 
 

Modified: trunk/eda/fped/inst.h
===================================================================
--- trunk/eda/fped/inst.h	2009-08-22 11:02:30 UTC (rev 5521)
+++ trunk/eda/fped/inst.h	2009-08-22 12:27:47 UTC (rev 5522)
@@ -79,7 +79,7 @@
 	int active;
 	union {
 		struct {
-			const struct frame *ref;
+			struct frame *ref;
 			int active;
 		} frame;
 		const char *name;
@@ -172,7 +172,7 @@
 void inst_begin_active(int active);
 void inst_end_active(void);
 
-void inst_begin_frame(struct obj *obj, const struct frame *frame,
+void inst_begin_frame(struct obj *obj, struct frame *frame,
     struct coord base, int active, int is_active_frame);
 void inst_end_frame(const struct frame *frame);
 

Modified: trunk/eda/fped/postscript.c
===================================================================
--- trunk/eda/fped/postscript.c	2009-08-22 11:02:30 UTC (rev 5521)
+++ trunk/eda/fped/postscript.c	2009-08-22 12:27:47 UTC (rev 5522)
@@ -14,6 +14,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 
+#include "util.h"
 #include "coord.h"
 #include "inst.h"
 #include "gui_status.h"
@@ -77,6 +78,77 @@
 static struct postscript_params active_params;
 
 
+/* ----- Boxes ------------------------------------------------------------- */
+
+
+static struct box {
+	unit_type x, y;		/* width and height */
+	unit_type x0, y0;	/* lower left corner */
+	struct box *next;
+} *boxes = NULL;
+
+
+static void add_box(unit_type xa, unit_type ya, unit_type xb, unit_type yb)
+{
+	struct box *box;
+
+	box = alloc_type(struct box);
+	box->x = xb-xa;
+	box->y = yb-ya;
+	box->x0 = xa;
+	box->y0 = ya;
+	box->next = boxes;
+	boxes = box;
+}
+
+
+static void free_boxes(void)
+{
+	struct box *next;
+
+	while (boxes) {
+		next = boxes->next;
+		free(boxes);
+		boxes = next;
+	}
+}
+
+
+static int get_box(unit_type x, unit_type y, unit_type *xa, unit_type *ya)
+{
+	struct box **box, **best = NULL;
+	struct box *b;
+	double size, best_size;
+
+	for (box = &boxes; *box; box = &(*box)->next) {
+		if ((*box)->x < x || (*box)->y < y)
+			continue;
+		size = (double) (*box)->x*(*box)->y;
+		if (!best || size < best_size) {
+			best = box;
+			best_size = size;
+		}
+	}
+	if (!best)
+		return 0;
+	b = *best;
+	if (xa)
+		*xa = b->x0;
+	if (ya)
+		*ya = b->y0;
+
+	*best = b->next;
+	add_box(b->x0+x, b->y0, b->x0+b->x, b->y0+y);
+	add_box(b->x0, b->y0+y, b->x0+b->x, b->y0+b->y);
+	free(b);
+
+	return 1;
+}
+
+
+/* ----- Items ------------------------------------------------------------- */
+
+
 static void ps_pad_name(FILE *file, const struct inst *inst)
 {
 	struct coord a = inst->base;
@@ -261,6 +333,9 @@
 }
 
 
+/* ----- Print layers ------------------------------------------------------ */
+
+
 static void ps_background(FILE *file, enum inst_prio prio,
      const struct inst *inst)
 {
@@ -347,6 +422,31 @@
 }
 
 
+/* ----- Object frames ----------------------------------------------------- */
+
+
+static int generate_frames(FILE *file, const struct pkg *pkg,
+    const struct frame *frame, double zoom)
+{
+	const struct inst *inst;
+
+	while (frame) {
+		if (frame->name)
+			for (inst = pkg->insts[ip_frame]; inst;
+			    inst = inst->next)
+				if (inst->u.frame.ref == frame)
+					goto found_frame;
+		frame = frame->next;
+	}
+	if (!frame)
+		return 1;
+
+found_frame:
+	/* @@@ */
+	return 0;
+}
+
+
 /* ----- Page level -------------------------------------------------------- */
 
 
@@ -372,7 +472,6 @@
 }
 
 
-
 static void ps_page(FILE *file, int page)
 {
 	fprintf(file, "%%%%Page: %d %d\n", page, page);
@@ -396,6 +495,7 @@
 	unit_type w, h;
 	double f;
 	unit_type c, d;
+	int done;
 
 	ps_page(file, page);
 	ps_header(file, pkg);
@@ -480,6 +580,15 @@
 	 * Put the frames
 	 */
 
+	for (f = 20; f >= 0.1; f = f > 1 ? f-1 : f-0.1) {
+		add_box(-PAGE_HALF_WIDTH, -PAGE_HALF_HEIGHT, PAGE_HALF_WIDTH,
+		    -PS_DIVIDER_BORDER);
+		done = generate_frames(file, pkg, frames, f);
+		free_boxes();
+		if (done)
+			break;
+	}
+
 	fprintf(file, "showpage\n");
 }
 
@@ -589,7 +698,7 @@
 	 * Stack: string -> string
 	 */
 
-fprintf(file,
+	fprintf(file,
 "/debugbox { gsave dup false charpath flattenpath pathbbox\n"
 "    /ury exch def /urx exch def /lly exch def /llx exch def\n"
 "    0 setgray 100 setlinewidth\n"
@@ -599,7 +708,7 @@
 	 * Stack: int -> int
 	 */
 
-fprintf(file,
+	fprintf(file,
 "/realsize {\n"
 "    254 div 72 mul 1000 div 0 matrix currentmatrix idtransform pop\n"
 "    } def\n");




More information about the commitlog mailing list