Annotation of OpenXM_contrib2/asir2018/plot/if.c, Revision 1.1
1.1 ! 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
! 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
! 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: *
! 48: * $OpenXM$
! 49: */
! 50: #include "ca.h"
! 51: #include "parse.h"
! 52: #include "ox.h"
! 53: #include "ifplot.h"
! 54:
! 55: #if defined(INTERVAL)
! 56: // Time message and func
! 57: #include <sys/types.h>
! 58: #include <sys/resource.h>
! 59: #include <sys/time.h>
! 60:
! 61: static struct oEGT ltime;
! 62: static double r0;
! 63: double get_rtime();
! 64: void MSGdraw(char *);
! 65: char msg[128];
! 66: #if defined(ITV_TIME_CHECK)
! 67: void tstart()
! 68: {
! 69: get_eg(<ime);
! 70: r0=get_rtime();
! 71: }
! 72:
! 73: void tstop(struct canvas *can)
! 74: {
! 75: struct oEGT egt1;
! 76: double e, g, r;
! 77: char ts[100];
! 78: void popdown_warning();
! 79: Widget warnshell,warndialog;
! 80:
! 81: get_eg(&egt1);
! 82: e=egt1.exectime - ltime.exectime;
! 83: g=egt1.gctime - ltime.gctime;
! 84: r=get_rtime() - r0;
! 85: sprintf(ts,"(%8.6f + gc %8.6f) total %8.6f \n",e,g,r);
! 86: create_popup(can->shell,"Message",&ts,&warnshell,&warndialog);
! 87: XawDialogAddButton(warndialog,"OK",popdown_warning,warnshell);
! 88: XtPopup(warnshell,XtGrabNone);
! 89: SetWM_Proto(warnshell);
! 90: }
! 91: #else
! 92: #define tstart()
! 93: #define tstop(a)
! 94: #endif
! 95: #endif
! 96:
! 97: extern JMP_BUF ox_env;
! 98:
! 99: int open_canvas(NODE arg){
! 100: int id;
! 101: struct canvas *can;
! 102: LIST wsize;
! 103: STRING wname;
! 104:
! 105: wsize=(LIST)ARG0(arg);
! 106: wname=(STRING)ARG1(arg);
! 107: id=search_canvas();
! 108: can=canvas[id];
! 109: can->mode=modeNO(INTERACTIVE);
! 110: if(!wsize){
! 111: can->width=DEFAULTWIDTH;
! 112: can->height=DEFAULTHEIGHT;
! 113: } else {
! 114: can->width=QTOS((Q)BDY(BDY(wsize)));
! 115: can->height=QTOS((Q)BDY(NEXT(BDY(wsize))));
! 116: }
! 117: if(wname)can->wname=BDY(wname);
! 118: else can->wname="";
! 119: create_canvas(can);
! 120: return id;
! 121: }
! 122:
! 123: int plot(NODE arg,int fn){
! 124: int id;
! 125: NODE n;
! 126: struct canvas *can;
! 127: P formula;
! 128: LIST xrange,yrange,zrange,wsize;
! 129: STRING wname;
! 130: V v;
! 131: Real r;
! 132: double rr;
! 133:
! 134: formula=(P)ARG0(arg);
! 135: xrange=(LIST)ARG1(arg);
! 136: yrange=(LIST)ARG2(arg);
! 137: zrange=(LIST)ARG3(arg);
! 138: wsize=(LIST)ARG4(arg);
! 139: wname=(STRING)ARG5(arg);
! 140: can=canvas[id=search_canvas()];
! 141: if(xrange){
! 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: }
! 146: if(yrange){
! 147: n=BDY(yrange);can->vy=VR((P)BDY(n));n=NEXT(n);
! 148: can->qymin=(Q)BDY(n);n=NEXT(n);can->qymax=(Q)BDY(n);
! 149: can->ymin=ToReal(can->qymin);can->ymax=ToReal(can->qymax);
! 150: } else if ( !formula || NUM(formula) ) {
! 151: devalr(CO,(Obj)formula,(Obj *)&r); rr = ToReal(r);
! 152: can->ymin=rr-1; can->ymax=rr+1;
! 153: }
! 154: can->mode=fn;
! 155: if(zrange){
! 156: n=NEXT(BDY(zrange));
! 157: can->zmin=ToReal(BDY(n));
! 158: n=NEXT(n);can->zmax=ToReal(BDY(n));
! 159: n=NEXT(n);
! 160: if(can->mode==modeNO(CONPLOT))can->nzstep=n?QTOS((Q)BDY(n)):MAXGC;
! 161: else {
! 162: can->vx=VR((P)BDY(BDY(zrange)));
! 163: can->nzstep=n?QTOS((Q)BDY(n)):DEFAULTPOLARSTEP;
! 164: }
! 165: }
! 166: if(!wsize){
! 167: can->width=DEFAULTWIDTH;
! 168: can->height=DEFAULTHEIGHT;
! 169: } else {
! 170: can->width=QTOS((Q)BDY(BDY(wsize)));
! 171: can->height=QTOS((Q)BDY(NEXT(BDY(wsize))));
! 172: }
! 173: if(wname) can->wname=BDY(wname);
! 174: else can->wname="";
! 175: can->formula=formula;
! 176: if(can->mode==modeNO(PLOT)){
! 177: //plot
! 178: can->prec=argc(arg)==7 ? QTOS((Q)ARG6(arg)) : 0;
! 179: plotcalc(can);
! 180: create_canvas(can);
! 181: plot_print(display,can);
! 182: } else if(can->mode==modeNO(POLARPLOT)){
! 183: polarcalc(can);
! 184: create_canvas(can);
! 185: plot_print(display,can);
! 186: } else {
! 187: create_canvas(can);
! 188: ifplotmain(can);
! 189: }
! 190: copy_to_canvas(can);
! 191: return id;
! 192: }
! 193:
! 194: void ifplotmain(struct canvas *can){
! 195: int i,width,height;
! 196: double ** tabe;
! 197:
! 198: width=can->width;height=can->height;
! 199: tabe=(double **)ALLOCA((width+1)*sizeof(double *));
! 200: for(i=0;i<width;i++)tabe[i]=(double *)ALLOCA((height+1)*sizeof(double));
! 201: define_cursor(can->window,runningcur);
! 202: set_busy(can); set_selection();
! 203: calc(tabe,can,0);
! 204: if_print(display,tabe,can);
! 205: reset_selection(); reset_busy(can);
! 206: define_cursor(can->window,normalcur);
! 207: }
! 208:
! 209: int memory_plot(NODE arg,LIST *bytes){
! 210: NODE n;
! 211: struct canvas tmp_can;
! 212: struct canvas *can;
! 213: P formula;
! 214: LIST xrange,yrange,zrange,wsize;
! 215: int width,height;
! 216: double **tabe;
! 217: int i;
! 218: BYTEARRAY barray;
! 219: Z qw,qh,prec;
! 220:
! 221: formula=(P)ARG0(arg);
! 222: xrange=(LIST)ARG1(arg);
! 223: yrange=(LIST)ARG2(arg);
! 224: zrange=(LIST)ARG3(arg);
! 225: wsize=(LIST)ARG4(arg);
! 226:
! 227: bzero((char *)&tmp_can,sizeof(tmp_can));
! 228: can=&tmp_can;
! 229: n=BDY(xrange); can->vx=VR((P)BDY(n)); n=NEXT(n);
! 230: can->qxmin=(Q)BDY(n); n=NEXT(n); can->qxmax=(Q)BDY(n);
! 231: can->xmin=ToReal(can->qxmin); can->xmax=ToReal(can->qxmax);
! 232: if( yrange ){
! 233: n=BDY(yrange); can->vy=VR((P)BDY(n)); n=NEXT(n);
! 234: can->qymin=(Q)BDY(n); n=NEXT(n); can->qymax=(Q)BDY(n);
! 235: can->ymin=ToReal(can->qymin); can->ymax=ToReal(can->qymax);
! 236: if( zrange ){
! 237: n=NEXT(BDY(zrange));
! 238: can->zmin=ToReal(BDY(n)); n=NEXT(n); can->zmax=ToReal(BDY(n));
! 239: n=NEXT(n);
! 240: if(n) can->nzstep=QTOS((Q)BDY(n));
! 241: else can->nzstep=MAXGC;
! 242: can->mode=modeNO(CONPLOT);
! 243: } else
! 244: can->mode=modeNO(IFPLOT);
! 245: } else
! 246: can->mode=modeNO(PLOT);
! 247: if( !wsize ){
! 248: can->width=DEFAULTWIDTH; can->height=DEFAULTHEIGHT;
! 249: } else {
! 250: can->width=QTOS((Q)BDY(BDY(wsize)));
! 251: can->height=QTOS((Q)BDY(NEXT(BDY(wsize))));
! 252: }
! 253: can->wname="";
! 254: can->formula=formula;
! 255: if( can->mode==modeNO(PLOT)){
! 256: can->prec = argc(arg)==6 ? QTOS((Q)ARG5(arg)) : 0;
! 257: plotcalc(can);
! 258: memory_print(can,&barray);
! 259: STOQ(can->width,qw); STOQ(can->height,qh);
! 260: n=mknode(3,qw,qh,barray);
! 261: MKLIST(*bytes,n);
! 262: } else {
! 263: width=can->width; height=can->height;
! 264: tabe=(double **)ALLOCA(width*sizeof(double *));
! 265: for( i=0; i<width; i++ )
! 266: tabe[i]=(double *)ALLOCA(height*sizeof(double));
! 267: calc(tabe,can,1);
! 268: memory_if_print(tabe,can,&barray);
! 269: STOQ(width,qw); STOQ(height,qh);
! 270: n=mknode(3,qw,qh,barray);
! 271: MKLIST(*bytes,n);
! 272: }
! 273: return 0;
! 274: }
! 275:
! 276: int plotover(NODE arg){
! 277: int id;
! 278: unsigned int orgcolor;
! 279: P formula;
! 280: struct canvas *can;
! 281: VL vl,vl0;
! 282:
! 283: id=QTOS((Q)ARG0(arg));
! 284: formula=(P)ARG1(arg);
! 285: can=canvas[id];
! 286: orgcolor=can->color;
! 287: if(argc(arg)==3) can->color=QTOS((Q)ARG2(arg));
! 288: else can->color=0;
! 289: get_vars_recursive((Obj)formula,&vl);
! 290: for(vl0=vl;vl0;vl0=NEXT(vl0))
! 291: if(vl0->v->attr==(pointer)V_IND)
! 292: if(vl->v!=can->vx && vl->v!=can->vy)return -1;
! 293: #if !defined(VISUAL) && !defined(__MINGW32__)
! 294: set_drawcolor(can->color);
! 295: #endif
! 296: current_can=can;
! 297: can->formula=formula;
! 298: if(can->mode==modeNO(PLOT)){
! 299: can->prec = argc(arg)==3 ? QTOS((Q)ARG2(arg)) : 0;
! 300: plotcalc(can);
! 301: plot_print(display,can);
! 302: } else ifplotmain(can);
! 303: copy_to_canvas(can);
! 304: can->color=orgcolor;
! 305: #if !defined(VISUAL) && !defined(__MINGW32__)
! 306: set_drawcolor(can->color);
! 307: #endif
! 308: return id;
! 309: }
! 310:
! 311: int drawcircle(NODE arg){
! 312: #if !defined(VISUAL) && !defined(__MINGW32__)
! 313: int id,index,wx,wy,wr;
! 314: unsigned int c;
! 315: pointer ptr;
! 316: Q ret;
! 317: LIST xyr;
! 318: Obj x,y,r;
! 319: struct canvas *can;
! 320:
! 321: index=QTOS((Q)ARG0(arg));
! 322: xyr=(LIST)ARG1(arg);
! 323: x=(Obj)ARG0(BDY(xyr)); y=(Obj)ARG1(BDY(xyr)); r=(Obj)ARG2(BDY(xyr));
! 324: c=QTOS((Q)ARG2(arg));
! 325: can=canvas[index];
! 326: if(!can->window)return -1;
! 327: else {
! 328: current_can=can;
! 329: set_drawcolor(c);
! 330: wx=(ToReal(x)-can->xmin)*can->width/(can->xmax-can->xmin);
! 331: wy=(can->ymax-ToReal(y))*can->height/(can->ymax-can->ymin);
! 332: wr=ToReal(r);
! 333: XFillArc(display,can->pix,cdrawGC,wx-wr/2,wy-wr/2,wr,wr,0,360*64);
! 334: copy_to_canvas(can);
! 335: set_drawcolor(can->color);
! 336: return index;
! 337: }
! 338: #endif
! 339: }
! 340:
! 341: int draw_obj(NODE arg){
! 342: int index,x,y,u,v,len,r;
! 343: unsigned int color;
! 344: NODE obj,n;
! 345: RealVect *vect;
! 346: struct canvas *can;
! 347:
! 348: index=QTOS((Q)ARG0(arg));
! 349: can=canvas[index];
! 350: if(!can && closed_canvas[index]){
! 351: canvas[index]=closed_canvas[index];
! 352: closed_canvas[index]=0;
! 353: can=canvas[index];
! 354: popup_canvas(index);
! 355: current_can=can;
! 356: } else if(!can||(can && !can->window)){
! 357: set_lasterror("draw_obj : canvas does not exist");
! 358: return -1;
! 359: }
! 360:
! 361: obj=BDY((LIST)ARG1(arg));
! 362: if(argc(arg)== 3) color=QTOS((Q)ARG2(arg));
! 363: else color=0; // black
! 364: switch(len=length(obj)){
! 365: case 2: // point
! 366: x=(int)ToReal((Q)ARG0(obj)); y=(int)ToReal((Q)ARG1(obj));
! 367: draw_point(display,can,x,y,color);
! 368: MKRVECT3(vect,x,y,color); MKNODE(n,vect,can->history);
! 369: can->history=n;
! 370: break;
! 371: case 3: // circle
! 372: x=(int)ToReal((Q)ARG0(obj)); y=(int)ToReal((Q)ARG1(obj));
! 373: r=(int)ToReal((Q)ARG2(obj));
! 374: MKRVECT4(vect,x,y,r,color); MKNODE(n,vect,can->history);
! 375: can->history=n;
! 376: break;
! 377: case 4: // line
! 378: x=(int)ToReal((Q)ARG0(obj)); y=(int)ToReal((Q)ARG1(obj));
! 379: u=(int)ToReal((Q)ARG2(obj)); v=(int)ToReal((Q)ARG3(obj));
! 380: draw_line(display,can,x,y,u,v,color);
! 381: MKRVECT5(vect,x,y,u,v,color); MKNODE(n,vect,can->history);
! 382: can->history=n;
! 383: break;
! 384: default:
! 385: set_lasterror("draw_obj : invalid request");
! 386: return -1;
! 387: }
! 388: #if !defined(VISUAL) && !defined(__MINGW32__)
! 389: set_drawcolor(can->color);
! 390: #endif
! 391: return 0;
! 392: }
! 393:
! 394: int draw_string(NODE arg){
! 395: int index,x,y;
! 396: unsigned int color;
! 397: char *str;
! 398: NODE pos;
! 399: struct canvas *can;
! 400:
! 401: index=QTOS((Q)ARG0(arg));
! 402: can=canvas[index];
! 403: if(!can && closed_canvas[index]){
! 404: canvas[index]=closed_canvas[index];
! 405: closed_canvas[index]=0;
! 406: can=canvas[index];
! 407: popup_canvas(index);
! 408: current_can=can;
! 409: } else if(!can||(can && !can->window)){
! 410: set_lasterror("draw_obj : canvas does not exist");
! 411: return -1;
! 412: }
! 413:
! 414: pos=BDY((LIST)ARG1(arg));
! 415: str=BDY((STRING)ARG2(arg));
! 416: if(argc(arg)==4)color=QTOS((Q)ARG3(arg));
! 417: else color=0; // black
! 418: x=(int)ToReal((Q)ARG0(pos));
! 419: y=(int)ToReal((Q)ARG1(pos));
! 420: draw_character_string(display,can,x,y,str,color);
! 421: #if !defined(VISUAL) && !defined(__MINGW32__)
! 422: set_drawcolor(can->color);
! 423: #endif
! 424: return 0;
! 425: }
! 426:
! 427: int clear_canvas(NODE arg){
! 428: int index;
! 429: struct canvas *can;
! 430:
! 431: index=QTOS((Q)ARG0(arg));
! 432: can=canvas[index];
! 433: if(!can||!can->window) return -1;
! 434: clear_pixmap(can);
! 435: copy_to_canvas(can);
! 436: // clear the history
! 437: can->history=0;
! 438: return 0;
! 439: }
! 440:
! 441: #define RealtoDbl(r) ((r)?BDY(r):0.0)
! 442:
! 443: int arrayplot(NODE arg){
! 444: int id,ix,w,h;
! 445: VECT array;
! 446: LIST xrange,wsize;
! 447: char *wname;
! 448: NODE n;
! 449: double ymax,ymin,dy,xstep;
! 450: Real *tab;
! 451: struct canvas *can;
! 452: POINT *pa;
! 453:
! 454: array=(VECT)ARG0(arg);
! 455: xrange=(LIST)ARG1(arg);
! 456: can=canvas[id=search_canvas()];
! 457: n=BDY(xrange); can->vx=VR((P)BDY(n)); n=NEXT(n);
! 458: can->qxmin=(Q)BDY(n); n=NEXT(n); can->qxmax=(Q)BDY(n);
! 459: can->xmin=ToReal(can->qxmin); can->xmax=ToReal(can->qxmax);
! 460: if(!wsize){
! 461: can->width=DEFAULTWIDTH;
! 462: can->height=DEFAULTHEIGHT;
! 463: } else {
! 464: can->width=QTOS((Q)BDY(BDY(wsize)));
! 465: can->height=QTOS((Q)BDY(NEXT(BDY(wsize))));
! 466: }
! 467: can->wname=wname; can->formula=0; can->mode=modeNO(PLOT);
! 468: create_canvas(can);
! 469: w=array->len;
! 470: h=can->height;
! 471: tab=(Real *)BDY(array);
! 472: if(can->ymax==can->ymin){
! 473: for(ymax=ymin=RealtoDbl(tab[0]),ix=1; ix<w; ix++){
! 474: if(RealtoDbl(tab[ix])>ymax)ymax=RealtoDbl(tab[ix]);
! 475: if(RealtoDbl(tab[ix])<ymin)ymin=RealtoDbl(tab[ix]);
! 476: }
! 477: can->ymax=ymax;
! 478: can->ymin=ymin;
! 479: } else {
! 480: ymax=can->ymax;
! 481: ymin=can->ymin;
! 482: }
! 483: dy=ymax-ymin;
! 484: can->pa=(struct pa *)MALLOC(sizeof(struct pa));
! 485: can->pa[0].length=w;
! 486: can->pa[0].pos=pa=(POINT *)MALLOC(w*sizeof(POINT));
! 487: xstep=(double)can->width/(double)(w-1);
! 488: for(ix=0;ix<w;ix++){
! 489: #ifndef MAXSHORT
! 490: #define MAXSHORT ((short)0x7fff)
! 491: #endif
! 492: double t;
! 493:
! 494: pa[ix].x=(int)(ix*xstep);
! 495: t=(h - 1)*(ymax - RealtoDbl(tab[ix]))/dy;
! 496: if(t>MAXSHORT)pa[ix].y=MAXSHORT;
! 497: else if(t<-MAXSHORT)pa[ix].y=-MAXSHORT;
! 498: else pa[ix].y=(long)t;
! 499: }
! 500: plot_print(display,can);
! 501: copy_to_canvas(can);
! 502: return id;
! 503: }
! 504: /*
! 505: void ifplot_resize(struct canvas *can,POINT spos,POINT epos){
! 506: struct canvas *ncan;
! 507: struct canvas fakecan;
! 508: Q dx,dy,dx2,dy2,xmin,xmax,ymin,ymax,xmid,ymid;
! 509: Q sx,sy,ex,ey,cw,ch,ten,two;
! 510: Q s,t;
! 511: int new;
! 512: int w,h,m;
! 513: if(XC(spos)<XC(epos) && YC(spos)<YC(epos)){
! 514: if(can->precise && !can->wide){
! 515: fakecan=*can;
! 516: ncan=&fakecan;
! 517: } else {
! 518: new=search_canvas();
! 519: ncan=canvas[new];
! 520: }
! 521: ncan->mode=can->mode;
! 522: ncan->zmin=can->zmin; ncan->zmax=can->zmax;
! 523: ncan->nzstep=can->nzstep;
! 524: ncan->wname=can->wname;
! 525: ncan->vx=can->vx; ncan->vy=can->vy;
! 526: ncan->formula=can->formula;
! 527: w=XC(epos)-XC(spos);
! 528: h=YC(epos)-YC(spos);
! 529: m=MAX(can->width,can->height);
! 530: if(can->precise){
! 531: ncan->width=w;
! 532: ncan->height=h;
! 533: } else if(w>h){
! 534: ncan->width=m;
! 535: ncan->height=m*h/w;
! 536: } else {
! 537: ncan->width=m*w/h;
! 538: ncan->height=m;
! 539: }
! 540: if(can->wide){
! 541: STOQ(10,ten);
! 542: STOQ(2,two);
! 543: subq(can->qxmax,can->qxmin,&t);
! 544: mulq(t,ten,&dx);
! 545: subq(can->qymax,can->qymin,&t);
! 546: mulq(t,ten,&dy);
! 547: addq(can->qxmax,can->qxmin,&t);
! 548: divq(t,two,&xmid);
! 549: addq(can->qymax,can->qymin,&t);
! 550: divq(t,two,&ymid);
! 551: divq(dx,two,&dx2);
! 552: divq(dy,two,&dy2);
! 553: subq(xmid,dx2,&xmin);
! 554: addq(xmid,dx2,&xmax);
! 555: subq(ymid,dy2,&ymin);
! 556: addq(ymid,dy2,&ymax);
! 557: } else {
! 558: subq(can->qxmax,can->qxmin,&dx);
! 559: subq(can->qymax,can->qymin,&dy);
! 560: xmin=can->qxmin;
! 561: xmax=can->qxmax;
! 562: ymin=can->qymin;
! 563: ymax=can->qymax;
! 564: }
! 565: STOQ(XC(spos),sx); STOQ(YC(spos),sy); STOQ(XC(epos),ex); STOQ(YC(epos),ey);
! 566: STOQ(can->width,cw); STOQ(can->height,ch);
! 567: mulq(sx,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmin);
! 568: mulq(ex,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmax);
! 569: mulq(ey,dy,&t); divq(t,ch,&s); subq(ymax,s,&ncan->qymin);
! 570: mulq(sy,dy,&t); divq(t,ch,&s); subq(ymax,s,&ncan->qymax);
! 571: ncan->xmin=ToReal(ncan->qxmin); ncan->xmax=ToReal(ncan->qxmax);
! 572: ncan->ymin=ToReal(ncan->qymin); ncan->ymax=ToReal(ncan->qymax);
! 573: if(can->precise && !can->wide){
! 574: current_can=can;
! 575: alloc_pixmap(ncan);
! 576: #if defined(VISUAL) || defined(__MINGW32__)
! 577: ncan->real_can=can;
! 578: #endif
! 579: qifplotmain(ncan);
! 580: copy_subimage(ncan,can,spos);
! 581: copy_to_canvas(can);
! 582: } else {
! 583: create_canvas(ncan);
! 584: if( can->precise ) qifplotmain(ncan);
! 585: else ifplotmain(ncan);
! 586: copy_to_canvas(ncan);
! 587: }
! 588: }
! 589: }
! 590: */
! 591:
! 592: void plot_resize(struct canvas *can,POINT spos,POINT epos){
! 593: struct canvas *ncan;
! 594: Q dx,dx2,xmin,xmax,xmid,s,t;
! 595: Z ten,two,sx,ex,cw;
! 596: double dy,ymin,ymax,ymid;
! 597: int new,w,h,m;
! 598:
! 599: if( XC(spos)<XC(epos) && YC(spos)<YC(epos) ){
! 600: new=search_canvas(); ncan=canvas[new];
! 601: ncan->mode=can->mode;
! 602: ncan->zmin=can->zmin; ncan->zmax=can->zmax;
! 603: ncan->nzstep=can->nzstep;
! 604: ncan->wname=can->wname;
! 605: ncan->vx=can->vx; ncan->vy=can->vy;
! 606: ncan->formula=can->formula;
! 607: ncan->color=can->color;
! 608: w=XC(epos)-XC(spos);
! 609: h=YC(epos)-YC(spos);
! 610: m=MAX(can->width,can->height);
! 611: if( w>h ){
! 612: ncan->width=m;
! 613: ncan->height=m * h/w;
! 614: } else {
! 615: ncan->width=m * w/h;
! 616: ncan->height=m;
! 617: }
! 618: if( can->wide ){
! 619: STOQ(10,ten); STOQ(2,two);
! 620: subq(can->qxmax,can->qxmin,&t); mulq(t,(Q)ten,&dx);
! 621: addq(can->qxmax,can->qxmin,&t); divq(t,(Q)two,&xmid);
! 622: divq(dx,(Q)two,&dx2); subq(xmid,dx2,&xmin); addq(xmid,dx2,&xmax);
! 623: dy=(can->ymax-can->ymin)*10;
! 624: ymid=(can->ymax+can->ymin)/2;
! 625: ymin=ymid-dy/2; ymax=ymid+dy/2;
! 626: } else {
! 627: subq(can->qxmax,can->qxmin,&dx);
! 628: xmin=can->qxmin;
! 629: xmax=can->qxmax;
! 630: dy=can->ymax-can->ymin;
! 631: ymin=can->ymin;
! 632: ymax=can->ymax;
! 633: }
! 634: STOQ(XC(spos),sx); STOQ(XC(epos),ex); STOQ(can->width,cw);
! 635: mulq((Q)sx,dx,&t); divq(t,(Q)cw,&s); addq(xmin,s,&ncan->qxmin);
! 636: mulq((Q)ex,dx,&t); divq(t,(Q)cw,&s); addq(xmin,s,&ncan->qxmax);
! 637: ncan->xmin=ToReal(ncan->qxmin); ncan->xmax=ToReal(ncan->qxmax);
! 638: ncan->ymin=ymax-YC(epos)*dy/can->height;
! 639: ncan->ymax=ymax-YC(spos)*dy/can->height;
! 640: ncan->prec = can->prec;
! 641: create_canvas(ncan);
! 642:
! 643: switch (ncan->mode){
! 644: case 0://IFPLOT
! 645: case 1://CONPLOT
! 646: ifplotmain(ncan);
! 647: break;
! 648: case 2://PLOT
! 649: plotcalc(ncan);
! 650: plot_print(display,ncan);
! 651: break;
! 652: case 4://POLARPLOT
! 653: polarcalc(ncan);
! 654: plot_print(display,ncan);
! 655: break;
! 656: case 30://MEMORY_PLOT
! 657: break;
! 658: case 31://ARRAYPLOT
! 659: break;
! 660: case 33://DRAWCIRCLE
! 661: break;
! 662: case 34://DRAW_OBJ
! 663: break;
! 664: case 35://DRAW_STRING
! 665: break;
! 666: case 36://OBJ_CP
! 667: break;
! 668: case 6://IFPLOTD
! 669: case 7://IFPLOTQ
! 670: case 8://IFPLOTB
! 671: case 9://INEQND
! 672: case 10://INEQNQ
! 673: case 11://INEQNB
! 674: case 21://CONPLOTD
! 675: case 22://CONPLOTQ
! 676: case 23://CONPLOTB
! 677: case 24://ITVIFPLOT
! 678: //ifplotNG
! 679: ifplotmainNG(ncan);
! 680: break;
! 681: case 12://INEQNDAND
! 682: case 13://INEQNQAND
! 683: case 14://INEQNBAND
! 684: case 15://INEQNDOR
! 685: case 16://INEQNQOR
! 686: case 17://INEQNBOR
! 687: case 18://INEQNDXOR
! 688: case 19://INEQNQXOR
! 689: case 20://INEQNBXOR
! 690: case 25://PLOTOVERD
! 691: case 26://PLOTOVERQ
! 692: case 27://PLOTOVERB
! 693: //ifplotOP
! 694: ifplotmainNG(ncan);
! 695: break;
! 696: case 38://POLARPLOTD
! 697: //polarplotNG
! 698: polarcalcNG(ncan);
! 699: polar_print(display,ncan);
! 700: break;
! 701: }
! 702: copy_to_canvas(ncan);
! 703: }
! 704: }
! 705:
! 706: void qifplotmain(struct canvas *can)
! 707: {
! 708: int width,height;
! 709: char **tabe,*tabeb;
! 710: int i;
! 711:
! 712: width=can->width; height=can->height;
! 713: tabe=(char **)ALLOCA(width*sizeof(char *)+width*height*sizeof(char));
! 714: bzero((void *)tabe,width*sizeof(char *)+width*height*sizeof(char));
! 715: for( i=0, tabeb=(char *)(tabe+width); i<width; i++ )
! 716: tabe[i]=tabeb + height*i;
! 717: define_cursor(can->window,runningcur);
! 718: set_busy(can); set_selection();
! 719: qcalc(tabe,can); qif_print(display,tabe,can);
! 720: reset_selection(); reset_busy(can);
! 721: define_cursor(can->window,normalcur);
! 722: }
! 723:
! 724: //*******************ifplotNG
! 725: int ifplotNG(NODE arg,int func){
! 726: int id,op_code;
! 727: unsigned int color;
! 728: NODE n;
! 729: struct canvas *can;
! 730: P formula;
! 731: LIST xrange,yrange,zrange,wsize;
! 732: STRING wname;
! 733:
! 734: can=canvas[id=search_canvas()];
! 735: formula=(P)ARG0(arg);
! 736: can->color=QTOS((Q)ARG1(arg));
! 737: xrange=(LIST)ARG2(arg);
! 738: yrange=(LIST)ARG3(arg);
! 739: zrange=(LIST)ARG4(arg);
! 740: wsize=(LIST)ARG5(arg);
! 741: wname=(STRING)ARG6(arg);
! 742: can->division=0;
! 743: // set canvas data
! 744: if(xrange){
! 745: n=BDY(xrange); can->vx=VR((P)BDY(n)); n=NEXT(n);
! 746: can->qxmin=(Q)BDY(n); n=NEXT(n); can->qxmax=(Q)BDY(n);
! 747: can->xmin=ToReal(can->qxmin); can->xmax=ToReal(can->qxmax);
! 748: }
! 749: if(yrange){
! 750: n=BDY(yrange); can->vy=VR((P)BDY(n)); n=NEXT(n);
! 751: can->qymin=(Q)BDY(n); n=NEXT(n); can->qymax=(Q)BDY(n);
! 752: can->ymin=ToReal(can->qymin); can->ymax=ToReal(can->qymax);
! 753: }
! 754: if(zrange){
! 755: n=BDY(zrange); can->zmin=ToReal(BDY(n));
! 756: n=NEXT(n); can->zmax=ToReal(BDY(n));
! 757: n=NEXT(n); can->nzstep=QTOS((Q)BDY(n));
! 758: }
! 759: if(!wsize){
! 760: can->width=DEFAULTWIDTH;
! 761: can->height=DEFAULTHEIGHT;
! 762: } else {
! 763: can->width=QTOS((Q)BDY(BDY(wsize)));
! 764: can->height=QTOS((Q)BDY(NEXT(BDY(wsize))));
! 765: }
! 766: if(wname) can->wname=BDY(wname);
! 767: else can->wname="";
! 768: can->formula=formula;
! 769: set_drawcolor(can->color);
! 770: can->mode=func;
! 771: create_canvas(can);
! 772: ifplotmainNG(can);
! 773: copy_to_canvas(can);
! 774: return id;
! 775: }
! 776:
! 777: int ifplotOP(NODE arg,int func){
! 778: //ineqnor[D,Q,B],ineqnand[D,Q,B],ineqnxor[D,Q,b],plotover[D,Q,B]
! 779: int index,op_code;
! 780: unsigned int orgcolor,color;
! 781: P formula;
! 782: struct canvas *can;
! 783: VL vl,vl0;
! 784: NODE n;
! 785:
! 786: index=QTOS((Q)ARG0(arg));
! 787: formula=(P)ARG1(arg);
! 788: color=QTOS((Q)ARG2(arg));
! 789: // set canvas data
! 790: can=canvas[index];
! 791: orgcolor=can->color;
! 792: can->color=color;
! 793: can->formula=formula;
! 794: current_can=can;
! 795: get_vars_recursive((Obj)formula,&vl);
! 796: for(vl0=vl;vl0;vl0=NEXT(vl0))
! 797: if(vl0->v->attr==(pointer)V_IND)
! 798: if(vl->v!=can->vx && vl->v!=can->vy)return -1;
! 799: #if !defined(VISUAL) && !defined(__MINGW32__)
! 800: set_drawcolor(can->color);
! 801: #endif
! 802: can->mode=func;
! 803: set_drawcolor(color);
! 804: ifplotmainNG(can);
! 805: set_drawcolor(orgcolor);
! 806: copy_to_canvas(can);
! 807: can->color=orgcolor;
! 808: #if !defined(VISUAL) && !defined(__MINGW32__)
! 809: set_drawcolor(can->color);
! 810: #endif
! 811: return index;
! 812: }
! 813:
! 814: void ifplotmainNG(struct canvas *can){
! 815: int width,height,i,j,ix,iy,**mask;
! 816: double **tabe;
! 817:
! 818: width=can->width; height=can->height;
! 819: tabe=(double **)ALLOCA((width+1)*sizeof(double *));
! 820: for(i=0;i<width;i++)tabe[i]=(double *)ALLOCA((height+1)*sizeof(double));
! 821: define_cursor(can->window,runningcur);
! 822: set_busy(can); set_selection();
! 823: set_drawcolor(can->color);
! 824: switch(can->mode){
! 825: case 6://IFPLOTD
! 826: calc(tabe,can,0);
! 827: if_printNG(display,tabe,can,1);
! 828: break;
! 829: case 7://IFPLOTQ
! 830: calcq(tabe,can,0);
! 831: if_printNG(display,tabe,can,1);
! 832: break;
! 833: case 8://IFPLOTB
! 834: calcb(tabe,can,0);
! 835: if_printNG(display,tabe,can,0);
! 836: break;
! 837: case 9://INEQND
! 838: calc(tabe,can,0);
! 839: area_print(display,tabe,can,0);
! 840: break;
! 841: case 10://INEQNQ
! 842: calcq(tabe,can,0);
! 843: area_print(display,tabe,can,0);
! 844: break;
! 845: case 11://INEQNB
! 846: calcb(tabe,can,0);
! 847: area_print(display,tabe,can,0);
! 848: break;
! 849: case 12://INEQNFAND
! 850: calc(tabe,can,0);
! 851: area_print(display,tabe,can,2);
! 852: break;
! 853: case 13://INEQNQAND
! 854: calcq(tabe,can,0);
! 855: area_print(display,tabe,can,2);
! 856: break;
! 857: case 14://INEQNBAND
! 858: calcb(tabe,can,0);
! 859: area_print(display,tabe,can,2);
! 860: break;
! 861: case 15://INEQNDOR
! 862: calc(tabe,can,0);
! 863: area_print(display,tabe,can,3);
! 864: break;
! 865: case 16://INEQNQOR
! 866: calcq(tabe,can,0);
! 867: area_print(display,tabe,can,3);
! 868: break;
! 869: case 17://INEQNBOR
! 870: calcb(tabe,can,0);
! 871: area_print(display,tabe,can,3);
! 872: break;
! 873: case 18://INEQNDXOR
! 874: calc(tabe,can,0);
! 875: area_print(display,tabe,can,4);
! 876: break;
! 877: case 19://INEQNQXOR
! 878: calcq(tabe,can,0);
! 879: area_print(display,tabe,can,4);
! 880: break;
! 881: case 20://INEQNBXOR
! 882: calcb(tabe,can,0);
! 883: area_print(display,tabe,can,4);
! 884: break;
! 885: case 21://CONPLOTD
! 886: calc(tabe,can,0);
! 887: con_print(display,tabe,can);
! 888: break;
! 889: case 22://CONPLOTQ
! 890: calcq(tabe,can,0);
! 891: con_print(display,tabe,can);
! 892: break;
! 893: case 23://CONPLOTB
! 894: calcb(tabe,can,0);
! 895: con_print(display,tabe,can);
! 896: break;
! 897: #if defined(INTERVAL)
! 898: case 24://ITVIFPLOT:
! 899: itvcalc(tabe,can,1);
! 900: if_printNG(display,tabe,can,1);
! 901: break;
! 902: #endif
! 903: case 25://PLOTOVERD
! 904: calc(tabe,can,0);
! 905: over_print(display,tabe,can,0);
! 906: break;
! 907: case 26://PLOTOVERQ:
! 908: calcq(tabe,can,0);
! 909: over_print(display,tabe,can,0);
! 910: break;
! 911: case 27://PLOTOVERB:
! 912: calcb(tabe,can,0);
! 913: over_print(display,tabe,can,0);
! 914: break;
! 915: }
! 916: set_drawcolor(can->color);
! 917: reset_selection(); reset_busy(can);
! 918: define_cursor(can->window,normalcur);
! 919: }
! 920:
! 921: #if !defined(VISUAL) && !defined(__MINGW32__)
! 922: int objcp(NODE arg){
! 923: int idsrc, idtrg, op_code;
! 924: struct canvas *cansrc, *cantrg;
! 925:
! 926: idsrc=QTOS((Q)ARG0(arg));
! 927: idtrg=QTOS((Q)ARG1(arg));
! 928: op_code=QTOS((Q)ARG2(arg));
! 929: cansrc=canvas[idsrc];
! 930: cantrg=canvas[idtrg];
! 931: obj_op(cansrc, cantrg, op_code);
! 932: return idsrc;
! 933: }
! 934:
! 935: void obj_op(struct canvas *cansrc, struct canvas *cantrg, int op){
! 936: XImage *imgsrc, *imgtrg;
! 937: int width, height, i, j;
! 938: unsigned long src, trg, black, white;
! 939:
! 940: width=cansrc->width; height=cansrc->height;
! 941: imgsrc=XGetImage(display, cansrc->pix, 0, 0, width, height, -1, ZPixmap);
! 942: imgtrg=XGetImage(display, cantrg->pix, 0, 0, width, height, -1, ZPixmap);
! 943: black=GetColor(display, "black");
! 944: white=GetColor(display, "white");
! 945: flush();
! 946: define_cursor(cantrg->window,runningcur);
! 947: set_busy(cantrg); set_selection();
! 948: cantrg->precise=cansrc->precise;
! 949: cantrg->noaxis=cansrc->noaxis;
! 950: cantrg->noaxisb=cansrc->noaxisb;
! 951: cantrg->vx=cansrc->vx;
! 952: cantrg->vy=cansrc->vy;
! 953: cantrg->formula=cansrc->formula;
! 954: cantrg->width=cansrc->width;
! 955: cantrg->height=cansrc->height;
! 956: cantrg->xmin=cansrc->xmin;
! 957: cantrg->xmax=cansrc->xmax;
! 958: cantrg->ymin=cansrc->ymin;
! 959: cantrg->ymax=cansrc->ymax;
! 960: cantrg->zmin=cansrc->zmin;
! 961: cantrg->zmax=cansrc->zmax;
! 962: cantrg->nzstep=cansrc->nzstep;
! 963: cantrg->qxmin=cansrc->qxmin;
! 964: cantrg->qxmax=cansrc->qxmax;
! 965: cantrg->qymin=cansrc->qymin;
! 966: cantrg->qymax=cansrc->qymax;
! 967: cantrg->pa=cansrc->pa;
! 968: switch(op){
! 969: case 1:/* and case */
! 970: for(i=0;i<width;i++)for(j=0;j<height;j++){
! 971: src=XGetPixel(imgsrc,i,j);
! 972: trg=XGetPixel(imgtrg,i,j);
! 973: if( (src == black) || (trg == black) )
! 974: XPutPixel(imgtrg,i,j,black);
! 975: else if( (src == white) || (trg == white) )
! 976: XPutPixel(imgtrg,i,j,white);
! 977: else XPutPixel(imgtrg,i,j,(src & trg));
! 978: }
! 979: break;
! 980: case 3:/* copy case */
! 981: imgtrg->data=imgsrc->data;
! 982: break;
! 983: case 6:/* xor case */
! 984: for(i=0;i<width;i++)for(j=0;j<height;j++){
! 985: src=XGetPixel(imgsrc,i,j);
! 986: trg=XGetPixel(imgtrg,i,j);
! 987: if( (src == black) || (trg == black) )
! 988: XPutPixel(imgtrg,i,j,black);
! 989: else if( (src == white) && (trg == white) )
! 990: XPutPixel(imgtrg,i,j,trg|src);
! 991: else if( (src != white) && (trg != white) )
! 992: XPutPixel(imgtrg,i,j,white);
! 993: else if( src == white )
! 994: XPutPixel(imgtrg,i,j,src);
! 995: }
! 996: break;
! 997: case 7:/* or case */
! 998: for(i=0;i<width;i++)for(j=0;j<height;j++){
! 999: src=XGetPixel(imgsrc,i,j);
! 1000: trg=XGetPixel(imgtrg,i,j);
! 1001: if( (src == black) || (trg == black) )
! 1002: XPutPixel(imgtrg,i,j,black);
! 1003: else if(src == white)
! 1004: XPutPixel(imgtrg,i,j,trg);
! 1005: else if(trg == white)
! 1006: XPutPixel(imgtrg,i,j,src);
! 1007: }
! 1008: break;
! 1009: default:
! 1010: break;
! 1011: }
! 1012: XPutImage(display, cantrg->pix, drawGC, imgtrg, 0, 0, 0, 0, width, height);
! 1013: reset_selection(); reset_busy(cantrg);
! 1014: define_cursor(cantrg->window,normalcur);
! 1015: copy_to_canvas(cantrg);
! 1016: count_and_flush();
! 1017: flush();
! 1018: }
! 1019: #endif
! 1020:
! 1021: int polarplotNG(NODE arg){
! 1022: int i,id,width,height;
! 1023: NODE n;
! 1024: struct canvas *can;
! 1025: LIST range,geom;
! 1026: STRING wname;
! 1027: V v;
! 1028:
! 1029: id=search_canvas();
! 1030: can=canvas[id];
! 1031: can->mode=modeNO(POLARPLOTD);
! 1032: can->formula=(P)ARG0(arg);
! 1033: can->color=QTOS((Q)ARG1(arg));
! 1034: range=(LIST)ARG2(arg);
! 1035: geom=(LIST)ARG3(arg);
! 1036: wname=(STRING)ARG4(arg);
! 1037:
! 1038: if(range){
! 1039: n=NEXT(BDY(range));
! 1040: can->zmin=ToReal(BDY(n));
! 1041: n=NEXT(n);can->zmax=ToReal(BDY(n));
! 1042: n=NEXT(n);
! 1043: can->vx=VR((P)BDY(BDY(range)));
! 1044: can->nzstep=n?QTOS((Q)BDY(n)):DEFAULTPOLARSTEP;
! 1045: }
! 1046: if(geom){
! 1047: can->width=width=QTOS((Q)BDY(BDY(geom)));
! 1048: can->height=height=QTOS((Q)BDY(NEXT(BDY(geom))));
! 1049: }
! 1050: if(wname)can->wname=BDY(wname);
! 1051: else can->wname="";
! 1052: polarcalcNG(can);
! 1053: create_canvas(can);
! 1054: set_drawcolor(can->color);
! 1055: polar_print(display,can);
! 1056: reset_selection();
! 1057: reset_busy(can);
! 1058: define_cursor(can->window,normalcur);
! 1059: return id;
! 1060: }
! 1061:
! 1062: void MSGdraw(char *str){
! 1063: int id,x,y;
! 1064: struct canvas *can;
! 1065:
! 1066: id=search_canvas();
! 1067: can=canvas[id];
! 1068: can->mode=modeNO(INTERACTIVE);
! 1069: can->width=300;
! 1070: can->height=300;
! 1071: can->wname="MSG";
! 1072: x=100;
! 1073: y=100;
! 1074: create_canvas(can);
! 1075: draw_character_string(display,can,x,y,str,0xff0000);
! 1076: }
! 1077:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>