Пример #1
0
/* called by SystemMenue / Print */
LRESULT PrintPlot( HWND hwnd)
{
   GRAPH * graph;
   GRAPH * temp;

   /* get pointer to graph */
   graph = pGraph( hwnd);
   if (!graph) return 0;

   /* switch to printer */
   /* (results in WPRINT_Init()) */
   if (DevSwitch("WinPrint")) return 0;

   /* Cursor = wait */
   SetCursor( LoadCursor( NULL, IDC_WAIT));

   /* copy graph */
   temp = CopyGraph(graph);
   if (!temp) goto PrintEND;

   /* add to the copy the new printer data */
   if (NewViewport(temp)) goto PrintEND2;

   /* make correction to placement of grid (copy from gr_init) */
   temp->viewportxoff = temp->fontwidth  * 8;
   temp->viewportyoff = temp->fontheight * 4;

   /* print the graph */
   gr_resize(temp);

PrintEND2:
   /* delete temporary graph */
   DestroyGraph(temp->graphid);

PrintEND:
   /* switch back to screen */
   DevSwitch(NULL);

   /* Cursor = normal */
   SetCursor( LoadCursor( NULL, IDC_ARROW));

   return 0;
}
Пример #2
0
Файл: graf.c Проект: imr/ngspice
int
gr_init(double *xlims, double *ylims, /* The size of the screen. */
        char *xname, char *plotname,  /* What to label things. */
        char *hcopy,                  /* The raster file. */
        int nplots,                   /* How many plots there will be. */
        double xdelta, double ydelta, /* Line increments for the scale. */
        GRIDTYPE gridtype,            /* The grid type */
        PLOTTYPE plottype,            /*  and the plot type. */
        char *xlabel, char *ylabel,   /* Labels for axes. */
        int xtype, int ytype,         /* The types of the data graphed. */
        char *pname,
        char *commandline)            /* For xi_zoomdata() */
{
    GRAPH *graph;
    wordlist *wl;
    char *comb_title;

    NG_IGNORE(nplots);

    if ((graph = NewGraph()) == NULL)
        return (FALSE);

    /*
      The global currentgraph will always be the current graph.
    */
    SetGraphContext(graph->graphid);

    graph->onevalue = (xname ? FALSE : TRUE);

    /* communicate filename to plot 5 driver */
    if (hcopy)
        graph->devdep = hcopy;

    cur.plotno = 0;

    /* note: should do only once, maybe in gr_init_once */
    if (!cp_getvar("pointchars", CP_STRING, pointchars, sizeof(pointchars)))
        (void) strcpy(pointchars, DEFPOINTCHARS);

    if (!cp_getvar("ticmarks", CP_NUM, &graph->ticmarks, 0)) {
        if (cp_getvar("ticmarks", CP_BOOL, NULL, 0))
            graph->ticmarks = 10;
        else
            graph->ticmarks = 0;
    }

    if (cp_getvar("ticlist", CP_LIST, ticlist, 0)) {
        wl = vareval("ticlist");
        ticlist = wl_flatten(wl);
        graph->ticdata = readtics(ticlist);
    } else {
        graph->ticdata = NULL;
    }

    if (!xlims || !ylims) {
        internalerror("gr_init:  no range specified");
        return (FALSE);
    }

    /* save upper and lower limits */
    graph->data.xmin = xlims[0];
    graph->data.xmax = xlims[1];
    graph->data.ymin = ylims[0];
    graph->data.ymax = ylims[1];

    /* get title into plot window */
    if (!pname)
        pname = "(unknown)";
    if (!plotname)
        plotname = "(unknown)";

    comb_title = tprintf("%s: %s", pname, plotname);
    graph->plotname = comb_title;

    /* note: have enum here or some better convention */
    if (NewViewport(graph) == 1) {
        /* note: where is the error message generated? */
        /* note: undo tmallocs */
        fprintf(cp_err, "Can't open viewport for graphics.\n");
        return (FALSE);
    }

    /* layout decisions */
    /* note: have to do before gr_fixgrid and after NewViewport */
    graph->viewportxoff = graph->fontwidth * 8;  /* 8 lines on left */
    graph->viewportyoff = graph->fontheight * 4; /* 4 on bottom */

    DevClear();

    graph->grid.gridtype = gridtype;
    graph->plottype = plottype;
    graph->grid.xdatatype = xtype;
    graph->grid.ydatatype = ytype;
    graph->grid.xdelta = xdelta;
    graph->grid.ydelta = ydelta;
    graph->grid.ysized = 0;
    graph->grid.xsized = 0;

    if (!graph->onevalue) {
        if (xlabel)
            graph->grid.xlabel = xlabel;
        else
            graph->grid.xlabel = xname;

        if (ylabel)
            graph->grid.ylabel = ylabel;
    } else {
        if (xlabel)
            graph->grid.xlabel = xlabel;
        else
            graph->grid.xlabel = "real";

        if (ylabel)
            graph->grid.ylabel = ylabel;
        else
            graph->grid.ylabel = "imag";
    }

    gr_resize_internal(graph);
    gr_redrawgrid(graph);

    /* Set up colors and line styles. */
    if (dispdev->numlinestyles == 1)
        cur.linestyle = 0; /* Use the same one all the time. */
    else
        cur.linestyle = 1;

    /* XXX Special exception for SMITH */
    if (dispdev->numcolors > 2 &&
        (graph->grid.gridtype == GRID_SMITH ||
         graph->grid.gridtype == GRID_SMITHGRID))
    {
        cur.color = 3;
    } else {
        cur.color = 1;
    }

    graph->commandline = copy(commandline);

    return (TRUE);
}