Exemplo n.º 1
0
static void
resize(Widget w, XtPointer client_data, XEvent *call_data, Boolean *continue_dispatch)
{
    GRAPH *graph = (GRAPH *) client_data;
    XEvent ev;

    NG_IGNORE(call_data);
    NG_IGNORE(continue_dispatch);

    /* pull out all other exposure events
       Also, get rid of other StructureNotify events on this window. */

    while (XCheckWindowEvent(display, DEVDEP(graph).window,
                             /* ExposureMask | */ StructureNotifyMask, &ev))
        ;

    XClearWindow(display, DEVDEP(graph).window);
    graph->absolute.width = w->core.width;
    graph->absolute.height = w->core.height;
    {
        GRAPH *tmp = currentgraph;
        currentgraph = graph;
        gr_resize(graph);
        currentgraph = tmp;
    }
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
void
resize(Widget w, caddr_t client_data, caddr_t call_data)
{

    GRAPH *graph = (GRAPH *) client_data;
    XEvent ev;

    /* pull out all other exposure events
       Also, get rid of other StructureNotify events on this window. */

    while (XCheckWindowEvent(display, DEVDEP(graph).window,
	    (long) /* ExposureMask | */ StructureNotifyMask, &ev))
	    ;

    XClearWindow(display, DEVDEP(graph).window);
    graph->absolute.width = w->core.width;
    graph->absolute.height = w->core.height;
    gr_resize(graph);

}
Exemplo n.º 4
0
Arquivo: graf.c Projeto: imr/ngspice
static int
iplot(struct plot *pl, int id)
{
    int len = pl->pl_scale->v_length;
    struct dvec *v, *xs = pl->pl_scale;
    double *lims, dy;
    double start, stop, step;
    register int j;
    bool changed = FALSE;
    int yt;
    char *yl = NULL;
    double xlims[2], ylims[2];
    static REQUEST reqst = { checkup_option, NULL };
    int inited = 0;
    char commandline[513];

    for (j = 0, v = pl->pl_dvecs; v; v = v->v_next)
        if (v->v_flags & VF_PLOT)
            j++;
    if (!j)
        return (0);
    if (ft_grdb)
        fprintf(cp_err, "Entering iplot, len = %d\n", len);

    if (len < IPOINTMIN) {
        /* Nothing yet */
        return (0);
    } else if (len == IPOINTMIN || !id) {
        resumption = FALSE;
        /* Draw the grid for the first time, and plot everything. */
        lims = ft_minmax(xs, TRUE);
        xlims[0] = lims[0];
        xlims[1] = lims[1];
        ylims[0] = HUGE;
        ylims[1] = - ylims[0];
        for (v = pl->pl_dvecs; v; v = v->v_next)
            if (v->v_flags & VF_PLOT) {
                lims = ft_minmax(v, TRUE);
                if (ylims[0] > lims[0])
                    ylims[0] = lims[0];
                if (ylims[1] < lims[1])
                    ylims[1] = lims[1];
                if (!yl)
                    yl = v->v_name;
            }
        /* generate a small difference between ymin and ymax
           to catch the y=const case */
        if (ylims[0] == ylims[1])
            ylims[1] += 1e-9;

        if (ft_grdb)
            fprintf(cp_err,
                    "iplot: after 5, xlims = %G, %G, ylims = %G, %G\n",
                    xlims[0], xlims[1], ylims[0], ylims[1]);

        for (yt = pl->pl_dvecs->v_type, v = pl->pl_dvecs->v_next; v; v = v->v_next)
            if ((v->v_flags & VF_PLOT) && (v->v_type != yt)) {
                yt = SV_NOTYPE;
                break;
            }

        /* note: have command options for iplot to specify xdelta,
           etc.  So don't need static variables hack.  Assume default
           values for now.  */
        sprintf(commandline, "plot %s", yl);

        (void) gr_init(xlims, ylims, xs->v_name,
                       pl->pl_title, NULL, j, 0.0, 0.0,
                       GRID_LIN, PLOT_LIN, xs->v_name, yl, xs->v_type, yt,
                       plot_cur->pl_typename, commandline);

        for (v = pl->pl_dvecs; v; v = v->v_next)
            if (v->v_flags & VF_PLOT) {
                gr_start_internal(v, FALSE);
                ft_graf(v, xs, TRUE);
            }
        inited = 1;

    } else {
        /* plot the last points and resize if needed */
        Input(&reqst, NULL);
        /* First see if we have to make the screen bigger */
        dy = (isreal(xs) ? xs->v_realdata[len - 1] :
              realpart(xs->v_compdata[len - 1]));
        if (ft_grdb)
            fprintf(cp_err, "x = %G\n", dy);
        if (!if_tranparams(ft_curckt, &start, &stop, &step) ||
            !ciprefix("tran", pl->pl_typename)) {
            stop = HUGE;
            start = - stop;
        }
        /* checking for x lo */
        while (dy < currentgraph->data.xmin) {
            changed = TRUE;
            if (ft_grdb)
                fprintf(cp_err, "resize: xlo %G -> %G\n",
                        currentgraph->data.xmin,
                        currentgraph->data.xmin -
                        (currentgraph->data.xmax - currentgraph->data.xmin)
                        * XFACTOR);
            /* set the new x lo value */
            currentgraph->data.xmin -=
                (currentgraph->data.xmax - currentgraph->data.xmin)
                * XFACTOR;
            if (currentgraph->data.xmin < start) {
                currentgraph->data.xmin = start;
                break;
            }
        }
        if (currentgraph->data.xmax < currentgraph->data.xmin)
            currentgraph->data.xmax = currentgraph->data.xmin;
        /* checking for x hi */
        while (dy > currentgraph->data.xmax) {
            changed = TRUE;
            if (ft_grdb)
                fprintf(cp_err, "resize: xhi %G -> %G\n",
                        currentgraph->data.xmax,
                        currentgraph->data.xmax +
                        (currentgraph->data.xmax - currentgraph->data.xmin)
                        * XFACTOR);
            /* set the new x hi value */
            currentgraph->data.xmax +=
                (currentgraph->data.xmax - currentgraph->data.xmin) *
                XFACTOR;
            if (currentgraph->data.xmax > stop) {
                currentgraph->data.xmax = stop;
                break;
            }
        }
        /* checking for all y values */
        for (v = pl->pl_dvecs; v; v = v->v_next) {
            if (!(v->v_flags & VF_PLOT))
                continue;
            dy = (isreal(v) ? v->v_realdata[len - 1] :
                  realpart(v->v_compdata[len - 1]));
            if (ft_grdb)
                fprintf(cp_err, "y = %G\n", dy);
            /* checking for y lo */
            while (dy < currentgraph->data.ymin) {
                changed = TRUE;
                if (ft_grdb)
                    fprintf(cp_err, "resize: ylo %G -> %G\n",
                            currentgraph->data.ymin,
                            currentgraph->data.ymin -
                            (currentgraph->data.ymax - currentgraph->data.ymin)
                            * YFACTOR);
                /* set the new y lo value */
                currentgraph->data.ymin -=
                    (currentgraph->data.ymax - currentgraph->data.ymin)
                    * YFACTOR;
                /* currentgraph->data.ymin +=
                  (dy - currentgraph->data.ymin) * YFACTOR;*/
                /* currentgraph->data.ymin = dy;
                  currentgraph->data.ymin *= (1 + YFACTOR); */
            }
            if (currentgraph->data.ymax < currentgraph->data.ymin)
                currentgraph->data.ymax = currentgraph->data.ymin;
            /* checking for y hi */
            while (dy > currentgraph->data.ymax) {
                changed = TRUE;
                if (ft_grdb)
                    fprintf(cp_err, "resize: yhi %G -> %G\n",
                            currentgraph->data.ymax,
                            currentgraph->data.ymax +
                            (currentgraph->data.ymax - currentgraph->data.ymin)
                            * YFACTOR);
                /* set the new y hi value */
                currentgraph->data.ymax +=
                    (currentgraph->data.ymax - currentgraph->data.ymin)
                    * YFACTOR;
                /* currentgraph->data.ymax +=
                  (dy - currentgraph->data.ymax) * YFACTOR;*/
                /* currentgraph->data.ymax = dy;
                  currentgraph->data.ymax *= (1 + YFACTOR); */
            }
        }

        if (changed) {
            /* Redraw everything. */
            gr_pmsg("Resizing screen");
            gr_resize(currentgraph);
#ifndef X_DISPLAY_MISSING
            gr_redraw(currentgraph);
#endif
        } else {
            /* Just connect the last two points. This won't be done
             * with curve interpolation, so it might look funny.  */
            for (v = pl->pl_dvecs; v; v = v->v_next)
                if (v->v_flags & VF_PLOT) {
                    gr_point(v,
                             (isreal(xs) ? xs->v_realdata[len - 1] :
                              realpart(xs->v_compdata[len - 1])),
                             (isreal(v) ? v->v_realdata[len - 1] :
                              realpart(v->v_compdata[len - 1])),
                             (isreal(xs) ? xs->v_realdata[len - 2] :
                              realpart(xs->v_compdata[len - 2])),
                             (isreal(v) ? v->v_realdata[len - 2] :
                              realpart(v->v_compdata[len - 2])),
                             len - 1);
                }
        }
    }
    DevUpdate();
    return (inited);
}
Exemplo n.º 5
0
/* window procedure */
LRESULT CALLBACK PlotWindowProc( HWND hwnd,
   UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   static int x0,y0,xep,yep;
   int xe, ye, prevmix;
   static double fx0,fy0;
   double fxe, fye;
   double angle;
   char buf[BSIZE_SP];
   char buf2[128];
   char *t;
   HDC hdc;
   HPEN OldPen;
   HPEN NewPen;   
   
   switch (uMsg) {
   case WM_SYSCOMMAND:
   {
      /* test command */
      int cmd = wParam & ID_MASK;
      switch(cmd) {
         case ID_DRUCKEN:  return PrintPlot( hwnd);
         case ID_DRUCKEINR:      return PrintInit( hwnd);
         case ID_HARDCOPY: return HcpyPlot( hwnd);
         case ID_HARDCOPY_BW: return HcpyPlotBW( hwnd);
      }
   }
   goto WIN_DEFAULT;

   case WM_LBUTTONDOWN:
   {
      GRAPH * gr = pGraph( hwnd);                      
      xep = x0 = LOWORD (lParam);
      yep = y0 = HIWORD (lParam);
      /* generate x,y data from grid coordinates */
      WIN_ScreentoData(gr, x0, y0, &fx0, &fy0);
   } 
   goto WIN_DEFAULT;  
   
   case WM_MOUSEMOVE:
      /* left mouse button: connect coordinate pair by dashed pair of x, y lines */
      if (wParam & MK_LBUTTON)
      {
          hdc = GetDC (hwnd) ;
          if (isblack)
             prevmix = SetROP2(hdc, R2_XORPEN);
          else
             prevmix = SetROP2(hdc, R2_NOTXORPEN);
          /* Create white dashed pen */
          NewPen = CreatePen( LType(12), 0, ColorTable[1] );
          OldPen = SelectObject(hdc, NewPen);
          /* draw lines with previous coodinates -> delete old line because of XOR */
          MoveToEx (hdc, x0, y0, NULL) ;
          LineTo   (hdc, x0, yep) ;
          LineTo   (hdc, xep, yep);
          /* get new end point */
          xe = LOWORD (lParam);
          ye = HIWORD (lParam);
          /* draw new lines */
          MoveToEx (hdc, x0, y0, NULL) ;
          LineTo   (hdc, x0, ye) ;
          LineTo   (hdc, xe, ye);
          /* restore standard color mix */
          SetROP2(hdc, prevmix);
          OldPen = SelectObject(hdc, OldPen);
          DeleteObject( NewPen);    
          ReleaseDC (hwnd, hdc) ;
          /* restore new to previous coordinates */
          yep = ye;
          xep = xe;
      }
      /* right mouse button: create white (black) dashed box */
      else if (wParam & MK_RBUTTON){
         hdc = GetDC (hwnd) ;
         if (isblack)
            prevmix = SetROP2(hdc, R2_XORPEN);
         else
            prevmix = SetROP2(hdc, R2_NOTXORPEN);
         /* Create white (black) dashed pen */
         NewPen = CreatePen( LType(12), 0, ColorTable[1] );
         OldPen = SelectObject(hdc, NewPen);
         /* draw box with previous coodinates -> delete old lines because of XOR */
         MoveToEx (hdc, x0, y0, NULL) ;
         LineTo   (hdc, x0, yep) ;
         LineTo   (hdc, xep, yep);
         LineTo   (hdc, xep, y0) ;
         LineTo   (hdc, x0, y0);
         /* get new end point */
         xe = LOWORD (lParam);
         ye = HIWORD (lParam);
         /* draw new box */
         MoveToEx (hdc, x0, y0, NULL) ;
         LineTo   (hdc, x0, ye) ;
         LineTo   (hdc, xe, ye);
         LineTo   (hdc, xe, y0) ;
         LineTo   (hdc, x0, y0);
         /* restore standard color mix */
         SetROP2(hdc, prevmix);
         OldPen = SelectObject(hdc, OldPen);
         DeleteObject( NewPen);    
         ReleaseDC (hwnd, hdc) ;
         /* restore new to previous coordinates */
         yep = ye;
         xep = xe;
      }
   goto WIN_DEFAULT;
           
   /* get final coordinates upon left mouse up */
   /* calculate and print out the data */
   case WM_LBUTTONUP:
   {
      GRAPH * gr = pGraph( hwnd);  
      InvalidateRect (hwnd, NULL, TRUE) ;
      xe = LOWORD (lParam);
      ye = HIWORD (lParam);
      WIN_ScreentoData(gr, xe, ye, &fxe, &fye);

      /* print it out */
      if (xe == x0 && ye == y0) {     /* only one location */
         fprintf(stdout, "\nx0 = %g, y0 = %g\n", fx0, fy0);
         if (gr->grid.gridtype == GRID_POLAR
         || gr->grid.gridtype == GRID_SMITH
         || gr->grid.gridtype == GRID_SMITHGRID)
         {
            angle = RAD_TO_DEG * atan2( fy0, fx0 );
            fprintf(stdout, "r0 = %g, a0 = %g\n",
            sqrt( fx0*fx0 + fy0*fy0 ),
            (angle>0)?angle:(double) 360+angle);
         }
      } else  {    
         /* need to print info about two points */
         fprintf(stdout, "\nx0 = %g, y0 = %g    x1 = %g, y1 = %g\n",
            fx0, fy0, fxe, fye);
         fprintf(stdout, "dx = %g, dy = %g\n", fxe-fx0, fye - fy0);
         if (xe != x0 && ye != y0) {
         /* add slope info if both dx and dy are zero, */
         /* because otherwise either dy/dx or dx/dy is zero, */
         /* which is uninteresting */
   
         fprintf(stdout, "dy/dx = %g    dx/dy = %g\n",
            (fye-fy0)/(fxe-fx0), (fxe-fx0)/(fye-fy0));
         }
      }
      SetFocus( swString);
   } 
   goto WIN_DEFAULT;
           
   /* get starting coordinates upon right mouse button down */
   case WM_RBUTTONDOWN:
   {
      GRAPH * gr = pGraph( hwnd);                      
      x0 = xep = LOWORD (lParam);
      y0 = yep = HIWORD (lParam);
      WIN_ScreentoData(gr, x0, y0, &fx0, &fy0);
   } 
   goto WIN_DEFAULT;  
   /* get final coordinates upon right mouse button up */
   /* copy xlimit, ylimit command into buf */
   /* start plot loop with argument buf   */
   case WM_RBUTTONUP:
   {
      GRAPH * gr = pGraph( hwnd);
      InvalidateRect (hwnd, NULL, TRUE) ;
      xe = LOWORD (lParam);
      ye = HIWORD (lParam);
      /* do nothing if mouse curser is not moved in both x and y */
      if ((xe == x0) || (ye == y0)) {
         SetFocus( swString);
         goto WIN_DEFAULT;
      }  
      WIN_ScreentoData(gr, xe, ye, &fxe, &fye);
      
      strncpy(buf2, gr->plotname, sizeof(buf2));
      if ((t = index(buf2, ':'))) /* strchr */
         *t = 0;

      if (!eq(plot_cur->pl_typename, buf2)) {
         (void) sprintf(buf,
//       "setplot %s; %s xlimit %e %e ylimit %e %e; setplot $curplot\n",
         "setplot %s; %s xlimit %e %e ylimit %e %e\n",
         buf2, gr->commandline, fx0, fxe, fy0, fye);
      } else {
         (void) sprintf(buf, "%s xlimit %e %e ylimit %e %e\n",
         gr->commandline, fx0, fxe, fy0, fye);
      }

      (void) cp_evloop(buf);
      SetFocus( swString);
   }
   goto WIN_DEFAULT;

   case WM_CLOSE: /* close window */
   {
      GRAPH * g = pGraph( hwnd);

      if (g) {
         /* if g equals currentgraph, set a new currentgraph. 
            Otherwise gr_resize(g) might fail. */
         if (g == currentgraph)
            currentgraph = FindGraph(g->graphid - 1);
         DestroyGraph(g->graphid);
      }
   }
   goto WIN_DEFAULT;

   case WM_PAINT: /* replot window (e.g. after Resize) */
      {
         PAINTSTRUCT ps;
         GRAPH * g;
         tpWindowData wd;
         HDC saveDC;    /* the DC from BeginPaint is different... */
         HDC newDC;

         /* has to happen */
         newDC = BeginPaint( hwnd, &ps);
         g = pGraph( hwnd);
         if (g) {
            wd = pWindowData(g);
            if (wd) {
               if (!wd->PaintFlag && !wd->FirstFlag) {
                  /* avoid recursive call */
                  wd->PaintFlag = 1;
                  /* get window sizes */
                  GetClientRect( hwnd, &(wd->Area));
                  g->absolute.width  = wd->Area.right;
                  g->absolute.height = wd->Area.bottom;
                  /* switch DC */
                  saveDC = wd->hDC;
                  wd->hDC = newDC;
//                currentgraph = g;
                  
                  /* plot anew */
                  gr_resize(g);
                  /* switch DC */
                  wd->hDC = saveDC;
                  /* ready */
                  wd->PaintFlag = 0;
               }
             }
         }
         /* finish */
         EndPaint( hwnd, &ps);
      }
      return 0;

   default:
WIN_DEFAULT:
      return DefWindowProc( hwnd, uMsg, wParam, lParam);
   }
}