[BACK]Return to plotp.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / plot

Annotation of OpenXM_contrib2/asir2000/plot/plotp.c, Revision 1.17

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>