-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcom_window.c
373 lines (339 loc) · 9.18 KB
/
com_window.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
#include <strings.h>
#include "db.h"
#include "xwin.h"
#include "token.h"
#include "rubber.h"
#include "rlgetc.h"
#include "eprintf.h"
#include "equate.h"
#define UNUSED(x) (void)(x)
static double x1, y1;
int fit=0; /* don't fit */
int nest=9; /* default nesting level */
int lastwin=0; /* go back to last window */
//int bounds=0; /* default pick boundary display level */
void draw_bounds();
int do_win();
int com_window(LEXER *lp, char *arg)
{
UNUSED(arg);
enum {START,NUM1,COM1,NUM2,NUM3,COM2,NUM4,END} state = START;
double scale=1.0; /* default scale */
fit=0;
nest=9;
lastwin=0;
TOKEN token;
int done=0;
char *word;
int debug=0;
double x2, y2;
int layer;
OPTS opts;
opt_set_defaults(&opts);
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 */
if (token == OPT ) {
token_get(lp, &word);
state = START;
if (strncasecmp(word, ":F", 2) == 0) {
fit++;
} else if (strncasecmp(word, ":X", 2) == 0) {
if(sscanf(word+2, "%lf", &scale) != 1) {
weprintf("WIN invalid scale argument: %s\n", word+2);
state = END;
} else {
if (scale < 0.0) {
scale = 1.0/(-scale);
}
if (scale > 100.0 || scale < 0.01) {
weprintf("WIN: scale out of range %s\n", word+2);
state = END;
}
}
} else if (strncasecmp(word, ":L", 2) == 0) { // logical nesting
if(sscanf(word+2, "%d", &nest) != 1) {
weprintf("WIN invalid logical nest level %s\n", word+2);
state=END;
} else {
db_set_physical(0); // logical nest
db_set_nest(nest); // nest level
}
} else if (strncasecmp(word, ":N", 2) == 0) { // physical nesting
if(sscanf(word+2, "%d", &nest) != 1) {
weprintf("WIN invalid physical nest level %s\n", word+2);
state=END;
} else {
db_set_physical(1); // physical nest
db_set_nest(nest); // nest level
}
} else if (strncasecmp(word, ":O", 2) == 0) {
if(sscanf(word+2, "%d", &layer) == 1) {
equate_toggle_override(layer);
} else {
db_set_fill(FILL_TOGGLE);
}
} else if (strncasecmp(word, ":Z", 2) == 0) {
lastwin++;
} else {
printf("WIN: bad option: %s\n", word);
state = END;
}
break;
} 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 || token == IDENT) {
if (token == EOC) token_get(lp, &word);
if (debug) printf("com_win: calling do_win 1 fit=%d, scale=%g\n", fit, scale);
do_win(lp, 0, 0.0, 0.0, 0.0, 0.0, scale);
fit = 0;
scale = 1.0;
state = END;
} else {
printf("WIN: expected OPT or COORD, got: %s\n",
tok2str(token));
state = END; /* error */
}
break;
case NUM1: /* get pair of xy coordinates */
if (token == NUMBER) {
if (getnum(lp, "WIN", &x1, &y1)) {
rubber_set_callback(draw_bounds);
state = NUM3;
} else {
state = END;
}
} else if (token == EOL) {
token_get(lp, &word); /* just ignore it */
} else if (token == EOC || token == CMD || token == IDENT) {
printf("WIN: cancelling WIN\n");
state = END;
} else {
printf("WIN: expected NUMBER, got: %s\n",
tok2str(token));
state = END;
}
break;
case NUM3: /* get pair of xy coordinates */
if (token == NUMBER) {
if (getnum(lp, "WIN", &x2, &y2)) {
state = START;
// token_get(lp, &word);
// sscanf(word, "%lf", &y2); /* scan it in */
rubber_clear_callback();
if (x1==x2 && y1==y2) {
if (debug) printf("calling do_win 3 inside com window\n");
do_win(lp, 2, x1, y1, 0.0, 0.0, scale); /* pan */
fit = 0;
scale = 1.0;
} else {
if (debug) printf("calling do_win 4 inside com window\n");
do_win(lp, 4, x1, y1, x2, y2, scale); /* zoom */
fit = 0;
scale = 1.0;
}
} else {
state = END;
}
} else if (token == EOL) {
token_get(lp, &word); /* just ignore it */
} else if (token == EOC || token == CMD || token == IDENT) {
if (debug) printf("WIN: doing pan\n");
if (debug) printf("calling do_win 2 inside com window\n");
do_win(lp, 2, x1, y1, 0.0, 0.0, scale);
fit = 0;
scale = 1.0;
state = END;
} else {
printf("WIN: expected COORD, got: %s\n",
tok2str(token));
state = END;
}
break;
case END:
default:
if (token == EOC) {
token_flush_EOL(lp); /* don't leave a dangling EOL */
} else if (token == CMD || token == IDENT) {
;
} else {
token_flush_EOL(lp);
}
done++;
break;
}
}
rubber_clear_callback();
return(1);
}
int do_win(LEXER *lp, int n, double x1, double y1, double x2, double y2, double scale) {
UNUSED(lp);
extern int fit, nest;
double dx, dy, xmin, ymin, xmax, ymax, tmp;
int debug=0;
if (currep != NULL) {
xmin = currep->vp_xmin;
ymin = currep->vp_ymin;
xmax = currep->vp_xmax;
ymax = currep->vp_ymax;
if (debug) printf("setting xmin inside do_win() = %g\n", xmin);
} else {
xmin = -100.0;
ymin = -100.0;
xmax = 100.0;
ymax = 100.0;
}
if (debug) printf("in do_win, %d %g %g %g %g %g\n",
n, x1, y1, x2, y2, scale);
if (n==2) {
dx=(xmax-xmin);
dy=(ymax-ymin);
xmin=x1-dx/2.0;
ymin=y1-dx/2.0;
xmax=x1+dx/2.0;
ymax=y1+dx/2.0;
if (debug) printf("setting xmin inside do_win() = %g\n", xmin);
} else if (n==4) { /* how cell bounds get loaded during readin */
if (currep != NULL) {
// currep->vp_xmin=x1;
// currep->vp_xmax=x2;
// currep->vp_ymin=y1;
// currep->vp_ymax=y2;
currep->minx=x1;
currep->maxx=x2;
currep->miny=y1;
currep->maxy=y2;
}
xmin=x1;
ymin=y1;
xmax=x2;
ymax=y2;
if (debug) printf("setting currep->xmin inside do_win() = %g %g %g %g\n", xmin, ymin, xmax, ymax);
} else if (n==0) {
;
} else {
eprintf("WIN: bad number of points");
return(0);
}
if (debug) printf("setting xmin, ymin, xmax, ymax %g %g %g %g\n",
xmin, ymin, xmax, ymax);
if (fit) {
if (currep != NULL ) {
xmin = currep->minx;
ymin = currep->miny;
xmax = currep->maxx;
ymax = currep->maxy;
} else {
xmin = -100.0;
ymin = -100.0;
xmax = 100.0;
ymax = 100.0;
}
}
if (debug) printf("%g %g %g %g %d\n", xmin, ymin, xmax, ymax, n);
if (xmax < xmin) { /* canonicalize the selection rectangle */
tmp = xmax; xmax = xmin; xmin = tmp;
}
if (ymax < ymin) {
tmp = ymax; ymax = ymin; ymin = tmp;
}
if (fit) {
if (debug) printf("doing fit \n");
dx=(xmax-xmin);
dy=(ymax-ymin);
xmin-=dx/40.0;
xmax+=dx/40.0;
ymin-=dy/40.0;
ymax+=dy/40.0;
}
if (scale != 1.0) {
if (debug) printf("doing scale \n");
dx=(xmax-xmin)/2.0;
dy=(ymax-ymin)/2.0;
xmin=((xmax+xmin)/2.0)-(dx*scale);
xmax=((xmax+xmin)/2.0)+(dx*scale);
ymin=((ymax+ymin)/2.0)-(dy*scale);
ymax=((ymax+ymin)/2.0)+(dy*scale);
}
if (currep != NULL && lastwin) {
if (debug) printf("setting old values\n");
xmin = currep->old_xmin;
ymin = currep->old_ymin;
xmax = currep->old_xmax;
ymax = currep->old_ymax;
}
if (currep != NULL) {
if (debug) printf("saving old values values\n");
currep->old_xmin = currep->vp_xmin;
currep->old_ymin = currep->vp_ymin;
currep->old_xmax = currep->vp_xmax;
currep->old_ymax = currep->vp_ymax;
currep->vp_xmin=xmin;
currep->vp_ymin=ymin;
currep->vp_xmax=xmax;
currep->vp_ymax=ymax;
}
if (debug) printf("%g %g %g %g\n", xmin, ymin, xmax, ymax);
if (xmin == 0 && ymin == 0 && xmax == 0 && ymax == 0) {
; /* don't set the window to a null size */
} else {
if (debug) printf("calling xwin_window_set = %g %g %g %g\n",
xmin, ymin, xmax, ymax);
xwin_window_set(xmin,ymin,xmax,ymax);
}
if (debug) printf("leaving dowin()\n");
return(0);
}
void draw_bounds(double x2, double y2, int count)
{
static double x1old, x2old, y1old, y2old;
static int called = 0;
BOUNDS bb;
if (count == 0) { /* first call */
jump(&bb, D_RUBBER); /* draw new shape */
draw(x1,y1, &bb, D_RUBBER);
draw(x1,y2, &bb, D_RUBBER);
draw(x2,y2, &bb, D_RUBBER);
draw(x2,y1, &bb, D_RUBBER);
draw(x1,y1, &bb, D_RUBBER);
called++;
} else if (count > 0) { /* intermediate calls */
jump(&bb, D_RUBBER); /* erase old shape */
draw(x1old,y1old, &bb, D_RUBBER);
draw(x1old,y2old, &bb, D_RUBBER);
draw(x2old,y2old, &bb, D_RUBBER);
draw(x2old,y1old, &bb, D_RUBBER);
draw(x1old,y1old, &bb, D_RUBBER);
jump(&bb, D_RUBBER); /* draw new shape */
draw(x1,y1, &bb, D_RUBBER);
draw(x1,y2, &bb, D_RUBBER);
draw(x2,y2, &bb, D_RUBBER);
draw(x2,y1, &bb, D_RUBBER);
draw(x1,y1, &bb, D_RUBBER);
called++;
} else { /* last call, cleanup */
if (called) {
jump(&bb, D_RUBBER); /* erase old shape */
draw(x1old,y1old, &bb, D_RUBBER);
draw(x1old,y2old, &bb, D_RUBBER);
draw(x2old,y2old, &bb, D_RUBBER);
draw(x2old,y1old, &bb, D_RUBBER);
draw(x1old,y1old, &bb, D_RUBBER);
}
called=0;
}
/* save old values */
x1old=x1;
y1old=y1;
x2old=x2;
y2old=y2;
jump(&bb, D_RUBBER);
}