Root/
| 1 | /* |
| 2 | * inst.h - Instance structures |
| 3 | * |
| 4 | * Written 2009, 2010, 2012 by Werner Almesberger |
| 5 | * Copyright 2009, 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 | #ifndef INST_H |
| 15 | #define INST_H |
| 16 | |
| 17 | #include <stdint.h> |
| 18 | #include <stdio.h> |
| 19 | |
| 20 | #include "coord.h" |
| 21 | #include "obj.h" |
| 22 | #include "meas.h" |
| 23 | |
| 24 | |
| 25 | enum mode { |
| 26 | mode_inactive, /* on inactive frame */ |
| 27 | mode_active, /* on active frame */ |
| 28 | mode_selected, /* item is selected */ |
| 29 | mode_hover, /* hovering over item's contact area */ |
| 30 | mode_n /* number of modes */ |
| 31 | }; |
| 32 | |
| 33 | struct bbox { |
| 34 | struct coord min; |
| 35 | struct coord max; |
| 36 | }; |
| 37 | |
| 38 | |
| 39 | enum inst_prio { |
| 40 | ip_frame, /* frames have their own selection */ |
| 41 | ip_pad_copper, /* pads also accept clicks inside; pads with copper */ |
| 42 | 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 */ |
| 44 | ip_circ, /* circles don't overlap easily */ |
| 45 | ip_arc, /* arcs are like circles, just shorter */ |
| 46 | ip_rect, /* rectangles have plenty of sides */ |
| 47 | ip_meas, /* mesurements are like lines but set a bit apart */ |
| 48 | ip_line, /* lines are easly overlapped by other things */ |
| 49 | ip_vec, /* vectors only have the end point */ |
| 50 | ip_n, /* number of priorities */ |
| 51 | }; |
| 52 | |
| 53 | |
| 54 | struct inst; |
| 55 | |
| 56 | |
| 57 | struct inst_ops { |
| 58 | void (*debug)(struct inst *self); |
| 59 | void (*save)(FILE *file, struct inst *self); |
| 60 | void (*draw)(struct inst *self); |
| 61 | struct pix_buf *(*hover)(struct inst *self); |
| 62 | unit_type (*distance)(struct inst *self, struct coord pos, |
| 63 | unit_type scale); |
| 64 | void (*select)(struct inst *self); |
| 65 | void (*begin_drag_move)(struct inst *from, int i); |
| 66 | struct inst *(*find_point)(struct inst *self, struct coord pos); |
| 67 | struct pix_buf *(*draw_move)(struct inst *inst, |
| 68 | struct coord pos, int i); |
| 69 | void (*end_drag_move)(void); |
| 70 | /* arcs and measurements need this special override */ |
| 71 | void (*do_move_to)(struct inst *inst, struct inst *to, int i); |
| 72 | }; |
| 73 | |
| 74 | struct inst { |
| 75 | const struct inst_ops *ops; |
| 76 | enum inst_prio prio; /* currently only used for icon selection */ |
| 77 | struct coord base; |
| 78 | struct bbox bbox; |
| 79 | struct vec *vec; /* NULL if not vector */ |
| 80 | struct obj *obj; /* NULL if not object */ |
| 81 | struct inst *outer; /* frame containing this item */ |
| 82 | int active; |
| 83 | union { |
| 84 | struct { |
| 85 | int highlighted; /* for measurements */ |
| 86 | struct coord end; |
| 87 | } vec; |
| 88 | struct { |
| 89 | struct frame *ref; |
| 90 | int active; |
| 91 | } frame; |
| 92 | const char *name; |
| 93 | struct { |
| 94 | unit_type width; |
| 95 | struct coord end; |
| 96 | } rect; |
| 97 | struct { |
| 98 | char *name; |
| 99 | struct coord other; |
| 100 | layer_type layers; /* bit-set of layers */ |
| 101 | struct inst *hole; /* through-hole or NULL */ |
| 102 | } pad; |
| 103 | struct { |
| 104 | struct coord other; |
| 105 | layer_type layers; /* bit-set of layers (mech only) */ |
| 106 | struct inst *pad; /* through-hole pad of NULL */ |
| 107 | } hole; |
| 108 | struct { |
| 109 | unit_type r; |
| 110 | double a1, a2; |
| 111 | unit_type width; |
| 112 | } arc; |
| 113 | struct { |
| 114 | struct coord end; |
| 115 | double offset; |
| 116 | int valid; /* only set if references exist */ |
| 117 | } meas; |
| 118 | } u; |
| 119 | struct inst *next; |
| 120 | }; |
| 121 | |
| 122 | |
| 123 | struct pkg { |
| 124 | const char *name; /* NULL if global package */ |
| 125 | struct inst *insts[ip_n]; |
| 126 | struct inst **next_inst[ip_n]; |
| 127 | struct bbox bbox; /* bbox only of items in this package */ |
| 128 | struct sample **samples; |
| 129 | int n_samples; |
| 130 | struct pkg *next; |
| 131 | }; |
| 132 | |
| 133 | |
| 134 | extern struct inst *selected_inst; |
| 135 | extern struct pkg *pkgs; /* list of packages */ |
| 136 | extern struct pkg *active_pkg; /* package selected in GUI */ |
| 137 | extern struct pkg *curr_pkg; /* package currently being instantiated */ |
| 138 | extern struct pkg *reachable_pkg; /* package reachable with active vars */ |
| 139 | extern struct bbox active_frame_bbox; |
| 140 | |
| 141 | /* |
| 142 | * frame being instantiated - we need to export this one for meas.c, so that |
| 143 | * measurements can update the root frame's bounding box. |
| 144 | */ |
| 145 | extern struct inst *frame_instantiating; |
| 146 | |
| 147 | /* |
| 148 | * @@@ Note that we over-generalize a bit here: the only item that ever ends up |
| 149 | * in the global package is currently the root frame. However, we may later |
| 150 | * allow other items shared by all packages be there as well. |
| 151 | */ |
| 152 | |
| 153 | #define FOR_INST_PRIOS_UP(prio) \ |
| 154 | for (prio = 0; prio != ip_n; prio++) |
| 155 | |
| 156 | #define FOR_INST_PRIOS_DOWN(prio) \ |
| 157 | for (prio = ip_n-1; prio != (enum inst_prio) -1; prio--) |
| 158 | |
| 159 | #define FOR_PKG_INSTS(pkg, prio, inst) \ |
| 160 | for (inst = (pkg) ? (pkg)->insts[prio] : NULL; inst; inst = inst->next) |
| 161 | |
| 162 | #define FOR_ALL_INSTS(i, prio, inst) \ |
| 163 | for (i = 0; i != 2; i++) \ |
| 164 | FOR_PKG_INSTS(i ? active_pkg : pkgs, prio, inst) |
| 165 | |
| 166 | |
| 167 | int bright(const struct inst *inst); |
| 168 | |
| 169 | void inst_select_outside(void *item, void (*deselect)(void *item)); |
| 170 | int inst_select(struct coord pos); |
| 171 | void inst_deselect(void); |
| 172 | |
| 173 | void inst_select_vec(struct vec *vec); |
| 174 | void inst_select_obj(struct obj *obj); |
| 175 | |
| 176 | struct inst *inst_find_point(struct coord pos); |
| 177 | int inst_find_point_selected(struct coord pos, struct inst **res); |
| 178 | struct coord inst_get_point(const struct inst *inst); |
| 179 | int inst_anchors(struct inst *inst, struct vec ***anchors); |
| 180 | struct vec *inst_get_vec(const struct inst *inst); |
| 181 | |
| 182 | int inst_vec(struct vec *vec, struct coord base); |
| 183 | int inst_line(struct obj *obj, struct coord a, struct coord b, unit_type width); |
| 184 | int inst_rect(struct obj *obj, struct coord a, struct coord b, unit_type width); |
| 185 | int inst_pad(struct obj *obj, const char *name, struct coord a, struct coord b); |
| 186 | int inst_hole(struct obj *obj, struct coord a, struct coord b); |
| 187 | int inst_arc(struct obj *obj, struct coord center, struct coord start, |
| 188 | struct coord stop, unit_type width); |
| 189 | struct inst *find_meas_hint(const struct obj *obj); |
| 190 | int inst_meas(struct obj *obj, struct coord from, struct coord to); |
| 191 | void inst_meas_hint(struct obj *obj, unit_type offset); |
| 192 | |
| 193 | void inst_begin_active(int active); |
| 194 | void inst_end_active(void); |
| 195 | |
| 196 | void inst_begin_frame(struct obj *obj, struct frame *frame, |
| 197 | struct coord base, int active, int is_active_frame); |
| 198 | void inst_end_frame(const struct frame *frame); |
| 199 | |
| 200 | void inst_select_pkg(const char *name, int active); |
| 201 | |
| 202 | struct bbox inst_get_bbox(const struct pkg *pkg); |
| 203 | |
| 204 | void inst_start(void); |
| 205 | void inst_commit(void); |
| 206 | void inst_revert(void); |
| 207 | |
| 208 | void inst_draw(void); |
| 209 | void inst_highlight_vecs(int (*pick)(struct inst *inst, void *user), |
| 210 | void *user); |
| 211 | struct inst *inst_find_vec(struct coord pos, |
| 212 | int (*pick)(struct inst *inst, void *user), void *user); |
| 213 | struct inst *insts_ip_vec(void); |
| 214 | |
| 215 | struct pix_buf *inst_draw_move(struct inst *inst, struct coord pos, int i); |
| 216 | int inst_do_move_to(struct inst *inst, struct inst *to, int i); |
| 217 | struct pix_buf *inst_hover(struct inst *inst); |
| 218 | void inst_begin_drag_move(struct inst *inst, int i); |
| 219 | void inst_delete(struct inst *inst); |
| 220 | |
| 221 | #endif /* !INST_H */ |
| 222 |
Branches:
master
