Annotation of OpenXM_contrib2/asir2000/plot/plotp.c, Revision 1.7
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.7 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/plot/plotp.c,v 1.6 2000/11/09 01:51:13 noro 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.1 noro 66: if_print(display,tab,can)
67: DISPLAY *display;
68: double **tab;
69: struct canvas *can;
70: {
71: int ix,iy,width,height;
72: double *px,*px1,*px2;
73: DRAWABLE pix;
74:
75: if ( can->mode == MODE_CONPLOT ) {
76: con_print(display,tab,can); return;
77: }
78: flush();
79: width = can->width; height = can->height; pix = can->pix;
80: for( ix=0; ix<width-1; ix++ )
81: for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
82: iy<height-1 ;iy++, px++, px1++, px2++ )
83: if ( ((*px >= 0) && ((*px1 <= 0) || (*px2 <= 0))) ||
84: ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) {
85: DRAWPOINT(display,pix,drawGC,ix,height-iy-1);
86: count_and_flush();
87: }
88: flush();
89: }
90:
91: con_print(display,tab,can)
92: DISPLAY *display;
93: double **tab;
94: struct canvas *can;
95: {
96: int ix,iy,iz,width,height,pas,pai,len;
97: double zstep,z;
98: double *px,*px1,*px2;
99: DRAWABLE pix;
100: POINT *pa,*pa1;
101: struct pa *parray;
102:
103:
104: width = can->width; height = can->height; pix = can->pix;
105: zstep = (can->zmax-can->zmin)/can->nzstep;
106: can->pa = (struct pa *)MALLOC((can->nzstep+1)*sizeof(struct pa));
107: pas = width;
108: pa = (POINT *)ALLOCA(pas*sizeof(POINT));
109: initmarker(can,"Drawing...");
110: for ( z = can->zmin, iz = 0; z <= can->zmax; z += zstep, iz++ ) {
111: marker(can,DIR_Z,iz);
112: pai = 0;
113: for( ix=0; ix<width-1; ix++ )
114: for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
115: iy<height-1 ;iy++, px++, px1++, px2++ )
116: if ( ((*px >= z) && ((*px1 <= z) || (*px2 <= z))) ||
117: ((*px <= z) && ((*px1 >= z) || (*px2 >= z))) ) {
118: if ( pai == pas ) {
119: pa1 = (POINT *)ALLOCA(2*pas*sizeof(POINT));
120: bcopy((char *)pa,(char *)pa1,pas*sizeof(POINT)); pa = pa1;
121: pas += pas;
122: }
123: XC(pa[pai]) = ix; YC(pa[pai]) = height-iy-1; pai++;
124: }
125: can->pa[iz].length = pai;
126: if ( pai ) {
127: pa1 = (POINT *)MALLOC(pai*sizeof(POINT));
128: bcopy((char *)pa,(char *)pa1,pai*sizeof(POINT));
129: can->pa[iz].pos = pa1;
130: }
131: }
132: flush();
133: for ( parray = can->pa, iz = 0; iz <= can->nzstep; iz++, parray++ )
134: for ( pa = parray->pos, len = parray->length, ix = 0; ix < len; ix++ ) {
135: DRAWPOINT(display,pix,drawGC,XC(pa[ix]),YC(pa[ix]));
136: count_and_flush();
137: }
138: flush();
139: }
140:
141: qif_print(display,tab,can)
142: DISPLAY *display;
143: char **tab;
144: struct canvas *can;
145: {
146: int ix,iy,width,height;
147: char *px;
148: DRAWABLE pix;
149:
150: flush();
151: width = can->width; height = can->height; pix = can->pix;
152: for( ix = 0; ix < width; ix++ )
153: for(iy = 0, px = tab[ix]; iy < height ;iy++, px++ )
154: if ( *px ) {
155: DRAWPOINT(display,pix,drawGC,ix,height-iy-1);
156: count_and_flush();
157: }
158: flush();
159: }
160:
161: plot_print(display,can)
162: DISPLAY *display;
163: struct canvas *can;
164: {
165: int len,i;
166: POINT *pa;
1.5 noro 167:
168: #if defined(VISUAL)
169: len = can->pa[0].length;
170: pa = can->pa[0].pos;
1.6 noro 171:
172: Polyline(can->pix,pa,len);
173: // for ( i = 0; i < len-1; i++ ) {
174: // DRAWLINE(display,can->pix,drawGC,pa[i].x,pa[i].y,pa[i+1].x,pa[i+1].y);
175: // }
1.5 noro 176: #else
1.1 noro 177: XDrawLines(display,can->pix,drawGC,
178: can->pa[0].pos,can->pa[0].length,CoordModeOrigin);
179: XFlush(display);
1.5 noro 180: #endif
181: }
182:
1.6 noro 183: draw_point(display,can,x,y,color)
1.5 noro 184: DISPLAY *display;
185: struct canvas *can;
186: int x,y;
1.6 noro 187: int color;
1.5 noro 188: {
189: #if defined(VISUAL)
190: HDC dc;
191:
1.6 noro 192: SetPixel(can->pix,x,y,(COLORREF)color);
1.5 noro 193: dc = GetDC(can->hwnd);
1.6 noro 194: SetPixel(dc,x,y,(COLORREF)color);
1.5 noro 195: ReleaseDC(can->hwnd,dc);
196: #else
1.7 ! noro 197: if ( color ) {
! 198: set_drawcolor(color);
! 199: DRAWPOINT(display,can->pix,cdrawGC,x,y);
! 200: DRAWPOINT(display,can->window,cdrawGC,x,y);
! 201: } else {
! 202: DRAWPOINT(display,can->pix,drawGC,x,y);
! 203: DRAWPOINT(display,can->window,drawGC,x,y);
! 204: }
1.5 noro 205: XFlush(display);
206: #endif
207: }
208:
1.6 noro 209: draw_line(display,can,x,y,u,v,color)
1.5 noro 210: DISPLAY *display;
211: struct canvas *can;
212: int x,y,u,v;
1.6 noro 213: int color;
1.5 noro 214: {
215: #if defined(VISUAL)
216: HDC dc;
1.6 noro 217: HPEN pen,oldpen;
1.5 noro 218:
1.6 noro 219: if ( color ) {
220: pen = CreatePen(PS_SOLID,1,color);
221: oldpen = SelectObject(can->pix,pen);
222: DRAWLINE(display,can->pix,drawGC,x,y,u,v);
223: SelectObject(can->pix,oldpen);
224:
225: dc = GetDC(can->hwnd);
226: oldpen = SelectObject(dc,pen);
227: DRAWLINE(display,dc,drawGC,x,y,u,v);
228: SelectObject(dc,oldpen);
229: ReleaseDC(can->hwnd,dc);
230:
231: DeleteObject(pen);
232: } else {
233: DRAWLINE(display,can->pix,drawGC,x,y,u,v);
234: dc = GetDC(can->hwnd);
235: DRAWLINE(display,dc,drawGC,x,y,u,v);
236: ReleaseDC(can->hwnd,dc);
237: }
1.5 noro 238: #else
1.7 ! noro 239: if ( color ) {
! 240: set_drawcolor(color);
! 241: DRAWLINE(display,can->pix,cdrawGC,x,y,u,v);
! 242: DRAWLINE(display,can->window,cdrawGC,x,y,u,v);
! 243: } else {
! 244: DRAWLINE(display,can->pix,drawGC,x,y,u,v);
! 245: DRAWLINE(display,can->window,drawGC,x,y,u,v);
! 246: }
1.5 noro 247: XFlush(display);
248: #endif
1.1 noro 249: }
250:
251: #define D 5
252:
253: pline(display,can,d)
254: DISPLAY *display;
255: struct canvas *can;
256: DRAWABLE d;
257: {
258: double w,w1,k,e,n;
259: int x0,y0,x,y,xadj,yadj;
260: char buf[BUFSIZ];
261: double adjust_scale();
262:
1.5 noro 263: /* XXX : should be cleaned up */
264: if ( can->noaxis || (can->mode == MODE_PLOT && !can->pa) )
265: return;
266: if ( can->mode == MODE_INTERACTIVE )
1.1 noro 267: return;
268:
269: xadj = yadj = 0;
270: if ( (can->xmin < 0) && (can->xmax > 0) ) {
1.6 noro 271: x0 = (int)((can->width)*(-can->xmin/(can->xmax-can->xmin)));
1.1 noro 272: DRAWLINE(display,d,dashGC,x0,0,x0,can->height);
273: } else if ( can->xmin >= 0 )
274: x0 = 0;
275: else
1.6 noro 276: x0 = can->width-D;
1.1 noro 277: if ( (can->ymin < 0) && (can->ymax > 0) ) {
1.6 noro 278: y0 = (int)((can->height)*(can->ymax/(can->ymax-can->ymin)));
1.1 noro 279: DRAWLINE(display,d,dashGC,0,y0,can->width,y0);
280: } else if ( can->ymin >= 0 )
1.6 noro 281: y0 = can->height;
1.1 noro 282: else
283: y0 = D;
1.6 noro 284:
285: /* scale on x-axis */
1.1 noro 286: w = can->xmax-can->xmin;
287: w1 = w * DEFAULTWIDTH/can->width;
288: e = adjust_scale(EXP10(floor(log10(w1))),w1);
289: for ( n = ceil(can->xmin/e); n*e<= can->xmax; n++ ) {
290: x = (int)can->width*(n*e-can->xmin)/w;
291: DRAWLINE(display,d,drawGC,x,y0,x,y0-D);
292: sprintf(buf,"%g",n*e);
1.6 noro 293: DRAWSTRING(display,d,scaleGC,x+2,y0+2,buf,strlen(buf));
1.1 noro 294: }
1.6 noro 295:
296: /* scale on y-axis */
1.1 noro 297: w = can->ymax-can->ymin;
298: w1 = w * DEFAULTHEIGHT/can->height;
299: e = adjust_scale(EXP10(floor(log10(w1))),w1);
300: for ( n = ceil(can->ymin/e); n*e<= can->ymax; n++ ) {
301: y = (int)can->height*(1-(n*e-can->ymin)/w);
302: DRAWLINE(display,d,drawGC,x0,y,x0+D,y);
303: sprintf(buf,"%g",n*e);
1.6 noro 304: if ( can->xmax <= 0 ) {
305: #if !defined(VISUAL)
1.1 noro 306: xadj = TEXTWIDTH(sffs,buf,strlen(buf));
1.6 noro 307: #else
308: SIZE size;
309:
310: GetTextExtentPoint32(d,buf,strlen(buf),&size);
311: xadj = size.cx;
312: #endif
313: }
314: DRAWSTRING(display,d,scaleGC,x0+2-xadj,y+2,buf,strlen(buf));
1.1 noro 315: }
316: }
317:
318: double adjust_scale(e,w)
319: double e,w;
320: {
321: switch ( (int)floor(w/e) ) {
322: case 1:
323: return e/4; break;
324: case 2: case 3:
325: return e/2; break;
326: case 4: case 5: case 6: case 7:
327: return e; break;
328: break;
329: case 8: case 9: case 10: default:
330: return 2*e; break;
331: }
332: }
333:
334: initmarker(can,message)
335: struct canvas *can;
336: char *message;
337: {
1.5 noro 338: #if defined(VISUAL)
339: can->real_can->percentage = 0;
340: can->real_can->prefix = message;
341: #else
1.1 noro 342: XawScrollbarSetThumb(can->xdone,0.0,0.0);
343: XawScrollbarSetThumb(can->ydone,1.0,0.0);
344: XFlush(display);
1.5 noro 345: #endif
1.1 noro 346: }
347:
348: marker(can,dir,p)
349: struct canvas *can;
350: int dir,p;
351: {
1.5 noro 352: #if defined(VISUAL)
353: if ( dir == DIR_X )
354: can->real_can->percentage = ceil((float)p/(float)can->real_can->width*100);
355: else if ( dir == DIR_Y )
356: can->real_can->percentage = ceil((float)p/(float)can->real_can->height*100);
357: else
358: can->real_can->percentage = ceil((float)p/(float)can->real_can->nzstep*100);
359: #else
1.1 noro 360: if ( dir == DIR_X ) {
361: XawScrollbarSetThumb(can->xdone,(float)p/(float)can->width,0.05);
362: count_and_flush();
363: } else if ( dir == DIR_Y ) {
364: XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->height,0.05);
365: count_and_flush();
366: } else {
367: XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->nzstep,0.05);
368: flush();
369: }
1.5 noro 370: #endif
1.1 noro 371: }
372:
373: define_cursor(w,cur)
374: WINDOW w;
375: CURSOR cur;
376: {
1.5 noro 377: #if !defined(VISUAL)
1.1 noro 378: XDefineCursor(display,w,cur); flush();
1.5 noro 379: #endif
1.1 noro 380: }
381:
382: static int flush_count;
383: #if defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__)
384: #define MAX_COUNT 64
385: #else
386: #define MAX_COUNT 32
387: #endif
388:
389: count_and_flush() {
1.5 noro 390: #if !defined(VISUAL)
1.1 noro 391: if ( ++flush_count == MAX_COUNT )
392: flush();
1.5 noro 393: #endif
1.1 noro 394: }
395:
396: flush() {
1.5 noro 397: #if !defined(VISUAL)
1.1 noro 398: flush_count = 0;
399: XFlush(display);
1.5 noro 400: #endif
1.1 noro 401: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>