void plot_docoms(wordlist *wl) { bool inter; inter = cp_interactive; cp_interactive = FALSE; while (wl) { (void) cp_evloop(wl->wl_word); wl = wl->wl_next; } cp_resetcontrol(); cp_interactive = inter; }
/* should be able to do this by sleight of hand on graph parameters */ static void zoomin(GRAPH *graph) { /* note: need to add circular boxes XXX */ int x0, y0, x1, y1; double fx0, fx1, fy0, fy1, ftemp; char buf[BSIZE_SP]; char buf2[128]; char *t; Window rootwindow, childwindow; int rootx, rooty; unsigned int state; int x, y, upperx, uppery; unsigned width, height; /* open box and get area to zoom in on */ XQueryPointer(display, DEVDEP(graph).window, &rootwindow, &childwindow, &rootx, &rooty, &x0, &y0, &state); x = x1 = x0 + BOXSIZE; y = y1 = y0 + BOXSIZE; upperx = x0; uppery = y0; width = BOXSIZE; height = BOXSIZE; XDrawRectangle(display, DEVDEP(graph).window, xorgc, upperx, uppery, width, height); XWarpPointer(display, None, DEVDEP(graph).window, 0, 0, 0, 0, x1, y1); while (state & Button3Mask) { if (x != x1 || y != y1) { x1 = x; y1 = y; XDrawRectangle(display, DEVDEP(graph).window, xorgc, upperx, uppery, width, height); upperx = MIN(x1, x0); uppery = MIN(y1, y0); width = (unsigned) ABS(x1 - x0); height = (unsigned) ABS(y1 - y0); XDrawRectangle(display, DEVDEP(graph).window, xorgc, upperx, uppery, width, height); } XQueryPointer(display, DEVDEP(graph).window, &rootwindow, &childwindow, &rootx, &rooty, &x, &y, &state); } XDrawRectangle(display, DEVDEP(graph).window, xorgc, upperx, uppery, width, height); X_ScreentoData(graph, x0, y0, &fx0, &fy0); X_ScreentoData(graph, x1, y1, &fx1, &fy1); if (fx0 > fx1) { ftemp = fx0; fx0 = fx1; fx1 = ftemp; } if (fy0 > fy1) { ftemp = fy0; fy0 = fy1; fy1 = ftemp; } strncpy(buf2, graph->plotname, sizeof(buf2)); if ((t = strchr(buf2, ':')) != NULL) *t = 0; if (!eq(plot_cur->pl_typename, buf2)) { (void) sprintf(buf, "setplot %s; %s xlimit %.20e %.20e ylimit %.20e %.20e; setplot $curplot\n", buf2, graph->commandline, fx0, fx1, fy0, fy1); } else { (void) sprintf(buf, "%s xlimit %e %e ylimit %e %e\n", graph->commandline, fx0, fx1, fy0, fy1); } /* don't use the following if using GNU Readline or BSD EditLine */ #if !defined(HAVE_GNUREADLINE) && !defined(HAVE_BSDEDITLINE) { wordlist *wl; /* hack for Gordon Jacobs */ /* add to history list if plothistory is set */ if (cp_getvar("plothistory", CP_BOOL, NULL)) { wl = cp_parse(buf); (void) cp_addhistent(cp_event++, wl); } } #endif /* !defined(HAVE_GNUREADLINE) && !defined(HAVE_BSDEDITLINE) */ (void) cp_evloop(buf); }
/* 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); } }
//void //inp_nutsource(FILE *fp, bool comfile, char *filename) void inp_nutsource(FILE *fp, int comfile, char *filename) { struct line *deck, *dd, *ld; struct line *realdeck, *options = NULL; char *tt = NULL, name[BSIZE_SP], *s, *t; //bool commands = FALSE; int commands = FALSE; wordlist *wl = NULL, *end = NULL; wordlist *controls = NULL; FILE *lastin, *lastout, *lasterr; deck = inp_readall(fp, NULL, comfile, FALSE); /* still to check if . or filename instead of NULL */ if (!deck) return; realdeck = inp_deckcopy(deck); if (!comfile) { /* Save the title before INPgetTitle gets it. */ tt = copy(deck->li_line); if (!deck->li_next) fprintf(cp_err, "Warning: no lines in deck...\n"); } (void) fclose(fp); /* Now save the IO context and start a new control set... After * we are done with the source we'll put the old file descriptors * back. I guess we could use a FILE stack, but since this routine * is recursive anyway... */ lastin = cp_curin; lastout = cp_curout; lasterr = cp_curerr; cp_curin = cp_in; cp_curout = cp_out; cp_curerr = cp_err; cp_pushcontrol(); /* We should now go through the deck and execute front-end * commands and remove them. Front-end commands are enclosed by * the lines .control and .endc, unless comfile * is TRUE, in which case every line must be a front-end command. * There are too many problems with matching the first word on * the line. */ ld = deck; if (comfile) { /* This is easy. */ for (dd = deck; dd; dd = ld) { ld = dd->li_next; if ((dd->li_line[0] == '*') && (dd->li_line[1] != '#')) continue; if (!ciprefix(".control", dd->li_line) && !ciprefix(".endc", dd->li_line)) { if (dd->li_line[0] == '*') (void) cp_evloop(dd->li_line + 2); else (void) cp_evloop(dd->li_line); } tfree(dd->li_line); tfree(dd); } } else { for (dd = deck->li_next; dd; dd = ld->li_next) { if ((dd->li_line[0] == '*') && (dd->li_line[1] != '#')) { ld = dd; continue; } (void) strncpy(name, dd->li_line, BSIZE_SP); for (s = name; *s && isspace(*s); s++) ; for (t = s; *t && !isspace(*t); t++) ; *t = '\0'; if (ciprefix(".control", dd->li_line)) { ld->li_next = dd->li_next; tfree(dd->li_line); tfree(dd); if (commands) fprintf(cp_err, "Warning: redundant .control line\n"); else commands = TRUE; } else if (ciprefix(".endc", dd->li_line)) { ld->li_next = dd->li_next; tfree(dd->li_line); tfree(dd); if (commands) commands = FALSE; else fprintf(cp_err, "Warning: misplaced .endc line\n"); } else if (commands || prefix("*#", dd->li_line)) { controls = wl_cons(NULL, controls); wl = controls; if (prefix("*#", dd->li_line)) wl->wl_word = copy(dd->li_line + 2); else wl->wl_word = dd->li_line; ld->li_next = dd->li_next; tfree(dd); } else if (!*dd->li_line) { /* So blank lines in com files don't get * considered as circuits. */ ld->li_next = dd->li_next; tfree(dd->li_line); tfree(dd); } else { inp_casefix(s); inp_casefix(dd->li_line); if (eq(s, ".width") || ciprefix(".four", s) || eq(s, ".plot") || eq(s, ".print") || eq(s, ".save")) { wl_append_word(&wl, &end, copy(dd->li_line)); ld->li_next = dd->li_next; tfree(dd->li_line); tfree(dd); } else { ld = dd; } } } if (deck->li_next) { /* There is something left after the controls. */ fprintf(cp_out, "\nCircuit: %s\n\n", tt); fprintf(stderr, "\nCircuit: %s\n\n", tt); /* Now expand subcircuit macros. Note that we have to * fix the case before we do this but after we * deal with the commands. */ if (!cp_getvar("nosubckt", CP_BOOL, NULL)) deck->li_next = inp_subcktexpand(deck->li_next); deck->li_actual = realdeck; nutinp_dodeck(deck, tt, wl, FALSE, options, filename); } /* Now that the deck is loaded, do the commands... */ controls = wl_reverse(controls); for (wl = controls; wl; wl = wl->wl_next) (void) cp_evloop(wl->wl_word); wl_free(controls); } /* Now reset everything. Pop the control stack, and fix up the IO * as it was before the source. */ cp_popcontrol(); cp_curin = lastin; cp_curout = lastout; cp_curerr = lasterr; tfree(tt); }
/* should be able to do this by sleight of hand on graph parameters */ void zoomin(GRAPH *graph) { /* note: need to add circular boxes XXX */ int x0, y0, x1, y1; double fx0, fx1, fy0, fy1, ftemp; char buf[BSIZE_SP]; char buf2[128]; char *t; Window rootwindow, childwindow; int rootx, rooty; unsigned int state; int x, y, upperx, uppery, lowerx, lowery; /* open box and get area to zoom in on */ XQueryPointer(display, DEVDEP(graph).window, &rootwindow, &childwindow, &rootx, &rooty, &x0, &y0, &state); x = lowerx = x1 = x0 + BOXSIZE; y = lowery = y1 = y0 + BOXSIZE; upperx = x0; uppery = y0; XDrawRectangle(display, DEVDEP(graph).window, xorgc, upperx, uppery, lowerx - upperx, lowery - uppery); /* note: what are src_x, src_y, src_width, and src_height for? XXX */ XWarpPointer(display, None, DEVDEP(graph).window, 0, 0, 0, 0, x1, y1); while (state & Button3Mask) { if (x != x1 || y != y1) { XDrawRectangle(display, DEVDEP(graph).window, xorgc, upperx, uppery, lowerx - upperx, lowery - uppery); x1 = x; y1 = y; /* figure out upper left corner */ /* remember X11's (and X10's) demented coordinate system */ if (y0 < y1) { uppery = y0; upperx = x0; lowery = y1; lowerx = x1; } else { uppery = y1; upperx = x1; lowery = y0; lowerx = x0; } XDrawRectangle(display, DEVDEP(graph).window, xorgc, upperx, uppery, lowerx - upperx, lowery - uppery); } XQueryPointer(display, DEVDEP(graph).window, &rootwindow, &childwindow, &rootx, &rooty, &x, &y, &state); } XDrawRectangle(display, DEVDEP(graph).window, xorgc, upperx, uppery, lowerx - upperx, lowery - uppery); X_ScreentoData(graph, x0, y0, &fx0, &fy0); X_ScreentoData(graph, x1, y1, &fx1, &fy1); if (fx0 > fx1) { ftemp = fx0; fx0 = fx1; fx1 = ftemp; } if (fy0 > fy1) { ftemp = fy0; fy0 = fy1; fy1 = ftemp; } strncpy(buf2, graph->plotname, sizeof(buf2)); if ((t =strchr(buf2, ':'))) *t = 0; if (!eq(plot_cur->pl_typename, buf2)) { (void) sprintf(buf, "setplot %s; %s xlimit %.20e %.20e ylimit %.20e %.20e; setplot $curplot\n", buf2, graph->commandline, fx0, fx1, fy0, fy1); } else { (void) sprintf(buf, "%s xlimit %e %e ylimit %e %e\n", graph->commandline, fx0, fx1, fy0, fy1); } /* don't use the following if using GNU Readline or BSD EditLine */ #if !defined(HAVE_GNUREADLINE) && !defined(HAVE_BSDEDITLINE) { wordlist *wl; int dummy; /* hack for Gordon Jacobs */ /* add to history list if plothistory is set */ if (cp_getvar("plothistory", VT_BOOL, (char *) &dummy)) { wl = cp_parse(buf); (void) cp_addhistent(cp_event++, wl); } } #endif /* !defined(HAVE_GNUREADLINE) && !defined(HAVE_BSDEDITLINE) */ (void) cp_evloop(buf); }