inst.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * inst.h - Instance structures
  3. *
  4. * Written 2009, 2010, 2012 by Werner Almesberger
  5. * Copyright 2009, 2010, 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 INST_H
  13. #define INST_H
  14. #include <stdint.h>
  15. #include <stdio.h>
  16. #include "coord.h"
  17. #include "obj.h"
  18. #include "meas.h"
  19. enum mode {
  20. mode_inactive, /* on inactive frame */
  21. mode_active, /* on active frame */
  22. mode_selected, /* item is selected */
  23. mode_hover, /* hovering over item's contact area */
  24. mode_n /* number of modes */
  25. };
  26. struct bbox {
  27. struct coord min;
  28. struct coord max;
  29. };
  30. enum inst_prio {
  31. ip_frame, /* frames have their own selection */
  32. ip_pad_copper, /* pads also accept clicks inside; pads with copper */
  33. ip_pad_special, /* pads with only solder paste or mask, on top */
  34. ip_hole, /* holes in pads must be on top to be seen */
  35. ip_circ, /* circles don't overlap easily */
  36. ip_arc, /* arcs are like circles, just shorter */
  37. ip_rect, /* rectangles have plenty of sides */
  38. ip_meas, /* mesurements are like lines but set a bit apart */
  39. ip_line, /* lines are easly overlapped by other things */
  40. ip_vec, /* vectors only have the end point */
  41. ip_n, /* number of priorities */
  42. };
  43. struct inst;
  44. struct inst_ops {
  45. void (*debug)(struct inst *self);
  46. void (*save)(FILE *file, struct inst *self);
  47. void (*draw)(struct inst *self);
  48. struct pix_buf *(*hover)(struct inst *self);
  49. unit_type (*distance)(struct inst *self, struct coord pos,
  50. unit_type scale);
  51. void (*select)(struct inst *self);
  52. void (*begin_drag_move)(struct inst *from, int i);
  53. struct inst *(*find_point)(struct inst *self, struct coord pos);
  54. struct pix_buf *(*draw_move)(struct inst *inst,
  55. struct coord pos, int i);
  56. void (*end_drag_move)(void);
  57. /* arcs and measurements need this special override */
  58. void (*do_move_to)(struct inst *inst, struct inst *to, int i);
  59. };
  60. struct inst {
  61. const struct inst_ops *ops;
  62. enum inst_prio prio; /* currently only used for icon selection */
  63. struct coord base;
  64. struct bbox bbox;
  65. struct vec *vec; /* NULL if not vector */
  66. struct obj *obj; /* NULL if not object */
  67. struct inst *outer; /* frame containing this item */
  68. int active;
  69. union {
  70. struct {
  71. int highlighted; /* for measurements */
  72. struct coord end;
  73. } vec;
  74. struct {
  75. struct frame *ref;
  76. int active;
  77. } frame;
  78. const char *name;
  79. struct {
  80. unit_type width;
  81. struct coord end;
  82. } rect;
  83. struct {
  84. char *name;
  85. struct coord other;
  86. layer_type layers; /* bit-set of layers */
  87. struct inst *hole; /* through-hole or NULL */
  88. } pad;
  89. struct {
  90. struct coord other;
  91. layer_type layers; /* bit-set of layers (mech only) */
  92. struct inst *pad; /* through-hole pad of NULL */
  93. } hole;
  94. struct {
  95. unit_type r;
  96. double a1, a2;
  97. unit_type width;
  98. } arc;
  99. struct {
  100. struct coord end;
  101. double offset;
  102. int valid; /* only set if references exist */
  103. } meas;
  104. } u;
  105. struct inst *next;
  106. };
  107. struct pkg {
  108. const char *name; /* NULL if global package */
  109. struct inst *insts[ip_n];
  110. struct inst **next_inst[ip_n];
  111. struct bbox bbox; /* bbox only of items in this package */
  112. struct sample **samples;
  113. int n_samples;
  114. struct pkg *next;
  115. };
  116. extern struct inst *selected_inst;
  117. extern struct pkg *pkgs; /* list of packages */
  118. extern struct pkg *active_pkg; /* package selected in GUI */
  119. extern struct pkg *curr_pkg; /* package currently being instantiated */
  120. extern struct pkg *reachable_pkg; /* package reachable with active vars */
  121. extern struct bbox active_frame_bbox;
  122. /*
  123. * frame being instantiated - we need to export this one for meas.c, so that
  124. * measurements can update the root frame's bounding box.
  125. */
  126. extern struct inst *frame_instantiating;
  127. /*
  128. * @@@ Note that we over-generalize a bit here: the only item that ever ends up
  129. * in the global package is currently the root frame. However, we may later
  130. * allow other items shared by all packages be there as well.
  131. */
  132. #define FOR_INST_PRIOS_UP(prio) \
  133. for (prio = 0; prio != ip_n; prio++)
  134. #define FOR_INST_PRIOS_DOWN(prio) \
  135. for (prio = ip_n-1; prio != (enum inst_prio) -1; prio--)
  136. #define FOR_PKG_INSTS(pkg, prio, inst) \
  137. for (inst = (pkg) ? (pkg)->insts[prio] : NULL; inst; inst = inst->next)
  138. #define FOR_ALL_INSTS(i, prio, inst) \
  139. for (i = 0; i != 2; i++) \
  140. FOR_PKG_INSTS(i ? active_pkg : pkgs, prio, inst)
  141. int bright(const struct inst *inst);
  142. void inst_select_outside(void *item, void (*deselect)(void *item));
  143. int inst_select(struct coord pos);
  144. void inst_deselect(void);
  145. void inst_select_vec(struct vec *vec);
  146. void inst_select_obj(struct obj *obj);
  147. struct inst *inst_find_point(struct coord pos);
  148. int inst_find_point_selected(struct coord pos, struct inst **res);
  149. struct coord inst_get_point(const struct inst *inst);
  150. int inst_anchors(struct inst *inst, struct vec ***anchors);
  151. struct vec *inst_get_vec(const struct inst *inst);
  152. int inst_vec(struct vec *vec, struct coord base);
  153. int inst_line(struct obj *obj, struct coord a, struct coord b, unit_type width);
  154. int inst_rect(struct obj *obj, struct coord a, struct coord b, unit_type width);
  155. int inst_pad(struct obj *obj, const char *name, struct coord a, struct coord b);
  156. int inst_hole(struct obj *obj, struct coord a, struct coord b);
  157. int inst_arc(struct obj *obj, struct coord center, struct coord start,
  158. struct coord stop, unit_type width);
  159. struct inst *find_meas_hint(const struct obj *obj);
  160. int inst_meas(struct obj *obj, struct coord from, struct coord to);
  161. void inst_meas_hint(struct obj *obj, unit_type offset);
  162. void inst_begin_active(int active);
  163. void inst_end_active(void);
  164. void inst_begin_frame(struct obj *obj, struct frame *frame,
  165. struct coord base, int active, int is_active_frame);
  166. void inst_end_frame(const struct frame *frame);
  167. void inst_select_pkg(const char *name, int active);
  168. struct bbox inst_get_bbox(const struct pkg *pkg);
  169. void inst_start(void);
  170. void inst_commit(void);
  171. void inst_revert(void);
  172. void inst_draw(void);
  173. void inst_highlight_vecs(int (*pick)(struct inst *inst, void *user),
  174. void *user);
  175. struct inst *inst_find_vec(struct coord pos,
  176. int (*pick)(struct inst *inst, void *user), void *user);
  177. struct inst *insts_ip_vec(void);
  178. struct pix_buf *inst_draw_move(struct inst *inst, struct coord pos, int i);
  179. int inst_do_move_to(struct inst *inst, struct inst *to, int i);
  180. struct pix_buf *inst_hover(struct inst *inst);
  181. void inst_begin_drag_move(struct inst *inst, int i);
  182. void inst_delete(struct inst *inst);
  183. #endif /* !INST_H */