Root/hole.c

Source at commit 809e8142b53ba7227241d39d2c4057f7201087a9 created 4 years 7 months ago.
By Werner Almesberger, gui.c (change_world): don't change color of the active frame
1/*
2 * hole.c - Classify holes and connect them with pads
3 *
4 * Written 2010, 2012 by Werner Almesberger
5 * Copyright 2010, 2012 by Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include "error.h"
15#include "inst.h"
16#include "overlap.h"
17#include "hole.h"
18
19
20static int check_through_hole(struct inst *pad, struct inst *hole)
21{
22    if (!overlap(pad, hole, ao_none))
23        return 1;
24    if (!inside(hole, pad)) {
25        fail("hole (line %d) not completely inside "
26            "pad \"%s\" (line %d)", hole->obj->lineno,
27            pad->u.pad.name, pad->obj->lineno);
28        instantiation_error = pad->obj;
29        return 0;
30    }
31    if (hole->u.hole.pad) {
32        /*
33         * A hole can only be on several pads if the pads themselves
34         * overlap. We'll catch this error in refine_copper.
35         */
36        return 1;
37    }
38    if (pad->u.pad.hole) {
39        fail("pad \"%s\" (line %d) has multiple holes (lines %d, %d)",
40            pad->u.pad.name, pad->obj->lineno,
41            hole->obj->lineno, pad->u.pad.hole->obj->lineno);
42        instantiation_error = pad->obj;
43        return 0;
44    }
45    pad->u.pad.hole = hole;
46    hole->u.hole.pad = pad;
47    return 1;
48}
49
50
51static int connect_holes(const struct pkg *pkg)
52{
53    struct inst *pad, *hole;
54
55    for (pad = pkg->insts[ip_pad_copper]; pad; pad = pad->next)
56        for (hole = pkg->insts[ip_hole]; hole; hole = hole->next)
57            if (!check_through_hole(pad, hole))
58                return 0;
59    return 1;
60}
61
62
63static void clear_links(const struct pkg *pkg)
64{
65    struct inst *pad, *hole;
66
67    for (pad = pkg->insts[ip_pad_copper]; pad; pad = pad->next)
68        pad->u.pad.hole = NULL;
69    for (pad = pkg->insts[ip_pad_special]; pad; pad = pad->next)
70        pad->u.pad.hole = NULL;
71    for (hole = pkg->insts[ip_hole]; hole; hole = hole->next)
72        hole->u.hole.pad = NULL;
73}
74
75
76int link_holes(int linked)
77{
78    const struct pkg *pkg;
79
80    for (pkg = pkgs; pkg; pkg = pkg->next) {
81        clear_links(pkg);
82        if (linked)
83            if (!connect_holes(pkg))
84                return 0;
85    }
86        return 1;
87}
88

Archive Download this file

Branches:
master



interactive