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