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