1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-09-28 22:14:10 +03:00

- added rounded pads

- initialize item_widget to NULL if not showing items or bad things happen



git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5440 99fdad57-331a-0410-800a-d7fa5415bdb3
This commit is contained in:
werner 2009-08-14 10:18:40 +00:00
parent dbcfae8261
commit d39ae30f6e
17 changed files with 197 additions and 24 deletions

View File

@ -16,9 +16,11 @@ OBJS = fped.o expr.o coord.o obj.o delete.o inst.o util.o error.o \
gui.o gui_util.o gui_style.o gui_inst.o gui_status.o gui_canvas.o \ gui.o gui_util.o gui_style.o gui_inst.o gui_status.o gui_canvas.o \
gui_tool.o gui_over.o gui_meas.o gui_frame.o gui_tool.o gui_over.o gui_meas.o gui_frame.o
XPMS = point.xpm delete.xpm vec.xpm frame.xpm frame_locked.xpm frame_ready.xpm \ XPMS = point.xpm delete.xpm delete_off.xpm \
line.xpm rect.xpm pad.xpm circ.xpm meas.xpm meas_x.xpm meas_y.xpm \ vec.xpm frame.xpm frame_locked.xpm frame_ready.xpm \
stuff.xpm stuff_off.xpm meas_off.xpm delete_off.xpm line.xpm rect.xpm pad.xpm rpad.xpm circ.xpm \
meas.xpm meas_x.xpm meas_y.xpm \
stuff.xpm stuff_off.xpm meas_off.xpm
CFLAGS_GTK = `pkg-config --cflags gtk+-2.0` CFLAGS_GTK = `pkg-config --cflags gtk+-2.0`
LIBS_GTK = `pkg-config --libs gtk+-2.0` LIBS_GTK = `pkg-config --libs gtk+-2.0`

10
README
View File

@ -199,6 +199,16 @@ vec @(1mm, 1mm)
pad "1" @ . pad "1" @ .
Rounded pads
- - - - - -
Rounded pads are like rectangular pads except that they end with a
semi-circle at each of the smaller sides of the enclosing rectangle.
If enclosed in a square, rounded pads form a circle.
rpad "<name>" <point-a> <point-b>
Measurements Measurements
- - - - - - - - - - - -

3
TODO
View File

@ -28,9 +28,6 @@ Bugs:
- default silk width has no business being hard-coded in obj.c - default silk width has no business being hard-coded in obj.c
- undelete only works if not much has changed since the deletion - undelete only works if not much has changed since the deletion
- focus should return to canvas if nobody else wants it - focus should return to canvas if nobody else wants it
- when in uninstantiated mode, objects can be changed and then manipulated
through the unchanged instance. Tricky to fix without an alternate means to
access the object list. (Getting there.)
Code cleanup: Code cleanup:
- merge edit_unique with edit_name - merge edit_unique with edit_name

4
dump.c
View File

@ -317,8 +317,8 @@ char *print_obj(const struct obj *obj, const struct vec *prev)
break; break;
case ot_pad: case ot_pad:
s1 = obj_base_name(obj->u.pad.other, prev); s1 = obj_base_name(obj->u.pad.other, prev);
s = stralloc_printf("pad \"%s\" %s %s", s = stralloc_printf("%spad \"%s\" %s %s",
obj->u.pad.name, base, s1); obj->u.pad.rounded ? "r" : "", obj->u.pad.name, base, s1);
free(s1); free(s1);
break; break;
case ot_arc: case ot_arc:

View File

