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