Root/
Source at commit a3b3ed4925927211fbb2a114cf183678bfc30346 created 13 years 5 months ago. By Xiangfu Liu, use the new version rules. | |
---|---|
1 | /* |
2 | * inst.h - Instance structures |
3 | * |
4 | * Written 2009, 2010 by Werner Almesberger |
5 | * Copyright 2009, 2010 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 | } meas; |
117 | } u; |
118 | struct inst *next; |
119 | }; |
120 | |
121 | |
122 | struct pkg { |
123 | const char *name; /* NULL if global package */ |
124 | struct inst *insts[ip_n]; |
125 | struct inst **next_inst[ip_n]; |
126 | struct sample **samples; |
127 | int n_samples; |
128 | struct pkg *next; |
129 | }; |
130 | |
131 | |
132 | extern struct inst *selected_inst; |
133 | extern struct pkg *pkgs; /* list of packages */ |
134 | extern struct pkg *active_pkg; /* package selected in GUI */ |
135 | extern struct pkg *curr_pkg; /* package currently being instantiated */ |
136 | extern struct bbox active_frame_bbox; |
137 | |
138 | /* |
139 | * frame being instantiated - we need to export this one for meas.c, so that |
140 | * measurements can update the root frame's bounding box. |
141 | */ |
142 | extern struct inst *frame_instantiating; |
143 | |
144 | /* |
145 | * @@@ Note that we over-generalize a bit here: the only item that ever ends up |
146 | * in the global package is currently the root frame. However, we may later |
147 | * allow other items shared by all packages be there as well. |
148 | */ |
149 | |
150 | #define FOR_INST_PRIOS_UP(prio) \ |
151 | for (prio = 0; prio != ip_n; prio++) |
152 | |
153 | #define FOR_INST_PRIOS_DOWN(prio) \ |
154 | for (prio = ip_n-1; prio != (enum inst_prio) -1; prio--) |
155 | |
156 | #define FOR_PKG_INSTS(pkg, prio, inst) \ |
157 | for (inst = (pkg)->insts[prio]; inst; inst = inst->next) |
158 | |
159 | #define FOR_ALL_INSTS(i, prio, inst) \ |
160 | for (i = 0; i != 2; i++) \ |
161 | FOR_PKG_INSTS(i ? active_pkg : pkgs, prio, inst) |
162 | |
163 | |
164 | int bright(const struct inst *inst); |
165 | |
166 | void inst_select_outside(void *item, void (*deselect)(void *item)); |
167 | int inst_select(struct coord pos); |
168 | void inst_deselect(void); |
169 | |
170 | void inst_select_vec(struct vec *vec); |
171 | void inst_select_obj(struct obj *obj); |
172 | |
173 | struct inst *inst_find_point(struct coord pos); |
174 | int inst_find_point_selected(struct coord pos, struct inst **res); |
175 | struct coord inst_get_point(const struct inst *inst); |
176 | int inst_anchors(struct inst *inst, struct vec ***anchors); |
177 | struct vec *inst_get_vec(const struct inst *inst); |
178 | |
179 | int inst_vec(struct vec *vec, struct coord base); |
180 | int inst_line(struct obj *obj, struct coord a, struct coord b, unit_type width); |
181 | int inst_rect(struct obj *obj, struct coord a, struct coord b, unit_type width); |
182 | int inst_pad(struct obj *obj, const char *name, struct coord a, struct coord b); |
183 | int inst_hole(struct obj *obj, struct coord a, struct coord b); |
184 | int inst_arc(struct obj *obj, struct coord center, struct coord start, |
185 | struct coord stop, unit_type width); |
186 | struct inst *find_meas_hint(const struct obj *obj); |
187 | int inst_meas(struct obj *obj, struct coord from, struct coord to); |
188 | void inst_meas_hint(struct obj *obj, unit_type offset); |
189 | |
190 | void inst_begin_active(int active); |
191 | void inst_end_active(void); |
192 | |
193 | void inst_begin_frame(struct obj *obj, struct frame *frame, |
194 | struct coord base, int active, int is_active_frame); |
195 | void inst_end_frame(const struct frame *frame); |
196 | |
197 | void inst_select_pkg(const char *name); |
198 | |
199 | struct bbox inst_get_bbox(void); |
200 | |
201 | void inst_start(void); |
202 | void inst_commit(void); |
203 | void inst_revert(void); |
204 | |
205 | void inst_draw(void); |
206 | void inst_highlight_vecs(int (*pick)(struct inst *inst, void *user), |
207 | void *user); |
208 | struct inst *inst_find_vec(struct coord pos, |
209 | int (*pick)(struct inst *inst, void *user), void *user); |
210 | struct inst *insts_ip_vec(void); |
211 | |
212 | struct pix_buf *inst_draw_move(struct inst *inst, struct coord pos, int i); |
213 | int inst_do_move_to(struct inst *inst, struct inst *to, int i); |
214 | struct pix_buf *inst_hover(struct inst *inst); |
215 | void inst_begin_drag_move(struct inst *inst, int i); |
216 | void inst_delete(struct inst *inst); |
217 | |
218 | #endif /* !INST_H */ |
219 |
Branches:
master