@ -12,7 +12,7 @@ frame pad {
__0: vec @(col*e-Px/2, row*-e-Py/2) __0: vec @(col*e-Px/2, row*-e-Py/2)
__1: vec .(0mm, Py) __1: vec .(0mm, Py)
__2: vec __0(Px, 0mm) __2: vec __0(Px, 0mm)
pad "$rname$cname" __1 . rpad "$rname$cname" __1 .
} }
frame inner { frame inner {

2
fpd.l
View File

@ -85,6 +85,8 @@ SP [\t ]*
return TOK_VEC; } return TOK_VEC; }
<INITIAL>"pad" { BEGIN(NOKEYWORD); <INITIAL>"pad" { BEGIN(NOKEYWORD);
return TOK_PAD; } return TOK_PAD; }
<INITIAL>"rpad" { BEGIN(NOKEYWORD);
return TOK_RPAD; }
<INITIAL>"rect" { BEGIN(NOKEYWORD); <INITIAL>"rect" { BEGIN(NOKEYWORD);
return TOK_RECT; } return TOK_RECT; }
<INITIAL>"line" { BEGIN(NOKEYWORD); <INITIAL>"line" { BEGIN(NOKEYWORD);

11
fpd.y
View File

@ -151,7 +151,7 @@ static struct obj *new_obj(enum obj_type type)
%token START_FPD START_EXPR %token START_FPD START_EXPR
%token TOK_SET TOK_LOOP TOK_PART TOK_FRAME TOK_TABLE TOK_VEC %token TOK_SET TOK_LOOP TOK_PART TOK_FRAME TOK_TABLE TOK_VEC
%token TOK_PAD TOK_RECT TOK_LINE TOK_CIRC TOK_ARC %token TOK_PAD TOK_RPAD TOK_RECT TOK_LINE TOK_CIRC TOK_ARC
%token TOK_MEAS TOK_MEASX TOK_MEASY %token TOK_MEAS TOK_MEASX TOK_MEASY
%token TOK_NEXT TOK_NEXT_INVERTED TOK_MAX TOK_MAX_INVERTED %token TOK_NEXT TOK_NEXT_INVERTED TOK_MAX TOK_MAX_INVERTED
@ -419,6 +419,15 @@ obj:
$$->base = $3; $$->base = $3;
$$->u.pad.name = $2; $$->u.pad.name = $2;
$$->u.pad.other = $4; $$->u.pad.other = $4;
$$->u.pad.rounded = 0;
}
| TOK_RPAD STRING base base
{
$$ = new_obj(ot_pad);
$$->base = $3;
$$->u.pad.name = $2;
$$->u.pad.other = $4;
$$->u.pad.rounded = 1;
} }
| TOK_RECT base base opt_expr | TOK_RECT base base opt_expr
{ {

View File

@ -938,6 +938,7 @@ static void set_item_color(struct inst *inst, const char *color)
label = inst->vec->list_widget; label = inst->vec->list_widget;
else else
label = inst->obj->list_widget; label = inst->obj->list_widget;
if (label)
label_in_box_bg(box_of_label(label), color); label_in_box_bg(box_of_label(label), color);
} }
@ -1100,6 +1101,18 @@ static GtkWidget *build_meas(struct frame *frame)
} }
static void dont_build_items(struct frame *frame)
{
struct vec *vec;
struct obj *obj;
for (vec = frame->vecs; vec; vec = vec->next)
vec->list_widget = NULL;
for (obj = frame->objs; obj; obj = obj->next)
obj->list_widget = NULL;
}
/* ----- part name --------------------------------------------------------- */ /* ----- part name --------------------------------------------------------- */
@ -1323,6 +1336,7 @@ void build_frames(GtkWidget *vbox)
vars = build_vars(frame); vars = build_vars(frame);
gtk_table_attach_defaults(GTK_TABLE(tab), vars, gtk_table_attach_defaults(GTK_TABLE(tab), vars,
1, 2, n*2+2, n*2+3); 1, 2, n*2+2, n*2+3);
dont_build_items(frame);
} else { } else {
items = build_items(frame); items = build_items(frame);
gtk_table_attach_defaults(GTK_TABLE(tab), items, gtk_table_attach_defaults(GTK_TABLE(tab), items,

View File

@ -235,7 +235,7 @@ unit_type gui_dist_pad(struct inst *self, struct coord pos, unit_type scale)
} }
void gui_draw_pad(struct inst *self) static void gui_draw_pad_text(struct inst *self)
{ {
struct coord min = translate(self->base); struct coord min = translate(self->base);
struct coord max = translate(self->u.pad.other); struct coord max = translate(self->u.pad.other);
@ -243,12 +243,8 @@ void gui_draw_pad(struct inst *self)
struct coord c; struct coord c;
unit_type h, w; unit_type h, w;
gc = gc_pad[get_mode(self)];
sort_coord(&min, &max);
gdk_draw_rectangle(DA, gc, TRUE,
min.x, min.y, max.x-min.x, max.y-min.y);
gc = gc_ptext[get_mode(self)]; gc = gc_ptext[get_mode(self)];
sort_coord(&min, &max);
c = add_vec(min, max); c = add_vec(min, max);
h = max.y-min.y; h = max.y-min.y;
w = max.x-min.x; w = max.x-min.x;
@ -258,6 +254,48 @@ void gui_draw_pad(struct inst *self)
} }
void gui_draw_pad(struct inst *self)
{
struct coord min = translate(self->base);
struct coord max = translate(self->u.pad.other);
GdkGC *gc;
gc = gc_pad[get_mode(self)];
sort_coord(&min, &max);
gdk_draw_rectangle(DA, gc, TRUE,
min.x, min.y, max.x-min.x, max.y-min.y);
gui_draw_pad_text(self);
}
void gui_draw_rpad(struct inst *self)
{
struct coord min = translate(self->base);
struct coord max = translate(self->u.pad.other);
GdkGC *gc;
unit_type h, w, r;
gc = gc_pad[get_mode(self)];
sort_coord(&min, &max);
h = max.y-min.y;
w = max.x-min.x;
if (h > w) {
r = w/2;
draw_arc(DA, gc, TRUE, min.x+r, max.y-r, r, 180, 0);
gdk_draw_rectangle(DA, gc, TRUE, min.x, min.y+r, w, h-2*r);
draw_arc(DA, gc, TRUE, min.x+r, min.y+r, r, 0, 180);
} else {
r = h/2;
draw_arc(DA, gc, TRUE, min.x+r, min.y+r, r, 90, 270);
gdk_draw_rectangle(DA, gc, TRUE, min.x+r, min.y, w-2*r, h);
draw_arc(DA, gc, TRUE, max.x-r, min.y+r, r, 270, 90);
}
gui_draw_pad_text(self);
}
/* ----- arc --------------------------------------------------------------- */ /* ----- arc --------------------------------------------------------------- */

View File

@ -39,6 +39,7 @@ void gui_draw_vec(struct inst *self);
void gui_draw_line(struct inst *self); void gui_draw_line(struct inst *self);
void gui_draw_rect(struct inst *self); void gui_draw_rect(struct inst *self);
void gui_draw_pad(struct inst *self); void gui_draw_pad(struct inst *self);
void gui_draw_rpad(struct inst *self);
void gui_draw_arc(struct inst *self); void gui_draw_arc(struct inst *self);
void gui_draw_meas(struct inst *self); void gui_draw_meas(struct inst *self);
void gui_draw_frame(struct inst *self); void gui_draw_frame(struct inst *self);

View File

@ -39,6 +39,7 @@
#include "icons/meas_x.xpm" #include "icons/meas_x.xpm"
#include "icons/meas_y.xpm" #include "icons/meas_y.xpm"
#include "icons/pad.xpm" #include "icons/pad.xpm"
#include "icons/rpad.xpm"
#include "icons/point.xpm" #include "icons/point.xpm"
#include "icons/delete.xpm" #include "icons/delete.xpm"
#include "icons/delete_off.xpm" #include "icons/delete_off.xpm"
@ -377,6 +378,7 @@ static int end_new_pad(struct inst *from, struct inst *to)
obj = new_obj(ot_pad, from); obj = new_obj(ot_pad, from);
obj->u.pad.other = inst_get_vec(to); obj->u.pad.other = inst_get_vec(to);
obj->u.pad.name = stralloc("?"); obj->u.pad.name = stralloc("?");
obj->u.pad.rounded = 0;
return 1; return 1;
} }
@ -393,6 +395,35 @@ static struct tool_ops pad_ops = {
}; };
/* ----- rounded pad ------------------------------------------------------- */
static int end_new_rpad(struct inst *from, struct inst *to)
{
struct obj *obj;
if (from == to)
return 0;
obj = new_obj(ot_pad, from);
obj->u.pad.other = inst_get_vec(to);
obj->u.pad.name = stralloc("?");
obj->u.pad.rounded = 1;
return 1;
}
struct pix_buf *draw_move_rpad(struct inst *inst, struct coord pos, int i)
{
return draw_move_rect_common(inst, inst->u.pad.other, pos, i);
}
static struct tool_ops rpad_ops = {
.drag_new = drag_new_rect,
.end_new = end_new_rpad,
};
/* ----- circ -------------------------------------------------------------- */ /* ----- circ -------------------------------------------------------------- */
@ -989,6 +1020,8 @@ GtkWidget *gui_setup_tools(GdkDrawable *drawable)
tool_button_press_event, &frame_ops); tool_button_press_event, &frame_ops);
tool_button(bar, drawable, xpm_pad, tool_button(bar, drawable, xpm_pad,
tool_button_press_event, &pad_ops); tool_button_press_event, &pad_ops);
tool_button(bar, drawable, xpm_rpad,
tool_button_press_event, &rpad_ops);
tool_button(bar, drawable, xpm_line, tool_button(bar, drawable, xpm_line,
tool_button_press_event, &line_ops); tool_button_press_event, &line_ops);
tool_button(bar, drawable, xpm_rect, tool_button(bar, drawable, xpm_rect,

View File

@ -35,6 +35,7 @@ struct pix_buf *draw_move_vec(struct inst *inst, struct coord pos, int i);
struct pix_buf *draw_move_line(struct inst *inst, struct coord pos, int i); struct pix_buf *draw_move_line(struct inst *inst, struct coord pos, int i);
struct pix_buf *draw_move_rect(struct inst *inst, struct coord pos, int i); struct pix_buf *draw_move_rect(struct inst *inst, struct coord pos, int i);
struct pix_buf *draw_move_pad(struct inst *inst, struct coord pos, int i); struct pix_buf *draw_move_pad(struct inst *inst, struct coord pos, int i);
struct pix_buf *draw_move_rpad(struct inst *inst, struct coord pos, int i);
struct pix_buf *draw_move_arc(struct inst *inst, struct coord pos, int i); struct pix_buf *draw_move_arc(struct inst *inst, struct coord pos, int i);
struct pix_buf *draw_move_meas(struct inst *inst, struct coord pos, int i); struct pix_buf *draw_move_meas(struct inst *inst, struct coord pos, int i);
struct pix_buf *draw_move_frame(struct inst *inst, struct coord pos, int i); struct pix_buf *draw_move_frame(struct inst *inst, struct coord pos, int i);

17
icons/rpad.fig Normal file
View File

@ -0,0 +1,17 @@
#FIG 3.2 Produced by xfig version 3.2.5a
Landscape
Center
Inches
A4
100.00
Single
-2
1200 2
5 1 0 0 0 4 50 -1 20 0.000 0 1 0 0 4800.000 3825.000 4125 3825 4800 4500 5475 3825
5 1 0 0 0 4 50 -1 20 0.000 0 0 0 0 4800.000 3375.000 4125 3375 4800 2700 5475 3375
2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
3600 2400 6000 2400 6000 4800 3600 4800 3600 2400
2 1 0 15 7 7 45 -1 -1 0.000 1 1 -1 0 0 3
4875 4050 4875 3150 4650 3375
2 2 0 0 0 4 50 -1 20 0.000 0 0 -1 0 0 5
4125 3375 5475 3375 5475 3825 4125 3825 4125 3375

21
inst.c
View File

@ -619,7 +619,7 @@ int inst_rect(struct obj *obj, struct coord a, struct coord b, unit_type width)
} }
/* ----- pad --------------------------------------------------------------- */ /* ----- pad / rpad -------------------------------------------------------- */
static void pad_op_debug(struct inst *self) static void pad_op_debug(struct inst *self)
@ -630,6 +630,13 @@ static void pad_op_debug(struct inst *self)
} }
static void rpad_op_debug(struct inst *self)
{
printf("r");
pad_op_debug(self);
}
static int validate_pad_name(const char *s, void *ctx) static int validate_pad_name(const char *s, void *ctx)
{ {
char *tmp; char *tmp;
@ -677,11 +684,21 @@ static struct inst_ops pad_ops = {
}; };
static struct inst_ops rpad_ops = {
.debug = rpad_op_debug,
.draw = gui_draw_rpad,
.distance = gui_dist_pad, /* @@@ */
.select = pad_op_select,
.anchors = pad_op_anchors,
.draw_move = draw_move_rpad,
};
int inst_pad(struct obj *obj, const char *name, struct coord a, struct coord b) int inst_pad(struct obj *obj, const char *name, struct coord a, struct coord b)
{ {
struct inst *inst; struct inst *inst;
inst = add_inst(&pad_ops, ip_pad, a); inst = add_inst(obj->u.pad.rounded ? &rpad_ops : &pad_ops, ip_pad, a);
inst->obj = obj; inst->obj = obj;
inst->u.pad.name = stralloc(name); inst->u.pad.name = stralloc(name);
inst->u.pad.other = b; inst->u.pad.other = b;

View File

@ -78,8 +78,9 @@ static void kicad_pad(FILE *file, const struct inst *inst)
/* /*
* name, shape (rectangle), Xsize, Ysize, Xdelta, Ydelta, Orientation * name, shape (rectangle), Xsize, Ysize, Xdelta, Ydelta, Orientation
*/ */
fprintf(file, "Sh \"%s\" R %d %d 0 0 0\n", fprintf(file, "Sh \"%s\" %c %d %d 0 0 0\n",
inst->u.pad.name, max.x-min.x, max.y-min.y); inst->u.pad.name, inst->obj->u.pad.rounded ? 'O' : 'R',
max.x-min.x, max.y-min.y);
/* /*
* Attributes: pad type, N, layer mask * Attributes: pad type, N, layer mask

5
obj.h
View File

@ -104,7 +104,7 @@ struct vec {
struct sample *samples; struct sample *samples;
/* for the GUI */ /* for the GUI */
GtkWidget *list_widget; GtkWidget *list_widget; /* NULL if items aren't shown */
}; };
struct frame { struct frame {
@ -148,6 +148,7 @@ struct rect {
struct pad { struct pad {
char *name; char *name;
struct vec *other; /* NULL if frame origin */ struct vec *other; /* NULL if frame origin */
int rounded;
}; };
struct arc { struct arc {
@ -175,7 +176,7 @@ struct obj {
int dumped; int dumped;
/* for the GUI */ /* for the GUI */
GtkWidget *list_widget; GtkWidget *list_widget; /* NULL if items are not shown */
}; };

View File

@ -48,6 +48,33 @@ static void ps_pad(FILE *file, const struct inst *inst)
} }
static void ps_rpad(FILE *file, const struct inst *inst)
{
struct coord a = inst->base;
struct coord b = inst->u.pad.other;
unit_type h, w, r;
sort_coord(&a, &b);
h = b.y-a.y;
w = b.x-a.x;
fprintf(file, "0 setgray %d setlinewidth\n", HATCH_LINE);
if (h > w) {
r = w/2;
fprintf(file, " %d %d moveto\n", b.x, b.y-r);
fprintf(file, " %d %d %d 0 180 arc\n", a.x+r, b.y-r, r);
fprintf(file, " %d %d lineto\n", a.x, a.y+r);
fprintf(file, " %d %d %d 180 360 arc\n", a.x+r, a.y+r, r);
} else {
r = h/2;
fprintf(file, " %d %d moveto\n", b.x-r, a.y);
fprintf(file, " %d %d %d -90 90 arc\n", b.x-r, a.y+r, r);
fprintf(file, " %d %d lineto\n", a.x+r, b.y);
fprintf(file, " %d %d %d 90 270 arc\n", a.x+r, a.y+r, r);
}
fprintf(file, " closepath gsave hatchpath grestore stroke\n");
}
static void ps_line(FILE *file, const struct inst *inst) static void ps_line(FILE *file, const struct inst *inst)
{ {
struct coord a = inst->base; struct coord a = inst->base;
@ -131,6 +158,9 @@ static void ps_foreground(FILE *file, enum inst_prio prio,
{ {
switch (prio) { switch (prio) {
case ip_pad: case ip_pad:
if (inst->obj->u.pad.rounded)
ps_rpad(file, inst);
else
ps_pad(file, inst); ps_pad(file, inst);
break; break;
case ip_vec: case ip_vec: