Root/
| 1 | /* |
| 2 | * obj.h - Object definition model |
| 3 | * |
| 4 | * Written 2009-2012 by Werner Almesberger |
| 5 | * Copyright 2009-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 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 | |
| 64 | /* key: 0 if the variable is set, 1 if the variable is compared */ |
| 65 | int key; |
| 66 | |
| 67 | /* for the GUI */ |
| 68 | GtkWidget *widget; |
| 69 | |
| 70 | /* for evaluation */ |
| 71 | int visited; |
| 72 | }; |
| 73 | |
| 74 | struct value { |
| 75 | struct expr *expr; |
| 76 | struct value *next; |
| 77 | |
| 78 | /* back reference, NULL if loop */ |
| 79 | struct row *row; |
| 80 | |
| 81 | /* for the GUI */ |
| 82 | GtkWidget *widget; |
| 83 | }; |
| 84 | |
| 85 | struct row { |
| 86 | struct value *values; |
| 87 | struct row *next; |
| 88 | |
| 89 | /* back reference */ |
| 90 | struct table *table; |
| 91 | }; |
| 92 | |
| 93 | struct table { |
| 94 | struct var *vars; |
| 95 | struct row *rows; |
| 96 | struct table *next; |
| 97 | |
| 98 | /* used during generation and when editing */ |
| 99 | struct row *curr_row; |
| 100 | |
| 101 | /* GUI use */ |
| 102 | struct row *active_row; |
| 103 | |
| 104 | /* For searching */ |
| 105 | struct row *found_row; /* NULL if not found yet */ |
| 106 | }; |
| 107 | |
| 108 | struct loop { |
| 109 | struct var var; |
| 110 | struct value from; |
| 111 | struct value to; |
| 112 | struct loop *next; |
| 113 | |
| 114 | /* used during generation */ |
| 115 | double curr_value; |
| 116 | |
| 117 | /* GUI use */ |
| 118 | int active; /* n-th iteration is active, 0 based */ |
| 119 | double n; /* start value when it was active */ |
| 120 | int iterations; /* iterations when it was active */ |
| 121 | |
| 122 | /* For searching */ |
| 123 | int found; /* -1 if not found yet */ |
| 124 | |
| 125 | /* for evaluation */ |
| 126 | int initialized; |
| 127 | }; |
| 128 | |
| 129 | struct sample; |
| 130 | |
| 131 | struct vec { |
| 132 | char nul_tag; /* tag for identifying vectors */ |
| 133 | const char *name; /* NULL if anonymous */ |
| 134 | struct expr *x; |
| 135 | struct expr *y; |
| 136 | struct vec *base; /* NULL if frame */ |
| 137 | struct vec *next; |
| 138 | |
| 139 | /* used during generation */ |
| 140 | struct coord pos; |
| 141 | |
| 142 | /* used when editing */ |
| 143 | struct frame *frame; |
| 144 | |
| 145 | /* index into table of samples */ |
| 146 | int n; |
| 147 | |
| 148 | /* for re-ordering after a move */ |
| 149 | int mark; |
| 150 | |
| 151 | /* for dumping */ |
| 152 | int dumped; |
| 153 | |
| 154 | /* for the GUI */ |
| 155 | GtkWidget *list_widget; /* NULL if items aren't shown */ |
| 156 | }; |
| 157 | |
| 158 | struct frame { |
| 159 | const char *name; /* NULL if top-level */ |
| 160 | struct table *tables; |
| 161 | struct loop *loops; |
| 162 | struct vec *vecs; |
| 163 | struct obj *objs; |
| 164 | struct frame *next; |
| 165 | |
| 166 | /* used during generation */ |
| 167 | const struct frame *curr_parent; |
| 168 | |
| 169 | /* generating and editing */ |
| 170 | struct obj *active_ref; |
| 171 | |
| 172 | /* for searching */ |
| 173 | struct obj *found_ref; /* NULL if not found yet */ |
| 174 | |
| 175 | /* index into bit vector in samples */ |
| 176 | int n; |
| 177 | |
| 178 | /* for dumping */ |
| 179 | int dumped; |
| 180 | |
| 181 | /* for the GUI */ |
| 182 | GtkWidget *label; |
| 183 | }; |
| 184 | |
| 185 | enum obj_type { |
| 186 | ot_frame, |
| 187 | ot_rect, |
| 188 | ot_pad, |
| 189 | ot_hole, |
| 190 | ot_line, |
| 191 | ot_arc, |
| 192 | ot_meas, |
| 193 | ot_iprint, |
| 194 | }; |
| 195 | |
| 196 | struct frame_ref { |
| 197 | struct frame *ref; |
| 198 | int lineno; |
| 199 | }; |
| 200 | |
| 201 | struct rect { |
| 202 | struct vec *other; /* NULL if frame origin */ |
| 203 | struct expr *width; |
| 204 | }; |
| 205 | |
| 206 | struct pad { |
| 207 | char *name; |
| 208 | struct vec *other; /* NULL if frame origin */ |
| 209 | int rounded; |
| 210 | enum pad_type type; |
| 211 | }; |
| 212 | |
| 213 | struct hole { |
| 214 | struct vec *other; /* NULL if frame origin */ |
| 215 | }; |
| 216 | |
| 217 | struct arc { |
| 218 | struct vec *start; /* NULL if frame origin */ |
| 219 | struct vec *end; /* NULL if this is a circle */ |
| 220 | struct expr *width; |
| 221 | }; |
| 222 | |
| 223 | struct iprint { |
| 224 | struct expr *expr; |
| 225 | }; |
| 226 | |
| 227 | struct obj { |
| 228 | enum obj_type type; |
| 229 | const char *name; /* NULL if anonymous */ |
| 230 | union { |
| 231 | struct frame_ref frame; |
| 232 | struct rect rect; |
| 233 | struct rect line; |
| 234 | struct pad pad; |
| 235 | struct hole hole; |
| 236 | struct arc arc; |
| 237 | struct meas meas; |
| 238 | struct iprint iprint; |
| 239 | } u; |
| 240 | struct frame *frame; |
| 241 | struct vec *base; |
| 242 | struct obj *next; |
| 243 | int lineno; |
| 244 | |
| 245 | /* for dumping */ |
| 246 | int dumped; |
| 247 | |
| 248 | /* for the GUI */ |
| 249 | GtkWidget *list_widget; /* NULL if items are not shown */ |
| 250 | }; |
| 251 | |
| 252 | |
| 253 | extern char *pkg_name; /* anonymous common package first */ |
| 254 | extern struct frame *frames; /* root frame first */ |
| 255 | extern struct frame *active_frame; |
| 256 | extern void *instantiation_error; |
| 257 | extern enum allow_overlap allow_overlap; |
| 258 | extern int holes_linked; |
| 259 | |
| 260 | |
| 261 | struct inst; |
| 262 | |
| 263 | /* |
| 264 | * Search callback from inst, invoked after the instance has been populated. |
| 265 | */ |
| 266 | |
| 267 | void find_inst(const struct inst *inst); |
| 268 | |
| 269 | /* |
| 270 | * If invoking search_inst before calling "instantiate", loop and tables are |
| 271 | * adjusted such that an instance matching the one passed to search_inst will |
| 272 | * become active. Note that this doesn't necessarily succeed, in which case no |
| 273 | * change is made. Also, if multiple matches are encountered, the result is |
| 274 | * arbitrary. |
| 275 | */ |
| 276 | |
| 277 | void search_inst(const struct inst *inst); |
| 278 | |
| 279 | int obj_anchors(struct obj *obj, struct vec ***anchors); |
| 280 | |
| 281 | int instantiate(void); |
| 282 | void obj_cleanup(void); |
| 283 | |
| 284 | #endif /* !OBJ_H */ |
| 285 |
Branches:
master
