Annotation of OpenXM_contrib2/asir2000/plot/if.c, Revision 1.1
1.1 ! noro 1: /* $OpenXM: OpenXM/src/asir99/plot/if.c,v 1.1.1.1 1999/11/10 08:12:34 noro Exp $ */
! 2: #include "ca.h"
! 3: #include "parse.h"
! 4: #include "ox.h"
! 5: #include "ifplot.h"
! 6:
! 7: extern jmp_buf ox_env;
! 8:
! 9: int plot(NODE arg)
! 10: {
! 11: int id;
! 12: NODE n;
! 13: struct canvas *can;
! 14: P formula;
! 15: LIST xrange,yrange,zrange,wsize;
! 16: STRING wname;
! 17:
! 18: formula = (P)ARG0(arg);
! 19: xrange = (LIST)ARG1(arg);
! 20: yrange = (LIST)ARG2(arg);
! 21: zrange = (LIST)ARG3(arg);
! 22: wsize = (LIST)ARG4(arg);
! 23: wname = (STRING)ARG5(arg);
! 24:
! 25: can = canvas[id = search_canvas()];
! 26: n = BDY(xrange); can->vx = VR((P)BDY(n)); n = NEXT(n);
! 27: can->qxmin = (Q)BDY(n); n = NEXT(n); can->qxmax = (Q)BDY(n);
! 28: can->xmin = ToReal(can->qxmin); can->xmax = ToReal(can->qxmax);
! 29: if ( yrange ) {
! 30: n = BDY(yrange); can->vy = VR((P)BDY(n)); n = NEXT(n);
! 31: can->qymin = (Q)BDY(n); n = NEXT(n); can->qymax = (Q)BDY(n);
! 32: can->ymin = ToReal(can->qymin); can->ymax = ToReal(can->qymax);
! 33: if ( zrange ) {
! 34: n = NEXT(BDY(zrange));
! 35: can->zmin = ToReal(BDY(n)); n = NEXT(n); can->zmax = ToReal(BDY(n));
! 36: if ( n = NEXT(n) )
! 37: can->nzstep = QTOS((Q)BDY(n));
! 38: else
! 39: can->nzstep = MAXGC;
! 40: can->mode = MODE_CONPLOT;
! 41: } else
! 42: can->mode = MODE_IFPLOT;
! 43: } else
! 44: can->mode = MODE_PLOT;
! 45: if ( !wsize ) {
! 46: can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
! 47: } else {
! 48: can->width = QTOS((Q)BDY(BDY(wsize)));
! 49: can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
! 50: }
! 51: if ( wname )
! 52: can->wname = BDY(wname);
! 53: else
! 54: can->wname = "";
! 55: can->formula = formula;
! 56: create_canvas(can);
! 57: if ( can->mode == MODE_PLOT ) {
! 58: plotcalc(can);
! 59: plot_print(display,can);
! 60: } else
! 61: ifplotmain(can);
! 62: copy_to_canvas(can);
! 63: return id;
! 64: }
! 65:
! 66: int plotover(NODE arg)
! 67: {
! 68: int index;
! 69: P formula;
! 70: struct canvas *can;
! 71: struct canvas fakecan;
! 72: VL vl,vl0;
! 73:
! 74: index = QTOS((Q)ARG0(arg));
! 75: formula = (P)ARG1(arg);
! 76: can = canvas[index];
! 77: if ( !can->window )
! 78: return -1;
! 79: get_vars_recursive(formula,&vl);
! 80: for ( vl0 = vl; vl0; vl0 = NEXT(vl0) )
! 81: if ( vl0->v->attr == V_IND )
! 82: if ( vl->v != can->vx && vl->v != can->vy )
! 83: return -1;
! 84: current_can = can;
! 85: fakecan = *can; fakecan.formula = formula;
! 86: if ( can->mode == MODE_PLOT ) {
! 87: plotcalc(&fakecan);
! 88: plot_print(display,&fakecan);
! 89: } else
! 90: ifplotmain(&fakecan);
! 91: copy_to_canvas(&fakecan);
! 92: return index;
! 93: }
! 94:
! 95: int drawcircle(NODE arg)
! 96: {
! 97: int id;
! 98: int index;
! 99: pointer ptr;
! 100: Q ret;
! 101: LIST xyr;
! 102: Obj x,y,r;
! 103: int wx,wy,wr;
! 104: struct canvas *can;
! 105: struct canvas fakecan;
! 106:
! 107: index = QTOS((Q)ARG0(arg));
! 108: xyr = (LIST)ARG1(arg);
! 109: x = (Obj)ARG0(BDY(xyr)); y = (Obj)ARG1(BDY(xyr)); r = (Obj)ARG2(BDY(xyr));
! 110: can = canvas[index];
! 111: if ( !can->window )
! 112: return -1;
! 113: else {
! 114: current_can = can;
! 115: wx = (ToReal(x)-can->xmin)*can->width/(can->xmax-can->xmin);
! 116: wy = (can->ymax-ToReal(y))*can->height/(can->ymax-can->ymin);
! 117: wr = ToReal(r);
! 118: XFillArc(display,can->pix,colorGC,wx-wr/2,wy-wr/2,wr,wr,0,360*64);
! 119: copy_to_canvas(can);
! 120: return index;
! 121: }
! 122: }
! 123:
! 124: #define RealtoDbl(r) ((r)?BDY(r):0.0)
! 125:
! 126: int arrayplot(NODE arg)
! 127: {
! 128: int id,ix,w,h;
! 129: VECT array;
! 130: LIST xrange,wsize;
! 131: char *wname;
! 132: NODE n;
! 133: Q ret;
! 134: double ymax,ymin,dy,xstep;
! 135: Real *tab;
! 136: struct canvas *can;
! 137: POINT *pa;
! 138:
! 139: array = (VECT)ARG0(arg);
! 140: xrange = (LIST)ARG1(arg);
! 141: can = canvas[id = search_canvas()];
! 142: n = BDY(xrange); can->vx = VR((P)BDY(n)); n = NEXT(n);
! 143: can->qxmin = (Q)BDY(n); n = NEXT(n); can->qxmax = (Q)BDY(n);
! 144: can->xmin = ToReal(can->qxmin); can->xmax = ToReal(can->qxmax);
! 145: if ( !wsize ) {
! 146: can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
! 147: } else {
! 148: can->width = QTOS((Q)BDY(BDY(wsize)));
! 149: can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
! 150: }
! 151: can->wname = wname; can->formula = 0; can->mode = MODE_PLOT;
! 152: create_canvas(can);
! 153: w = array->len;
! 154: h = can->height;
! 155: tab = (Real *)BDY(array);
! 156: if ( can->ymax == can->ymin ) {
! 157: for ( ymax = ymin = RealtoDbl(tab[0]), ix = 1; ix < w; ix++ ) {
! 158: if ( RealtoDbl(tab[ix]) > ymax )
! 159: ymax = RealtoDbl(tab[ix]);
! 160: if ( RealtoDbl(tab[ix]) < ymin )
! 161: ymin = RealtoDbl(tab[ix]);
! 162: }
! 163: can->ymax = ymax; can->ymin = ymin;
! 164: } else {
! 165: ymax = can->ymax; ymin = can->ymin;
! 166: }
! 167: dy = ymax-ymin;
! 168: can->pa = (struct pa *)MALLOC(sizeof(struct pa));
! 169: can->pa[0].length = w;
! 170: can->pa[0].pos = pa = (POINT *)MALLOC(w*sizeof(POINT));
! 171: xstep = (double)can->width/(double)(w-1);
! 172: for ( ix = 0; ix < w; ix++ ) {
! 173: #ifndef MAXSHORT
! 174: #define MAXSHORT ((short)0x7fff)
! 175: #endif
! 176: double t;
! 177:
! 178: pa[ix].x = (int)(ix*xstep);
! 179: t = (h - 1)*(ymax - RealtoDbl(tab[ix]))/dy;
! 180: if ( t > MAXSHORT )
! 181: pa[ix].y = MAXSHORT;
! 182: else if ( t < -MAXSHORT )
! 183: pa[ix].y = -MAXSHORT;
! 184: else
! 185: pa[ix].y = t;
! 186: }
! 187: plot_print(display,can);
! 188: copy_to_canvas(can);
! 189: return id;
! 190: }
! 191:
! 192: ifplot_resize(can,spos,epos)
! 193: struct canvas *can;
! 194: POINT spos,epos;
! 195: {
! 196: struct canvas *ncan;
! 197: struct canvas fakecan;
! 198: Q dx,dy,dx2,dy2,xmin,xmax,ymin,ymax,xmid,ymid;
! 199: Q sx,sy,ex,ey,cw,ch,ten,two;
! 200: Q s,t;
! 201: int new;
! 202: int w,h,m;
! 203: Q ret;
! 204:
! 205: if ( XC(spos) < XC(epos) && YC(spos) < YC(epos) ) {
! 206: if ( can->precise && !can->wide ) {
! 207: fakecan = *can; ncan = &fakecan;
! 208: } else {
! 209: new = search_canvas(); ncan = canvas[new];
! 210: }
! 211: ncan->mode = can->mode;
! 212: ncan->zmin = can->zmin; ncan->zmax = can->zmax;
! 213: ncan->nzstep = can->nzstep;
! 214: ncan->wname = can->wname;
! 215: ncan->vx = can->vx; ncan->vy = can->vy;
! 216: ncan->formula = can->formula;
! 217: w = XC(epos)-XC(spos);
! 218: h = YC(epos)-YC(spos);
! 219: m = MAX(can->width,can->height);
! 220: if ( can->precise ) {
! 221: ncan->width = w; ncan->height = h;
! 222: } else if ( w > h ) {
! 223: ncan->width = m; ncan->height = m * h/w;
! 224: } else {
! 225: ncan->width = m * w/h; ncan->height = m;
! 226: }
! 227: if ( can->wide ) {
! 228: STOQ(10,ten); STOQ(2,two);
! 229: subq(can->qxmax,can->qxmin,&t); mulq(t,ten,&dx);
! 230: subq(can->qymax,can->qymin,&t); mulq(t,ten,&dy);
! 231: addq(can->qxmax,can->qxmin,&t); divq(t,two,&xmid);
! 232: addq(can->qymax,can->qymin,&t); divq(t,two,&ymid);
! 233: divq(dx,two,&dx2); divq(dy,two,&dy2);
! 234: subq(xmid,dx2,&xmin); addq(xmid,dx2,&xmax);
! 235: subq(ymid,dy2,&ymin); addq(ymid,dy2,&ymax);
! 236: } else {
! 237: subq(can->qxmax,can->qxmin,&dx); subq(can->qymax,can->qymin,&dy);
! 238: xmin = can->qxmin; xmax = can->qxmax;
! 239: ymin = can->qymin; ymax = can->qymax;
! 240: }
! 241: STOQ(XC(spos),sx); STOQ(YC(spos),sy); STOQ(XC(epos),ex); STOQ(YC(epos),ey);
! 242: STOQ(can->width,cw); STOQ(can->height,ch);
! 243: mulq(sx,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmin);
! 244: mulq(ex,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmax);
! 245: mulq(ey,dy,&t); divq(t,ch,&s); subq(ymax,s,&ncan->qymin);
! 246: mulq(sy,dy,&t); divq(t,ch,&s); subq(ymax,s,&ncan->qymax);
! 247: ncan->xmin = ToReal(ncan->qxmin); ncan->xmax = ToReal(ncan->qxmax);
! 248: ncan->ymin = ToReal(ncan->qymin); ncan->ymax = ToReal(ncan->qymax);
! 249: if ( can->precise && !can->wide ) {
! 250: current_can = can;
! 251: alloc_pixmap(ncan);
! 252: qifplotmain(ncan);
! 253: copy_subimage(ncan,can,spos);
! 254: copy_to_canvas(can);
! 255: } else {
! 256: create_canvas(ncan);
! 257: if ( can->precise )
! 258: qifplotmain(ncan);
! 259: else
! 260: ifplotmain(ncan);
! 261: copy_to_canvas(ncan);
! 262: }
! 263: }
! 264: }
! 265:
! 266: plot_resize(can,spos,epos)
! 267: struct canvas *can;
! 268: POINT spos,epos;
! 269: {
! 270: struct canvas *ncan;
! 271: Q dx,dx2,xmin,xmax,xmid;
! 272: double dy,dy2,ymin,ymax,ymid;
! 273: Q sx,ex,cw,ten,two;
! 274: double sy,ey;
! 275: Q s,t;
! 276: int new;
! 277: int w,h,m;
! 278:
! 279: if ( XC(spos) < XC(epos) && YC(spos) < YC(epos) ) {
! 280: new = search_canvas(); ncan = canvas[new];
! 281: ncan->mode = can->mode;
! 282: ncan->zmin = can->zmin; ncan->zmax = can->zmax;
! 283: ncan->nzstep = can->nzstep;
! 284: ncan->wname = can->wname;
! 285: ncan->vx = can->vx; ncan->vy = can->vy;
! 286: ncan->formula = can->formula;
! 287: w = XC(epos)-XC(spos);
! 288: h = YC(epos)-YC(spos);
! 289: m = MAX(can->width,can->height);
! 290: if ( w > h ) {
! 291: ncan->width = m; ncan->height = m * h/w;
! 292: } else {
! 293: ncan->width = m * w/h; ncan->height = m;
! 294: }
! 295: if ( can->wide ) {
! 296: STOQ(10,ten); STOQ(2,two);
! 297: subq(can->qxmax,can->qxmin,&t); mulq(t,ten,&dx);
! 298: addq(can->qxmax,can->qxmin,&t); divq(t,two,&xmid);
! 299: divq(dx,two,&dx2); subq(xmid,dx2,&xmin); addq(xmid,dx2,&xmax);
! 300:
! 301: dy = (can->ymax-can->ymin)*10;
! 302: ymid = (can->ymax+can->ymin)/2;
! 303: ymin = ymid-dy/2; ymax = ymid+dy/2;
! 304: } else {
! 305: subq(can->qxmax,can->qxmin,&dx);
! 306: xmin = can->qxmin; xmax = can->qxmax;
! 307:
! 308: dy = can->ymax-can->ymin;
! 309: ymin = can->ymin; ymax = can->ymax;
! 310: }
! 311: STOQ(XC(spos),sx); STOQ(XC(epos),ex); STOQ(can->width,cw);
! 312: mulq(sx,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmin);
! 313: mulq(ex,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmax);
! 314: ncan->xmin = ToReal(ncan->qxmin); ncan->xmax = ToReal(ncan->qxmax);
! 315:
! 316: ncan->ymin = ymax-YC(epos)*dy/can->height;
! 317: ncan->ymax = ymax-YC(spos)*dy/can->height;
! 318:
! 319: create_canvas(ncan);
! 320: plotcalc(ncan);
! 321: plot_print(display,ncan);
! 322: copy_to_canvas(ncan);
! 323: }
! 324: }
! 325:
! 326: ifplotmain(can)
! 327: struct canvas *can;
! 328: {
! 329: int width,height;
! 330: double **tabe,*tabeb;
! 331: int i;
! 332:
! 333: width = can->width; height = can->height;
! 334: tabe = (double **)ALLOCA(width*sizeof(double *));
! 335: for ( i = 0; i < width; i++ )
! 336: tabe[i] = (double *)ALLOCA(height*sizeof(double));
! 337: define_cursor(can->window,runningcur);
! 338: set_busy(can); set_selection();
! 339: calc(tabe,can); if_print(display,tabe,can);
! 340: reset_selection(); reset_busy(can);
! 341: define_cursor(can->window,normalcur);
! 342: }
! 343:
! 344: qifplotmain(can)
! 345: struct canvas *can;
! 346: {
! 347: int width,height;
! 348: char **tabe,*tabeb;
! 349: int i;
! 350:
! 351: width = can->width; height = can->height;
! 352: tabe = (char **)ALLOCA(width*sizeof(char *)+width*height*sizeof(char));
! 353: bzero(tabe,width*sizeof(char *)+width*height*sizeof(char));
! 354: for ( i = 0, tabeb = (char *)(tabe+width); i < width; i++ )
! 355: tabe[i] = tabeb + height*i;
! 356: define_cursor(can->window,runningcur);
! 357: set_busy(can); set_selection();
! 358: qcalc(tabe,can); qif_print(display,tabe,can);
! 359: reset_selection(); reset_busy(can);
! 360: define_cursor(can->window,normalcur);
! 361: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>