From e7e5ad190b2298ccb6de824a39d617f39df7e93c Mon Sep 17 00:00:00 2001 From: Stefan Frederik Date: Sun, 6 Dec 2020 02:10:53 +0100 Subject: [PATCH] more schematic context in xctx: cairo surfaces and context, save buffer graphic context (GC), hilight hash tables and data, node name hash tables. Refactoring of resetwin , resetcairo routines (also used in xinit to avoid code duplication), switching schematics seems almost complete now --- src/actions.c | 410 ++++++++++++++++-------------------------------- src/callback.c | 12 +- src/draw.c | 66 ++++---- src/editprop.c | 8 +- src/findnet.c | 2 +- src/globals.c | 10 +- src/hilight.c | 92 ++++++----- src/move.c | 38 ++--- src/netlist.c | 53 +++---- src/node_hash.c | 46 ++---- src/scheduler.c | 7 +- src/select.c | 62 ++++---- src/token.c | 8 +- src/xinit.c | 327 +++++++++++++++++++++++++------------- src/xschem.h | 22 ++- src/xschem.tcl | 15 +- 16 files changed, 561 insertions(+), 617 deletions(-) diff --git a/src/actions.c b/src/actions.c index cdbb67f8..401874e8 100644 --- a/src/actions.c +++ b/src/actions.c @@ -59,7 +59,6 @@ void print_version() exit(EXIT_SUCCESS); } - char *escape_chars(char *dest, const char *source, int size) { int s=0; @@ -195,241 +194,110 @@ const char *add_ext(const char *f, const char *ext) return ff; } -static void reset_cairo(int create, int clear) -{ - #ifdef HAS_CAIRO - if(clear) { - /* xctx->save_sfc is based on pixmap and pixmaps are not resizeable, so on resize - * we must destroy & recreate everything. sfc can be resized using cairo_*_surface_set_size - * being based on window */ - cairo_destroy(xctx->cairo_save_ctx); - cairo_surface_destroy(xctx->save_sfc); - } - if(create) { - #if HAS_XRENDER==1 - #if HAS_XCB==1 - xctx->save_sfc = cairo_xcb_surface_create_with_xrender_format(xcbconn, screen_xcb, xctx->save_pixmap, - &format_rgb, xctx->xschem_w, xctx->xschem_h); - #else - xctx->save_sfc = cairo_xlib_surface_create_with_xrender_format(display, xctx->save_pixmap, - DefaultScreenOfDisplay(display), format, xctx->xschem_w, xctx->xschem_h); - #endif /* HAS_XCB */ - #else - xctx->save_sfc = cairo_xlib_surface_create(display, xctx->save_pixmap, visual, xctx->xschem_w, xctx->xschem_h); - #endif /* HAS_XRENDER */ - if(cairo_surface_status(xctx->save_sfc)!=CAIRO_STATUS_SUCCESS) { - fprintf(errfp, "ERROR: invalid cairo xcb surface\n"); - exit(-1); - } - xctx->cairo_save_ctx = cairo_create(xctx->save_sfc); - cairo_set_line_width(xctx->cairo_save_ctx, 1); - cairo_set_line_join(xctx->cairo_save_ctx, CAIRO_LINE_JOIN_ROUND); - cairo_set_line_cap(xctx->cairo_save_ctx, CAIRO_LINE_CAP_ROUND); - cairo_select_font_face (xctx->cairo_save_ctx, cairo_font_name, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); - cairo_set_font_size (xctx->cairo_save_ctx, 20); - } - /* 20171125 select xlib or xcb :-) */ - #if HAS_XCB==1 && HAS_XRENDER==1 - cairo_xcb_surface_set_size(sfc, xctx->xschem_w, xctx->xschem_h); - #else - cairo_xlib_surface_set_size(sfc, xctx->xschem_w, xctx->xschem_h); - #endif /* HAS_XCB && HAS_XRENDER */ - #endif /* HAS_CAIRO */ -} - -void resetwin(int create_pixmap, int clear_pixmap, int force) -{ - int i; - XWindowAttributes wattr; - if(has_x) { -#ifdef __unix__ - i = XGetWindowAttributes(display, xctx->window, &wattr); /* should call only when resized */ - /* to avoid server roundtrip replies */ - if(!i) { - return; - } - /* if(wattr.map_state==IsUnmapped) return; */ - - xctx->xschem_w=wattr.width; - xctx->xschem_h=wattr.height; - xctx->areax2 = xctx->xschem_w+2*INT_WIDTH(xctx->lw); - xctx->areay2 = xctx->xschem_h+2*INT_WIDTH(xctx->lw); - xctx->areax1 = -2*INT_WIDTH(xctx->lw); - xctx->areay1 = -2*INT_WIDTH(xctx->lw); - xctx->areaw = xctx->areax2-xctx->areax1; - xctx->areah = xctx->areay2-xctx->areay1; - - /* if no force avoid unnecessary work if no resize */ - if( force || xctx->xschem_w !=xctx->xrect[0].width || xctx->xschem_h !=xctx->xrect[0].height) { - dbg(1, "resetwin(): x=%d y=%d xctx->xschem_w=%d xctx->xschem_h=%d\n", - wattr.x, wattr.y, xctx->xschem_w,xctx->xschem_h); - dbg(1, "resetwin(): changing size\n\n"); - xctx->xrect[0].x = 0; - xctx->xrect[0].y = 0; - xctx->xrect[0].width = xctx->xschem_w; - xctx->xrect[0].height = xctx->xschem_h; - if(clear_pixmap) XFreePixmap(display,xctx->save_pixmap); - /* - { - unsigned int w, h; - XQueryBestSize(display, TileShape, xctx->window, xctx->xschem_w, xctx->xschem_h, &w, &h); - dbg(1, "XQueryBestSize: req: w=%d, h=%d, opt: w=%d h=%d\n", - xctx->xschem_w, xctx->xschem_h, w, h); - } - */ - if(create_pixmap) { - xctx->save_pixmap = XCreatePixmap(display, xctx->window, xctx->xschem_w, xctx->xschem_h, depth); - } - XSetTile(display,gctiled, xctx->save_pixmap); - reset_cairo(create_pixmap, clear_pixmap); - } -#else - HWND hwnd = Tk_GetHWND(xctx->window); - RECT rct; - if (GetWindowRect(hwnd, &rct)) - { - unsigned int width = rct.right - rct.left; - unsigned int height = rct.bottom - rct.top; - xctx->xschem_w = width; - xctx->xschem_h = height; - xctx->areax2 = xctx->xschem_w + 2 * INT_WIDTH(xctx->lw); - xctx->areay2 = xctx->xschem_h + 2 * INT_WIDTH(xctx->lw); - xctx->areax1 = -2 * INT_WIDTH(xctx->lw); - xctx->areay1 = -2 * INT_WIDTH(xctx->lw); - xctx->areaw = xctx->areax2 - xctx->areax1; - xctx->areah = xctx->areay2 - xctx->areay1; - /* if no force avoid unnecessary work if no resize */ - if( force || xctx->xschem_w !=xctx->xrect[0].width || - xctx->xschem_h !=xctx->xrect[0].height) { - dbg(1, "resetwin(): x=%d y=%d xctx->xschem_w=%d xctx->xschem_h=%d\n", - rct.right, rct.bottom, xctx->xschem_w, xctx->xschem_h); - dbg(1, "resetwin(): changing size\n\n"); - xctx->xrect[0].x = 0; - xctx->xrect[0].y = 0; - xctx->xrect[0].width = xctx->xschem_w; - xctx->xrect[0].height = xctx->xschem_h; - if(clear_pixmap) Tk_FreePixmap(display, xctx->save_pixmap); - if(create_pixmap) { - xctx->save_pixmap = Tk_GetPixmap(display, xctx->window, xctx->xschem_w, xctx->xschem_h, depth); - } - XSetTile(display, gctiled, xctx->save_pixmap); - } - reset_cairo(create_pixmap, clear_pixmap); - } -#endif - if(pending_fullzoom) { - zoom_full(0, 0); - pending_fullzoom=0; - } - dbg(1, "resetwin(): Window reset\n"); - } /* end if(has_x) */ -} - void toggle_only_probes() { - static double save_lw; - if(!only_probes) { - save_lw = xctx->lw; - xctx->lw=3.0; - } else { - xctx->lw= save_lw; - } - only_probes =!only_probes; - if(only_probes) { - tclsetvar("only_probes","1"); - } - else { - tclsetvar("only_probes","0"); - } - change_linewidth(xctx->lw); - draw(); + static double save_lw; + if(!only_probes) { + save_lw = xctx->lw; + xctx->lw=3.0; + } else { + xctx->lw= save_lw; + } + only_probes =!only_probes; + if(only_probes) { + tclsetvar("only_probes","1"); + } + else { + tclsetvar("only_probes","0"); + } + change_linewidth(xctx->lw); + draw(); } void toggle_fullscreen() { - char fullscr[]="add,fullscreen"; - char normal[]="remove,fullscreen"; - static int menu_removed = 0; - fullscreen = (fullscreen+1)%2; - if(fullscreen==1) tclsetvar("fullscreen","1"); - else if(fullscreen==2) tclsetvar("fullscreen","2"); - else tclsetvar("fullscreen","0"); + char fullscr[]="add,fullscreen"; + char normal[]="remove,fullscreen"; + static int menu_removed = 0; + fullscreen = (fullscreen+1)%2; + if(fullscreen==1) tclsetvar("fullscreen","1"); + else if(fullscreen==2) tclsetvar("fullscreen","2"); + else tclsetvar("fullscreen","0"); - dbg(1, "toggle_fullscreen(): fullscreen=%d\n", fullscreen); - if(fullscreen==2) { - tcleval("pack forget .menubar .statusbar; update"); - menu_removed = 1; - } - if(fullscreen !=2 && menu_removed) { - tcleval("pack .menubar -anchor n -side top -fill x -before .drw\n\ - pack .statusbar -after .drw -anchor sw -fill x; update"); - menu_removed=0; - } + dbg(1, "toggle_fullscreen(): fullscreen=%d\n", fullscreen); + if(fullscreen==2) { + tcleval("pack forget .menubar .statusbar; update"); + menu_removed = 1; + } + if(fullscreen !=2 && menu_removed) { + tcleval("pack .menubar -anchor n -side top -fill x -before .drw\n\ + pack .statusbar -after .drw -anchor sw -fill x; update"); + menu_removed=0; + } - if(fullscreen == 1) { - window_state(display , parent_of_topwindow,fullscr); - } else if(fullscreen == 2) { - window_state(display , parent_of_topwindow,normal); - window_state(display , parent_of_topwindow,fullscr); - } else { - window_state(display , parent_of_topwindow,normal); - } - pending_fullzoom=1; + if(fullscreen == 1) { + window_state(display , parent_of_topwindow,fullscr); + } else if(fullscreen == 2) { + window_state(display , parent_of_topwindow,normal); + window_state(display , parent_of_topwindow,fullscr); + } else { + window_state(display , parent_of_topwindow,normal); + } + pending_fullzoom=1; } #ifdef __unix__ void new_window(const char *cell, int symbol) { + char f[PATH_MAX]; /* overflow safe 20161122 */ + struct stat buf; + pid_t pid1; + pid_t pid2; + int status; - char f[PATH_MAX]; /* overflow safe 20161122 */ - struct stat buf; - pid_t pid1; - pid_t pid2; - int status; + dbg(1, "new_window(): executable: %s, cell=%s, symbol=%d\n", xschem_executable, cell, symbol); + if(stat(xschem_executable,&buf)) { + fprintf(errfp, "new_window(): executable not found\n"); + return; + } - dbg(1, "new_window(): executable: %s, cell=%s, symbol=%d\n", xschem_executable, cell, symbol); - if(stat(xschem_executable,&buf)) { - fprintf(errfp, "new_window(): executable not found\n"); - return; - } - - /* double fork method to avoid zombies 20180925*/ - if ( (pid1 = fork()) ) { - /* parent process */ - waitpid(pid1, &status, 0); - } else if (!pid1) { - /* child process */ - if ( (pid2 = fork()) ) { - exit(0); /* --> child of child will be reparented to init */ - } else if (!pid2) { - /* child of child */ - if(!(freopen("/dev/null","w",stdout) && freopen("/dev/null","r",stdin) && - freopen("/dev/null","w",stderr))){ - fprintf(errfp, "new_window(): freopen error\n"); - tcleval("exit"); - } - if(!cell || !cell[0]) { - execl(xschem_executable,xschem_executable,"-r", NULL); - } - else if(!symbol) { - my_strncpy(f, cell, S(f)); - execl(xschem_executable,xschem_executable,"-r",f, NULL); - } - else { - my_strncpy(f, cell, S(f)); - execl(xschem_executable,xschem_executable,"-r",f, NULL); - } - } else { - /* error */ - fprintf(errfp, "new_window(): fork error 1\n"); - tcleval( "exit"); - } - } else { - /* error */ - fprintf(errfp, "new_window(): fork error 2\n"); - tcleval( "exit"); - } + /* double fork method to avoid zombies 20180925*/ + if ( (pid1 = fork()) ) { + /* parent process */ + waitpid(pid1, &status, 0); + } else if (!pid1) { + /* child process */ + if ( (pid2 = fork()) ) { + exit(0); /* --> child of child will be reparented to init */ + } else if (!pid2) { + /* child of child */ + if(!(freopen("/dev/null","w",stdout) && freopen("/dev/null","r",stdin) && + freopen("/dev/null","w",stderr))){ + fprintf(errfp, "new_window(): freopen error\n"); + tcleval("exit"); + } + if(!cell || !cell[0]) { + execl(xschem_executable,xschem_executable,"-r", NULL); + } + else if(!symbol) { + my_strncpy(f, cell, S(f)); + execl(xschem_executable,xschem_executable,"-r",f, NULL); + } + else { + my_strncpy(f, cell, S(f)); + execl(xschem_executable,xschem_executable,"-r",f, NULL); + } + } else { + /* error */ + fprintf(errfp, "new_window(): fork error 1\n"); + tcleval( "exit"); + } + } else { + /* error */ + fprintf(errfp, "new_window(): fork error 2\n"); + tcleval( "exit"); + } } #else @@ -1230,7 +1098,7 @@ void descend_schematic(int instnumber) my_strncpy(filename, add_ext(abs_sym_path(xctx->inst[xctx->sel_array[0].n].name, ""), ".sch"), S(filename)); load_schematic(1, filename, 1); } - if(hilight_nets) + if(xctx->hilight_nets) { prepare_netlist_structs(0); if(enable_drill) drill_hilight(); @@ -1295,37 +1163,21 @@ void go_back(int confirm) /* 20171006 add confirm */ } } -void change_linewidth(double w) +#ifndef __unix__ +/* Source: https://www.tcl.tk/man/tcl8.7/TclCmd/glob.htm */ +/* backslash character has a special meaning to glob command, +so glob patterns containing Windows style path separators need special care.*/ +void change_to_unix_fn(char* fn) { - int i, changed; - - changed=0; - /* choose line width automatically based on zoom */ - if(w<0.) { - if(change_lw) { - xctx->lw=xctx->mooz * 0.09 * cadsnap; - cadhalfdotsize = CADHALFDOTSIZE + 0.04 * (cadsnap-10); - changed=1; - } - /* explicitly set line width */ - } else { - xctx->lw=w; - changed=1; + int len, i, ii; + len = strlen(fn); + ii = 0; + for (i = 0; i < len; ++i) { + if (fn[i]!='\\') fn[ii++] = fn[i]; + else { fn[ii++] = '/'; if (fn[i + 1] == '\\') ++i; } } - if(!changed) return; - if(has_x) { - for(i=0;ilw), LineSolid, CapRound , JoinRound); - } - XSetLineAttributes (display, gctiled, INT_WIDTH(xctx->lw), LineSolid, CapRound , JoinRound); - } - xctx->areax1 = -2*INT_WIDTH(xctx->lw); - xctx->areay1 = -2*INT_WIDTH(xctx->lw); - xctx->areax2 = xctx->xrect[0].width+2*INT_WIDTH(xctx->lw); - xctx->areay2 = xctx->xrect[0].height+2*INT_WIDTH(xctx->lw); - xctx->areaw = xctx->areax2-xctx->areax1; - xctx->areah = xctx->areay2 - xctx->areay1; } +#endif void calc_drawing_bbox(xRect *boundbox, int selected) { @@ -1436,7 +1288,7 @@ void calc_drawing_bbox(xRect *boundbox, int selected) updatebbox(count,boundbox,&tmp); } #ifdef HAS_CAIRO - if(customfont) cairo_restore(cairo_ctx); + if(customfont) cairo_restore(xctx->cairo_ctx); #endif } for(i=0;iinstances;i++) @@ -1574,7 +1426,7 @@ void zoom_box(int what) { xctx->ui_state &= ~STARTZOOM; RECTORDER(x1,y1,x2,y2); - drawtemprect(gctiled, NOW, xx1,yy1,xx2,yy2); + drawtemprect(xctx->gctiled, NOW, xx1,yy1,xx2,yy2); xctx->xorigin=-x1;xctx->yorigin=-y1; xctx->zoom=(x2-x1)/(xctx->areaw-4*INT_WIDTH(xctx->lw)); yy1=(y2-y1)/(xctx->areah-4*INT_WIDTH(xctx->lw)); @@ -1589,7 +1441,7 @@ void zoom_box(int what) { xx1=x1;yy1=y1;xx2=x2;yy2=y2; RECTORDER(xx1,yy1,xx2,yy2); - drawtemprect(gctiled,NOW, xx1,yy1,xx2,yy2); + drawtemprect(xctx->gctiled,NOW, xx1,yy1,xx2,yy2); x2=xctx->mousex_snap;y2=xctx->mousey_snap; @@ -1789,10 +1641,10 @@ void new_wire(int what, double mx_snap, double my_snap) if(manhattan_lines==1) { xx1=x1;yy1=y1;xx2=x2;yy2=y2; ORDER(xx1,yy1,xx2,yy1); - drawtempline(gctiled, NOW, xx1,yy1,xx2,yy1); + drawtempline(xctx->gctiled, NOW, xx1,yy1,xx2,yy1); xx1=x1;yy1=y1;xx2=x2;yy2=y2; ORDER(xx2,yy1,xx2,yy2); - drawtempline(gctiled, NOW, xx2,yy1,xx2,yy2); + drawtempline(xctx->gctiled, NOW, xx2,yy1,xx2,yy2); restore_selection(x1, y1, x2, y2); x2 = mx_snap; y2 = my_snap; if(!(what & CLEAR)) { @@ -1806,10 +1658,10 @@ void new_wire(int what, double mx_snap, double my_snap) } else if(manhattan_lines==2) { xx1 = x1; yy1 = y1; xx2 = x2; yy2 = y2; ORDER(xx1,yy1,xx1,yy2); - drawtempline(gctiled, NOW, xx1,yy1,xx1,yy2); + drawtempline(xctx->gctiled, NOW, xx1,yy1,xx1,yy2); xx1 = x1; yy1 = y1; xx2 = x2; yy2 = y2; ORDER(xx1,yy2,xx2,yy2); - drawtempline(gctiled, NOW, xx1,yy2,xx2,yy2); + drawtempline(xctx->gctiled, NOW, xx1,yy2,xx2,yy2); restore_selection(x1, y1, x2, y2); x2 = mx_snap; y2 = my_snap; if(!(what & CLEAR)) { @@ -1823,7 +1675,7 @@ void new_wire(int what, double mx_snap, double my_snap) } else { xx1 = x1; yy1 = y1; xx2 = x2; yy2 = y2; ORDER(xx1,yy1,xx2,yy2); - drawtempline(gctiled, NOW, xx1,yy1,xx2,yy2); + drawtempline(xctx->gctiled, NOW, xx1,yy1,xx2,yy2); restore_selection(x1, y1, x2, y2); x2 = mx_snap; y2 = my_snap; if(!(what & CLEAR)) { @@ -1897,7 +1749,7 @@ void new_arc(int what, double sweep) if(state==0) { x2 = xctx->mousex_snap; y2 = xctx->mousey_snap; - drawtempline(gctiled, NOW, xx1,yy1,xx2,yy2); + drawtempline(xctx->gctiled, NOW, xx1,yy1,xx2,yy2); state=1; } else if(state==1) { x3 = xctx->mousex_snap; @@ -1915,7 +1767,7 @@ void new_arc(int what, double sweep) } if(what & RUBBER) { if(state==0) { - drawtempline(gctiled, NOW, xx1,yy1,xx2,yy2); + drawtempline(xctx->gctiled, NOW, xx1,yy1,xx2,yy2); xx2 = xctx->mousex_snap; yy2 = xctx->mousey_snap; xx1 = x1;yy1 = y1; @@ -1925,7 +1777,7 @@ void new_arc(int what, double sweep) else if(state==1) { x3 = xctx->mousex_snap; y3 = xctx->mousey_snap; - if(r>0.) drawtemparc(gctiled, NOW, x, y, r, a, b); + if(r>0.) drawtemparc(xctx->gctiled, NOW, x, y, r, a, b); arc_3_points(x1, y1, x2, y2, x3, y3, &x, &y, &r, &a, &b); if(sweep_angle==360.) b=360.; if(r>0.) drawtemparc(gc[rectcolor], NOW, x, y, r, a, b); @@ -1988,10 +1840,10 @@ void new_line(int what) if(manhattan_lines==1) { xx1=x1;yy1=y1;xx2=x2;yy2=y2; ORDER(xx1,yy1,xx2,yy1); - drawtempline(gctiled, NOW, xx1,yy1,xx2,yy1); + drawtempline(xctx->gctiled, NOW, xx1,yy1,xx2,yy1); xx1=x1;yy1=y1;xx2=x2;yy2=y2; ORDER(xx2,yy1,xx2,yy2); - drawtempline(gctiled, NOW, xx2,yy1,xx2,yy2); + drawtempline(xctx->gctiled, NOW, xx2,yy1,xx2,yy2); restore_selection(x1, y1, x2, y2); x2 = xctx->mousex_snap; y2 = xctx->mousey_snap; if(!(what & CLEAR)) { @@ -2005,10 +1857,10 @@ void new_line(int what) } else if(manhattan_lines==2) { xx1 = x1; yy1 = y1; xx2 = x2; yy2 = y2; ORDER(xx1,yy1,xx1,yy2); - drawtempline(gctiled, NOW, xx1,yy1,xx1,yy2); + drawtempline(xctx->gctiled, NOW, xx1,yy1,xx1,yy2); xx1 = x1; yy1 = y1; xx2 = x2; yy2 = y2; ORDER(xx1,yy2,xx2,yy2); - drawtempline(gctiled, NOW, xx1,yy2,xx2,yy2); + drawtempline(xctx->gctiled, NOW, xx1,yy2,xx2,yy2); restore_selection(x1, y1, x2, y2); x2 = xctx->mousex_snap; y2 = xctx->mousey_snap; if(!(what & CLEAR)) { @@ -2022,7 +1874,7 @@ void new_line(int what) } else { xx1 = x1; yy1 = y1; xx2 = x2; yy2 = y2; ORDER(xx1,yy1,xx2,yy2); - drawtempline(gctiled, NOW, xx1,yy1,xx2,yy2); + drawtempline(xctx->gctiled, NOW, xx1,yy1,xx2,yy2); restore_selection(x1, y1, x2, y2); x2 = xctx->mousex_snap; y2 = xctx->mousey_snap; if(!(what & CLEAR)) { @@ -2064,7 +1916,7 @@ void new_rect(int what) { xx1=x1;yy1=y1;xx2=x2;yy2=y2; RECTORDER(xx1,yy1,xx2,yy2); - drawtemprect(gctiled,NOW, xx1,yy1,xx2,yy2); + drawtemprect(xctx->gctiled,NOW, xx1,yy1,xx2,yy2); x2=xctx->mousex_snap;y2=xctx->mousey_snap; xx1=x1;yy1=y1;xx2=x2;yy2=y2; RECTORDER(xx1,yy1,xx2,yy2); @@ -2102,7 +1954,7 @@ void new_polygon(int what) /* closed poly */ if(what & END) { /* delete last rubber */ - drawtemppolygon(gctiled, NOW, x, y, points+1); + drawtemppolygon(xctx->gctiled, NOW, x, y, points+1); x[points] = x[0]; y[points] = y[0]; /* add point */ @@ -2121,7 +1973,7 @@ void new_polygon(int what) /* closed poly end by clicking on first point */ ((what & ADD) && x[points-1] == x[0] && y[points-1] == y[0]) ) { push_undo(); - drawtemppolygon(gctiled, NOW, x, y, points+1); + drawtemppolygon(xctx->gctiled, NOW, x, y, points+1); store_poly(-1, x, y, points, rectcolor, 0, NULL); /* fprintf(errfp, "new_poly: finish: points=%d\n", points); */ drawtemppolygon(gc[rectcolor], NOW, x, y, points); @@ -2134,7 +1986,7 @@ void new_polygon(int what) if(what & RUBBER) { /* fprintf(errfp, "new_poly: RUBBER\n"); */ - drawtemppolygon(gctiled, NOW, x, y, points+1); + drawtemppolygon(xctx->gctiled, NOW, x, y, points+1); y[points] = xctx->mousey_snap; x[points] = xctx->mousex_snap; drawtemppolygon(gc[rectcolor], NOW, x, y, points+1); @@ -2159,8 +2011,8 @@ int text_bbox(const char *str, double xscale, double yscale, /* if(size*xctx->mooz>800.) { */ /* return 0; */ /* } */ - cairo_set_font_size (cairo_ctx, size*xctx->mooz); - cairo_font_extents(cairo_ctx, &fext); + cairo_set_font_size (xctx->cairo_ctx, size*xctx->mooz); + cairo_font_extents(xctx->cairo_ctx, &fext); ww=0.; hh=1.; c=0; @@ -2173,7 +2025,7 @@ int text_bbox(const char *str, double xscale, double yscale, hh++; cairo_lines++; if(str_ptr[0]!='\0') { - cairo_text_extents(cairo_ctx, str_ptr, &ext); + cairo_text_extents(xctx->cairo_ctx, str_ptr, &ext); maxw = ext.x_advance > ext.width ? ext.x_advance : ext.width; if(maxw > ww) ww= maxw; } @@ -2184,7 +2036,7 @@ int text_bbox(const char *str, double xscale, double yscale, c++; } if(str_ptr && str_ptr[0]!='\0') { - cairo_text_extents(cairo_ctx, str_ptr, &ext); + cairo_text_extents(xctx->cairo_ctx, str_ptr, &ext); maxw = ext.x_advance > ext.width ? ext.x_advance : ext.width; if(maxw > ww) ww= maxw; } @@ -2352,9 +2204,9 @@ void place_text(int draw_text, double mx, double my) slant = CAIRO_FONT_SLANT_NORMAL; if(t->flags & TEXT_ITALIC) slant = CAIRO_FONT_SLANT_ITALIC; if(t->flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE; - cairo_save(cairo_ctx); + cairo_save(xctx->cairo_ctx); cairo_save(xctx->cairo_save_ctx); - cairo_select_font_face (cairo_ctx, textfont, slant, weight); + cairo_select_font_face (xctx->cairo_ctx, textfont, slant, weight); cairo_select_font_face (xctx->cairo_save_ctx, textfont, slant, weight); } #endif @@ -2366,7 +2218,7 @@ void place_text(int draw_text, double mx, double my) draw_window = save_draw; #ifdef HAS_CAIRO if((textfont && textfont[0]) || t->flags) { - cairo_restore(cairo_ctx); + cairo_restore(xctx->cairo_ctx); cairo_restore(xctx->cairo_save_ctx); } #endif @@ -2412,7 +2264,7 @@ void pan(int what) { xx1=xpan;yy1=ypan;xx2=xpan2;yy2=ypan2; ORDER(xx1,yy1,xx2,yy2); - drawtempline(gctiled, NOW, xx1,yy1,xx2,yy2); + drawtempline(xctx->gctiled, NOW, xx1,yy1,xx2,yy2); xpan2=xctx->mousex_snap;ypan2=xctx->mousey_snap; xx1=xpan;yy1=ypan;xx2=xpan2;yy2=ypan2; ORDER(xx1,yy1,xx2,yy2); @@ -2447,7 +2299,7 @@ void select_rect(int what, int select) } xx1=xr;xx2=xr2;yy1=yr;yy2=yr2; RECTORDER(xx1,yy1,xx2,yy2); - drawtemprect(gctiled,NOW, xx1,yy1,xx2,yy2); + drawtemprect(xctx->gctiled,NOW, xx1,yy1,xx2,yy2); xr2=xctx->mousex_snap;yr2=xctx->mousey_snap; /* 20171026 update unselected objects while dragging */ @@ -2486,7 +2338,7 @@ void select_rect(int what, int select) else if(what & END) { RECTORDER(xr,yr,xr2,yr2); - drawtemprect(gctiled, NOW, xr,yr,xr2,yr2); + drawtemprect(xctx->gctiled, NOW, xr,yr,xr2,yr2); /* draw_selection(gc[SELLAYER], 0); */ select_inside(xr,yr,xr2,yr2, sel); diff --git a/src/callback.c b/src/callback.c index 171e2e8c..fd2ba553 100644 --- a/src/callback.c +++ b/src/callback.c @@ -129,7 +129,7 @@ int callback(int event, int mx, int my, KeySym key, if(event != MotionNotify) fprintf(errfp, "callback(): reentrant call of callback(), xctx->semaphore=%d\n", xctx->semaphore); /* if(event==Expose) { - * XCopyArea(display, xctx->save_pixmap, xctx->window, gctiled, mx,my,button,aux,mx,my); + * XCopyArea(display, xctx->save_pixmap, xctx->window, xctx->gctiled, mx,my,button,aux,mx,my); * * } */ @@ -168,7 +168,7 @@ int callback(int event, int mx, int my, KeySym key, break; case Expose: - XCopyArea(display, xctx->save_pixmap, xctx->window, gctiled, mx,my,button,aux,mx,my); + XCopyArea(display, xctx->save_pixmap, xctx->window, xctx->gctiled, mx,my,button,aux,mx,my); { XRectangle xr[1]; xr[0].x=mx; @@ -196,7 +196,7 @@ int callback(int event, int mx, int my, KeySym key, (xctx->ui_state & STARTCOPY) || (xctx->ui_state & STARTRECT) || (xctx->ui_state & STARTPOLYGON) || (xctx->ui_state & STARTPAN2) || (xctx->ui_state & STARTPAN) || (xctx->ui_state & STARTSELECT)) { - XCopyArea(display, xctx->save_pixmap, xctx->window, gctiled, xctx->xrect[0].x, xctx->xrect[0].y, + XCopyArea(display, xctx->save_pixmap, xctx->window, xctx->gctiled, xctx->xrect[0].x, xctx->xrect[0].y, xctx->xrect[0].width, xctx->xrect[0].height, xctx->xrect[0].x, xctx->xrect[0].y); } #endif @@ -205,7 +205,7 @@ int callback(int event, int mx, int my, KeySym key, #ifdef TURBOX_FIX /* fix Exceed TurboX bugs when drawing with pixmap tiled fill pattern */ /* *NOT* a solution but at least makes the program useable. 20171130 */ - XSetClipRectangles(display, gctiled, 0,0, xctx->xrect, 1, Unsorted); + XSetClipRectangles(display, xctx->gctiled, 0,0, xctx->xrect, 1, Unsorted); #endif my_snprintf(str, S(str), "mouse = %.16g %.16g - selected: %d w=%.16g h=%.16g", xctx->mousex_snap, xctx->mousey_snap, @@ -1632,7 +1632,7 @@ int callback(int event, int mx, int my, KeySym key, if( !(state & ShiftMask) && !(state & Mod1Mask) ) { unselect_all(); #ifndef __unix__ - XCopyArea(display, xctx->save_pixmap, xctx->window, gctiled, xctx->xrect[0].x, xctx->xrect[0].y, + XCopyArea(display, xctx->save_pixmap, xctx->window, xctx->gctiled, xctx->xrect[0].x, xctx->xrect[0].y, xctx->xrect[0].width, xctx->xrect[0].height, xctx->xrect[0].x, xctx->xrect[0].y); #endif } @@ -1646,7 +1646,7 @@ int callback(int event, int mx, int my, KeySym key, } if( !(state & ShiftMask) ) { xRect boundbox; - if(auto_hilight && hilight_nets && sel == 0 ) { /* 20160413 20160503 */ + if(auto_hilight && xctx->hilight_nets && sel == 0 ) { /* 20160413 20160503 */ if(!prev_last_sel) { int big = xctx->wires> 2000 || xctx->instances > 2000 ; if(!big) calc_drawing_bbox(&boundbox, 2); diff --git a/src/draw.c b/src/draw.c index 4e53eff3..22c57ff3 100644 --- a/src/draw.c +++ b/src/draw.c @@ -105,27 +105,27 @@ void print_image() Tk_FreePixmap(display, xctx->save_pixmap); xctx->save_pixmap = Tk_GetPixmap(display, xctx->window, w, h, depth); #endif - XSetTile(display, gctiled, xctx->save_pixmap); + XSetTile(display, xctx->gctiled, xctx->save_pixmap); #ifdef HAS_CAIRO cairo_destroy(xctx->cairo_save_ctx); - cairo_surface_destroy(xctx->save_sfc); + cairo_surface_destroy(xctx->cairo_save_sfc); #if HAS_XRENDER==1 #if HAS_XCB==1 - xctx->save_sfc = cairo_xcb_surface_create_with_xrender_format(xcbconn, screen_xcb, xctx->save_pixmap, &format_rgb, w, h); + xctx->cairo_save_sfc = cairo_xcb_surface_create_with_xrender_format(xcbconn, screen_xcb, xctx->save_pixmap, &format_rgb, w, h); #else - xctx->save_sfc = cairo_xlib_surface_create_with_xrender_format(display, + xctx->cairo_save_sfc = cairo_xlib_surface_create_with_xrender_format(display, xctx->save_pixmap, DefaultScreenOfDisplay(display), format, w, h); #endif /*HAS_XCB */ #else - xctx->save_sfc = cairo_xlib_surface_create(display, xctx->save_pixmap, visual, w, h); + xctx->cairo_save_sfc = cairo_xlib_surface_create(display, xctx->save_pixmap, visual, w, h); #endif /*HAS_XRENDER */ - if(cairo_surface_status(xctx->save_sfc)!=CAIRO_STATUS_SUCCESS) { + if(cairo_surface_status(xctx->cairo_save_sfc)!=CAIRO_STATUS_SUCCESS) { fprintf(errfp, "ERROR: invalid cairo xcb surface\n"); exit(-1); } - xctx->cairo_save_ctx = cairo_create(xctx->save_sfc); + xctx->cairo_save_ctx = cairo_create(xctx->cairo_save_sfc); cairo_set_line_width(xctx->cairo_save_ctx, 1); cairo_set_line_join(xctx->cairo_save_ctx, CAIRO_LINE_JOIN_ROUND); cairo_set_line_cap(xctx->cairo_save_ctx, CAIRO_LINE_CAP_ROUND); @@ -138,7 +138,7 @@ void print_image() XSetClipRectangles(display, gc[tmp], 0,0, xctx->xrect, 1, Unsorted); XSetClipRectangles(display, gcstipple[tmp], 0,0, xctx->xrect, 1, Unsorted); } - XSetClipRectangles(display, gctiled, 0,0, xctx->xrect, 1, Unsorted); + XSetClipRectangles(display, xctx->gctiled, 0,0, xctx->xrect, 1, Unsorted); save_draw_grid = draw_grid; draw_grid=0; draw_pixmap=1; @@ -180,28 +180,28 @@ void print_image() Tk_FreePixmap(display, xctx->save_pixmap); xctx->save_pixmap = Tk_GetPixmap(display, xctx->window, xctx->areaw, xctx->areah, depth); #endif - XSetTile(display, gctiled, xctx->save_pixmap); + XSetTile(display, xctx->gctiled, xctx->save_pixmap); #ifdef HAS_CAIRO cairo_destroy(xctx->cairo_save_ctx); - cairo_surface_destroy(xctx->save_sfc); + cairo_surface_destroy(xctx->cairo_save_sfc); #if HAS_XRENDER==1 #if HAS_XCB==1 - xctx->save_sfc = cairo_xcb_surface_create_with_xrender_format(xcbconn, screen_xcb, xctx->save_pixmap, &format_rgb, w, h); + xctx->cairo_save_sfc = cairo_xcb_surface_create_with_xrender_format(xcbconn, screen_xcb, xctx->save_pixmap, &format_rgb, w, h); #else - xctx->save_sfc = cairo_xlib_surface_create_with_xrender_format (display, + xctx->cairo_save_sfc = cairo_xlib_surface_create_with_xrender_format (display, xctx->save_pixmap, DefaultScreenOfDisplay(display), format, w, h); #endif /*HAS_XCB */ #else - xctx->save_sfc = cairo_xlib_surface_create(display, xctx->save_pixmap, visual, w, h); + xctx->cairo_save_sfc = cairo_xlib_surface_create(display, xctx->save_pixmap, visual, w, h); #endif /*HAS_XRENDER */ - if(cairo_surface_status(xctx->save_sfc)!=CAIRO_STATUS_SUCCESS) { + if(cairo_surface_status(xctx->cairo_save_sfc)!=CAIRO_STATUS_SUCCESS) { fprintf(errfp, "ERROR: invalid cairo xcb surface\n"); exit(-1); } - xctx->cairo_save_ctx = cairo_create(xctx->save_sfc); + xctx->cairo_save_ctx = cairo_create(xctx->cairo_save_sfc); cairo_set_line_width(xctx->cairo_save_ctx, 1); cairo_set_line_join(xctx->cairo_save_ctx, CAIRO_LINE_JOIN_ROUND); cairo_set_line_cap(xctx->cairo_save_ctx, CAIRO_LINE_CAP_ROUND); @@ -214,7 +214,7 @@ void print_image() XSetClipMask(display, gc[tmp], None); /*20171110 no need to clip, already done in software */ XSetClipMask(display, gcstipple[tmp], None); } - XSetClipMask(display, gctiled, None); + XSetClipMask(display, xctx->gctiled, None); XMapWindow(display, xctx->window); draw_grid=save_draw_grid; @@ -226,7 +226,7 @@ void print_image() #ifdef HAS_CAIRO void set_cairo_color(int layer) { - cairo_set_source_rgb(cairo_ctx, + cairo_set_source_rgb(xctx->cairo_ctx, (double)xcolor_array[layer].red/65535.0, (double)xcolor_array[layer].green/65535.0, (double)xcolor_array[layer].blue/65535.0); @@ -236,7 +236,7 @@ void set_cairo_color(int layer) (double)xcolor_array[layer].blue/65535.0); } -/* remember to call cairo_restore(cairo_ctx) when done !! */ +/* remember to call cairo_restore(xctx->cairo_ctx) when done !! */ int set_text_custom_font(xText *txt) /* 20171122 for correct text_bbox calculation */ { char *textfont; @@ -250,8 +250,8 @@ int set_text_custom_font(xText *txt) /* 20171122 for correct text_bbox calculati slant = CAIRO_FONT_SLANT_NORMAL; if(txt->flags & TEXT_ITALIC) slant = CAIRO_FONT_SLANT_ITALIC; if(txt->flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE; - cairo_save(cairo_ctx); - cairo_select_font_face (cairo_ctx, textfont, slant, weight); + cairo_save(xctx->cairo_ctx); + cairo_select_font_face (xctx->cairo_ctx, textfont, slant, weight); return 1; } return 0; @@ -353,9 +353,9 @@ void draw_string(int layer, int what, const char *str, short rot, short flip, in } set_cairo_color(layer); - cairo_set_font_size (cairo_ctx, size*xctx->mooz); + cairo_set_font_size (xctx->cairo_ctx, size*xctx->mooz); cairo_set_font_size (xctx->cairo_save_ctx, size*xctx->mooz); - cairo_font_extents(cairo_ctx, &fext); + cairo_font_extents(xctx->cairo_ctx, &fext); dbg(1, "draw_string(): size * mooz=%g height=%g ascent=%g descent=%g\n", size * xctx->mooz, fext.height, fext.ascent, fext.descent); llength=0; @@ -366,7 +366,7 @@ void draw_string(int layer, int what, const char *str, short rot, short flip, in if(c=='\n' || c==0) { *ss='\0'; /*fprintf(errfp, "cairo_draw_string(): tt=%s, longest line: %d\n", tt, cairo_longest_line); */ - if(draw_window) cairo_draw_string_line(cairo_ctx, tt, x, y, rot, flip, + if(draw_window) cairo_draw_string_line(xctx->cairo_ctx, tt, x, y, rot, flip, lineno, fext.height, fext.ascent, fext.descent, llength); if(draw_pixmap) cairo_draw_string_line(xctx->cairo_save_ctx, tt, x, y, rot, flip, lineno, fext.height, fext.ascent, fext.descent, llength); @@ -600,9 +600,9 @@ void draw_symbol(int what,int c, int n,int layer,short tmp_flip, short rot, if(symptr->text[j].flags & TEXT_ITALIC) slant = CAIRO_FONT_SLANT_ITALIC; if(symptr->text[j].flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE; - cairo_save(cairo_ctx); + cairo_save(xctx->cairo_ctx); cairo_save(xctx->cairo_save_ctx); - cairo_select_font_face (cairo_ctx, textfont, slant, weight); + cairo_select_font_face (xctx->cairo_ctx, textfont, slant, weight); cairo_select_font_face (xctx->cairo_save_ctx, textfont, slant, weight); } #endif @@ -617,7 +617,7 @@ void draw_symbol(int what,int c, int n,int layer,short tmp_flip, short rot, #endif #ifdef HAS_CAIRO if( (textfont && textfont[0]) || symptr->text[j].flags) { - cairo_restore(cairo_ctx); + cairo_restore(xctx->cairo_ctx); cairo_restore(xctx->cairo_save_ctx); } #endif @@ -743,7 +743,7 @@ void draw_temp_symbol(int what, GC gc, int n,int layer,short tmp_flip, short rot (text.rot + ( (flip && (text.rot & 1) ) ? rot+2 : rot) ) & 0x3, flip^text.flip, text.hcenter, text.vcenter, x0+x1, y0+y1, text.xscale, text.yscale); #ifdef HAS_CAIRO - if(customfont) cairo_restore(cairo_ctx); + if(customfont) cairo_restore(xctx->cairo_ctx); #endif } @@ -1629,7 +1629,7 @@ void draw(void) type = symptr->type; if(!( - hilight_nets && + xctx->hilight_nets && type && ( ( @@ -1663,7 +1663,7 @@ void draw(void) type = (xctx->inst[i].ptr+ xctx->sym)->type; if(!( - hilight_nets && + xctx->hilight_nets && type && ( ( @@ -1737,9 +1737,9 @@ void draw(void) if(xctx->text[i].flags & TEXT_ITALIC) slant = CAIRO_FONT_SLANT_ITALIC; if(xctx->text[i].flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE; - cairo_save(cairo_ctx); + cairo_save(xctx->cairo_ctx); cairo_save(xctx->cairo_save_ctx); - cairo_select_font_face (cairo_ctx, textfont, slant, weight); + cairo_select_font_face (xctx->cairo_ctx, textfont, slant, weight); cairo_select_font_face (xctx->cairo_save_ctx, textfont, slant, weight); } #endif @@ -1750,7 +1750,7 @@ void draw(void) xctx->text[i].xscale, xctx->text[i].yscale); #ifdef HAS_CAIRO if((textfont && textfont[0]) || xctx->text[i].flags ) { - cairo_restore(cairo_ctx); + cairo_restore(xctx->cairo_ctx); cairo_restore(xctx->cairo_save_ctx); } #endif @@ -1763,7 +1763,7 @@ void draw(void) } /* !only_probes, 20110112 */ draw_hilight_net(draw_window); if(!draw_window) { - XCopyArea(display, xctx->save_pixmap, xctx->window, gctiled, xctx->xrect[0].x, xctx->xrect[0].y, + XCopyArea(display, xctx->save_pixmap, xctx->window, xctx->gctiled, xctx->xrect[0].x, xctx->xrect[0].y, xctx->xrect[0].width, xctx->xrect[0].height, xctx->xrect[0].x, xctx->xrect[0].y); } draw_selection(gc[SELLAYER], 0); /* 20181009 moved outside of cadlayers loop */ diff --git a/src/editprop.c b/src/editprop.c index 8317101c..0f12467f 100644 --- a/src/editprop.c +++ b/src/editprop.c @@ -764,7 +764,7 @@ void edit_text_property(int x) xctx->text[sel].x0, xctx->text[sel].y0, &xx1,&yy1,&xx2,&yy2); #ifdef HAS_CAIRO - if(customfont) cairo_restore(cairo_ctx); + if(customfont) cairo_restore(xctx->cairo_ctx); #endif bbox(ADD, xx1, yy1, xx2, yy2 ); @@ -785,7 +785,7 @@ void edit_text_property(int x) xctx->text[sel].x0, xctx->text[sel].y0, &xx1,&yy1,&xx2,&yy2); #ifdef HAS_CAIRO - if(customfont) cairo_restore(cairo_ctx); + if(customfont) cairo_restore(xctx->cairo_ctx); #endif pcx = (xctx->rect[PINLAYER][l].x1+xctx->rect[PINLAYER][l].x2)/2.0; @@ -849,7 +849,7 @@ void edit_text_property(int x) xctx->text[sel].x0, xctx->text[sel].y0, &xx1,&yy1,&xx2,&yy2); #ifdef HAS_CAIRO - if(customfont) cairo_restore(cairo_ctx); + if(customfont) cairo_restore(xctx->cairo_ctx); #endif bbox(ADD, xx1, yy1, xx2, yy2 ); @@ -1062,7 +1062,7 @@ void update_symbol(const char *result, int x) and drawn back unhilighted . | \|/ */ - if(show_pin_net_names || hilight_nets) { + if(show_pin_net_names || xctx->hilight_nets) { prepare_netlist_structs(0); for(k = 0; k < (xctx->inst[i].ptr + xctx->sym)->rects[PINLAYER]; k++) { if( xctx->inst[i].node && xctx->inst[i].node[k]) { diff --git a/src/findnet.c b/src/findnet.c index 6dde465c..9f2ed85a 100644 --- a/src/findnet.c +++ b/src/findnet.c @@ -290,7 +290,7 @@ void find_closest_text(double mx,double my) xctx->text[i].x0, xctx->text[i].y0, &xx1,&yy1, &xx2,&yy2); #ifdef HAS_CAIRO - if(customfont) cairo_restore(cairo_ctx); + if(customfont) cairo_restore(xctx->cairo_ctx); #endif if(POINTINSIDE(mx,my,xx1,yy1, xx2, yy2)) { diff --git a/src/globals.c b/src/globals.c index c6f85b5f..3f7211db 100644 --- a/src/globals.c +++ b/src/globals.c @@ -95,7 +95,7 @@ unsigned char pixdata_init[22][32]={ /* fill patterns... indexed by laynumb. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},/*20 */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}/*21 */ }; -GC *gcstipple,*gc, gctiled; +GC *gcstipple,*gc; Pixmap *pixmap = NULL; Display *display; Pixmap cad_icon_pixmap=0, cad_icon_mask=0; @@ -103,9 +103,7 @@ XPoint *gridpoint; /* pointer to array of gridpoints, used in draw() */ XColor xcolor_array[256]; Visual *visual; #ifdef HAS_CAIRO -XRenderPictFormat *format; -cairo_surface_t *sfc; -cairo_t *cairo_ctx; +XRenderPictFormat *render_format; #if HAS_XCB==1 xcb_connection_t *xcbconn; @@ -115,8 +113,6 @@ xcb_visualtype_t *visual_xcb; #endif /*HAS_XCB */ #endif /*HAS_CAIRO */ - - /* these variables are mirrored in tcl code */ int fullscreen=0; char *netlist_dir=NULL; /* user set netlist directory via cmd-option or menu or xschemrc */ @@ -214,7 +210,6 @@ char hiersep[20]="."; char bus_char[3] = {0, 0, 0}; int horizontal_move=0; int vertical_move=0; -int hilight_color=0; int pending_fullzoom=0; double color_dim=0.0; int no_undo=0; @@ -225,7 +220,6 @@ int batch_mode = 0; /* no tcl console if set; batch mode */ int cairo_longest_line; int cairo_lines; int show_erc=1; -int hilight_nets=0; /* following data is relative to the current schematic */ Xschem_ctx *xctx; diff --git a/src/hilight.c b/src/hilight.c index dde9ba4e..8e546a8e 100644 --- a/src/hilight.c +++ b/src/hilight.c @@ -22,8 +22,6 @@ #include "xschem.h" -static struct hilight_hashentry *hilight_table[HASHSIZE]; -static int nelements=0; static int *inst_color=NULL; static unsigned int hi_hash(const char *tok) @@ -59,7 +57,7 @@ void display_hilights(char **str) int first = 1; struct hilight_hashentry *entry; for(i=0;ihilight_table[i]; while(entry) { if(!first) my_strcat(93, str, " "); my_strcat(943, str,"{"); @@ -79,10 +77,8 @@ void free_hilight_hash(void) /* remove the whole hash table */ dbg(2, "free_hilight_hash(): removing hash table\n"); for(i=0;ihilight_table[i] = free_hilight_entry( xctx->hilight_table[i] ); } - dbg(2, "free_hilight_hash(): : nelements=%d\n", nelements); - nelements=0; } @@ -119,7 +115,7 @@ void create_plot_cmd(int viewer) first = 1; for(i=0;ihilight_table[i]; while(entry) { tok = entry->token; node_entry = bus_hash_lookup(tok, "", XLOOKUP, 0, "", "", "", ""); @@ -191,8 +187,8 @@ struct hilight_hashentry *hilight_lookup(const char *token, int value, int remov if(token==NULL) return NULL; hashcode=hi_hash(token); index=hashcode % HASHSIZE; - entry=hilight_table[index]; - preventry=&hilight_table[index]; + entry=xctx->hilight_table[index]; + preventry=&xctx->hilight_table[index]; depth=0; while(1) { @@ -211,8 +207,7 @@ struct hilight_hashentry *hilight_lookup(const char *token, int value, int remov entry->value=value; entry->hash=hashcode; *preventry=entry; - hilight_nets=1; /* some nets should be hilighted .... 07122002 */ - nelements++; + xctx->hilight_nets=1; /* some nets should be hilighted .... 07122002 */ } return NULL; /* whether inserted or not return NULL since it was not in */ } @@ -288,18 +283,19 @@ struct hilight_hashentry *bus_hilight_lookup(const char *token, int value, int r void delete_hilight_net(void) { - int i; - if(!hilight_nets) return; - free_hilight_hash(); - - hilight_nets=0; - for(i=0;iinstances;i++) { - xctx->inst[i].flags &= ~4 ; - } - dbg(1, "delete_hilight_net(): clearing\n"); - my_free(766, &inst_color); - hilight_color=0; + int i; + if(!xctx->hilight_nets) return; + free_hilight_hash(); + + xctx->hilight_nets=0; + for(i=0;iinstances;i++) { + xctx->inst[i].flags &= ~4 ; + } + dbg(1, "delete_hilight_net(): clearing\n"); + my_free(766, &inst_color); + xctx->hilight_color=0; } + void hilight_net_pin_mismatches(void) { int i,j,k; @@ -330,8 +326,8 @@ void hilight_net_pin_mismatches(void) dbg(1, "delete_hilight_net(): i=%d labname=%s explabname = %s net = %s\n", i, labname, lab, netname); if(netname && strcmp(lab, netname)) { dbg(1, "delete_hilight_net(): hilight: %s\n", netname); - bus_hilight_lookup(netname, hilight_color, XINSERT); - if(incr_hilight) hilight_color++; + bus_hilight_lookup(netname, xctx->hilight_color, XINSERT); + if(incr_hilight) xctx->hilight_color++; } } @@ -352,7 +348,7 @@ void hilight_parent_pins(void) char *net_node=NULL; int mult, net_mult, inst_number; - if(!hilight_nets) return; + if(!xctx->hilight_nets) return; prepare_netlist_structs(0); i=xctx->previous_instance[xctx->currsch]; inst_number = xctx->sch_inst_number[xctx->currsch+1]; @@ -401,7 +397,7 @@ void hilight_child_pins(void) int mult, net_mult, i, inst_number; i = xctx->previous_instance[xctx->currsch-1]; - if(!hilight_nets) return; + if(!xctx->hilight_nets) return; prepare_netlist_structs(0); rects = (xctx->inst[i].ptr+ xctx->sym)->rects[PINLAYER]; inst_number = xctx->sch_inst_number[xctx->currsch]; @@ -477,9 +473,9 @@ int search(const char *tok, const char *val, int sub, int sel, int what) if(what==ADD || what==NOW) { if(!sel) { - col=hilight_color; + col=xctx->hilight_color; hilight_layer = get_color(col); - if(incr_hilight) hilight_color++; + if(incr_hilight) xctx->hilight_color++; } has_token = 0; prepare_netlist_structs(0); @@ -520,13 +516,13 @@ int search(const char *tok, const char *val, int sub, int sel, int what) if(!sel) { type = (xctx->inst[i].ptr+ xctx->sym)->type; if( type && IS_LABEL_SH_OR_PIN(type) ) { - if(!bus_hilight_lookup(xctx->inst[i].node[0], col, XINSERT)) hilight_nets = 1; + if(!bus_hilight_lookup(xctx->inst[i].node[0], col, XINSERT)) xctx->hilight_nets = 1; if(what==NOW) for(c=0;chilight_nets=1; xctx->inst[i].flags |= 4; if(what==NOW) for(c=0;chilight_color, XINSERT)) { + xctx->hilight_nets=1; + if(incr_hilight) xctx->hilight_color++; redraw_hilights(); } return ret; @@ -738,7 +734,7 @@ static void send_net_to_gaw(int simtype, const char *node) if(tok[0] == '#') tok++; if(node_entry && (node_entry->d.port == 0 || !strcmp(xctx->sch_path[xctx->currsch], ".") )) { char *t=NULL, *p=NULL; - c = get_color(hilight_color); + c = get_color(xctx->hilight_color); sprintf(color_str, "%02x%02x%02x", xcolor_array[c].red>>8, xcolor_array[c].green>>8, xcolor_array[c].blue>>8); expanded_tok = expandlabel(tok, &tok_mult); tcleval("if { ![info exists gaw_fd] } { gaw_setup_tcp }\n"); @@ -773,7 +769,7 @@ static void send_current_to_gaw(int simtype, const char *node) if(!node || !node[0]) return; tok = node; - /* c = get_color(hilight_color); */ + /* c = get_color(xctx->hilight_color); */ c = PINLAYER; sprintf(color_str, "%02x%02x%02x", xcolor_array[c].red>>8, xcolor_array[c].green>>8, xcolor_array[c].blue>>8); expanded_tok = expandlabel(tok, &tok_mult); @@ -820,23 +816,23 @@ void hilight_net(int to_waveform) switch(xctx->sel_array[i].type) { case WIRE: - hilight_nets=1; - if(!bus_hilight_lookup(xctx->wire[n].node, hilight_color, XINSERT)) { + xctx->hilight_nets=1; + if(!bus_hilight_lookup(xctx->wire[n].node, xctx->hilight_color, XINSERT)) { if(to_waveform == GAW) send_net_to_gaw(sim_is_xyce, xctx->wire[n].node); - if(incr_hilight) hilight_color++; + if(incr_hilight) xctx->hilight_color++; } break; case ELEMENT: type = (xctx->inst[n].ptr+ xctx->sym)->type; if( type && xctx->inst[n].node && IS_LABEL_SH_OR_PIN(type) ) { /* instance must have a pin! */ - if(!bus_hilight_lookup(xctx->inst[n].node[0], hilight_color, XINSERT)) { + if(!bus_hilight_lookup(xctx->inst[n].node[0], xctx->hilight_color, XINSERT)) { if(to_waveform == GAW) send_net_to_gaw(sim_is_xyce, xctx->inst[n].node[0]); - hilight_nets=1; - if(incr_hilight) hilight_color++; + xctx->hilight_nets=1; + if(incr_hilight) xctx->hilight_color++; } } else { dbg(1, "hilight_net(): setting hilight flag on inst %d\n",n); - hilight_nets=1; + xctx->hilight_nets=1; xctx->inst[n].flags |= 4; } if(type && (!strcmp(type, "current_probe") || !strcmp(type, "vsource")) ) { @@ -847,7 +843,7 @@ void hilight_net(int to_waveform) break; } } - if(!incr_hilight) hilight_color++; + if(!incr_hilight) xctx->hilight_color++; if(enable_drill) { drill_hilight(); /*traverse_schematic(); */ @@ -869,13 +865,13 @@ void unhilight_net(void) switch(xctx->sel_array[i].type) { case WIRE: - bus_hilight_lookup(xctx->wire[n].node, hilight_color, XDELETE); + bus_hilight_lookup(xctx->wire[n].node, xctx->hilight_color, XDELETE); break; case ELEMENT: type = (xctx->inst[n].ptr+ xctx->sym)->type; if( type && xctx->inst[n].node && IS_LABEL_SH_OR_PIN(type) ) { /* instance must have a pin! */ - bus_hilight_lookup(xctx->inst[n].node[0], hilight_color, XDELETE); + bus_hilight_lookup(xctx->inst[n].node[0], xctx->hilight_color, XDELETE); } else { } xctx->inst[n].flags &= ~4; @@ -910,7 +906,7 @@ void select_hilight_net(void) struct hilight_hashentry *entry; int hilight_connected_inst; - if(!hilight_nets) return; + if(!xctx->hilight_nets) return; prepare_netlist_structs(0); for(i=0;iwires;i++) { if( (entry = bus_hilight_lookup(xctx->wire[i].node, 0, XLOOKUP)) ) { @@ -965,7 +961,7 @@ void draw_hilight_net(int on_window) struct wireentry *wireptr; int hilight_connected_inst; - if(!hilight_nets) return; + if(!xctx->hilight_nets) return; prepare_netlist_structs(0); save_draw = draw_window; draw_window = on_window; @@ -1163,7 +1159,7 @@ void print_hilight_net(int show) my_snprintf(cmd3, S(cmd3), "awk -f \"%s/sort_labels.awk\" %s", tclgetvar("XSCHEM_SHAREDIR"), filetmp1); #endif for(i=0;ihilight_table[i]; while(entry) { node_entry = bus_hash_lookup(entry->token, "", XLOOKUP, 0, "", "", "", ""); diff --git a/src/move.c b/src/move.c index 71bc3941..3bc17920 100644 --- a/src/move.c +++ b/src/move.c @@ -221,7 +221,7 @@ void draw_selection(GC g, int interruptable) rx1+deltax, ry1+deltay, xctx->text[n].xscale, xctx->text[n].yscale); #ifdef HAS_CAIRO - if(customfont) cairo_restore(cairo_ctx); + if(customfont) cairo_restore(xctx->cairo_ctx); #endif break; @@ -532,7 +532,7 @@ void copy_objects(int what) if(what & ABORT) /* draw objects while moving */ { char *str = NULL; /* 20161122 overflow safe */ - draw_selection(gctiled,0); + draw_selection(xctx->gctiled,0); move_rot=move_flip=deltax=deltay=0; xctx->ui_state&=~STARTCOPY; my_strdup(225, &str, user_conf_dir); @@ -544,7 +544,7 @@ void copy_objects(int what) if(what & RUBBER) /* draw objects while moving */ { x2=xctx->mousex_snap;y_2=xctx->mousey_snap; - draw_selection(gctiled,0); + draw_selection(xctx->gctiled,0); deltax = x2-x1; deltay = y_2 - y_1; draw_selection(gc[SELLAYER],1); } @@ -552,13 +552,13 @@ void copy_objects(int what) rotatelocal=1; } if(what & ROTATE) { - draw_selection(gctiled,0); + draw_selection(xctx->gctiled,0); move_rot= (move_rot+1) & 0x3; update_symbol_bboxes(move_rot, move_flip); } if(what & FLIP) { - draw_selection(gctiled,0); + draw_selection(xctx->gctiled,0); move_flip = !move_flip; update_symbol_bboxes(move_rot, move_flip); } @@ -571,7 +571,7 @@ void copy_objects(int what) update_symbol_bboxes(0, 0); save_draw = draw_window; draw_window=1; /* temporarily re-enable draw to window together with pixmap */ - draw_selection(gctiled,0); + draw_selection(xctx->gctiled,0); bbox(START, 0.0 , 0.0 , 0.0 , 0.0); newpropcnt=0; set_modify(1); push_undo(); /* 20150327 push_undo */ @@ -789,7 +789,7 @@ void copy_objects(int what) xctx->text[n].x0, xctx->text[n].y0, &rx1,&ry1, &rx2,&ry2); #ifdef HAS_CAIRO - if(customfont) cairo_restore(cairo_ctx); + if(customfont) cairo_restore(xctx->cairo_ctx); #endif bbox(ADD, rx1, ry1, rx2, ry2 ); */ @@ -849,9 +849,9 @@ void copy_objects(int what) slant = CAIRO_FONT_SLANT_NORMAL; if(flags & TEXT_ITALIC) slant = CAIRO_FONT_SLANT_ITALIC; if(flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE; - cairo_save(cairo_ctx); + cairo_save(xctx->cairo_ctx); cairo_save(xctx->cairo_save_ctx); - cairo_select_font_face (cairo_ctx, textfont, slant, weight); + cairo_select_font_face (xctx->cairo_ctx, textfont, slant, weight); cairo_select_font_face (xctx->cairo_save_ctx, textfont, slant, weight); } #endif @@ -866,7 +866,7 @@ void copy_objects(int what) #endif #ifdef HAS_CAIRO if( (textfont && textfont[0]) || xctx->text[xctx->texts].flags) { - cairo_restore(cairo_ctx); + cairo_restore(xctx->cairo_ctx); cairo_restore(xctx->cairo_save_ctx); } #endif @@ -1008,7 +1008,7 @@ void move_objects(int what, int merge, double dx, double dy) } if(what & ABORT) /* draw objects while moving */ { - draw_selection(gctiled,0); + draw_selection(xctx->gctiled,0); move_rot=move_flip=deltax=deltay=0; xctx->ui_state &= ~STARTMOVE; xctx->ui_state &= ~PLACE_SYMBOL; @@ -1017,7 +1017,7 @@ void move_objects(int what, int merge, double dx, double dy) if(what & RUBBER) /* abort operation */ { x2=xctx->mousex_snap;y_2=xctx->mousey_snap; - draw_selection(gctiled,0); + draw_selection(xctx->gctiled,0); deltax = x2-x1; deltay = y_2 - y_1; draw_selection(gc[SELLAYER],1); } @@ -1025,13 +1025,13 @@ void move_objects(int what, int merge, double dx, double dy) rotatelocal=1; } if(what & ROTATE) { - draw_selection(gctiled,0); + draw_selection(xctx->gctiled,0); move_rot= (move_rot+1) & 0x3; update_symbol_bboxes(move_rot, move_flip); } if(what & FLIP) { - draw_selection(gctiled,0); + draw_selection(xctx->gctiled,0); move_flip = !move_flip; update_symbol_bboxes(move_rot, move_flip); } @@ -1042,7 +1042,7 @@ void move_objects(int what, int merge, double dx, double dy) save_draw = draw_window; draw_window=1; /* temporarily re-enable draw to xctx->window together with pixmap */ - draw_selection(gctiled,0); + draw_selection(xctx->gctiled,0); bbox(START, 0.0 , 0.0 , 0.0 , 0.0); set_modify(1); if( !(xctx->ui_state & (STARTMERGE | PLACE_SYMBOL)) ) { @@ -1354,7 +1354,7 @@ void move_objects(int what, int merge, double dx, double dy) xctx->text[n].yscale, xctx->text[n].rot,xctx->text[n].flip, xctx->text[n].hcenter, xctx->text[n].vcenter, xctx->text[n].x0, xctx->text[n].y0, &rx1,&ry1, &rx2,&ry2); #ifdef HAS_CAIRO - if(customfont) cairo_restore(cairo_ctx); + if(customfont) cairo_restore(xctx->cairo_ctx); #endif bbox(ADD, rx1, ry1, rx2, ry2 ); @@ -1383,9 +1383,9 @@ void move_objects(int what, int merge, double dx, double dy) slant = CAIRO_FONT_SLANT_NORMAL; if(xctx->text[n].flags & TEXT_ITALIC) slant = CAIRO_FONT_SLANT_ITALIC; if(xctx->text[n].flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE; - cairo_save(cairo_ctx); + cairo_save(xctx->cairo_ctx); cairo_save(xctx->cairo_save_ctx); - cairo_select_font_face (cairo_ctx, textfont, slant, weight); + cairo_select_font_face (xctx->cairo_ctx, textfont, slant, weight); cairo_select_font_face (xctx->cairo_save_ctx, textfont, slant, weight); } #endif @@ -1399,7 +1399,7 @@ void move_objects(int what, int merge, double dx, double dy) #endif #ifdef HAS_CAIRO if( (textfont && textfont[0]) || xctx->text[n].flags) { - cairo_restore(cairo_ctx); + cairo_restore(xctx->cairo_ctx); cairo_restore(xctx->cairo_save_ctx); } #endif diff --git a/src/netlist.c b/src/netlist.c index 7235b0bb..edf6aa21 100644 --- a/src/netlist.c +++ b/src/netlist.c @@ -277,7 +277,7 @@ void hash_inst_pin(int what, int i, int j) statusmsg(str,2); if(!netlist_count) { xctx->inst[i].flags |=4; - hilight_nets=1; + xctx->hilight_nets=1; } } rot=xctx->inst[i].rot; @@ -445,10 +445,10 @@ static void signal_short( char *n1, char *n2) dbg(1, "signal_short(): signal_short: shorted: %s - %s", n1, n2); statusmsg(str,2); if(!netlist_count) { - bus_hilight_lookup(n1, hilight_color, XINSERT); - if(incr_hilight) hilight_color++; - bus_hilight_lookup(n2, hilight_color, XINSERT); - if(incr_hilight) hilight_color++; + bus_hilight_lookup(n1, xctx->hilight_color, XINSERT); + if(incr_hilight) xctx->hilight_color++; + bus_hilight_lookup(n2, xctx->hilight_color, XINSERT); + if(incr_hilight) xctx->hilight_color++; } } } @@ -524,41 +524,38 @@ void wirecheck(int k) /* recursive routine */ /* what==3 -> get node multiplicity */ int get_unnamed_node(int what, int mult,int node) { - static int new_node=0; - static int *node_mult=NULL; - static int node_mult_size; int i; dbg(2, "get_unnamed_node(): what=%d mult=%d node=%d\n", what, mult, node); if (what==0) /* initialize unnamed node data structures */ { - new_node=0; - my_free(828, &node_mult); - node_mult_size=0; + xctx->new_node=0; + my_free(828, &xctx->node_mult); + xctx->node_mult_size=0; return 0; } else if (what==1) /* get a new unique unnamed node */ { - ++new_node; - if (new_node>= node_mult_size) /* enlarge array and zero it */ + ++xctx->new_node; + if (xctx->new_node>= xctx->node_mult_size) /* enlarge array and zero it */ { - node_mult_size += CADCHUNKALLOC; - my_realloc(242, &node_mult, sizeof(int) * node_mult_size ); - for (i=node_mult_size-CADCHUNKALLOC;inode_mult_size += CADCHUNKALLOC; + my_realloc(242, &xctx->node_mult, sizeof(int) * xctx->node_mult_size ); + for (i=xctx->node_mult_size-CADCHUNKALLOC;inode_mult_size;i++) xctx->node_mult[i]=0; } - node_mult[new_node]=mult; - return new_node; + xctx->node_mult[xctx->new_node]=mult; + return xctx->new_node; } else if(what==2) /* update node multiplicity if given mult is lower */ { - if (node_mult[node]==0) node_mult[node]=mult; - else if (multnode_mult[node]==0) xctx->node_mult[node]=mult; + else if (multnode_mult[node]) xctx->node_mult[node]=mult; return 0; } else /* what=3 , return node multiplicity */ { - dbg(2, "get_unnamed_node(): returning mult=%d\n", node_mult[node]); - return node_mult[node]; + dbg(2, "get_unnamed_node(): returning mult=%d\n", xctx->node_mult[node]); + return xctx->node_mult[node]; } } /*------------ */ @@ -702,7 +699,7 @@ void prepare_netlist_structs(int for_netlist) my_snprintf(str, S(str), "instance: %d (%s): no name attribute set", i, inst[i].name); statusmsg(str,2); inst[i].flags |=4; - hilight_nets=1; + xctx->hilight_nets=1; } } if(print_erc && (!type || !type[0]) ) { @@ -710,7 +707,7 @@ void prepare_netlist_structs(int for_netlist) my_snprintf(str, S(str), "Symbol: %s: no type attribute set", inst[i].name); statusmsg(str,2); inst[i].flags |=4; - hilight_nets=1; + xctx->hilight_nets=1; } if(type && inst[i].node && IS_LABEL_OR_PIN(type) ) { /* instance must have a pin! */ if (for_netlist>0) { @@ -1188,7 +1185,7 @@ int sym_vs_sch_pins() for(j = 0; j < xctx->instances; j++) { if(!strcmp(xctx->inst[j].name, xctx->sym[i].name)) { xctx->inst[j].flags |=4; - hilight_nets=1; + xctx->hilight_nets=1; } } } @@ -1204,7 +1201,7 @@ int sym_vs_sch_pins() for(j = 0; j < xctx->instances; j++) { if(!strcmp(xctx->inst[j].name, xctx->sym[i].name)) { xctx->inst[j].flags |=4; - hilight_nets=1; + xctx->hilight_nets=1; } } } @@ -1237,7 +1234,7 @@ int sym_vs_sch_pins() for(j = 0; j < xctx->instances; j++) { if(!strcmp(xctx->inst[j].name, xctx->sym[i].name)) { xctx->inst[j].flags |=4; - hilight_nets=1; + xctx->hilight_nets=1; } } } @@ -1260,7 +1257,7 @@ int sym_vs_sch_pins() for(k = 0; k < xctx->instances; k++) { if(!strcmp(xctx->inst[k].name, xctx->sym[i].name)) { xctx->inst[k].flags |=4; - hilight_nets=1; + xctx->hilight_nets=1; } } } diff --git a/src/node_hash.c b/src/node_hash.c index 6a9aa5a0..d57b67fe 100644 --- a/src/node_hash.c +++ b/src/node_hash.c @@ -22,8 +22,6 @@ #include "xschem.h" -static struct node_hashentry *node_table[HASHSIZE]; - static unsigned int nh_hash(const char *tok) { unsigned int hash = 0; @@ -37,7 +35,7 @@ static unsigned int nh_hash(const char *tok) struct node_hashentry **get_node_table_ptr(void) { - return node_table; + return xctx->node_table; } void print_vhdl_signals(FILE *fd) @@ -50,7 +48,7 @@ void print_vhdl_signals(FILE *fd) found=0; for(i=0;inode_table[i]; while(ptr) { if(strstr(ptr->token, ".")) { @@ -125,7 +123,7 @@ void print_verilog_signals(FILE *fd) found=0; for(i=0;inode_table[i]; while(ptr) { if(ptr->d.port == 0 ) @@ -252,8 +250,8 @@ struct node_hashentry *node_hash_lookup(const char *token, const char *dir,int w d.port=port; hashcode=nh_hash(token); index=hashcode % HASHSIZE; - entry=node_table[index]; - preventry=&node_table[index]; + entry=xctx->node_table[index]; + preventry=&xctx->node_table[index]; while(1) { if( !entry ) /* empty slot */ @@ -331,43 +329,43 @@ void traverse_node_hash() if(!show_erc)return; for(i=0;inode_table[i]; while(entry) { if( !record_global_node(3, NULL, entry->token)) { if(entry->d.out + entry->d.inout + entry->d.in == 1) { my_snprintf(str, S(str), "open net: %s", entry->token); - if(!netlist_count) bus_hilight_lookup(entry->token, hilight_color, XINSERT); - if(incr_hilight) hilight_color++; + if(!netlist_count) bus_hilight_lookup(entry->token, xctx->hilight_color, XINSERT); + if(incr_hilight) xctx->hilight_color++; statusmsg(str,2); } else if(entry->d.out ==0 && entry->d.inout == 0) { my_snprintf(str, S(str), "undriven node: %s", entry->token); - if(!netlist_count) bus_hilight_lookup(entry->token, hilight_color, XINSERT); - if(incr_hilight) hilight_color++; + if(!netlist_count) bus_hilight_lookup(entry->token, xctx->hilight_color, XINSERT); + if(incr_hilight) xctx->hilight_color++; statusmsg(str,2); } else if(entry->d.out >=2 && entry->d.port>=0) /* era d.port>=2 03102001 */ { my_snprintf(str, S(str), "shorted output node: %s", entry->token); - if(!netlist_count) bus_hilight_lookup(entry->token, hilight_color, XINSERT); - if(incr_hilight) hilight_color++; + if(!netlist_count) bus_hilight_lookup(entry->token, xctx->hilight_color, XINSERT); + if(incr_hilight) xctx->hilight_color++; statusmsg(str,2); } else if(entry->d.in ==0 && entry->d.inout == 0) { my_snprintf(str, S(str), "node: %s goes nowhere", entry->token); - if(!netlist_count) bus_hilight_lookup(entry->token, hilight_color, XINSERT); - if(incr_hilight) hilight_color++; + if(!netlist_count) bus_hilight_lookup(entry->token, xctx->hilight_color, XINSERT); + if(incr_hilight) xctx->hilight_color++; statusmsg(str,2); } else if(entry->d.out >=2 && entry->d.inout == 0 && entry->d.port>=0) /* era d.port>=2 03102001 */ { my_snprintf(str, S(str), "shorted output node: %s", entry->token); - if(!netlist_count) bus_hilight_lookup(entry->token, hilight_color, XINSERT); - if(incr_hilight) hilight_color++; + if(!netlist_count) bus_hilight_lookup(entry->token, xctx->hilight_color, XINSERT); + if(incr_hilight) xctx->hilight_color++; statusmsg(str,2); } } @@ -379,14 +377,11 @@ void traverse_node_hash() } } -static int collisions, max_collisions=0, n_elements=0; - static struct node_hashentry *free_hash_entry(struct node_hashentry *entry) { struct node_hashentry *tmp; while(entry) { - n_elements++; collisions++; tmp = entry->next; my_free(861, &entry->token); my_free(862, &entry->verilog_type); @@ -405,16 +400,9 @@ void free_node_hash(void) /* remove the whole hash table */ int i; dbg(2, "free_node_hash(): removing hash table\n"); - n_elements=0; for(i=0;imax_collisions) max_collisions=collisions; + xctx->node_table[i] = free_hash_entry( xctx->node_table[i] ); } - dbg(1, "# free_node_hash(): max_collisions=%d n_elements=%d hashsize=%d\n", - max_collisions, n_elements, HASHSIZE); - max_collisions=0; - } diff --git a/src/scheduler.c b/src/scheduler.c index 5f62cfec..8cdf54d4 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -851,7 +851,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg printf("modified=%d\n", xctx->modified); printf("color_ps=%d\n", color_ps); printf("a3page=%d\n", a3page); - printf("hilight_nets=%d\n", hilight_nets); + printf("xctx->hilight_nets=%d\n", xctx->hilight_nets); printf("need_reb_sel_arr=%d\n", xctx->need_reb_sel_arr); printf("******* end global variables:*******\n"); } @@ -1924,9 +1924,6 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg if(!strcmp(argv[2],"cairo_font_name")) { if( strlen(argv[3]) < sizeof(cairo_font_name) ) { my_strncpy(cairo_font_name, argv[3], S(cairo_font_name)); - cairo_select_font_face(cairo_ctx, cairo_font_name, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); - cairo_select_font_face(xctx->cairo_save_ctx, cairo_font_name, - CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); } } else #endif @@ -2210,7 +2207,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(argv[1][0] == 't') { if(!strcmp(argv[1],"test")) { - /*XSetWMHints(display, topwindow, hints_ptr); */ + } else if(!strcmp(argv[1],"toggle_colorscheme")) diff --git a/src/select.c b/src/select.c index b32b17ae..1d8f703b 100644 --- a/src/select.c +++ b/src/select.c @@ -82,7 +82,7 @@ void symbol_bbox(int i, double *x1,double *y1, double *x2, double *y2) sym_flip ^ text.flip, text.hcenter, text.vcenter, x0+text_x0,y0+text_y0, &xx1,&yy1,&xx2,&yy2); #ifdef HAS_CAIRO - if(customfont) cairo_restore(cairo_ctx); + if(customfont) cairo_restore(xctx->cairo_ctx); #endif if(xx1<*x1) *x1=xx1; if(yy1<*y1) *y1=yy1; @@ -279,7 +279,7 @@ void delete(void) xctx->text[i].x0, xctx->text[i].y0, &xx1,&yy1, &xx2,&yy2); #ifdef HAS_CAIRO - if(customfont) cairo_restore(cairo_ctx); + if(customfont) cairo_restore(xctx->cairo_ctx); #endif bbox(ADD, xx1, yy1, xx2, yy2 ); my_free(935, &xctx->text[i].prop_ptr); @@ -443,7 +443,7 @@ void bbox(int what,double x1,double y1, double x2, double y2) xctx->xrect[0].width = xctx->areaw-4*INT_WIDTH(xctx->lw); xctx->xrect[0].height = xctx->areah-4*INT_WIDTH(xctx->lw); - XSetClipMask(display, gctiled, None); /* 20171110 optimization, clipping already done in software */ + XSetClipMask(display, xctx->gctiled, None); /* 20171110 optimization, clipping already done in software */ for(i=0;icairo_ctx); cairo_reset_clip(xctx->cairo_save_ctx); #endif sem=0; @@ -477,11 +477,11 @@ void bbox(int what,double x1,double y1, double x2, double y2) XSetClipRectangles(display, gc[i], 0,0, xctx->xrect, 1, Unsorted); XSetClipRectangles(display, gcstipple[i], 0,0, xctx->xrect, 1, Unsorted); } - XSetClipRectangles(display, gctiled, 0,0, xctx->xrect, 1, Unsorted); + XSetClipRectangles(display, xctx->gctiled, 0,0, xctx->xrect, 1, Unsorted); dbg(1, "bbox(): bbox= %d %d %d %d\n",xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2); #ifdef HAS_CAIRO - cairo_rectangle(cairo_ctx, xctx->xrect[0].x, xctx->xrect[0].y, xctx->xrect[0].width, xctx->xrect[0].height); - cairo_clip(cairo_ctx); + cairo_rectangle(xctx->cairo_ctx, xctx->xrect[0].x, xctx->xrect[0].y, xctx->xrect[0].width, xctx->xrect[0].height); + cairo_clip(xctx->cairo_ctx); cairo_rectangle(xctx->cairo_save_ctx, xctx->xrect[0].x, xctx->xrect[0].y, xctx->xrect[0].width, xctx->xrect[0].height); cairo_clip(xctx->cairo_save_ctx); #endif @@ -508,9 +508,9 @@ void unselect_all(void) xctx->wire[i].sel = 0; { if(xctx->wire[i].bus) - drawtempline(gctiled, THICK, xctx->wire[i].x1, xctx->wire[i].y1, xctx->wire[i].x2, xctx->wire[i].y2); + drawtempline(xctx->gctiled, THICK, xctx->wire[i].x1, xctx->wire[i].y1, xctx->wire[i].x2, xctx->wire[i].y2); else - drawtempline(gctiled, ADD, xctx->wire[i].x1, xctx->wire[i].y1, xctx->wire[i].x2, xctx->wire[i].y2); + drawtempline(xctx->gctiled, ADD, xctx->wire[i].x1, xctx->wire[i].y1, xctx->wire[i].x2, xctx->wire[i].y2); } } } @@ -520,7 +520,7 @@ void unselect_all(void) { xctx->inst[i].sel = 0; for(c=0;cgctiled, i, c,0,0,0.0,0.0); } } for(i=0;itexts;i++) @@ -531,12 +531,12 @@ void unselect_all(void) #ifdef HAS_CAIRO customfont = set_text_custom_font(& xctx->text[i]); /* needed for bbox calculation */ #endif - draw_temp_string(gctiled,ADD, xctx->text[i].txt_ptr, + draw_temp_string(xctx->gctiled,ADD, xctx->text[i].txt_ptr, xctx->text[i].rot, xctx->text[i].flip, xctx->text[i].hcenter, xctx->text[i].vcenter, xctx->text[i].x0, xctx->text[i].y0, xctx->text[i].xscale, xctx->text[i].yscale); #ifdef HAS_CAIRO - if(customfont) cairo_restore(cairo_ctx); + if(customfont) cairo_restore(xctx->cairo_ctx); #endif } } @@ -547,7 +547,7 @@ void unselect_all(void) if(xctx->arc[c][i].sel) { xctx->arc[c][i].sel = 0; - drawtemparc(gctiled, ADD, xctx->arc[c][i].x, xctx->arc[c][i].y, + drawtemparc(xctx->gctiled, ADD, xctx->arc[c][i].x, xctx->arc[c][i].y, xctx->arc[c][i].r, xctx->arc[c][i].a, xctx->arc[c][i].b); } } @@ -556,7 +556,7 @@ void unselect_all(void) if(xctx->rect[c][i].sel) { xctx->rect[c][i].sel = 0; - drawtemprect(gctiled, ADD, xctx->rect[c][i].x1, xctx->rect[c][i].y1, + drawtemprect(xctx->gctiled, ADD, xctx->rect[c][i].x1, xctx->rect[c][i].y1, xctx->rect[c][i].x2, xctx->rect[c][i].y2); } } @@ -566,10 +566,10 @@ void unselect_all(void) { xctx->line[c][i].sel = 0; if(xctx->line[c][i].bus) - drawtempline(gctiled, THICK, xctx->line[c][i].x1, xctx->line[c][i].y1, + drawtempline(xctx->gctiled, THICK, xctx->line[c][i].x1, xctx->line[c][i].y1, xctx->line[c][i].x2, xctx->line[c][i].y2); else - drawtempline(gctiled, ADD, xctx->line[c][i].x1, xctx->line[c][i].y1, + drawtempline(xctx->gctiled, ADD, xctx->line[c][i].x1, xctx->line[c][i].y1, xctx->line[c][i].x2, xctx->line[c][i].y2); } } @@ -580,13 +580,13 @@ void unselect_all(void) int k; for(k=0;kpoly[c][i].points; k++) xctx->poly[c][i].selected_point[k] = 0; xctx->poly[c][i].sel = 0; - drawtemppolygon(gctiled, NOW, xctx->poly[c][i].x, xctx->poly[c][i].y, xctx->poly[c][i].points); + drawtemppolygon(xctx->gctiled, NOW, xctx->poly[c][i].x, xctx->poly[c][i].y, xctx->poly[c][i].points); } } } - drawtemparc(gctiled, END, 0.0, 0.0, 0.0, 0.0, 0.0); - drawtemprect(gctiled, END, 0.0, 0.0, 0.0, 0.0); - drawtempline(gctiled,END, 0.0, 0.0, 0.0, 0.0); + drawtemparc(xctx->gctiled, END, 0.0, 0.0, 0.0, 0.0, 0.0); + drawtemprect(xctx->gctiled, END, 0.0, 0.0, 0.0, 0.0); + drawtempline(xctx->gctiled,END, 0.0, 0.0, 0.0, 0.0); xctx->ui_state &= ~SELECTION; /*\statusmsg("",2); */ my_snprintf(str, S(str), "%s/%s", user_conf_dir, ".selection.sch"); /* 20161115 PWD->HOME */ @@ -625,9 +625,9 @@ void select_wire(int i,unsigned short select_mode, int fast) } else { if(xctx->wire[i].bus) - drawtempline(gctiled, THICK, xctx->wire[i].x1, xctx->wire[i].y1, xctx->wire[i].x2, xctx->wire[i].y2); + drawtempline(xctx->gctiled, THICK, xctx->wire[i].x1, xctx->wire[i].y1, xctx->wire[i].x2, xctx->wire[i].y2); else - drawtempline(gctiled, NOW, xctx->wire[i].x1, xctx->wire[i].y1, xctx->wire[i].x2, xctx->wire[i].y2); + drawtempline(xctx->gctiled, NOW, xctx->wire[i].x1, xctx->wire[i].y1, xctx->wire[i].x2, xctx->wire[i].y2); } xctx->need_reb_sel_arr=1; } @@ -675,7 +675,7 @@ void select_element(int i,unsigned short select_mode, int fast, int override_loc } } else { for(c=0;cgctiled, i,c,0,0,0.0,0.0); } } xctx->need_reb_sel_arr=1; @@ -707,12 +707,12 @@ void select_text(int i,unsigned short select_mode, int fast) xctx->text[i].x0, xctx->text[i].y0, xctx->text[i].xscale, xctx->text[i].yscale); else - draw_temp_string(gctiled,NOW, xctx->text[i].txt_ptr, + draw_temp_string(xctx->gctiled,NOW, xctx->text[i].txt_ptr, xctx->text[i].rot, xctx->text[i].flip, xctx->text[i].hcenter, xctx->text[i].vcenter, xctx->text[i].x0, xctx->text[i].y0, xctx->text[i].xscale, xctx->text[i].yscale); #ifdef HAS_CAIRO - if(customfont) cairo_restore(cairo_ctx); + if(customfont) cairo_restore(xctx->cairo_ctx); #endif xctx->need_reb_sel_arr=1; } @@ -743,7 +743,7 @@ void select_box(int c, int i, unsigned short select_mode, int fast) xctx->rect[c][i].x2, xctx->rect[c][i].y2); } else { xctx->rect[c][i].sel = 0; - drawtemprect(gctiled, NOW, xctx->rect[c][i].x1, xctx->rect[c][i].y1, + drawtemprect(xctx->gctiled, NOW, xctx->rect[c][i].x1, xctx->rect[c][i].y1, xctx->rect[c][i].x2, xctx->rect[c][i].y2); } @@ -774,7 +774,7 @@ void select_arc(int c, int i, unsigned short select_mode, int fast) xctx->arc[c][i].r, xctx->arc[c][i].a, xctx->arc[c][i].b); } else { xctx->arc[c][i].sel = 0; - drawtemparc(gctiled, NOW, xctx->arc[c][i].x, xctx->arc[c][i].y, + drawtemparc(xctx->gctiled, NOW, xctx->arc[c][i].x, xctx->arc[c][i].y, xctx->arc[c][i].r, xctx->arc[c][i].a, xctx->arc[c][i].b); } @@ -801,7 +801,7 @@ void select_polygon(int c, int i, unsigned short select_mode, int fast ) drawtemppolygon(gc[SELLAYER], NOW, xctx->poly[c][i].x, xctx->poly[c][i].y, xctx->poly[c][i].points); } else - drawtemppolygon(gctiled, NOW, xctx->poly[c][i].x, xctx->poly[c][i].y, xctx->poly[c][i].points); + drawtemppolygon(xctx->gctiled, NOW, xctx->poly[c][i].x, xctx->poly[c][i].y, xctx->poly[c][i].points); xctx->need_reb_sel_arr=1; } @@ -836,10 +836,10 @@ void select_line(int c, int i, unsigned short select_mode, int fast ) } else if(xctx->line[c][i].bus) - drawtempline(gctiled, THICK, xctx->line[c][i].x1, xctx->line[c][i].y1, + drawtempline(xctx->gctiled, THICK, xctx->line[c][i].x1, xctx->line[c][i].y1, xctx->line[c][i].x2, xctx->line[c][i].y2); else - drawtempline(gctiled, NOW, xctx->line[c][i].x1, xctx->line[c][i].y1, + drawtempline(xctx->gctiled, NOW, xctx->line[c][i].x1, xctx->line[c][i].y1, xctx->line[c][i].x2, xctx->line[c][i].y2); xctx->need_reb_sel_arr=1; } @@ -927,7 +927,7 @@ void select_inside(double x1,double y1, double x2, double y2, int sel) /* 201509 xctx->text[i].x0, xctx->text[i].y0, &xx1,&yy1, &xx2,&yy2); #ifdef HAS_CAIRO - if(customfont) cairo_restore(cairo_ctx); + if(customfont) cairo_restore(xctx->cairo_ctx); #endif if(RECTINSIDE(xx1,yy1, xx2, yy2,x1,y1,x2,y2)) { diff --git a/src/token.c b/src/token.c index ffdd20ae..ac057df8 100644 --- a/src/token.c +++ b/src/token.c @@ -183,7 +183,7 @@ void check_unique_names(int rename) int big = xctx->wires> 2000 || xctx->instances > 2000; /* int save_draw; */ - if(hilight_nets) { + if(xctx->hilight_nets) { xRect boundbox; if(!big) calc_drawing_bbox(&boundbox, 2); enable_drill=0; @@ -211,7 +211,7 @@ void check_unique_names(int rename) dbg(1, "check_unique_names(): checking %s\n", start); if( (entry = inst_hash_lookup(table, start, i, XINSERT_NOREPLACE, strlen(start)) ) && entry->value != i) { xctx->inst[i].flags |=4; - hilight_nets=1; + xctx->hilight_nets=1; if(rename == 1) { if(first) { bbox(START,0.0,0.0,0.0,0.0); @@ -241,7 +241,7 @@ void check_unique_names(int rename) my_free(973, &expanded_instname); } } /* for(i...) */ - if(rename == 1 && hilight_nets) { + if(rename == 1 && xctx->hilight_nets) { bbox(SET,0.0,0.0,0.0,0.0); draw(); bbox(END,0.0,0.0,0.0,0.0); @@ -2327,7 +2327,7 @@ const char *net_name(int i, int j, int *multip, int hash_prefix_unnamed_net, int statusmsg(errstr,2); if(!netlist_count) { xctx->inst[i].flags |=4; - hilight_nets=1; + xctx->hilight_nets=1; } } return unconn; diff --git a/src/xinit.c b/src/xinit.c index 13eaed30..9d822f3e 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -371,7 +371,7 @@ void free_xschem_data() void alloc_xschem_data() { - int i; + int i, j; xctx = my_calloc(153, 1, sizeof(Xschem_ctx)); xctx->cur_undo_ptr = 0; @@ -413,12 +413,34 @@ void alloc_xschem_data() xctx->modified = 0; xctx->semaphore = 0; xctx->netlist_name[0] = '\0'; + xctx->current_dirname[0] = '\0'; + for(i = 0; i < NBOXES; i++) { + for(j = 0; j < NBOXES; j++) { + xctx->instpintable[i][j] = NULL; + xctx->wiretable[i][j] = NULL; + xctx->insttable[i][j] = NULL; + } + } + for(i = 0 ; i < HASHSIZE; i++) { + xctx->node_table[i] = NULL; + xctx->hilight_table[i] = NULL; + } + xctx->inst_color=NULL; + xctx->window = xctx->save_pixmap = 0; xctx->xrect[0].width = xctx->xrect[0].height = xctx->xrect[0].x = xctx->xrect[0].y = 0; + xctx->cairo_ctx = xctx->cairo_save_ctx = NULL; + xctx->cairo_sfc = xctx->cairo_save_sfc = NULL; + xctx->gctiled = 0; + /* get_unnamed_node() */ + xctx->new_node = 0; + xctx->node_mult = NULL; + xctx->node_mult_size = 0; + xctx->hilight_nets = 0; + xctx->hilight_color = 0; for(i=0;isch_path[i]=NULL; my_strdup(1187, &xctx->sch_path[0],"."); xctx->sch_inst_number[0] = 1; - xctx->maxt=CADMAXTEXT; xctx->maxw=CADMAXWIRES; xctx->maxi=ELEMINST; @@ -641,29 +663,22 @@ void xwin_exit(void) int i; if(!init_done) { - dbg(1, "xwin_exit() double call, doing nothing...\n"); + dbg(0, "xwin_exit() double call, doing nothing...\n"); return; } delete_netlist_structs(); delete_hilight_net(); get_unnamed_node(0, 0, 0); - if(has_x) { - #ifdef HAS_CAIRO - cairo_destroy(cairo_ctx); - cairo_destroy(xctx->cairo_save_ctx); - cairo_surface_destroy(sfc); - cairo_surface_destroy(xctx->save_sfc); - #endif - dbg(1, "xwin_exit(): Releasing pixmaps\n"); + resetwin(0, 1, 1); /* create_pixmap, clear_pixmap, force */ + dbg(1, "xwin_exit(): Releasing pixmaps and cairo data structures\n"); for(i=0;iwindow = pre_window; resetwin(1, 0, 1); /* create preview pixmap. resetwin(create_pixmap, clear_pixmap, force) */ + dbg(1, "preview_window() draw, load schematic\n"); + load_schematic(1,filename, 0); } - resetwin(1, 1, 1); /* handle resize. resetwin(create_pixmap, clear_pixmap, force) */ zoom_full(1, 0); /* draw */ xctx = save_xctx; } @@ -899,14 +913,14 @@ void preview_window(const char *what, const char *tk_win_path, const char *filen dbg(1, "preview_window() destroy\n"); xctx = preview_xctx; if(current_file) { - preview_clear(); + delete_schematic_data(); preview_xctx = NULL; } + Tk_DestroyWindow(tkpre_window); my_free(1144, ¤t_file); xctx = save_xctx; /* restore schematic */ save_xctx = NULL; - resetwin(0, 0, 1); /* handle resize. resetwin(create_pixmap, clear_pixmap, force) */ change_linewidth(xctx->lw); /* restore correct linewidth since it was changed in preview * need to do the XSetLineAttributes */ set_modify(xctx->modified); @@ -934,9 +948,9 @@ void new_schematic(const char *what, const char *tk_win_path, const char *filena alloc_xschem_data(); /* alloc data into xctx */ save_xctx[cnt] = xctx; dbg(1, "new_schematic() draw, load schematic\n"); - load_schematic(1,filename, 0); xctx->window = new_window; resetwin(1, 0, 1); /* create preview pixmap. resetwin(create_pixmap, clear_pixmap, force) */ + load_schematic(1,filename, 0); zoom_full(1, 0); /* draw */ } else if(!strcmp(what, "redraw")) { Xschem_ctx *save; @@ -945,7 +959,6 @@ void new_schematic(const char *what, const char *tk_win_path, const char *filena if(n <0) n = 0; if(n > cnt) n = cnt; xctx = save_xctx[n]; - resetwin(1, 1, 1); /* create preview pixmap. resetwin(create_pixmap, clear_pixmap, force) */ draw(); xctx = save; set_modify(xctx->modified); @@ -953,13 +966,12 @@ void new_schematic(const char *what, const char *tk_win_path, const char *filena if(cnt > 0) { dbg(1, "new_schematic() destroy\n"); xctx = save_xctx[cnt]; - preview_clear(); + delete_schematic_data(); save_xctx[cnt] = NULL; Tk_DestroyWindow(tknew_window[cnt]); cnt--; n = 0; xctx = save_xctx[0]; /* restore schematic */ - resetwin(1, 1, 0); /* create preview pixmap. resetwin(create_pixmap, clear_pixmap, force) */ set_modify(xctx->modified); } } else if(!strcmp(what, "switch")) { @@ -967,27 +979,181 @@ void new_schematic(const char *what, const char *tk_win_path, const char *filena if(n <0) n = 0; if(n > cnt) n = cnt; xctx = save_xctx[n]; - resetwin(1, 1, 1); /* create preview pixmap. resetwin(create_pixmap, clear_pixmap, force) */ - draw(); + change_linewidth(xctx->lw); /* restore correct linewidth since it was changed in preview + * need to do the XSetLineAttributes */ set_modify(xctx->modified); + /* draw();*/ } } -#ifndef __unix__ -/* Source: https://www.tcl.tk/man/tcl8.7/TclCmd/glob.htm */ -/* backslash character has a special meaning to glob command, -so glob patterns containing Windows style path separators need special care.*/ -void change_to_unix_fn(char* fn) +void change_linewidth(double w) { - int len, i, ii; - len = strlen(fn); - ii = 0; - for (i = 0; i < len; ++i) { - if (fn[i]!='\\') fn[ii++] = fn[i]; - else { fn[ii++] = '/'; if (fn[i + 1] == '\\') ++i; } + int i, changed; + + changed=0; + /* choose line width automatically based on zoom */ + if(w<0.) { + if(change_lw) { + xctx->lw=xctx->mooz * 0.09 * cadsnap; + cadhalfdotsize = CADHALFDOTSIZE + 0.04 * (cadsnap-10); + changed=1; + } + /* explicitly set line width */ + } else { + xctx->lw=w; + changed=1; } + if(!changed) return; + if(has_x) { + for(i=0;ilw), LineSolid, CapRound , JoinRound); + } + XSetLineAttributes (display, xctx->gctiled, INT_WIDTH(xctx->lw), LineSolid, CapRound , JoinRound); + } + xctx->areax1 = -2*INT_WIDTH(xctx->lw); + xctx->areay1 = -2*INT_WIDTH(xctx->lw); + xctx->areax2 = xctx->xrect[0].width+2*INT_WIDTH(xctx->lw); + xctx->areay2 = xctx->xrect[0].height+2*INT_WIDTH(xctx->lw); + xctx->areaw = xctx->areax2-xctx->areax1; + xctx->areah = xctx->areay2 - xctx->areay1; } + + +/* clears and creates cairo_sfc, cairo_ctx, cairo_save_sfc, cairo_save_ctx + * and sets some graphical attributes */ +void resetcairo(int create, int clear, int force_or_resize) +{ + #ifdef HAS_CAIRO + dbg(1, "resetcairo() %d, %d, %d\n", create, clear, force_or_resize); + if(clear && force_or_resize) { + /* xctx->cairo_save_sfc is based on pixmap and pixmaps are not resizeable, so on resize + * we must destroy & recreate everything. xctx->cairo_sfc can be resized using cairo_*_surface_set_size + * being based on window */ + cairo_destroy(xctx->cairo_save_ctx); + cairo_surface_destroy(xctx->cairo_save_sfc); + cairo_destroy(xctx->cairo_ctx); + cairo_surface_destroy(xctx->cairo_sfc); + } + if(create && force_or_resize) { + /***** Create Cairo save buffer drawing area *****/ + #if HAS_XRENDER==1 + #if HAS_XCB==1 + xctx->cairo_save_sfc = cairo_xcb_surface_create_with_xrender_format(xcbconn, screen_xcb, xctx->save_pixmap, + &format_rgb, xctx->xschem_w, xctx->xschem_h); + #else + xctx->cairo_save_sfc = cairo_xlib_surface_create_with_xrender_format(display, xctx->save_pixmap, + DefaultScreenOfDisplay(display), format, xctx->xschem_w, xctx->xschem_h); + #endif /* HAS_XCB */ + #else + xctx->cairo_save_sfc = + cairo_xlib_surface_create(display, xctx->save_pixmap, visual, xctx->xschem_w, xctx->xschem_h); + #endif /* HAS_XRENDER */ + if(cairo_surface_status(xctx->cairo_save_sfc)!=CAIRO_STATUS_SUCCESS) { + fprintf(errfp, "ERROR: invalid cairo xcb surface\n"); + } + xctx->cairo_save_ctx = cairo_create(xctx->cairo_save_sfc); + cairo_select_font_face(xctx->cairo_save_ctx, cairo_font_name, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size(xctx->cairo_save_ctx, 20); + cairo_set_line_width(xctx->cairo_save_ctx, 1); + cairo_set_line_join(xctx->cairo_save_ctx, CAIRO_LINE_JOIN_ROUND); + cairo_set_line_cap(xctx->cairo_save_ctx, CAIRO_LINE_CAP_ROUND); + /***** Create Cairo main drawing window structures *****/ + #if HAS_XRENDER==1 + #if HAS_XCB==1 + dbg(1, "create_cairo_surface: w=%d, h=%d\n", xctx->xschem_w, xctx->xschem_h); + xctx->cairo_sfc = cairo_xcb_surface_create_with_xrender_format(xcbconn, + screen_xcb, xctx->window, &format_rgb, xctx->xschem_w, xctx->xschem_h); + #else + render_format = XRenderFindStandardFormat(display, PictStandardRGB24); + xctx->cairo_sfc = cairo_xlib_surface_create_with_xrender_format (display, + xctx->window, DefaultScreenOfDisplay(display), render_format, xctx->xschem_w, xctx->xschem_h); + #endif /* HAS_XCB */ + #else + xctx->cairo_sfc = cairo_xlib_surface_create(display, xctx->window, visual, xctx->xschem_w, xctx->xschem_h); + #endif /* HAS_XRENDER */ + if(cairo_surface_status(xctx->cairo_sfc)!=CAIRO_STATUS_SUCCESS) { + fprintf(errfp, "ERROR: invalid cairo surface\n"); + } + xctx->cairo_ctx = cairo_create(xctx->cairo_sfc); + cairo_select_font_face(xctx->cairo_ctx, cairo_font_name, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size(xctx->cairo_ctx, 20); + cairo_set_line_width(xctx->cairo_ctx, 1); + cairo_set_line_join(xctx->cairo_ctx, CAIRO_LINE_JOIN_ROUND); + cairo_set_line_cap(xctx->cairo_ctx, CAIRO_LINE_CAP_ROUND); + #if 0 + #if HAS_XCB==1 && HAS_XRENDER==1 + cairo_xcb_surface_set_size(xctx->cairo_sfc, xctx->xschem_w, xctx->xschem_h); + #else + cairo_xlib_surface_set_size(xctx->cairo_sfc, xctx->xschem_w, xctx->xschem_h); + #endif /* HAS_XCB && HAS_XRENDER */ + #endif + } + #endif /* HAS_CAIRO */ +} + +void resetwin(int create_pixmap, int clear_pixmap, int force) +{ + unsigned int width, height; + XWindowAttributes wattr; + if(has_x) { +#ifdef __unix__ + if( XGetWindowAttributes(display, xctx->window, &wattr) ) { + width = wattr.width; + height = wattr.height; +#else + HWND hwnd = Tk_GetHWND(xctx->window); + RECT rct; + if (GetWindowRect(hwnd, &rct)) { + width = rct.right - rct.left; + height = rct.bottom - rct.top; #endif + /* if(wattr.map_state==IsUnmapped) return; */ + xctx->xschem_w=width; + xctx->xschem_h=height; + xctx->areax2 = xctx->xschem_w+2*INT_WIDTH(xctx->lw); + xctx->areay2 = xctx->xschem_h+2*INT_WIDTH(xctx->lw); + xctx->areax1 = -2*INT_WIDTH(xctx->lw); + xctx->areay1 = -2*INT_WIDTH(xctx->lw); + xctx->areaw = xctx->areax2-xctx->areax1; + xctx->areah = xctx->areay2-xctx->areay1; + /* if no force avoid unnecessary work if no resize */ + if( force || xctx->xschem_w !=xctx->xrect[0].width || xctx->xschem_h !=xctx->xrect[0].height) { + dbg(1, "resetwin(): %d, %d, %d, xschem_w=%d xschem_h=%d\n", + create_pixmap, clear_pixmap, force, xctx->xschem_w,xctx->xschem_h); + dbg(1, "resetwin(): changing size\n\n"); + xctx->xrect[0].x = 0; + xctx->xrect[0].y = 0; + xctx->xrect[0].width = xctx->xschem_w; + xctx->xrect[0].height = xctx->xschem_h; + if(clear_pixmap) { + resetcairo(0, 1, 1); /* create, clear, force */ + #ifdef __unix__ + XFreePixmap(display,xctx->save_pixmap); + #else + Tk_FreePixmap(display, xctx->save_pixmap); + #endif + XFreeGC(display,xctx->gctiled); + } + if(create_pixmap) { + #ifdef __unix__ + xctx->save_pixmap = XCreatePixmap(display, xctx->window, xctx->xschem_w, xctx->xschem_h, depth); + #else + xctx->save_pixmap = Tk_GetPixmap(display, xctx->window, xctx->xschem_w, xctx->xschem_h, depth); + #endif + xctx->gctiled = XCreateGC(display,xctx->window,0L, NULL); + XSetTile(display,xctx->gctiled, xctx->save_pixmap); + XSetFillStyle(display,xctx->gctiled,FillTiled); + resetcairo(1, 0, 1); /* create, clear, force */ + } + } + } + if(pending_fullzoom) { + zoom_full(0, 0); + pending_fullzoom=0; + } + dbg(1, "resetwin(): Window reset\n"); + } /* end if(has_x) */ +} int Tcl_AppInit(Tcl_Interp *inter) { @@ -1421,76 +1587,19 @@ int Tcl_AppInit(Tcl_Interp *inter) if(fill_type[i]==1) XSetFillStyle(display,gcstipple[i],FillSolid); else XSetFillStyle(display,gcstipple[i],FillStippled); } - gctiled = XCreateGC(display,xctx->window,0L, NULL); dbg(1, "Tcl_AppInit(): done step c of xinit()\n"); if(build_colors(0.0)) exit(-1); dbg(1, "Tcl_AppInit(): done step e of xinit()\n"); /* xctx->save_pixmap must be created as resetwin() frees it before recreating with new size. */ -#ifdef __unix__ - xctx->save_pixmap = XCreatePixmap(display,xctx->window,CADWIDTH,CADHEIGHT,depth); -#else - xctx->save_pixmap = Tk_GetPixmap(display, xctx->window, CADWIDTH, CADHEIGHT, depth); -#endif - XSetTile(display, gctiled, xctx->save_pixmap); - XSetFillStyle(display,gctiled,FillTiled); + + + resetwin(1, 0, 1); #ifdef HAS_CAIRO - { - XWindowAttributes wattr; - XGetWindowAttributes(display, xctx->window, &wattr); - #if HAS_XRENDER==1 - #if HAS_XCB==1 - sfc = cairo_xcb_surface_create_with_xrender_format(xcbconn, - screen_xcb, xctx->window, &format_rgb, 1 , 1); - xctx->save_sfc = cairo_xcb_surface_create_with_xrender_format(xcbconn, - screen_xcb, xctx->save_pixmap, &format_rgb, 1 , 1); - #else - format = XRenderFindStandardFormat(display, PictStandardRGB24); - sfc = cairo_xlib_surface_create_with_xrender_format (display, - xctx->window, DefaultScreenOfDisplay(display), format, 1, 1); - xctx->save_sfc = cairo_xlib_surface_create_with_xrender_format( - display, xctx->save_pixmap, DefaultScreenOfDisplay(display), format, 1, 1); - #endif - #else - sfc = cairo_xlib_surface_create(display, xctx->window, visual, wattr.width, wattr.height); - xctx->save_sfc = cairo_xlib_surface_create(display, xctx->save_pixmap, visual, wattr.width, wattr.height); - #endif - if(cairo_surface_status(sfc)!=CAIRO_STATUS_SUCCESS) { - fprintf(errfp, "ERROR: invalid cairo surface\n"); - return 1; - } - if(cairo_surface_status(xctx->save_sfc)!=CAIRO_STATUS_SUCCESS) { - fprintf(errfp, "ERROR: invalid cairo surface\n"); - return 1; - } - cairo_ctx = cairo_create(sfc); - xctx->cairo_save_ctx = cairo_create(xctx->save_sfc); - - #if 0 - { - cairo_font_options_t *cfo; - cfo = cairo_font_options_create (); - cairo_font_options_set_antialias(cfo, CAIRO_ANTIALIAS_DEFAULT); /* CAIRO_ANTIALIAS_NONE */ - cairo_set_font_options (cairo_ctx, cfo); - cairo_set_font_options (xctx->cairo_save_ctx, cfo); - } - #endif - - /* load font from tcl 20171112 */ - tcleval("xschem set svg_font_name $svg_font_name"); - tcleval("xschem set cairo_font_name $cairo_font_name"); - tclsetvar("has_cairo","1"); - cairo_select_font_face(cairo_ctx, cairo_font_name, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); - cairo_set_font_size(cairo_ctx, 20); - cairo_select_font_face(xctx->cairo_save_ctx, cairo_font_name, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); - cairo_set_font_size(xctx->cairo_save_ctx, 20); - cairo_set_line_width(cairo_ctx, 1); - cairo_set_line_width(xctx->cairo_save_ctx, 1); - cairo_set_line_join(cairo_ctx, CAIRO_LINE_JOIN_ROUND); - cairo_set_line_cap(cairo_ctx, CAIRO_LINE_CAP_ROUND); - cairo_set_line_join(xctx->cairo_save_ctx, CAIRO_LINE_JOIN_ROUND); - cairo_set_line_cap(xctx->cairo_save_ctx, CAIRO_LINE_CAP_ROUND); - } - #endif /* HAS_CAIRO */ + /* load font from tcl 20171112 */ + tcleval("xschem set svg_font_name $svg_font_name"); + tcleval("xschem set cairo_font_name $cairo_font_name"); + tclsetvar("has_cairo","1"); + #endif change_linewidth(0.); dbg(1, "Tcl_AppInit(): done xinit()\n"); diff --git a/src/xschem.h b/src/xschem.h index 9b2b4fb8..55a90478 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -534,13 +534,25 @@ typedef struct { Pixmap save_pixmap; XRectangle xrect[1]; #ifdef HAS_CAIRO - cairo_surface_t *save_sfc; - cairo_t *cairo_save_ctx; + cairo_surface_t *cairo_sfc, *cairo_save_sfc; + cairo_t *cairo_ctx, *cairo_save_ctx; + #endif + GC gctiled; char *undo_dirname; int cur_undo_ptr; int tail_undo_ptr; int head_undo_ptr; + struct node_hashentry *node_table[HASHSIZE]; + struct hilight_hashentry *hilight_table[HASHSIZE]; + int *inst_color; + int hilight_nets; + int hilight_color; + /* get_unnamed_node() */ + int new_node; + int *node_mult; + int node_mult_size; + } Xschem_ctx; struct Lcc { /* used for symbols containing schematics as instances (LCC, Local Custom Cell) */ @@ -624,7 +636,6 @@ extern int cadlayers; extern int *active_layer; extern int *enable_layer; extern int n_active_layers; -extern int hilight_color; extern int do_print; extern int has_x; extern int no_draw; @@ -694,7 +705,6 @@ extern int spiceprefix; extern char hiersep[20]; extern int quit; extern int show_erc; -extern int hilight_nets; extern int color_ps; extern int only_probes; extern int pending_fullzoom; @@ -737,9 +747,6 @@ extern XColor xcolor_array[]; extern Visual *visual; #ifdef HAS_CAIRO extern XRenderPictFormat *format; -extern cairo_surface_t *sfc; -extern cairo_t *cairo_ctx; - #if HAS_XCB==1 extern xcb_connection_t *xcbconn; extern xcb_screen_t *screen_xcb; @@ -820,6 +827,7 @@ extern unsigned short select_object(double mx,double my, unsigned short sel_mode extern void unselect_all(void); extern void select_inside(double x1,double y1, double x2, double y2, int sel); extern void xwin_exit(void); +extern void resetcairo(int create, int clear, int force_or_resize); extern int Tcl_AppInit(Tcl_Interp *interp); extern int source_tcl_file(char *s); extern int callback(int event, int mx, int my, KeySym key, diff --git a/src/xschem.tcl b/src/xschem.tcl index 9a5095fb..66c7e5ff 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -2939,8 +2939,6 @@ proc launcher {} { # XSCHEM_SHAREDIR and netlist_dir not used directly but useful in paths passed thru launcher_var global launcher_var launcher_default_program launcher_program env XSCHEM_SHAREDIR netlist_dir - ## puts ">>> $launcher_program $launcher_var " - # 20170413 if { ![string compare $launcher_program {}] } { set launcher_program $launcher_default_program} eval exec [subst $launcher_program] {[subst $launcher_var]} & } @@ -3162,7 +3160,7 @@ proc raise_dialog {window_path } { #### TEST MODE ##### proc new_window {what {path {}} {filename {}}} { if { $what eq {create}} { - toplevel $path -bg {} + toplevel $path -bg {} -width 400 -height 400 update xschem new_schematic create $path $filename set_bindings $path @@ -3176,9 +3174,9 @@ proc new_window {what {path {}} {filename {}}} { } proc test1 {} { - xschem load /home/schippes/xschem-repo/trunk/xschem_library/rom8k/rom8k.sch - new_window create .xx /home/schippes/xschem-repo/trunk/xschem_library/examples/mos_power_ampli.sch - new_window create .yy /home/schippes/xschem-repo/trunk/xschem_library/examples/MSA-2643.sch + xschem load [abs_sym_path rom8k.sch] + new_window create .xx [abs_sym_path mos_power_ampli.sch] + new_window create .yy [abs_sym_path solar_panel.sch] bind .xx { new_window redraw 1 } bind .yy { new_window redraw 2 } bind .xx { new_window switch 1 } @@ -3186,6 +3184,11 @@ proc test1 {} { bind .drw {+ new_window switch 0} } +proc test1_end {} { + new_window destroy + new_window destroy +} + proc set_bindings {window_path} { global env no_x ###