1 |
< |
/* Copyright (c) 1994 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
27 |
|
|
28 |
|
int (*mg_ehand[MG_NENTITIES])(); |
29 |
|
|
30 |
+ |
/* Handler routine for unknown entities */ |
31 |
+ |
|
32 |
+ |
int (*mg_uhand)() = mg_defuhand; |
33 |
+ |
|
34 |
+ |
unsigned mg_nunknown; /* count of unknown entities */ |
35 |
+ |
|
36 |
|
/* error messages */ |
37 |
|
|
38 |
|
char *mg_err[MG_NERRS] = MG_ERRLIST; |
65 |
|
e_ies(), /* IES luminaire file */ |
66 |
|
e_include(), /* include file */ |
67 |
|
e_sph(), /* sphere */ |
68 |
+ |
e_cct(), /* color temperature */ |
69 |
|
e_cmix(), /* color mixtures */ |
70 |
|
e_cspec(), /* color spectra */ |
71 |
|
e_cyl(), /* cylinder */ |
95 |
|
mg_ehand[MG_E_INCLUDE] = e_include; |
96 |
|
if (mg_ehand[MG_E_SPH] == NULL) { |
97 |
|
mg_ehand[MG_E_SPH] = e_sph; |
98 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_VERTEX; |
98 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
99 |
|
} else |
100 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
100 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
101 |
|
if (mg_ehand[MG_E_CYL] == NULL) { |
102 |
|
mg_ehand[MG_E_CYL] = e_cyl; |
103 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_VERTEX; |
103 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
104 |
|
} else |
105 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
105 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
106 |
|
if (mg_ehand[MG_E_CONE] == NULL) { |
107 |
|
mg_ehand[MG_E_CONE] = e_cone; |
108 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_VERTEX; |
108 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
109 |
|
} else |
110 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
110 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
111 |
|
if (mg_ehand[MG_E_RING] == NULL) { |
112 |
|
mg_ehand[MG_E_RING] = e_ring; |
113 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX; |
113 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX; |
114 |
|
} else |
115 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX|1<<MG_E_XF; |
115 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
116 |
|
if (mg_ehand[MG_E_PRISM] == NULL) { |
117 |
|
mg_ehand[MG_E_PRISM] = e_prism; |
118 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_VERTEX; |
118 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
119 |
|
} else |
120 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
120 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
121 |
|
if (mg_ehand[MG_E_TORUS] == NULL) { |
122 |
|
mg_ehand[MG_E_TORUS] = e_torus; |
123 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX; |
123 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX; |
124 |
|
} else |
125 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX|1<<MG_E_XF; |
125 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
126 |
|
if (mg_ehand[MG_E_COLOR] != NULL) { |
127 |
|
if (mg_ehand[MG_E_CMIX] == NULL) { |
128 |
|
mg_ehand[MG_E_CMIX] = e_cmix; |
129 |
< |
ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX; |
129 |
> |
ineed |= 1L<<MG_E_COLOR|1L<<MG_E_CXY|1L<<MG_E_CSPEC|1L<<MG_E_CMIX|1L<<MG_E_CCT; |
130 |
|
} |
131 |
|
if (mg_ehand[MG_E_CSPEC] == NULL) { |
132 |
|
mg_ehand[MG_E_CSPEC] = e_cspec; |
133 |
< |
ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX; |
133 |
> |
ineed |= 1L<<MG_E_COLOR|1L<<MG_E_CXY|1L<<MG_E_CSPEC|1L<<MG_E_CMIX|1L<<MG_E_CCT; |
134 |
|
} |
135 |
+ |
if (mg_ehand[MG_E_CCT] == NULL) { |
136 |
+ |
mg_ehand[MG_E_CCT] = e_cct; |
137 |
+ |
ineed |= 1L<<MG_E_COLOR|1L<<MG_E_CXY|1L<<MG_E_CSPEC|1L<<MG_E_CMIX|1L<<MG_E_CCT; |
138 |
+ |
} |
139 |
|
} |
140 |
|
/* check for consistency */ |
141 |
|
if (mg_ehand[MG_E_FACE] != NULL) |
142 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
142 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
143 |
|
if (mg_ehand[MG_E_CXY] != NULL || mg_ehand[MG_E_CSPEC] != NULL || |
144 |
|
mg_ehand[MG_E_CMIX] != NULL) |
145 |
< |
uneed |= 1<<MG_E_COLOR; |
145 |
> |
uneed |= 1L<<MG_E_COLOR; |
146 |
|
if (mg_ehand[MG_E_RD] != NULL || mg_ehand[MG_E_TD] != NULL || |
147 |
+ |
mg_ehand[MG_E_IR] != NULL || |
148 |
|
mg_ehand[MG_E_ED] != NULL || |
149 |
|
mg_ehand[MG_E_RS] != NULL || |
150 |
< |
mg_ehand[MG_E_TS] != NULL) |
151 |
< |
uneed |= 1<<MG_E_MATERIAL; |
150 |
> |
mg_ehand[MG_E_TS] != NULL || |
151 |
> |
mg_ehand[MG_E_SIDES] != NULL) |
152 |
> |
uneed |= 1L<<MG_E_MATERIAL; |
153 |
|
for (i = 0; i < MG_NENTITIES; i++) |
154 |
< |
if (uneed & 1<<i && mg_ehand[i] == NULL) { |
154 |
> |
if (uneed & 1L<<i && mg_ehand[i] == NULL) { |
155 |
|
fprintf(stderr, "Missing support for \"%s\" entity\n", |
156 |
|
mg_ename[i]); |
157 |
|
exit(1); |
158 |
|
} |
159 |
|
/* add support as needed */ |
160 |
< |
if (ineed & 1<<MG_E_VERTEX && mg_ehand[MG_E_VERTEX] != c_hvertex) |
160 |
> |
if (ineed & 1L<<MG_E_VERTEX && mg_ehand[MG_E_VERTEX] != c_hvertex) |
161 |
|
e_supp[MG_E_VERTEX] = c_hvertex; |
162 |
< |
if (ineed & 1<<MG_E_POINT && mg_ehand[MG_E_POINT] != c_hvertex) |
162 |
> |
if (ineed & 1L<<MG_E_POINT && mg_ehand[MG_E_POINT] != c_hvertex) |
163 |
|
e_supp[MG_E_POINT] = c_hvertex; |
164 |
< |
if (ineed & 1<<MG_E_NORMAL && mg_ehand[MG_E_NORMAL] != c_hvertex) |
164 |
> |
if (ineed & 1L<<MG_E_NORMAL && mg_ehand[MG_E_NORMAL] != c_hvertex) |
165 |
|
e_supp[MG_E_NORMAL] = c_hvertex; |
166 |
< |
if (ineed & 1<<MG_E_COLOR && mg_ehand[MG_E_COLOR] != c_hcolor) |
166 |
> |
if (ineed & 1L<<MG_E_COLOR && mg_ehand[MG_E_COLOR] != c_hcolor) |
167 |
|
e_supp[MG_E_COLOR] = c_hcolor; |
168 |
< |
if (ineed & 1<<MG_E_CXY && mg_ehand[MG_E_CXY] != c_hcolor) |
168 |
> |
if (ineed & 1L<<MG_E_CXY && mg_ehand[MG_E_CXY] != c_hcolor) |
169 |
|
e_supp[MG_E_CXY] = c_hcolor; |
170 |
< |
if (ineed & 1<<MG_E_CSPEC && mg_ehand[MG_E_CSPEC] != c_hcolor) |
170 |
> |
if (ineed & 1L<<MG_E_CSPEC && mg_ehand[MG_E_CSPEC] != c_hcolor) |
171 |
|
e_supp[MG_E_CSPEC] = c_hcolor; |
172 |
< |
if (ineed & 1<<MG_E_CMIX && mg_ehand[MG_E_CMIX] != c_hcolor) |
172 |
> |
if (ineed & 1L<<MG_E_CMIX && mg_ehand[MG_E_CMIX] != c_hcolor) |
173 |
|
e_supp[MG_E_CMIX] = c_hcolor; |
174 |
+ |
if (ineed & 1L<<MG_E_CCT && mg_ehand[MG_E_CCT] != c_hcolor) |
175 |
+ |
e_supp[MG_E_CCT] = c_hcolor; |
176 |
|
/* discard remaining entities */ |
177 |
|
for (i = 0; i < MG_NENTITIES; i++) |
178 |
|
if (mg_ehand[i] == NULL) |
180 |
|
} |
181 |
|
|
182 |
|
|
168 |
– |
|
183 |
|
int |
184 |
|
mg_entity(name) /* get entity number from its name */ |
185 |
|
char *name; |
201 |
|
} |
202 |
|
|
203 |
|
|
204 |
< |
static int |
205 |
< |
handle_it(en, ac, av) /* pass entity to appropriate handler */ |
204 |
> |
int |
205 |
> |
mg_handle(en, ac, av) /* pass entity to appropriate handler */ |
206 |
|
register int en; |
207 |
|
int ac; |
208 |
|
char **av; |
209 |
|
{ |
210 |
|
int rv; |
211 |
|
|
212 |
< |
if (en < 0 && (en = mg_entity(av[0])) < 0) |
212 |
> |
if (en < 0 && (en = mg_entity(av[0])) < 0) { /* unknown entity */ |
213 |
> |
if (mg_uhand != NULL) |
214 |
> |
return((*mg_uhand)(ac, av)); |
215 |
|
return(MG_EUNK); |
216 |
< |
if (e_supp[en] != NULL) { |
216 |
> |
} |
217 |
> |
if (e_supp[en] != NULL) { /* support handler */ |
218 |
|
if ((rv = (*e_supp[en])(ac, av)) != MG_OK) |
219 |
|
return(rv); |
220 |
|
} |
221 |
< |
return((*mg_ehand[en])(ac, av)); |
221 |
> |
return((*mg_ehand[en])(ac, av)); /* assigned handler */ |
222 |
|
} |
223 |
|
|
224 |
|
|
227 |
|
register MG_FCTXT *ctx; |
228 |
|
char *fn; |
229 |
|
{ |
230 |
< |
int olen; |
230 |
> |
static int nfids; |
231 |
|
register char *cp; |
232 |
|
|
233 |
+ |
ctx->fid = ++nfids; |
234 |
|
ctx->lineno = 0; |
235 |
|
if (fn == NULL) { |
236 |
|
strcpy(ctx->fname, "<stdin>"); |
240 |
|
return(MG_OK); |
241 |
|
} |
242 |
|
/* get name relative to this context */ |
243 |
< |
if (mg_file != NULL && |
226 |
< |
(cp = strrchr(mg_file->fname, '/')) != NULL) |
227 |
< |
olen = cp - mg_file->fname + 1; |
228 |
< |
else |
229 |
< |
olen = 0; |
230 |
< |
if (olen) |
243 |
> |
if (mg_file != NULL && (cp = strrchr(mg_file->fname, '/')) != NULL) { |
244 |
|
strcpy(ctx->fname, mg_file->fname); |
245 |
< |
strcpy(ctx->fname+olen, fn); |
245 |
> |
strcpy(ctx->fname+(cp-mg_file->fname+1), fn); |
246 |
> |
} else |
247 |
> |
strcpy(ctx->fname, fn); |
248 |
|
ctx->fp = fopen(ctx->fname, "r"); |
249 |
|
if (ctx->fp == NULL) |
250 |
|
return(MG_ENOFILE); |
266 |
|
} |
267 |
|
|
268 |
|
|
269 |
+ |
void |
270 |
+ |
mg_fgetpos(pos) /* get current position in input file */ |
271 |
+ |
register MG_FPOS *pos; |
272 |
+ |
{ |
273 |
+ |
extern long ftell(); |
274 |
+ |
|
275 |
+ |
pos->fid = mg_file->fid; |
276 |
+ |
pos->lineno = mg_file->lineno; |
277 |
+ |
pos->offset = ftell(mg_file->fp); |
278 |
+ |
} |
279 |
+ |
|
280 |
+ |
|
281 |
|
int |
282 |
< |
mg_rewind() /* rewind input file */ |
282 |
> |
mg_fgoto(pos) /* reposition input file pointer */ |
283 |
> |
register MG_FPOS *pos; |
284 |
|
{ |
285 |
< |
if (mg_file->lineno == 0) |
285 |
> |
if (pos->fid != mg_file->fid) |
286 |
> |
return(MG_ESEEK); |
287 |
> |
if (pos->lineno == mg_file->lineno) |
288 |
|
return(MG_OK); |
289 |
|
if (mg_file->fp == stdin) |
290 |
|
return(MG_ESEEK); /* cannot seek on standard input */ |
291 |
< |
if (fseek(mg_file->fp, 0L, 0) == EOF) |
291 |
> |
if (fseek(mg_file->fp, pos->offset, 0) == EOF) |
292 |
|
return(MG_ESEEK); |
293 |
< |
mg_file->lineno = 0; |
293 |
> |
mg_file->lineno = pos->lineno; |
294 |
|
return(MG_OK); |
295 |
|
} |
296 |
|
|
339 |
|
return(MG_OK); /* no words in line */ |
340 |
|
*ap = NULL; |
341 |
|
/* else handle it */ |
342 |
< |
return(handle_it(-1, ap-argv, argv)); |
342 |
> |
return(mg_handle(-1, ap-argv, argv)); |
343 |
|
} |
344 |
|
|
345 |
|
|
348 |
|
char *fn; |
349 |
|
{ |
350 |
|
MG_FCTXT cntxt; |
351 |
< |
int rval; |
351 |
> |
register int rval; |
352 |
|
|
353 |
|
if ((rval = mg_open(&cntxt, fn)) != MG_OK) { |
354 |
|
fprintf(stderr, "%s: %s\n", fn, mg_err[rval]); |
355 |
|
return(rval); |
356 |
|
} |
357 |
< |
while (mg_read()) /* parse each line */ |
357 |
> |
while ((rval = mg_read()) > 0) { /* parse each line */ |
358 |
> |
if (rval >= MG_MAXLINE-1 && cntxt.inpline[rval-1] != '\n') { |
359 |
> |
fprintf(stderr, "%s: %d: %s\n", cntxt.fname, |
360 |
> |
cntxt.lineno, mg_err[rval=MG_ELINE]); |
361 |
> |
break; |
362 |
> |
} |
363 |
|
if ((rval = mg_parse()) != MG_OK) { |
364 |
|
fprintf(stderr, "%s: %d: %s:\n%s", cntxt.fname, |
365 |
|
cntxt.lineno, mg_err[rval], |
366 |
|
cntxt.inpline); |
367 |
|
break; |
368 |
|
} |
369 |
+ |
} |
370 |
|
mg_close(); |
371 |
|
return(rval); |
372 |
|
} |
373 |
|
|
374 |
|
|
375 |
+ |
int |
376 |
+ |
mg_defuhand(ac, av) /* default handler for unknown entities */ |
377 |
+ |
int ac; |
378 |
+ |
char **av; |
379 |
+ |
{ |
380 |
+ |
if (mg_nunknown++ == 0) /* report first incident */ |
381 |
+ |
fprintf(stderr, "%s: %d: %s: %s\n", mg_file->fname, |
382 |
+ |
mg_file->lineno, mg_err[MG_EUNK], av[0]); |
383 |
+ |
return(MG_OK); |
384 |
+ |
} |
385 |
+ |
|
386 |
+ |
|
387 |
|
void |
388 |
|
mg_clear() /* clear parser history */ |
389 |
|
{ |
392 |
|
} |
393 |
|
|
394 |
|
|
347 |
– |
int |
348 |
– |
mg_iterate(ac, av, f) /* iterate on statement */ |
349 |
– |
int ac; |
350 |
– |
register char **av; |
351 |
– |
int (*f)(); |
352 |
– |
{ |
353 |
– |
int niter, rval; |
354 |
– |
register int i, j; |
355 |
– |
char *argv[MG_MAXARGC]; |
356 |
– |
char cntbuf[10]; |
357 |
– |
/* build partial transformation */ |
358 |
– |
for (i = 0; i < ac; i++) { |
359 |
– |
if (av[i][0] == '-' && av[i][1] == 'a' && av[i][2] == '\0') |
360 |
– |
break; |
361 |
– |
argv[i+1] = av[i]; |
362 |
– |
} |
363 |
– |
argv[i+1] = NULL; |
364 |
– |
if (i) { /* handle transformation */ |
365 |
– |
argv[0] = mg_ename[MG_E_XF]; |
366 |
– |
if ((rval = handle_it(MG_E_XF, i+1, argv)) != MG_OK) |
367 |
– |
return(rval); |
368 |
– |
} |
369 |
– |
if (i < ac) { /* run array */ |
370 |
– |
if (i+1 >= ac || !isint(av[i+1])) |
371 |
– |
return(MG_ETYPE); |
372 |
– |
niter = atoi(av[i+1]); |
373 |
– |
argv[0] = mg_ename[MG_E_OBJECT]; |
374 |
– |
argv[1] = cntbuf; |
375 |
– |
for (j = 2; j+i < ac; j++) |
376 |
– |
argv[j] = av[j+i]; |
377 |
– |
argv[j] = NULL; |
378 |
– |
for (j = 0; j < niter; j++) { |
379 |
– |
sprintf(cntbuf, "%d", j); |
380 |
– |
if ((rval = handle_it(MG_E_OBJECT, 2, argv)) != MG_OK) |
381 |
– |
return(rval); |
382 |
– |
argv[0] = "-i"; |
383 |
– |
if ((rval = mg_iterate(ac-i, argv, f)) != MG_OK) |
384 |
– |
return(rval); |
385 |
– |
argv[0] = mg_ename[MG_E_OBJECT]; |
386 |
– |
if ((rval = handle_it(MG_E_OBJECT, 1, argv)) != MG_OK) |
387 |
– |
return(rval); |
388 |
– |
} |
389 |
– |
} else if ((rval = (*f)()) != MG_OK) /* else do this instance */ |
390 |
– |
return(rval); |
391 |
– |
if (i) { /* reset the transform */ |
392 |
– |
argv[0] = mg_ename[MG_E_XF]; |
393 |
– |
argv[1] = NULL; |
394 |
– |
(void)handle_it(MG_E_XF, 1, argv); |
395 |
– |
} |
396 |
– |
return(MG_OK); |
397 |
– |
} |
398 |
– |
|
399 |
– |
|
395 |
|
/**************************************************************************** |
396 |
|
* The following routines handle unsupported entities |
397 |
|
*/ |
407 |
|
|
408 |
|
|
409 |
|
static int |
415 |
– |
reload_file() /* reload current MGF file */ |
416 |
– |
{ |
417 |
– |
register int rval; |
418 |
– |
|
419 |
– |
if ((rval = mg_rewind()) != MG_OK) |
420 |
– |
return(rval); |
421 |
– |
while (mg_read()) |
422 |
– |
if ((rval = mg_parse()) != MG_OK) |
423 |
– |
return(rval); |
424 |
– |
return(MG_OK); |
425 |
– |
} |
426 |
– |
|
427 |
– |
|
428 |
– |
static int |
410 |
|
e_include(ac, av) /* include file */ |
411 |
|
int ac; |
412 |
|
char **av; |
413 |
|
{ |
414 |
+ |
char *xfarg[MG_MAXARGC]; |
415 |
|
MG_FCTXT ictx; |
416 |
< |
int rv; |
416 |
> |
XF_SPEC *xf_orig = xf_context; |
417 |
> |
register int rv; |
418 |
|
|
419 |
|
if (ac < 2) |
420 |
|
return(MG_EARGC); |
421 |
|
if ((rv = mg_open(&ictx, av[1])) != MG_OK) |
422 |
|
return(rv); |
423 |
< |
if ((rv = mg_iterate(ac-2, av+2, reload_file)) != MG_OK) { |
424 |
< |
fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, |
425 |
< |
ictx.lineno, mg_err[rv], ictx.inpline); |
426 |
< |
mg_close(); |
427 |
< |
return(MG_EINCL); |
423 |
> |
if (ac > 2) { |
424 |
> |
register int i; |
425 |
> |
|
426 |
> |
xfarg[0] = mg_ename[MG_E_XF]; |
427 |
> |
for (i = 1; i < ac-1; i++) |
428 |
> |
xfarg[i] = av[i+1]; |
429 |
> |
xfarg[ac-1] = NULL; |
430 |
> |
if ((rv = mg_handle(MG_E_XF, ac-1, xfarg)) != MG_OK) |
431 |
> |
return(rv); |
432 |
|
} |
433 |
+ |
do { |
434 |
+ |
while ((rv = mg_read()) > 0) { |
435 |
+ |
if (rv >= MG_MAXLINE-1 && ictx.inpline[rv-1] != '\n') { |
436 |
+ |
fprintf(stderr, "%s: %d: %s\n", ictx.fname, |
437 |
+ |
ictx.lineno, mg_err[MG_ELINE]); |
438 |
+ |
mg_close(); |
439 |
+ |
return(MG_EINCL); |
440 |
+ |
} |
441 |
+ |
if ((rv = mg_parse()) != MG_OK) { |
442 |
+ |
fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, |
443 |
+ |
ictx.lineno, mg_err[rv], |
444 |
+ |
ictx.inpline); |
445 |
+ |
mg_close(); |
446 |
+ |
return(MG_EINCL); |
447 |
+ |
} |
448 |
+ |
} |
449 |
+ |
if (ac > 2) |
450 |
+ |
if ((rv = mg_handle(MG_E_XF, 1, xfarg)) != MG_OK) |
451 |
+ |
return(rv); |
452 |
+ |
} while (xf_context != xf_orig); |
453 |
|
mg_close(); |
454 |
|
return(MG_OK); |
455 |
|
} |
497 |
|
rad = atof(av[2]); |
498 |
|
/* initialize */ |
499 |
|
warpconends = 1; |
500 |
< |
if ((rval = handle_it(MG_E_VERTEX, 3, v2ent)) != MG_OK) |
500 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 3, v2ent)) != MG_OK) |
501 |
|
return(rval); |
502 |
|
sprintf(p2x, FLTFMT, cv->p[0]); |
503 |
|
sprintf(p2y, FLTFMT, cv->p[1]); |
504 |
|
sprintf(p2z, FLTFMT, cv->p[2]+rad); |
505 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
505 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
506 |
|
return(rval); |
507 |
|
r2[0] = '0'; r2[1] = '\0'; |
508 |
|
for (i = 1; i <= 2*mg_nqcdivs; i++) { |
509 |
|
theta = i*(PI/2)/mg_nqcdivs; |
510 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
510 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
511 |
|
return(rval); |
512 |
|
sprintf(p2z, FLTFMT, cv->p[2]+rad*cos(theta)); |
513 |
< |
if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
513 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
514 |
|
return(rval); |
515 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
515 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
516 |
|
return(rval); |
517 |
|
strcpy(r1, r2); |
518 |
|
sprintf(r2, FLTFMT, rad*sin(theta)); |
519 |
< |
if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) |
519 |
> |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
520 |
|
return(rval); |
521 |
|
} |
522 |
|
warpconends = 0; |
571 |
|
for (j = 0; j < 3; j++) |
572 |
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
573 |
|
.5*sgn*(maxrad-minrad)*cv->n[j]); |
574 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
574 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
575 |
|
return(rval); |
576 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
576 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
577 |
|
return(rval); |
578 |
|
sprintf(r2, FLTFMT, avgrad=.5*(minrad+maxrad)); |
579 |
|
/* run outer section */ |
580 |
|
for (i = 1; i <= 2*mg_nqcdivs; i++) { |
581 |
|
theta = i*(PI/2)/mg_nqcdivs; |
582 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
582 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
583 |
|
return(rval); |
584 |
|
for (j = 0; j < 3; j++) |
585 |
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
586 |
|
.5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]); |
587 |
< |
if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
587 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
588 |
|
return(rval); |
589 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
589 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
590 |
|
return(rval); |
591 |
|
strcpy(r1, r2); |
592 |
|
sprintf(r2, FLTFMT, avgrad + .5*(maxrad-minrad)*sin(theta)); |
593 |
< |
if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) |
593 |
> |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
594 |
|
return(rval); |
595 |
|
} |
596 |
|
/* run inner section */ |
600 |
|
for (j = 0; j < 3; j++) |
601 |
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
602 |
|
.5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]); |
603 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
603 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
604 |
|
return(rval); |
605 |
< |
if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
605 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
606 |
|
return(rval); |
607 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
607 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
608 |
|
return(rval); |
609 |
|
strcpy(r1, r2); |
610 |
|
sprintf(r2, FLTFMT, -avgrad - .5*(maxrad-minrad)*sin(theta)); |
611 |
< |
if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) |
611 |
> |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
612 |
|
return(rval); |
613 |
|
} |
614 |
|
warpconends = 0; |
629 |
|
avnew[2] = av[2]; |
630 |
|
avnew[3] = av[3]; |
631 |
|
avnew[4] = av[2]; |
632 |
< |
return(handle_it(MG_E_CONE, 5, avnew)); |
632 |
> |
return(mg_handle(MG_E_CONE, 5, avnew)); |
633 |
|
} |
634 |
|
|
635 |
|
|
671 |
|
make_axes(u, v, cv->n); |
672 |
|
for (j = 0; j < 3; j++) |
673 |
|
sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*u[j]); |
674 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
674 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
675 |
|
return(rv); |
676 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
676 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
677 |
|
return(rv); |
678 |
|
if (minrad == 0.) { /* closed */ |
679 |
|
v1ent[3] = av[1]; |
680 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
680 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
681 |
|
return(rv); |
682 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, nzent)) != MG_OK) |
682 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, nzent)) != MG_OK) |
683 |
|
return(rv); |
684 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
685 |
|
theta = i*(PI/2)/mg_nqcdivs; |
686 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
686 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
687 |
|
return(rv); |
688 |
|
for (j = 0; j < 3; j++) |
689 |
|
sprintf(p3[j], FLTFMT, cv->p[j] + |
690 |
|
maxrad*u[j]*cos(theta) + |
691 |
|
maxrad*v[j]*sin(theta)); |
692 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
692 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
693 |
|
return(rv); |
694 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
694 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
695 |
|
return(rv); |
696 |
< |
if ((rv = handle_it(MG_E_FACE, 4, fent)) != MG_OK) |
696 |
> |
if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK) |
697 |
|
return(rv); |
698 |
|
} |
699 |
|
} else { /* open */ |
700 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
700 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
701 |
|
return(rv); |
702 |
|
for (j = 0; j < 3; j++) |
703 |
|
sprintf(p4[j], FLTFMT, cv->p[j] + minrad*u[j]); |
704 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
704 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
705 |
|
return(rv); |
706 |
|
v1ent[3] = "_rv4"; |
707 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
708 |
|
theta = i*(PI/2)/mg_nqcdivs; |
709 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
709 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
710 |
|
return(rv); |
711 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
711 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
712 |
|
return(rv); |
713 |
|
for (j = 0; j < 3; j++) { |
714 |
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
715 |
|
sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*d); |
716 |
|
sprintf(p4[j], FLTFMT, cv->p[j] + minrad*d); |
717 |
|
} |
718 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
718 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
719 |
|
return(rv); |
720 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
720 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
721 |
|
return(rv); |
722 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
722 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
723 |
|
return(rv); |
724 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
724 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
725 |
|
return(rv); |
726 |
< |
if ((rv = handle_it(MG_E_FACE, 5, fent)) != MG_OK) |
726 |
> |
if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK) |
727 |
|
return(rv); |
728 |
|
} |
729 |
|
} |
746 |
|
static char *p4ent[5] = {mg_ename[MG_E_POINT],p4[0],p4[1],p4[2]}; |
747 |
|
static char *n4ent[5] = {mg_ename[MG_E_NORMAL],n4[0],n4[1],n4[2]}; |
748 |
|
static char *fent[6] = {mg_ename[MG_E_FACE],"_cv1","_cv2","_cv3","_cv4"}; |
749 |
+ |
char *v1n; |
750 |
|
register C_VERTEX *cv1, *cv2; |
751 |
|
register int i, j; |
752 |
|
FVECT u, v, w; |
762 |
|
if ((cv1 = c_getvert(av[1])) == NULL || |
763 |
|
(cv2 = c_getvert(av[3])) == NULL) |
764 |
|
return(MG_EUNDEF); |
765 |
+ |
v1n = av[1]; |
766 |
|
if (!isflt(av[2]) || !isflt(av[4])) |
767 |
|
return(MG_ETYPE); |
768 |
|
rad1 = atof(av[2]); |
781 |
|
cv = cv1; |
782 |
|
cv1 = cv2; |
783 |
|
cv2 = cv; |
784 |
+ |
v1n = av[3]; |
785 |
|
d = rad1; |
786 |
|
rad1 = rad2; |
787 |
|
rad2 = d; |
808 |
|
else |
809 |
|
sprintf(n3[j], FLTFMT, u[j] + w[j]*n2off); |
810 |
|
} |
811 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
811 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
812 |
|
return(rv); |
813 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
813 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
814 |
|
return(rv); |
815 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
815 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
816 |
|
return(rv); |
817 |
|
if (rad1 == 0.) { /* triangles */ |
818 |
< |
v1ent[3] = av[1]; |
819 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
818 |
> |
v1ent[3] = v1n; |
819 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
820 |
|
return(rv); |
821 |
|
for (j = 0; j < 3; j++) |
822 |
|
sprintf(n4[j], FLTFMT, w[j]); |
823 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
823 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
824 |
|
return(rv); |
825 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
826 |
|
theta = sgn*i*(PI/2)/mg_nqcdivs; |
827 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
827 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
828 |
|
return(rv); |
829 |
|
for (j = 0; j < 3; j++) { |
830 |
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
832 |
|
if (n2off > -FHUGE) |
833 |
|
sprintf(n3[j], FLTFMT, d + w[j]*n2off); |
834 |
|
} |
835 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
835 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
836 |
|
return(rv); |
837 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
837 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
838 |
|
return(rv); |
839 |
|
if (n2off > -FHUGE && |
840 |
< |
(rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
840 |
> |
(rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
841 |
|
return(rv); |
842 |
< |
if ((rv = handle_it(MG_E_FACE, 4, fent)) != MG_OK) |
842 |
> |
if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK) |
843 |
|
return(rv); |
844 |
|
} |
845 |
|
} else { /* quads */ |
858 |
|
else |
859 |
|
sprintf(n4[j], FLTFMT, u[j] + w[j]*n1off); |
860 |
|
} |
861 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
861 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
862 |
|
return(rv); |
863 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
863 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
864 |
|
return(rv); |
865 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
865 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
866 |
|
return(rv); |
867 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
868 |
|
theta = sgn*i*(PI/2)/mg_nqcdivs; |
869 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
869 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
870 |
|
return(rv); |
871 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
871 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
872 |
|
return(rv); |
873 |
|
for (j = 0; j < 3; j++) { |
874 |
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
879 |
|
if (n1off < FHUGE) |
880 |
|
sprintf(n4[j], FLTFMT, d + w[j]*n1off); |
881 |
|
} |
882 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
882 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
883 |
|
return(rv); |
884 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
884 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
885 |
|
return(rv); |
886 |
|
if (n2off > -FHUGE && |
887 |
< |
(rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
887 |
> |
(rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
888 |
|
return(rv); |
889 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
889 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
890 |
|
return(rv); |
891 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
891 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
892 |
|
return(rv); |
893 |
|
if (n1off < FHUGE && |
894 |
< |
(rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
894 |
> |
(rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
895 |
|
return(rv); |
896 |
< |
if ((rv = handle_it(MG_E_FACE, 5, fent)) != MG_OK) |
896 |
> |
if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK) |
897 |
|
return(rv); |
898 |
|
} |
899 |
|
} |
907 |
|
char **av; |
908 |
|
{ |
909 |
|
static char p[3][24]; |
910 |
< |
static char *vent[4] = {mg_ename[MG_E_VERTEX],NULL,"="}; |
910 |
> |
static char *vent[5] = {mg_ename[MG_E_VERTEX],NULL,"="}; |
911 |
|
static char *pent[5] = {mg_ename[MG_E_POINT],p[0],p[1],p[2]}; |
912 |
+ |
static char *znorm[5] = {mg_ename[MG_E_NORMAL],"0","0","0"}; |
913 |
|
char *newav[MG_MAXARGC], nvn[MG_MAXARGC-1][8]; |
914 |
|
double length; |
915 |
+ |
int hasnorm; |
916 |
|
FVECT v1, v2, v3, norm; |
917 |
|
register C_VERTEX *cv; |
918 |
|
C_VERTEX *cv0; |
919 |
|
int rv; |
920 |
|
register int i, j; |
921 |
< |
|
921 |
> |
/* check arguments */ |
922 |
|
if (ac < 5) |
923 |
|
return(MG_EARGC); |
924 |
|
if (!isflt(av[ac-1])) |
926 |
|
length = atof(av[ac-1]); |
927 |
|
if (length <= FTINY && length >= -FTINY) |
928 |
|
return(MG_EILL); |
929 |
< |
/* do bottom face */ |
918 |
< |
newav[0] = mg_ename[MG_E_FACE]; |
919 |
< |
for (i = 1; i < ac-1; i++) |
920 |
< |
newav[i] = av[i]; |
921 |
< |
newav[i] = NULL; |
922 |
< |
if ((rv = handle_it(MG_E_FACE, i, newav)) != MG_OK) |
923 |
< |
return(rv); |
924 |
< |
/* compute face normal */ |
929 |
> |
/* compute face normal */ |
930 |
|
if ((cv0 = c_getvert(av[1])) == NULL) |
931 |
|
return(MG_EUNDEF); |
932 |
+ |
hasnorm = 0; |
933 |
|
norm[0] = norm[1] = norm[2] = 0.; |
934 |
|
v1[0] = v1[1] = v1[2] = 0.; |
935 |
|
for (i = 2; i < ac-1; i++) { |
936 |
|
if ((cv = c_getvert(av[i])) == NULL) |
937 |
|
return(MG_EUNDEF); |
938 |
+ |
hasnorm += !is0vect(cv->n); |
939 |
|
v2[0] = cv->p[0] - cv0->p[0]; |
940 |
|
v2[1] = cv->p[1] - cv0->p[1]; |
941 |
|
v2[2] = cv->p[2] - cv0->p[2]; |
947 |
|
} |
948 |
|
if (normalize(norm) == 0.) |
949 |
|
return(MG_EILL); |
950 |
< |
/* create moved vertices */ |
950 |
> |
/* create moved vertices */ |
951 |
|
for (i = 1; i < ac-1; i++) { |
952 |
|
sprintf(nvn[i-1], "_pv%d", i); |
953 |
|
vent[1] = nvn[i-1]; |
954 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, vent)) != MG_OK) |
954 |
> |
vent[3] = av[i]; |
955 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK) |
956 |
|
return(rv); |
957 |
|
cv = c_getvert(av[i]); /* checked above */ |
958 |
|
for (j = 0; j < 3; j++) |
959 |
|
sprintf(p[j], FLTFMT, cv->p[j] - length*norm[j]); |
960 |
< |
if ((rv = handle_it(MG_E_POINT, 4, pent)) != MG_OK) |
960 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, pent)) != MG_OK) |
961 |
|
return(rv); |
954 |
– |
newav[ac-1-i] = nvn[i-1]; /* reverse */ |
962 |
|
} |
963 |
< |
/* do top face */ |
964 |
< |
if ((rv = handle_it(MG_E_FACE, ac-1, newav)) != MG_OK) |
958 |
< |
return(rv); |
963 |
> |
/* make faces */ |
964 |
> |
newav[0] = mg_ename[MG_E_FACE]; |
965 |
|
/* do the side faces */ |
966 |
|
newav[5] = NULL; |
967 |
|
newav[3] = av[ac-2]; |
969 |
|
for (i = 1; i < ac-1; i++) { |
970 |
|
newav[1] = nvn[i-1]; |
971 |
|
newav[2] = av[i]; |
972 |
< |
if ((rv = handle_it(MG_E_FACE, 5, newav)) != MG_OK) |
972 |
> |
if ((rv = mg_handle(MG_E_FACE, 5, newav)) != MG_OK) |
973 |
|
return(rv); |
974 |
|
newav[3] = newav[2]; |
975 |
|
newav[4] = newav[1]; |
976 |
|
} |
977 |
+ |
/* do top face */ |
978 |
+ |
for (i = 1; i < ac-1; i++) { |
979 |
+ |
if (hasnorm) { /* zero normals */ |
980 |
+ |
vent[1] = nvn[i-1]; |
981 |
+ |
if ((rv = mg_handle(MG_E_VERTEX, 2, vent)) != MG_OK) |
982 |
+ |
return(rv); |
983 |
+ |
if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK) |
984 |
+ |
return(rv); |
985 |
+ |
} |
986 |
+ |
newav[ac-1-i] = nvn[i-1]; /* reverse */ |
987 |
+ |
} |
988 |
+ |
if ((rv = mg_handle(MG_E_FACE, ac-1, newav)) != MG_OK) |
989 |
+ |
return(rv); |
990 |
+ |
/* do bottom face */ |
991 |
+ |
if (hasnorm) |
992 |
+ |
for (i = 1; i < ac-1; i++) { |
993 |
+ |
vent[1] = nvn[i-1]; |
994 |
+ |
vent[3] = av[i]; |
995 |
+ |
if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK) |
996 |
+ |
return(rv); |
997 |
+ |
if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK) |
998 |
+ |
return(rv); |
999 |
+ |
newav[i] = nvn[i-1]; |
1000 |
+ |
} |
1001 |
+ |
else |
1002 |
+ |
for (i = 1; i < ac-1; i++) |
1003 |
+ |
newav[i] = av[i]; |
1004 |
+ |
newav[i] = NULL; |
1005 |
+ |
if ((rv = mg_handle(MG_E_FACE, i, newav)) != MG_OK) |
1006 |
+ |
return(rv); |
1007 |
|
return(MG_OK); |
1008 |
|
} |
1009 |
|
|
1010 |
|
|
1011 |
|
static int |
1012 |
< |
e_cspec(ac, av) /* handle spectral color */ |
977 |
< |
int ac; |
978 |
< |
char **av; |
1012 |
> |
put_cxy() /* put out current xy chromaticities */ |
1013 |
|
{ |
1014 |
|
static char xbuf[24], ybuf[24]; |
1015 |
|
static char *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf}; |
1016 |
|
int rv; |
1017 |
|
|
1018 |
+ |
sprintf(xbuf, "%.4f", c_ccolor->cx); |
1019 |
+ |
sprintf(ybuf, "%.4f", c_ccolor->cy); |
1020 |
+ |
if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK) |
1021 |
+ |
return(rv); |
1022 |
+ |
return(MG_OK); |
1023 |
+ |
} |
1024 |
+ |
|
1025 |
+ |
|
1026 |
+ |
static int |
1027 |
+ |
put_cspec() /* put out current color spectrum */ |
1028 |
+ |
{ |
1029 |
+ |
char wl[2][6], vbuf[C_CNSS][24]; |
1030 |
+ |
char *newav[C_CNSS+4]; |
1031 |
+ |
double sf; |
1032 |
+ |
register int i; |
1033 |
+ |
|
1034 |
+ |
if (mg_ehand[MG_E_CSPEC] != c_hcolor) { |
1035 |
+ |
sprintf(wl[0], "%d", C_CMINWL); |
1036 |
+ |
sprintf(wl[1], "%d", C_CMAXWL); |
1037 |
+ |
newav[0] = mg_ename[MG_E_CSPEC]; |
1038 |
+ |
newav[1] = wl[0]; |
1039 |
+ |
newav[2] = wl[1]; |
1040 |
+ |
sf = (double)C_CNSS / c_ccolor->ssum; |
1041 |
+ |
for (i = 0; i < C_CNSS; i++) { |
1042 |
+ |
sprintf(vbuf[i], "%.4f", sf*c_ccolor->ssamp[i]); |
1043 |
+ |
newav[i+3] = vbuf[i]; |
1044 |
+ |
} |
1045 |
+ |
newav[C_CNSS+3] = NULL; |
1046 |
+ |
if ((i = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK) |
1047 |
+ |
return(i); |
1048 |
+ |
} |
1049 |
+ |
return(MG_OK); |
1050 |
+ |
} |
1051 |
+ |
|
1052 |
+ |
|
1053 |
+ |
static int |
1054 |
+ |
e_cspec(ac, av) /* handle spectral color */ |
1055 |
+ |
int ac; |
1056 |
+ |
char **av; |
1057 |
+ |
{ |
1058 |
+ |
/* convert to xy chromaticity */ |
1059 |
|
c_ccvt(c_ccolor, C_CSXY); |
1060 |
|
/* if it's really their handler, use it */ |
1061 |
< |
if (mg_ehand[MG_E_CXY] != c_hcolor) { |
1062 |
< |
sprintf(xbuf, "%.4f", c_ccolor->cx); |
988 |
< |
sprintf(ybuf, "%.4f", c_ccolor->cy); |
989 |
< |
if ((rv = handle_it(MG_E_CXY, 3, ccom)) != MG_OK) |
990 |
< |
return(rv); |
991 |
< |
} |
1061 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1062 |
> |
return(put_cxy()); |
1063 |
|
return(MG_OK); |
1064 |
|
} |
1065 |
|
|
1069 |
|
int ac; |
1070 |
|
char **av; |
1071 |
|
{ |
1001 |
– |
char wl[2][6], vbuf[C_CNSS][24]; |
1002 |
– |
char *newav[C_CNSS+4]; |
1003 |
– |
int rv; |
1004 |
– |
register int i; |
1072 |
|
/* |
1073 |
|
* Contorted logic works as follows: |
1074 |
|
* 1. the colors are already mixed in c_hcolor() support function |
1079 |
|
*/ |
1080 |
|
if (mg_ehand[MG_E_CSPEC] == e_cspec) |
1081 |
|
c_ccvt(c_ccolor, C_CSXY); |
1082 |
< |
else if (c_ccolor->flags & C_CDSPEC) { |
1083 |
< |
if (mg_ehand[MG_E_CSPEC] != c_hcolor) { |
1084 |
< |
sprintf(wl[0], "%d", C_CMINWL); |
1085 |
< |
sprintf(wl[1], "%d", C_CMAXWL); |
1086 |
< |
newav[0] = mg_ename[MG_E_CSPEC]; |
1087 |
< |
newav[1] = wl[0]; |
1088 |
< |
newav[2] = wl[1]; |
1089 |
< |
for (i = 0; i < C_CNSS; i++) { |
1090 |
< |
sprintf(vbuf[i], "%.6f", |
1091 |
< |
(double)c_ccolor->ssamp[i] / |
1092 |
< |
c_ccolor->ssum); |
1093 |
< |
newav[i+3] = vbuf[i]; |
1094 |
< |
} |
1095 |
< |
newav[C_CNSS+3] = NULL; |
1096 |
< |
if ((rv = handle_it(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK) |
1097 |
< |
return(rv); |
1098 |
< |
} |
1099 |
< |
return(MG_OK); |
1100 |
< |
} |
1101 |
< |
if (mg_ehand[MG_E_CXY] != c_hcolor) { |
1102 |
< |
sprintf(vbuf[0], "%.4f", c_ccolor->cx); |
1103 |
< |
sprintf(vbuf[1], "%.4f", c_ccolor->cy); |
1104 |
< |
newav[0] = mg_ename[MG_E_CXY]; |
1105 |
< |
newav[1] = vbuf[0]; |
1039 |
< |
newav[2] = vbuf[1]; |
1040 |
< |
newav[3] = NULL; |
1041 |
< |
if ((rv = handle_it(MG_E_CXY, 3, newav)) != MG_OK) |
1042 |
< |
return(rv); |
1043 |
< |
} |
1082 |
> |
else if (c_ccolor->flags & C_CDSPEC) |
1083 |
> |
return(put_cspec()); |
1084 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1085 |
> |
return(put_cxy()); |
1086 |
> |
return(MG_OK); |
1087 |
> |
} |
1088 |
> |
|
1089 |
> |
|
1090 |
> |
static int |
1091 |
> |
e_cct(ac, av) /* handle color temperature */ |
1092 |
> |
int ac; |
1093 |
> |
char **av; |
1094 |
> |
{ |
1095 |
> |
/* |
1096 |
> |
* Logic is similar to e_cmix here. Support handler has already |
1097 |
> |
* converted temperature to spectral color. Put it out as such |
1098 |
> |
* if they support it, otherwise convert to xy chromaticity and |
1099 |
> |
* put it out if they handle it. |
1100 |
> |
*/ |
1101 |
> |
if (mg_ehand[MG_E_CSPEC] != e_cspec) |
1102 |
> |
return(put_cspec()); |
1103 |
> |
c_ccvt(c_ccolor, C_CSXY); |
1104 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1105 |
> |
return(put_cxy()); |
1106 |
|
return(MG_OK); |
1107 |
|
} |