Date:2010-04-25 12:58:07 (13 years 11 months ago)
Author:werner
Commit:1dda2ac2aee9a4177e49ebd3deb32a9d4e7e754d
Message:When creating an object in the GUI, its label wasn't initialized. Added infrastructure for hole objects. (Postscript and KiCad output are still missing, and so does sanity checking.)

- gui_tool.c (new_obj_unconnected): set obj->name to NULL
- added hole objects to tool bar, all the various GUI routines, the .fpd
parser, and the .fpd dumper



git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5939 99fdad57-331a-0410-800a-d7fa5415bdb3
Files: Makefile (1 diff)
delete.c (3 diffs)
dump.c (2 diffs)
fpd.l (1 diff)
fpd.y (2 diffs)
gui_inst.c (3 diffs)
gui_inst.h (3 diffs)
gui_style.c (3 diffs)
gui_style.h (1 diff)
gui_tool.c (5 diffs)
gui_tool.h (1 diff)
icons/hole.fig (1 diff)
inst.c (1 diff)
inst.h (3 diffs)
obj.c (2 diffs)
obj.h (3 diffs)

Change Details

Makefile
2323
2424XPMS = point.xpm delete.xpm delete_off.xpm \
2525       vec.xpm frame.xpm \
26       line.xpm rect.xpm pad.xpm rpad.xpm arc.xpm circ.xpm \
26       line.xpm rect.xpm pad.xpm rpad.xpm hole.xpm arc.xpm circ.xpm \
2727       meas.xpm meas_x.xpm meas_y.xpm \
2828       stuff.xpm stuff_off.xpm meas_off.xpm \
2929       bright.xpm bright_off.xpm all.xpm all_off.xpm
delete.c
11/*
22 * delete.c - Object deletion
33 *
4 * Written 2009 by Werner Almesberger
5 * Copyright 2009 by Werner Almesberger
4 * Written 2009, 2010 by Werner Almesberger
5 * Copyright 2009, 2010 by Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
137137        return obj->u.rect.other == ref;
138138    case ot_pad:
139139        return obj->u.pad.other == ref;
140    case ot_hole:
141        return obj->u.hole.other == ref;
140142    case ot_arc:
141143        return obj->u.arc.start == ref || obj->u.arc.end == ref;
142144    case ot_meas:
...... 
210212    case ot_pad:
211213        free(obj->u.pad.name);
212214        break;
215    case ot_hole:
216        break;
213217    case ot_line:
214218        if (obj->u.line.width)
215219            free_expr(obj->u.line.width);
dump.c
111111        n |= need(obj->u.pad.other, prev);
112112        l |= later(obj->u.pad.other, prev);
113113        break;
114    case ot_hole:
115        n |= need(obj->u.hole.other, prev);
116        l |= later(obj->u.hole.other, prev);
117        break;
114118    case ot_arc:
115119        n |= need(obj->u.arc.start, prev);
116120        n |= need(obj->u.arc.end, prev);
...... 
352356            obj->u.pad.rounded ? "r" : "",
353357            obj->u.pad.name, base, s1, s2);
354358        break;
359    case ot_hole:
360        s1 = obj_base_name(obj->u.hole.other, prev);
361        s = stralloc_printf("hole %s %s", base, s1);
362        break;
355363    case ot_arc:
356364        s1 = obj_base_name(obj->u.arc.start, prev);
357365        s2 = unparse(obj->u.arc.width);
fpd.l
104104                  return TOK_PAD; }
105105<INITIAL>"rpad" { BEGIN(NOKEYWORD);
106106                  return TOK_RPAD; }
107<INITIAL>"hole" { BEGIN(NOKEYWORD);
108                  return TOK_HOLE; }
107109<INITIAL>"rect" { BEGIN(NOKEYWORD);
108110                  return TOK_RECT; }
109111<INITIAL>"line" { BEGIN(NOKEYWORD);
fpd.y
285285
286286%token START_FPD START_EXPR START_VAR START_VALUES
287287%token TOK_SET TOK_LOOP TOK_PACKAGE TOK_FRAME TOK_TABLE TOK_VEC
288%token TOK_PAD TOK_RPAD TOK_RECT TOK_LINE TOK_CIRC TOK_ARC
288%token TOK_PAD TOK_RPAD TOK_HOLE TOK_RECT TOK_LINE TOK_CIRC TOK_ARC
289289%token TOK_MEAS TOK_MEASX TOK_MEASY TOK_UNIT
290290%token TOK_NEXT TOK_NEXT_INVERTED TOK_MAX TOK_MAX_INVERTED
291291%token TOK_DBG_DEL TOK_DBG_MOVE TOK_DBG_PRINT TOK_DBG_DUMP
...... 
653653            $$->u.pad.rounded = 1;
654654            $$->u.pad.type = $5;
655655        }
656    | TOK_HOLE base base
657        {
658            $$ = new_obj(ot_hole);
659            $$->base = $2;
660            $$->u.hole.other = $3;
661        }
656662    | TOK_RECT base base opt_expr
657663        {
658664            $$ = new_obj(ot_rect);
gui_inst.c
11/*
22 * gui_inst.c - GUI, instance functions
33 *
4 * Written 2009 by Werner Almesberger
5 * Copyright 2009 by Werner Almesberger
4 * Written 2009, 2010 by Werner Almesberger
5 * Copyright 2009, 2010 by Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
288288}
289289
290290
291void gui_draw_rpad(struct inst *self)
291static void draw_rounded_rect(GdkGC *gc, struct coord a, struct coord b,
292     int fill)
292293{
293    struct coord min = translate(self->base);
294    struct coord max = translate(self->u.pad.other);
295    GdkGC *gc;
296    int fill;
294    struct coord min = translate(a);
295    struct coord max = translate(b);
297296    unit_type h, w, r;
298297
299    gc = pad_gc(self, &fill);
300298    sort_coord(&min, &max);
301299    h = max.y-min.y;
302300    w = max.x-min.x;
...... 
323321        }
324322        draw_arc(DA, gc, fill, max.x-r, min.y+r, r, 270, 90);
325323    }
324}
326325
326
327void gui_draw_rpad(struct inst *self)
328{
329    GdkGC *gc;
330    int fill;
331
332    gc = pad_gc(self, &fill);
333    draw_rounded_rect(gc, self->base, self->u.pad.other, fill);
327334    gui_draw_pad_text(self);
328335}
329336
330337
338/* ----- hole -------------------------------------------------------------- */
339
340
341unit_type gui_dist_hole(struct inst *self, struct coord pos, unit_type scale)
342{
343    unit_type d;
344
345    /* @@@ not quite right ... */
346    if (inside_rect(pos, self->base, self->u.hole.other))
347        return SELECT_R;
348    d = dist_rect(pos, self->base, self->u.hole.other)/scale;
349    return d > SELECT_R ? -1 : d;
350}
351
352
353void gui_draw_hole(struct inst *self)
354{
355    draw_rounded_rect(gc_hole[get_mode(self)],
356        self->base, self->u.hole.other, 1);
357    draw_rounded_rect(gc_rim[get_mode(self)],
358        self->base, self->u.hole.other, 0);
359}
360
361
331362/* ----- arc --------------------------------------------------------------- */
332363
333364
gui_inst.h
11/*
22 * gui_inst.h - GUI, instance functions
33 *
4 * Written 2009 by Werner Almesberger
5 * Copyright 2009 by Werner Almesberger
4 * Written 2009, 2010 by Werner Almesberger
5 * Copyright 2009, 2010 by Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
3030unit_type gui_dist_line(struct inst *self, struct coord pos, unit_type scale);
3131unit_type gui_dist_rect(struct inst *self, struct coord pos, unit_type scale);
3232unit_type gui_dist_pad(struct inst *self, struct coord pos, unit_type scale);
33unit_type gui_dist_hole(struct inst *self, struct coord pos, unit_type scale);
3334unit_type gui_dist_arc(struct inst *self, struct coord pos, unit_type scale);
3435unit_type gui_dist_meas(struct inst *self, struct coord pos, unit_type scale);
3536unit_type gui_dist_frame(struct inst *self, struct coord pos, unit_type scale);
...... 
4445void gui_draw_rect(struct inst *self);
4546void gui_draw_pad(struct inst *self);
4647void gui_draw_rpad(struct inst *self);
48void gui_draw_hole(struct inst *self);
4749void gui_draw_arc(struct inst *self);
4850void gui_draw_meas(struct inst *self);
4951void gui_draw_frame(struct inst *self);
gui_style.c
11/* * gui_style.c - GUI, style definitions
22 *
3 * Written 2009 by Werner Almesberger
4 * Copyright 2009 by Werner Almesberger
3 * Written 2009, 2010 by Werner Almesberger
4 * Copyright 2009, 2010 by Werner Almesberger
55 *
66 * This program is free software; you can redistribute it and/or modify
77 * it under the terms of the GNU General Public License as published by
...... 
2828GdkGC *gc_pad_bare[mode_n];
2929GdkGC *gc_pad_mask[mode_n];
3030GdkGC *gc_ptext[mode_n];
31GdkGC *gc_rim[mode_n];
32GdkGC *gc_hole[mode_n];
3133GdkGC *gc_meas[mode_n];
3234GdkGC *gc_frame[mode_n];
3335
...... 
6163    gc_bg = gc("#000000", 0);
6264    gc_bg_error = gc("#000040", 0);
6365    gc_drag = gc("#ffffff", 2);
64    /* inactive active selected */
66    /* inactive active selected width */
6567    style(gc_vec, "#202000", "#b0b050", "#ffff80", 1);
6668    style(gc_obj, "#006060", "#00ffff", "#ffff80", 1);
6769    style(gc_pad, "#400000", "#ff0000", "#ffff80", 1);
6870    style(gc_pad_bare, "#402000", "#ff6000", "#ffff80", 1);
6971    style(gc_pad_mask, "#000040", "#0000ff", "#ffff80", 2);
7072    style(gc_ptext, "#404040", "#ffffff", "#ffffff", 1);
73    style(gc_hole, "#000000", "#000000", "#000000", 0);
74    style(gc_rim, "#202020", "#606060", "#ffff80", 3);
7175    style(gc_meas, "#280040", "#ff00ff", "#ffff80", 1);
7276    style(gc_frame, "#005000", "#009000", "#ffff80", 1);
7377
gui_style.h
116116extern GdkGC *gc_pad_bare[mode_n];
117117extern GdkGC *gc_pad_mask[mode_n];
118118extern GdkGC *gc_ptext[mode_n];
119extern GdkGC *gc_rim[mode_n];
120extern GdkGC *gc_hole[mode_n];
119121extern GdkGC *gc_meas[mode_n];
120122extern GdkGC *gc_frame[mode_n];
121123
gui_tool.c
4040#include "icons/meas_y.xpm"
4141#include "icons/pad.xpm"
4242#include "icons/rpad.xpm"
43#include "icons/hole.xpm"
4344#include "icons/point.xpm"
4445#include "icons/delete.xpm"
4546#include "icons/delete_off.xpm"
...... 
8889
8990    obj = alloc_type(struct obj);
9091    obj->type = type;
92    obj->name = NULL;
9193    obj->frame = active_frame;
9294    obj->base = inst_get_vec(base);
9395    obj->next = NULL;
...... 
459461};
460462
461463
464/* ----- hole -------------------------------------------------------------- */
465
466
467static int end_new_hole(struct inst *from, struct inst *to)
468{
469    struct obj *obj;
470
471    if (from == to)
472        return 0;
473    obj = new_obj(ot_hole, from);
474    obj->u.hole.other = inst_get_vec(to);
475    return 1;
476}
477
478
479struct pix_buf *draw_move_hole(struct inst *inst, struct coord pos, int i)
480{
481    return draw_move_rect_common(inst, inst->u.hole.other, pos, i);
482}
483
484
485static struct tool_ops hole_ops = {
486    .drag_new = drag_new_rect,
487    .end_new = end_new_hole,
488};
489
490
462491/* ----- circ -------------------------------------------------------------- */
463492
464493
...... 
10491078    case ip_pad_special:
10501079        image = inst->obj->u.pad.rounded ? xpm_rpad : xpm_pad;
10511080        break;
1081    case ip_hole:
1082        image = xpm_hole;
1083        break;
10521084    case ip_circ:
10531085        image = xpm_circ;
10541086        break;
...... 
11661198    tool_button(bar, drawable, xpm_rpad,
11671199        "Add a rounded pad",
11681200        tool_button_press_event, &rpad_ops);
1201    tool_button(bar, drawable, xpm_hole,
1202        "Add a hole",
1203        tool_button_press_event, &hole_ops);
11691204    tool_button(bar, drawable, xpm_line,
11701205        "Add a silk screen line",
11711206        tool_button_press_event, &line_ops);
gui_tool.h
3636struct pix_buf *draw_move_rect(struct inst *inst, struct coord pos, int i);
3737struct pix_buf *draw_move_pad(struct inst *inst, struct coord pos, int i);
3838struct pix_buf *draw_move_rpad(struct inst *inst, struct coord pos, int i);
39struct pix_buf *draw_move_hole(struct inst *inst, struct coord pos, int i);
3940struct pix_buf *draw_move_arc(struct inst *inst, struct coord pos, int i);
4041struct pix_buf *draw_move_meas(struct inst *inst, struct coord pos, int i);
4142struct pix_buf *draw_move_frame(struct inst *inst, struct coord pos, int i);
icons/hole.fig
1#FIG 3.2 Produced by xfig version 3.2.5a
2Landscape
3Center
4Inches
5A4
6100.00
7Single
8-2
91200 2
106 3600 2400 6000 4800
111 3 0 8 0 7 45 -1 20 0.000 1 0.0000 4800 3600 600 600 4800 3600 5400 3600
122 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
13     3600 2400 6000 2400 6000 4800 3600 4800 3600 2400
142 1 0 5 0 7 50 -1 20 0.000 0 1 -1 0 0 2
15     3900 4500 5700 2700
162 1 0 5 0 7 50 -1 20 0.000 0 1 -1 0 0 2
17     3900 3900 5100 2700
182 1 0 5 0 7 50 -1 20 0.000 0 1 -1 0 0 2
19     3900 3300 4500 2700
202 1 0 5 0 7 50 -1 20 0.000 0 1 -1 0 0 2
21     4500 4500 5700 3300
222 1 0 5 0 7 50 -1 20 0.000 0 1 -1 0 0 2
23     5100 4500 5700 3900
24-6
inst.c
909909}
910910
911911
912/* ----- hole -------------------------------------------------------------- */
913
914
915static void hole_op_select(struct inst *self)
916{
917    rect_status_sort(self->base, self->u.hole.other, -1, 1);
918}
919
920
921static struct inst_ops hole_ops = {
922    .draw = gui_draw_hole,
923    .distance = gui_dist_hole,
924    .select = hole_op_select,
925    .draw_move = draw_move_hole,
926};
927
928
929int inst_hole(struct obj *obj, struct coord a, struct coord b)
930{
931    struct inst *inst;
932
933    inst = add_inst(&hole_ops, ip_hole, a);
934    inst->obj = obj;
935    inst->u.hole.other = b;
936    find_inst(inst);
937    update_bbox(&inst->bbox, b);
938    propagate_bbox(inst);
939    return 1;
940}
941
942
912943/* ----- arc --------------------------------------------------------------- */
913944
914945
inst.h
4040    ip_frame, /* frames have their own selection */
4141    ip_pad_copper, /* pads also accept clicks inside; pads with copper */
4242    ip_pad_special, /* pads with only solder paste or mask, on top */
43    ip_hole, /* holes in pads must be on top to be seen */
4344    ip_circ, /* circles don't overlap easily */
4445    ip_arc, /* arcs are like circles, just shorter */
4546    ip_rect, /* rectangles have plenty of sides */
...... 
99100            layer_type layers; /* bit-set of layers */
100101        } pad;
101102        struct {
103            struct coord other;
104        } hole;
105        struct {
102106            unit_type r;
103107            double a1, a2;
104108            unit_type width;
...... 
173177int inst_line(struct obj *obj, struct coord a, struct coord b, unit_type width);
174178int inst_rect(struct obj *obj, struct coord a, struct coord b, unit_type width);
175179int inst_pad(struct obj *obj, const char *name, struct coord a, struct coord b);
180int inst_hole(struct obj *obj, struct coord a, struct coord b);
176181int inst_arc(struct obj *obj, struct coord center, struct coord start,
177182    struct coord stop, unit_type width);
178183int inst_meas(struct obj *obj, struct coord from, struct coord to);
obj.c
112112    case ot_pad:
113113        anchors[1] = &obj->u.pad.other;
114114        return 2;
115    case ot_hole:
116        anchors[1] = &obj->u.hole.other;
117        return 2;
115118    case ot_meas:
116119        anchors[1] = &obj->u.meas.high;
117120        return 2;
...... 
234237            if (!ok)
235238                goto error;
236239            break;
240        case ot_hole:
241            if (!inst_hole(obj, obj->base ? obj->base->pos : base,
242                obj->u.hole.other ? obj->u.hole.other->pos : base))
243                goto error;
244            break;
237245        case ot_arc:
238246            width = eval_unit_default(obj->u.arc.width, frame,
239247                DEFAULT_SILK_WIDTH);
obj.h
178178    ot_frame,
179179    ot_rect,
180180    ot_pad,
181    ot_hole,
181182    ot_line,
182183    ot_arc,
183184    ot_meas,
...... 
200201    enum pad_type type;
201202};
202203
204struct hole {
205    struct vec *other; /* NULL if frame origin */
206};
207
203208struct arc {
204209    struct vec *start; /* NULL if frame origin */
205210    struct vec *end; /* NULL if this is a circle */
...... 
214219        struct rect rect;
215220        struct rect line;
216221        struct pad pad;
222        struct hole hole;
217223        struct arc arc;
218224        struct meas meas;
219225    } u;

Archive Download the corresponding diff file

Branches:
master



interactive