Root/
Source at commit e6b2658a65f4143f68acebde8771f7e5debc6d15 created 13 years 7 months ago. By werner, Added relaxation of pad overlap checking. Not GUI-settable yet. | |
---|---|
1 | /* |
2 | * obj.h - Object definition model |
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 OBJ_H |
15 | #define OBJ_H |
16 | |
17 | #include <assert.h> |
18 | #include <gtk/gtk.h> |
19 | |
20 | #include "expr.h" |
21 | #include "coord.h" |
22 | #include "meas.h" |
23 | #include "overlap.h" |
24 | #include "layer.h" |
25 | |
26 | |
27 | /* |
28 | * Objects contain various fields that help to select instances under various |
29 | * conditions. They are "current", "active", and "found": |
30 | * |
31 | * - current: the path taken while instantiating. E.g., we may make one frame |
32 | * reference the "current" reference of this frame and then recurse into it. |
33 | * "Current" is reset to a null value after instantiation is complete, to |
34 | * allow other functions (such as expression evaluation) to distinguish |
35 | * between instantiation and editing. |
36 | * |
37 | * - active: the path selected by the user, through the GUI. This allows the |
38 | * user to reach any instance, similar to how instantiation visits all |
39 | * instances. The difference to "current" is that "active" is persistent |
40 | * across instantiation while "current" iterates through all possible values |
41 | * during instantiation. |
42 | * |
43 | * - found: then clicking on an unselected instance, fped will try to activate |
44 | * this instance. In order to do so, it needs to determine which choices need |
45 | * to be activated to reach the instance. "Found" records this information. |
46 | * At the end of the search, all "found" choices become "active". |
47 | * |
48 | * If, during the search, an instance can be reached with the "found" choice |
49 | * being equal to the choice active at that time, "found" will not be set to |
50 | * any other value. This prevents searches from affecting choices that play |
51 | * no role in the selection of the instance. |
52 | */ |
53 | |
54 | |
55 | struct var { |
56 | const char *name; |
57 | struct var *next; |
58 | |
59 | /* back reference */ |
60 | struct frame *frame; |
61 | struct table *table; /* NULL if loop */ |
62 | |
63 | /* for the GUI */ |
64 | GtkWidget *widget; |
65 | |
66 | /* for evaluation */ |
67 | int visited; |
68 | }; |
69 | |
70 | struct value { |
71 | struct expr *expr; |
72 | struct value *next; |
73 | |
74 | /* back reference, NULL if loop */ |
75 | struct row *row; |
76 | |
77 | /* for the GUI */ |
78 | GtkWidget *widget; |
79 | }; |
80 | |
81 | struct row { |
82 | struct value *values; |
83 | struct row *next; |
84 | |
85 | /* back reference */ |
86 | struct table *table; |
87 | }; |
88 | |
89 | struct table { |
90 | struct var *vars; |
91 | struct row *rows; |
92 | struct table *next; |
93 | |
94 | /* used during generation and when editing */ |
95 | struct row *curr_row; |
96 | |
97 | /* GUI use */ |
98 | struct row *active_row; |
99 | |
100 | /* For searching */ |
101 | struct row *found_row; /* NULL if not found yet */ |
102 | }; |
103 | |
104 | struct loop { |
105 | struct var var; |
106 | struct value from; |
107 | struct value to; |
108 | struct loop *next; |
109 | |
110 | /* used during generation */ |
111 | double curr_value; |
112 | |
113 | /* GUI use */ |
114 | int active; /* n-th iteration is active, 0 based */ |
115 | double n; /* start value when it was active */ |
116 | int iterations; /* iterations when it was active */ |
117 | |
118 | /* For searching */ |
119 | int found; /* -1 if not found yet */ |
120 | |
121 | /* for evaluation */ |
122 | int initialized; |
123 | }; |
124 | |
125 | struct sample; |
126 | |
127 | struct vec { |
128 | const char *name; /* NULL if anonymous */ |
129 | struct expr *x; |
130 | struct expr *y; |
131 | struct vec *base; /* NULL if frame */ |
132 | struct vec *next; |
133 | |
134 | /* used during generation */ |
135 | struct coord pos; |
136 | |
137 | /* used when editing */ |
138 | struct frame *frame; |
139 | |
140 | /* index into table of samples */ |
141 | int n; |
142 | |
143 | /* for re-ordering after a move */ |
144 | int mark; |
145 | |
146 | /* for dumping */ |
147 | int dumped; |
148 | |
149 | /* for the GUI */ |
150 | GtkWidget *list_widget; /* NULL if items aren't shown */ |
151 | }; |
152 | |
153 | struct frame { |
154 | const char *name; /* NULL if top-level */ |
155 | struct table *tables; |
156 | struct loop *loops; |
157 | struct vec *vecs; |
158 | struct obj *objs; |
159 | struct frame *next; |
160 | |
161 | /* used during generation */ |
162 | const struct frame *curr_parent; |
163 | |
164 | /* generating and editing */ |
165 | struct obj *active_ref; |
166 | |
167 | /* for searching */ |
168 | struct obj *found_ref; /* NULL if not found yet */ |
169 | |
170 | /* index into bit vector in samples */ |
171 | int n; |
172 | |
173 | /* for dumping */ |
174 | int dumped; |
175 | |
176 | /* for the GUI */ |
177 | GtkWidget *label; |
178 | }; |
179 | |
180 | enum obj_type { |
181 | ot_frame, |
182 | ot_rect, |
183 | ot_pad, |
184 | ot_hole, |
185 | ot_line, |
186 | ot_arc, |
187 | ot_meas, |
188 | }; |
189 | |
190 | struct frame_ref { |
191 | struct frame *ref; |
192 | int lineno; |
193 | }; |
194 | |
195 | struct rect { |
196 | struct vec *other; /* NULL if frame origin */ |
197 | struct expr *width; |
198 | }; |
199 | |
200 | struct pad { |
201 | char *name; |
202 | struct vec *other; /* NULL if frame origin */ |
203 | int rounded; |
204 | enum pad_type type; |
205 | }; |
206 | |
207 | struct hole { |
208 | struct vec *other; /* NULL if frame origin */ |
209 | }; |
210 | |
211 | struct arc { |
212 | struct vec *start; /* NULL if frame origin */ |
213 | struct vec *end; /* NULL if this is a circle */ |
214 | struct expr *width; |
215 | }; |
216 | |
217 | struct obj { |
218 | enum obj_type type; |
219 | const char *name; /* NULL if anonymous */ |
220 | union { |
221 | struct frame_ref frame; |
222 | struct rect rect; |
223 | struct rect line; |
224 | struct pad pad; |
225 | struct hole hole; |
226 | struct arc arc; |
227 | struct meas meas; |
228 | } u; |
229 | struct frame *frame; |
230 | struct vec *base; |
231 | struct obj *next; |
232 | int lineno; |
233 | |
234 | /* for dumping */ |
235 | int dumped; |
236 | |
237 | /* for the GUI */ |
238 | GtkWidget *list_widget; /* NULL if items are not shown */ |
239 | }; |
240 | |
241 | |
242 | extern char *pkg_name; /* anonymous common package first */ |
243 | extern struct frame *frames; /* root frame first */ |
244 | extern struct frame *active_frame; |
245 | extern void *instantiation_error; |
246 | extern enum allow_overlap allow_overlap; |
247 | |
248 | |
249 | struct inst; |
250 | |
251 | /* |
252 | * Search callback from inst, invoked after the instance has been populated. |
253 | */ |
254 | |
255 | void find_inst(const struct inst *inst); |
256 | |
257 | /* |
258 | * If invoking search_inst before calling "instantiate", loop and tables are |
259 | * adjusted such that an instance matching the one passed to search_inst will |
260 | * become active. Note that this doesn't necessarily succeed, in which case no |
261 | * change is made. Also, if multiple matches are encountered, the result is |
262 | * arbitrary. |
263 | */ |
264 | |
265 | void search_inst(const struct inst *inst); |
266 | |
267 | int obj_anchors(struct obj *obj, struct vec ***anchors); |
268 | |
269 | int instantiate(void); |
270 | void obj_cleanup(void); |
271 | |
272 | #endif /* !OBJ_H */ |
273 |
Branches:
master