=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/plot/plotp.c,v retrieving revision 1.1 retrieving revision 1.11 diff -u -p -r1.1 -r1.11 --- OpenXM_contrib2/asir2000/plot/plotp.c 1999/12/03 07:39:13 1.1 +++ OpenXM_contrib2/asir2000/plot/plotp.c 2002/07/10 09:13:53 1.11 @@ -1,8 +1,57 @@ -/* $OpenXM: OpenXM/src/asir99/plot/plotp.c,v 1.1.1.1 1999/11/10 08:12:34 noro Exp $ */ +/* + * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED + * All rights reserved. + * + * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited, + * non-exclusive and royalty-free license to use, copy, modify and + * redistribute, solely for non-commercial and non-profit purposes, the + * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and + * conditions of this Agreement. For the avoidance of doubt, you acquire + * only a limited right to use the SOFTWARE hereunder, and FLL or any + * third party developer retains all rights, including but not limited to + * copyrights, in and to the SOFTWARE. + * + * (1) FLL does not grant you a license in any way for commercial + * purposes. You may use the SOFTWARE only for non-commercial and + * non-profit purposes only, such as academic, research and internal + * business use. + * (2) The SOFTWARE is protected by the Copyright Law of Japan and + * international copyright treaties. If you make copies of the SOFTWARE, + * with or without modification, as permitted hereunder, you shall affix + * to all such copies of the SOFTWARE the above copyright notice. + * (3) An explicit reference to this SOFTWARE and its copyright owner + * shall be made on your publication or presentation in any form of the + * results obtained by use of the SOFTWARE. + * (4) In the event that you modify the SOFTWARE, you shall notify FLL by + * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification + * for such modification or the source code of the modified part of the + * SOFTWARE. + * + * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL + * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND + * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES' + * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY + * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY. + * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT, + * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL + * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES + * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES + * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY + * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF + * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART + * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY + * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, + * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. + * + * $OpenXM: OpenXM_contrib2/asir2000/plot/plotp.c,v 1.10 2002/07/10 05:29:36 noro Exp $ +*/ #include "ca.h" #include "parse.h" #include "ox.h" #include "ifplot.h" +#include #if defined(sun) && !defined(__svr4__) #define EXP10(a) exp10(a) @@ -10,10 +59,11 @@ #define EXP10(a) pow(10.0,a) #endif -if_print(display,tab,can) -DISPLAY *display; -double **tab; -struct canvas *can; +#if defined(VISUAL) +static POINT oldpos; +#endif + +void if_print(DISPLAY *display,double **tab,struct canvas *can) { int ix,iy,width,height; double *px,*px1,*px2; @@ -35,11 +85,35 @@ struct canvas *can; flush(); } -con_print(display,tab,can) -DISPLAY *display; -double **tab; -struct canvas *can; +#define MEMORY_DRAWPOINT(a,len,x,y) (((a)[(len)*(y)+((x)>>3)]) |= (1<<((x)&7))) + +void memory_if_print(double **tab,struct canvas *can,BYTEARRAY *bytes) { + int ix,iy,width,height; + double *px,*px1,*px2; + unsigned char *array; + int scan_len; + + if ( can->mode == MODE_CONPLOT ) { + memory_con_print(tab,can,bytes); return; + } + width = can->width; height = can->height; + + /* scan_len = byte length of the scan line */ + scan_len = (width+7)/8; + MKBYTEARRAY(*bytes,scan_len*height); + array = BDY(*bytes); + for( ix=0; ix= 0) && ((*px1 <= 0) || (*px2 <= 0))) || + ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) { + MEMORY_DRAWPOINT(array,scan_len,ix,height-iy-1); + } +} + +void con_print(DISPLAY *display,double **tab,struct canvas *can) +{ int ix,iy,iz,width,height,pas,pai,len; double zstep,z; double *px,*px1,*px2; @@ -85,11 +159,54 @@ struct canvas *can; flush(); } -qif_print(display,tab,can) -DISPLAY *display; -char **tab; -struct canvas *can; +void memory_con_print(double **tab,struct canvas *can,BYTEARRAY *bytes) { + int ix,iy,iz,width,height,pas,pai,len; + double zstep,z; + double *px,*px1,*px2; + POINT *pa,*pa1; + struct pa *parray; + unsigned char *array; + int scan_len; + + width = can->width; height = can->height; + zstep = (can->zmax-can->zmin)/can->nzstep; + can->pa = (struct pa *)MALLOC((can->nzstep+1)*sizeof(struct pa)); + pas = width; + pa = (POINT *)ALLOCA(pas*sizeof(POINT)); + for ( z = can->zmin, iz = 0; z <= can->zmax; z += zstep, iz++ ) { + pai = 0; + for( ix=0; ix= z) && ((*px1 <= z) || (*px2 <= z))) || + ((*px <= z) && ((*px1 >= z) || (*px2 >= z))) ) { + if ( pai == pas ) { + pa1 = (POINT *)ALLOCA(2*pas*sizeof(POINT)); + bcopy((char *)pa,(char *)pa1,pas*sizeof(POINT)); pa = pa1; + pas += pas; + } + XC(pa[pai]) = ix; YC(pa[pai]) = height-iy-1; pai++; + } + can->pa[iz].length = pai; + if ( pai ) { + pa1 = (POINT *)MALLOC(pai*sizeof(POINT)); + bcopy((char *)pa,(char *)pa1,pai*sizeof(POINT)); + can->pa[iz].pos = pa1; + } + } + /* scan_len = byte length of the scan line */ + scan_len = (width+7)/8; + MKBYTEARRAY(*bytes,scan_len*height); + array = BDY(*bytes); + for ( parray = can->pa, iz = 0; iz <= can->nzstep; iz++, parray++ ) + for ( pa = parray->pos, len = parray->length, ix = 0; ix < len; ix++ ) { + MEMORY_DRAWPOINT(array,scan_len,XC(pa[ix]),YC(pa[ix])); + } +} + +void qif_print(DISPLAY *display,char **tab,struct canvas *can) +{ int ix,iy,width,height; char *px; DRAWABLE pix; @@ -105,72 +222,186 @@ struct canvas *can; flush(); } -plot_print(display,can) -DISPLAY *display; -struct canvas *can; +void plot_print(DISPLAY *display,struct canvas *can) { - int len,i; + int len; POINT *pa; - + +#if defined(VISUAL) + len = can->pa[0].length; + pa = can->pa[0].pos; + + Polyline(can->pix,pa,len); +// for ( i = 0; i < len-1; i++ ) { +// DRAWLINE(display,can->pix,drawGC,pa[i].x,pa[i].y,pa[i+1].x,pa[i+1].y); +// } +#else XDrawLines(display,can->pix,drawGC, can->pa[0].pos,can->pa[0].length,CoordModeOrigin); XFlush(display); +#endif } +void draw_point(DISPLAY *display,struct canvas *can,int x,int y,int color) +{ +#if defined(VISUAL) + HDC dc; + + SetPixel(can->pix,x,y,(COLORREF)color); + dc = GetDC(can->hwnd); + SetPixel(dc,x,y,(COLORREF)color); + ReleaseDC(can->hwnd,dc); +#else + if ( color ) { + set_drawcolor(color); + DRAWPOINT(display,can->pix,cdrawGC,x,y); + DRAWPOINT(display,can->window,cdrawGC,x,y); + } else { + DRAWPOINT(display,can->pix,drawGC,x,y); + DRAWPOINT(display,can->window,drawGC,x,y); + } + XFlush(display); +#endif +} + +void draw_line(DISPLAY *display,struct canvas *can,int x,int y,int u,int v,int color) +{ +#if defined(VISUAL) + HDC dc; + HPEN pen,oldpen; + + if ( color ) { + pen = CreatePen(PS_SOLID,1,color); + oldpen = SelectObject(can->pix,pen); + DRAWLINE(display,can->pix,drawGC,x,y,u,v); + SelectObject(can->pix,oldpen); + + dc = GetDC(can->hwnd); + oldpen = SelectObject(dc,pen); + DRAWLINE(display,dc,drawGC,x,y,u,v); + SelectObject(dc,oldpen); + ReleaseDC(can->hwnd,dc); + + DeleteObject(pen); + } else { + DRAWLINE(display,can->pix,drawGC,x,y,u,v); + dc = GetDC(can->hwnd); + DRAWLINE(display,dc,drawGC,x,y,u,v); + ReleaseDC(can->hwnd,dc); + } +#else + if ( color ) { + set_drawcolor(color); + DRAWLINE(display,can->pix,cdrawGC,x,y,u,v); + DRAWLINE(display,can->window,cdrawGC,x,y,u,v); + } else { + DRAWLINE(display,can->pix,drawGC,x,y,u,v); + DRAWLINE(display,can->window,drawGC,x,y,u,v); + } + XFlush(display); +#endif +} + +void draw_character_string(DISPLAY *display,struct canvas *can,int x,int y,char *str,int color) +{ +#if defined(VISUAL) + HDC dc; + COLORREF oldcolor; + + if ( color ) { + oldcolor = SetTextColor(can->pix,color); + DRAWSTRING(display,can->pix,drawGC,x,y,str,strlen(str)); + SetTextColor(can->pix,oldcolor); + + dc = GetDC(can->hwnd); + oldcolor = SetTextColor(dc,color); + DRAWSTRING(display,dc,drawGC,x,y,str,strlen(str)); + SetTextColor(dc,oldcolor); + ReleaseDC(can->hwnd,dc); + } else { + DRAWSTRING(display,can->pix,drawGC,x,y,str,strlen(str)); + dc = GetDC(can->hwnd); + DRAWSTRING(display,dc,drawGC,x,y,str,strlen(str)); + ReleaseDC(can->hwnd,dc); + } +#else + if ( color ) { + set_drawcolor(color); + DRAWSTRING(display,can->pix,cdrawGC,x,y,str,strlen(str)); + DRAWSTRING(display,can->window,cdrawGC,x,y,str,strlen(str)); + } else { + DRAWSTRING(display,can->pix,drawGC,x,y,str,strlen(str)); + DRAWSTRING(display,can->window,drawGC,x,y,str,strlen(str)); + } + XFlush(display); +#endif +} + #define D 5 -pline(display,can,d) -DISPLAY *display; -struct canvas *can; -DRAWABLE d; +void pline(DISPLAY *display,struct canvas *can,DRAWABLE d) { - double w,w1,k,e,n; + double w,w1,e,n; int x0,y0,x,y,xadj,yadj; char buf[BUFSIZ]; double adjust_scale(); - if ( can->noaxis ) + /* XXX : should be cleaned up */ + if ( can->noaxis || (can->mode == MODE_PLOT && !can->pa) ) return; + if ( can->mode == MODE_INTERACTIVE ) + return; xadj = yadj = 0; if ( (can->xmin < 0) && (can->xmax > 0) ) { - x0 = (int)((can->width-1)*(-can->xmin/(can->xmax-can->xmin))); + x0 = (int)((can->width)*(-can->xmin/(can->xmax-can->xmin))); DRAWLINE(display,d,dashGC,x0,0,x0,can->height); } else if ( can->xmin >= 0 ) x0 = 0; else - x0 = can->width-1-D; + x0 = can->width-D; if ( (can->ymin < 0) && (can->ymax > 0) ) { - y0 = (int)((can->height-1)*(can->ymax/(can->ymax-can->ymin))); + y0 = (int)((can->height)*(can->ymax/(can->ymax-can->ymin))); DRAWLINE(display,d,dashGC,0,y0,can->width,y0); } else if ( can->ymin >= 0 ) - y0 = can->height-1; + y0 = can->height; else y0 = D; + + /* scale on x-axis */ w = can->xmax-can->xmin; w1 = w * DEFAULTWIDTH/can->width; e = adjust_scale(EXP10(floor(log10(w1))),w1); for ( n = ceil(can->xmin/e); n*e<= can->xmax; n++ ) { - x = (int)can->width*(n*e-can->xmin)/w; + x = (int)(can->width*(n*e-can->xmin)/w); DRAWLINE(display,d,drawGC,x,y0,x,y0-D); sprintf(buf,"%g",n*e); - DRAWSTRING(display,d,scaleGC,x+2,y0,buf,strlen(buf)); + DRAWSTRING(display,d,scaleGC,x+2,y0+2,buf,strlen(buf)); } + + /* scale on y-axis */ w = can->ymax-can->ymin; w1 = w * DEFAULTHEIGHT/can->height; e = adjust_scale(EXP10(floor(log10(w1))),w1); for ( n = ceil(can->ymin/e); n*e<= can->ymax; n++ ) { - y = (int)can->height*(1-(n*e-can->ymin)/w); + y = (int)(can->height*(1-(n*e-can->ymin)/w)); DRAWLINE(display,d,drawGC,x0,y,x0+D,y); sprintf(buf,"%g",n*e); - if ( can->xmax <= 0 ) + if ( can->xmax <= 0 ) { +#if !defined(VISUAL) xadj = TEXTWIDTH(sffs,buf,strlen(buf)); - DRAWSTRING(display,d,scaleGC,x0-xadj,y,buf,strlen(buf)); +#else + SIZE size; + + GetTextExtentPoint32(d,buf,strlen(buf),&size); + xadj = size.cx; +#endif + } + DRAWSTRING(display,d,scaleGC,x0+2-xadj,y+2,buf,strlen(buf)); } } -double adjust_scale(e,w) -double e,w; +double adjust_scale(double e,double w) { switch ( (int)floor(w/e) ) { case 1: @@ -185,19 +416,28 @@ double e,w; } } -initmarker(can,message) -struct canvas *can; -char *message; +void initmarker(struct canvas *can,char *message) { +#if defined(VISUAL) + can->real_can->percentage = 0; + can->real_can->prefix = message; +#else XawScrollbarSetThumb(can->xdone,0.0,0.0); XawScrollbarSetThumb(can->ydone,1.0,0.0); XFlush(display); +#endif } -marker(can,dir,p) -struct canvas *can; -int dir,p; +void marker(struct canvas *can,int dir,int p) { +#if defined(VISUAL) + if ( dir == DIR_X ) + can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->width*100); + else if ( dir == DIR_Y ) + can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->height*100); + else + can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->nzstep*100); +#else if ( dir == DIR_X ) { XawScrollbarSetThumb(can->xdone,(float)p/(float)can->width,0.05); count_and_flush(); @@ -208,13 +448,14 @@ int dir,p; XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->nzstep,0.05); flush(); } +#endif } -define_cursor(w,cur) -WINDOW w; -CURSOR cur; +void define_cursor(WINDOW w,CURSOR cur) { +#if !defined(VISUAL) XDefineCursor(display,w,cur); flush(); +#endif } static int flush_count; @@ -224,12 +465,16 @@ static int flush_count; #define MAX_COUNT 32 #endif -count_and_flush() { +void count_and_flush() { +#if !defined(VISUAL) if ( ++flush_count == MAX_COUNT ) flush(); +#endif } -flush() { +void flush() { +#if !defined(VISUAL) flush_count = 0; XFlush(display); +#endif }