[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.9

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.9     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/plot/if.c,v 1.8 2001/12/25 02:39:07 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:
1.8       noro       55: extern JMP_BUF ox_env;
1.1       noro       56:
1.4       noro       57: int open_canvas(NODE arg)
                     58: {
                     59:        int id;
                     60:        struct canvas *can;
                     61:        LIST wsize;
                     62:        STRING wname;
                     63:
                     64:        wsize = (LIST)ARG0(arg);
                     65:        wname = (STRING)ARG1(arg);
                     66:
                     67:        can = canvas[id = search_canvas()];
                     68:        can->mode = MODE_INTERACTIVE;
                     69:        if ( !wsize ) {
                     70:                can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
                     71:        } else {
                     72:                can->width = QTOS((Q)BDY(BDY(wsize)));
                     73:                can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
                     74:        }
                     75:        if ( wname )
                     76:                can->wname = BDY(wname);
                     77:        else
                     78:                can->wname = "";
                     79:        create_canvas(can);
                     80:        return id;
                     81: }
                     82:
1.1       noro       83: int plot(NODE arg)
                     84: {
                     85:        int id;
                     86:        NODE n;
                     87:        struct canvas *can;
                     88:        P formula;
                     89:        LIST xrange,yrange,zrange,wsize;
                     90:        STRING wname;
                     91:
                     92:        formula = (P)ARG0(arg);
                     93:        xrange = (LIST)ARG1(arg);
                     94:        yrange = (LIST)ARG2(arg);
                     95:        zrange = (LIST)ARG3(arg);
                     96:        wsize = (LIST)ARG4(arg);
                     97:        wname = (STRING)ARG5(arg);
                     98:
                     99:        can = canvas[id = search_canvas()];
                    100:        n = BDY(xrange); can->vx = VR((P)BDY(n)); n = NEXT(n);
                    101:        can->qxmin = (Q)BDY(n); n = NEXT(n); can->qxmax = (Q)BDY(n);
                    102:        can->xmin = ToReal(can->qxmin); can->xmax = ToReal(can->qxmax);
                    103:        if ( yrange ) {
                    104:                n = BDY(yrange); can->vy = VR((P)BDY(n)); n = NEXT(n);
                    105:                can->qymin = (Q)BDY(n); n = NEXT(n); can->qymax = (Q)BDY(n);
                    106:                can->ymin = ToReal(can->qymin); can->ymax = ToReal(can->qymax);
                    107:                if ( zrange ) {
                    108:                        n = NEXT(BDY(zrange));
                    109:                        can->zmin = ToReal(BDY(n)); n = NEXT(n); can->zmax = ToReal(BDY(n));
                    110:                        if ( n = NEXT(n) )
                    111:                                can->nzstep = QTOS((Q)BDY(n));
                    112:                        else
                    113:                                can->nzstep = MAXGC;
                    114:                        can->mode = MODE_CONPLOT;
                    115:                } else
                    116:                        can->mode = MODE_IFPLOT;
                    117:        } else
                    118:                can->mode = MODE_PLOT;
                    119:        if ( !wsize ) {
                    120:                can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
                    121:        } else {
                    122:                can->width = QTOS((Q)BDY(BDY(wsize)));
                    123:                can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
                    124:        }
                    125:        if ( wname )
                    126:                can->wname = BDY(wname);
                    127:        else
                    128:                can->wname = "";
                    129:        can->formula = formula;
                    130:        create_canvas(can);
                    131:        if ( can->mode == MODE_PLOT ) {
                    132:                plotcalc(can);
                    133:                plot_print(display,can);
                    134:        } else
                    135:                ifplotmain(can);
                    136:        copy_to_canvas(can);
                    137:        return id;
                    138: }
                    139:
1.6       noro      140: int memory_plot(NODE arg,LIST *bytes)
                    141: {
                    142:        NODE n;
                    143:        struct canvas tmp_can;
                    144:        struct canvas *can;
                    145:        P formula;
                    146:        LIST xrange,yrange,zrange,wsize;
                    147:        int width,height;
                    148:        double **tabe;
                    149:        int i;
                    150:        BYTEARRAY barray;
                    151:        Q qw,qh;
                    152:
                    153:        formula = (P)ARG0(arg);
                    154:        xrange = (LIST)ARG1(arg);
                    155:        yrange = (LIST)ARG2(arg);
                    156:        zrange = (LIST)ARG3(arg);
                    157:        wsize = (LIST)ARG4(arg);
                    158:
                    159:        can = &tmp_can;
                    160:        n = BDY(xrange); can->vx = VR((P)BDY(n)); n = NEXT(n);
                    161:        can->qxmin = (Q)BDY(n); n = NEXT(n); can->qxmax = (Q)BDY(n);
                    162:        can->xmin = ToReal(can->qxmin); can->xmax = ToReal(can->qxmax);
                    163:        if ( yrange ) {
                    164:                n = BDY(yrange); can->vy = VR((P)BDY(n)); n = NEXT(n);
                    165:                can->qymin = (Q)BDY(n); n = NEXT(n); can->qymax = (Q)BDY(n);
                    166:                can->ymin = ToReal(can->qymin); can->ymax = ToReal(can->qymax);
                    167:                if ( zrange ) {
                    168:                        n = NEXT(BDY(zrange));
                    169:                        can->zmin = ToReal(BDY(n)); n = NEXT(n); can->zmax = ToReal(BDY(n));
                    170:                        if ( n = NEXT(n) )
                    171:                                can->nzstep = QTOS((Q)BDY(n));
                    172:                        else
                    173:                                can->nzstep = MAXGC;
                    174:                        can->mode = MODE_CONPLOT;
                    175:                } else
                    176:                        can->mode = MODE_IFPLOT;
                    177:        } else
                    178:                can->mode = MODE_PLOT;
                    179:        if ( !wsize ) {
                    180:                can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
                    181:        } else {
                    182:                can->width = QTOS((Q)BDY(BDY(wsize)));
                    183:                can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
                    184:        }
                    185:        can->wname = "";
                    186:        can->formula = formula;
                    187:        if ( can->mode == MODE_PLOT )
                    188:                plotcalc(can);
                    189:        else {
                    190:                width = can->width; height = can->height;
                    191:                tabe = (double **)ALLOCA(width*sizeof(double *));
                    192:                for ( i = 0; i < width; i++ )
                    193:                        tabe[i] = (double *)ALLOCA(height*sizeof(double));
                    194:                calc(tabe,can,1);
                    195:                memory_if_print(tabe,can,&barray);
                    196:                STOQ(width,qw); STOQ(height,qh);
                    197:                n = mknode(3,qw,qh,barray);
                    198:                MKLIST(*bytes,n);
                    199:        }
                    200: }
                    201:
1.1       noro      202: int plotover(NODE arg)
                    203: {
                    204:        int index;
                    205:        P formula;
                    206:        struct canvas *can;
                    207:        struct canvas fakecan;
                    208:        VL vl,vl0;
                    209:
                    210:        index = QTOS((Q)ARG0(arg));
                    211:        formula = (P)ARG1(arg);
                    212:        can = canvas[index];
                    213:        if ( !can->window )
                    214:                return -1;
1.7       noro      215:        get_vars_recursive((Obj)formula,&vl);
1.1       noro      216:        for ( vl0 = vl; vl0; vl0 = NEXT(vl0) )
1.7       noro      217:                if ( vl0->v->attr == (pointer)V_IND )
1.1       noro      218:                        if ( vl->v != can->vx && vl->v != can->vy )
                    219:                                return -1;
                    220:        current_can = can;
                    221:        fakecan = *can; fakecan.formula = formula;
                    222:        if ( can->mode == MODE_PLOT ) {
                    223:                plotcalc(&fakecan);
                    224:                plot_print(display,&fakecan);
                    225:        } else
                    226:                ifplotmain(&fakecan);
                    227:        copy_to_canvas(&fakecan);
                    228:        return index;
                    229: }
                    230:
                    231: int drawcircle(NODE arg)
                    232: {
1.4       noro      233: #if !defined(VISUAL)
1.1       noro      234:        int id;
                    235:        int index;
                    236:        pointer ptr;
                    237:        Q ret;
                    238:        LIST xyr;
                    239:        Obj x,y,r;
                    240:        int wx,wy,wr;
                    241:        struct canvas *can;
                    242:        struct canvas fakecan;
                    243:
                    244:        index = QTOS((Q)ARG0(arg));
                    245:        xyr = (LIST)ARG1(arg);
                    246:        x = (Obj)ARG0(BDY(xyr)); y = (Obj)ARG1(BDY(xyr)); r = (Obj)ARG2(BDY(xyr));
                    247:        can = canvas[index];
                    248:        if ( !can->window )
                    249:                return -1;
                    250:        else {
                    251:                current_can = can;
                    252:                wx = (ToReal(x)-can->xmin)*can->width/(can->xmax-can->xmin);
                    253:                wy = (can->ymax-ToReal(y))*can->height/(can->ymax-can->ymin);
                    254:                wr = ToReal(r);
                    255:                XFillArc(display,can->pix,colorGC,wx-wr/2,wy-wr/2,wr,wr,0,360*64);
                    256:                copy_to_canvas(can);
                    257:                return index;
                    258:        }
1.4       noro      259: #endif
                    260: }
                    261:
                    262: int draw_obj(NODE arg)
                    263: {
                    264:        int index;
1.5       noro      265:        int x,y,u,v,len,r;
1.4       noro      266:        NODE obj,n;
                    267:        RealVect *vect;
                    268:        struct canvas *can;
1.5       noro      269:        int color;
1.4       noro      270:
                    271:        index = QTOS((Q)ARG0(arg));
                    272:        can = canvas[index];
1.5       noro      273:        if ( !can || !can->window ) {
                    274:                set_lasterror("draw_obj : canvas does not exist");
1.4       noro      275:                return -1;
1.5       noro      276:        }
1.4       noro      277:
                    278:        obj = BDY((LIST)ARG1(arg));
1.5       noro      279:        if ( argc(arg) == 3 )
                    280:                color = QTOS((Q)ARG2(arg));
                    281:        else
                    282:                color = 0; /* black */
                    283:        switch ( len = length(obj) ) {
1.4       noro      284:                case 2: /* point */
                    285:                        x = (int)ToReal((Q)ARG0(obj)); y = (int)ToReal((Q)ARG1(obj));
1.5       noro      286:                        draw_point(display,can,x,y,color);
                    287:                        MKRVECT2(vect,x,y); MKNODE(n,vect,can->history); can->history = n;
                    288:                        break;
                    289:                case 3: /* circle */
                    290:                        x = (int)ToReal((Q)ARG0(obj)); y = (int)ToReal((Q)ARG1(obj));
                    291:                        r = (int)ToReal((Q)ARG2(obj));
                    292:                        MKRVECT3(vect,x,y,r); MKNODE(n,vect,can->history); can->history = n;
1.4       noro      293:                        break;
                    294:                case 4: /* line */
                    295:                        x = (int)ToReal((Q)ARG0(obj)); y = (int)ToReal((Q)ARG1(obj));
                    296:                        u = (int)ToReal((Q)ARG2(obj)); v = (int)ToReal((Q)ARG3(obj));
1.5       noro      297:                        draw_line(display,can,x,y,u,v,color);
1.4       noro      298:                        MKRVECT4(vect,x,y,u,v); MKNODE(n,vect,can->history); can->history = n;
                    299:                        break;
                    300:                default:
1.5       noro      301:                        set_lasterror("draw_obj : invalid request");
1.4       noro      302:                        return -1;
                    303:        }
1.9     ! noro      304:        return 0;
        !           305: }
        !           306:
        !           307: int draw_string(NODE arg)
        !           308: {
        !           309:        int index,x,y;
        !           310:        char *str;
        !           311:        NODE pos;
        !           312:        struct canvas *can;
        !           313:        int color;
        !           314:
        !           315:        index = QTOS((Q)ARG0(arg));
        !           316:        can = canvas[index];
        !           317:        if ( !can || !can->window ) {
        !           318:                set_lasterror("draw_string : canvas does not exist");
        !           319:                return -1;
        !           320:        }
        !           321:
        !           322:        pos = BDY((LIST)ARG1(arg));
        !           323:        str = BDY((STRING)ARG2(arg));
        !           324:        if ( argc(arg) == 4 )
        !           325:                color = QTOS((Q)ARG3(arg));
        !           326:        else
        !           327:                color = 0; /* black */
        !           328:        x = (int)ToReal((Q)ARG0(pos));
        !           329:        y = (int)ToReal((Q)ARG1(pos));
        !           330:        draw_character_string(display,can,x,y,str,color);
1.4       noro      331:        return 0;
                    332: }
                    333:
                    334: int clear_canvas(NODE arg)
                    335: {
                    336:        int index;
                    337:        struct canvas *can;
                    338:
                    339:        index = QTOS((Q)ARG0(arg));
                    340:        can = canvas[index];
                    341:        if ( !can || !can->window )
                    342:                return -1;
                    343:        clear_pixmap(can);
                    344:        copy_to_canvas(can);
                    345:        /* clear the history */
                    346:        can->history = 0;
1.1       noro      347: }
                    348:
                    349: #define RealtoDbl(r) ((r)?BDY(r):0.0)
                    350:
                    351: int arrayplot(NODE arg)
                    352: {
                    353:        int id,ix,w,h;
                    354:        VECT array;
                    355:        LIST xrange,wsize;
                    356:        char *wname;
                    357:        NODE n;
                    358:        double ymax,ymin,dy,xstep;
                    359:        Real *tab;
                    360:        struct canvas *can;
                    361:        POINT *pa;
                    362:
                    363:        array = (VECT)ARG0(arg);
                    364:        xrange = (LIST)ARG1(arg);
                    365:        can = canvas[id = search_canvas()];
                    366:        n = BDY(xrange); can->vx = VR((P)BDY(n)); n = NEXT(n);
                    367:        can->qxmin = (Q)BDY(n); n = NEXT(n); can->qxmax = (Q)BDY(n);
                    368:        can->xmin = ToReal(can->qxmin); can->xmax = ToReal(can->qxmax);
                    369:        if ( !wsize ) {
                    370:                can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
                    371:        } else {
                    372:                can->width = QTOS((Q)BDY(BDY(wsize)));
                    373:                can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
                    374:        }
                    375:        can->wname = wname; can->formula = 0; can->mode = MODE_PLOT;
                    376:        create_canvas(can);
                    377:        w = array->len;
                    378:        h = can->height;
                    379:        tab = (Real *)BDY(array);
                    380:        if ( can->ymax == can->ymin ) {
                    381:                for ( ymax = ymin = RealtoDbl(tab[0]), ix = 1; ix < w; ix++ ) {
                    382:                        if ( RealtoDbl(tab[ix]) > ymax )
                    383:                                ymax = RealtoDbl(tab[ix]);
                    384:                        if ( RealtoDbl(tab[ix]) < ymin )
                    385:                                ymin = RealtoDbl(tab[ix]);
                    386:                }
                    387:                can->ymax = ymax; can->ymin = ymin;
                    388:        } else {
                    389:                ymax = can->ymax; ymin = can->ymin;
                    390:        }
                    391:        dy = ymax-ymin;
                    392:        can->pa = (struct pa *)MALLOC(sizeof(struct pa));
                    393:        can->pa[0].length = w;
                    394:        can->pa[0].pos = pa = (POINT *)MALLOC(w*sizeof(POINT));
                    395:        xstep = (double)can->width/(double)(w-1);
                    396:        for ( ix = 0; ix < w; ix++ ) {
                    397: #ifndef MAXSHORT
                    398: #define MAXSHORT ((short)0x7fff)
                    399: #endif
                    400:                double t;
                    401:
                    402:                pa[ix].x = (int)(ix*xstep);
                    403:                t = (h - 1)*(ymax - RealtoDbl(tab[ix]))/dy;
                    404:                if ( t > MAXSHORT )
                    405:                        pa[ix].y = MAXSHORT;
                    406:                else if ( t < -MAXSHORT )
                    407:                        pa[ix].y = -MAXSHORT;
                    408:                else
1.7       noro      409:                        pa[ix].y = (long)t;
1.1       noro      410:        }
                    411:        plot_print(display,can);
                    412:        copy_to_canvas(can);
                    413:        return id;
                    414: }
                    415:
1.7       noro      416: void ifplot_resize(struct canvas *can,POINT spos,POINT epos)
1.1       noro      417: {
                    418:        struct canvas *ncan;
                    419:        struct canvas fakecan;
                    420:        Q dx,dy,dx2,dy2,xmin,xmax,ymin,ymax,xmid,ymid;
                    421:        Q sx,sy,ex,ey,cw,ch,ten,two;
                    422:        Q s,t;
                    423:        int new;
                    424:        int w,h,m;
                    425:
                    426:        if ( XC(spos) < XC(epos) && YC(spos) < YC(epos) ) {
                    427:                if ( can->precise && !can->wide ) {
                    428:                        fakecan = *can; ncan = &fakecan;
                    429:                } else {
                    430:                        new = search_canvas(); ncan = canvas[new];
                    431:                }
                    432:                ncan->mode = can->mode;
                    433:                ncan->zmin = can->zmin; ncan->zmax = can->zmax;
                    434:                ncan->nzstep = can->nzstep;
                    435:                ncan->wname = can->wname;
                    436:                ncan->vx = can->vx; ncan->vy = can->vy;
                    437:                ncan->formula = can->formula;
                    438:                w = XC(epos)-XC(spos);
                    439:                h = YC(epos)-YC(spos);
                    440:                m = MAX(can->width,can->height);
                    441:                if ( can->precise ) {
                    442:                        ncan->width = w; ncan->height = h;
                    443:                } else if ( w > h ) {
                    444:                        ncan->width = m; ncan->height = m * h/w;
                    445:                } else {
                    446:                        ncan->width = m * w/h; ncan->height = m;
                    447:                }
                    448:                if ( can->wide ) {
                    449:                        STOQ(10,ten); STOQ(2,two);
                    450:                        subq(can->qxmax,can->qxmin,&t); mulq(t,ten,&dx);
                    451:                        subq(can->qymax,can->qymin,&t); mulq(t,ten,&dy);
                    452:                        addq(can->qxmax,can->qxmin,&t); divq(t,two,&xmid);
                    453:                        addq(can->qymax,can->qymin,&t); divq(t,two,&ymid);
                    454:                        divq(dx,two,&dx2); divq(dy,two,&dy2);
                    455:                        subq(xmid,dx2,&xmin); addq(xmid,dx2,&xmax);
                    456:                        subq(ymid,dy2,&ymin); addq(ymid,dy2,&ymax);
                    457:                } else {
                    458:                        subq(can->qxmax,can->qxmin,&dx); subq(can->qymax,can->qymin,&dy);
                    459:                        xmin = can->qxmin; xmax = can->qxmax;
                    460:                        ymin = can->qymin; ymax = can->qymax;
                    461:                }
                    462:                STOQ(XC(spos),sx); STOQ(YC(spos),sy); STOQ(XC(epos),ex); STOQ(YC(epos),ey);
                    463:                STOQ(can->width,cw); STOQ(can->height,ch);
                    464:                mulq(sx,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmin);
                    465:                mulq(ex,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmax);
                    466:                mulq(ey,dy,&t); divq(t,ch,&s); subq(ymax,s,&ncan->qymin);
                    467:                mulq(sy,dy,&t); divq(t,ch,&s); subq(ymax,s,&ncan->qymax);
                    468:                ncan->xmin = ToReal(ncan->qxmin); ncan->xmax = ToReal(ncan->qxmax);
                    469:                ncan->ymin = ToReal(ncan->qymin); ncan->ymax = ToReal(ncan->qymax);
                    470:                if ( can->precise && !can->wide ) {
                    471:                        current_can = can;
                    472:                        alloc_pixmap(ncan);
1.4       noro      473: #if defined(VISUAL)
                    474:                        ncan->real_can = can;
                    475: #endif
1.1       noro      476:                        qifplotmain(ncan);
                    477:                        copy_subimage(ncan,can,spos);
                    478:                        copy_to_canvas(can);
                    479:                } else {
                    480:                        create_canvas(ncan);
                    481:                        if ( can->precise )
                    482:                                qifplotmain(ncan);
                    483:                        else
                    484:                                ifplotmain(ncan);
                    485:                        copy_to_canvas(ncan);
                    486:                }
                    487:        }
                    488: }
                    489:
1.7       noro      490: void plot_resize(struct canvas *can,POINT spos,POINT epos)
1.1       noro      491: {
                    492:        struct canvas *ncan;
                    493:        Q dx,dx2,xmin,xmax,xmid;
1.7       noro      494:        double dy,ymin,ymax,ymid;
1.1       noro      495:        Q sx,ex,cw,ten,two;
                    496:        Q s,t;
                    497:        int new;
                    498:        int w,h,m;
                    499:
                    500:        if ( XC(spos) < XC(epos) && YC(spos) < YC(epos) ) {
                    501:                new = search_canvas(); ncan = canvas[new];
                    502:                ncan->mode = can->mode;
                    503:                ncan->zmin = can->zmin; ncan->zmax = can->zmax;
                    504:                ncan->nzstep = can->nzstep;
                    505:                ncan->wname = can->wname;
                    506:                ncan->vx = can->vx; ncan->vy = can->vy;
                    507:                ncan->formula = can->formula;
                    508:                w = XC(epos)-XC(spos);
                    509:                h = YC(epos)-YC(spos);
                    510:                m = MAX(can->width,can->height);
                    511:                if ( w > h ) {
                    512:                        ncan->width = m; ncan->height = m * h/w;
                    513:                } else {
                    514:                        ncan->width = m * w/h; ncan->height = m;
                    515:                }
                    516:                if ( can->wide ) {
                    517:                        STOQ(10,ten); STOQ(2,two);
                    518:                        subq(can->qxmax,can->qxmin,&t); mulq(t,ten,&dx);
                    519:                        addq(can->qxmax,can->qxmin,&t); divq(t,two,&xmid);
                    520:                        divq(dx,two,&dx2); subq(xmid,dx2,&xmin); addq(xmid,dx2,&xmax);
                    521:
                    522:                        dy = (can->ymax-can->ymin)*10;
                    523:                        ymid = (can->ymax+can->ymin)/2;
                    524:                        ymin = ymid-dy/2; ymax = ymid+dy/2;
                    525:                } else {
                    526:                        subq(can->qxmax,can->qxmin,&dx);
                    527:                        xmin = can->qxmin; xmax = can->qxmax;
                    528:
                    529:                        dy = can->ymax-can->ymin;
                    530:                        ymin = can->ymin; ymax = can->ymax;
                    531:                }
                    532:                STOQ(XC(spos),sx); STOQ(XC(epos),ex); STOQ(can->width,cw);
                    533:                mulq(sx,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmin);
                    534:                mulq(ex,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmax);
                    535:                ncan->xmin = ToReal(ncan->qxmin); ncan->xmax = ToReal(ncan->qxmax);
                    536:
                    537:                ncan->ymin = ymax-YC(epos)*dy/can->height;
                    538:                ncan->ymax = ymax-YC(spos)*dy/can->height;
                    539:
                    540:                create_canvas(ncan);
                    541:                plotcalc(ncan);
                    542:                plot_print(display,ncan);
                    543:                copy_to_canvas(ncan);
                    544:        }
                    545: }
                    546:
1.7       noro      547: void ifplotmain(struct canvas *can)
1.1       noro      548: {
                    549:        int width,height;
1.7       noro      550:        double **tabe;
1.1       noro      551:        int i;
                    552:
                    553:        width = can->width; height = can->height;
                    554:        tabe = (double **)ALLOCA(width*sizeof(double *));
                    555:        for ( i = 0; i < width; i++ )
                    556:                tabe[i] = (double *)ALLOCA(height*sizeof(double));
                    557:        define_cursor(can->window,runningcur);
                    558:        set_busy(can); set_selection();
1.6       noro      559:        calc(tabe,can,0); if_print(display,tabe,can);
1.1       noro      560:        reset_selection(); reset_busy(can);
                    561:        define_cursor(can->window,normalcur);
                    562: }
                    563:
1.7       noro      564: void qifplotmain(struct canvas *can)
1.1       noro      565: {
                    566:        int width,height;
                    567:        char **tabe,*tabeb;
                    568:        int i;
                    569:
                    570:        width = can->width; height = can->height;
                    571:        tabe = (char **)ALLOCA(width*sizeof(char *)+width*height*sizeof(char));
1.8       noro      572:        bzero((void *)tabe,width*sizeof(char *)+width*height*sizeof(char));
1.1       noro      573:        for ( i = 0, tabeb = (char *)(tabe+width); i < width; i++ )
                    574:                tabe[i] = tabeb + height*i;
                    575:        define_cursor(can->window,runningcur);
                    576:        set_busy(can); set_selection();
                    577:        qcalc(tabe,can); qif_print(display,tabe,can);
                    578:        reset_selection(); reset_busy(can);
                    579:        define_cursor(can->window,normalcur);
                    580: }

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