obj.h 6.0 KB

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