-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgeom_arc.c
193 lines (173 loc) · 4.24 KB
/
geom_arc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include "db.h"
#include "token.h"
#include "xwin.h"
#include "rubber.h"
#include "rlgetc.h"
#include "opt_parse.h"
#include <math.h>
// DB_TAB dbtab;
DB_ARC dbarc;
void draw_arc();
OPTS aopts;
double gx1, gy1, x2, y2;
int add_arc(LEXER *lp, int *layer)
{
enum {START,NUM1,NUM2,NUM3,END} state = START;
int debug=0;
int done=0;
TOKEN token;
char *word;
double x3, y3;
// static double xold, yold;
if (debug) {printf("layer %d\n",*layer);}
rl_saveprompt();
rl_setprompt("ADD_ARC> ");
opt_set_defaults(&aopts);
while (!done) {
token = token_look(lp, &word);
if (debug) {printf("got %s: %s\n", tok2str(token), word);}
if (token==CMD) {
state=END;
}
switch(state) {
case START: /* get option or first xy pair */
db_checkpoint(lp);
if (debug) printf("in start\n");
if (token == OPT ) {
token_get(lp,&word);
if (opt_parse(word, ARC_OPTS, &aopts) == -1) {
state = END;
} else {
state = START;
}
} else if (token == NUMBER) {
state = NUM1;
} else if (token == EOL) {
token_get(lp,&word); /* just eat it up */
state = START;
} else if (token == EOC || token == CMD) {
state = END;
} else {
token_err("ARC", lp, "expected OPT or COORD", token);
state = END;
}
// xold=yold=0.0;
break;
case NUM1: /* get pair of xy coordinates */
if (debug) printf("in num1\n");
if (token == NUMBER) {
if (getnum(lp, "ARC", &gx1, &gy1)) {
state = NUM2;
} else {
state = END;
}
} else if (token == EOL) {
token_get(lp,&word); /* just ignore it */
} else if (token == EOC || CMD) {
state = END;
} else {
token_err("ARC", lp, "expected NUMBER", token);
state = END;
}
break;
case NUM2: /* get pair of xy coordinates */
if (debug) printf("in num2\n");
if (token == NUMBER) {
if (getnum(lp, "ARC", &x2, &y2)) {
rubber_set_callback(draw_arc);
state = NUM3;
} else {
state = END;
}
} else if (token == EOL) {
token_get(lp,&word); /* just ignore it */
} else if (token == EOC || CMD) {
state = END;
} else {
token_err("ARC", lp, "expected NUMBER", token);
state = END;
}
break;
case NUM3: /* get pair of xy coordinates */
if (debug) printf("in num3\n");
if (token == NUMBER) {
if (getnum(lp, "ARC", &x3, &y3)) {
db_add_arc(currep, *layer, opt_copy(&aopts), gx1, gy1, x2, y2, x3, y3);
need_redraw++;
rubber_clear_callback();
state=START;
} else {
state=END;
}
} else if (token == EOL) {
token_get(lp,&word); /* just ignore it */
} else if (token == EOC || CMD) {
state = END;
} else {
token_err("ARC", lp, "expected NUMBER", token);
state = END;
}
break;
case END:
default:
if (debug) printf("in end\n");
rubber_clear_callback();
if (token == EOC || token == CMD) {
;
} else {
token_flush_EOL(lp);
}
done++;
break;
}
}
rl_restoreprompt();
return(1);
}
void draw_arc(double x3, double y3, int count)
{
static double x3old, y3old;
int debug=0;
BOUNDS bb;
static DB_DEFLIST dbdeflist;
bb.init=0;
/* DB_TAB dbtab; */
/* DB_DEFLIST dbdeflist; */
/* DB_ARC dbarc; */
// dbtab.dbhead = &dbdeflist;
// dbtab.next = NULL;
// dbtab.name = "callback";
dbdeflist.u.a = &dbarc;
dbdeflist.type = ARC;
dbarc.layer=1;
dbarc.opts=&aopts;
dbarc.x1 = gx1;
dbarc.y1 = gy1;
dbarc.x2 = x2;
dbarc.y2 = y2;
if (debug) {printf("in draw_arc\n");}
if (count == 0) { /* first call */
jump(&bb, D_RUBBER); /* draw new shape */
dbarc.x3 = x3;
dbarc.y3 = y3;
do_arc(&dbdeflist, &bb, D_RUBBER);
} else if (count > 0) { /* intermediate calls */
jump(&bb, D_RUBBER); /* erase old shape */
dbarc.x3 = x3old;
dbarc.y3 = y3old;
do_arc(&dbdeflist, &bb, D_RUBBER);
jump(&bb, D_RUBBER); /* draw new shape */
dbarc.x3 = x3;
dbarc.y3 = y3;
do_arc(&dbdeflist, &bb, D_RUBBER);
} else { /* last call, cleanup */
jump(&bb, D_RUBBER); /* erase old shape */
dbarc.x3 = x3old;
dbarc.y3 = y3old;
do_arc(&dbdeflist, &bb, D_RUBBER);
}
/* save old values */
x3old=x3;
y3old=y3;
jump(&bb, D_RUBBER);
}