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

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

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