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

Annotation of OpenXM_contrib2/asir2000/plot/if.c, Revision 1.3

1.2       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.3     ! noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2       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.3     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/plot/if.c,v 1.2 2000/08/21 08:31:50 noro Exp $
1.2       noro       49: */
1.1       noro       50: #include "ca.h"
                     51: #include "parse.h"
                     52: #include "ox.h"
                     53: #include "ifplot.h"
                     54:
                     55: extern jmp_buf ox_env;
                     56:
                     57: int plot(NODE arg)
                     58: {
                     59:        int id;
                     60:        NODE n;
                     61:        struct canvas *can;
                     62:        P formula;
                     63:        LIST xrange,yrange,zrange,wsize;
                     64:        STRING wname;
                     65:
                     66:        formula = (P)ARG0(arg);
                     67:        xrange = (LIST)ARG1(arg);
                     68:        yrange = (LIST)ARG2(arg);
                     69:        zrange = (LIST)ARG3(arg);
                     70:        wsize = (LIST)ARG4(arg);
                     71:        wname = (STRING)ARG5(arg);
                     72:
                     73:        can = canvas[id = search_canvas()];
                     74:        n = BDY(xrange); can->vx = VR((P)BDY(n)); n = NEXT(n);
                     75:        can->qxmin = (Q)BDY(n); n = NEXT(n); can->qxmax = (Q)BDY(n);
                     76:        can->xmin = ToReal(can->qxmin); can->xmax = ToReal(can->qxmax);
                     77:        if ( yrange ) {
                     78:                n = BDY(yrange); can->vy = VR((P)BDY(n)); n = NEXT(n);
                     79:                can->qymin = (Q)BDY(n); n = NEXT(n); can->qymax = (Q)BDY(n);
                     80:                can->ymin = ToReal(can->qymin); can->ymax = ToReal(can->qymax);
                     81:                if ( zrange ) {
                     82:                        n = NEXT(BDY(zrange));
                     83:                        can->zmin = ToReal(BDY(n)); n = NEXT(n); can->zmax = ToReal(BDY(n));
                     84:                        if ( n = NEXT(n) )
                     85:                                can->nzstep = QTOS((Q)BDY(n));
                     86:                        else
                     87:                                can->nzstep = MAXGC;
                     88:                        can->mode = MODE_CONPLOT;
                     89:                } else
                     90:                        can->mode = MODE_IFPLOT;
                     91:        } else
                     92:                can->mode = MODE_PLOT;
                     93:        if ( !wsize ) {
                     94:                can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
                     95:        } else {
                     96:                can->width = QTOS((Q)BDY(BDY(wsize)));
                     97:                can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
                     98:        }
                     99:        if ( wname )
                    100:                can->wname = BDY(wname);
                    101:        else
                    102:                can->wname = "";
                    103:        can->formula = formula;
                    104:        create_canvas(can);
                    105:        if ( can->mode == MODE_PLOT ) {
                    106:                plotcalc(can);
                    107:                plot_print(display,can);
                    108:        } else
                    109:                ifplotmain(can);
                    110:        copy_to_canvas(can);
                    111:        return id;
                    112: }
                    113:
                    114: int plotover(NODE arg)
                    115: {
                    116:        int index;
                    117:        P formula;
                    118:        struct canvas *can;
                    119:        struct canvas fakecan;
                    120:        VL vl,vl0;
                    121:
                    122:        index = QTOS((Q)ARG0(arg));
                    123:        formula = (P)ARG1(arg);
                    124:        can = canvas[index];
                    125:        if ( !can->window )
                    126:                return -1;
                    127:        get_vars_recursive(formula,&vl);
                    128:        for ( vl0 = vl; vl0; vl0 = NEXT(vl0) )
                    129:                if ( vl0->v->attr == V_IND )
                    130:                        if ( vl->v != can->vx && vl->v != can->vy )
                    131:                                return -1;
                    132:        current_can = can;
                    133:        fakecan = *can; fakecan.formula = formula;
                    134:        if ( can->mode == MODE_PLOT ) {
                    135:                plotcalc(&fakecan);
                    136:                plot_print(display,&fakecan);
                    137:        } else
                    138:                ifplotmain(&fakecan);
                    139:        copy_to_canvas(&fakecan);
                    140:        return index;
                    141: }
                    142:
                    143: int drawcircle(NODE arg)
                    144: {
                    145:        int id;
                    146:        int index;
                    147:        pointer ptr;
                    148:        Q ret;
                    149:        LIST xyr;
                    150:        Obj x,y,r;
                    151:        int wx,wy,wr;
                    152:        struct canvas *can;
                    153:        struct canvas fakecan;
                    154:
                    155:        index = QTOS((Q)ARG0(arg));
                    156:        xyr = (LIST)ARG1(arg);
                    157:        x = (Obj)ARG0(BDY(xyr)); y = (Obj)ARG1(BDY(xyr)); r = (Obj)ARG2(BDY(xyr));
                    158:        can = canvas[index];
                    159:        if ( !can->window )
                    160:                return -1;
                    161:        else {
                    162:                current_can = can;
                    163:                wx = (ToReal(x)-can->xmin)*can->width/(can->xmax-can->xmin);
                    164:                wy = (can->ymax-ToReal(y))*can->height/(can->ymax-can->ymin);
                    165:                wr = ToReal(r);
                    166:                XFillArc(display,can->pix,colorGC,wx-wr/2,wy-wr/2,wr,wr,0,360*64);
                    167:                copy_to_canvas(can);
                    168:                return index;
                    169:        }
                    170: }
                    171:
                    172: #define RealtoDbl(r) ((r)?BDY(r):0.0)
                    173:
                    174: int arrayplot(NODE arg)
                    175: {
                    176:        int id,ix,w,h;
                    177:        VECT array;
                    178:        LIST xrange,wsize;
                    179:        char *wname;
                    180:        NODE n;
                    181:        Q ret;
                    182:        double ymax,ymin,dy,xstep;
                    183:        Real *tab;
                    184:        struct canvas *can;
                    185:        POINT *pa;
                    186:
                    187:        array = (VECT)ARG0(arg);
                    188:        xrange = (LIST)ARG1(arg);
                    189:        can = canvas[id = search_canvas()];
                    190:        n = BDY(xrange); can->vx = VR((P)BDY(n)); n = NEXT(n);
                    191:        can->qxmin = (Q)BDY(n); n = NEXT(n); can->qxmax = (Q)BDY(n);
                    192:        can->xmin = ToReal(can->qxmin); can->xmax = ToReal(can->qxmax);
                    193:        if ( !wsize ) {
                    194:                can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
                    195:        } else {
                    196:                can->width = QTOS((Q)BDY(BDY(wsize)));
                    197:                can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
                    198:        }
                    199:        can->wname = wname; can->formula = 0; can->mode = MODE_PLOT;
                    200:        create_canvas(can);
                    201:        w = array->len;
                    202:        h = can->height;
                    203:        tab = (Real *)BDY(array);
                    204:        if ( can->ymax == can->ymin ) {
                    205:                for ( ymax = ymin = RealtoDbl(tab[0]), ix = 1; ix < w; ix++ ) {
                    206:                        if ( RealtoDbl(tab[ix]) > ymax )
                    207:                                ymax = RealtoDbl(tab[ix]);
                    208:                        if ( RealtoDbl(tab[ix]) < ymin )
                    209:                                ymin = RealtoDbl(tab[ix]);
                    210:                }
                    211:                can->ymax = ymax; can->ymin = ymin;
                    212:        } else {
                    213:                ymax = can->ymax; ymin = can->ymin;
                    214:        }
                    215:        dy = ymax-ymin;
                    216:        can->pa = (struct pa *)MALLOC(sizeof(struct pa));
                    217:        can->pa[0].length = w;
                    218:        can->pa[0].pos = pa = (POINT *)MALLOC(w*sizeof(POINT));
                    219:        xstep = (double)can->width/(double)(w-1);
                    220:        for ( ix = 0; ix < w; ix++ ) {
                    221: #ifndef MAXSHORT
                    222: #define MAXSHORT ((short)0x7fff)
                    223: #endif
                    224:                double t;
                    225:
                    226:                pa[ix].x = (int)(ix*xstep);
                    227:                t = (h - 1)*(ymax - RealtoDbl(tab[ix]))/dy;
                    228:                if ( t > MAXSHORT )
                    229:                        pa[ix].y = MAXSHORT;
                    230:                else if ( t < -MAXSHORT )
                    231:                        pa[ix].y = -MAXSHORT;
                    232:                else
                    233:                        pa[ix].y = t;
                    234:        }
                    235:        plot_print(display,can);
                    236:        copy_to_canvas(can);
                    237:        return id;
                    238: }
                    239:
                    240: ifplot_resize(can,spos,epos)
                    241: struct canvas *can;
                    242: POINT spos,epos;
                    243: {
                    244:        struct canvas *ncan;
                    245:        struct canvas fakecan;
                    246:        Q dx,dy,dx2,dy2,xmin,xmax,ymin,ymax,xmid,ymid;
                    247:        Q sx,sy,ex,ey,cw,ch,ten,two;
                    248:        Q s,t;
                    249:        int new;
                    250:        int w,h,m;
                    251:        Q ret;
                    252:
                    253:        if ( XC(spos) < XC(epos) && YC(spos) < YC(epos) ) {
                    254:                if ( can->precise && !can->wide ) {
                    255:                        fakecan = *can; ncan = &fakecan;
                    256:                } else {
                    257:                        new = search_canvas(); ncan = canvas[new];
                    258:                }
                    259:                ncan->mode = can->mode;
                    260:                ncan->zmin = can->zmin; ncan->zmax = can->zmax;
                    261:                ncan->nzstep = can->nzstep;
                    262:                ncan->wname = can->wname;
                    263:                ncan->vx = can->vx; ncan->vy = can->vy;
                    264:                ncan->formula = can->formula;
                    265:                w = XC(epos)-XC(spos);
                    266:                h = YC(epos)-YC(spos);
                    267:                m = MAX(can->width,can->height);
                    268:                if ( can->precise ) {
                    269:                        ncan->width = w; ncan->height = h;
                    270:                } else if ( w > h ) {
                    271:                        ncan->width = m; ncan->height = m * h/w;
                    272:                } else {
                    273:                        ncan->width = m * w/h; ncan->height = m;
                    274:                }
                    275:                if ( can->wide ) {
                    276:                        STOQ(10,ten); STOQ(2,two);
                    277:                        subq(can->qxmax,can->qxmin,&t); mulq(t,ten,&dx);
                    278:                        subq(can->qymax,can->qymin,&t); mulq(t,ten,&dy);
                    279:                        addq(can->qxmax,can->qxmin,&t); divq(t,two,&xmid);
                    280:                        addq(can->qymax,can->qymin,&t); divq(t,two,&ymid);
                    281:                        divq(dx,two,&dx2); divq(dy,two,&dy2);
                    282:                        subq(xmid,dx2,&xmin); addq(xmid,dx2,&xmax);
                    283:                        subq(ymid,dy2,&ymin); addq(ymid,dy2,&ymax);
                    284:                } else {
                    285:                        subq(can->qxmax,can->qxmin,&dx); subq(can->qymax,can->qymin,&dy);
                    286:                        xmin = can->qxmin; xmax = can->qxmax;
                    287:                        ymin = can->qymin; ymax = can->qymax;
                    288:                }
                    289:                STOQ(XC(spos),sx); STOQ(YC(spos),sy); STOQ(XC(epos),ex); STOQ(YC(epos),ey);
                    290:                STOQ(can->width,cw); STOQ(can->height,ch);
                    291:                mulq(sx,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmin);
                    292:                mulq(ex,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmax);
                    293:                mulq(ey,dy,&t); divq(t,ch,&s); subq(ymax,s,&ncan->qymin);
                    294:                mulq(sy,dy,&t); divq(t,ch,&s); subq(ymax,s,&ncan->qymax);
                    295:                ncan->xmin = ToReal(ncan->qxmin); ncan->xmax = ToReal(ncan->qxmax);
                    296:                ncan->ymin = ToReal(ncan->qymin); ncan->ymax = ToReal(ncan->qymax);
                    297:                if ( can->precise && !can->wide ) {
                    298:                        current_can = can;
                    299:                        alloc_pixmap(ncan);
                    300:                        qifplotmain(ncan);
                    301:                        copy_subimage(ncan,can,spos);
                    302:                        copy_to_canvas(can);
                    303:                } else {
                    304:                        create_canvas(ncan);
                    305:                        if ( can->precise )
                    306:                                qifplotmain(ncan);
                    307:                        else
                    308:                                ifplotmain(ncan);
                    309:                        copy_to_canvas(ncan);
                    310:                }
                    311:        }
                    312: }
                    313:
                    314: plot_resize(can,spos,epos)
                    315: struct canvas *can;
                    316: POINT spos,epos;
                    317: {
                    318:        struct canvas *ncan;
                    319:        Q dx,dx2,xmin,xmax,xmid;
                    320:        double dy,dy2,ymin,ymax,ymid;
                    321:        Q sx,ex,cw,ten,two;
                    322:        double sy,ey;
                    323:        Q s,t;
                    324:        int new;
                    325:        int w,h,m;
                    326:
                    327:        if ( XC(spos) < XC(epos) && YC(spos) < YC(epos) ) {
                    328:                new = search_canvas(); ncan = canvas[new];
                    329:                ncan->mode = can->mode;
                    330:                ncan->zmin = can->zmin; ncan->zmax = can->zmax;
                    331:                ncan->nzstep = can->nzstep;
                    332:                ncan->wname = can->wname;
                    333:                ncan->vx = can->vx; ncan->vy = can->vy;
                    334:                ncan->formula = can->formula;
                    335:                w = XC(epos)-XC(spos);
                    336:                h = YC(epos)-YC(spos);
                    337:                m = MAX(can->width,can->height);
                    338:                if ( w > h ) {
                    339:                        ncan->width = m; ncan->height = m * h/w;
                    340:                } else {
                    341:                        ncan->width = m * w/h; ncan->height = m;
                    342:                }
                    343:                if ( can->wide ) {
                    344:                        STOQ(10,ten); STOQ(2,two);
                    345:                        subq(can->qxmax,can->qxmin,&t); mulq(t,ten,&dx);
                    346:                        addq(can->qxmax,can->qxmin,&t); divq(t,two,&xmid);
                    347:                        divq(dx,two,&dx2); subq(xmid,dx2,&xmin); addq(xmid,dx2,&xmax);
                    348:
                    349:                        dy = (can->ymax-can->ymin)*10;
                    350:                        ymid = (can->ymax+can->ymin)/2;
                    351:                        ymin = ymid-dy/2; ymax = ymid+dy/2;
                    352:                } else {
                    353:                        subq(can->qxmax,can->qxmin,&dx);
                    354:                        xmin = can->qxmin; xmax = can->qxmax;
                    355:
                    356:                        dy = can->ymax-can->ymin;
                    357:                        ymin = can->ymin; ymax = can->ymax;
                    358:                }
                    359:                STOQ(XC(spos),sx); STOQ(XC(epos),ex); STOQ(can->width,cw);
                    360:                mulq(sx,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmin);
                    361:                mulq(ex,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmax);
                    362:                ncan->xmin = ToReal(ncan->qxmin); ncan->xmax = ToReal(ncan->qxmax);
                    363:
                    364:                ncan->ymin = ymax-YC(epos)*dy/can->height;
                    365:                ncan->ymax = ymax-YC(spos)*dy/can->height;
                    366:
                    367:                create_canvas(ncan);
                    368:                plotcalc(ncan);
                    369:                plot_print(display,ncan);
                    370:                copy_to_canvas(ncan);
                    371:        }
                    372: }
                    373:
                    374: ifplotmain(can)
                    375: struct canvas *can;
                    376: {
                    377:        int width,height;
                    378:        double **tabe,*tabeb;
                    379:        int i;
                    380:
                    381:        width = can->width; height = can->height;
                    382:        tabe = (double **)ALLOCA(width*sizeof(double *));
                    383:        for ( i = 0; i < width; i++ )
                    384:                tabe[i] = (double *)ALLOCA(height*sizeof(double));
                    385:        define_cursor(can->window,runningcur);
                    386:        set_busy(can); set_selection();
                    387:        calc(tabe,can); if_print(display,tabe,can);
                    388:        reset_selection(); reset_busy(can);
                    389:        define_cursor(can->window,normalcur);
                    390: }
                    391:
                    392: qifplotmain(can)
                    393: struct canvas *can;
                    394: {
                    395:        int width,height;
                    396:        char **tabe,*tabeb;
                    397:        int i;
                    398:
                    399:        width = can->width; height = can->height;
                    400:        tabe = (char **)ALLOCA(width*sizeof(char *)+width*height*sizeof(char));
                    401:        bzero(tabe,width*sizeof(char *)+width*height*sizeof(char));
                    402:        for ( i = 0, tabeb = (char *)(tabe+width); i < width; i++ )
                    403:                tabe[i] = tabeb + height*i;
                    404:        define_cursor(can->window,runningcur);
                    405:        set_busy(can); set_selection();
                    406:        qcalc(tabe,can); qif_print(display,tabe,can);
                    407:        reset_selection(); reset_busy(can);
                    408:        define_cursor(can->window,normalcur);
                    409: }

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