object.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /* This file is part of the GNU plotutils package. Copyright (C) 1995,
  2. 1996, 1997, 1998, 1999, 2000, 2005, 2008, Free Software Foundation, Inc.
  3. The GNU plotutils package is free software. You may redistribute it
  4. and/or modify it under the terms of the GNU General Public License as
  5. published by the Free Software foundation; either version 2, or (at your
  6. option) any later version.
  7. The GNU plotutils package is distributed in the hope that it will be
  8. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. General Public License for more details.
  11. You should have received a copy of the GNU General Public License along
  12. with the GNU plotutils package; see the file COPYING. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
  14. Boston, MA 02110-1301, USA. */
  15. struct place;
  16. enum object_type
  17. {
  18. OTHER_OBJECT,
  19. BOX_OBJECT,
  20. CIRCLE_OBJECT,
  21. ELLIPSE_OBJECT,
  22. ARC_OBJECT,
  23. SPLINE_OBJECT,
  24. LINE_OBJECT,
  25. ARROW_OBJECT,
  26. MOVE_OBJECT,
  27. TEXT_OBJECT,
  28. BLOCK_OBJECT,
  29. MARK_OBJECT
  30. };
  31. class bounding_box;
  32. class object
  33. {
  34. public:
  35. // ctor, dtor
  36. object();
  37. virtual ~object();
  38. // doubly linked list
  39. object *prev;
  40. object *next;
  41. // public functions (all virtual)
  42. // 1. functions returning positions and dimensions
  43. virtual position origin();
  44. virtual double width();
  45. virtual double radius();
  46. virtual double height();
  47. virtual position north();
  48. virtual position south();
  49. virtual position east();
  50. virtual position west();
  51. virtual position north_east();
  52. virtual position north_west();
  53. virtual position south_east();
  54. virtual position south_west();
  55. virtual position start();
  56. virtual position end();
  57. virtual position center();
  58. virtual place *find_label(const char *); // lookup location by string
  59. // 2. other functions
  60. virtual void move_by(const position &);
  61. virtual int blank();
  62. virtual void update_bounding_box(bounding_box *);
  63. virtual object_type type() = 0;
  64. virtual void print();
  65. virtual void print_text();
  66. };
  67. typedef position (object::*corner)();
  68. struct place
  69. {
  70. object *obj;
  71. double x, y;
  72. };
  73. class string_list;
  74. class path
  75. {
  76. public:
  77. // ctors, dtor
  78. path(corner = 0);
  79. path(char *, corner = 0);
  80. ~path();
  81. // public functions
  82. void append(corner);
  83. void append(char *);
  84. void set_ypath(path *);
  85. int follow(const place &, place *) const;
  86. private:
  87. corner crn;
  88. string_list *label_list;
  89. path *ypath;
  90. };
  91. class object_list
  92. {
  93. public:
  94. // ctor
  95. object_list();
  96. // public functions
  97. void append(object *);
  98. void wrap_up_block(object_list *);
  99. // public data
  100. object *head;
  101. object *tail;
  102. };
  103. declare_ptable(place)
  104. // these go counterclockwise
  105. enum direction
  106. {
  107. RIGHT_DIRECTION,
  108. UP_DIRECTION,
  109. LEFT_DIRECTION,
  110. DOWN_DIRECTION
  111. };
  112. struct graphics_state
  113. {
  114. double x, y;
  115. direction dir;
  116. };
  117. struct saved_state : public graphics_state
  118. {
  119. saved_state *prev;
  120. PTABLE(place) *tbl;
  121. };
  122. class text_item
  123. {
  124. public:
  125. // ctor, dtor
  126. text_item(char *, const char *, int);
  127. ~text_item();
  128. // public data
  129. text_item *next;
  130. char *text;
  131. adjustment adj;
  132. const char *filename;
  133. int lineno;
  134. };
  135. const unsigned long IS_DOTTED = 01;
  136. const unsigned long IS_DASHED = 02;
  137. const unsigned long IS_CLOCKWISE = 04;
  138. const unsigned long IS_INVISIBLE = 020;
  139. const unsigned long HAS_LEFT_ARROW_HEAD = 040;
  140. const unsigned long HAS_RIGHT_ARROW_HEAD = 0100;
  141. const unsigned long HAS_SEGMENT = 0200;
  142. const unsigned long IS_SAME = 0400;
  143. const unsigned long HAS_FROM = 01000;
  144. const unsigned long HAS_AT = 02000;
  145. const unsigned long HAS_WITH = 04000;
  146. const unsigned long HAS_HEIGHT = 010000;
  147. const unsigned long HAS_WIDTH = 020000;
  148. const unsigned long HAS_RADIUS = 040000;
  149. const unsigned long HAS_TO = 0100000;
  150. const unsigned long IS_CHOPPED = 0200000;
  151. const unsigned long IS_DEFAULT_CHOPPED = 0400000;
  152. const unsigned long HAS_THICKNESS = 01000000;
  153. const unsigned long IS_FILLED = 02000000;
  154. const unsigned long IS_DEFAULT_FILLED = 04000000;
  155. const unsigned long IS_ALIGNED = 010000000;
  156. class segment
  157. {
  158. public:
  159. // ctor
  160. segment(const position &, int, segment *);
  161. // public data
  162. int is_absolute;
  163. position pos;
  164. segment *next;
  165. };
  166. class rectangle_object;
  167. class graphic_object;
  168. class linear_object;
  169. class object_spec
  170. {
  171. public:
  172. // ctor, dtor
  173. object_spec(object_type);
  174. ~object_spec();
  175. // public functions (mostly for creating objects)
  176. object *make_object(position *, direction *);
  177. graphic_object *make_box(position *, direction *);
  178. graphic_object *make_block(position *, direction *);
  179. graphic_object *make_text(position *, direction *);
  180. graphic_object *make_ellipse(position *, direction *);
  181. graphic_object *make_circle(position *, direction *);
  182. linear_object *make_line(position *, direction *);
  183. linear_object *make_arc(position *, direction *);
  184. graphic_object *make_linear(position *, direction *);
  185. graphic_object *make_move(position *, direction *);
  186. int position_rectangle(rectangle_object *p, position *curpos, direction *dirp);
  187. // public data (mostly, object attributes)
  188. unsigned long flags;
  189. object_type type;
  190. object_list oblist;
  191. PTABLE(place) *tbl;
  192. double dash_width;
  193. position from;
  194. position to;
  195. position at;
  196. position by;
  197. path *with;
  198. text_item *text;
  199. double height;
  200. double radius;
  201. double width;
  202. double segment_width;
  203. double segment_height;
  204. double start_chop;
  205. double end_chop;
  206. double thickness;
  207. double fill;
  208. direction dir;
  209. segment *segment_list;
  210. position segment_pos;
  211. int segment_is_absolute;
  212. };
  213. object *make_object(object_spec *, position *, direction *);
  214. object *make_mark_object();
  215. object *make_command_object(char *, const char *, int);
  216. // interface to parser in gram.cc
  217. extern void define_variable (const char *name, double val);
  218. extern int lookup_variable (const char *name, double *val);
  219. // function in object.cc
  220. extern void print_picture (object *obj);