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