Annotation of OpenXM_contrib2/asir2000/plot/plotp.c, Revision 1.16
1.3 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.4 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.3 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.16 ! saito 48: * $OpenXM: OpenXM_contrib2/asir2000/plot/plotp.c,v 1.15 2011/08/11 06:25:06 saito Exp $
1.3 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "parse.h"
52: #include "ox.h"
53: #include "ifplot.h"
1.2 noro 54: #include <math.h>
1.1 noro 55:
56: #if defined(sun) && !defined(__svr4__)
57: #define EXP10(a) exp10(a)
58: #else
59: #define EXP10(a) pow(10.0,a)
60: #endif
61:
1.5 noro 62: #if defined(VISUAL)
63: static POINT oldpos;
64: #endif
65:
1.15 saito 66: #if defined(INTERVAL)
1.14 saito 67: unsigned long GetColor(Display *, char *);
68:
69: unsigned long GetColor(Display *dis, char *color_name)
70: {
71: Colormap cmap;
72: XColor near_color, true_color;
73:
74: cmap = DefaultColormap( dis, 0 );
75: XAllocNamedColor( dis, cmap, color_name, &near_color, &true_color );
76: return( near_color.pixel );
77: }
78:
1.16 ! saito 79: void area_print(DISPLAY *display,double **tab,struct canvas *can,int GXcode){
! 80: int ix,iy,width,height,wc,**mask;
1.14 saito 81: XImage *image;
1.16 ! saito 82: DRAWABLE pix;
! 83: unsigned long color,black,white,c2;
! 84: double *px,*px1,*px2;
! 85: //GXcode 0:new 1:cp 2:and 3:or 4:xor
! 86: width=can->width;
! 87: height=can->height;
! 88: pix=can->pix;
! 89: mask=(int **)ALLOCA((width)*sizeof(int *));
! 90: for(ix=0;ix<width;ix++)mask[ix]=(int *)ALLOCA((height)*sizeof(int));
! 91: // create mask table values boundary:0 positive:1 negativ:-1
! 92: for(ix=0;ix<width;ix++)for(iy=0;iy<height;iy++)
! 93: if((tab[ix][iy]>0)&&(tab[ix+1][iy]>0)&&(tab[ix][iy+1]>0)&&
! 94: (tab[ix+1][iy+1]>0)) mask[ix][iy]=1;//all postive
! 95: else if((tab[ix][iy]<0)&&(tab[ix+1][iy]<0)&&(tab[ix][iy+1]<0)&&
! 96: (tab[ix+1][iy+1]<0)) mask[ix][iy]=-1;//all negativ
! 97: else mask[ix][iy]=0;//boundary
1.14 saito 98: flush();
1.16 ! saito 99: black=GetColor(display,"black");
! 100: white=GetColor(display,"white");
! 101: set_drawcolor(can->color);
! 102: color=can->color;
! 103: image=XGetImage(display,pix,0,0,width,height,-1,ZPixmap);
! 104: for(ix=0;ix<width;ix++){
! 105: for(iy=0;iy<height;iy++){
! 106: c2=XGetPixel(image,ix,height-iy-1);
! 107: if(c2==white)wc=-1;
! 108: else if(c2==black)wc=0;
! 109: else wc=1;
! 110: if(wc!=0){//XPutPixel(image,ix,iy,black);
! 111: if(mask[ix][iy]==0)XPutPixel(image,ix,height-iy-1,black);//boundary
1.14 saito 112: else {
1.16 ! saito 113: switch (GXcode){
! 114: case 0: //new window
! 115: case 1: //cp
! 116: if(mask[ix][iy]==1)XPutPixel(image,ix,height-iy-1,color);
! 117: else XPutPixel(image,ix,height-iy-1,BackPixel);
1.14 saito 118: break;
1.16 ! saito 119: case 2: //and
! 120: if((mask[ix][iy]==1)&&(wc==1))XPutPixel(image,ix,height-iy-1,color);
! 121: else XPutPixel(image,ix,height-iy-1,BackPixel);
1.14 saito 122: break;
1.16 ! saito 123: case 3: //or
! 124: if((mask[ix][iy]==1)||(wc==1))XPutPixel(image,ix,height-iy-1,color);
! 125: else XPutPixel(image,ix,height-iy-1,BackPixel);
1.14 saito 126: break;
1.16 ! saito 127: case 4: //xor
! 128: if((mask[ix][iy]==1)^(wc==1))XPutPixel(image,ix,height-iy-1,color);
! 129: else XPutPixel(image,ix,height-iy-1,BackPixel);
1.14 saito 130: break;
131: }
132: }
133: }
134: }
135: }
1.16 ! saito 136: XPutImage(display,pix,drawGC,image,0,0,0,0,width,height);
1.14 saito 137: count_and_flush();
138: flush();
139: }
1.16 ! saito 140:
! 141: void over_print(DISPLAY *display,double **tab,struct canvas *can,int GXcode){
! 142: int ix,iy,width,height;
! 143: DRAWABLE pix;
! 144: double vmin,vmax;
! 145: //GXcode 0:over 1:cp 2:and 3:or 4:xor
! 146: pix=can->pix; width=can->width; height=can->height;
! 147: for(ix=0;ix<width;ix++){
! 148: for(iy=0;iy<height;iy++){
! 149: vmax=
! 150: MAX(MAX(tab[ix][iy],tab[ix][iy+1]),MAX(tab[ix+1][iy],tab[ix+1][iy+1]));
! 151: vmin=
! 152: MIN(MIN(tab[ix][iy],tab[ix][iy+1]),MIN(tab[ix+1][iy],tab[ix+1][iy+1]));
! 153: if(vmin<=0.0&vmax>=0.0)DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
! 154: }
! 155: count_and_flush();
! 156: }
! 157: flush();
! 158: }
1.15 saito 159: #endif
1.14 saito 160:
1.16 ! saito 161: void if_print(DISPLAY *display,double **tab,struct canvas *can,int cond){
1.1 noro 162: int ix,iy,width,height;
1.16 ! saito 163: double zst,zed,zsp;
! 164: DRAWABLE pix;
! 165: width=can->width; height=can->height; pix=can->pix;
! 166: if(cond==0){
! 167: //MODE_IFPLOTB
! 168: for(iy=0;iy<height-1;iy++)for(ix=0;ix<width-1;ix++)
! 169: if(tab[ix][iy]==0.0) DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
! 170: } else {
! 171: //MODE_IFPLOT,MODE_IFPLOTD,MODE_IFPLOTQ
! 172: for(iy=0;iy<height-1;iy++)for(ix=0;ix<width-1;ix++){
! 173: if(tab[ix][iy]==0.0) DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
! 174: else if(tab[ix][iy]>0){
! 175: if(tab[ix+1][iy+1]<0||tab[ix][iy+1]<0||tab[ix+1][iy]<0)
! 176: DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
! 177: } else if(tab[ix+1][iy+1]>0||tab[ix][iy+1]>0||tab[ix+1][iy]>0)
! 178: DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
! 179: count_and_flush();
! 180: }
! 181: }
! 182: flush();
! 183: }
! 184:
! 185: void if_printOld(DISPLAY *display,double **tab,struct canvas *can){
! 186: int i,ix,iy,width,height;
1.1 noro 187: double *px,*px1,*px2;
1.16 ! saito 188: double **vmax,**vmin,*zst,zstep,zv,u,l;
1.1 noro 189: DRAWABLE pix;
1.16 ! saito 190: POINT *pa,*pa1;
! 191: struct pa *parray;
1.1 noro 192:
1.16 ! saito 193: if(can->mode==MODE_CONPLOT){
! 194: width=can->width;height=can->height;pix=can->pix;
! 195: //con_print(display,tab,can);
! 196: // calc all cell max,min value
! 197: vmax=((double **)ALLOCA((width+1)*sizeof(double *)));
! 198: vmin=((double **)ALLOCA((width+1)*sizeof(double *)));
! 199: for(i=0;i<width;i++){
! 200: vmax[i]=(double *)ALLOCA((height+1)*sizeof(double));
! 201: vmin[i]=(double *)ALLOCA((height+1)*sizeof(double));
! 202: }
! 203: for(ix=0;ix<width;ix++){
! 204: for(iy=0;iy<height;iy++){
! 205: vmax[ix][iy]=
! 206: MAX(MAX(tab[ix][iy],tab[ix][iy+1]),MAX(tab[ix+1][iy],tab[ix+1][iy+1]));
! 207: vmin[ix][iy]=
! 208: MIN(MIN(tab[ix][iy],tab[ix][iy+1]),MIN(tab[ix+1][iy],tab[ix+1][iy+1]));
! 209: }
! 210: }
! 211: if(can->zmax==can->zmin)zstep=(can->vmax-can->vmin)/can->nzstep;
! 212: else zstep=(can->zmax-can->zmin)/can->nzstep;
! 213: zst=(double *)ALLOCA((can->nzstep+1)*sizeof(double));
! 214: zv=can->xmin;
! 215: for(i=0,zv=can->xmin;i<can->nzstep;zv+=zstep,i++)zst[i]=zv;
! 216: for(iy=0;iy<height-1;iy++){
! 217: for(ix=0;ix<width-1;ix++){
! 218: for(i=0;i<can->nzstep;i++){
! 219: if(vmin[ix][iy]<=zst[i] && vmax[ix][iy]>=zst[i]){
! 220: DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
! 221: break;
! 222: }
! 223: count_and_flush();
! 224: }
! 225: }
! 226: }
! 227: } else {
! 228: width=can->width;height=can->height;pix=can->pix;
! 229: for(ix=0;ix<width-1;ix++)
! 230: for(iy=0,px=tab[ix],px1=tab[ix+1],px2=px+1;iy<height-1;
! 231: iy++,px++,px1++,px2++)
! 232: if(((*px>=0)&&((*px1<=0)||(*px2<=0)))||
! 233: ((*px<=0)&&((*px1>=0)||(*px2>=0)))){
1.12 noro 234: DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
1.1 noro 235: count_and_flush();
236: }
1.16 ! saito 237: }
1.1 noro 238: flush();
239: }
240:
1.8 noro 241: #define MEMORY_DRAWPOINT(a,len,x,y) (((a)[(len)*(y)+((x)>>3)]) |= (1<<((x)&7)))
242:
1.16 ! saito 243: void memory_if_print(double **tab,struct canvas *can,BYTEARRAY *bytes){
1.8 noro 244: int ix,iy,width,height;
245: double *px,*px1,*px2;
246: unsigned char *array;
247: int scan_len;
1.16 ! saito 248: if ( can->mode == MODE_CONPLOT ){
! 249: memory_con_print(tab,can,bytes);
! 250: return;
1.8 noro 251: }
252: width = can->width; height = can->height;
1.16 ! saito 253: // scan_len = byte length of the scan line
1.8 noro 254: scan_len = (width+7)/8;
255: MKBYTEARRAY(*bytes,scan_len*height);
256: array = BDY(*bytes);
257: for( ix=0; ix<width-1; ix++ )
258: for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
259: iy<height-1 ;iy++, px++, px1++, px2++ )
260: if ( ((*px >= 0) && ((*px1 <= 0) || (*px2 <= 0))) ||
261: ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) {
262: MEMORY_DRAWPOINT(array,scan_len,ix,height-iy-1);
263: }
264: }
265:
1.16 ! saito 266: void con_print(DISPLAY *display,double **tab,struct canvas *can){
! 267: int i,ix,iy,width,height;
1.1 noro 268: double *px,*px1,*px2;
1.16 ! saito 269: double **vmax,**vmin,*zst,zstep,zv,u,l;
1.1 noro 270: DRAWABLE pix;
271: POINT *pa,*pa1;
272: struct pa *parray;
273:
1.16 ! saito 274: width=can->width;height=can->height;pix=can->pix;
! 275: vmax=((double **)ALLOCA((width+1)*sizeof(double *)));
! 276: vmin=((double **)ALLOCA((width+1)*sizeof(double *)));
! 277: for(i=0;i<width;i++){
! 278: vmax[i]=(double *)ALLOCA((height+1)*sizeof(double));
! 279: vmin[i]=(double *)ALLOCA((height+1)*sizeof(double));
! 280: }
! 281: for(ix=0;ix<width;ix++){
! 282: for(iy=0;iy<height;iy++){
! 283: vmax[ix][iy]=
! 284: MAX(MAX(tab[ix][iy],tab[ix][iy+1]),MAX(tab[ix+1][iy],tab[ix+1][iy+1]));
! 285: vmin[ix][iy]=
! 286: MIN(MIN(tab[ix][iy],tab[ix][iy+1]),MIN(tab[ix+1][iy],tab[ix+1][iy+1]));
! 287: }
! 288: }
! 289: if(can->zmax==can->zmin)zstep=(can->vmax-can->vmin)/can->nzstep;
! 290: else zstep=(can->zmax-can->zmin)/can->nzstep;
! 291: zst=(double *)ALLOCA((can->nzstep+1)*sizeof(double));
! 292: zv=can->xmin;
! 293: for(i=0,zv=can->xmin;i<can->nzstep;zv+=zstep,i++)zst[i]=zv;
! 294: for(iy=0;iy<height-1;iy++){
! 295: for(ix=0;ix<width-1;ix++){
! 296: for(i=0;i<can->nzstep;i++){
! 297: if(vmin[ix][iy]<=zst[i] && vmax[ix][iy]>=zst[i]){
! 298: DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
! 299: break;
1.1 noro 300: }
1.16 ! saito 301: count_and_flush();
! 302: }
1.1 noro 303: }
304: }
305: flush();
1.8 noro 306: }
307:
1.16 ! saito 308: void memory_con_print(double **tab,struct canvas *can,BYTEARRAY *bytes){
1.8 noro 309: int ix,iy,iz,width,height,pas,pai,len;
310: double zstep,z;
311: double *px,*px1,*px2;
312: POINT *pa,*pa1;
313: struct pa *parray;
314: unsigned char *array;
315: int scan_len;
316:
317: width = can->width; height = can->height;
318: zstep = (can->zmax-can->zmin)/can->nzstep;
319: can->pa = (struct pa *)MALLOC((can->nzstep+1)*sizeof(struct pa));
320: pas = width;
321: pa = (POINT *)ALLOCA(pas*sizeof(POINT));
322: for ( z = can->zmin, iz = 0; z <= can->zmax; z += zstep, iz++ ) {
323: pai = 0;
324: for( ix=0; ix<width-1; ix++ )
325: for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
326: iy<height-1 ;iy++, px++, px1++, px2++ )
327: if ( ((*px >= z) && ((*px1 <= z) || (*px2 <= z))) ||
328: ((*px <= z) && ((*px1 >= z) || (*px2 >= z))) ) {
329: if ( pai == pas ) {
330: pa1 = (POINT *)ALLOCA(2*pas*sizeof(POINT));
331: bcopy((char *)pa,(char *)pa1,pas*sizeof(POINT)); pa = pa1;
332: pas += pas;
333: }
334: XC(pa[pai]) = ix; YC(pa[pai]) = height-iy-1; pai++;
335: }
336: can->pa[iz].length = pai;
337: if ( pai ) {
338: pa1 = (POINT *)MALLOC(pai*sizeof(POINT));
339: bcopy((char *)pa,(char *)pa1,pai*sizeof(POINT));
340: can->pa[iz].pos = pa1;
341: }
342: }
343: /* scan_len = byte length of the scan line */
344: scan_len = (width+7)/8;
345: MKBYTEARRAY(*bytes,scan_len*height);
346: array = BDY(*bytes);
347: for ( parray = can->pa, iz = 0; iz <= can->nzstep; iz++, parray++ )
348: for ( pa = parray->pos, len = parray->length, ix = 0; ix < len; ix++ ) {
349: MEMORY_DRAWPOINT(array,scan_len,XC(pa[ix]),YC(pa[ix]));
350: }
1.13 noro 351: }
352:
1.16 ! saito 353: void memory_print(struct canvas *can,BYTEARRAY *bytes){
1.13 noro 354: int len,scan_len,i;
355: POINT *pa;
356: char *array;
357:
358: /* scan_len = byte length of the scan line */
359: scan_len = (can->width+7)/8;
360: MKBYTEARRAY(*bytes,scan_len*can->height);
361: array = BDY(*bytes);
362:
363: len = can->pa[0].length;
364: pa = can->pa[0].pos;
365: for ( i = 0; i < len; i++ ) {
366: MEMORY_DRAWPOINT(array,scan_len,pa[i].x,pa[i].y);
367: }
1.1 noro 368: }
369:
1.16 ! saito 370: void qif_print(DISPLAY *display,char **tab,struct canvas *can){
1.1 noro 371: int ix,iy,width,height;
372: char *px;
373: DRAWABLE pix;
374:
375: flush();
376: width = can->width; height = can->height; pix = can->pix;
377: for( ix = 0; ix < width; ix++ )
378: for(iy = 0, px = tab[ix]; iy < height ;iy++, px++ )
379: if ( *px ) {
1.12 noro 380: DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
1.1 noro 381: count_and_flush();
382: }
383: flush();
384: }
385:
1.16 ! saito 386: void plot_print(DISPLAY *display,struct canvas *can){
1.9 noro 387: int len;
1.1 noro 388: POINT *pa;
1.5 noro 389:
390: #if defined(VISUAL)
391: len = can->pa[0].length;
392: pa = can->pa[0].pos;
1.6 noro 393:
394: Polyline(can->pix,pa,len);
395: // for ( i = 0; i < len-1; i++ ) {
396: // DRAWLINE(display,can->pix,drawGC,pa[i].x,pa[i].y,pa[i+1].x,pa[i+1].y);
397: // }
1.5 noro 398: #else
1.1 noro 399: XDrawLines(display,can->pix,drawGC,
400: can->pa[0].pos,can->pa[0].length,CoordModeOrigin);
401: XFlush(display);
1.5 noro 402: #endif
403: }
404:
1.16 ! saito 405: void draw_point(DISPLAY *display,struct canvas *can,int x,int y,int color){
1.5 noro 406: #if defined(VISUAL)
407: HDC dc;
408:
1.6 noro 409: SetPixel(can->pix,x,y,(COLORREF)color);
1.5 noro 410: dc = GetDC(can->hwnd);
1.6 noro 411: SetPixel(dc,x,y,(COLORREF)color);
1.5 noro 412: ReleaseDC(can->hwnd,dc);
413: #else
1.12 noro 414: set_drawcolor(color);
415: DRAWPOINT(display,can->pix,cdrawGC,x,y);
416: DRAWPOINT(display,can->window,cdrawGC,x,y);
1.5 noro 417: XFlush(display);
418: #endif
419: }
420:
1.16 ! saito 421: void draw_line(
! 422: DISPLAY *display,struct canvas *can,int x,int y,int u,int v,int color){
1.5 noro 423: #if defined(VISUAL)
424: HDC dc;
1.6 noro 425: HPEN pen,oldpen;
1.5 noro 426:
1.6 noro 427: if ( color ) {
428: pen = CreatePen(PS_SOLID,1,color);
429: oldpen = SelectObject(can->pix,pen);
430: DRAWLINE(display,can->pix,drawGC,x,y,u,v);
431: SelectObject(can->pix,oldpen);
432:
433: dc = GetDC(can->hwnd);
434: oldpen = SelectObject(dc,pen);
435: DRAWLINE(display,dc,drawGC,x,y,u,v);
436: SelectObject(dc,oldpen);
437: ReleaseDC(can->hwnd,dc);
438:
439: DeleteObject(pen);
440: } else {
441: DRAWLINE(display,can->pix,drawGC,x,y,u,v);
442: dc = GetDC(can->hwnd);
443: DRAWLINE(display,dc,drawGC,x,y,u,v);
444: ReleaseDC(can->hwnd,dc);
445: }
1.5 noro 446: #else
1.12 noro 447: set_drawcolor(color);
448: DRAWLINE(display,can->pix,cdrawGC,x,y,u,v);
449: DRAWLINE(display,can->window,cdrawGC,x,y,u,v);
1.10 noro 450: XFlush(display);
451: #endif
452: }
453:
1.16 ! saito 454: void draw_character_string(
! 455: DISPLAY *display,struct canvas *can,int x,int y,char *str,int color){
1.10 noro 456: #if defined(VISUAL)
457: HDC dc;
1.11 noro 458: COLORREF oldcolor;
1.10 noro 459:
460: if ( color ) {
1.11 noro 461: oldcolor = SetTextColor(can->pix,color);
1.10 noro 462: DRAWSTRING(display,can->pix,drawGC,x,y,str,strlen(str));
1.11 noro 463: SetTextColor(can->pix,oldcolor);
1.10 noro 464:
465: dc = GetDC(can->hwnd);
1.11 noro 466: oldcolor = SetTextColor(dc,color);
1.10 noro 467: DRAWSTRING(display,dc,drawGC,x,y,str,strlen(str));
1.11 noro 468: SetTextColor(dc,oldcolor);
1.10 noro 469: ReleaseDC(can->hwnd,dc);
470: } else {
471: DRAWSTRING(display,can->pix,drawGC,x,y,str,strlen(str));
472: dc = GetDC(can->hwnd);
473: DRAWSTRING(display,dc,drawGC,x,y,str,strlen(str));
474: ReleaseDC(can->hwnd,dc);
475: }
476: #else
1.12 noro 477: set_drawcolor(color);
478: DRAWSTRING(display,can->pix,cdrawGC,x,y,str,strlen(str));
479: DRAWSTRING(display,can->window,cdrawGC,x,y,str,strlen(str));
1.5 noro 480: XFlush(display);
481: #endif
1.1 noro 482: }
483:
484: #define D 5
485:
1.16 ! saito 486: void pline(DISPLAY *display,struct canvas *can,DRAWABLE d){
1.9 noro 487: double w,w1,e,n;
1.1 noro 488: int x0,y0,x,y,xadj,yadj;
489: char buf[BUFSIZ];
490: double adjust_scale();
491:
1.5 noro 492: /* XXX : should be cleaned up */
493: if ( can->noaxis || (can->mode == MODE_PLOT && !can->pa) )
494: return;
495: if ( can->mode == MODE_INTERACTIVE )
1.1 noro 496: return;
497:
498: xadj = yadj = 0;
499: if ( (can->xmin < 0) && (can->xmax > 0) ) {
1.6 noro 500: x0 = (int)((can->width)*(-can->xmin/(can->xmax-can->xmin)));
1.1 noro 501: DRAWLINE(display,d,dashGC,x0,0,x0,can->height);
502: } else if ( can->xmin >= 0 )
503: x0 = 0;
504: else
1.6 noro 505: x0 = can->width-D;
1.1 noro 506: if ( (can->ymin < 0) && (can->ymax > 0) ) {
1.6 noro 507: y0 = (int)((can->height)*(can->ymax/(can->ymax-can->ymin)));
1.1 noro 508: DRAWLINE(display,d,dashGC,0,y0,can->width,y0);
509: } else if ( can->ymin >= 0 )
1.6 noro 510: y0 = can->height;
1.1 noro 511: else
512: y0 = D;
1.6 noro 513:
514: /* scale on x-axis */
1.1 noro 515: w = can->xmax-can->xmin;
516: w1 = w * DEFAULTWIDTH/can->width;
517: e = adjust_scale(EXP10(floor(log10(w1))),w1);
518: for ( n = ceil(can->xmin/e); n*e<= can->xmax; n++ ) {
1.9 noro 519: x = (int)(can->width*(n*e-can->xmin)/w);
1.1 noro 520: DRAWLINE(display,d,drawGC,x,y0,x,y0-D);
521: sprintf(buf,"%g",n*e);
1.6 noro 522: DRAWSTRING(display,d,scaleGC,x+2,y0+2,buf,strlen(buf));
1.1 noro 523: }
1.6 noro 524:
525: /* scale on y-axis */
1.1 noro 526: w = can->ymax-can->ymin;
527: w1 = w * DEFAULTHEIGHT/can->height;
528: e = adjust_scale(EXP10(floor(log10(w1))),w1);
529: for ( n = ceil(can->ymin/e); n*e<= can->ymax; n++ ) {
1.9 noro 530: y = (int)(can->height*(1-(n*e-can->ymin)/w));
1.1 noro 531: DRAWLINE(display,d,drawGC,x0,y,x0+D,y);
532: sprintf(buf,"%g",n*e);
1.6 noro 533: if ( can->xmax <= 0 ) {
534: #if !defined(VISUAL)
1.1 noro 535: xadj = TEXTWIDTH(sffs,buf,strlen(buf));
1.6 noro 536: #else
537: SIZE size;
538:
539: GetTextExtentPoint32(d,buf,strlen(buf),&size);
540: xadj = size.cx;
541: #endif
542: }
543: DRAWSTRING(display,d,scaleGC,x0+2-xadj,y+2,buf,strlen(buf));
1.1 noro 544: }
545: }
546:
1.16 ! saito 547: double adjust_scale(double e,double w){
1.1 noro 548: switch ( (int)floor(w/e) ) {
549: case 1:
550: return e/4; break;
551: case 2: case 3:
552: return e/2; break;
553: case 4: case 5: case 6: case 7:
554: return e; break;
555: break;
556: case 8: case 9: case 10: default:
557: return 2*e; break;
558: }
559: }
560:
1.16 ! saito 561: void initmarker(struct canvas *can,char *message){
1.5 noro 562: #if defined(VISUAL)
563: can->real_can->percentage = 0;
564: can->real_can->prefix = message;
565: #else
1.1 noro 566: XawScrollbarSetThumb(can->xdone,0.0,0.0);
567: XawScrollbarSetThumb(can->ydone,1.0,0.0);
568: XFlush(display);
1.5 noro 569: #endif
1.1 noro 570: }
571:
1.16 ! saito 572: void marker(struct canvas *can,int dir,int p){
1.5 noro 573: #if defined(VISUAL)
574: if ( dir == DIR_X )
1.9 noro 575: can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->width*100);
1.5 noro 576: else if ( dir == DIR_Y )
1.9 noro 577: can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->height*100);
1.5 noro 578: else
1.9 noro 579: can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->nzstep*100);
1.5 noro 580: #else
1.1 noro 581: if ( dir == DIR_X ) {
582: XawScrollbarSetThumb(can->xdone,(float)p/(float)can->width,0.05);
583: count_and_flush();
584: } else if ( dir == DIR_Y ) {
585: XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->height,0.05);
586: count_and_flush();
587: } else {
588: XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->nzstep,0.05);
589: flush();
590: }
1.5 noro 591: #endif
1.1 noro 592: }
593:
1.16 ! saito 594: void define_cursor(WINDOW w,CURSOR cur){
1.5 noro 595: #if !defined(VISUAL)
1.1 noro 596: XDefineCursor(display,w,cur); flush();
1.5 noro 597: #endif
1.1 noro 598: }
599:
600: static int flush_count;
601: #if defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__)
602: #define MAX_COUNT 64
603: #else
604: #define MAX_COUNT 32
605: #endif
606:
1.16 ! saito 607: void count_and_flush(){
1.5 noro 608: #if !defined(VISUAL)
1.1 noro 609: if ( ++flush_count == MAX_COUNT )
610: flush();
1.5 noro 611: #endif
1.1 noro 612: }
613:
1.16 ! saito 614: void flush(){
1.5 noro 615: #if !defined(VISUAL)
1.1 noro 616: flush_count = 0;
617: XFlush(display);
1.5 noro 618: #endif
1.1 noro 619: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>