Blame


1 90a99688 2006-04-14 devnull #include <math.h>
2 b6d98463 2006-04-14 devnull #include <stdio.h>
3 b6d98463 2006-04-14 devnull #include "pic.h"
4 b6d98463 2006-04-14 devnull #include "y.tab.h"
5 b6d98463 2006-04-14 devnull
6 b6d98463 2006-04-14 devnull obj*
7 b6d98463 2006-04-14 devnull linegen(int type)
8 b6d98463 2006-04-14 devnull {
9 b6d98463 2006-04-14 devnull static double prevdx = HT;
10 b6d98463 2006-04-14 devnull static double prevdy = 0;
11 b6d98463 2006-04-14 devnull static double prevw = HT10;
12 b6d98463 2006-04-14 devnull static double prevh = HT5;
13 b6d98463 2006-04-14 devnull int i, j, some, head, ddtype, invis, chop;
14 b6d98463 2006-04-14 devnull double ddval, chop1, chop2, x0, y0, x1, y1;
15 90a99688 2006-04-14 devnull double theta;
16 b6d98463 2006-04-14 devnull double defx, defy;
17 b6d98463 2006-04-14 devnull obj *p, *ppos;
18 b6d98463 2006-04-14 devnull static int xtab[] = { 1, 0, -1, 0 }; /* R=0, U=1, L=2, D=3 */
19 b6d98463 2006-04-14 devnull static int ytab[] = { 0, 1, 0, -1 };
20 b6d98463 2006-04-14 devnull double dx[500], dy[500];
21 b6d98463 2006-04-14 devnull int ndxy;
22 b6d98463 2006-04-14 devnull double nx, ny;
23 b6d98463 2006-04-14 devnull Attr *ap;
24 b6d98463 2006-04-14 devnull
25 b6d98463 2006-04-14 devnull nx = curx;
26 b6d98463 2006-04-14 devnull ny = cury;
27 b6d98463 2006-04-14 devnull defx = getfval("linewid");
28 b6d98463 2006-04-14 devnull defy = getfval("lineht");
29 b6d98463 2006-04-14 devnull prevh = getfval("arrowht");
30 b6d98463 2006-04-14 devnull prevw = getfval("arrowwid");
31 b6d98463 2006-04-14 devnull dx[0] = dy[0] = ndxy = some = head = invis = 0;
32 b6d98463 2006-04-14 devnull chop = chop1 = chop2 = 0;
33 b6d98463 2006-04-14 devnull ddtype = ddval = 0;
34 b6d98463 2006-04-14 devnull for (i = 0; i < nattr; i++) {
35 b6d98463 2006-04-14 devnull ap = &attr[i];
36 b6d98463 2006-04-14 devnull switch (ap->a_type) {
37 b6d98463 2006-04-14 devnull case TEXTATTR:
38 b6d98463 2006-04-14 devnull savetext(ap->a_sub, ap->a_val.p);
39 b6d98463 2006-04-14 devnull break;
40 b6d98463 2006-04-14 devnull case HEAD:
41 b6d98463 2006-04-14 devnull head += ap->a_val.i;
42 b6d98463 2006-04-14 devnull break;
43 b6d98463 2006-04-14 devnull case INVIS:
44 b6d98463 2006-04-14 devnull invis = INVIS;
45 b6d98463 2006-04-14 devnull break;
46 b6d98463 2006-04-14 devnull case CHOP:
47 b6d98463 2006-04-14 devnull if (chop++ == 0)
48 b6d98463 2006-04-14 devnull chop1 = chop2 = ap->a_val.f;
49 b6d98463 2006-04-14 devnull else
50 b6d98463 2006-04-14 devnull chop2 = ap->a_val.f;
51 b6d98463 2006-04-14 devnull break;
52 b6d98463 2006-04-14 devnull case DOT:
53 b6d98463 2006-04-14 devnull case DASH:
54 b6d98463 2006-04-14 devnull ddtype = ap->a_type==DOT ? DOTBIT : DASHBIT;
55 b6d98463 2006-04-14 devnull if (ap->a_sub == DEFAULT)
56 b6d98463 2006-04-14 devnull ddval = getfval("dashwid");
57 b6d98463 2006-04-14 devnull else
58 b6d98463 2006-04-14 devnull ddval = ap->a_val.f;
59 b6d98463 2006-04-14 devnull break;
60 b6d98463 2006-04-14 devnull case SAME:
61 b6d98463 2006-04-14 devnull dx[ndxy] = prevdx;
62 b6d98463 2006-04-14 devnull dy[ndxy] = prevdy;
63 b6d98463 2006-04-14 devnull some++;
64 b6d98463 2006-04-14 devnull break;
65 b6d98463 2006-04-14 devnull case LEFT:
66 b6d98463 2006-04-14 devnull dx[ndxy] -= (ap->a_sub==DEFAULT) ? defx : ap->a_val.f;
67 b6d98463 2006-04-14 devnull some++;
68 b6d98463 2006-04-14 devnull hvmode = L_DIR;
69 b6d98463 2006-04-14 devnull break;
70 b6d98463 2006-04-14 devnull case RIGHT:
71 b6d98463 2006-04-14 devnull dx[ndxy] += (ap->a_sub==DEFAULT) ? defx : ap->a_val.f;
72 b6d98463 2006-04-14 devnull some++;
73 b6d98463 2006-04-14 devnull hvmode = R_DIR;
74 b6d98463 2006-04-14 devnull break;
75 b6d98463 2006-04-14 devnull case UP:
76 b6d98463 2006-04-14 devnull dy[ndxy] += (ap->a_sub==DEFAULT) ? defy : ap->a_val.f;
77 b6d98463 2006-04-14 devnull some++;
78 b6d98463 2006-04-14 devnull hvmode = U_DIR;
79 b6d98463 2006-04-14 devnull break;
80 b6d98463 2006-04-14 devnull case DOWN:
81 b6d98463 2006-04-14 devnull dy[ndxy] -= (ap->a_sub==DEFAULT) ? defy : ap->a_val.f;
82 b6d98463 2006-04-14 devnull some++;
83 b6d98463 2006-04-14 devnull hvmode = D_DIR;
84 b6d98463 2006-04-14 devnull break;
85 b6d98463 2006-04-14 devnull case HEIGHT: /* length of arrowhead */
86 b6d98463 2006-04-14 devnull prevh = ap->a_val.f;
87 b6d98463 2006-04-14 devnull break;
88 b6d98463 2006-04-14 devnull case WIDTH: /* width of arrowhead */
89 b6d98463 2006-04-14 devnull prevw = ap->a_val.f;
90 b6d98463 2006-04-14 devnull break;
91 b6d98463 2006-04-14 devnull case TO:
92 b6d98463 2006-04-14 devnull if (some) {
93 b6d98463 2006-04-14 devnull nx += dx[ndxy];
94 b6d98463 2006-04-14 devnull ny += dy[ndxy];
95 b6d98463 2006-04-14 devnull ndxy++;
96 b6d98463 2006-04-14 devnull dx[ndxy] = dy[ndxy] = some = 0;
97 b6d98463 2006-04-14 devnull }
98 b6d98463 2006-04-14 devnull ppos = attr[i].a_val.o;
99 b6d98463 2006-04-14 devnull dx[ndxy] = ppos->o_x - nx;
100 b6d98463 2006-04-14 devnull dy[ndxy] = ppos->o_y - ny;
101 b6d98463 2006-04-14 devnull some++;
102 b6d98463 2006-04-14 devnull break;
103 b6d98463 2006-04-14 devnull case BY:
104 b6d98463 2006-04-14 devnull if (some) {
105 b6d98463 2006-04-14 devnull nx += dx[ndxy];
106 b6d98463 2006-04-14 devnull ny += dy[ndxy];
107 b6d98463 2006-04-14 devnull ndxy++;
108 b6d98463 2006-04-14 devnull dx[ndxy] = dy[ndxy] = some = 0;
109 b6d98463 2006-04-14 devnull }
110 b6d98463 2006-04-14 devnull ppos = ap->a_val.o;
111 b6d98463 2006-04-14 devnull dx[ndxy] = ppos->o_x;
112 b6d98463 2006-04-14 devnull dy[ndxy] = ppos->o_y;
113 b6d98463 2006-04-14 devnull some++;
114 b6d98463 2006-04-14 devnull break;
115 b6d98463 2006-04-14 devnull case THEN: /* turn off any previous accumulation */
116 b6d98463 2006-04-14 devnull if (some) {
117 b6d98463 2006-04-14 devnull nx += dx[ndxy];
118 b6d98463 2006-04-14 devnull ny += dy[ndxy];
119 b6d98463 2006-04-14 devnull ndxy++;
120 b6d98463 2006-04-14 devnull dx[ndxy] = dy[ndxy] = some = 0;
121 b6d98463 2006-04-14 devnull }
122 b6d98463 2006-04-14 devnull break;
123 b6d98463 2006-04-14 devnull case FROM:
124 b6d98463 2006-04-14 devnull case AT:
125 b6d98463 2006-04-14 devnull ppos = ap->a_val.o;
126 b6d98463 2006-04-14 devnull nx = curx = ppos->o_x;
127 b6d98463 2006-04-14 devnull ny = cury = ppos->o_y;
128 b6d98463 2006-04-14 devnull break;
129 b6d98463 2006-04-14 devnull }
130 b6d98463 2006-04-14 devnull }
131 b6d98463 2006-04-14 devnull if (some) {
132 b6d98463 2006-04-14 devnull nx += dx[ndxy];
133 b6d98463 2006-04-14 devnull ny += dy[ndxy];
134 b6d98463 2006-04-14 devnull ndxy++;
135 b6d98463 2006-04-14 devnull defx = dx[ndxy-1];
136 b6d98463 2006-04-14 devnull defy = dy[ndxy-1];
137 b6d98463 2006-04-14 devnull } else {
138 b6d98463 2006-04-14 devnull defx *= xtab[hvmode];
139 b6d98463 2006-04-14 devnull defy *= ytab[hvmode];
140 b6d98463 2006-04-14 devnull dx[ndxy] = defx;
141 b6d98463 2006-04-14 devnull dy[ndxy] = defy;
142 b6d98463 2006-04-14 devnull ndxy++;
143 b6d98463 2006-04-14 devnull nx += defx;
144 b6d98463 2006-04-14 devnull ny += defy;
145 b6d98463 2006-04-14 devnull }
146 b6d98463 2006-04-14 devnull prevdx = defx;
147 b6d98463 2006-04-14 devnull prevdy = defy;
148 b6d98463 2006-04-14 devnull if (chop) {
149 b6d98463 2006-04-14 devnull if (chop == 1 && chop1 == 0) /* just said "chop", so use default */
150 b6d98463 2006-04-14 devnull chop1 = chop2 = getfval("circlerad");
151 b6d98463 2006-04-14 devnull theta = atan2(dy[0], dx[0]);
152 b6d98463 2006-04-14 devnull x0 = chop1 * cos(theta);
153 b6d98463 2006-04-14 devnull y0 = chop1 * sin(theta);
154 b6d98463 2006-04-14 devnull curx += x0;
155 b6d98463 2006-04-14 devnull cury += y0;
156 b6d98463 2006-04-14 devnull dx[0] -= x0;
157 b6d98463 2006-04-14 devnull dy[0] -= y0;
158 b6d98463 2006-04-14 devnull
159 b6d98463 2006-04-14 devnull theta = atan2(dy[ndxy-1], dx[ndxy-1]);
160 b6d98463 2006-04-14 devnull x1 = chop2 * cos(theta);
161 b6d98463 2006-04-14 devnull y1 = chop2 * sin(theta);
162 b6d98463 2006-04-14 devnull nx -= x1;
163 b6d98463 2006-04-14 devnull ny -= y1;
164 b6d98463 2006-04-14 devnull dx[ndxy-1] -= x1;
165 b6d98463 2006-04-14 devnull dy[ndxy-1] -= y1;
166 b6d98463 2006-04-14 devnull dprintf("chopping %g %g %g %g; cur=%g,%g end=%g,%g\n",
167 b6d98463 2006-04-14 devnull x0, y0, x1, y1, curx, cury, nx, ny);
168 b6d98463 2006-04-14 devnull }
169 b6d98463 2006-04-14 devnull p = makenode(type, 5 + 2 * ndxy);
170 b6d98463 2006-04-14 devnull curx = p->o_val[0] = nx;
171 b6d98463 2006-04-14 devnull cury = p->o_val[1] = ny;
172 b6d98463 2006-04-14 devnull if (head || type == ARROW) {
173 b6d98463 2006-04-14 devnull p->o_nhead = getfval("arrowhead");
174 b6d98463 2006-04-14 devnull p->o_val[2] = prevw;
175 b6d98463 2006-04-14 devnull p->o_val[3] = prevh;
176 b6d98463 2006-04-14 devnull if (head == 0)
177 b6d98463 2006-04-14 devnull head = HEAD2; /* default arrow head */
178 b6d98463 2006-04-14 devnull }
179 b6d98463 2006-04-14 devnull p->o_attr = head | invis | ddtype;
180 b6d98463 2006-04-14 devnull p->o_val[4] = ndxy;
181 b6d98463 2006-04-14 devnull nx = p->o_x;
182 b6d98463 2006-04-14 devnull ny = p->o_y;
183 b6d98463 2006-04-14 devnull for (i = 0, j = 5; i < ndxy; i++, j += 2) {
184 b6d98463 2006-04-14 devnull p->o_val[j] = dx[i];
185 b6d98463 2006-04-14 devnull p->o_val[j+1] = dy[i];
186 b6d98463 2006-04-14 devnull if (type == LINE || type == ARROW)
187 b6d98463 2006-04-14 devnull extreme(nx += dx[i], ny += dy[i]);
188 b6d98463 2006-04-14 devnull else if (type == SPLINE && i < ndxy-1) {
189 b6d98463 2006-04-14 devnull /* to compute approx extreme of spline at p,
190 b6d98463 2006-04-14 devnull /* compute midway between p-1 and p+1,
191 b6d98463 2006-04-14 devnull /* then go 3/4 from there to p */
192 b6d98463 2006-04-14 devnull double ex, ey, xi, yi, xi1, yi1;
193 b6d98463 2006-04-14 devnull xi = nx + dx[i]; yi = ny + dy[i]; /* p */
194 b6d98463 2006-04-14 devnull xi1 = xi + dx[i+1]; yi1 = yi + dy[i+1]; /* p+1 */
195 b6d98463 2006-04-14 devnull ex = (nx+xi1)/2; ey = (ny+yi1)/2; /* midway */
196 b6d98463 2006-04-14 devnull ex += 0.75*(xi-ex); ey += 0.75*(yi-ey);
197 b6d98463 2006-04-14 devnull extreme(ex, ey);
198 b6d98463 2006-04-14 devnull nx = xi; ny = yi;
199 b6d98463 2006-04-14 devnull }
200 b6d98463 2006-04-14 devnull
201 b6d98463 2006-04-14 devnull }
202 b6d98463 2006-04-14 devnull p->o_ddval = ddval;
203 b6d98463 2006-04-14 devnull if (dbg) {
204 b6d98463 2006-04-14 devnull printf("S or L from %g %g to %g %g with %d elements:\n", p->o_x, p->o_y, curx, cury, ndxy);
205 b6d98463 2006-04-14 devnull for (i = 0, j = 5; i < ndxy; i++, j += 2)
206 b6d98463 2006-04-14 devnull printf("%g %g\n", p->o_val[j], p->o_val[j+1]);
207 b6d98463 2006-04-14 devnull }
208 b6d98463 2006-04-14 devnull extreme(p->o_x, p->o_y);
209 b6d98463 2006-04-14 devnull extreme(curx, cury);
210 b6d98463 2006-04-14 devnull return(p);
211 b6d98463 2006-04-14 devnull }