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

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

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