mirror of
git://projects.qi-hardware.com/fped.git
synced 2024-11-22 18:56:15 +02:00
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 git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5522 99fdad57-331a-0410-800a-d7fa5415bdb3
This commit is contained in:
parent
9e48901814
commit
a44530f621
1
TODO
1
TODO
@ -36,6 +36,7 @@ Bugs:
|
|||||||
- whenever we call parse_* for input parsing, we may leak lots of expressions
|
- whenever we call parse_* for input parsing, we may leak lots of expressions
|
||||||
- can't edit measurement labels through the GUI
|
- can't edit measurement labels through the GUI
|
||||||
- unbalanced parentheses in text throw off Postscript syntax
|
- unbalanced parentheses in text throw off Postscript syntax
|
||||||
|
- we can't drag points that are at a frame base
|
||||||
|
|
||||||
Code cleanup:
|
Code cleanup:
|
||||||
- merge edit_unique with edit_name
|
- merge edit_unique with edit_name
|
||||||
|
@ -200,7 +200,6 @@ static gboolean button_press_event(GtkWidget *widget, GdkEventButton *event,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
prev = selected_inst;
|
prev = selected_inst;
|
||||||
inst_deselect();
|
|
||||||
inst_select(pos);
|
inst_select(pos);
|
||||||
if (prev != selected_inst)
|
if (prev != selected_inst)
|
||||||
redraw();
|
redraw();
|
||||||
|
@ -625,6 +625,7 @@ static int end_new_frame(struct inst *from, struct inst *to)
|
|||||||
locked_frame->active_ref = obj;
|
locked_frame->active_ref = obj;
|
||||||
locked_frame = NULL;
|
locked_frame = NULL;
|
||||||
tool_frame_update();
|
tool_frame_update();
|
||||||
|
tool_reset();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
60
inst.c
60
inst.c
@ -137,37 +137,88 @@ static void inst_select_inst(struct inst *inst)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
int inst_select(struct coord pos)
|
||||||
{
|
{
|
||||||
enum inst_prio prio;
|
enum inst_prio prio;
|
||||||
|
const struct inst *prev;
|
||||||
struct inst *inst;
|
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 best_dist = 0; /* keep gcc happy */
|
||||||
|
int select_next;
|
||||||
int dist, i;
|
int dist, i;
|
||||||
|
|
||||||
|
prev = selected_inst;
|
||||||
deselect_outside();
|
deselect_outside();
|
||||||
edit_nothing();
|
edit_nothing();
|
||||||
if (selected_inst) {
|
if (selected_inst) {
|
||||||
gui_frame_deselect_inst(selected_inst);
|
gui_frame_deselect_inst(selected_inst);
|
||||||
tool_selected_inst(NULL);
|
tool_selected_inst(NULL);
|
||||||
}
|
}
|
||||||
selected_inst = NULL;
|
inst_deselect();
|
||||||
|
select_next = 0;
|
||||||
FOR_INST_PRIOS_DOWN(prio) {
|
FOR_INST_PRIOS_DOWN(prio) {
|
||||||
if (!show(prio))
|
if (!show(prio))
|
||||||
continue;
|
continue;
|
||||||
FOR_ALL_INSTS(i, prio, inst) {
|
FOR_ALL_INSTS(i, prio, inst) {
|
||||||
if (!inst->active || !inst->ops->distance)
|
if (!inst->ops->distance)
|
||||||
continue;
|
continue;
|
||||||
if (!inst_connected(inst))
|
if (!inst_connected(inst))
|
||||||
continue;
|
continue;
|
||||||
dist = inst->ops->distance(inst, pos, draw_ctx.scale);
|
dist = inst->ops->distance(inst, pos, draw_ctx.scale);
|
||||||
if (dist >= 0 && (!selected_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;
|
selected_inst = inst;
|
||||||
best_dist = dist;
|
best_dist = dist;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (select_next) {
|
||||||
|
selected_inst = next ? next : first;
|
||||||
|
goto selected;
|
||||||
|
}
|
||||||
if (selected_inst)
|
if (selected_inst)
|
||||||
goto selected;
|
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)
|
if (!show_stuff)
|
||||||
return 0;
|
return 0;
|
||||||
@ -958,7 +1009,7 @@ static struct inst_ops frame_ops = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
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 coord base, int active, int is_active_frame)
|
||||||
{
|
{
|
||||||
struct inst *inst;
|
struct inst *inst;
|
||||||
@ -1061,6 +1112,7 @@ void inst_start(void)
|
|||||||
pkgs = NULL;
|
pkgs = NULL;
|
||||||
inst_select_pkg(NULL);
|
inst_select_pkg(NULL);
|
||||||
curr_pkg = pkgs;
|
curr_pkg = pkgs;
|
||||||
|
curr_frame = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
4
inst.h
4
inst.h
@ -79,7 +79,7 @@ struct inst {
|
|||||||
int active;
|
int active;
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
const struct frame *ref;
|
struct frame *ref;
|
||||||
int active;
|
int active;
|
||||||
} frame;
|
} frame;
|
||||||
const char *name;
|
const char *name;
|
||||||
@ -172,7 +172,7 @@ void inst_meas_hint(struct obj *obj, unit_type offset);
|
|||||||
void inst_begin_active(int active);
|
void inst_begin_active(int active);
|
||||||
void inst_end_active(void);
|
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);
|
struct coord base, int active, int is_active_frame);
|
||||||
void inst_end_frame(const struct frame *frame);
|
void inst_end_frame(const struct frame *frame);
|
||||||
|
|
||||||
|
115
postscript.c
115
postscript.c
@ -14,6 +14,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
#include "coord.h"
|
#include "coord.h"
|
||||||
#include "inst.h"
|
#include "inst.h"
|
||||||
#include "gui_status.h"
|
#include "gui_status.h"
|
||||||
@ -77,6 +78,77 @@ static const struct postscript_params minimal_params;
|
|||||||
static struct postscript_params active_params;
|
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)
|
static void ps_pad_name(FILE *file, const struct inst *inst)
|
||||||
{
|
{
|
||||||
struct coord a = inst->base;
|
struct coord a = inst->base;
|
||||||
@ -261,6 +333,9 @@ static void ps_meas(FILE *file, const struct inst *inst,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ----- Print layers ------------------------------------------------------ */
|
||||||
|
|
||||||
|
|
||||||
static void ps_background(FILE *file, enum inst_prio prio,
|
static void ps_background(FILE *file, enum inst_prio prio,
|
||||||
const struct inst *inst)
|
const struct inst *inst)
|
||||||
{
|
{
|
||||||
@ -347,6 +422,31 @@ static void ps_draw_package(FILE *file, const struct pkg *pkg, double zoom)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ----- 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 -------------------------------------------------------- */
|
/* ----- Page level -------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
@ -372,7 +472,6 @@ static void ps_header(FILE *file, const struct pkg *pkg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void ps_page(FILE *file, int page)
|
static void ps_page(FILE *file, int page)
|
||||||
{
|
{
|
||||||
fprintf(file, "%%%%Page: %d %d\n", page, page);
|
fprintf(file, "%%%%Page: %d %d\n", page, page);
|
||||||
@ -396,6 +495,7 @@ static void ps_package(FILE *file, const struct pkg *pkg, int page)
|
|||||||
unit_type w, h;
|
unit_type w, h;
|
||||||
double f;
|
double f;
|
||||||
unit_type c, d;
|
unit_type c, d;
|
||||||
|
int done;
|
||||||
|
|
||||||
ps_page(file, page);
|
ps_page(file, page);
|
||||||
ps_header(file, pkg);
|
ps_header(file, pkg);
|
||||||
@ -480,6 +580,15 @@ static void ps_package(FILE *file, const struct pkg *pkg, int page)
|
|||||||
* Put the frames
|
* 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");
|
fprintf(file, "showpage\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -589,7 +698,7 @@ fprintf(file,
|
|||||||
* Stack: string -> string
|
* Stack: string -> string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fprintf(file,
|
fprintf(file,
|
||||||
"/debugbox { gsave dup false charpath flattenpath pathbbox\n"
|
"/debugbox { gsave dup false charpath flattenpath pathbbox\n"
|
||||||
" /ury exch def /urx exch def /lly exch def /llx exch def\n"
|
" /ury exch def /urx exch def /lly exch def /llx exch def\n"
|
||||||
" 0 setgray 100 setlinewidth\n"
|
" 0 setgray 100 setlinewidth\n"
|
||||||
@ -599,7 +708,7 @@ fprintf(file,
|
|||||||
* Stack: int -> int
|
* Stack: int -> int
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fprintf(file,
|
fprintf(file,
|
||||||
"/realsize {\n"
|
"/realsize {\n"
|
||||||
" 254 div 72 mul 1000 div 0 matrix currentmatrix idtransform pop\n"
|
" 254 div 72 mul 1000 div 0 matrix currentmatrix idtransform pop\n"
|
||||||
" } def\n");
|
" } def\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user