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

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

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