From a64d69ed7aa055470dde53d97a15b5baa4b76cf2 Mon Sep 17 00:00:00 2001 From: Stefan Frederik Date: Thu, 3 Dec 2020 04:20:05 +0100 Subject: [PATCH] some code refactoring, more globals in xctx context, fixed unnoticed shift-reduce conflict in expandlabel --- src/actions.c | 102 +++++++++++++------------- src/callback.c | 142 ++++++++++++++++++------------------ src/check.c | 2 +- src/draw.c | 174 ++++++++++++++++++++++---------------------- src/expandlabel.y | 51 +++++++------ src/globals.c | 90 ++++++++++++----------- src/move.c | 2 +- src/save.c | 6 +- src/scheduler.c | 18 +++-- src/spice_netlist.c | 2 +- src/tedax_netlist.c | 2 +- src/xinit.c | 141 +++++++++++++++-------------------- src/xschem.h | 8 +- src/xschem.tcl | 41 ++++++----- 14 files changed, 388 insertions(+), 393 deletions(-) diff --git a/src/actions.c b/src/actions.c index 469fd69c..d0245973 100644 --- a/src/actions.c +++ b/src/actions.c @@ -194,6 +194,43 @@ const char *add_ext(const char *f, const char *ext) dbg(1, "add_ext(): 3: ff=%s\n", ff); return ff; } +static void reset_cairo(void) +{ + #ifdef HAS_CAIRO + /* 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(cairo_save_ctx); + cairo_surface_destroy(save_sfc); + #if HAS_XRENDER==1 + #if HAS_XCB==1 + save_sfc = cairo_xcb_surface_create_with_xrender_format(xcbconn, screen_xcb, xctx->save_pixmap, + &format_rgb, xctx->xschem_w, xctx->xschem_h); + #else + 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 + save_sfc = cairo_xlib_surface_create(display, xctx->save_pixmap, visual, xctx->xschem_w, xctx->xschem_h); + #endif /* HAS_XRENDER */ + if(cairo_surface_status(save_sfc)!=CAIRO_STATUS_SUCCESS) { + fprintf(errfp, "ERROR: invalid cairo xcb surface\n"); + exit(-1); + } + cairo_save_ctx = cairo_create(save_sfc); + cairo_set_line_width(cairo_save_ctx, 1); + cairo_set_line_join(cairo_save_ctx, CAIRO_LINE_JOIN_ROUND); + cairo_set_line_cap(cairo_save_ctx, CAIRO_LINE_CAP_ROUND); + cairo_select_font_face (cairo_save_ctx, cairo_font_name, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size (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 */ + #endif /* HAS_CAIRO */ +} void resetwin(int create_pixmap, int clear_pixmap, int preview_window) { @@ -201,7 +238,7 @@ void resetwin(int create_pixmap, int clear_pixmap, int preview_window) XWindowAttributes wattr; if(has_x) { #ifdef __unix__ - i = XGetWindowAttributes(display, window, &wattr); /* should call only when resized */ + i = XGetWindowAttributes(display, xctx->window, &wattr); /* should call only when resized */ /* to avoid server roundtrip replies */ if(!i) { return; @@ -227,22 +264,21 @@ void resetwin(int create_pixmap, int clear_pixmap, int preview_window) xrect[0].y = 0; xrect[0].width = xctx->xschem_w; xrect[0].height = xctx->xschem_h; - - if(clear_pixmap) XFreePixmap(display,save_pixmap); - + if(clear_pixmap) XFreePixmap(display,xctx->save_pixmap); /* { unsigned int w, h; - XQueryBestSize(display, TileShape, window, xctx->xschem_w, xctx->xschem_h, &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) { - save_pixmap = XCreatePixmap(display, window, xctx->xschem_w, xctx->xschem_h, depth); + xctx->save_pixmap = XCreatePixmap(display, xctx->window, xctx->xschem_w, xctx->xschem_h, depth); } - XSetTile(display,gctiled, save_pixmap); + XSetTile(display,gctiled, xctx->save_pixmap); + reset_cairo(); + } #else HWND hwnd; if (preview_window) { @@ -276,55 +312,21 @@ void resetwin(int create_pixmap, int clear_pixmap, int preview_window) xrect[0].y = 0; xrect[0].width = xctx->xschem_w; xrect[0].height = xctx->xschem_h; - if(clear_pixmap) Tk_FreePixmap(display, save_pixmap); + if(clear_pixmap) Tk_FreePixmap(display, xctx->save_pixmap); if(create_pixmap) { - save_pixmap = Tk_GetPixmap(display, window, xctx->xschem_w, xctx->xschem_h, depth); + xctx->save_pixmap = Tk_GetPixmap(display, xctx->window, xctx->xschem_w, xctx->xschem_h, depth); } - XSetTile(display, gctiled, save_pixmap); + XSetTile(display, gctiled, xctx->save_pixmap); } -#endif - #ifdef HAS_CAIRO - cairo_destroy(cairo_save_ctx); - cairo_surface_destroy(save_sfc); - - #if HAS_XRENDER==1 - #if HAS_XCB==1 - save_sfc = cairo_xcb_surface_create_with_xrender_format(xcbconn, screen_xcb, save_pixmap, - &format_rgb, xctx->xschem_w, xctx->xschem_h); - #else - save_sfc = cairo_xlib_surface_create_with_xrender_format(display, save_pixmap, - DefaultScreenOfDisplay(display), format, xctx->xschem_w, xctx->xschem_h); - #endif /* HAS_XCB */ - #else - save_sfc = cairo_xlib_surface_create(display, save_pixmap, visual, xctx->xschem_w, xctx->xschem_h); - #endif /* HAS_XRENDER */ - if(cairo_surface_status(save_sfc)!=CAIRO_STATUS_SUCCESS) { - fprintf(errfp, "ERROR: invalid cairo xcb surface\n"); - exit(-1); - } - cairo_save_ctx = cairo_create(save_sfc); - cairo_set_line_width(cairo_save_ctx, 1); - cairo_set_line_join(cairo_save_ctx, CAIRO_LINE_JOIN_ROUND); - cairo_set_line_cap(cairo_save_ctx, CAIRO_LINE_CAP_ROUND); - cairo_select_font_face (cairo_save_ctx, cairo_font_name, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); - cairo_set_font_size (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 */ - #endif /* HAS_CAIRO */ - + reset_cairo(); } - +#endif if(pending_fullzoom) { zoom_full(0, 0); pending_fullzoom=0; } - /* debug ... */ dbg(1, "resetwin(): Window reset\n"); - } + } /* end if(has_x) */ } void toggle_only_probes() @@ -552,7 +554,7 @@ void ask_new_file(void) } } -/* remove symbol and decrement xctx->symbols */ +/* remove symbol and decrement symbols */ /* Warning: removing a symbol with a loaded schematic will make all symbol references corrupt */ /* you should clear_drawing() first or load_schematic() or link_symbols_to_instances() immediately afterwards */ @@ -1276,7 +1278,7 @@ void go_back(int confirm) /* 20171006 add confirm */ } my_strncpy(xctx->sch[xctx->currsch] , "", S(xctx->sch[xctx->currsch])); xctx->currsch--; - save_modified = xctx->modified; /* we propagate xctx->modified flag (cleared by load_schematic */ + save_modified = xctx->modified; /* we propagate modified flag (cleared by load_schematic */ /* by default) to parent schematic if going back from embedded symbol */ my_strncpy(filename, xctx->sch[xctx->currsch], S(filename)); diff --git a/src/callback.c b/src/callback.c index 3af6ce9f..9f41e517 100644 --- a/src/callback.c +++ b/src/callback.c @@ -123,19 +123,19 @@ int callback(int event, int mx, int my, KeySym key, } #endif state &=~Mod2Mask; /* 20170511 filter out NumLock status */ - if(semaphore) + if(xctx->semaphore) { if(debug_var>=2) if(event != MotionNotify) - fprintf(errfp, "callback(): reentrant call of callback(), semaphore=%d\n", semaphore); + fprintf(errfp, "callback(): reentrant call of callback(), xctx->semaphore=%d\n", xctx->semaphore); /* if(event==Expose) { - * XCopyArea(display, save_pixmap, window, gctiled, mx,my,button,aux,mx,my); + * XCopyArea(display, xctx->save_pixmap, xctx->window, gctiled, mx,my,button,aux,mx,my); * * } */ /* return 0; */ } - semaphore++; /* used to debug Tcl-Tk frontend */ + xctx->semaphore++; /* used to debug Tcl-Tk frontend */ xctx->mousex=X_TO_XSCHEM(mx); xctx->mousey=Y_TO_XSCHEM(my); xctx->mousex_snap=ROUND(xctx->mousex / cadsnap) * cadsnap; @@ -150,7 +150,7 @@ int callback(int event, int mx, int my, KeySym key, /* xschem window *sending* selected objects when the pointer comes back in abort copy operation since it has been done - in another xschem window; STARTCOPY set and selection file does not exist any more */ + in another xschem xctx->window; STARTCOPY set and selection file does not exist any more */ if( stat(sel_or_clip, &buf) && (xctx->ui_state & STARTCOPY) ) { copy_objects(ABORT); /* also unlinks sel_or_flip file */ @@ -168,7 +168,7 @@ int callback(int event, int mx, int my, KeySym key, break; case Expose: - XCopyArea(display, save_pixmap, window, gctiled, mx,my,button,aux,mx,my); + XCopyArea(display, xctx->save_pixmap, xctx->window, gctiled, mx,my,button,aux,mx,my); { XRectangle xr[1]; xr[0].x=mx; @@ -189,14 +189,14 @@ int callback(int event, int mx, int my, KeySym key, break; case MotionNotify: - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; #ifndef __unix__ if ((xctx->ui_state & STARTWIRE) || (xctx->ui_state & STARTARC) || (xctx->ui_state & STARTLINE) || (xctx->ui_state & STARTMOVE) || (xctx->ui_state & STARTCOPY) || (xctx->ui_state & STARTRECT) ||i (xctx->ui_state & STARTPOLYGON) || (xctx->ui_state & STARTPAN2) || (xctx->ui_state & STARTPAN) || (xctx->ui_state & STARTSELECT)) { - XCopyArea(display, save_pixmap, window, gctiled, xrect[0].x, xrect[0].y, + XCopyArea(display, xctx->save_pixmap, xctx->window, gctiled, xrect[0].x, xrect[0].y, xrect[0].width, xrect[0].height, xrect[0].x, xrect[0].y); } #endif @@ -309,7 +309,7 @@ int callback(int event, int mx, int my, KeySym key, manhattan_lines %=3; new_line(RUBBER); } else { - if(semaphore<2) { + if(xctx->semaphore<2) { rebuild_selected_array(); if(xctx->lastsel==0) xctx->ui_state &=~SELECTION; } @@ -363,25 +363,25 @@ int callback(int event, int mx, int my, KeySym key, } if(key == 'j' && state==0 ) /* print list of highlight nets */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; print_hilight_net(1); break; } if(key == 'j' && state==ControlMask) /* create ipins from highlight nets */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; print_hilight_net(0); break; } if(key == 'j' && state==Mod1Mask) /* create labels without i prefix from hilight nets */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; print_hilight_net(4); break; } if(key == 'J' && state==(Mod1Mask | ShiftMask) ) /* create labels with i prefix from hilight nets */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; print_hilight_net(2); break; } @@ -517,7 +517,7 @@ int callback(int event, int mx, int my, KeySym key, if(key== 'W' && state == ShiftMask) { /* create wire snapping to closest instance pin */ double x, y; int xx, yy; - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; if(!(xctx->ui_state & STARTWIRE)){ find_closest_net_or_symbol_pin(xctx->mousex, xctx->mousey, &x, &y); xx = X_TO_SCREEN(x); @@ -538,7 +538,7 @@ int callback(int event, int mx, int my, KeySym key, } if(key == 'w'&& state==0) /* place wire. */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; start_wire(mx, my); break; } @@ -549,7 +549,7 @@ int callback(int event, int mx, int my, KeySym key, if(key == XK_Escape ) /* abort & redraw */ { no_draw = 0; - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; tcleval("set vertical_move 0; set horizontal_move 0" ); last_command=0; manhattan_lines = 0; @@ -601,7 +601,7 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='w' && !xctx->ui_state && state==ControlMask) /* start polygon, 20171115 */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; dbg(1, "callback(): start polygon\n"); mx_save = mx; my_save = my; xctx->mx_double_save=xctx->mousex_snap; @@ -636,7 +636,7 @@ int callback(int event, int mx, int my, KeySym key, } if(key==XK_Delete && (xctx->ui_state & SELECTION) ) /* delete objects */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; delete();break; } if(key==XK_Right) /* left */ @@ -665,7 +665,7 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='q' && state == ControlMask) /* exit */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; if(xctx->modified) { tcleval("tk_messageBox -type okcancel -message {UNSAVED data: want to exit?}"); if(strcmp(tclresult(),"ok")==0) { @@ -679,7 +679,7 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='t' && state == 0) /* place text */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; last_command = 0; place_text(1, xctx->mousex_snap, xctx->mousey_snap); /* 1 = draw text 24122002 */ break; @@ -722,7 +722,7 @@ int callback(int event, int mx, int my, KeySym key, if(key=='s' && (state == ControlMask) ) /* save 20121201 */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; /* check if unnamed schematic, use saveas in this case */ if(!strcmp(xctx->sch[xctx->currsch],"") || strstr(xctx->sch[xctx->currsch], "untitled")) { saveas(NULL, SCHEMATIC); @@ -733,19 +733,19 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='s' && state == (ControlMask | Mod1Mask) ) /* save as symbol */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; saveas(NULL, SYMBOL); break; } if(key=='S' && state == (ShiftMask | ControlMask)) /* save as schematic */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; saveas(NULL, SCHEMATIC); break; } if(key=='e' && state == 0) /* descend to schematic */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; descend_schematic(0);break; } if(key=='e' && state == Mod1Mask) /* edit schematic in new window */ @@ -760,13 +760,13 @@ int callback(int event, int mx, int my, KeySym key, } if( (key=='e' && state == ControlMask) || (key==XK_BackSpace)) /* back */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; go_back(1);break; } if(key=='a' && state == 0) /* make symbol */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; tcleval("tk_messageBox -type okcancel -message {do you want to make symbol view ?}"); if(strcmp(tclresult(),"ok")==0) { @@ -796,7 +796,7 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='x' && state == ControlMask) /* cut into clipboard */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; rebuild_selected_array(); if(xctx->lastsel) { /* 20071203 check if something selected */ save_selection(2); @@ -806,7 +806,7 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='c' && state == ControlMask) /* save clipboard */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; rebuild_selected_array(); if(xctx->lastsel) { /* 20071203 check if something selected */ save_selection(2); @@ -815,7 +815,7 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='C' && state == ShiftMask) /* place arc */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; mx_save = mx; my_save = my; xctx->mx_double_save=xctx->mousex_snap; xctx->my_double_save=xctx->mousey_snap; @@ -825,7 +825,7 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='C' && state == (ControlMask|ShiftMask)) /* place circle */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; mx_save = mx; my_save = my; xctx->mx_double_save=xctx->mousex_snap; xctx->my_double_save=xctx->mousey_snap; @@ -844,7 +844,7 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='v' && state == ControlMask) /* load clipboard */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; merge_file(2,".sch"); break; } @@ -854,13 +854,13 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='q' && state==0) /* edit prop */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; edit_property(0); break; } if(key=='q' && state==Mod1Mask) /* edit .sch file (DANGER!!) */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; rebuild_selected_array(); if(xctx->lastsel==0 ) { my_snprintf(str, S(str), "edit_file {%s}", abs_sym_path(xctx->sch[xctx->currsch], "")); @@ -876,17 +876,17 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='Q' && state == ShiftMask) /* edit prop with vim */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; edit_property(1);break; } if(key=='i' && state==0) /* descend to symbol */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; descend_symbol();break; } if(key==XK_Insert || (key == 'I' && state == ShiftMask) ) /* insert sym */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; last_command = 0; unselect_all(); @@ -904,7 +904,7 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='s' && state & Mod1Mask) /* reload */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; tcleval("tk_messageBox -type okcancel -message {Are you sure you want to reload from disk?}"); if(strcmp(tclresult(),"ok")==0) { char filename[PATH_MAX]; @@ -919,14 +919,14 @@ int callback(int event, int mx, int my, KeySym key, if(key=='o' && state == ControlMask) /* load */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; tcleval("catch { ngspice::resetdata }"); ask_new_file(); break; } if(key=='S' && state == ShiftMask) /* change element order */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; change_elem_order(); break; } @@ -939,7 +939,7 @@ int callback(int event, int mx, int my, KeySym key, { xRect boundbox; int big = xctx->wires> 2000 || xctx->instances > 2000 ; - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; if(!big) calc_drawing_bbox(&boundbox, 2); unhilight_net(); /* undraw_hilight_net(1); */ @@ -955,7 +955,7 @@ int callback(int event, int mx, int my, KeySym key, if(key=='K' && state==(ControlMask|ShiftMask)) /* hilight net drilling thru elements */ /* with 'propagate_to' prop set on pins */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; enable_drill=1; hilight_net(0); redraw_hilights(); @@ -964,7 +964,7 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='k' && state==0) /* hilight net */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; enable_drill=0; hilight_net(0); redraw_hilights(); @@ -975,7 +975,7 @@ int callback(int event, int mx, int my, KeySym key, { xRect boundbox; int big = xctx->wires> 2000 || xctx->instances > 2000 ; - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; enable_drill=0; if(!big) calc_drawing_bbox(&boundbox, 2); delete_hilight_net(); @@ -990,7 +990,7 @@ int callback(int event, int mx, int my, KeySym key, break; } if(key=='g' && state==Mod1Mask) { /* highlight net and send to gaw viewer */ - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; enable_drill=0; hilight_net(GAW); redraw_hilights(); @@ -1016,25 +1016,25 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='*' && state==(Mod1Mask|ShiftMask) ) /* svg print , 20121108 */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; svg_draw(); break; } if(key=='*' && state==ShiftMask ) /* postscript print */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; ps_draw(); break; } if(key=='*' && state==(ControlMask|ShiftMask) ) /* xpm print */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; print_image(); break; } if(key=='u' && state==Mod1Mask) /* align to grid */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; push_undo(); round_schematic_to_grid(cadsnap); set_modify(1); @@ -1064,21 +1064,21 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='u' && state==0) /* undo */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; pop_undo(0); draw(); break; } if(key=='U' && state==ShiftMask) /* redo */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; pop_undo(1); draw(); break; } if(key=='&') /* check wire connectivity */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; push_undo(); trim_wires(); draw(); @@ -1086,7 +1086,7 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='l' && state == ControlMask) { /* create schematic from selected symbol 20171004 */ - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; create_sch_from_sym(); break; } @@ -1184,7 +1184,7 @@ int callback(int event, int mx, int my, KeySym key, if(key=='c' && state==0 && /* copy selected obj. */ !(xctx->ui_state & (STARTMOVE | STARTCOPY))) { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; mx_save = mx; my_save = my; xctx->mx_double_save=xctx->mousex_snap; xctx->my_double_save=xctx->mousey_snap; @@ -1193,18 +1193,18 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='n' && state==ControlMask) /* New schematic */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; tcleval("xschem clear SCHEMATIC"); } if(key=='N' && state==(ShiftMask|ControlMask) ) /* New symbol */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; tcleval("xschem clear SYMBOL"); } if(key=='n' && state==0) /* hierarchical netlist */ { yyparse_error = 0; - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; unselect_all(); if(set_netlist_dir(0, NULL)) { dbg(1, "callback(): -------------\n"); @@ -1226,7 +1226,7 @@ int callback(int event, int mx, int my, KeySym key, if(key=='N' && state==ShiftMask) /* current level only netlist */ { yyparse_error = 0; - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; unselect_all(); if( set_netlist_dir(0, NULL) ) { dbg(1, "callback(): -------------\n"); @@ -1258,13 +1258,13 @@ int callback(int event, int mx, int my, KeySym key, break; } if(key=='>') { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; if(draw_single_layer< cadlayers-1) draw_single_layer++; draw(); break; } if(key=='<') { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; if(draw_single_layer>=0 ) draw_single_layer--; draw(); break; @@ -1284,13 +1284,13 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='b' && state==0) /* merge schematic */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; merge_file(0, ""); /* 2nd parameter not used any more for merge 25122002 */ break; } if(key=='b' && state==Mod1Mask) /* hide/show instance details */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; hide_symbols++; if(hide_symbols >= 3) hide_symbols = 0; tclsetvar("hide_symbols", hide_symbols == 2 ? "2" : hide_symbols == 1 ? "1" : "0"); @@ -1299,7 +1299,7 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='D' && state==ShiftMask) /* delete files */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; delete_files(); break; } @@ -1366,7 +1366,7 @@ int callback(int event, int mx, int my, KeySym key, if(key=='f' && state == ControlMask) /* search */ { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; tcleval("property_search"); break; } @@ -1382,7 +1382,7 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='!') { - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; break_wires_at_pins(); break; } @@ -1399,7 +1399,7 @@ int callback(int event, int mx, int my, KeySym key, break; } if(button==Button5 && state == 0 ) view_unzoom(CADZOOMSTEP); - else if(button == Button3 && semaphore <2) { + else if(button == Button3 && xctx->semaphore <2) { if(!(xctx->ui_state & STARTPOLYGON) && !(state & Mod1Mask) ) { last_command = 0; unselect_all(); @@ -1438,7 +1438,7 @@ int callback(int event, int mx, int my, KeySym key, xctx->my_double_save=xctx->mousey_snap; /* useless code ? 20200905 */ - /* if(semaphore<2) { + /* if(xctx->semaphore<2) { rebuild_selected_array(); if(xctx->lastsel==0) xctx->ui_state &=~SELECTION; } */ @@ -1452,7 +1452,7 @@ int callback(int event, int mx, int my, KeySym key, xctx->ui_state |= STARTPAN2; break; } - else if(semaphore >= 2) { /* button1 click to select another instance while edit prop dialog open */ + else if(xctx->semaphore >= 2) { /* button1 click to select another instance while edit prop dialog open */ if(button==Button1 && state==0 && tclgetvar("edit_symbol_prop_new_sel")[0]) { tcleval("set edit_symbol_prop_new_sel 1; .dialog.f1.b1 invoke"); /* invoke 'OK' of edit prop dialog */ } else if(button==Button1 && (state & ShiftMask) && tclgetvar("edit_symbol_prop_new_sel")[0]) { @@ -1625,7 +1625,7 @@ int callback(int event, int mx, int my, KeySym key, if( !(state & ShiftMask) && !(state & Mod1Mask) ) { unselect_all(); #ifndef __unix__ - XCopyArea(display, save_pixmap, window, gctiled, xrect[0].x, xrect[0].y, + XCopyArea(display, xctx->save_pixmap, xctx->window, gctiled, xrect[0].x, xrect[0].y, xrect[0].width, xrect[0].height, xrect[0].x, xrect[0].y); #endif } @@ -1676,7 +1676,7 @@ int callback(int event, int mx, int my, KeySym key, break; } dbg(1, "callback(): ButtonRelease xctx->ui_state=%ld state=%d\n",xctx->ui_state,state); - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; if(xctx->ui_state & STARTSELECT) { if(state & ControlMask) { enable_stretch=1; @@ -1695,7 +1695,7 @@ int callback(int event, int mx, int my, KeySym key, } break; case -3: /* double click : edit prop */ - if(semaphore >= 2) break; + if(xctx->semaphore >= 2) break; dbg(1, "callback(): DoubleClick xctx->ui_state=%ld state=%d\n",xctx->ui_state,state); if(button==Button1) { if(xctx->ui_state == STARTWIRE) { @@ -1722,7 +1722,7 @@ int callback(int event, int mx, int my, KeySym key, break; } - semaphore--; + xctx->semaphore--; return 0; } diff --git a/src/check.c b/src/check.c index aabd114a..9cc2baff 100644 --- a/src/check.c +++ b/src/check.c @@ -52,7 +52,7 @@ void update_conn_cues(int draw_cues, int dr_win) struct wireentry *wireptr; xWire * const wire = xctx->wire; - hash_wires(); /* must be done also if xctx->wires==0 to clear xctx->wiretable */ + hash_wires(); /* must be done also if wires==0 to clear wiretable */ if(!xctx->wires) return; if(!draw_dots) return; if(cadhalfdotsize*xctx->mooz<0.7) return; diff --git a/src/draw.c b/src/draw.c index db37bd4d..82f13d52 100644 --- a/src/draw.c +++ b/src/draw.c @@ -81,7 +81,7 @@ void print_image() push_undo(); trim_wires(); /* 20161121 add connection boxes on wires but undo at end */ - XUnmapWindow(display, window); + XUnmapWindow(display, xctx->window); xrect[0].x = 0; xrect[0].y = 0; @@ -97,15 +97,15 @@ void print_image() saveory = xctx->yorigin; savezoom = xctx->zoom; #ifdef __unix__ - XFreePixmap(display,save_pixmap); - /* save_pixmap = XCreatePixmap(display,window,xctx->areaw,xctx->areah,depth); */ - save_pixmap = XCreatePixmap(display,window,w,h,depth); /* 20161119 pixmap should be exact size of */ + XFreePixmap(display,xctx->save_pixmap); + /* xctx->save_pixmap = XCreatePixmap(display,xctx->window,xctx->areaw,xctx->areah,depth); */ + xctx->save_pixmap = XCreatePixmap(display,xctx->window,w,h,depth); /* 20161119 pixmap should be exact size of */ /* cliprectangle to avoid random borders */ #else - Tk_FreePixmap(display, save_pixmap); - save_pixmap = Tk_GetPixmap(display, window, w, h, depth); + Tk_FreePixmap(display, xctx->save_pixmap); + xctx->save_pixmap = Tk_GetPixmap(display, xctx->window, w, h, depth); #endif - XSetTile(display, gctiled, save_pixmap); + XSetTile(display, gctiled, xctx->save_pixmap); #ifdef HAS_CAIRO cairo_destroy(cairo_save_ctx); @@ -113,13 +113,13 @@ void print_image() #if HAS_XRENDER==1 #if HAS_XCB==1 - save_sfc = cairo_xcb_surface_create_with_xrender_format(xcbconn, screen_xcb, save_pixmap, &format_rgb, w, h); + save_sfc = cairo_xcb_surface_create_with_xrender_format(xcbconn, screen_xcb, xctx->save_pixmap, &format_rgb, w, h); #else save_sfc = cairo_xlib_surface_create_with_xrender_format(display, - save_pixmap, DefaultScreenOfDisplay(display), format, w, h); + xctx->save_pixmap, DefaultScreenOfDisplay(display), format, w, h); #endif /*HAS_XCB */ #else - save_sfc = cairo_xlib_surface_create(display, save_pixmap, visual, w, h); + save_sfc = cairo_xlib_surface_create(display, xctx->save_pixmap, visual, w, h); #endif /*HAS_XRENDER */ if(cairo_surface_status(save_sfc)!=CAIRO_STATUS_SUCCESS) { fprintf(errfp, "ERROR: invalid cairo xcb surface\n"); @@ -146,7 +146,7 @@ void print_image() draw(); #ifdef __unix__ - XpmWriteFileFromPixmap(display, "plot.xpm", save_pixmap,0, NULL ); /* .gz ???? */ + XpmWriteFileFromPixmap(display, "plot.xpm", xctx->save_pixmap,0, NULL ); /* .gz ???? */ #endif dbg(1, "print_image(): Window image saved\n"); @@ -174,13 +174,13 @@ void print_image() xctx->xorigin = saveorx; xctx->yorigin = saveory; #ifdef __unix__ - XFreePixmap(display,save_pixmap); - save_pixmap = XCreatePixmap(display,window,xctx->areaw,xctx->areah,depth); + XFreePixmap(display,xctx->save_pixmap); + xctx->save_pixmap = XCreatePixmap(display,xctx->window,xctx->areaw,xctx->areah,depth); #else - Tk_FreePixmap(display, save_pixmap); - save_pixmap = Tk_GetPixmap(display, window, xctx->areaw, xctx->areah, depth); + Tk_FreePixmap(display, xctx->save_pixmap); + xctx->save_pixmap = Tk_GetPixmap(display, xctx->window, xctx->areaw, xctx->areah, depth); #endif - XSetTile(display, gctiled, save_pixmap); + XSetTile(display, gctiled, xctx->save_pixmap); #ifdef HAS_CAIRO @@ -189,13 +189,13 @@ void print_image() #if HAS_XRENDER==1 #if HAS_XCB==1 - save_sfc = cairo_xcb_surface_create_with_xrender_format(xcbconn, screen_xcb, save_pixmap, &format_rgb, w, h); + save_sfc = cairo_xcb_surface_create_with_xrender_format(xcbconn, screen_xcb, xctx->save_pixmap, &format_rgb, w, h); #else save_sfc = cairo_xlib_surface_create_with_xrender_format (display, - save_pixmap, DefaultScreenOfDisplay(display), format, w, h); + xctx->save_pixmap, DefaultScreenOfDisplay(display), format, w, h); #endif /*HAS_XCB */ #else - save_sfc = cairo_xlib_surface_create(display, save_pixmap, visual, w, h); + save_sfc = cairo_xlib_surface_create(display, xctx->save_pixmap, visual, w, h); #endif /*HAS_XRENDER */ if(cairo_surface_status(save_sfc)!=CAIRO_STATUS_SUCCESS) { fprintf(errfp, "ERROR: invalid cairo xcb surface\n"); @@ -216,7 +216,7 @@ void print_image() } XSetClipMask(display, gctiled, None); - XMapWindow(display, window); + XMapWindow(display, xctx->window); draw_grid=save_draw_grid; draw_pixmap=1; draw(); @@ -763,15 +763,15 @@ void drawgrid() x = xctx->xorigin*xctx->mooz;y = xctx->yorigin*xctx->mooz; if(y>xctx->areay1 && yareay2) { - if(draw_window) XDrawLine(display, window, gc[GRIDLAYER],xctx->areax1+1,(int)y, xctx->areax2-1, (int)y); + if(draw_window) XDrawLine(display, xctx->window, gc[GRIDLAYER],xctx->areax1+1,(int)y, xctx->areax2-1, (int)y); if(draw_pixmap) - XDrawLine(display, save_pixmap, gc[GRIDLAYER],xctx->areax1+1,(int)y, xctx->areax2-1, (int)y); + XDrawLine(display, xctx->save_pixmap, gc[GRIDLAYER],xctx->areax1+1,(int)y, xctx->areax2-1, (int)y); } if(x>xctx->areax1 && xareax2) { - if(draw_window) XDrawLine(display, window, gc[GRIDLAYER],(int)x,xctx->areay1+1, (int)x, xctx->areay2-1); + if(draw_window) XDrawLine(display, xctx->window, gc[GRIDLAYER],(int)x,xctx->areay1+1, (int)x, xctx->areay2-1); if(draw_pixmap) - XDrawLine(display, save_pixmap, gc[GRIDLAYER],(int)x,xctx->areay1+1, (int)x, xctx->areay2-1); + XDrawLine(display, xctx->save_pixmap, gc[GRIDLAYER],(int)x,xctx->areay1+1, (int)x, xctx->areay2-1); } tmp = floor((xctx->areay1+1)/delta)*delta-fmod(-xctx->yorigin*xctx->mooz,delta); for(x=floor((xctx->areax1+1)/delta)*delta-fmod(-xctx->xorigin*xctx->mooz,delta);xareax2;x+=delta) @@ -780,18 +780,18 @@ void drawgrid() { if(i>=CADMAXGRIDPOINTS) { - if(draw_window) XDrawPoints(display,window,gc[GRIDLAYER],gridpoint,i,CoordModeOrigin); + if(draw_window) XDrawPoints(display,xctx->window,gc[GRIDLAYER],gridpoint,i,CoordModeOrigin); if(draw_pixmap) - XDrawPoints(display,save_pixmap,gc[GRIDLAYER],gridpoint,i,CoordModeOrigin); + XDrawPoints(display,xctx->save_pixmap,gc[GRIDLAYER],gridpoint,i,CoordModeOrigin); i=0; } gridpoint[i].x=(int)(x);gridpoint[i++].y=(int)(y); } } - if(draw_window) XDrawPoints(display,window,gc[GRIDLAYER],gridpoint,i,CoordModeOrigin); + if(draw_window) XDrawPoints(display,xctx->window,gc[GRIDLAYER],gridpoint,i,CoordModeOrigin); if(draw_pixmap) - XDrawPoints(display,save_pixmap,gc[GRIDLAYER],gridpoint,i,CoordModeOrigin); + XDrawPoints(display,xctx->save_pixmap,gc[GRIDLAYER],gridpoint,i,CoordModeOrigin); /* debug ... */ /* XFlush(display); */ } @@ -817,15 +817,15 @@ void drawline(int c, int what, double linex1, double liney1, double linex2, doub if(i>=CADDRAWBUFFERSIZE) { #ifdef __unix__ - if(draw_window) XDrawSegments(display, window, gc[c], rr,i); + if(draw_window) XDrawSegments(display, xctx->window, gc[c], rr,i); if(draw_pixmap) - XDrawSegments(display, save_pixmap, gc[c], rr,i); + XDrawSegments(display, xctx->save_pixmap, gc[c], rr,i); #else for (j = 0; j < i; ++j) { if (draw_window) - XDrawLine(display, window, gc[c], rr[j].x1, rr[j].y1, rr[j].x2, rr[j].y2); + XDrawLine(display, xctx->window, gc[c], rr[j].x1, rr[j].y1, rr[j].x2, rr[j].y2); if (draw_pixmap) - XDrawLine(display, save_pixmap, gc[c], rr[j].x1, rr[j].y1, rr[j].x2, rr[j].y2); + XDrawLine(display, xctx->save_pixmap, gc[c], rr[j].x1, rr[j].y1, rr[j].x2, rr[j].y2); } #endif i=0; @@ -858,9 +858,9 @@ void drawline(int c, int what, double linex1, double liney1, double linex2, doub XSetDashes(display, gc[c], 0, dash_arr, 2); XSetLineAttributes (display, gc[c], INT_WIDTH(xctx->lw), xDashType, CapButt, JoinBevel); } - if(draw_window) XDrawLine(display, window, gc[c], x1, y1, x2, y2); + if(draw_window) XDrawLine(display, xctx->window, gc[c], x1, y1, x2, y2); if(draw_pixmap) - XDrawLine(display, save_pixmap, gc[c], x1, y1, x2, y2); + XDrawLine(display, xctx->save_pixmap, gc[c], x1, y1, x2, y2); if(dash) { XSetLineAttributes (display, gc[c], INT_WIDTH(xctx->lw), LineSolid, CapRound, JoinRound); } @@ -883,8 +883,8 @@ void drawline(int c, int what, double linex1, double liney1, double linex2, doub } else { XSetLineAttributes (display, gc[c], INT_BUS_WIDTH(xctx->lw), LineSolid, CapRound, JoinRound); } - if(draw_window) XDrawLine(display, window, gc[c], x1, y1, x2, y2); - if(draw_pixmap) XDrawLine(display, save_pixmap, gc[c], x1, y1, x2, y2); + if(draw_window) XDrawLine(display, xctx->window, gc[c], x1, y1, x2, y2); + if(draw_pixmap) XDrawLine(display, xctx->save_pixmap, gc[c], x1, y1, x2, y2); XSetLineAttributes (display, gc[c], INT_WIDTH(xctx->lw), LineSolid, CapRound , JoinRound); } } @@ -892,14 +892,14 @@ void drawline(int c, int what, double linex1, double liney1, double linex2, doub else if((what & END) && i) { #ifdef __unix__ - if(draw_window) XDrawSegments(display, window, gc[c], rr,i); - if(draw_pixmap) XDrawSegments(display, save_pixmap, gc[c], rr,i); + if(draw_window) XDrawSegments(display, xctx->window, gc[c], rr,i); + if(draw_pixmap) XDrawSegments(display, xctx->save_pixmap, gc[c], rr,i); #else for (j = 0; j < i; ++j) { if (draw_window) - XDrawLine(display, window, gc[c], rr[j].x1, rr[j].y1, rr[j].x2, rr[j].y2); + XDrawLine(display, xctx->window, gc[c], rr[j].x1, rr[j].y1, rr[j].x2, rr[j].y2); if (draw_pixmap) - XDrawLine(display, save_pixmap, gc[c], rr[j].x1, rr[j].y1, rr[j].x2, rr[j].y2); + XDrawLine(display, xctx->save_pixmap, gc[c], rr[j].x1, rr[j].y1, rr[j].x2, rr[j].y2); } #endif i=0; @@ -921,10 +921,10 @@ void drawtempline(GC gc, int what, double linex1,double liney1,double linex2,dou if(i>=CADDRAWBUFFERSIZE) { #ifdef __unix__ - XDrawSegments(display, window, gc, r,i); + XDrawSegments(display, xctx->window, gc, r,i); #else for (j = 0; j < i; ++j) { - XDrawLine(display, window, gc, r[j].x1, r[j].y1, r[j].x2, r[j].y2); + XDrawLine(display, xctx->window, gc, r[j].x1, r[j].y1, r[j].x2, r[j].y2); } #endif i=0; @@ -950,7 +950,7 @@ void drawtempline(GC gc, int what, double linex1,double liney1,double linex2,dou y2=Y_TO_SCREEN(liney2); if( clip(&x1,&y1,&x2,&y2) ) { - XDrawLine(display, window, gc, x1, y1, x2, y2); + XDrawLine(display, xctx->window, gc, x1, y1, x2, y2); } } else if(what & THICK) @@ -963,7 +963,7 @@ void drawtempline(GC gc, int what, double linex1,double liney1,double linex2,dou { XSetLineAttributes (display, gc, INT_BUS_WIDTH(xctx->lw), LineSolid, CapRound , JoinRound); - XDrawLine(display, window, gc, x1, y1, x2, y2); + XDrawLine(display, xctx->window, gc, x1, y1, x2, y2); XSetLineAttributes (display, gc, INT_WIDTH(xctx->lw), LineSolid, CapRound , JoinRound); } } @@ -972,10 +972,10 @@ void drawtempline(GC gc, int what, double linex1,double liney1,double linex2,dou else if((what & END) && i) { #ifdef __unix__ - XDrawSegments(display, window, gc, r,i); + XDrawSegments(display, xctx->window, gc, r,i); #else for (j = 0; j < i; ++j) { - XDrawLine(display, window, gc, r[j].x1, r[j].y1, r[j].x2, r[j].y2); + XDrawLine(display, xctx->window, gc, r[j].x1, r[j].y1, r[j].x2, r[j].y2); } #endif i=0; @@ -994,7 +994,7 @@ void drawtemparc(GC gc, int what, double x, double y, double r, double a, double { if(i>=CADDRAWBUFFERSIZE) { - XDrawArcs(display, window, gc, xarc,i); + XDrawArcs(display, xctx->window, gc, xarc,i); i=0; } xx1=X_TO_SCREEN(x-r); @@ -1030,13 +1030,13 @@ void drawtemparc(GC gc, int what, double x, double y, double r, double a, double y2=Y_TO_SCREEN(y2); if( rectclip(xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2,&x1,&y1,&x2,&y2) ) { - XDrawArc(display, window, gc, xx1, yy1, xx2-xx1, yy2-yy1, a*64, b*64); + XDrawArc(display, xctx->window, gc, xx1, yy1, xx2-xx1, yy2-yy1, a*64, b*64); } } else if(what & START) i=0; else if((what & END) && i) { - XDrawArcs(display, window, gc, xarc,i); + XDrawArcs(display, xctx->window, gc, xarc,i); i=0; } } @@ -1088,8 +1088,8 @@ void filledarc(int c, int what, double x, double y, double r, double a, double b { if(i>=CADDRAWBUFFERSIZE) { - if(draw_window) XFillArcs(display, window, gc[c], xarc,i); - if(draw_pixmap) XFillArcs(display, save_pixmap, gc[c], xarc,i); + if(draw_window) XFillArcs(display, xctx->window, gc[c], xarc,i); + if(draw_pixmap) XFillArcs(display, xctx->save_pixmap, gc[c], xarc,i); i=0; } xx1=X_TO_SCREEN(x-r); @@ -1125,15 +1125,15 @@ void filledarc(int c, int what, double x, double y, double r, double a, double b y2=Y_TO_SCREEN(y2); if( rectclip(xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2,&x1,&y1,&x2,&y2) ) { - if(draw_window) XFillArc(display, window, gc[c], xx1, yy1, xx2-xx1, yy2-yy1, a*64, b*64); - if(draw_pixmap) XFillArc(display, save_pixmap, gc[c], xx1, yy1, xx2-xx1, yy2-yy1, a*64, b*64); + if(draw_window) XFillArc(display, xctx->window, gc[c], xx1, yy1, xx2-xx1, yy2-yy1, a*64, b*64); + if(draw_pixmap) XFillArc(display, xctx->save_pixmap, gc[c], xx1, yy1, xx2-xx1, yy2-yy1, a*64, b*64); } } else if(what & START) i=0; else if((what & END) && i) { - if(draw_window) XFillArcs(display, window, gc[c], xarc,i); - if(draw_pixmap) XFillArcs(display, save_pixmap, gc[c], xarc,i); + if(draw_window) XFillArcs(display, xctx->window, gc[c], xarc,i); + if(draw_pixmap) XFillArcs(display, xctx->save_pixmap, gc[c], xarc,i); i=0; } } @@ -1153,8 +1153,8 @@ void drawarc(int c, int what, double x, double y, double r, double a, double b, { if(i>=CADDRAWBUFFERSIZE) { - if(draw_window) XDrawArcs(display, window, gc[c], xarc,i); - if(draw_pixmap) XDrawArcs(display, save_pixmap, gc[c], xarc,i); + if(draw_window) XDrawArcs(display, xctx->window, gc[c], xarc,i); + if(draw_pixmap) XDrawArcs(display, xctx->save_pixmap, gc[c], xarc,i); i=0; } xx1=X_TO_SCREEN(x-r); @@ -1201,18 +1201,18 @@ void drawarc(int c, int what, double x, double y, double r, double a, double b, } if(draw_window) { - XDrawArc(display, window, gc[c], xx1, yy1, xx2-xx1, yy2-yy1, a*64, b*64); + XDrawArc(display, xctx->window, gc[c], xx1, yy1, xx2-xx1, yy2-yy1, a*64, b*64); } if(draw_pixmap) { - XDrawArc(display, save_pixmap, gc[c], xx1, yy1, xx2-xx1, yy2-yy1, a*64, b*64); + XDrawArc(display, xctx->save_pixmap, gc[c], xx1, yy1, xx2-xx1, yy2-yy1, a*64, b*64); } if(fill && fill_type[c]){ if(arc_fill) { if(draw_window) - XFillArc(display, window, gcstipple[c], xx1, yy1, xx2-xx1, yy2-yy1, a*64, b*64); + XFillArc(display, xctx->window, gcstipple[c], xx1, yy1, xx2-xx1, yy2-yy1, a*64, b*64); if(draw_pixmap) - XFillArc(display, save_pixmap, gcstipple[c], xx1, yy1, xx2-xx1, yy2-yy1, a*64, b*64); + XFillArc(display, xctx->save_pixmap, gcstipple[c], xx1, yy1, xx2-xx1, yy2-yy1, a*64, b*64); } } if(dash) { @@ -1223,8 +1223,8 @@ void drawarc(int c, int what, double x, double y, double r, double a, double b, else if(what & START) i=0; else if((what & END) && i) { - if(draw_window) XDrawArcs(display, window, gc[c], xarc,i); - if(draw_pixmap) XDrawArcs(display, save_pixmap, gc[c], xarc,i); + if(draw_window) XDrawArcs(display, xctx->window, gc[c], xarc,i); + if(draw_pixmap) XDrawArcs(display, xctx->save_pixmap, gc[c], xarc,i); i=0; } } @@ -1247,11 +1247,11 @@ void filledrect(int c, int what, double rectx1,double recty1,double rectx2,doubl if(!only_probes && (x2-x1)< 2 && (y2-y1)< 2) return; if( rectclip(xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2,&x1,&y1,&x2,&y2) ) { - if(draw_window) XFillRectangle(display, window, gcstipple[c], (int)x1, (int)y1, + if(draw_window) XFillRectangle(display, xctx->window, gcstipple[c], (int)x1, (int)y1, (unsigned int)x2 - (unsigned int)x1, (unsigned int)y2 - (unsigned int)y1); if(draw_pixmap) - XFillRectangle(display, save_pixmap,gcstipple[c], (int)x1, (int)y1, + XFillRectangle(display, xctx->save_pixmap,gcstipple[c], (int)x1, (int)y1, (unsigned int)x2 - (unsigned int)x1, (unsigned int)y2 - (unsigned int)y1); } @@ -1261,9 +1261,9 @@ void filledrect(int c, int what, double rectx1,double recty1,double rectx2,doubl { if(i>=CADDRAWBUFFERSIZE) { - if(draw_window) XFillRectangles(display, window, gcstipple[c], r,i); + if(draw_window) XFillRectangles(display, xctx->window, gcstipple[c], r,i); if(draw_pixmap) - XFillRectangles(display, save_pixmap, gcstipple[c], r,i); + XFillRectangles(display, xctx->save_pixmap, gcstipple[c], r,i); i=0; } x1=X_TO_SCREEN(rectx1); @@ -1282,8 +1282,8 @@ void filledrect(int c, int what, double rectx1,double recty1,double rectx2,doubl } else if((what & END) && i) { - if(draw_window) XFillRectangles(display, window, gcstipple[c], r,i); - if(draw_pixmap) XFillRectangles(display, save_pixmap, gcstipple[c], r,i); + if(draw_window) XFillRectangles(display, xctx->window, gcstipple[c], r,i); + if(draw_pixmap) XFillRectangles(display, xctx->save_pixmap, gcstipple[c], r,i); i=0; } } @@ -1386,14 +1386,14 @@ void drawpolygon(int c, int what, double *x, double *y, int points, int poly_fil XSetDashes(display, gc[c], 0, dash_arr, 2); XSetLineAttributes (display, gc[c], INT_WIDTH(xctx->lw), xDashType, CapButt, JoinBevel); } - if(draw_window) XDrawLines(display, window, gc[c], p, points, CoordModeOrigin); + if(draw_window) XDrawLines(display, xctx->window, gc[c], p, points, CoordModeOrigin); if(draw_pixmap) - XDrawLines(display, save_pixmap, gc[c], p, points, CoordModeOrigin); + XDrawLines(display, xctx->save_pixmap, gc[c], p, points, CoordModeOrigin); if(fill && fill_type[c]){ if(poly_fill && (x[0] == x[points-1]) && (y[0] == y[points-1])) { - if(draw_window) XFillPolygon(display, window, gcstipple[c], p, points, Polygontype, CoordModeOrigin); + if(draw_window) XFillPolygon(display, xctx->window, gcstipple[c], p, points, Polygontype, CoordModeOrigin); if(draw_pixmap) - XFillPolygon(display, save_pixmap, gcstipple[c], p, points, Polygontype, CoordModeOrigin); + XFillPolygon(display, xctx->save_pixmap, gcstipple[c], p, points, Polygontype, CoordModeOrigin); } } if(dash) { @@ -1420,7 +1420,7 @@ void drawtemppolygon(GC g, int what, double *x, double *y, int points) p[i].x = X_TO_SCREEN(x[i]); p[i].y = Y_TO_SCREEN(y[i]); } - XDrawLines(display, window, g, p, points, CoordModeOrigin); + XDrawLines(display, xctx->window, g, p, points, CoordModeOrigin); } my_free(723, &p); } @@ -1448,12 +1448,12 @@ void drawrect(int c, int what, double rectx1,double recty1,double rectx2,double XSetDashes(display, gc[c], 0, dash_arr, 2); XSetLineAttributes (display, gc[c], INT_WIDTH(xctx->lw), xDashType, CapButt, JoinBevel); } - if(draw_window) XDrawRectangle(display, window, gc[c], (int)x1, (int)y1, + if(draw_window) XDrawRectangle(display, xctx->window, gc[c], (int)x1, (int)y1, (unsigned int)x2 - (unsigned int)x1, (unsigned int)y2 - (unsigned int)y1); if(draw_pixmap) { - XDrawRectangle(display, save_pixmap, gc[c], (int)x1, (int)y1, + XDrawRectangle(display, xctx->save_pixmap, gc[c], (int)x1, (int)y1, (unsigned int)x2 - (unsigned int)x1, (unsigned int)y2 - (unsigned int)y1); } @@ -1467,9 +1467,9 @@ void drawrect(int c, int what, double rectx1,double recty1,double rectx2,double { if(i>=CADDRAWBUFFERSIZE) { - if(draw_window) XDrawRectangles(display, window, gc[c], r,i); + if(draw_window) XDrawRectangles(display, xctx->window, gc[c], r,i); if(draw_pixmap) - XDrawRectangles(display, save_pixmap, gc[c], r,i); + XDrawRectangles(display, xctx->save_pixmap, gc[c], r,i); i=0; } x1=X_TO_SCREEN(rectx1); @@ -1488,8 +1488,8 @@ void drawrect(int c, int what, double rectx1,double recty1,double rectx2,double } else if((what & END) && i) { - if(draw_window) XDrawRectangles(display, window, gc[c], r,i); - if(draw_pixmap) XDrawRectangles(display, save_pixmap, gc[c], r,i); + if(draw_window) XDrawRectangles(display, xctx->window, gc[c], r,i); + if(draw_pixmap) XDrawRectangles(display, xctx->save_pixmap, gc[c], r,i); i=0; } } @@ -1510,7 +1510,7 @@ void drawtemprect(GC gc, int what, double rectx1,double recty1,double rectx2,dou if( (x2-x1)< 0.3 && (y2-y1)< 0.3) return; if( rectclip(xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2,&x1,&y1,&x2,&y2) ) { - XDrawRectangle(display, window, gc, (int)x1, (int)y1, + XDrawRectangle(display, xctx->window, gc, (int)x1, (int)y1, (unsigned int)x2 - (unsigned int)x1, (unsigned int)y2 - (unsigned int)y1); } @@ -1520,7 +1520,7 @@ void drawtemprect(GC gc, int what, double rectx1,double recty1,double rectx2,dou { if(i>=CADDRAWBUFFERSIZE) { - XDrawRectangles(display, window, gc, r,i); + XDrawRectangles(display, xctx->window, gc, r,i); i=0; } x1=X_TO_SCREEN(rectx1); @@ -1539,7 +1539,7 @@ void drawtemprect(GC gc, int what, double rectx1,double recty1,double rectx2,dou } else if((what & END) && i) { - XDrawRectangles(display, window, gc, r,i); + XDrawRectangles(display, xctx->window, gc, r,i); i=0; } } @@ -1565,9 +1565,9 @@ void draw(void) rebuild_selected_array(); if(has_x) { if(draw_pixmap) - XFillRectangle(display, save_pixmap, gc[BACKLAYER], xctx->areax1, xctx->areay1, xctx->areaw, xctx->areah); + XFillRectangle(display, xctx->save_pixmap, gc[BACKLAYER], xctx->areax1, xctx->areay1, xctx->areaw, xctx->areah); if(draw_window) - XFillRectangle(display, window, gc[BACKLAYER], xctx->areax1, xctx->areay1, xctx->areaw, xctx->areah); + XFillRectangle(display, xctx->window, gc[BACKLAYER], xctx->areax1, xctx->areay1, xctx->areaw, xctx->areah); dbg(2, "draw(): window: %d %d %d %d\n",xctx->areax1, xctx->areay1, xctx->areax2, xctx->areay2); drawgrid(); x1 = X_TO_XSCHEM(xctx->areax1); @@ -1761,7 +1761,7 @@ void draw(void) } /* !only_probes, 20110112 */ draw_hilight_net(draw_window); if(!draw_window) { - XCopyArea(display, save_pixmap, window, gctiled, xrect[0].x, xrect[0].y, + XCopyArea(display, xctx->save_pixmap, xctx->window, gctiled, xrect[0].x, xrect[0].y, xrect[0].width, xrect[0].height, xrect[0].x, xrect[0].y); } draw_selection(gc[SELLAYER], 0); /* 20181009 moved outside of cadlayers loop */ @@ -1777,7 +1777,7 @@ int XSetClipRectangles(register Display* dpy, GC gc, int clip_x_origin, int clip { return 0; } -int XSetTile(Display* display, GC gc, Pixmap save_pixmap) +int XSetTile(Display* display, GC gc, Pixmap xctx->save_pixmap) { return 0; } diff --git a/src/expandlabel.y b/src/expandlabel.y index 5d5e42c7..99d22947 100644 --- a/src/expandlabel.y +++ b/src/expandlabel.y @@ -245,51 +245,47 @@ int *idx; /* for bus index & bus index ranges */ %type index_nobracket /* operator precedences (bottom = highest) and associativity */ +%left B_NAME %left B_DOUBLEDOT +%left ':' %left B_CAR %left ',' -%left ':' %left '*' /* Grammar follows */ %% -input: /* empty string. allows ctrl-D as input */ - | input line -; -line: list { + + +line: /* empty */ + | list { my_strdup(129, &(dest_string.str),$1.str); /*19102004 */ my_free(737, &$1.str); /*19102004 */ dest_string.m=$1.m; } - | B_NUM { - char n[40]; - dbg(3, "yyparse(): B_NUM = %d\n", $1); - sprintf(n, "%d", $1); - my_strdup(158, &(dest_string.str),n); /*19102004 */ - dest_string.m = 1; - } - ; list: B_NAME { dbg(3, "yyparse(): B_NAME, $1=%s\n", $1); - $$.str = expandlabel_strdup($1); /* 19102004 prima era =$1 */ + $$.str = expandlabel_strdup($1); my_free(738, &$1); $$.m = 1; } - | list B_NAME { - dbg(3, "yyparse(): list B_NAME, $2=%s\n", $2); - $$.str = expandlabel_strcat($1.str, $2); - my_free(452, &$1); - my_free(1208, &$1.str); - $$.m = 1; - } | B_LINE { dbg(3, "yyparse(): B_LINE\n"); $$.str = expandlabel_strdup($1); /* 19102004 prima era =$1 */ my_free(739, &$1); $$.m = 1; } - | list '*' B_NUM{ + + | list B_NAME { + dbg(3, "yyparse(): list B_NAME, $2=%s\n", $2); + $$.str = expandlabel_strcat($1.str, $2); + my_free(1208, &$1.str); + my_free(452, &$2); + $$.m = $1.m; + } + + | list '*' B_NUM + { dbg(3, "yyparse(): list * B_NUM\n"); dbg(3, "yyparse(): |%s| %d \n",$1.str,$3); $$.str=expandlabel_strmult2($3,$1.str); @@ -297,12 +293,21 @@ list: B_NAME { $$.m = $3 * $1.m; my_free(740, &$1.str); } - | B_NUM '*' list{ + | B_NUM '*' list + { dbg(3, "yyparse(): B_NUM * list\n"); $$.str=expandlabel_strmult($1,$3.str); $$.m = $1 * $3.m; my_free(741, &$3.str); } + | B_NAME '*' list + { + dbg(3, "yyparse(): B_NAME * list\n"); + $$.str=expandlabel_strcat_char($1, '*', $3.str); + $$.m = 1; + my_free(883, &$1); + my_free(158, &$3.str); + } | list ',' list { dbg(3, "yyparse(): list , list\n"); $$.str=expandlabel_strcat_char($1.str, ',', $3.str); diff --git a/src/globals.c b/src/globals.c index 3aaeadd0..bdc7dd7e 100644 --- a/src/globals.c +++ b/src/globals.c @@ -25,7 +25,6 @@ /* X11 specific globals */ Colormap colormap; -Window window; /* window is the drawing area, topwindow is the root win */ Window pre_window; /* preview when opening files */ Window parent_of_topwindow; unsigned char **pixdata; @@ -97,10 +96,11 @@ 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}/*21 */ }; GC *gcstipple,*gc, gctiled; +Pixmap *pixmap = NULL; Display *display; XRectangle xrect[1] = {{0,0,0,0}}; -Pixmap cad_icon_pixmap=0, cad_icon_mask=0, *pixmap,save_pixmap; /* save_pixmap used to restore window */ -XPoint *gridpoint; /* pointer to array of gridpoints, used in draw() */ +Pixmap cad_icon_pixmap=0, cad_icon_mask=0; +XPoint *gridpoint; /* pointer to array of gridpoints, used in draw() */ XColor xcolor_array[256]; Visual *visual; #ifdef HAS_CAIRO @@ -117,16 +117,54 @@ xcb_visualtype_t *visual_xcb; #endif /*HAS_CAIRO */ -int help=0; /* help option set to global scope, printing help is deferred */ - /* when configuration ~/.schem has been read 20140406 */ + +/* these variables are mirrored in tcl code */ int fullscreen=0; -int semaphore=0; /* needed at global scope as it is set by tcl */ +char *netlist_dir=NULL; /* user set netlist directory via cmd-option or menu or xschemrc */ +int top_subckt = 0; +int spiceprefix = 1; int unzoom_nodrift=1; +int change_lw=0; /* allow change xctx->lw */ +int incr_hilight=1; +unsigned short enable_stretch=0; +int auto_hilight=0; int a3page=-1; int has_x=1; -int no_draw=0; -int sym_txt=1; +int split_files=0; /* split netlist files 20081202 */ +double cadgrid = CADGRID; +double cadsnap = CADSNAP; +int draw_grid=1; int rainbow_colors=0; +int dis_uniq_names=0; /* if set allow instances with duplicate names */ +int persistent_command=0; /* remember last command 20181022 */ +int color_ps=-1; +int only_probes=0; +int netlist_show=0; +int flat_netlist=0; +int cadlayers=0; +int hide_symbols = 0; /* draw only a bounding box for component instances and @symname, @name texts */ +int dark_colorscheme=1; +char cairo_font_name[1024]="Sans Serif"; +char svg_font_name[1024]="Sans Serif"; +double cairo_font_scale=1.0; /* default: 1.0, allows to adjust font size */ +double nocairo_font_xscale=0.85; /* match with cairo sizing */ +double nocairo_font_yscale=0.88; /* match with cairo sizing */ +double cairo_font_line_spacing=1.0; /* allows to change line spacing: default: 1.0 */ +/* lift up the text by 'n' pixels (zoom corrected) within the bbox. */ +/* This correction is used to better align existing schematics */ +/* compared to the nocairo xschem version. */ +/* allowed values should be in the range [-4, 4] */ +double cairo_vert_correct=0.0; +double nocairo_vert_correct=0.0; +int sym_txt=1; +int netlist_type=-1; +int show_pin_net_names = 0; + + + +int help=0; /* help option set to global scope, printing help is deferred */ + /* when configuration ~/.schem has been read 20140406 */ +int no_draw=0; int manhattan_lines=0; FILE *errfp; char *filename=NULL; /* filename given on cmdline */ @@ -144,8 +182,6 @@ char plotfile[PATH_MAX] = {'\0'}; char rcfile[PATH_MAX] = {'\0'}; char *tcl_command = NULL; char tcl_script[PATH_MAX] = {'\0'}; -int persistent_command=0; /* remember last command 20181022 */ -int dis_uniq_names=0; /* if set allow instances with duplicate names */ int quit=0; /* set from process_options (ex netlist from cmdline and quit) */ int debug_var=-10; /* will be set to 0 in xinit.c */ int tcp_port = 0; @@ -154,13 +190,8 @@ int no_readline=0; int fill=1; /* filled rectangles */ int draw_pixmap=1; /* use pixmap for double buffer */ int draw_window=0; -int draw_grid=1; int text_svg=1; /* use svg element for text instead of xschem's internal vector font */ -double cadgrid = CADGRID; double cadhalfdotsize = CADHALFDOTSIZE; -int change_lw=0; /* allow change xctx->lw */ -int incr_hilight=1; -int auto_hilight=0; unsigned int color_index[256]; /* layer color lookup table */ unsigned int rectcolor ; /* this is the currently used layer */ char *undo_dirname = NULL; @@ -172,8 +203,6 @@ int draw_dots=1; int draw_single_layer=-1; int check_version = 0; /* if set ensures 'v' version header line is present before loading file */ int yyparse_error = 0; -unsigned short enable_stretch=0; -int cadlayers=0; int *enable_layer; int n_active_layers=0; int *active_layer; @@ -181,53 +210,26 @@ int depth; int *fill_type; /*20171117 for every layer: 0: no fill, 1, solid fill, 2: stipple fill */ char **color_array; char *xschem_executable=NULL; -double cadsnap = CADSNAP; double *character[256]; /* array or per-char coordinates of xschem internal vector font */ Tcl_Interp *interp; int do_netlist=0; /* set by process_options if user wants netllist from cmdline */ int do_simulation=0; int do_waves=0; int netlist_count=0; /* netlist counter incremented at any cell being netlisted */ -int top_subckt = 0; -int spiceprefix = 1; char hiersep[20]="."; -int netlist_show=0; -int flat_netlist=0; -int netlist_type=-1; char bus_char[3] = {0, 0, 0}; int horizontal_move=0; int vertical_move=0; -int color_ps=-1; -int only_probes=0; int hilight_color=0; int pending_fullzoom=0; -int split_files=0; /* split netlist files 20081202 */ -char *netlist_dir=NULL; /* user set netlist directory via cmd-option or menu or xschemrc */ -int dark_colorscheme=1; double color_dim=0.0; int no_undo=0; int enable_drill=0; /* 20171211 pass net hilights through components with 'propagate_to' property set on pins */ size_t get_tok_value_size; size_t get_tok_size; int batch_mode = 0; /* no tcl console if set; batch mode */ -int hide_symbols = 0; /* draw only a bounding box for component instances and @symname, @name texts */ -int show_pin_net_names = 0; - -char cairo_font_name[1024]="Sans Serif"; -char svg_font_name[1024]="Sans Serif"; int cairo_longest_line; int cairo_lines; -double cairo_font_scale=1.0; /* default: 1.0, allows to adjust font size */ -double nocairo_font_xscale=0.85; /* match with cairo sizing */ -double nocairo_font_yscale=0.88; /* match with cairo sizing */ -double cairo_font_line_spacing=1.0; /* allows to change line spacing: default: 1.0 */ - -/* lift up the text by 'n' pixels (zoom corrected) within the bbox. */ -/* This correction is used to better align existing schematics */ -/* compared to the nocairo xschem version. */ -/* allowed values should be in the range [-4, 4] */ -double cairo_vert_correct=0.0; -double nocairo_vert_correct=0.0; int show_erc=1; int hilight_nets=0; diff --git a/src/move.c b/src/move.c index 39419d05..b417c528 100644 --- a/src/move.c +++ b/src/move.c @@ -1040,7 +1040,7 @@ void move_objects(int what, int merge, double dx, double dy) int save_draw; save_draw = draw_window; - draw_window=1; /* temporarily re-enable draw to window together with pixmap */ + draw_window=1; /* temporarily re-enable draw to xctx->window together with pixmap */ draw_selection(gctiled,0); bbox(START, 0.0 , 0.0 , 0.0 , 0.0); set_modify(1); diff --git a/src/save.c b/src/save.c index 1b175167..86e9871c 100644 --- a/src/save.c +++ b/src/save.c @@ -986,9 +986,9 @@ void load_schematic(int load_symbols, const char *filename, int reset_undo) /* 2 if(filename && filename[0]) { my_strncpy(name, filename, S(name)); my_strncpy(xctx->sch[xctx->currsch], name, S(xctx->sch[xctx->currsch])); - /* if current_dirname is /some/path/. remove /. at end */ - my_snprintf(msg, S(msg), "set current_dirname \"[regsub {/\\.$} [file dirname {%s}] {}]\"", name); - tcleval(msg); + /* if name is /some/path/. remove /. at end */ + my_snprintf(msg, S(msg), "regsub {/\\.$} [file dirname {%s}] {}", name); + my_strncpy(xctx->current_dirname, tcleval(msg), S(xctx->current_dirname)); my_strncpy(xctx->current_name, rel_sym_path(name), S(xctx->current_name)); dbg(1, "load_schematic(): opening file for loading:%s, filename=%s\n", name, filename); dbg(1, "load_schematic(): sch[currsch]=%s\n", xctx->sch[xctx->currsch]); diff --git a/src/scheduler.c b/src/scheduler.c index 68ed1421..2ab298e9 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -311,7 +311,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(!strcmp(argv[1],"place_symbol")) { int ret; - semaphore++; + xctx->semaphore++; xctx->mx_double_save = xctx->mousex_snap; xctx->my_double_save = xctx->mousey_snap; if(argc == 4) { @@ -328,7 +328,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg move_objects(START,0,0,0); xctx->ui_state |= PLACE_SYMBOL; } - semaphore--; + xctx->semaphore--; Tcl_ResetResult(interp); } @@ -1823,7 +1823,15 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg } else if(!strcmp(argv[1],"get") && argc==3) { - if(!strcmp(argv[2],"incr_hilight")) { + if(!strcmp(argv[2],"current_dirname")) { + Tcl_SetResult(interp, xctx->current_dirname, TCL_VOLATILE); + } + else if(!strcmp(argv[2],"line_width")) { + char s[40]; + my_snprintf(s, S(s), "%g", xctx->lw); + Tcl_SetResult(interp, s, TCL_VOLATILE); + } + else if(!strcmp(argv[2],"incr_hilight")) { if( incr_hilight != 0 ) Tcl_AppendResult(interp, "1",NULL); else @@ -1949,7 +1957,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg } else if(!strcmp(argv[2],"semaphore")) { char s[30]; /* overflow safe 20161122 */ - my_snprintf(s, S(s), "%d",semaphore); + my_snprintf(s, S(s), "%d",xctx->semaphore); Tcl_AppendResult(interp, s,NULL); } else if(!strcmp(argv[2],"change_lw")) { @@ -2167,7 +2175,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg tclsetvar("netlist_show", netlist_show ? "1" : "0"); } else if(!strcmp(argv[2],"semaphore")) { - semaphore=atoi(argv[3]); + xctx->semaphore=atoi(argv[3]); } else if(!strcmp(argv[2],"cadsnap")) { set_snap( atof(argv[3]) ); diff --git a/src/spice_netlist.c b/src/spice_netlist.c index 3b200880..d5d00c02 100644 --- a/src/spice_netlist.c +++ b/src/spice_netlist.c @@ -347,7 +347,7 @@ void spice_block_netlist(FILE *fd, int i) } else { dbg(1, "spice_block_netlist(): loading: %s -> %s\n", xctx->sym[i].name, add_ext(abs_sym_path(xctx->sym[i].name, ""), ".sch")); - dbg(1, "spice_block_netlist(): current_dirname=%s\n", tclgetvar("current_dirname")); + dbg(1, "spice_block_netlist(): current_dirname=%s\n", xctx->current_dirname); load_schematic(1, add_ext(abs_sym_path(xctx->sym[i].name, ""), ".sch") ,0); } spice_netlist(fd, spice_stop); /* 20111113 added spice_stop */ diff --git a/src/tedax_netlist.c b/src/tedax_netlist.c index 1cdaa92d..a8a64f5c 100644 --- a/src/tedax_netlist.c +++ b/src/tedax_netlist.c @@ -175,7 +175,7 @@ void tedax_block_netlist(FILE *fd, int i) } else { dbg(1, "tedax_block_netlist(): loading: %s -> %s\n", xctx->sym[i].name, add_ext(abs_sym_path(xctx->sym[i].name, ""), ".sch")); - dbg(1, "tedax_block_netlist(): current_dirname=%s\n", tclgetvar("current_dirname")); + dbg(1, "tedax_block_netlist(): current_dirname=%s\n", xctx->current_dirname); load_schematic(1, add_ext(abs_sym_path(xctx->sym[i].name, ""), ".sch"), 0); } tedax_netlist(fd, tedax_stop); diff --git a/src/xinit.c b/src/xinit.c index 08ac7f5b..c890e22b 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -362,8 +362,13 @@ void free_xschem_data() my_free(1131, &xctx->maxp); my_free(1132, &xctx->maxa); my_free(1133, &xctx->maxl); + my_free(1108, &xctx->sel_array); for(i=0;isch_path[i]); - + #ifdef __unix__ + XFreePixmap(display,xctx->save_pixmap); + #else + Tk_FreePixmap(display, xctx->save_pixmap); + #endif my_free(269, &xctx); } @@ -396,6 +401,7 @@ void alloc_xschem_data() xctx->prep_hash_inst = 0; xctx->prep_hash_wires = 0; xctx->modified = 0; + xctx->semaphore = 0; xctx->netlist_name[0] = '\0'; for(i=0;isch_path[i]=NULL; @@ -555,6 +561,16 @@ void alloc_xschem_data() if(xctx->lines==NULL){ fprintf(errfp, "Tcl_AppInit(): calloc error\n");tcleval( "exit"); } + xctx->maxsel=MAXGROUP; + xctx->sel_array=my_calloc(619, xctx->maxsel, sizeof(Selected)); + if(xctx->sel_array==NULL){ + fprintf(errfp, "Tcl_AppInit(): calloc error\n");tcleval( "exit"); + } + pixmap=my_calloc(636, cadlayers, sizeof(Pixmap)); + if(pixmap==NULL){ + fprintf(errfp, "Tcl_AppInit(): calloc error\n");tcleval( "exit"); + } + } void alloc_data() @@ -564,22 +580,11 @@ void alloc_data() alloc_xschem_data(); /* global context / graphic preferences/settings */ - xctx->maxsel=MAXGROUP; - xctx->sel_array=my_calloc(619, xctx->maxsel, sizeof(Selected)); - if(xctx->sel_array==NULL){ - fprintf(errfp, "Tcl_AppInit(): calloc error\n");tcleval( "exit"); - } - gridpoint=(XPoint*)my_calloc(608, CADMAXGRIDPOINTS,sizeof(XPoint)); if(gridpoint==NULL){ fprintf(errfp, "Tcl_AppInit(): calloc error\n");tcleval( "exit"); } - pixmap=my_calloc(636, cadlayers, sizeof(Pixmap)); - if(pixmap==NULL){ - fprintf(errfp, "Tcl_AppInit(): calloc error\n");tcleval( "exit"); - } - color_array=my_calloc(637, cadlayers, sizeof(char*)); if(color_array==NULL){ fprintf(errfp, "Tcl_AppInit(): calloc error\n");tcleval( "exit"); @@ -639,13 +644,6 @@ void xwin_exit(void) cairo_surface_destroy(sfc); cairo_surface_destroy(save_sfc); #endif -#ifdef __unix__ - XFreePixmap(display,save_pixmap); - for(i=0;isel_array); my_free(1120, &fill_type); my_free(1121, &active_layer); my_free(1122, &pixdata); my_free(1123, &enable_layer); my_free(1099, &gridpoint); - my_free(1134, &pixmap); my_free(1135, &gc); my_free(1136, &gcstipple); my_free(1137, &color_array); @@ -844,62 +846,42 @@ void preview_window(const char *what, const char *tk_win_path, const char *filen } else if(!strcmp(what, "draw")) { Xschem_ctx *save_xctx = NULL; /* save pointer to current schematic context structure */ - char *saveptr = NULL; - int save_mod, save_show_pin; - Pixmap save_save_pixmap; - Window save_window; - + int save_show_pin; save_xctx = xctx; /* save current schematic */ xctx = NULL; /* reset for preview */ alloc_xschem_data(); /* alloc data into xctx */ /* save some relevant global context */ - save_window = window; - save_save_pixmap = save_pixmap; - save_mod = xctx->modified; save_show_pin = show_pin_net_names; show_pin_net_names = 0; - my_strdup(117, &saveptr, tclgetvar("current_dirname")); /* preview */ check_version = 0; /* if set refuse to load and preview anything if not a rel 1.1+ xschem file */ /* if not set heuristics is done in xschem.tcl to ensure it is an xschem file */ load_schematic(1,filename, 0); - window = pre_window; - resetwin(1, 0, 1); + xctx->window = pre_window; + resetwin(1, 0, 1); /* resetwin( create_pixmap, clear_pixmap, preview_window) */ zoom_full(1, 0); /* draw */ check_version = 0; /* restore context */ - tclsetvar("current_dirname", saveptr); - my_free(1144, &saveptr); unselect_all(); remove_symbols(); clear_drawing(); free_xschem_data(); show_pin_net_names = save_show_pin; - xctx = save_xctx; /* restore schematic */ - xctx->modified = save_mod; - set_modify(xctx->modified); /* free the pixmap (if a different one) used for preview */ -#ifdef __unix__ - if (save_pixmap != save_save_pixmap) - XFreePixmap(display,save_pixmap); -#else - if (save_pixmap != save_save_pixmap) - Tk_FreePixmap(display, save_pixmap); -#endif - window = save_window; - save_pixmap = save_save_pixmap; - /* reset window (back to main window), but don't delete and create a pixmap since we + xctx = save_xctx; /* restore schematic */ + set_modify(xctx->modified); + /* reset window (back to main xctx->window), but don't delete and create a pixmap since we have preserved the main window pixmap and already erased the preview pixmap the goal of this complicated pixmap saving is to avoid a draw() call in the main window to regenerate the save_pixmap every time user browses a new symbol */ - resetwin(0, 0, 0); + resetwin(0, 0, 0); /* preview save_pixmap already deleted in free_xschem_data() */ change_linewidth(-1.); - /* not needed: event loop takes care of this and don't need to regenerate save_pixmap. */ + /* not needed: event loop takes care of this and don't need to regenerate xctx->save_pixmap. */ /* draw(); */ } else if(!strcmp(what, "destroy")) { @@ -1260,8 +1242,8 @@ int Tcl_AppInit(Tcl_Interp *inter) xctx->xschem_w = CADWIDTH; xctx->xschem_h = CADHEIGHT; - xctx->areaw = CADWIDTH+4*INT_WIDTH(xctx->lw); /* clip area extends 1 pixel beyond physical window area */ - xctx->areah = CADHEIGHT+4*INT_WIDTH(xctx->lw); /* to avoid drawing clipped rectangle borders at window edges */ + xctx->areaw = CADWIDTH+4*INT_WIDTH(xctx->lw); /* clip area extends 1 pixel beyond physical xctx->window area */ + xctx->areah = CADHEIGHT+4*INT_WIDTH(xctx->lw); /* to avoid drawing clipped rectangle borders at xctx->window edges */ xctx->areax1 = -2*INT_WIDTH(xctx->lw); xctx->areay1 = -2*INT_WIDTH(xctx->lw); xctx->areax2 = xctx->areaw-2*INT_WIDTH(xctx->lw); @@ -1278,16 +1260,12 @@ int Tcl_AppInit(Tcl_Interp *inter) for(i = 0; i < cadlayers; i++) enable_layer[i] = 1; compile_font(); /* restore current dir after loading font */ - if(tcleval("info exists env(PWD)")[0] == '1') { + if(getenv("PWD")) { /* $env(PWD) better than pwd_dir as it does not dereference symlinks */ - tcleval("set current_dirname $env(PWD)"); + my_strncpy(xctx->current_dirname, getenv("PWD"), S(xctx->current_dirname)); } else { - Tcl_VarEval(interp, "set current_dirname ", pwd_dir, NULL); + my_strncpy(xctx->current_dirname, pwd_dir, S(xctx->current_dirname)); } - /* - my_snprintf(tmp, S(tmp), "set current_dirname \"%s\"", pwd_dir); - tcleval(tmp); - */ /* */ /* X INITIALIZATION */ @@ -1301,10 +1279,10 @@ int Tcl_AppInit(Tcl_Interp *inter) display = Tk_Display(mainwindow); tkwindow = Tk_NameToWindow(interp, ".drw", mainwindow); Tk_MakeWindowExist(tkwindow); - window = Tk_WindowId(tkwindow); + xctx->window = Tk_WindowId(tkwindow); topwindow = Tk_WindowId(mainwindow); - dbg(1, "Tcl_AppInit(): drawing window ID=0x%lx\n",window); + dbg(1, "Tcl_AppInit(): drawing window ID=0x%lx\n",xctx->window); dbg(1, "Tcl_AppInit(): top window ID=0x%lx\n",topwindow); dbg(1, "Tcl_AppInit(): done tkinit()\n"); @@ -1363,45 +1341,45 @@ int Tcl_AppInit(Tcl_Interp *inter) rectcolor= 4; /* this is the current layer when xschem started. */ for(i=0;iwindow, (char*)(pixdata[i]),16,16); + gc[i] = XCreateGC(display,xctx->window,0L,NULL); + gcstipple[i] = XCreateGC(display,xctx->window,0L,NULL); XSetStipple(display,gcstipple[i],pixmap[i]); if(fill_type[i]==1) XSetFillStyle(display,gcstipple[i],FillSolid); else XSetFillStyle(display,gcstipple[i],FillStippled); } - gctiled = XCreateGC(display,window,0L, NULL); + 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"); - /* save_pixmap must be created as resetwin() frees it before recreating with new size. */ + /* xctx->save_pixmap must be created as resetwin() frees it before recreating with new size. */ #ifdef __unix__ - save_pixmap = XCreatePixmap(display,window,CADWIDTH,CADHEIGHT,depth); + xctx->save_pixmap = XCreatePixmap(display,xctx->window,CADWIDTH,CADHEIGHT,depth); #else - save_pixmap = Tk_GetPixmap(display, window, CADWIDTH, CADHEIGHT, depth); + xctx->save_pixmap = Tk_GetPixmap(display, xctx->window, CADWIDTH, CADHEIGHT, depth); #endif - XSetTile(display, gctiled, save_pixmap); + XSetTile(display, gctiled, xctx->save_pixmap); XSetFillStyle(display,gctiled,FillTiled); #ifdef HAS_CAIRO { XWindowAttributes wattr; - XGetWindowAttributes(display, window, &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, window, &format_rgb, 1 , 1); + screen_xcb, xctx->window, &format_rgb, 1 , 1); save_sfc = cairo_xcb_surface_create_with_xrender_format(xcbconn, - screen_xcb, save_pixmap, &format_rgb, 1 , 1); + screen_xcb, xctx->save_pixmap, &format_rgb, 1 , 1); #else format = XRenderFindStandardFormat(display, PictStandardRGB24); sfc = cairo_xlib_surface_create_with_xrender_format (display, - window, DefaultScreenOfDisplay(display), format, 1, 1); + xctx->window, DefaultScreenOfDisplay(display), format, 1, 1); save_sfc = cairo_xlib_surface_create_with_xrender_format( - display, save_pixmap, DefaultScreenOfDisplay(display), format, 1, 1); + display, xctx->save_pixmap, DefaultScreenOfDisplay(display), format, 1, 1); #endif #else - sfc = cairo_xlib_surface_create(display, window, visual, wattr.width, wattr.height); - save_sfc = cairo_xlib_surface_create(display, save_pixmap, visual, wattr.width, wattr.height); + sfc = cairo_xlib_surface_create(display, xctx->window, visual, wattr.width, wattr.height); + 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"); @@ -1428,19 +1406,16 @@ int Tcl_AppInit(Tcl_Interp *inter) 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 (cairo_save_ctx, cairo_font_name, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); - cairo_set_font_size (cairo_save_ctx, 20); - - cairo_save_ctx = cairo_create(save_sfc); + 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(cairo_save_ctx, cairo_font_name, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size(cairo_save_ctx, 20); cairo_set_line_width(cairo_ctx, 1); cairo_set_line_width(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(cairo_save_ctx, CAIRO_LINE_JOIN_ROUND); cairo_set_line_cap(cairo_save_ctx, CAIRO_LINE_CAP_ROUND); - } #endif /* HAS_CAIRO */ @@ -1453,8 +1428,6 @@ int Tcl_AppInit(Tcl_Interp *inter) dbg(1, "Tcl_AppInit(): sizeof xInstance=%lu , sizeof xSymbol=%lu\n", (unsigned long) sizeof(xInstance),(unsigned long) sizeof(xSymbol)); - - tcleval("xschem line_width $line_width"); #ifdef __unix__ dbg(1, "Tcl_AppInit(): xserver max request size: %d\n", (int)XMaxRequestSize(display)); diff --git a/src/xschem.h b/src/xschem.h index 58015461..4cd7bbb7 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -524,10 +524,14 @@ typedef struct { int prep_hash_inst; int prep_hash_wires; int modified; + int semaphore; char netlist_name[PATH_MAX]; + char current_dirname[PATH_MAX]; struct instpinentry *instpintable[NBOXES][NBOXES]; struct wireentry *wiretable[NBOXES][NBOXES]; struct instentry *insttable[NBOXES][NBOXES]; + Window window; + Pixmap save_pixmap; } Xschem_ctx; struct Lcc { /* used for symbols containing schematics as instances (LCC, Local Custom Cell) */ @@ -605,7 +609,6 @@ struct instentry { extern Xschem_ctx *xctx; extern int help; extern char *cad_icon[]; -extern int semaphore; extern int a3page; extern int manhattan_lines; extern int cadlayers; @@ -718,7 +721,6 @@ extern const char fopen_read_mode[]; /* X11 specific globals */ extern Colormap colormap; -extern Window window; extern Window pre_window; extern Window parent_of_topwindow; extern unsigned char **pixdata; @@ -727,7 +729,7 @@ extern GC *gc, *gcstipple, gctiled; extern Display *display; extern XRectangle *rectangle; extern XPoint *gridpoint; -extern Pixmap cad_icon_pixmap, cad_icon_mask, *pixmap,save_pixmap; +extern Pixmap cad_icon_pixmap, cad_icon_mask, *pixmap; extern XColor xcolor_array[]; extern Visual *visual; #ifdef HAS_CAIRO diff --git a/src/xschem.tcl b/src/xschem.tcl index ab29bf6a..681c75cd 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -779,7 +779,7 @@ proc simulate {{callback {}}} { ## $S : schematic name full path (/home/schippes/.xschem/xschem_library/opamp.sch) ## $d : netlist directory - global netlist_dir netlist_type computerfarm terminal current_dirname sim + global netlist_dir netlist_type computerfarm terminal sim global execute_callback XSCHEM_SHAREDIR set_sim_defaults @@ -892,7 +892,7 @@ proc waves {} { ## $S : schematic name full path (/home/schippes/.xschem/xschem_library/opamp.sch) ## $d : netlist directory - global netlist_dir netlist_type computerfarm terminal current_dirname sim XSCHEM_SHAREDIR + global netlist_dir netlist_type computerfarm terminal sim XSCHEM_SHAREDIR set_sim_defaults if { [select_netlist_dir 0] ne {}} { @@ -1122,15 +1122,16 @@ proc myload_set_colors2 {} { } } proc myload_set_home {dir} { - global pathlist myload_files1 myload_index1 current_dirname + global pathlist myload_files1 myload_index1 + set curr_dirname [xschem get current_dirname] .dialog.l.paneleft.list selection clear 0 end - if { $dir eq {.}} { set dir $current_dirname} + if { $dir eq {.}} { set dir $curr_dirname} # puts "set home: dir=$dir, pathlist=$pathlist" set pl {} foreach path_elem $pathlist { - if { ![string compare $path_elem .] && [info exist current_dirname]} { - set path_elem $current_dirname + if { ![string compare $path_elem .]} { + set path_elem $curr_dirname } lappend pl $path_elem } @@ -1745,7 +1746,7 @@ proc enter_text {textlabel {preserve_disabled disabled}} { button .dialog.buttons.b3 -text "Load" -command \ { global INITIALTEXTDIR - if { ![info exists INITIALTEXTDIR] } { set INITIALTEXTDIR $current_dirname } + if { ![info exists INITIALTEXTDIR] } { set INITIALTEXTDIR [xschem get current_dirname] } set a [tk_getOpenFile -parent .dialog -initialdir $INITIALTEXTDIR ] if [string compare $a ""] { set INITIALTEXTDIR [file dirname $a] @@ -2770,12 +2771,13 @@ proc viewdata {data {ro {}}} { # given an absolute path of a symbol/schematic remove the path prefix # if file is in a library directory (a $pathlist dir) proc rel_sym_path {symbol} { - global pathlist current_dirname + global pathlist + set curr_dirname [xschem get current_dirname] set name {} foreach path_elem $pathlist { - if { ![string compare $path_elem .] && [info exist current_dirname]} { - set path_elem $current_dirname + if { ![string compare $path_elem .] && [info exist curr_dirname]} { + set path_elem $curr_dirname } set pl [string length $path_elem] if { [string equal -length $pl $path_elem $symbol] } { @@ -2793,7 +2795,9 @@ proc rel_sym_path {symbol} { # given a library/symbol return its absolute path proc abs_sym_path {fname {ext {} } } { - global pathlist current_dirname + global pathlist + + set curr_dirname [xschem get current_dirname] # empty: do nothing if {$fname eq {} } return {} @@ -2819,9 +2823,9 @@ proc abs_sym_path {fname {ext {} } } { # remove trailing '/'s to non empty path regsub {([^/]+)/+$} $fname {\1} fname # if fname copy tmpfname is ../../e/f - # and current_dirname copy tmpdirname is /a/b/c + # and curr_dirname copy tmpdirname is /a/b/c # set tmpfname to /a/e/f - set tmpdirname $current_dirname + set tmpdirname $curr_dirname set tmpfname $fname set found 0 while { [regexp {^\.\./} $tmpfname ] } { @@ -2840,16 +2844,16 @@ proc abs_sym_path {fname {ext {} } } { while { [regsub {^\./} $fname {} fname] } {} # if previous operation left fname empty set to '.' if { $fname eq {} } { set fname . } - # if fname is just "." return $current_dirname + # if fname is just "." return $curr_dirname if {[regexp {^\.$} $fname] } { - return "$current_dirname" + return "$curr_dirname" } # if fname is present in one of the pathlist paths get the absolute path set name {} foreach path_elem $pathlist { # in xschem a . in pathlist means the directory of currently loaded schematic/symbol - if { ![string compare $path_elem .] && [info exist current_dirname]} { - set path_elem $current_dirname + if { ![string compare $path_elem .] && [info exist curr_dirname]} { + set path_elem $curr_dirname } set fullpath "$path_elem/$fname" if { [file exists $fullpath] } { @@ -2858,7 +2862,7 @@ proc abs_sym_path {fname {ext {} } } { } } if {$name eq {} } { - set name "$current_dirname/$fname" + set name "$curr_dirname/$fname" } regsub {/\.$} $name {} name return $name @@ -3305,7 +3309,6 @@ set_ne fullscreen 0 set_ne unzoom_nodrift 1 set_ne change_lw 0 set_ne draw_window 0 -set_ne line_width 0 set_ne incr_hilight 1 set_ne enable_stretch 0 set_ne horizontal_move 0 ; # 20171023