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