Annotation of OpenXM_contrib2/asir2000/plot/if.c, Revision 1.4
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.4 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/plot/if.c,v 1.3 2000/08/22 05:04:31 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;
! 203: int x,y,u,v,r,l;
! 204: NODE obj,n;
! 205: RealVect *vect;
! 206: struct canvas *can;
! 207:
! 208: index = QTOS((Q)ARG0(arg));
! 209: can = canvas[index];
! 210: if ( !can || !can->window )
! 211: return -1;
! 212:
! 213: obj = BDY((LIST)ARG1(arg));
! 214: switch ( l = length(obj) ) {
! 215: case 2: /* point */
! 216: x = (int)ToReal((Q)ARG0(obj)); y = (int)ToReal((Q)ARG1(obj));
! 217: draw_point(display,can,x,y);
! 218: MKRVECT2(vect,x,y);
! 219: MKNODE(n,vect,can->history);
! 220: can->history = n;
! 221: break;
! 222: // case 3: /* circle */
! 223: // x = (int)ToReal((Q)ARG0(obj)); y = (int)ToReal((Q)ARG1(obj));
! 224: // r = (int)ToReal((Q)ARG2(obj));
! 225: // break;
! 226: case 4: /* line */
! 227: x = (int)ToReal((Q)ARG0(obj)); y = (int)ToReal((Q)ARG1(obj));
! 228: u = (int)ToReal((Q)ARG2(obj)); v = (int)ToReal((Q)ARG3(obj));
! 229: draw_line(display,can,x,y,u,v);
! 230: MKRVECT4(vect,x,y,u,v); MKNODE(n,vect,can->history); can->history = n;
! 231: break;
! 232: default:
! 233: return -1;
! 234: }
! 235: return 0;
! 236: }
! 237:
! 238: int clear_canvas(NODE arg)
! 239: {
! 240: int index;
! 241: struct canvas *can;
! 242:
! 243: index = QTOS((Q)ARG0(arg));
! 244: can = canvas[index];
! 245: if ( !can || !can->window )
! 246: return -1;
! 247: clear_pixmap(can);
! 248: copy_to_canvas(can);
! 249: /* clear the history */
! 250: can->history = 0;
1.1 noro 251: }
252:
253: #define RealtoDbl(r) ((r)?BDY(r):0.0)
254:
255: int arrayplot(NODE arg)
256: {
257: int id,ix,w,h;
258: VECT array;
259: LIST xrange,wsize;
260: char *wname;
261: NODE n;
262: Q ret;
263: double ymax,ymin,dy,xstep;
264: Real *tab;
265: struct canvas *can;
266: POINT *pa;
267:
268: array = (VECT)ARG0(arg);
269: xrange = (LIST)ARG1(arg);
270: can = canvas[id = search_canvas()];
271: n = BDY(xrange); can->vx = VR((P)BDY(n)); n = NEXT(n);
272: can->qxmin = (Q)BDY(n); n = NEXT(n); can->qxmax = (Q)BDY(n);
273: can->xmin = ToReal(can->qxmin); can->xmax = ToReal(can->qxmax);
274: if ( !wsize ) {
275: can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
276: } else {
277: can->width = QTOS((Q)BDY(BDY(wsize)));
278: can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
279: }
280: can->wname = wname; can->formula = 0; can->mode = MODE_PLOT;
281: create_canvas(can);
282: w = array->len;
283: h = can->height;
284: tab = (Real *)BDY(array);
285: if ( can->ymax == can->ymin ) {
286: for ( ymax = ymin = RealtoDbl(tab[0]), ix = 1; ix < w; ix++ ) {
287: if ( RealtoDbl(tab[ix]) > ymax )
288: ymax = RealtoDbl(tab[ix]);
289: if ( RealtoDbl(tab[ix]) < ymin )
290: ymin = RealtoDbl(tab[ix]);
291: }
292: can->ymax = ymax; can->ymin = ymin;
293: } else {
294: ymax = can->ymax; ymin = can->ymin;
295: }
296: dy = ymax-ymin;
297: can->pa = (struct pa *)MALLOC(sizeof(struct pa));
298: can->pa[0].length = w;
299: can->pa[0].pos = pa = (POINT *)MALLOC(w*sizeof(POINT));
300: xstep = (double)can->width/(double)(w-1);
301: for ( ix = 0; ix < w; ix++ ) {
302: #ifndef MAXSHORT
303: #define MAXSHORT ((short)0x7fff)
304: #endif
305: double t;
306:
307: pa[ix].x = (int)(ix*xstep);
308: t = (h - 1)*(ymax - RealtoDbl(tab[ix]))/dy;
309: if ( t > MAXSHORT )
310: pa[ix].y = MAXSHORT;
311: else if ( t < -MAXSHORT )
312: pa[ix].y = -MAXSHORT;
313: else
314: pa[ix].y = t;
315: }
316: plot_print(display,can);
317: copy_to_canvas(can);
318: return id;
319: }
320:
321: ifplot_resize(can,spos,epos)
322: struct canvas *can;
323: POINT spos,epos;
324: {
325: struct canvas *ncan;
326: struct canvas fakecan;
327: Q dx,dy,dx2,dy2,xmin,xmax,ymin,ymax,xmid,ymid;
328: Q sx,sy,ex,ey,cw,ch,ten,two;
329: Q s,t;
330: int new;
331: int w,h,m;
332: Q ret;
333:
334: if ( XC(spos) < XC(epos) && YC(spos) < YC(epos) ) {
335: if ( can->precise && !can->wide ) {
336: fakecan = *can; ncan = &fakecan;
337: } else {
338: new = search_canvas(); ncan = canvas[new];
339: }
340: ncan->mode = can->mode;
341: ncan->zmin = can->zmin; ncan->zmax = can->zmax;
342: ncan->nzstep = can->nzstep;
343: ncan->wname = can->wname;
344: ncan->vx = can->vx; ncan->vy = can->vy;
345: ncan->formula = can->formula;
346: w = XC(epos)-XC(spos);
347: h = YC(epos)-YC(spos);
348: m = MAX(can->width,can->height);
349: if ( can->precise ) {
350: ncan->width = w; ncan->height = h;
351: } else if ( w > h ) {
352: ncan->width = m; ncan->height = m * h/w;
353: } else {
354: ncan->width = m * w/h; ncan->height = m;
355: }
356: if ( can->wide ) {
357: STOQ(10,ten); STOQ(2,two);
358: subq(can->qxmax,can->qxmin,&t); mulq(t,ten,&dx);
359: subq(can->qymax,can->qymin,&t); mulq(t,ten,&dy);
360: addq(can->qxmax,can->qxmin,&t); divq(t,two,&xmid);
361: addq(can->qymax,can->qymin,&t); divq(t,two,&ymid);
362: divq(dx,two,&dx2); divq(dy,two,&dy2);
363: subq(xmid,dx2,&xmin); addq(xmid,dx2,&xmax);
364: subq(ymid,dy2,&ymin); addq(ymid,dy2,&ymax);
365: } else {
366: subq(can->qxmax,can->qxmin,&dx); subq(can->qymax,can->qymin,&dy);
367: xmin = can->qxmin; xmax = can->qxmax;
368: ymin = can->qymin; ymax = can->qymax;
369: }
370: STOQ(XC(spos),sx); STOQ(YC(spos),sy); STOQ(XC(epos),ex); STOQ(YC(epos),ey);
371: STOQ(can->width,cw); STOQ(can->height,ch);
372: mulq(sx,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmin);
373: mulq(ex,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmax);
374: mulq(ey,dy,&t); divq(t,ch,&s); subq(ymax,s,&ncan->qymin);
375: mulq(sy,dy,&t); divq(t,ch,&s); subq(ymax,s,&ncan->qymax);
376: ncan->xmin = ToReal(ncan->qxmin); ncan->xmax = ToReal(ncan->qxmax);
377: ncan->ymin = ToReal(ncan->qymin); ncan->ymax = ToReal(ncan->qymax);
378: if ( can->precise && !can->wide ) {
379: current_can = can;
380: alloc_pixmap(ncan);
1.4 ! noro 381: #if defined(VISUAL)
! 382: ncan->real_can = can;
! 383: #endif
1.1 noro 384: qifplotmain(ncan);
385: copy_subimage(ncan,can,spos);
386: copy_to_canvas(can);
387: } else {
388: create_canvas(ncan);
389: if ( can->precise )
390: qifplotmain(ncan);
391: else
392: ifplotmain(ncan);
393: copy_to_canvas(ncan);
394: }
395: }
396: }
397:
398: plot_resize(can,spos,epos)
399: struct canvas *can;
400: POINT spos,epos;
401: {
402: struct canvas *ncan;
403: Q dx,dx2,xmin,xmax,xmid;
404: double dy,dy2,ymin,ymax,ymid;
405: Q sx,ex,cw,ten,two;
406: double sy,ey;
407: Q s,t;
408: int new;
409: int w,h,m;
410:
411: if ( XC(spos) < XC(epos) && YC(spos) < YC(epos) ) {
412: new = search_canvas(); ncan = canvas[new];
413: ncan->mode = can->mode;
414: ncan->zmin = can->zmin; ncan->zmax = can->zmax;
415: ncan->nzstep = can->nzstep;
416: ncan->wname = can->wname;
417: ncan->vx = can->vx; ncan->vy = can->vy;
418: ncan->formula = can->formula;
419: w = XC(epos)-XC(spos);
420: h = YC(epos)-YC(spos);
421: m = MAX(can->width,can->height);
422: if ( w > h ) {
423: ncan->width = m; ncan->height = m * h/w;
424: } else {
425: ncan->width = m * w/h; ncan->height = m;
426: }
427: if ( can->wide ) {
428: STOQ(10,ten); STOQ(2,two);
429: subq(can->qxmax,can->qxmin,&t); mulq(t,ten,&dx);
430: addq(can->qxmax,can->qxmin,&t); divq(t,two,&xmid);
431: divq(dx,two,&dx2); subq(xmid,dx2,&xmin); addq(xmid,dx2,&xmax);
432:
433: dy = (can->ymax-can->ymin)*10;
434: ymid = (can->ymax+can->ymin)/2;
435: ymin = ymid-dy/2; ymax = ymid+dy/2;
436: } else {
437: subq(can->qxmax,can->qxmin,&dx);
438: xmin = can->qxmin; xmax = can->qxmax;
439:
440: dy = can->ymax-can->ymin;
441: ymin = can->ymin; ymax = can->ymax;
442: }
443: STOQ(XC(spos),sx); STOQ(XC(epos),ex); STOQ(can->width,cw);
444: mulq(sx,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmin);
445: mulq(ex,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmax);
446: ncan->xmin = ToReal(ncan->qxmin); ncan->xmax = ToReal(ncan->qxmax);
447:
448: ncan->ymin = ymax-YC(epos)*dy/can->height;
449: ncan->ymax = ymax-YC(spos)*dy/can->height;
450:
451: create_canvas(ncan);
452: plotcalc(ncan);
453: plot_print(display,ncan);
454: copy_to_canvas(ncan);
455: }
456: }
457:
458: ifplotmain(can)
459: struct canvas *can;
460: {
461: int width,height;
462: double **tabe,*tabeb;
463: int i;
464:
465: width = can->width; height = can->height;
466: tabe = (double **)ALLOCA(width*sizeof(double *));
467: for ( i = 0; i < width; i++ )
468: tabe[i] = (double *)ALLOCA(height*sizeof(double));
469: define_cursor(can->window,runningcur);
470: set_busy(can); set_selection();
471: calc(tabe,can); if_print(display,tabe,can);
472: reset_selection(); reset_busy(can);
473: define_cursor(can->window,normalcur);
474: }
475:
476: qifplotmain(can)
477: struct canvas *can;
478: {
479: int width,height;
480: char **tabe,*tabeb;
481: int i;
482:
483: width = can->width; height = can->height;
484: tabe = (char **)ALLOCA(width*sizeof(char *)+width*height*sizeof(char));
485: bzero(tabe,width*sizeof(char *)+width*height*sizeof(char));
486: for ( i = 0, tabeb = (char *)(tabe+width); i < width; i++ )
487: tabe[i] = tabeb + height*i;
488: define_cursor(can->window,runningcur);
489: set_busy(can); set_selection();
490: qcalc(tabe,can); qif_print(display,tabe,can);
491: reset_selection(); reset_busy(can);
492: define_cursor(can->window,normalcur);
493: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>