Date:2010-08-09 06:16:37 (8 years 10 months ago)
Author:werner
Commit:e6b2658a65f4143f68acebde8771f7e5debc6d15
Message:Added relaxation of pad overlap checking. Not GUI-settable yet.

- README, fpd.l, fpd.y: added directives "allow touch" and "allow overlap" to
make overlap checking more permissive
- dump.c (dump_allow, dump): generate "allow" directive
- obj.h, obj.c (allow_overlap): added global variable for strictness of overlap
checking
- overlap.h, overlap.c (overlap, ...), layer.h, layer.c (refine_layers):
strictness of overlap checking is passed as an argument
- hole.c (check_through_hole), layer.h, layer.c (refine_copper), obj.c
(instantiate): updated callers of "overlap" to provide "allow" argument



git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5974 99fdad57-331a-0410-800a-d7fa5415bdb3
Files: README (3 diffs)
dump.c (2 diffs)
fpd.l (2 diffs)
fpd.y (4 diffs)
hole.c (1 diff)
layer.c (5 diffs)
layer.h (2 diffs)
obj.c (3 diffs)
obj.h (2 diffs)
overlap.c (7 diffs)
overlap.h (3 diffs)

Change Details

README
106106frame definitions
107107...
108108package name
109unit
109setup
110110objects
111111...
112112
...... 
124124the two points.
125125
126126
127Setup
128- - -
129
130The setup section defines settings that affect the entire footprint.
131It is optional and can contain a "unit" directive and an "allow"
132directive.
133
134
127135Units
128136- - -
129137
...... 
154162unit set in the GUI.
155163
156164
165Allow
166- - -
167
168fped normally disallows overlapping pads. This restriction can be
169relaxed with the "allow" directive.
170
171allow touch
172
173Allows pads touching but not having more than their border in common.
174
175allow overlap
176
177Do not check for overlaps at all.
178
179If the "allow" directive is omitted, fped defaults to allowing
180neigher overlap nor touch.
181
182
157183Vectors
158184- - - -
159185
dump.c
569569}
570570
571571
572static void dump_allow(FILE *file)
573{
574    switch (allow_overlap) {
575    case ao_none:
576        break;
577    case ao_touch:
578        fprintf(file, "allow touch\n");
579        break;
580    case ao_any:
581        fprintf(file, "allow overlap\n");
582        break;
583    default:
584        abort();
585    }
586}
587
588
572589static void reverse_frames(FILE *file, struct frame *last)
573590{
574591    if (last) {
...... 
589606    reverse_frames(file, frames->next);
590607    fprintf(file, "package \"%s\"\n", pkg_name);
591608    dump_unit(file);
609    dump_allow(file);
610    fprintf(file, "\n");
592611    dump_frame(file, frames, "");
593612
594613    fflush(file);
fpd.l
6161
6262/* keywords are only accepted at the beginning of a line */
6363%s NOKEYWORD
64/* ALLOW is followed by special keywords (we could use NOKEYWORD as well) */
65%s ALLOW
6466
6567NUM [0-9]+\.?[0-9]*
6668SP [\t ]*
...... 
123125<INITIAL>"unit" { BEGIN(NOKEYWORD);
124126                  return TOK_UNIT; }
125127
128<INITIAL>"allow" BEGIN(ALLOW);
129<ALLOW>"overlap" return TOK_ALLOW_OVERLAP;
130<ALLOW>"touch" return TOK_ALLOW_TOUCH;
131
126132<INITIAL>"%del" { BEGIN(NOKEYWORD);
127133                  return TOK_DBG_DEL; }
128134<INITIAL>"%move" { BEGIN(NOKEYWORD);
fpd.y
459459%token TOK_NEXT TOK_NEXT_INVERTED TOK_MAX TOK_MAX_INVERTED
460460%token TOK_DBG_DEL TOK_DBG_MOVE TOK_DBG_FRAME TOK_DBG_PRINT
461461%token TOK_DBG_DUMP TOK_DBG_EXIT TOK_DBG_TSORT TOK_DBG_MEAS
462%token TOK_ALLOW_OVERLAP TOK_ALLOW_TOUCH
462463
463464%token <num> NUMBER
464465%token <str> STRING
...... 
508509    ;
509510
510511fpd:
511    frame_defs part_name opt_unit opt_frame_items opt_measurements
512    | frame_defs unit opt_frame_items opt_measurements
512    frame_defs part_name opt_setup opt_frame_items opt_measurements
513    | frame_defs setup opt_frame_items opt_measurements
513514    | frame_defs frame_items opt_measurements
514515    | frame_defs opt_measurements
515516    ;
...... 
532533        }
533534    ;
534535
535opt_unit:
536    | unit
536opt_setup:
537    | setup
538    ;
539
540setup:
541    unit
542    | allow
543    | unit allow
544    | allow unit
537545    ;
538546
539547unit:
...... 
552560        }
553561    ;
554562
563allow:
564    TOK_ALLOW_TOUCH
565        {
566            allow_overlap = ao_touch;
567        }
568    | TOK_ALLOW_OVERLAP
569        {
570            allow_overlap = ao_any;
571        }
572    ;
573
555574frame_defs:
556575    | frame_defs frame_def
557576    ;
hole.c
1919
2020static int check_through_hole(struct inst *pad, struct inst *hole)
2121{
22    if (!overlap(pad, hole))
22    if (!overlap(pad, hole, ao_none))
2323        return 1;
2424    if (!inside(hole, pad)) {
2525        fail("hole (line %d) not completely inside "
layer.c
113113}
114114
115115
116static int refine_copper(const struct pkg *pkg_copper, struct inst *copper)
116static int refine_copper(const struct pkg *pkg_copper, struct inst *copper,
117    enum allow_overlap allow)
117118{
118119    const struct pkg *pkg;
119120    struct inst *other;
...... 
126127            continue;
127128        for (other = pkg->insts[ip_pad_copper]; other;
128129            other = other->next)
129            if (copper != other && overlap(copper, other)) {
130            if (copper != other && overlap(copper, other, allow)) {
130131                fail("overlapping copper pads "
131132                    "(\"%s\" line %d, \"%s\" line %d)",
132133                    copper->u.pad.name, copper->obj->lineno,
...... 
136137            }
137138        for (other = pkg->insts[ip_pad_special]; other;
138139            other = other->next)
139            if (overlap(copper, other))
140            if (overlap(copper, other, ao_none))
140141                if (!refine_overlapping(copper, other))
141142                    return 0;
142143    }
...... 
155156}
156157
157158
158int refine_layers(void)
159int refine_layers(enum allow_overlap allow)
159160{
160161    const struct pkg *pkg;
161162    struct inst *copper;
...... 
163164    for (pkg = pkgs; pkg; pkg = pkg->next)
164165        for (copper = pkg->insts[ip_pad_copper]; copper;
165166            copper = copper->next) {
166            if (!refine_copper(pkg, copper))
167            if (!refine_copper(pkg, copper, allow))
167168                return 0;
168169            if (copper->u.pad.hole)
169170                mirror_layers(&copper->u.pad.layers);
layer.h
1515
1616#include <stdint.h>
1717
18#include "overlap.h"
19
1820
1921typedef uint32_t layer_type;
2022
...... 
7577
7678layer_type mech_hole_layers(void);
7779
78int refine_layers(void);
80int refine_layers(enum allow_overlap allow);
7981
8082#endif /* !LAYER_H */
obj.c
2222#include "meas.h"
2323#include "inst.h"
2424#include "hole.h"
25#include "overlap.h"
2526#include "layer.h"
2627#include "delete.h"
2728#include "obj.h"
...... 
3738struct frame *frames = NULL;
3839struct frame *active_frame = NULL;
3940void *instantiation_error = NULL;
41enum allow_overlap allow_overlap = ao_none;
4042
4143
4244static struct bitset *frame_set; /* frames visited in "call chain" */
...... 
498500    if (ok)
499501        ok = link_holes();
500502    if (ok)
501        ok = refine_layers();
503        ok = refine_layers(allow_overlap);
502504    if (ok)
503505        ok = instantiate_meas(n_frames);
504506    if (ok)
obj.h
2020#include "expr.h"
2121#include "coord.h"
2222#include "meas.h"
23#include "overlap.h"
2324#include "layer.h"
2425
2526
...... 
242243extern struct frame *frames; /* root frame first */
243244extern struct frame *active_frame;
244245extern void *instantiation_error;
246extern enum allow_overlap allow_overlap;
245247
246248
247249struct inst;
overlap.c
7171
7272
7373static int circle_circle_overlap(struct coord c1, unit_type r1,
74    struct coord c2, unit_type r2)
74    struct coord c2, unit_type r2, enum allow_overlap allow)
7575{
76    if (allow == ao_touch)
77        return dist_point(c1, c2) < r1+r2;
7678    return dist_point(c1, c2) <= r1+r2;
7779}
7880
7981
8082static int circle_rect_overlap(struct coord c, unit_type r,
81    struct coord min, struct coord max)
83    struct coord min, struct coord max, enum allow_overlap allow)
8284{
85    if (allow == ao_touch) {
86        if (c.x <= min.x-r || c.x >= max.x+r)
87            return 0;
88        if (c.y <= min.y-r || c.y >= max.y+r)
89            return 0;
90    }
8391    if (c.x < min.x-r || c.x > max.x+r)
8492        return 0;
8593    if (c.y < min.y-r || c.y > max.y+r)
...... 
8997
9098
9199static int rect_rect_overlap(struct coord min1, struct coord max1,
92    struct coord min2, struct coord max2)
100    struct coord min2, struct coord max2, enum allow_overlap allow)
93101{
102    if (allow == ao_touch) {
103        if (max1.x <= min2.x || max2.x <= min1.x)
104            return 0;
105        if (max1.y <= min2.y || max2.y <= min1.y)
106            return 0;
107    }
94108    if (max1.x < min2.x || max2.x < min1.x)
95109        return 0;
96110    if (max1.y < min2.y || max2.y < min1.y)
...... 
99113}
100114
101115
102static int shapes_overlap(const struct shape *a, const struct shape *b)
116static int shapes_overlap(const struct shape *a, const struct shape *b,
117    enum allow_overlap allow)
103118{
104119    if (a->circle && !b->circle)
105        return shapes_overlap(b, a);
120        return shapes_overlap(b, a, allow);
106121    if (a->circle) /* b must be circle, too */
107        return circle_circle_overlap(a->center, a->r, b->center, b->r);
122        return circle_circle_overlap(a->center, a->r, b->center, b->r,
123            allow);
108124    if (b->circle) /* a must be rect */
109        return circle_rect_overlap(b->center, b->r, a->min, a->max);
110    return rect_rect_overlap(a->min, a->max, b->min, b->max);
125        return circle_rect_overlap(b->center, b->r, a->min, a->max,
126            allow);
127    return rect_rect_overlap(a->min, a->max, b->min, b->max, allow);
111128}
112129
113130
...... 
115132
116133
117134static int test_overlap(const struct inst *a, const struct inst *b,
118    const struct shape *other);
135    const struct shape *other, enum allow_overlap allow);
119136
120137
121138static int do_circle(const struct inst *next, const struct shape *other,
122    unit_type x, unit_type y, unit_type r)
139    unit_type x, unit_type y, unit_type r, enum allow_overlap allow)
123140{
124141    struct shape shape = {
125142        .circle = 1,
...... 
131148    };
132149
133150    if (next)
134        return test_overlap(next, NULL, &shape);
135    return shapes_overlap(other, &shape);
151        return test_overlap(next, NULL, &shape, allow);
152    return shapes_overlap(other, &shape, allow);
136153}
137154
138155
139156static int do_rect(const struct inst *next, const struct shape *other,
140    unit_type x, unit_type y, unit_type w, unit_type h)
157    unit_type x, unit_type y, unit_type w, unit_type h,
158    enum allow_overlap allow)
141159{
142160    struct shape shape = {
143161        .circle = 0,
...... 
152170    };
153171
154172    if (next)
155        return test_overlap(next, NULL, &shape);
156    return shapes_overlap(other, &shape);
173        return test_overlap(next, NULL, &shape, allow);
174    return shapes_overlap(other, &shape, allow);
157175}
158176
159177
160178static int test_overlap(const struct inst *a, const struct inst *b,
161    const struct shape *other)
179    const struct shape *other, enum allow_overlap allow)
162180{
163181    struct coord min, max;
164182    unit_type h, w, r;
...... 
183201    w = max.x-min.x;
184202
185203    if (!rounded)
186        return do_rect(b, other, min.x, min.y, w, h);
204        return do_rect(b, other, min.x, min.y, w, h, allow);
187205
188206    if (h > w) {
189207        r = w/2;
190        return do_circle(b, other, min.x+r, max.y-r, r) ||
191            do_rect(b, other, min.x, min.y+r, w, h-2*r) ||
192            do_circle(b, other, min.x+r, min.y+r, r);
208        return do_circle(b, other, min.x+r, max.y-r, r, allow) ||
209            do_rect(b, other, min.x, min.y+r, w, h-2*r, allow) ||
210            do_circle(b, other, min.x+r, min.y+r, r, allow);
193211    } else {
194212        r = h/2;
195        return do_circle(b, other, min.x+r, min.y+r, r) ||
196            do_rect(b, other, min.x+r, min.y, w-2*r, h) ||
197            do_circle(b, other, max.x-r, min.y+r, r);
213        return do_circle(b, other, min.x+r, min.y+r, r, allow) ||
214            do_rect(b, other, min.x+r, min.y, w-2*r, h, allow) ||
215            do_circle(b, other, max.x-r, min.y+r, r, allow);
198216    }
199217}
200218
201219
202int overlap(const struct inst *a, const struct inst *b)
220int overlap(const struct inst *a, const struct inst *b,
221    enum allow_overlap allow)
203222{
204    return test_overlap(a, b, NULL);
223    if (allow == ao_any)
224        return 0;
225    return test_overlap(a, b, NULL, allow);
205226}
overlap.h
11/*
22 * overlap.h - Test for overlaps
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
...... 
1313#ifndef OVERLAP_H
1414#define OVERLAP_H
1515
16#include "inst.h"
16
17enum allow_overlap {
18    ao_none,
19    ao_touch,
20    ao_any,
21};
22
23
24/*
25 * Avoid inst.h -> layer.h -> overlay.h -> inst.h loop
26 */
27
28struct inst;
1729
1830
1931/*
...... 
2739 * "overlap" returns 1 if "a" and "b" have at least one point in common.
2840 */
2941
30int overlap(const struct inst *a, const struct inst *b);
42int overlap(const struct inst *a, const struct inst *b,
43    enum allow_overlap allow);
3144
3245#endif /* !OVERLAP_H */

Archive Download the corresponding diff file

Branches:
master



interactive