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