-
Notifications
You must be signed in to change notification settings - Fork 4
/
com_area.c
198 lines (181 loc) · 4.67 KB
/
com_area.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
#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)
/*
measure the area of a component in the current device.
AREA <restrictor> { xysel } ... <EOC>
*/
int com_area(LEXER *lp, char *arg)
{
UNUSED(arg);
enum {START,NUM1,END} state = START;
TOKEN token;
char *word;
int debug=0;
int done=0;
int valid_comp=0;
size_t i;
DB_DEFLIST *p_best;
DB_DEFLIST *p_prev = NULL;
double x1, y1;
double area;
double cum_area=0.0;
char instname[BUFSIZE];
char *pinst = (char *) NULL;
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 AREA\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 */
if (debug) printf("in START\n");
if (token == OPT ) {
token_get(lp,&word); /* ignore for now */
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 = NUM1;
/* 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++;
}
}
}
} else {
if (db_lookup(word)) {
strncpy(instname, word, BUFSIZE);
pinst = instname;
} else {
printf("not a valid instance name: %s\n", word);
state = START;
}
}
} else {
token_err("AREA", 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, "AREA", &x1, &y1)) {
if (debug) printf("got comp %d, layer %d\n", comp, my_layer);
if (p_prev != NULL) {
db_highlight(p_prev); /* unhighlight it */
p_prev = NULL;
}
if ((p_best=db_ident(currep, x1,y1,0,my_layer, comp, pinst)) != NULL) {
db_notate(p_best); /* print out id information */
db_highlight(p_best);
area = db_area(p_best);
cum_area += area;
if (area >= 0) {
printf(" area = %g, total = %g\n", area, cum_area );
}
p_prev=p_best;
state = NUM1;
} else {
printf("nothing here to measure... try SHO command?\n");
state = START;
}
} else {
state = END;
}
} else if (token == EOL) {
token_get(lp,&word); /* just ignore it */
} else if (token == EOC || token == CMD) {
printf("AREA: cancelling POINT\n");
state = END;
} else {
token_err("AREA", 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);
}