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