-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcom_wrap.c
329 lines (297 loc) · 8.77 KB
/
com_wrap.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
#include <stddef.h>
#include <stdio.h>
#include <string.h> /* for strchr() */
#include <ctype.h> /* for toupper() */
#include "rlgetc.h"
#include "db.h"
#include "token.h"
#include "xwin.h"
#include "rubber.h"
#define UNUSED(x) (void)(x)
static double x1, y1, x2, y2, x3, y3;
void wrap_draw_box();
STACK *zstack;
char ybuf[MAXFILENAME];
static int instcounter=0; /* used for generating uniq instance names */
/*
wrap a set of components in the current device.
WRAP [<restrictor>] [<devicename>] { xyorig coord1 coord2 } ... <EOC>
*/
int com_wrap(LEXER *lp, char *arg)
{
UNUSED(arg);
enum {START,NUM1,NUM2,NUM3,END} state = START;
int done=0;
TOKEN token;
char *word;
int debug=0;
int valid_comp=0;
size_t i;
DB_DEFLIST *p_best;
DB_DEFLIST *p_new;
DB_TAB *newrep;
OPTS *opts;
char *wrap_inst_name = NULL;
double tmp;
int anonymous=0; /* 0=user supplied name, 1=autogenerated devicename */
int my_layer=0; /* internal working layer */
int comp=ALL;
/* check that we are editing a rep */
if (currep == NULL ) {
printf("must do \"EDIT <name>\" before WRAP\n");
token_flush_EOL(lp);
return(1);
}
/*
To create a show set for restricting the pick, we look
here for and optional primitive indicator
concatenated with an optional layer number:
A[layer_num] ;(arc)
C[layer_num] ;(circle)
L[layer_num] ;(line)
N[layer_num] ;(note)
O[layer_num] ;(oval)
P[layer_num] ;(poly)
R[layer_num] ;(rectangle)
T[layer_num] ;(text)
or a instance name. Instance names can be quoted, which
allows the user to have instances which overlap the primitive
namespace. For example: N7 is a note on layer seven, but
"N7" is an instance call.
*/
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 (word[0]==':') {
switch (toupper((unsigned char)word[1])) {
default:
printf("WRAP: bad option: %s\n", word);
state=END;
break;
}
} else {
printf("WRAP: bad option: %s\n", word);
state = END;
}
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 if (token == IDENT) {
token_get(lp,&word);
state = START;
/* check to see if is a valid comp descriptor */
valid_comp=0;
if ((comp = is_comp(toupper((unsigned char)word[0])))) {
if (strlen(word) == 1) {
my_layer = default_layer();
printf("using default layer=%d\n",my_layer);
valid_comp++; /* no layer given */
} else {
valid_comp++;
/* check for any non-digit characters */
/* to allow instance names like "L1234b" */
for (i=0; i<strlen(&word[1]); i++) {
if (!isdigit((unsigned char)word[1+i])) {
valid_comp=0;
}
}
if (valid_comp) {
if(sscanf(&word[1], "%d", &my_layer) == 1) {
if (debug) printf("given layer=%d\n",my_layer);
} else {
valid_comp=0;
}
}
if (valid_comp) {
if (my_layer > MAX_LAYER) {
printf("layer must be less than %d\n",
MAX_LAYER);
valid_comp=0;
done++;
}
if (!show_check_modifiable(currep, comp, my_layer)) {
printf("layer %d is not modifiable!\n",
my_layer);
token_flush_EOL(lp);
valid_comp=0;
done++;
}
}
}
}
if (valid_comp==0) {
/* must be the new name of the wrapped instance */
if (db_exists(word)) {
printf("can't wrap onto an existing cell!\n");
state = END;
} else {
wrap_inst_name = strsave(word);
if (debug) printf("got %s wrap_inst_name\n", wrap_inst_name);
}
}
} else {
token_err("WRAP", lp, "expected DESC or NUMBER", token);
state = END; /* error */
}
break;
case NUM1: /* get pair of xy coordinates */
if (debug) printf("in NUM1\n");
if (token == NUMBER) {
if (getnum(lp, "WRAP", &x1, &y1)) {
state = NUM2;
} else {
state = END;
}
} else if (token == EOL) {
token_get(lp,&word); /* just ignore it */
} else if (token == EOC || token == CMD) {
printf("WRAP: cancelling POINT\n");
state = END;
} else {
token_err("WRAP", 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, "WRAP", &x2, &y2)) {
rubber_set_callback(wrap_draw_box);
state = NUM3;
} else {
state = END;
}
} else if (token == EOL) {
token_get(lp,&word); /* just ignore it */
} else if (token == EOC || token == CMD) {
printf("IDENT: cancelling POINT\n");
state = END;
} else {
token_err("IDENT", lp, "expected NUMBER", token);
state = END;
}
break;
case NUM3:
if (debug) printf("in NUM6\n");
if (token == NUMBER) {
if (getnum(lp, "WRAP", &x3, &y3)) {
printf("got %g %g\n", x3, y3);
rubber_clear_callback();
if (x2 > x3) {
tmp = x3; x3 = x2; x2 = tmp;
}
if (y2 > y3) {
tmp = y3; y3 = y2; y2 = tmp;
}
zstack=db_ident_region(currep, x2, y2, x3, y3, 1, my_layer, comp, 0);
if (zstack==NULL) {
printf("Nothing here to wrap. Try \"SHO #E\"?\n");
} else {
if (wrap_inst_name == NULL) {
anonymous++; /* autogenerated name */
sprintf(ybuf, "NONAME_%03d", instcounter++);
if (debug) printf("autonaming rep %s\n", ybuf);
wrap_inst_name = ybuf;
}
newrep = (DB_TAB *) db_install(wrap_inst_name);
if (debug) printf("doing db_install for rep %s, ptr = %ld\n",
ybuf, (long int) newrep);
// for each selected item in the zstack,
// copy the item and put it in wrap_inst_name
// take it out of the original
// fix up the coordinates to account for being wrapped
// put it in the new wrap instance
while ((p_best = (DB_DEFLIST *) stack_pop(&zstack))!=NULL) {
p_new = db_copy_component(p_best, NULL);
if (debug) printf("copying %ld, p_new = %ld\n",
(long int) p_best, (long int) p_new);
db_unlink_component(currep, p_best);
db_move_component(p_new, -x1, -y1);
db_insert_component(newrep, p_new);
}
// db_fsck(currep->dbhead);
// add the new wrap instance to the currep
opts = opt_create();
opt_set_defaults(opts);
show_init(newrep);
newrep->minx = min(x2-x1, x3-x1);
newrep->maxx = max(x2-x1, x3-x1);
newrep->miny = min(y2-y1, y3-y1);
newrep->maxy = max(y2-y1, y3-y1);
db_add_inst(currep, newrep, opts, x1, y1);
newrep->modified++;
if (anonymous) {
newrep->is_tmp_rep++; // flag as a tmp rep
} else {
db_save(lp, newrep, wrap_inst_name);
newrep->modified=0;
}
if (!anonymous) {
free(wrap_inst_name); // just free the name string
}
wrap_inst_name=NULL;
currep->modified++;
need_redraw++;
}
state = END; // BUG? FIXME
} else {
state = END;
}
} else if (token == EOL) {
token_get(lp,&word); /* just ignore it */
} else if (token == EOC || token == CMD) {
printf("WRAP: cancelling POINT\n");
state = END;
} else {
token_err("WRAP", lp, "expected NUMBER", token);
state = END;
}
break;
case END:
default:
if (token == EOC || token == CMD) {
;
} else {
token_flush_EOL(lp);
}
done++;
rubber_clear_callback();
break;
}
}
return(1);
}
void wrap_draw_box(double x3, double y3, int count)
{
static double x2old, x3old, y2old, y3old;
BOUNDS bb;
bb.init=0;
if (count == 0) { /* first call */
db_drawbounds(x2,y2,x3,y3,D_RUBBER); /* draw new shape */
} else if (count > 0) { /* intermediate calls */
db_drawbounds(x2old,y2old,x3old,y3old,D_RUBBER); /* erase old shape */
db_drawbounds(x2,y2,x3,y3,D_RUBBER); /* draw new shape */
} else { /* last call, cleanup */
db_drawbounds(x2old,y2old,x3old,y3old,D_RUBBER); /* erase old shape */
}
/* save old values */
x2old=x2; /* global */
y2old=y2;
x3old=x3;
y3old=y3;
jump(&bb, D_RUBBER);
}