Пример #1
0
Файл: graf.c Проект: imr/ngspice
void
gr_end_iplot(void)
{
    struct dbcomm *db, *prev, *next;
    GRAPH *graph;
    struct dveclist *link;
    struct dvec *dv;

    prev = NULL;
    for (db = dbs; db; prev = db, db = next) {
        next = db->db_next;
        if (db->db_type == DB_DEADIPLOT) {
            if (db->db_graphid) {
                DestroyGraph(db->db_graphid);
                if (prev)
                    prev->db_next = next;
                else
                    ft_curckt->ci_dbs = dbs = next;
                dbfree1(db);
            }
        } else if (db->db_type == DB_IPLOT || db->db_type == DB_IPLOTALL) {
            if (db->db_graphid) {

                /* get private copy of dvecs */
                graph = FindGraph(db->db_graphid);

                link = graph->plotdata;

                while (link) {
                    dv = link->vector;
                    link->vector = vec_copy(dv);
                    /* vec_copy doesn't set v_color or v_linestyle */
                    link->vector->v_color = dv->v_color;
                    link->vector->v_linestyle = dv->v_linestyle;
                    link->vector->v_flags |= VF_PERMANENT;
                    link = link->next;
                }

                db->db_graphid = 0;
            } else {
                /* warn that this wasn't plotted */
                fprintf(cp_err, "Warning: iplot %d was not executed.\n",
                        db->db_number);
            }
        }
    }
}
Пример #2
0
int
GL_Close(void)
{
    /* in case GL_Close is called as part of an abort,
       w/o having reached GL_NewViewport */
    if (plotfile) {
        if (DEVDEP(currentgraph).lastlinestyle != -1) {
            DEVDEP(currentgraph).linecount = 0;
        }
        fclose(plotfile);
        plotfile = NULL;
    }
    /* In case of hardcopy command destroy the hardcopy graph
     * and reset currentgraph to graphid 1, if possible
     */
    if (!screenflag) {
        DestroyGraph(hcopygraphid);
        currentgraph = FindGraph(1);
    }

    return 0;
}
Пример #3
0
void
SetGraphContext(int graphid)
{
    currentgraph = FindGraph(graphid);
}
Пример #4
0
Файл: graf.c Проект: imr/ngspice
void
gr_iplot(struct plot *plot)
{
    struct dbcomm *db;
    int dontpop;        /* So we don't pop w/o push. */
    char buf[30];

    hit = 0;
    for (db = dbs; db; db = db->db_next) {
        if (db->db_type == DB_IPLOT || db->db_type == DB_IPLOTALL) {

            if (db->db_graphid)
                PushGraphContext(FindGraph(db->db_graphid));

            set(plot, db, FALSE, VF_PLOT);

            dontpop = 0;
            if (iplot(plot, db->db_graphid)) {
                /* graph just assigned */
                db->db_graphid = currentgraph->graphid;
                dontpop = 1;
            }

            set(plot, db, TRUE, VF_PLOT);

            if (!dontpop && db->db_graphid)
                PopGraphContext();

        } else if (db->db_type == DB_TRACENODE || db->db_type == DB_TRACEALL) {

            struct dvec *v, *u;
            int len;

            set(plot, db, FALSE, VF_PRINT);

            len = plot->pl_scale->v_length;

            dontpop = 0;
            for (v = plot->pl_dvecs; v; v = v->v_next) {
                if (v->v_flags & VF_PRINT) {
                    u = plot->pl_scale;
                    if (len <= 1 || hit <= 0 || hit2 < 0) {
                        if (len <= 1 || hit2 < 0)
                            term_clear();
                        else
                            term_home();
                        hit = 1;
                        hit2 = 1;
                        printf(
                            "\tExecution trace (remove with the \"delete\" command)");
                        term_cleol();
                        printf("\n");

                        if (u) {
                            printf("%12s:", u->v_name);
                            if (isreal(u)) {
                                printf("%s",
                                       getitright(buf, u->v_realdata[len - 1]));
                            } else {
                                /* MW. Complex data here, realdata is NULL
                                   (why someone use realdata here again) */
                                printf("%s",
                                       getitright(buf, u->v_compdata[len - 1].cx_real));
                                printf(", %s",
                                       getitright(buf, u->v_compdata[len - 1].cx_imag));
                            }
                            term_cleol();
                            printf("\n");
                        }
                    }
                    if (v == u)
                        continue;
                    printf("%12s:", v->v_name);
                    if (isreal(v)) {
                        printf("%s", getitright(buf, v->v_realdata[len - 1]));
                    } else {
                        /* MW. Complex data again */
                        printf("%s", getitright(buf, v->v_compdata[len - 1].cx_real));
                        printf(", %s", getitright(buf, v->v_compdata[len - 1].cx_imag));
                    }
                    term_cleol();
                    printf("\n");
                }
            }
            set(plot, db, TRUE, VF_PRINT);
        }
    }
}
Пример #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);
   }
}