Annotation of OpenXM_contrib2/asir2000/plot/if.c, Revision 1.5
1.2 noro 1: /*
2: * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
3: * All rights reserved.
4: *
5: * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
6: * non-exclusive and royalty-free license to use, copy, modify and
7: * redistribute, solely for non-commercial and non-profit purposes, the
8: * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
9: * conditions of this Agreement. For the avoidance of doubt, you acquire
10: * only a limited right to use the SOFTWARE hereunder, and FLL or any
11: * third party developer retains all rights, including but not limited to
12: * copyrights, in and to the SOFTWARE.
13: *
14: * (1) FLL does not grant you a license in any way for commercial
15: * purposes. You may use the SOFTWARE only for non-commercial and
16: * non-profit purposes only, such as academic, research and internal
17: * business use.
18: * (2) The SOFTWARE is protected by the Copyright Law of Japan and
19: * international copyright treaties. If you make copies of the SOFTWARE,
20: * with or without modification, as permitted hereunder, you shall affix
21: * to all such copies of the SOFTWARE the above copyright notice.
22: * (3) An explicit reference to this SOFTWARE and its copyright owner
23: * shall be made on your publication or presentation in any form of the
24: * results obtained by use of the SOFTWARE.
25: * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.3 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2 noro 27: * for such modification or the source code of the modified part of the
28: * SOFTWARE.
29: *
30: * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
31: * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
32: * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
33: * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
34: * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
35: * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
36: * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
37: * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
38: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
39: * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
40: * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
41: * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
42: * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
43: * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
44: * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
45: * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
46: * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
47: *
1.5 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/plot/if.c,v 1.4 2000/11/07 06:06:40 noro Exp $
1.2 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "parse.h"
52: #include "ox.h"
53: #include "ifplot.h"
54:
55: extern jmp_buf ox_env;
56:
1.4 noro 57: int open_canvas(NODE arg)
58: {
59: int id;
60: struct canvas *can;
61: LIST wsize;
62: STRING wname;
63:
64: wsize = (LIST)ARG0(arg);
65: wname = (STRING)ARG1(arg);
66:
67: can = canvas[id = search_canvas()];
68: can->mode = MODE_INTERACTIVE;
69: if ( !wsize ) {
70: can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
71: } else {
72: can->width = QTOS((Q)BDY(BDY(wsize)));
73: can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
74: }
75: if ( wname )
76: can->wname = BDY(wname);
77: else
78: can->wname = "";
79: create_canvas(can);
80: return id;
81: }
82:
1.1 noro 83: int plot(NODE arg)
84: {
85: int id;
86: NODE n;
87: struct canvas *can;
88: P formula;
89: LIST xrange,yrange,zrange,wsize;
90: STRING wname;
91:
92: formula = (P)ARG0(arg);
93: xrange = (LIST)ARG1(arg);
94: yrange = (LIST)ARG2(arg);
95: zrange = (LIST)ARG3(arg);
96: wsize = (LIST)ARG4(arg);
97: wname = (STRING)ARG5(arg);
98:
99: can = canvas[id = search_canvas()];
100: n = BDY(xrange); can->vx = VR((P)BDY(n)); n = NEXT(n);
101: can->qxmin = (Q)BDY(n); n = NEXT(n); can->qxmax = (Q)BDY(n);
102: can->xmin = ToReal(can->qxmin); can->xmax = ToReal(can->qxmax);
103: if ( yrange ) {
104: n = BDY(yrange); can->vy = VR((P)BDY(n)); n = NEXT(n);
105: can->qymin = (Q)BDY(n); n = NEXT(n); can->qymax = (Q)BDY(n);
106: can->ymin = ToReal(can->qymin); can->ymax = ToReal(can->qymax);
107: if ( zrange ) {
108: n = NEXT(BDY(zrange));
109: can->zmin = ToReal(BDY(n)); n = NEXT(n); can->zmax = ToReal(BDY(n));
110: if ( n = NEXT(n) )
111: can->nzstep = QTOS((Q)BDY(n));
112: else
113: can->nzstep = MAXGC;
114: can->mode = MODE_CONPLOT;
115: } else
116: can->mode = MODE_IFPLOT;
117: } else
118: can->mode = MODE_PLOT;
119: if ( !wsize ) {
120: can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
121: } else {
122: can->width = QTOS((Q)BDY(BDY(wsize)));
123: can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
124: }
125: if ( wname )
126: can->wname = BDY(wname);
127: else
128: can->wname = "";
129: can->formula = formula;
130: create_canvas(can);
131: if ( can->mode == MODE_PLOT ) {
132: plotcalc(can);
133: plot_print(display,can);
134: } else
135: ifplotmain(can);
136: copy_to_canvas(can);
137: return id;
138: }
139:
140: int plotover(NODE arg)
141: {
142: int index;
143: P formula;
144: struct canvas *can;
145: struct canvas fakecan;
146: VL vl,vl0;
147:
148: index = QTOS((Q)ARG0(arg));
149: formula = (P)ARG1(arg);
150: can = canvas[index];
151: if ( !can->window )
152: return -1;
153: get_vars_recursive(formula,&vl);
154: for ( vl0 = vl; vl0; vl0 = NEXT(vl0) )
155: if ( vl0->v->attr == V_IND )
156: if ( vl->v != can->vx && vl->v != can->vy )
157: return -1;
158: current_can = can;
159: fakecan = *can; fakecan.formula = formula;
160: if ( can->mode == MODE_PLOT ) {
161: plotcalc(&fakecan);
162: plot_print(display,&fakecan);
163: } else
164: ifplotmain(&fakecan);
165: copy_to_canvas(&fakecan);
166: return index;
167: }
168:
169: int drawcircle(NODE arg)
170: {
1.4 noro 171: #if !defined(VISUAL)
1.1 noro 172: int id;
173: int index;
174: pointer ptr;
175: Q ret;
176: LIST xyr;
177: Obj x,y,r;
178: int wx,wy,wr;
179: struct canvas *can;
180: struct canvas fakecan;
181:
182: index = QTOS((Q)ARG0(arg));
183: xyr = (LIST)ARG1(arg);
184: x = (Obj)ARG0(BDY(xyr)); y = (Obj)ARG1(BDY(xyr)); r = (Obj)ARG2(BDY(xyr));
185: can = canvas[index];
186: if ( !can->window )
187: return -1;
188: else {
189: current_can = can;
190: wx = (ToReal(x)-can->xmin)*can->width/(can->xmax-can->xmin);
191: wy = (can->ymax-ToReal(y))*can->height/(can->ymax-can->ymin);
192: wr = ToReal(r);
193: XFillArc(display,can->pix,colorGC,wx-wr/2,wy-wr/2,wr,wr,0,360*64);
194: copy_to_canvas(can);
195: return index;
196: }
1.4 noro 197: #endif
198: }
199:
200: int draw_obj(NODE arg)
201: {
202: int index;
1.5 ! noro 203: int x,y,u,v,len,r;
1.4 noro 204: NODE obj,n;
205: RealVect *vect;
206: struct canvas *can;
1.5 ! noro 207: int color;
1.4 noro 208:
209: index = QTOS((Q)ARG0(arg));
210: can = canvas[index];
1.5 ! noro 211: if ( !can || !can->window ) {
! 212: set_lasterror("draw_obj : canvas does not exist");
1.4 noro 213: return -1;
1.5 ! noro 214: }
1.4 noro 215:
216: obj = BDY((LIST)ARG1(arg));
1.5 ! noro 217: if ( argc(arg) == 3 )
! 218: color = QTOS((Q)ARG2(arg));
! 219: else
! 220: color = 0; /* black */
! 221: switch ( len = length(obj) ) {
1.4 noro 222: case 2: /* point */
223: x = (int)ToReal((Q)ARG0(obj)); y = (int)ToReal((Q)ARG1(obj));
1.5 ! noro 224: draw_point(display,can,x,y,color);
! 225: MKRVECT2(vect,x,y); MKNODE(n,vect,can->history); can->history = n;
! 226: break;
! 227: case 3: /* circle */
! 228: x = (int)ToReal((Q)ARG0(obj)); y = (int)ToReal((Q)ARG1(obj));
! 229: r = (int)ToReal((Q)ARG2(obj));
! 230: MKRVECT3(vect,x,y,r); MKNODE(n,vect,can->history); can->history = n;
1.4 noro 231: break;
232: case 4: /* line */
233: x = (int)ToReal((Q)ARG0(obj)); y = (int)ToReal((Q)ARG1(obj));
234: u = (int)ToReal((Q)ARG2(obj)); v = (int)ToReal((Q)ARG3(obj));
1.5 ! noro 235: draw_line(display,can,x,y,u,v,color);
1.4 noro 236: MKRVECT4(vect,x,y,u,v); MKNODE(n,vect,can->history); can->history = n;
237: break;
238: default:
1.5 ! noro 239: set_lasterror("draw_obj : invalid request");
1.4 noro 240: return -1;
241: }
242: return 0;
243: }
244:
245: int clear_canvas(NODE arg)
246: {
247: int index;
248: struct canvas *can;
249:
250: index = QTOS((Q)ARG0(arg));
251: can = canvas[index];
252: if ( !can || !can->window )
253: return -1;
254: clear_pixmap(can);
255: copy_to_canvas(can);
256: /* clear the history */
257: can->history = 0;
1.1 noro 258: }
259:
260: #define RealtoDbl(r) ((r)?BDY(r):0.0)
261:
262: int arrayplot(NODE arg)
263: {
264: int id,ix,w,h;
265: VECT array;
266: LIST xrange,wsize;
267: char *wname;
268: NODE n;
269: Q ret;
270: double ymax,ymin,dy,xstep;
271: Real *tab;
272: struct canvas *can;
273: POINT *pa;
274:
275: array = (VECT)ARG0(arg);
276: xrange = (LIST)ARG1(arg);
277: can = canvas[id = search_canvas()];
278: n = BDY(xrange); can->vx = VR((P)BDY(n)); n = NEXT(n);
279: can->qxmin = (Q)BDY(n); n = NEXT(n); can->qxmax = (Q)BDY(n);
280: can->xmin = ToReal(can->qxmin); can->xmax = ToReal(can->qxmax);
281: if ( !wsize ) {
282: can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
283: } else {
284: can->width = QTOS((Q)BDY(BDY(wsize)));
285: can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
286: }
287: can->wname = wname; can->formula = 0; can->mode = MODE_PLOT;
288: create_canvas(can);
289: w = array->len;
290: h = can->height;
291: tab = (Real *)BDY(array);
292: if ( can->ymax == can->ymin ) {
293: for ( ymax = ymin = RealtoDbl(tab[0]), ix = 1; ix < w; ix++ ) {
294: if ( RealtoDbl(tab[ix]) > ymax )
295: ymax = RealtoDbl(tab[ix]);
296: if ( RealtoDbl(tab[ix]) < ymin )
297: ymin = RealtoDbl(tab[ix]);
298: }
299: can->ymax = ymax; can->ymin = ymin;
300: } else {
301: ymax = can->ymax; ymin = can->ymin;
302: }
303: dy = ymax-ymin;
304: can->pa = (struct pa *)MALLOC(sizeof(struct pa));
305: can->pa[0].length = w;
306: can->pa[0].pos = pa = (POINT *)MALLOC(w*sizeof(POINT));
307: xstep = (double)can->width/(double)(w-1);
308: for ( ix = 0; ix < w; ix++ ) {
309: #ifndef MAXSHORT
310: #define MAXSHORT ((short)0x7fff)
311: #endif
312: double t;
313:
314: pa[ix].x = (int)(ix*xstep);
315: t = (h - 1)*(ymax - RealtoDbl(tab[ix]))/dy;
316: if ( t > MAXSHORT )
317: pa[ix].y = MAXSHORT;
318: else if ( t < -MAXSHORT )
319: pa[ix].y = -MAXSHORT;
320: else
321: pa[ix].y = t;
322: }
323: plot_print(display,can);
324: copy_to_canvas(can);
325: return id;
326: }
327:
328: ifplot_resize(can,spos,epos)
329: struct canvas *can;
330: POINT spos,epos;
331: {
332: struct canvas *ncan;
333: struct canvas fakecan;
334: Q dx,dy,dx2,dy2,xmin,xmax,ymin,ymax,xmid,ymid;
335: Q sx,sy,ex,ey,cw,ch,ten,two;
336: Q s,t;
337: int new;
338: int w,h,m;
339: Q ret;
340:
341: if ( XC(spos) < XC(epos) && YC(spos) < YC(epos) ) {
342: if ( can->precise && !can->wide ) {
343: fakecan = *can; ncan = &fakecan;
344: } else {
345: new = search_canvas(); ncan = canvas[new];
346: }
347: ncan->mode = can->mode;
348: ncan->zmin = can->zmin; ncan->zmax = can->zmax;
349: ncan->nzstep = can->nzstep;
350: ncan->wname = can->wname;
351: ncan->vx = can->vx; ncan->vy = can->vy;
352: ncan->formula = can->formula;
353: w = XC(epos)-XC(spos);
354: h = YC(epos)-YC(spos);
355: m = MAX(can->width,can->height);
356: if ( can->precise ) {
357: ncan->width = w; ncan->height = h;
358: } else if ( w > h ) {
359: ncan->width = m; ncan->height = m * h/w;
360: } else {
361: ncan->width = m * w/h; ncan->height = m;
362: }
363: if ( can->wide ) {
364: STOQ(10,ten); STOQ(2,two);
365: subq(can->qxmax,can->qxmin,&t); mulq(t,ten,&dx);
366: subq(can->qymax,can->qymin,&t); mulq(t,ten,&dy);
367: addq(can->qxmax,can->qxmin,&t); divq(t,two,&xmid);
368: addq(can->qymax,can->qymin,&t); divq(t,two,&ymid);
369: divq(dx,two,&dx2); divq(dy,two,&dy2);
370: subq(xmid,dx2,&xmin); addq(xmid,dx2,&xmax);
371: subq(ymid,dy2,&ymin); addq(ymid,dy2,&ymax);
372: } else {
373: subq(can->qxmax,can->qxmin,&dx); subq(can->qymax,can->qymin,&dy);
374: xmin = can->qxmin; xmax = can->qxmax;
375: ymin = can->qymin; ymax = can->qymax;
376: }
377: STOQ(XC(spos),sx); STOQ(YC(spos),sy); STOQ(XC(epos),ex); STOQ(YC(epos),ey);
378: STOQ(can->width,cw); STOQ(can->height,ch);
379: mulq(sx,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmin);
380: mulq(ex,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmax);
381: mulq(ey,dy,&t); divq(t,ch,&s); subq(ymax,s,&ncan->qymin);
382: mulq(sy,dy,&t); divq(t,ch,&s); subq(ymax,s,&ncan->qymax);
383: ncan->xmin = ToReal(ncan->qxmin); ncan->xmax = ToReal(ncan->qxmax);
384: ncan->ymin = ToReal(ncan->qymin); ncan->ymax = ToReal(ncan->qymax);
385: if ( can->precise && !can->wide ) {
386: current_can = can;
387: alloc_pixmap(ncan);
1.4 noro 388: #if defined(VISUAL)
389: ncan->real_can = can;
390: #endif
1.1 noro 391: qifplotmain(ncan);
392: copy_subimage(ncan,can,spos);
393: copy_to_canvas(can);
394: } else {
395: create_canvas(ncan);
396: if ( can->precise )
397: qifplotmain(ncan);
398: else
399: ifplotmain(ncan);
400: copy_to_canvas(ncan);
401: }
402: }
403: }
404:
405: plot_resize(can,spos,epos)
406: struct canvas *can;
407: POINT spos,epos;
408: {
409: struct canvas *ncan;
410: Q dx,dx2,xmin,xmax,xmid;
411: double dy,dy2,ymin,ymax,ymid;
412: Q sx,ex,cw,ten,two;
413: double sy,ey;
414: Q s,t;
415: int new;
416: int w,h,m;
417:
418: if ( XC(spos) < XC(epos) && YC(spos) < YC(epos) ) {
419: new = search_canvas(); ncan = canvas[new];
420: ncan->mode = can->mode;
421: ncan->zmin = can->zmin; ncan->zmax = can->zmax;
422: ncan->nzstep = can->nzstep;
423: ncan->wname = can->wname;
424: ncan->vx = can->vx; ncan->vy = can->vy;
425: ncan->formula = can->formula;
426: w = XC(epos)-XC(spos);
427: h = YC(epos)-YC(spos);
428: m = MAX(can->width,can->height);
429: if ( w > h ) {
430: ncan->width = m; ncan->height = m * h/w;
431: } else {
432: ncan->width = m * w/h; ncan->height = m;
433: }
434: if ( can->wide ) {
435: STOQ(10,ten); STOQ(2,two);
436: subq(can->qxmax,can->qxmin,&t); mulq(t,ten,&dx);
437: addq(can->qxmax,can->qxmin,&t); divq(t,two,&xmid);
438: divq(dx,two,&dx2); subq(xmid,dx2,&xmin); addq(xmid,dx2,&xmax);
439:
440: dy = (can->ymax-can->ymin)*10;
441: ymid = (can->ymax+can->ymin)/2;
442: ymin = ymid-dy/2; ymax = ymid+dy/2;
443: } else {
444: subq(can->qxmax,can->qxmin,&dx);
445: xmin = can->qxmin; xmax = can->qxmax;
446:
447: dy = can->ymax-can->ymin;
448: ymin = can->ymin; ymax = can->ymax;
449: }
450: STOQ(XC(spos),sx); STOQ(XC(epos),ex); STOQ(can->width,cw);
451: mulq(sx,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmin);
452: mulq(ex,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmax);
453: ncan->xmin = ToReal(ncan->qxmin); ncan->xmax = ToReal(ncan->qxmax);
454:
455: ncan->ymin = ymax-YC(epos)*dy/can->height;
456: ncan->ymax = ymax-YC(spos)*dy/can->height;
457:
458: create_canvas(ncan);
459: plotcalc(ncan);
460: plot_print(display,ncan);
461: copy_to_canvas(ncan);
462: }
463: }
464:
465: ifplotmain(can)
466: struct canvas *can;
467: {
468: int width,height;
469: double **tabe,*tabeb;
470: int i;
471:
472: width = can->width; height = can->height;
473: tabe = (double **)ALLOCA(width*sizeof(double *));
474: for ( i = 0; i < width; i++ )
475: tabe[i] = (double *)ALLOCA(height*sizeof(double));
476: define_cursor(can->window,runningcur);
477: set_busy(can); set_selection();
478: calc(tabe,can); if_print(display,tabe,can);
479: reset_selection(); reset_busy(can);
480: define_cursor(can->window,normalcur);
481: }
482:
483: qifplotmain(can)
484: struct canvas *can;
485: {
486: int width,height;
487: char **tabe,*tabeb;
488: int i;
489:
490: width = can->width; height = can->height;
491: tabe = (char **)ALLOCA(width*sizeof(char *)+width*height*sizeof(char));
492: bzero(tabe,width*sizeof(char *)+width*height*sizeof(char));
493: for ( i = 0, tabeb = (char *)(tabe+width); i < width; i++ )
494: tabe[i] = tabeb + height*i;
495: define_cursor(can->window,runningcur);
496: set_busy(can); set_selection();
497: qcalc(tabe,can); qif_print(display,tabe,can);
498: reset_selection(); reset_busy(can);
499: define_cursor(can->window,normalcur);
500: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>