From 64c0abc58e572f8ff624e0820feead9d913101b5 Mon Sep 17 00:00:00 2001 From: Stefan Schippers Date: Mon, 12 Oct 2020 13:13:31 +0200 Subject: [PATCH] code refactoring (global context in Xschem_ctx), "New Schematic" or "New Symbol" will set netlist_type to "spice" or "symbol" respectively --- src/actions.c | 886 ++++++++++++++++----------------- src/callback.c | 290 +++++------ src/check.c | 333 +++++++------ src/clip.c | 10 +- src/draw.c | 528 ++++++++++---------- src/editprop.c | 593 ++++++++++++----------- src/findnet.c | 114 ++--- src/font.c | 26 +- src/globals.c | 88 +--- src/hash_iterator.c | 22 +- src/hilight.c | 372 +++++++------- src/hspice_backannotate.tcl | 2 +- src/icon.c | 4 +- src/in_memory_undo.c | 290 +++++------ src/main.c | 24 +- src/move.c | 916 ++++++++++++++++++----------------- src/netlist.c | 564 ++++++++++----------- src/ngspice_backannotate.tcl | 4 +- src/node_hash.c | 84 ++-- src/options.c | 4 +- src/paste.c | 182 +++---- src/psprint.c | 209 ++++---- src/rawtovcd.c | 16 +- src/save.c | 791 +++++++++++++++--------------- src/scheduler.c | 451 ++++++++--------- src/select.c | 715 +++++++++++++-------------- src/spice_netlist.c | 228 ++++----- src/store.c | 304 ++++++------ src/svgdraw.c | 212 ++++---- src/tedax_netlist.c | 110 ++--- src/token.c | 810 ++++++++++++++++--------------- src/verilog_netlist.c | 314 ++++++------ src/vhdl_netlist.c | 454 ++++++++--------- src/xinit.c | 552 +++++++++------------ src/xschem.h | 275 +++++------ src/xschem.tcl | 10 +- 36 files changed, 5344 insertions(+), 5443 deletions(-) diff --git a/src/actions.c b/src/actions.c index e6fc25a8..0470a0d7 100644 --- a/src/actions.c +++ b/src/actions.c @@ -1,7 +1,7 @@ /* File: actions.c - * + * * This file is part of XSCHEM, - * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit + * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit * simulation. * Copyright (C) 1998-2020 Stefan Frederik Schippers * @@ -26,23 +26,23 @@ #endif void here(void) -{ +{ fprintf(stderr, "here\n"); } -void set_modify(int mod) +void set_modify(int mod) { static int prev = -1; modified = mod; if(mod != prev) { prev = mod; - if(has_x && strcmp(get_cell(schematic[currentsch],1), "systemlib/font")) { + if(has_x && strcmp(get_cell(xctx.sch[xctx.currsch],1), "systemlib/font")) { if(mod == 1) { - tcleval( "wm title . \"xschem - [file tail [xschem get schname]]*\""); /* 20161207 */ - tcleval( "wm iconname . \"xschem - [file tail [xschem get schname]]*\""); /* 20161207 */ + tcleval( "wm title . \"xschem - [file tail [xschem get schname]]*\""); + tcleval( "wm iconname . \"xschem - [file tail [xschem get schname]]*\""); } else { - tcleval( "wm title . \"xschem - [file tail [xschem get schname]]\""); /* 20161207 */ - tcleval( "wm iconname . \"xschem - [file tail [xschem get schname]]\""); /* 20161207 */ + tcleval( "wm title . \"xschem - [file tail [xschem get schname]]\""); + tcleval( "wm iconname . \"xschem - [file tail [xschem get schname]]\""); } } } @@ -188,7 +188,7 @@ const char *add_ext(const char *f, const char *ext) i = my_strncpy(ff, f, S(ff)); p = ff+i; dbg(1, "add_ext() 2: ff=%s\n", ff); - } + } my_strncpy(p, ext, S(ff)-(p-ff)); dbg(1, "add_ext() 3: ff=%s\n", ff); return ff; @@ -202,7 +202,7 @@ void resetwin(void) #ifdef __unix__ i = XGetWindowAttributes(display, window, &wattr); /* should call only when resized */ /* to avoid server roundtrip replies */ - if(!i) { /* 20171105 */ + if(!i) { return; } /* if(wattr.map_state==IsUnmapped) return; */ @@ -221,31 +221,31 @@ void resetwin(void) wattr.x, wattr.y, xschem_w,xschem_h); dbg(1, "resetwin(): changing size\n\n"); xrect[0].x = 0; - xrect[0].y = 0; + xrect[0].y = 0; xrect[0].width = xschem_w; xrect[0].height = xschem_h; - + XFreePixmap(display,save_pixmap); - - /* + + /* { unsigned int w, h; XQueryBestSize(display, TileShape, window, xschem_w, xschem_h, &w, &h); - dbg(1, "XQueryBestSize: req: w=%d, h=%d, opt: w=%d h=%d\n", + dbg(1, "XQueryBestSize: req: w=%d, h=%d, opt: w=%d h=%d\n", xschem_w, xschem_h, w, h); } */ - save_pixmap = XCreatePixmap(display, window, xschem_w, xschem_h, depth); /* 20171111 */ + save_pixmap = XCreatePixmap(display, window, xschem_w, xschem_h, depth); XSetTile(display,gctiled, save_pixmap); #else Tk_Window mainwindow = Tk_MainWindow(interp); HWND hwnd = Tk_GetHWND(Tk_WindowId(mainwindow)); - RECT rect; - if (GetWindowRect(hwnd, &rect)) + RECT rct; + if (GetWindowRect(hwnd, &rct)) { - unsigned int width = rect.right - rect.left; - unsigned int height = rect.bottom - rect.top; + unsigned int width = rct.right - rct.left; + unsigned int height = rct.bottom - rct.top; xschem_w = width; xschem_h = height; areax2 = xschem_w + 2 * lw; @@ -254,16 +254,16 @@ void resetwin(void) areay1 = -2 * lw; areaw = areax2 - areax1; areah = areay2 - areay1; - if (xschem_w != xrect[0].width || xschem_h != xrect[0].height) { /* 20171123 avoid unnecessary work if no resize */ + if (xschem_w != xrect[0].width || xschem_h != xrect[0].height) { /* avoid unnecessary work if no resize */ dbg(1, "resetwin(): x=%d y=%d xschem_w=%d xschem_h=%d\n", - rect.right, rect.bottom, xschem_w, xschem_h); + rct.right, rct.bottom, xschem_w, xschem_h); dbg(1, "resetwin(): changing size\n\n"); xrect[0].x = 0; xrect[0].y = 0; xrect[0].width = xschem_w; xrect[0].height = xschem_h; Tk_FreePixmap(display, save_pixmap); - save_pixmap = Tk_GetPixmap(display, window, xschem_w, xschem_h, depth); /* 20171111 */ + save_pixmap = Tk_GetPixmap(display, window, xschem_w, xschem_h, depth); XSetTile(display, gctiled, save_pixmap); } #endif @@ -273,10 +273,10 @@ void resetwin(void) #if HAS_XRENDER==1 #if HAS_XCB==1 - save_sfc = cairo_xcb_surface_create_with_xrender_format(xcbconn, screen_xcb, save_pixmap, + save_sfc = cairo_xcb_surface_create_with_xrender_format(xcbconn, screen_xcb, save_pixmap, &format_rgb, xschem_w, xschem_h); #else - save_sfc = cairo_xlib_surface_create_with_xrender_format(display, save_pixmap, + save_sfc = cairo_xlib_surface_create_with_xrender_format(display, save_pixmap, DefaultScreenOfDisplay(display), format, xschem_w, xschem_h); #endif /* HAS_XCB */ #else @@ -294,18 +294,18 @@ void resetwin(void) 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, xschem_w, xschem_h); /* 20171123 */ + cairo_xcb_surface_set_size(sfc, xschem_w, xschem_h); #else - cairo_xlib_surface_set_size(sfc, xschem_w, xschem_h); /* 20171123 */ + cairo_xlib_surface_set_size(sfc, xschem_w, xschem_h); #endif /* HAS_XCB */ #endif /* HAS_CAIRO */ - } + } if(pending_fullzoom) { zoom_full(0, 0); pending_fullzoom=0; - } + } /* debug ... */ dbg(1, "resetwin(): Window reset\n"); } @@ -351,7 +351,7 @@ void toggle_fullscreen() pack .statusbar -after .drw -anchor sw -fill x; update"); menu_removed=0; } - + if(fullscreen == 1) { window_state(display , parent_of_topwindow,fullscr); @@ -367,15 +367,15 @@ void toggle_fullscreen() #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; - + dbg(1, "new_window(): executable: %s, cell=%s, symbol=%d\n", xschem_executable, cell, symbol); - if(stat(xschem_executable,&buf)) { /* 20121110 */ + if(stat(xschem_executable,&buf)) { fprintf(errfp, "new_window(): executable not found\n"); return; } @@ -424,7 +424,7 @@ void new_window(const char* cell, int symbol) { struct stat buf; dbg(1, "new_window(): executable: %s, cell=%s, symbol=%d\n", xschem_executable, cell, symbol); - if (stat(xschem_executable, &buf)) { /* 20121110 */ + if (stat(xschem_executable, &buf)) { fprintf(errfp, "new_window(): executable not found\n"); return; } @@ -443,7 +443,7 @@ const char *get_file_path(char *f) int save(int confirm) /* 20171006 add confirm */ { int cancel; - int save_ok; /* 20171020 */ + int save_ok; save_ok=0; cancel=0; @@ -452,9 +452,9 @@ int save(int confirm) /* 20171006 add confirm */ if(confirm) { tcleval("ask_save"); if(!strcmp(tclresult(), "") ) cancel=1; - if(!strcmp(tclresult(), "yes") ) save_ok = save_schematic(abs_sym_path(schematic[currentsch],"")); + if(!strcmp(tclresult(), "yes") ) save_ok = save_schematic(abs_sym_path(xctx.sch[xctx.currsch],"")); } else { - save_ok = save_schematic(abs_sym_path(schematic[currentsch],"")); + save_ok = save_schematic(abs_sym_path(xctx.sch[xctx.currsch],"")); } } if(save_ok==-1) return 1; @@ -468,7 +468,7 @@ void saveas(const char *f, int type) /* changed name from ask_save_file to save char res[PATH_MAX]; char *p; if(!f && has_x) { - my_strncpy(filename , abs_sym_path(schematic[currentsch], ""), S(filename)); + my_strncpy(filename , abs_sym_path(xctx.sch[xctx.currsch], ""), S(filename)); if(type == SYMBOL) { if( (p = strrchr(filename, '.')) && !strcmp(p, ".sch") ) { my_strncpy(filename, add_ext(filename, ".sym"), S(filename)); @@ -486,22 +486,22 @@ void saveas(const char *f, int type) /* changed name from ask_save_file to save } else res[0]='\0'; - if(!res[0]) return; /* 20071104 */ + if(!res[0]) return; dbg(1, "saveas(): res = %s\n", res); save_schematic(res); Tcl_VarEval(interp, "update_recent_file {", res,"}", NULL); - my_strncpy(current_name, rel_sym_path(res), S(current_name)); /* 20190519 */ + my_strncpy(xctx.current_name, rel_sym_path(res), S(xctx.current_name)); return; } void ask_new_file(void) { char fullname[PATH_MAX]; /* overflow safe 20161125 */ - + if(!has_x) return; - if(modified) { /* 20161209 */ + if(modified) { if(save(1)) return; /* user cancels save, so do nothing. */ } tcleval("load_file_dialog {Load Schematic} .sch.sym INITIALLOADDIR"); @@ -511,108 +511,108 @@ void ask_new_file(void) if( fullname[0] ) { dbg(1, "ask_new_file(): load file: %s\n", fullname); delete_hilight_net(); - currentsch = 0; - unselect_all(); /* 20180929 */ + xctx.currsch = 0; + unselect_all(); remove_symbols(); load_schematic(1, fullname,1); /* 20180925.1 */ Tcl_VarEval(interp, "update_recent_file {", fullname, "}", NULL); - my_strdup(1, &sch_path[currentsch],"."); - sch_inst_number[currentsch] = 1; + my_strdup(1, &xctx.sch_path[xctx.currsch],"."); + xctx.sch_inst_number[xctx.currsch] = 1; zoom_full(1, 0); } } -/* remove symbol and decrement lastinstdef */ +/* remove symbol and decrement xctx.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 */ void remove_symbol(int j) { int i,c; - Instdef save; + xSymbol save; dbg(1, "remove_symbol(): removing symbol %d\n", j); - if(instdef[j].prop_ptr != NULL) { - my_free(666, &instdef[j].prop_ptr); + if(xctx.sym[j].prop_ptr != NULL) { + my_free(666, &xctx.sym[j].prop_ptr); } - /* 20150409 */ - if(instdef[j].templ != NULL) { - my_free(667, &instdef[j].templ); + + if(xctx.sym[j].templ != NULL) { + my_free(667, &xctx.sym[j].templ); } - if(instdef[j].type != NULL) { - my_free(668, &instdef[j].type); + if(xctx.sym[j].type != NULL) { + my_free(668, &xctx.sym[j].type); } /* /20150409 */ - for(c=0;c=0;j--) { + + for(j=xctx.symbols-1;j>=0;j--) { dbg(2, "remove_symbols(): removing symbol %d\n",j); remove_symbol(j); } @@ -627,59 +627,59 @@ void remove_symbols(void) void clear_drawing(void) { int i,j; - del_inst_table(); /* 20180917 */ - del_wire_table(); /* 20180917 */ - my_free(685, &schtedaxprop); - my_free(686, &schsymbolprop); - my_free(687, &schprop); - my_free(688, &schvhdlprop); - my_free(689, &xschem_version_string); - my_free(690, &schverilogprop); /* 09112003 */ - for(i=0;itype); /* 20150409 */ + my_strdup(7, &type,(xctx.inst[selectedgroup[j].n].ptr+ xctx.sym)->type); if( type && IS_LABEL_OR_PIN(type) ) { continue; } - if(!do_all_inst && !strcmp(tclgetvar("do_all_inst"),"1")) do_all_inst=1; /* 20171206 */ + if(!do_all_inst && !strcmp(tclgetvar("do_all_inst"),"1")) do_all_inst=1; - dbg(1, " 200711 1--> %s %.16g %.16g %s\n", - inst_ptr[selectedgroup[j].n].name, - inst_ptr[selectedgroup[j].n].x0, - inst_ptr[selectedgroup[j].n].y0, - instdef[inst_ptr[selectedgroup[j].n].ptr].name); + dbg(1, " 200711 1--> %s %.16g %.16g %s\n", + xctx.inst[selectedgroup[j].n].name, + xctx.inst[selectedgroup[j].n].x0, + xctx.inst[selectedgroup[j].n].y0, + xctx.sym[xctx.inst[selectedgroup[j].n].ptr].name); - x0 = inst_ptr[selectedgroup[j].n].x0; - y0 = inst_ptr[selectedgroup[j].n].y0; - rot = inst_ptr[selectedgroup[j].n].rot; - flip = inst_ptr[selectedgroup[j].n].flip; - symbol = instdef + inst_ptr[selectedgroup[j].n].ptr; + x0 = xctx.inst[selectedgroup[j].n].x0; + y0 = xctx.inst[selectedgroup[j].n].y0; + rot = xctx.inst[selectedgroup[j].n].rot; + flip = xctx.inst[selectedgroup[j].n].flip; + symbol = xctx.sym + xctx.inst[selectedgroup[j].n].ptr; npin = symbol->rects[PINLAYER]; - rect=symbol->boxptr[PINLAYER]; - - for(i=0;i labname=%s\n", labname); - - pinx0 = (rect[i].x1+rect[i].x2)/2; - piny0 = (rect[i].y1+rect[i].y2)/2; + rct=symbol->rect[PINLAYER]; - if(strcmp(get_tok_value(rect[i].prop_ptr,"dir",0),"in")) dir=1; /* out or inout pin */ + for(i=0;i labname=%s\n", labname); + + pinx0 = (rct[i].x1+rct[i].x2)/2; + piny0 = (rct[i].y1+rct[i].y2)/2; + + if(strcmp(get_tok_value(rct[i].prop_ptr,"dir",0),"in")) dir=1; /* out or inout pin */ else dir=0; /* input pin */ /* opin or iopin on left of symbol--> reverse orientation 20171205 */ if(rotated_text ==-1 && dir==1 && pinx0<0) dir=0; - - ROTATION(0.0, 0.0, pinx0, piny0, pinx0, piny0); /* 20101129 */ - + + ROTATION(0.0, 0.0, pinx0, piny0, pinx0, piny0); + pinx0 += x0; piny0 += y0; @@ -814,7 +814,7 @@ void attach_labels_to_inst() /* offloaded from callback.c 20171005 */ iptr = iptr->next; continue; } - + if( iptr->x0 == pinx0 && iptr->y0 == piny0 ) { skip=1; break; @@ -822,8 +822,8 @@ void attach_labels_to_inst() /* offloaded from callback.c 20171005 */ iptr = iptr->next; } while(wptr) { - if( touch(wire[wptr->n].x1, wire[wptr->n].y1, - wire[wptr->n].x2, wire[wptr->n].y2, pinx0, piny0) ) { + if( touch(xctx.wire[wptr->n].x1, xctx.wire[wptr->n].y1, + xctx.wire[wptr->n].x2, xctx.wire[wptr->n].y2, pinx0, piny0) ) { skip=1; break; } @@ -832,7 +832,7 @@ void attach_labels_to_inst() /* offloaded from callback.c 20171005 */ if(!skip) { my_strdup(9, &prop, "name=p1 lab="); - /* 20171005 */ + if(use_label_prefix) { my_strcat(10, &prop, (char *)tclgetvar("custom_label_prefix")); } @@ -842,18 +842,18 @@ void attach_labels_to_inst() /* offloaded from callback.c 20171005 */ dir ^= flip; /* 20101129 20111030 */ if(rotated_text ==-1) { rot1=rot; - if(rot1==1 || rot1==2) { dir=!dir;rot1 = (rot1+2) %4;} /* 20111103 */ + if(rot1==1 || rot1==2) { dir=!dir;rot1 = (rot1+2) %4;} } else { rot1=(rot+rotated_text)%4; /* 20111103 20171208 text_rotation */ } if(!strcmp(tclgetvar("use_lab_wire"),"0")) { - if(indirect) + if(indirect) place_symbol(-1,symname_pin, pinx0, piny0, rot1, dir, prop, 2, first_call); else place_symbol(-1,symname_pin2, pinx0, piny0, rot1, dir, prop, 2, first_call); first_call=0; } else { - if(indirect) + if(indirect) place_symbol(-1,symname_wire, pinx0, piny0, rot1, dir, prop, 2, first_call); else place_symbol(-1,symname_wire2, pinx0, piny0, rot1, dir, prop, 2, first_call); @@ -881,7 +881,7 @@ void attach_labels_to_inst() /* offloaded from callback.c 20171005 */ /* first_call: set to 1 on first invocation for a given set of symbols (same prefix) */ /* set to 0 on next calls, this speeds up searching for unique names in prop string */ /* returns 1 if symbol successfully placed, 0 otherwise */ -int place_symbol(int pos, const char *symbol_name, double x, double y, int rot, int flip, +int place_symbol(int pos, const char *symbol_name, double x, double y, int rot, int flip, const char *inst_props, int draw_sym, int first_call) /* if symbol_name is a valid string load specified cell and */ /* use the given params, otherwise query user */ @@ -906,34 +906,34 @@ int place_symbol(int pos, const char *symbol_name, double x, double y, int rot, if(i!=-1) { check_inst_storage(); - if(pos==-1 || pos > lastinst) n=lastinst; + if(pos==-1 || pos > xctx.instances) n=xctx.instances; else { - for(j=lastinst;j>pos;j--) + for(j=xctx.instances;j>pos;j--) { - inst_ptr[j]=inst_ptr[j-1]; + xctx.inst[j]=xctx.inst[j-1]; } n=pos; } /* 03-02-2000 */ - dbg(1, "place_symbol(): checked inst_ptr storage, instdef number i=%d\n", i); - inst_ptr[n].ptr = i; - inst_ptr[n].name=NULL; - inst_ptr[n].instname=NULL; /* 20150409 */ + dbg(1, "place_symbol(): checked inst_ptr storage, xctx.sym number i=%d\n", i); + xctx.inst[n].ptr = i; + xctx.inst[n].name=NULL; + xctx.inst[n].instname=NULL; dbg(1, "place_symbol(): entering my_strdup: name=%s\n",name); /* 03-02-2000 */ - my_strdup(12, &inst_ptr[n].name ,name); + my_strdup(12, &xctx.inst[n].name ,name); dbg(1, "place_symbol(): done my_strdup: name=%s\n",name); /* 03-02-2000 */ - /* inst_ptr[n].x0=symbol_name ? x : mousex_snap; */ - /* inst_ptr[n].y0=symbol_name ? y : mousey_snap; */ - inst_ptr[n].x0= x ; /* 20070228 x and y given in callback */ - inst_ptr[n].y0= y ; /* 20070228 */ - inst_ptr[n].rot=symbol_name ? rot : 0; - inst_ptr[n].flip=symbol_name ? flip : 0; + /* xctx.inst[n].x0=symbol_name ? x : mousex_snap; */ + /* xctx.inst[n].y0=symbol_name ? y : mousey_snap; */ + xctx.inst[n].x0= x ; /* 20070228 x and y given in callback */ + xctx.inst[n].y0= y ; + xctx.inst[n].rot=symbol_name ? rot : 0; + xctx.inst[n].flip=symbol_name ? flip : 0; - inst_ptr[n].flags=0; - inst_ptr[n].sel=0; - inst_ptr[n].node=NULL; - inst_ptr[n].prop_ptr=NULL; + xctx.inst[n].flags=0; + xctx.inst[n].sel=0; + xctx.inst[n].node=NULL; + xctx.inst[n].prop_ptr=NULL; dbg(1, "place_symbol() :all inst_ptr members set\n"); /* 03-02-2000 */ if(first_call) hash_all_names(n); if(inst_props) { @@ -944,24 +944,24 @@ int place_symbol(int pos, const char *symbol_name, double x, double y, int rot, } dbg(1, "place_symbol(): done set_inst_prop()\n"); /* 03-02-2000 */ - my_strdup2(13, &inst_ptr[n].instname, get_tok_value(inst_ptr[n].prop_ptr,"name",0) ); /* 20150409 */ + my_strdup2(13, &xctx.inst[n].instname, get_tok_value(xctx.inst[n].prop_ptr,"name",0) ); - type = instdef[inst_ptr[n].ptr].type; /* 20150409 */ + type = xctx.sym[xctx.inst[n].ptr].type; cond= !type || !IS_LABEL_SH_OR_PIN(type); - if(cond) inst_ptr[n].flags|=2; - else inst_ptr[n].flags &=~2; + if(cond) xctx.inst[n].flags|=2; + else xctx.inst[n].flags &=~2; if(first_call && (draw_sym & 3) ) bbox(BEGIN, 0.0 , 0.0 , 0.0 , 0.0); - lastinst++; /* must be updated before calling symbol_bbox() */ - prepared_hash_instances=0; /* 20171224 */ + xctx.instances++; /* must be updated before calling symbol_bbox() */ + prepared_hash_instances=0; /* force these vars to 0 to trigger a prepare_netlist_structs(0) needed by symbol_bbox->translate * to translate @#n:net_name texts */ prepared_netlist_structs=0; prepared_hilight_structs=0; - symbol_bbox(n, &inst_ptr[n].x1, &inst_ptr[n].y1, - &inst_ptr[n].x2, &inst_ptr[n].y2); - if(draw_sym & 3) bbox(ADD, inst_ptr[n].x1, inst_ptr[n].y1, inst_ptr[n].x2, inst_ptr[n].y2); + symbol_bbox(n, &xctx.inst[n].x1, &xctx.inst[n].y1, + &xctx.inst[n].x2, &xctx.inst[n].y2); + if(draw_sym & 3) bbox(ADD, xctx.inst[n].x1, xctx.inst[n].y1, xctx.inst[n].x2, xctx.inst[n].y2); set_modify(1); if(draw_sym&1) { bbox(SET , 0.0 , 0.0 , 0.0 , 0.0); @@ -976,7 +976,7 @@ int place_symbol(int pos, const char *symbol_name, double x, double y, int rot, drawtemparc(gc[SELLAYER], END, 0.0, 0.0, 0.0, 0.0, 0.0); drawtemprect(gc[SELLAYER], END, 0.0, 0.0, 0.0, 0.0); drawtempline(gc[SELLAYER], END, 0.0, 0.0, 0.0, 0.0); - need_rebuild_selected_array = 1; /* 20191127 */ + need_rebuild_selected_array = 1; rebuild_selected_array(); } @@ -989,11 +989,11 @@ void symbol_in_new_window(void) rebuild_selected_array(); if(lastselected !=1 || selectedgroup[0].type!=ELEMENT) { - new_window(schematic[currentsch],1); + new_window(xctx.sch[xctx.currsch],1); } else { - new_window(abs_sym_path(inst_ptr[selectedgroup[0].n].name, ""),1); + new_window(abs_sym_path(xctx.inst[selectedgroup[0].n].name, ""),1); } } @@ -1003,52 +1003,52 @@ void schematic_in_new_window(void) { char filename[PATH_MAX]; rebuild_selected_array(); - if(lastselected !=1 || selectedgroup[0].type!=ELEMENT) + if(lastselected !=1 || selectedgroup[0].type!=ELEMENT) { /* new_window("", 0); */ - new_window(schematic[currentsch], 0); /* 20111007 duplicate current schematic if no inst selected */ + new_window(xctx.sch[xctx.currsch], 0); /* 20111007 duplicate current schematic if no inst selected */ return; } else { if( /* do not descend if not subcircuit */ - (inst_ptr[selectedgroup[0].n].ptr+instdef)->type && + (xctx.inst[selectedgroup[0].n].ptr+ xctx.sym)->type && strcmp( - (inst_ptr[selectedgroup[0].n].ptr+instdef)->type, /* 20150409 */ + (xctx.inst[selectedgroup[0].n].ptr+ xctx.sym)->type, "subcircuit" - ) && + ) && strcmp( - (inst_ptr[selectedgroup[0].n].ptr+instdef)->type, /* 20150409 */ + (xctx.inst[selectedgroup[0].n].ptr+ xctx.sym)->type, "primitive" - ) + ) ) return; my_strncpy(filename, abs_sym_path(get_tok_value( - (inst_ptr[selectedgroup[0].n].ptr+instdef)->prop_ptr, "schematic",0 ), "") + (xctx.inst[selectedgroup[0].n].ptr+ xctx.sym)->prop_ptr, "schematic",0 ), "") , S(filename)); if(!filename[0]) { - my_strncpy(filename, add_ext(abs_sym_path(inst_ptr[selectedgroup[0].n].name, ""), ".sch"), S(filename)); + my_strncpy(filename, add_ext(abs_sym_path(xctx.inst[selectedgroup[0].n].name, ""), ".sch"), S(filename)); } new_window(filename, 0); } } -void launcher(void) /* 20161102 */ +void launcher(void) { const char *str; char program[PATH_MAX]; int n; rebuild_selected_array(); - if(lastselected ==1 && selectedgroup[0].type==ELEMENT) + if(lastselected ==1 && selectedgroup[0].type==ELEMENT) { double mx=mousex, my=mousey; select_object(mx,my,SELECTED, 0); tcleval("update; after 300"); select_object(mx,my,0, 0); n=selectedgroup[0].n; - my_strncpy(program, get_tok_value(inst_ptr[n].prop_ptr,"program",2), S(program)); /* 20170414 handle backslashes */ - str = get_tok_value(inst_ptr[n].prop_ptr,"url",2); /* 20170414 handle backslashes */ + my_strncpy(program, get_tok_value(xctx.inst[n].prop_ptr,"program",2), S(program)); /* handle backslashes */ + str = get_tok_value(xctx.inst[n].prop_ptr,"url",2); /* handle backslashes */ dbg(1, "launcher(): str=%s\n", str); if(str[0] || (program[0])) { tclsetvar("launcher_var",str); @@ -1059,12 +1059,12 @@ void launcher(void) /* 20161102 */ } tcleval( "launcher"); } else { - my_strncpy(program, get_tok_value(inst_ptr[n].prop_ptr,"tclcommand",2), S(program)); /* 20170415 */ + my_strncpy(program, get_tok_value(xctx.inst[n].prop_ptr,"tclcommand",2), S(program)); if(program[0]) { /* 20170415 execute tcl command */ tcleval(program); } } - } + } } void descend_schematic(int instnumber) @@ -1075,75 +1075,75 @@ void descend_schematic(int instnumber) int save_ok = 0; rebuild_selected_array(); - if(lastselected !=1 || selectedgroup[0].type!=ELEMENT) + if(lastselected !=1 || selectedgroup[0].type!=ELEMENT) { dbg(1, "descend_schematic(): wrong selection\n"); return; } else { - dbg(1, "descend_schematic(): selected:%s\n", inst_ptr[selectedgroup[0].n].name); + dbg(1, "descend_schematic(): selected:%s\n", xctx.inst[selectedgroup[0].n].name); /* no name set for current schematic: save it before descending*/ - if(!strcmp(schematic[currentsch],"")) + if(!strcmp(xctx.sch[xctx.currsch],"")) { char cmd[PATH_MAX+1000]; char filename[PATH_MAX]; char res[PATH_MAX]; - my_strncpy(filename, schematic[currentsch], S(filename)); + my_strncpy(filename, xctx.sch[xctx.currsch], S(filename)); my_snprintf(cmd, S(cmd), "save_file_dialog {Save file} .sch.sym INITIALLOADDIR {%s}", filename); tcleval(cmd); my_strncpy(res, tclresult(), S(res)); - if(!res[0]) return; /* 20071104 */ + if(!res[0]) return; dbg(1, "descend_schematic(): saving: %s\n",res); save_ok = save_schematic(res); - if(save_ok==-1) return; /* 20171020 */ + if(save_ok==-1) return; } - dbg(1, "type of instance: %s\n", (inst_ptr[selectedgroup[0].n].ptr+instdef)->type); + dbg(1, "type of instance: %s\n", (xctx.inst[selectedgroup[0].n].ptr+ xctx.sym)->type); if( /* do not descend if not subcircuit */ - (inst_ptr[selectedgroup[0].n].ptr+instdef)->type && + (xctx.inst[selectedgroup[0].n].ptr+ xctx.sym)->type && strcmp( - (inst_ptr[selectedgroup[0].n].ptr+instdef)->type, /* 20150409 */ + (xctx.inst[selectedgroup[0].n].ptr+ xctx.sym)->type, "subcircuit" - ) && + ) && strcmp( - (inst_ptr[selectedgroup[0].n].ptr+instdef)->type, /* 20150409 */ + (xctx.inst[selectedgroup[0].n].ptr+ xctx.sym)->type, "primitive" - ) + ) ) return; if(modified) { - if(save(1)) return; /* 20161209 */ + if(save(1)) return; } /* build up current hierarchy path */ - dbg(1, "descend_schematic(): selected instname=%s\n", inst_ptr[selectedgroup[0].n].instname); + dbg(1, "descend_schematic(): selected instname=%s\n", xctx.inst[selectedgroup[0].n].instname); - if(inst_ptr[selectedgroup[0].n].instname && inst_ptr[selectedgroup[0].n].instname[0]) { - str=expandlabel(inst_ptr[selectedgroup[0].n].instname, &inst_mult); /* 20150409 */ + if(xctx.inst[selectedgroup[0].n].instname && xctx.inst[selectedgroup[0].n].instname[0]) { + str=expandlabel(xctx.inst[selectedgroup[0].n].instname, &inst_mult); } else { str = ""; inst_mult = 1; } - my_strdup(14, &sch_path[currentsch+1], sch_path[currentsch]); + my_strdup(14, &xctx.sch_path[xctx.currsch+1], xctx.sch_path[xctx.currsch]); inst_number = 1; - if(inst_mult > 1) { /* on multiple instances ask where to descend, to correctly evaluate + if(inst_mult > 1) { /* on multiple instances ask where to descend, to correctly evaluate the hierarchy path you descend to */ if(instnumber <= 0 ) { const char *inum; - Tcl_VarEval(interp, "input_line ", "{input instance number (leftmost = 1) to descend into:\n" + Tcl_VarEval(interp, "input_line ", "{input instance number (leftmost = 1) to descend into:\n" "negative numbers select instance starting\nfrom the right (rightmost = -1)}" " {} 1 6", NULL); inum = tclresult(); dbg(1, "descend_schematic(): inum=%s\n", inum); if(!inum[0]) { - my_free(710, &sch_path[currentsch+1]); + my_free(710, &xctx.sch_path[xctx.currsch+1]); return; } inst_number=atoi(inum); @@ -1154,22 +1154,22 @@ void descend_schematic(int instnumber) if(inst_number <1 || inst_number > inst_mult) inst_number = 1; /* any invalid number->descend to leftmost inst */ } dbg(1," inst_number=%d\n", inst_number); - my_strcat(15, &sch_path[currentsch+1], find_nth(str, ',', inst_number)); + my_strcat(15, &xctx.sch_path[xctx.currsch+1], find_nth(str, ',', inst_number)); dbg(1," inst_number=%d\n", inst_number); - my_strcat(16, &sch_path[currentsch+1], "."); - sch_inst_number[currentsch+1] = inst_number; - dbg(1, "descend_schematic(): current path: %s\n", sch_path[currentsch+1]); + my_strcat(16, &xctx.sch_path[xctx.currsch+1], "."); + xctx.sch_inst_number[xctx.currsch+1] = inst_number; + dbg(1, "descend_schematic(): current path: %s\n", xctx.sch_path[xctx.currsch+1]); dbg(1, "descend_schematic(): inst_number=%d\n", inst_number); - previous_instance[currentsch]=selectedgroup[0].n; - zoom_array[currentsch].x=xorigin; - zoom_array[currentsch].y=yorigin; - zoom_array[currentsch].zoom=zoom; - currentsch++; + xctx.previous_instance[xctx.currsch]=selectedgroup[0].n; + xctx.zoom_array[xctx.currsch].x=xctx.xorigin; + xctx.zoom_array[xctx.currsch].y=xctx.yorigin; + xctx.zoom_array[xctx.currsch].zoom=xctx.zoom; + xctx.currsch++; hilight_child_pins(); my_strncpy(filename, abs_sym_path(get_tok_value( - (inst_ptr[selectedgroup[0].n].ptr+instdef)->prop_ptr, "schematic",0 ), "") + (xctx.inst[selectedgroup[0].n].ptr+ xctx.sym)->prop_ptr, "schematic",0 ), "") , S(filename)); unselect_all(); @@ -1177,84 +1177,84 @@ void descend_schematic(int instnumber) if(filename[0]) { load_schematic(1,filename, 1); } else { - my_strncpy(filename, add_ext(abs_sym_path(inst_ptr[selectedgroup[0].n].name, ""), ".sch"), S(filename)); + my_strncpy(filename, add_ext(abs_sym_path(xctx.inst[selectedgroup[0].n].name, ""), ".sch"), S(filename)); load_schematic(1, filename, 1); } - if(hilight_nets) + if(hilight_nets) { prepare_netlist_structs(0); - if(enable_drill) drill_hilight(); /* 20171212 */ + if(enable_drill) drill_hilight(); } - dbg(1, "descend_schematic(): before zoom(): prepared_hash_instances=%d\n", prepared_hash_instances); + dbg(1, "descend_schematic(): before xctx.zoom(): prepared_hash_instances=%d\n", prepared_hash_instances); zoom_full(1, 0); } } void go_back(int confirm) /* 20171006 add confirm */ { - int save_ok; /* 20171020 */ + int save_ok; int from_embedded_sym; int save_modified; char filename[PATH_MAX]; save_ok=0; - if(currentsch>0) + if(xctx.currsch>0) { /* if current sym/schematic is changed ask save before going up */ if(modified) { if(confirm) { tcleval("ask_save"); - if(!strcmp(tclresult(), "yes") ) save_ok = save_schematic(schematic[currentsch]); + if(!strcmp(tclresult(), "yes") ) save_ok = save_schematic(xctx.sch[xctx.currsch]); else if(!strcmp(tclresult(), "") ) return; } else { - save_ok = save_schematic(schematic[currentsch]); + save_ok = save_schematic(xctx.sch[xctx.currsch]); } } - if(save_ok==-1) return; /* 20171020 */ + if(save_ok==-1) return; unselect_all(); remove_symbols(); from_embedded_sym=0; - if(strstr(schematic[currentsch], ".xschem_embedded_")) { + if(strstr(xctx.sch[xctx.currsch], ".xschem_embedded_")) { /* when returning after editing an embedded symbol - * load immediately symbol definition before going back (.xschem_embedded... file will be lost) + * load immediately symbol definition before going back (.xschem_embedded... file will be lost) */ - load_sym_def(schematic[currentsch], NULL); + load_sym_def(xctx.sch[xctx.currsch], NULL); from_embedded_sym=1; } - my_strncpy(schematic[currentsch] , "", S(schematic[currentsch])); - currentsch--; + my_strncpy(xctx.sch[xctx.currsch] , "", S(xctx.sch[xctx.currsch])); + xctx.currsch--; save_modified = modified; /* we propagate modified flag (cleared by load_schematic */ /* by default) to parent schematic if going back from embedded symbol */ - my_strncpy(filename, abs_sym_path(schematic[currentsch], ""), S(filename)); + my_strncpy(filename, abs_sym_path(xctx.sch[xctx.currsch], ""), S(filename)); load_schematic(1, filename, 1); if(from_embedded_sym) modified=save_modified; /* to force ask save embedded sym in parent schematic */ hilight_parent_pins(); - if(enable_drill) drill_hilight(); /* 20171212 */ - xorigin=zoom_array[currentsch].x; - yorigin=zoom_array[currentsch].y; - zoom=zoom_array[currentsch].zoom; - mooz=1/zoom; + if(enable_drill) drill_hilight(); + xctx.xorigin=xctx.zoom_array[xctx.currsch].x; + xctx.yorigin=xctx.zoom_array[xctx.currsch].y; + xctx.zoom=xctx.zoom_array[xctx.currsch].zoom; + xctx.mooz=1/xctx.zoom; change_linewidth(-1.); draw(); - dbg(1, "go_back(): current path: %s\n", sch_path[currentsch]); + dbg(1, "go_back(): current path: %s\n", xctx.sch_path[xctx.currsch]); } } void change_linewidth(double w) { int i, changed; - + changed=0; /* choose line width automatically based on zoom */ if(w<0.) { if(change_lw) { - lw_double=mooz * 0.09 * cadsnap; - bus_width = BUS_WIDTH * mooz * 0.09 * cadsnap; + lw_double=xctx.mooz * 0.09 * cadsnap; + bus_width = BUS_WIDTH * xctx.mooz * 0.09 * cadsnap; cadhalfdotsize = CADHALFDOTSIZE + 0.04 * (cadsnap-10); changed=1; } @@ -1282,11 +1282,11 @@ void change_linewidth(double w) areah = areay2 - areay1; } -void calc_drawing_bbox(Box *boundbox, int selected) +void calc_drawing_bbox(xRect *boundbox, int selected) { - Box tmp; - int c, i; + xRect tmp; + int c, i; int count=0; #ifdef HAS_CAIRO int customfont; @@ -1298,93 +1298,94 @@ void calc_drawing_bbox(Box *boundbox, int selected) boundbox->y2=100; for(c=0;c x2) x2 = polygon[c][i].x[k]; - if(k==0 || polygon[c][i].y[k] > y2) y2 = polygon[c][i].y[k]; + if(k==0 || xctx.poly[c][i].x[k] < x1) x1 = xctx.poly[c][i].x[k]; + if(k==0 || xctx.poly[c][i].y[k] < y1) y1 = xctx.poly[c][i].y[k]; + if(k==0 || xctx.poly[c][i].x[k] > x2) x2 = xctx.poly[c][i].x[k]; + if(k==0 || xctx.poly[c][i].y[k] > y2) y2 = xctx.poly[c][i].y[k]; } tmp.x1=x1;tmp.y1=y1;tmp.x2=x2;tmp.y2=y2; updatebbox(count,boundbox,&tmp); } - for(i=0;i cadhalfdotsize ? bus_width : CADHALFDOTSIZE; - if(wire[i].y1 < wire[i].y2) { y1 = wire[i].y1-ov; y2 = wire[i].y2+ov; } - else { y1 = wire[i].y1+ov; y2 = wire[i].y2-ov; } + if(xctx.wire[i].y1 < xctx.wire[i].y2) { y1 = xctx.wire[i].y1-ov; y2 = xctx.wire[i].y2+ov; } + else { y1 = xctx.wire[i].y1+ov; y2 = xctx.wire[i].y2-ov; } } else { ov = cadhalfdotsize; - if(wire[i].y1 < wire[i].y2) { y1 = wire[i].y1-ov; y2 = wire[i].y2+ov; } - else { y1 = wire[i].y1+ov; y2 = wire[i].y2-ov; } + if(xctx.wire[i].y1 < xctx.wire[i].y2) { y1 = xctx.wire[i].y1-ov; y2 = xctx.wire[i].y2+ov; } + else { y1 = xctx.wire[i].y1+ov; y2 = xctx.wire[i].y2-ov; } } - tmp.x1 = wire[i].x1-ov; - tmp.x2 = wire[i].x2+ov; + tmp.x1 = xctx.wire[i].x1-ov; + tmp.x2 = xctx.wire[i].x2+ov; tmp.y1 = y1; tmp.y2 = y2; count++; updatebbox(count,boundbox,&tmp); } - if(has_x) for(i=0;itype; /* 20150409 */ + type = (xctx.inst[i].ptr+ xctx.sym)->type; found = 0; - hilight_connected_inst = !strcmp(get_tok_value((inst_ptr[i].ptr+instdef)->prop_ptr, "highlight", 0), "true") || - !strcmp(get_tok_value(inst_ptr[i].prop_ptr, "highlight", 0), "true"); - if( hilight_connected_inst && (rects = (inst_ptr[i].ptr+instdef)->rects[PINLAYER]) > 0 ) { + hilight_connected_inst = !strcmp(get_tok_value((xctx.inst[i].ptr+ xctx.sym)->prop_ptr, "highlight", 0), "true") || + !strcmp(get_tok_value(xctx.inst[i].prop_ptr, "highlight", 0), "true"); + if( hilight_connected_inst && (rects = (xctx.inst[i].ptr+ xctx.sym)->rects[PINLAYER]) > 0 ) { prepare_netlist_structs(0); for(j=0;jzoom) zoom=yy1; - zoom*=1.05; - mooz=1/zoom; - xorigin=-boundbox.x1+(areaw-4*lw)/40*zoom; - yorigin=(areah-4*lw)*zoom-boundbox.y2 - (areah-4*lw)/40*zoom; + if(yy1>xctx.zoom) xctx.zoom=yy1; + xctx.zoom*=1.05; + xctx.mooz=1/xctx.zoom; + xctx.xorigin=-boundbox.x1+(areaw-4*lw)/40*xctx.zoom; + xctx.yorigin=(areah-4*lw)*xctx.zoom-boundbox.y2 - (areah-4*lw)/40*xctx.zoom; dbg(1, "zoom_full(): areaw=%d, areah=%d\n", areaw, areah); change_linewidth(-1.); if(dr) - { + { if(!has_x) return; draw(); } @@ -1483,11 +1484,11 @@ void view_zoom(double z) double factor; /* int i; */ factor = z!=0.0 ? z : CADZOOMSTEP; - if(zoomCADMAXZOOM) return; - zoom*= factor; - mooz=1/zoom; + if(xctx.zoom>CADMAXZOOM) return; + xctx.zoom*= factor; + xctx.mooz=1/xctx.zoom; /* 20181022 make unzoom and zoom symmetric */ /* keeping the mouse pointer as the origin */ if(unzoom_nodrift) { - xorigin=-mousex_snap+(mousex_snap+xorigin)*factor; - yorigin=-mousey_snap+(mousey_snap+yorigin)*factor; + xctx.xorigin=-mousex_snap+(mousex_snap+xctx.xorigin)*factor; + xctx.yorigin=-mousey_snap+(mousey_snap+xctx.yorigin)*factor; } else { - xorigin=xorigin+areaw*zoom*(1-1/factor)/2; - yorigin=yorigin+areah*zoom*(1-1/factor)/2; + xctx.xorigin=xctx.xorigin+areaw*xctx.zoom*(1-1/factor)/2; + xctx.yorigin=xctx.yorigin+areah*xctx.zoom*(1-1/factor)/2; } change_linewidth(-1.); draw(); @@ -1528,14 +1529,14 @@ void zoom_box(int what) ui_state &= ~STARTZOOM; RECTORDER(x1,y1,x2,y2); drawtemprect(gctiled, NOW, xx1,yy1,xx2,yy2); - xorigin=-x1;yorigin=-y1; - zoom=(x2-x1)/(areaw-4*lw); + xctx.xorigin=-x1;xctx.yorigin=-y1; + xctx.zoom=(x2-x1)/(areaw-4*lw); yy1=(y2-y1)/(areah-4*lw); - if(yy1>zoom) zoom=yy1; - mooz=1/zoom; + if(yy1>xctx.zoom) xctx.zoom=yy1; + xctx.mooz=1/xctx.zoom; change_linewidth(-1.); draw(); - dbg(1, "zoom_box(): coord: %.16g %.16g %.16g %.16g zoom=%.16g\n",x1,y1,mousex_snap, mousey_snap,zoom); + dbg(1, "zoom_box(): coord: %.16g %.16g %.16g %.16g xctx.zoom=%.16g\n",x1,y1,mousex_snap, mousey_snap,xctx.zoom); } if(what & RUBBER) { @@ -1567,10 +1568,10 @@ void draw_stuff(void) view_unzoom(40); for(i=0;i<=210000;i++) { - w=(float)(areaw*zoom/800) * rand() / (RAND_MAX+1.0); - h=(float)(areah*zoom/80) * rand() / (RAND_MAX+1.0); - x1=(float)(areaw*zoom) * rand() / (RAND_MAX+1.0)-xorigin; - y1=(float)(areah*zoom) * rand() / (RAND_MAX+1.0)-yorigin; + w=(float)(areaw*xctx.zoom/800) * rand() / (RAND_MAX+1.0); + h=(float)(areah*xctx.zoom/80) * rand() / (RAND_MAX+1.0); + x1=(float)(areaw*xctx.zoom) * rand() / (RAND_MAX+1.0)-xctx.xorigin; + y1=(float)(areah*xctx.zoom) * rand() / (RAND_MAX+1.0)-xctx.yorigin; x2=x1+w; y2=y1+h; ORDER(x1,y1,x2,y2); @@ -1580,10 +1581,10 @@ void draw_stuff(void) for(i=0;i<=210000;i++) { - w=(float)(areaw*zoom/80) * rand() / (RAND_MAX+1.0); - h=(float)(areah*zoom/800) * rand() / (RAND_MAX+1.0); - x1=(float)(areaw*zoom) * rand() / (RAND_MAX+1.0)-xorigin; - y1=(float)(areah*zoom) * rand() / (RAND_MAX+1.0)-yorigin; + w=(float)(areaw*xctx.zoom/80) * rand() / (RAND_MAX+1.0); + h=(float)(areah*xctx.zoom/800) * rand() / (RAND_MAX+1.0); + x1=(float)(areaw*xctx.zoom) * rand() / (RAND_MAX+1.0)-xctx.xorigin; + y1=(float)(areah*xctx.zoom) * rand() / (RAND_MAX+1.0)-xctx.yorigin; x2=x1+w; y2=y1+h; ORDER(x1,y1,x2,y2); @@ -1593,10 +1594,10 @@ void draw_stuff(void) for(i=0;i<=210000;i++) { - w=(float)zoom * rand() / (RAND_MAX+1.0); + w=(float)xctx.zoom * rand() / (RAND_MAX+1.0); h=w; - x1=(float)(areaw*zoom) * rand() / (RAND_MAX+1.0)-xorigin; - y1=(float)(areah*zoom) * rand() / (RAND_MAX+1.0)-yorigin; + x1=(float)(areaw*xctx.zoom) * rand() / (RAND_MAX+1.0)-xctx.xorigin; + y1=(float)(areah*xctx.zoom) * rand() / (RAND_MAX+1.0)-xctx.yorigin; x2=x1+w; y2=y1+h; rectcolor = (int) (10.0*rand()/(RAND_MAX+1.0))+4; @@ -1663,14 +1664,14 @@ void new_wire(int what, double mx_snap, double my_snap) printf("xschem wire %g %g %g %g %d\n", xx1, yy1, xx2, yy2, -1); fflush(stdout); } - hash_wire(XINSERT, lastwire-1); + hash_wire(XINSERT, xctx.wires-1); /* prepared_hash_wires = 0; */ prepared_hilight_structs = 0; update_conn_cues(1,1); if(show_pin_net_names) { prepare_netlist_structs(0); bbox(BEGIN , 0.0 , 0.0 , 0.0 , 0.0); - find_inst_to_be_redrawn(wire[lastwire-1].node); + find_inst_to_be_redrawn(xctx.wire[xctx.wires-1].node); find_inst_hash_clear(); bbox(SET , 0.0 , 0.0 , 0.0 , 0.0); draw(); @@ -1771,36 +1772,37 @@ void change_layer() double x1,y1,x2,y2, a, b, r; - if(lastselected) push_undo(); /* 20151204 */ + if(lastselected) push_undo(); for(k=0;k800.) { */ + /* if(size*xctx.mooz>800.) { */ /* return 0; */ /* } */ - cairo_set_font_size (cairo_ctx, size*mooz); + cairo_set_font_size (cairo_ctx, size*xctx.mooz); cairo_font_extents(cairo_ctx, &fext); ww=0.; hh=1.; @@ -2121,31 +2123,31 @@ int text_bbox(const char *str, double xscale, double yscale, hh = hh*fext.height*cairo_font_line_spacing; cairo_longest_line = ww; - *rx1=x1;*ry1=y1; + *rx1=x1;*ry1=y1; if(hcenter) { - if (rot==0 && flip == 0) { *rx1-= ww*zoom/2;} - else if(rot==1 && flip == 0) { *ry1-= ww*zoom/2;} - else if(rot==2 && flip == 0) { *rx1+= ww*zoom/2;} - else if(rot==3 && flip == 0) { *ry1+= ww*zoom/2;} - else if(rot==0 && flip == 1) { *rx1+= ww*zoom/2;} - else if(rot==1 && flip == 1) { *ry1+= ww*zoom/2;} - else if(rot==2 && flip == 1) { *rx1-= ww*zoom/2;} - else if(rot==3 && flip == 1) { *ry1-= ww*zoom/2;} + if (rot==0 && flip == 0) { *rx1-= ww*xctx.zoom/2;} + else if(rot==1 && flip == 0) { *ry1-= ww*xctx.zoom/2;} + else if(rot==2 && flip == 0) { *rx1+= ww*xctx.zoom/2;} + else if(rot==3 && flip == 0) { *ry1+= ww*xctx.zoom/2;} + else if(rot==0 && flip == 1) { *rx1+= ww*xctx.zoom/2;} + else if(rot==1 && flip == 1) { *ry1+= ww*xctx.zoom/2;} + else if(rot==2 && flip == 1) { *rx1-= ww*xctx.zoom/2;} + else if(rot==3 && flip == 1) { *ry1-= ww*xctx.zoom/2;} } if(vcenter) { - if (rot==0 && flip == 0) { *ry1-= hh*zoom/2;} - else if(rot==1 && flip == 0) { *rx1+= hh*zoom/2;} - else if(rot==2 && flip == 0) { *ry1+= hh*zoom/2;} - else if(rot==3 && flip == 0) { *rx1-= hh*zoom/2;} - else if(rot==0 && flip == 1) { *ry1-= hh*zoom/2;} - else if(rot==1 && flip == 1) { *rx1+= hh*zoom/2;} - else if(rot==2 && flip == 1) { *ry1+= hh*zoom/2;} - else if(rot==3 && flip == 1) { *rx1-= hh*zoom/2;} + if (rot==0 && flip == 0) { *ry1-= hh*xctx.zoom/2;} + else if(rot==1 && flip == 0) { *rx1+= hh*xctx.zoom/2;} + else if(rot==2 && flip == 0) { *ry1+= hh*xctx.zoom/2;} + else if(rot==3 && flip == 0) { *rx1-= hh*xctx.zoom/2;} + else if(rot==0 && flip == 1) { *ry1-= hh*xctx.zoom/2;} + else if(rot==1 && flip == 1) { *rx1+= hh*xctx.zoom/2;} + else if(rot==2 && flip == 1) { *ry1+= hh*xctx.zoom/2;} + else if(rot==3 && flip == 1) { *rx1-= hh*xctx.zoom/2;} } - ROTATION(0.0,0.0, ww*zoom,hh*zoom,(*rx2),(*ry2)); + ROTATION(0.0,0.0, ww*xctx.zoom,hh*xctx.zoom,(*rx2),(*ry2)); *rx2+=*rx1;*ry2+=*ry1; if (rot==0) {*ry1-=cairo_vert_correct; *ry2-=cairo_vert_correct;} else if(rot==1) {*rx1+=cairo_vert_correct; *rx2+=cairo_vert_correct;} @@ -2173,7 +2175,7 @@ int text_bbox(const char * str,double xscale, double yscale, else length++; if(length > w) w = length; - } + } w *= (FONTWIDTH+FONTWHITESPACE)*xscale*nocairo_font_xscale; h *= (FONTHEIGHT+FONTDESCENT+FONTWHITESPACE)*yscale*nocairo_font_yscale; *rx1=x1;*ry1=y1; @@ -2206,7 +2208,7 @@ int text_bbox(const char * str,double xscale, double yscale, ROTATION(0.0,0.0,w,h,(*rx2),(*ry2)); *rx2+=*rx1;*ry2+=*ry1; - RECTORDER((*rx1),(*ry1),(*rx2),(*ry2)); + RECTORDER((*rx1),(*ry1),(*rx2),(*ry2)); return 1; } @@ -2216,7 +2218,7 @@ void place_text(int draw_text, double mx, double my) int textlayer; const char *str; int save_draw; - Text *t = &textelement[lasttext]; + xText *t = &xctx.text[xctx.texts]; #ifdef HAS_CAIRO char *textfont; #endif @@ -2231,14 +2233,14 @@ void place_text(int draw_text, double mx, double my) tcleval("enter_text {text:} normal"); dbg(1, "place_text(): hsize=%s vsize=%s\n",tclgetvar("hsize"), tclgetvar("vsize") ); - + txt = (char *)tclgetvar("retval"); if(!strcmp(txt,"")) return; /* dont allocate text object if empty string given */ - push_undo(); /* 20150327 */ + push_undo(); check_text_storage(); t->txt_ptr=NULL; t->prop_ptr=NULL; /* 20111006 added missing initialization of pointer */ - t->font=NULL; /* 20171206 */ + t->font=NULL; my_strdup(19, &t->txt_ptr, txt); t->x0=mx; t->y0=my; @@ -2268,7 +2270,7 @@ void place_text(int draw_text, double mx, double my) str = get_tok_value(t->prop_ptr, "weight", 0); t->flags |= strcmp(str, "bold") ? 0 : TEXT_BOLD; - my_strdup(21, &t->font, get_tok_value(t->prop_ptr, "font", 0));/* 20171206 */ + my_strdup(21, &t->font, get_tok_value(t->prop_ptr, "font", 0)); textlayer = t->layer; if(textlayer < 0 || textlayer >= cadlayers) textlayer = TEXTLAYER; #ifdef HAS_CAIRO @@ -2287,7 +2289,7 @@ void place_text(int draw_text, double mx, double my) cairo_select_font_face (cairo_save_ctx, textfont, slant, weight); } #endif - save_draw=draw_window; /* 20181009 */ + save_draw=draw_window; draw_window=1; if(draw_text) { draw_string(textlayer, NOW, t->txt_ptr, 0, 0, t->hcenter, t->vcenter, t->x0,t->y0, t->xscale, t->yscale); @@ -2299,24 +2301,24 @@ void place_text(int draw_text, double mx, double my) cairo_restore(cairo_save_ctx); } #endif - select_text(lasttext, SELECTED, 0); + select_text(xctx.texts, SELECTED, 0); drawtemprect(gc[SELLAYER], END, 0.0, 0.0, 0.0, 0.0); drawtempline(gc[SELLAYER], END, 0.0, 0.0, 0.0, 0.0); - lasttext++; + xctx.texts++; set_modify(1); } -void pan2(int what, int mx, int my) /* 20121123 */ +void pan2(int what, int mx, int my) { int dx, dy, ddx, ddy; static int mx_save, my_save; static int mmx_save, mmy_save; static double xorig_save, yorig_save; if(what & BEGIN) { - mmx_save = mx_save = mx; - mmy_save = my_save = my; - xorig_save = xorigin; - yorig_save = yorigin; + mmx_save = mx_save = mx; + mmy_save = my_save = my; + xorig_save = xctx.xorigin; + yorig_save = xctx.yorigin; } else if(what == RUBBER) { dx = mx - mx_save; @@ -2324,8 +2326,8 @@ void pan2(int what, int mx, int my) /* 20121123 */ ddx = abs(mx -mmx_save); ddy = abs(my -mmy_save); if(ddx>5 || ddy>5) { - xorigin = xorig_save + dx*zoom; - yorigin = yorig_save + dy*zoom; + xctx.xorigin = xorig_save + dx*xctx.zoom; + xctx.yorigin = yorig_save + dy*xctx.zoom; draw(); mmx_save = mx; mmy_save = my; @@ -2341,11 +2343,11 @@ 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(gctiled, NOW, xx1,yy1,xx2,yy2); xpan2=mousex_snap;ypan2=mousey_snap; xx1=xpan;yy1=ypan;xx2=xpan2;yy2=ypan2; ORDER(xx1,yy1,xx2,yy2); - drawtempline(gc[SELLAYER], NOW, xx1,yy1,xx2,yy2); + drawtempline(gc[SELLAYER], NOW, xx1,yy1,xx2,yy2); } if(what & BEGIN) { @@ -2355,7 +2357,7 @@ void pan(int what) if(what & END) { ui_state &= ~STARTPAN; - xorigin+=-xpan+mousex_snap;yorigin+=-ypan+mousey_snap; + xctx.xorigin+=-xpan+mousex_snap;xctx.yorigin+=-ypan+mousey_snap; draw(); } } @@ -2366,13 +2368,13 @@ void select_rect(int what, int select) static double xr,yr,xr2,yr2; static double xx1,xx2,yy1,yy2; static int sel; - static int sem=0; /* 20171130 */ + static int sem=0; if(what & RUBBER) { if(sem==0) { fprintf(errfp, "ERROR: select_rect() RUBBER called before BEGIN\n"); - tcleval("alert_ {ERROR: select_rect() RUBBER called before BEGIN} {}"); /* 20171020 */ + tcleval("alert_ {ERROR: select_rect() RUBBER called before BEGIN} {}"); } xx1=xr;xx2=xr2;yy1=yr;yy2=yr2; RECTORDER(xx1,yy1,xx2,yy2); @@ -2399,7 +2401,7 @@ void select_rect(int what, int select) * tcleval("alert_ {ERROR: reentrant call of select_rect()} {}"); * } */ - sel = select; /* 20150927 */ + sel = select; ui_state |= STARTSELECT; /* use m[xy]_double_save instead of mouse[xy]_snap */ @@ -2419,7 +2421,7 @@ void select_rect(int what, int select) /* draw_selection(gc[SELLAYER], 0); */ select_inside(xr,yr,xr2,yr2, sel); - /* 20171219 */ + bbox(BEGIN,0.0, 0.0, 0.0, 0.0); bbox(ADD, xr, yr, xr2, yr2); bbox(SET,0.0, 0.0, 0.0, 0.0); diff --git a/src/callback.c b/src/callback.c index 1c866bd6..3cec0cd6 100644 --- a/src/callback.c +++ b/src/callback.c @@ -1,7 +1,7 @@ /* File: callback.c - * + * * This file is part of XSCHEM, - * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit + * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit * simulation. * Copyright (C) 1998-2020 Stefan Frederik Schippers * @@ -22,7 +22,7 @@ #include "xschem.h" static int mx_save, my_save; -static int last_command=0; +static int last_command=0; void start_line(double mx, double my) { @@ -33,13 +33,13 @@ void start_line(double mx, double my) mx_double_save=mousex_snap; } if(!horizontal_move) { - my_save = my; /* 20070323 */ + my_save = my; my_double_save=mousey_snap; } - if(horizontal_move) mousey_snap = my_double_save; /* 20171023 */ + if(horizontal_move) mousey_snap = my_double_save; if(vertical_move) mousex_snap = mx_double_save; } else { - mx_save = mx; my_save = my; /* 20070323 */ + mx_save = mx; my_save = my; mx_double_save=mousex_snap; my_double_save=mousey_snap; } @@ -55,13 +55,13 @@ void start_wire(double mx, double my) mx_double_save=mousex_snap; } if(!horizontal_move) { - my_save = my; /* 20070323 */ + my_save = my; my_double_save=mousey_snap; } - if(horizontal_move) mousey_snap = my_double_save; /* 20171023 */ + if(horizontal_move) mousey_snap = my_double_save; if(vertical_move) mousex_snap = mx_double_save; } else { - mx_save = mx; my_save = my; /* 20070323 */ + mx_save = mx; my_save = my; mx_double_save=mousex_snap; my_double_save=mousey_snap; } @@ -70,8 +70,8 @@ void start_wire(double mx, double my) } /* main window callback */ /* mx and my are set to the mouse coord. relative to window */ -int callback(int event, int mx, int my, KeySym key, - int button, int aux, int state) +int callback(int event, int mx, int my, KeySym key, + int button, int aux, int state) { char str[PATH_MAX];/* overflow safe 20161122 */ static char sel_or_clip[PATH_MAX] = "";/* overflow safe 20161122 */ @@ -125,35 +125,35 @@ int callback(int event, int mx, int my, KeySym key, state &=~Mod2Mask; /* 20170511 filter out NumLock status */ if(semaphore) { - if(debug_var>=2) + if(debug_var>=2) if(event != MotionNotify) fprintf(errfp, "callback(): reentrant call of callback(), semaphore=%d\n", semaphore); /* if(event==Expose) { * XCopyArea(display, save_pixmap, window, gctiled, mx,my,button,aux,mx,my); - * + * * } */ /* return 0; */ } semaphore++; /* used to debug Tcl-Tk frontend */ mousex=X_TO_XSCHEM(mx); - mousey=Y_TO_XSCHEM(my); + mousey=Y_TO_XSCHEM(my); mousex_snap=ROUND(mousex / cadsnap) * cadsnap; mousey_snap=ROUND(mousey / cadsnap) * cadsnap; - my_snprintf(str, S(str), "mouse = %.16g %.16g - selected: %d path: %s", - mousex_snap, mousey_snap, lastselected, sch_path[currentsch] ); + my_snprintf(str, S(str), "mouse = %.16g %.16g - selected: %d path: %s", + mousex_snap, mousey_snap, lastselected, xctx.sch_path[xctx.currsch] ); statusmsg(str,1); switch(event) { case EnterNotify: if(!sel_or_clip[0]) my_snprintf(sel_or_clip, S(sel_or_clip), "%s/%s", user_conf_dir, ".selection.sch"); - /* xschem window *sending* selected objects - when the pointer comes back in abort copy operation since it has been done + /* 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 */ - if( stat(sel_or_clip, &buf) && (ui_state & STARTCOPY) ) + if( stat(sel_or_clip, &buf) && (ui_state & STARTCOPY) ) { copy_objects(ABORT); /* also unlinks sel_or_flip file */ - unselect_all(); + unselect_all(); } /* xschem window *receiving* selected objects */ /* no selected objects and selection file exists */ @@ -204,10 +204,10 @@ int callback(int event, int mx, int my, KeySym key, /* *NOT* a solution but at least makes the program useable. 20171130 */ XSetClipRectangles(display, gctiled, 0,0, xrect, 1, Unsorted); #endif - my_snprintf(str, S(str), "mouse = %.16g %.16g - selected: %d w=%.16g h=%.16g", - mousex_snap, mousey_snap, + my_snprintf(str, S(str), "mouse = %.16g %.16g - selected: %d w=%.16g h=%.16g", + mousex_snap, mousey_snap, lastselected , - mousex_snap-mx_double_save, mousey_snap-my_double_save /* 20070322 */ + mousex_snap-mx_double_save, mousey_snap-my_double_save ); statusmsg(str,1); } @@ -221,27 +221,27 @@ int callback(int event, int mx, int my, KeySym key, } } if(ui_state & STARTWIRE) { - if(horizontal_move) mousey_snap = my_double_save; /* 20171023 */ + if(horizontal_move) mousey_snap = my_double_save; if(vertical_move) mousex_snap = mx_double_save; new_wire(RUBBER, mousex_snap, mousey_snap); } if(ui_state & STARTARC) { - if(horizontal_move) mousey_snap = my_double_save; /* 20171023 */ + if(horizontal_move) mousey_snap = my_double_save; if(vertical_move) mousex_snap = mx_double_save; new_arc(RUBBER, 0); } if(ui_state & STARTLINE) { - if(horizontal_move) mousey_snap = my_double_save; /* 20171023 */ + if(horizontal_move) mousey_snap = my_double_save; if(vertical_move) mousex_snap = mx_double_save; new_line(RUBBER); } if(ui_state & STARTMOVE) { - if(horizontal_move) mousey_snap = my_double_save; /* 20171023 */ + if(horizontal_move) mousey_snap = my_double_save; if(vertical_move) mousex_snap = mx_double_save; move_objects(RUBBER,0,0,0); } if(ui_state & STARTCOPY) { - if(horizontal_move) mousey_snap = my_double_save; /* 20171023 */ + if(horizontal_move) mousey_snap = my_double_save; if(vertical_move) mousex_snap = mx_double_save; copy_objects(RUBBER); } @@ -249,7 +249,7 @@ int callback(int event, int mx, int my, KeySym key, if(ui_state & STARTPOLYGON) { if(horizontal_move) mousey_snap = my_double_save; if(vertical_move) mousex_snap = mx_double_save; - new_polygon(RUBBER); /* 20171115 */ + new_polygon(RUBBER); } if(!(ui_state & STARTPOLYGON) && (state&Button1Mask) && !(ui_state & STARTWIRE) && !(ui_state & STARTPAN2) && !(state & Mod1Mask) && !(state & ShiftMask) && !(ui_state & PLACE_SYMBOL)) /* start of a mouse area select */ @@ -282,15 +282,15 @@ int callback(int event, int mx, int my, KeySym key, select_rect(BEGIN,1); } if(abs(mx-mx_save) > 8 || abs(my-my_save) > 8 ) { /* set some reasonable threshold before unselecting */ - select_object(X_TO_XSCHEM(mx_save), Y_TO_XSCHEM(my_save), 0, 0); /* 20121130 remove near object if dragging */ + select_object(X_TO_XSCHEM(mx_save), Y_TO_XSCHEM(my_save), 0, 0); /* remove near object if dragging */ rebuild_selected_array(); } } } break; - case KeyRelease: /* 20161118 */ + case KeyRelease: break; - case KeyPress: /* 20161118 */ + case KeyPress: if(key==' ') { if(ui_state & STARTWIRE) { /* & instead of == 20190409 */ new_wire(RUBBER|CLEAR, mousex_snap, mousey_snap); @@ -304,7 +304,7 @@ int callback(int event, int mx, int my, KeySym key, manhattan_lines %=3; new_line(RUBBER); } else { - if(semaphore<2) { /* 20160425 */ + if(semaphore<2) { rebuild_selected_array(); if(lastselected==0) ui_state &=~SELECTION; } @@ -399,12 +399,12 @@ int callback(int event, int mx, int my, KeySym key, tcleval("xschem set horizontal_move"); } if(ui_state & STARTWIRE) { - if(horizontal_move) mousey_snap = my_double_save; /* 20171023 */ + if(horizontal_move) mousey_snap = my_double_save; if(vertical_move) mousex_snap = mx_double_save; new_wire(RUBBER, mousex_snap, mousey_snap); } if(ui_state & STARTLINE) { - if(horizontal_move) mousey_snap = my_double_save; /* 20171023 */ + if(horizontal_move) mousey_snap = my_double_save; if(vertical_move) mousex_snap = mx_double_save; new_line(RUBBER); } @@ -423,12 +423,12 @@ int callback(int event, int mx, int my, KeySym key, tcleval("xschem set vertical_move"); } if(ui_state & STARTWIRE) { - if(horizontal_move) mousey_snap = my_double_save; /* 20171023 */ + if(horizontal_move) mousey_snap = my_double_save; if(vertical_move) mousex_snap = mx_double_save; new_wire(RUBBER, mousex_snap, mousey_snap); } if(ui_state & STARTLINE) { - if(horizontal_move) mousey_snap = my_double_save; /* 20171023 */ + if(horizontal_move) mousey_snap = my_double_save; if(vertical_move) mousex_snap = mx_double_save; new_line(RUBBER); } @@ -477,12 +477,12 @@ int callback(int event, int mx, int my, KeySym key, } else if(fill==2) { tcleval("alert_ { solid pattern fill} {}"); - for(x=0;xprop_ptr,"type",0)); */ - my_strdup(23, &type,(inst_ptr[j].ptr+instdef)->type); /* 20150409 */ + /* my_strdup(22, &type,get_tok_value((xctx.inst[j].ptr+ xctx.sym)->prop_ptr,"type",0)); */ + my_strdup(23, &type,(xctx.inst[j].ptr+ xctx.sym)->type); if( type && IS_LABEL_SH_OR_PIN(type)) break; - symbol = instdef + inst_ptr[j].ptr; + symbol = xctx.sym + xctx.inst[j].ptr; npin = symbol->rects[PINLAYER]; - rect=symbol->boxptr[PINLAYER]; + rct=symbol->rect[PINLAYER]; dbg(1, "\n"); for(i=0;i= 2) break; - start_wire(mx, my); + start_wire(mx, my); break; } if(key == XK_Return && (state == 0 ) && ui_state & STARTPOLYGON) { /* close polygon */ @@ -592,7 +592,7 @@ int callback(int event, int mx, int my, KeySym key, tcleval("set vertical_move 0; set horizontal_move 0" ); last_command=0; manhattan_lines = 0; - horizontal_move = vertical_move = 0; /* 20171023 */ + horizontal_move = vertical_move = 0; dbg(1, "callback(): Escape: ui_state=%ld\n", ui_state); if(ui_state & STARTMOVE) { @@ -612,9 +612,9 @@ int callback(int event, int mx, int my, KeySym key, delete(); set_modify(0); /* aborted merge: no change, so reset modify flag set by delete() */ } - + ui_state = 0; - unselect_all(); + unselect_all(); draw(); break; } @@ -630,7 +630,7 @@ int callback(int event, int mx, int my, KeySym key, if(key=='p' && state == Mod1Mask) /* add symbol pin */ { unselect_all(); - storeobject(-1, mousex_snap-2.5, mousey_snap-2.5, mousex_snap+2.5, mousey_snap+2.5, + storeobject(-1, mousex_snap-2.5, mousey_snap-2.5, mousex_snap+2.5, mousey_snap+2.5, xRECT, PINLAYER, SELECTED, "name=XXX\ndir=inout"); need_rebuild_selected_array=1; rebuild_selected_array(); @@ -642,7 +642,7 @@ int callback(int event, int mx, int my, KeySym key, { if(semaphore >= 2) break; dbg(1, "callback(): start polygon\n"); - mx_save = mx; my_save = my; /* 20070323 */ + mx_save = mx; my_save = my; mx_double_save=mousex_snap; my_double_save=mousey_snap; last_command = 0; @@ -655,7 +655,7 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='P' && state == ShiftMask) /* pan, other way to. */ { - xorigin=-mousex_snap+areaw*zoom/2.0;yorigin=-mousey_snap+areah*zoom/2.0; + xctx.xorigin=-mousex_snap+areaw*xctx.zoom/2.0;xctx.yorigin=-mousey_snap+areah*xctx.zoom/2.0; draw(); break; } @@ -679,25 +679,25 @@ int callback(int event, int mx, int my, KeySym key, } if(key==XK_Right) /* left */ { - xorigin+=-CADMOVESTEP*zoom; + xctx.xorigin+=-CADMOVESTEP*xctx.zoom; draw(); break; } if(key==XK_Left) /* right */ { - xorigin-=-CADMOVESTEP*zoom; + xctx.xorigin-=-CADMOVESTEP*xctx.zoom; draw(); break; } if(key==XK_Down) /* down */ { - yorigin+=-CADMOVESTEP*zoom; + xctx.yorigin+=-CADMOVESTEP*xctx.zoom; draw(); break; } if(key==XK_Up) /* up */ { - yorigin-=-CADMOVESTEP*zoom; + xctx.yorigin-=-CADMOVESTEP*xctx.zoom; draw(); break; } @@ -709,7 +709,7 @@ int callback(int event, int mx, int my, KeySym key, if(strcmp(tclresult(),"ok")==0) { tcleval( "exit"); } - } + } else { tcleval( "exit"); } @@ -725,7 +725,7 @@ int callback(int event, int mx, int my, KeySym key, if(key=='r' && !ui_state && state==0) /* start rect */ { dbg(1, "callback(): start rect\n"); - mx_save = mx; my_save = my; /* 20070323 */ + mx_save = mx; my_save = my; mx_double_save=mousex_snap; my_double_save=mousey_snap; last_command = 0; @@ -762,7 +762,7 @@ int callback(int event, int mx, int my, KeySym key, { if(semaphore >= 2) break; /* check if unnamed schematic, use saveas in this case */ - if(!strcmp(schematic[currentsch],"") || strstr(schematic[currentsch], "untitled")) { + if(!strcmp(xctx.sch[xctx.currsch],"") || strstr(xctx.sch[xctx.currsch], "untitled")) { saveas(NULL, SCHEMATIC); } else { save(1); @@ -804,11 +804,11 @@ int callback(int event, int mx, int my, KeySym key, if(key=='a' && state == 0) /* make symbol */ { - if(semaphore >= 2) break; /* 20180914 */ + if(semaphore >= 2) break; tcleval("tk_messageBox -type okcancel -message {do you want to make symbol view ?}"); - if(strcmp(tclresult(),"ok")==0) + if(strcmp(tclresult(),"ok")==0) { - save_schematic(schematic[currentsch]); + save_schematic(xctx.sch[xctx.currsch]); make_symbol(); } break; @@ -821,7 +821,7 @@ int callback(int event, int mx, int my, KeySym key, if(key=='y' && state == 0) /* toggle stretching */ { enable_stretch=!enable_stretch; - + if(enable_stretch) { tcleval("alert_ { enabling stretch mode } {}"); tclsetvar("enable_stretch","1"); @@ -839,7 +839,7 @@ int callback(int event, int mx, int my, KeySym key, if(lastselected) { /* 20071203 check if something selected */ save_selection(2); delete(); - } + } break; } if(key=='c' && state == ControlMask) /* save clipboard */ @@ -901,14 +901,14 @@ int callback(int event, int mx, int my, KeySym key, if(semaphore >= 2) break; rebuild_selected_array(); if(lastselected==0 ) { - my_snprintf(str, S(str), "edit_file {%s}", abs_sym_path(schematic[currentsch], "")); + my_snprintf(str, S(str), "edit_file {%s}", abs_sym_path(xctx.sch[xctx.currsch], "")); tcleval(str); } else if(selectedgroup[0].type==ELEMENT) { - my_snprintf(str, S(str), "edit_file {%s}", - abs_sym_path(inst_ptr[selectedgroup[0].n].name, "")); + my_snprintf(str, S(str), "edit_file {%s}", + abs_sym_path(xctx.inst[selectedgroup[0].n].name, "")); tcleval(str); - + } break; } @@ -928,7 +928,7 @@ int callback(int event, int mx, int my, KeySym key, last_command = 0; /* place_symbol(-1,NULL,mousex_snap, mousey_snap, 0, 0, NULL,3, 1);*/ - mx_save = mx; my_save = my; /* 20070323 */ + mx_save = mx; my_save = my; mx_double_save = mousex_snap; my_double_save = mousey_snap; if(place_symbol(-1,NULL,mousex_snap, mousey_snap, 0, 0, NULL, 4, 1) ) { @@ -947,7 +947,7 @@ int callback(int event, int mx, int my, KeySym key, char filename[PATH_MAX]; unselect_all(); remove_symbols(); - my_strncpy(filename, abs_sym_path(schematic[currentsch], ""), S(filename)); + my_strncpy(filename, abs_sym_path(xctx.sch[xctx.currsch], ""), S(filename)); load_schematic(1, filename, 1); draw(); } @@ -972,7 +972,7 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='k' && state==ControlMask) /* unhilight net */ { - Box boundbox; + xRect boundbox; if(semaphore >= 2) break; calc_drawing_bbox(&boundbox, 2); @@ -1006,7 +1006,7 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='K' && state == ShiftMask) /* delete hilighted nets */ { - Box boundbox; + xRect boundbox; if(semaphore >= 2) break; enable_drill=0; calc_drawing_bbox(&boundbox, 2); @@ -1034,7 +1034,7 @@ int callback(int event, int mx, int my, KeySym key, if(key=='g' && state==ControlMask) /* set snap factor 20161212 */ { my_snprintf(str, S(str), - "input_line {Enter snap value (default: %.16g current: %.16g)} {xschem set cadsnap} {%g} 10", + "input_line {Enter snap value (default: %.16g current: %.16g)} {xschem set cadsnap} {%g} 10", CADSNAP, cadsnap, cadsnap); tcleval(str); break; @@ -1065,14 +1065,14 @@ int callback(int event, int mx, int my, KeySym key, if(key=='u' && state==Mod1Mask) /* align to grid */ { if(semaphore >= 2) break; - push_undo(); /* 20150327 */ + push_undo(); round_schematic_to_grid(cadsnap); set_modify(1); prepared_hash_instances=0; prepared_hash_wires=0; prepared_netlist_structs=0; prepared_hilight_structs=0; - + draw(); break; } @@ -1109,13 +1109,13 @@ int callback(int event, int mx, int my, KeySym key, if(key=='&') /* check wire connectivity */ { if(semaphore >= 2) break; - push_undo(); /* 20150327 */ + push_undo(); trim_wires(); draw(); break; } if(key=='l' && state == ControlMask) { /* create schematic from selected symbol 20171004 */ - + if(semaphore >= 2) break; create_sch_from_sym(); break; @@ -1154,7 +1154,7 @@ int callback(int event, int mx, int my, KeySym key, else if(ui_state & STARTCOPY) copy_objects(FLIP); else { rebuild_selected_array(); - mx_save = mx; my_save = my; /* 20070323 */ + mx_save = mx; my_save = my; mx_double_save=mousex_snap; my_double_save=mousey_snap; move_objects(BEGIN,0,0,0); @@ -1176,7 +1176,7 @@ int callback(int event, int mx, int my, KeySym key, else if(ui_state & STARTCOPY) copy_objects(FLIP|ROTATELOCAL); else { rebuild_selected_array(); - mx_save = mx; my_save = my; /* 20070323 */ + mx_save = mx; my_save = my; mx_double_save=mousex_snap; my_double_save=mousey_snap; move_objects(BEGIN,0,0,0); @@ -1191,7 +1191,7 @@ int callback(int event, int mx, int my, KeySym key, else if(ui_state & STARTCOPY) copy_objects(ROTATE); else { rebuild_selected_array(); - mx_save = mx; my_save = my; /* 20070323 */ + mx_save = mx; my_save = my; mx_double_save=mousex_snap; my_double_save=mousey_snap; move_objects(BEGIN,0,0,0); @@ -1208,7 +1208,7 @@ int callback(int event, int mx, int my, KeySym key, else if(ui_state & STARTCOPY) copy_objects(ROTATE|ROTATELOCAL); else { rebuild_selected_array(); - mx_save = mx; my_save = my; /* 20070323 */ + mx_save = mx; my_save = my; mx_double_save=mousex_snap; my_double_save=mousey_snap; move_objects(BEGIN,0,0,0); @@ -1219,18 +1219,18 @@ int callback(int event, int mx, int my, KeySym key, } if(key=='m' && state==0 && !(ui_state & (STARTMOVE | STARTCOPY)))/* move selected obj. */ { - mx_save = mx; my_save = my; /* 20070323 */ + mx_save = mx; my_save = my; mx_double_save=mousex_snap; my_double_save=mousey_snap; move_objects(BEGIN,0,0,0); break; } - + if(key=='c' && state==0 && /* copy selected obj. */ !(ui_state & (STARTMOVE | STARTCOPY))) { if(semaphore >= 2) break; - mx_save = mx; my_save = my; /* 20070323 */ + mx_save = mx; my_save = my; mx_double_save=mousex_snap; my_double_save=mousey_snap; copy_objects(BEGIN); @@ -1250,7 +1250,7 @@ int callback(int event, int mx, int my, KeySym key, { yyparse_error = 0; if(semaphore >= 2) break; - unselect_all(); /* 20180929 */ + unselect_all(); if(set_netlist_dir(0, NULL)) { dbg(1, "callback(): -------------\n"); if(netlist_type == CAD_SPICE_NETLIST) @@ -1272,7 +1272,7 @@ int callback(int event, int mx, int my, KeySym key, { yyparse_error = 0; if(semaphore >= 2) break; - unselect_all(); /* 20180929 */ + unselect_all(); if( set_netlist_dir(0, NULL) ) { dbg(1, "callback(): -------------\n"); if(netlist_type == CAD_SPICE_NETLIST) @@ -1302,15 +1302,15 @@ int callback(int event, int mx, int my, KeySym key, } break; } - if(key=='>') { /* 20151117 */ + if(key=='>') { if(semaphore >= 2) break; - if(draw_single_layer< cadlayers-1) draw_single_layer++; + if(draw_single_layer< cadlayers-1) draw_single_layer++; draw(); break; } - if(key=='<') { /* 20151117 */ + if(key=='<') { if(semaphore >= 2) break; - if(draw_single_layer>=0 ) draw_single_layer--; + if(draw_single_layer>=0 ) draw_single_layer--; draw(); break; } @@ -1345,14 +1345,14 @@ int callback(int event, int mx, int my, KeySym key, if(key=='B' && state==ShiftMask) /* delete files */ { - if(semaphore >= 2) break; /* 20160423 */ + if(semaphore >= 2) break; rebuild_selected_array(); if(lastselected && selectedgroup[0].type==ELEMENT) { - my_snprintf(str, S(str), "delete_files {%s}", - abs_sym_path(inst_ptr[selectedgroup[0].n].name, "")); + my_snprintf(str, S(str), "delete_files {%s}", + abs_sym_path(xctx.inst[selectedgroup[0].n].name, "")); } else { - my_snprintf(str, S(str), "delete_files {%s}", - abs_sym_path(schematic[currentsch], "")); + my_snprintf(str, S(str), "delete_files {%s}", + abs_sym_path(xctx.sch[xctx.currsch], "")); } tcleval(str); @@ -1361,8 +1361,8 @@ int callback(int event, int mx, int my, KeySym key, if(key=='x' && state == 0 ) /* new cad session */ { char * tmp; - tmp = (char *) tclgetvar("XSCHEM_START_WINDOW"); /* 20121110 */ - if(tmp && tmp[0]) new_window(abs_sym_path(tmp, "") ,0); /* 20090708 */ + tmp = (char *) tclgetvar("XSCHEM_START_WINDOW"); + if(tmp && tmp[0]) new_window(abs_sym_path(tmp, "") ,0); else new_window(NULL, 0); break; } @@ -1378,7 +1378,7 @@ int callback(int event, int mx, int my, KeySym key, } if( 0 && (key==';') && (state & ControlMask) ) /* testmode: for performance testing */ { - draw_stuff(); + draw_stuff(); draw(); break; } @@ -1436,7 +1436,7 @@ int callback(int event, int mx, int my, KeySym key, } if((key=='z' && state==ControlMask)) /* zoom out */ { - view_unzoom(0.0); + view_unzoom(0.0); break; } if(key=='!') @@ -1449,11 +1449,11 @@ int callback(int event, int mx, int my, KeySym key, case ButtonPress: /* end operation */ dbg(1, "callback(): ButtonPress ui_state=%ld state=%d\n",ui_state,state); - if(ui_state & STARTPAN2) { /* 20121123 */ + if(ui_state & STARTPAN2) { ui_state &=~STARTPAN2; mx_save = mx; my_save = my; - mx_double_save=mousex_snap; /* 20070322 */ - my_double_save=mousey_snap; /* 20070322 */ + mx_double_save=mousex_snap; + my_double_save=mousey_snap; break; } @@ -1473,26 +1473,26 @@ int callback(int event, int mx, int my, KeySym key, } else if(button==Button4 && state == 0 ) view_zoom(CADZOOMSTEP); - /* 20111114 */ + else if(button==Button4 && (state & ShiftMask) && !(state & Button2Mask)) { - xorigin+=-CADMOVESTEP*zoom/2.; + xctx.xorigin+=-CADMOVESTEP*xctx.zoom/2.; draw(); } else if(button==Button5 && (state & ShiftMask) && !(state & Button2Mask)) { - xorigin-=-CADMOVESTEP*zoom/2.; + xctx.xorigin-=-CADMOVESTEP*xctx.zoom/2.; draw(); } else if(button==Button4 && (state & ControlMask) && !(state & Button2Mask)) { - yorigin+=-CADMOVESTEP*zoom/2.; + xctx.yorigin+=-CADMOVESTEP*xctx.zoom/2.; draw(); } else if(button==Button5 && (state & ControlMask) && !(state & Button2Mask)) { - yorigin-=-CADMOVESTEP*zoom/2.; + xctx.yorigin-=-CADMOVESTEP*xctx.zoom/2.; draw(); } else if(button==Button1 && (state & Mod1Mask) ) { last_command = 0; - mx_save = mx; my_save = my; /* 20171218 */ + mx_save = mx; my_save = my; mx_double_save=mousex_snap; my_double_save=mousey_snap; @@ -1528,30 +1528,30 @@ int callback(int event, int mx, int my, KeySym key, break; } if(!(ui_state & STARTPOLYGON) && !(ui_state & STARTWIRE) && !(ui_state & STARTLINE) ) { - horizontal_move = vertical_move=0; /* 20171023 */ + horizontal_move = vertical_move=0; tcleval("set vertical_move 0; set horizontal_move 0" ); } if(ui_state & MENUSTARTTEXT) { - place_text(1, mousex_snap, mousey_snap); /* 20161201 */ + place_text(1, mousex_snap, mousey_snap); ui_state &=~MENUSTARTTEXT; - break; /* 20161201 */ + break; } if(ui_state & MENUSTARTWIRE) { - mx_save = mx; my_save = my; /* 20070323 */ + mx_save = mx; my_save = my; mx_double_save=mousex_snap; my_double_save=mousey_snap; - new_wire(PLACE, mousex_snap, mousey_snap); + new_wire(PLACE, mousex_snap, mousey_snap); ui_state &=~MENUSTARTWIRE; break; } - if(ui_state & MENUSTARTSNAPWIRE) { /* 20171022 */ + if(ui_state & MENUSTARTSNAPWIRE) { double x, y; int xx, yy; - + find_closest_net_or_symbol_pin(mousex, mousey, &x, &y); xx = X_TO_SCREEN(x); yy = Y_TO_SCREEN(y); - mx_save = xx; my_save = yy; /* 20070323 */ + mx_save = xx; my_save = yy; mx_double_save = ROUND(x / cadsnap) * cadsnap; my_double_save = ROUND(y / cadsnap) * cadsnap; @@ -1560,7 +1560,7 @@ int callback(int event, int mx, int my, KeySym key, break; } if(ui_state & MENUSTARTLINE) { - mx_save = mx; my_save = my; /* 20070323 */ + mx_save = mx; my_save = my; mx_double_save=mousex_snap; my_double_save=mousey_snap; new_line(PLACE); @@ -1568,7 +1568,7 @@ int callback(int event, int mx, int my, KeySym key, break; } if(ui_state & MENUSTARTRECT) { - mx_save = mx; my_save = my; /* 20070323 */ + mx_save = mx; my_save = my; mx_double_save=mousex_snap; my_double_save=mousey_snap; new_rect(PLACE); @@ -1619,10 +1619,10 @@ int callback(int event, int mx, int my, KeySym key, mx_double_save=mousex_snap; } if(!horizontal_move) { - my_save = my; /* 20070323 */ + my_save = my; my_double_save=mousey_snap; } - if(horizontal_move) mousey_snap = my_double_save; /* 20171023 */ + if(horizontal_move) mousey_snap = my_double_save; if(vertical_move) mousex_snap = mx_double_save; new_wire(PLACE, mousex_snap, mousey_snap); @@ -1642,10 +1642,10 @@ int callback(int event, int mx, int my, KeySym key, mx_double_save=mousex_snap; } if(!horizontal_move) { - my_save = my; /* 20070323 */ + my_save = my; my_double_save=mousey_snap; } - if(horizontal_move) mousey_snap = my_double_save; /* 20171023 */ + if(horizontal_move) mousey_snap = my_double_save; if(vertical_move) mousex_snap = mx_double_save; new_line(PLACE); } else { @@ -1657,13 +1657,13 @@ int callback(int event, int mx, int my, KeySym key, new_rect(PLACE|END); break; } - if(ui_state & STARTPOLYGON) { /* 20171115 */ + if(ui_state & STARTPOLYGON) { if(horizontal_move) mousey_snap = my_double_save; if(vertical_move) mousex_snap = mx_double_save; new_polygon(ADD); mx_double_save=mousex_snap; my_double_save=mousey_snap; - horizontal_move = vertical_move=0; /* 20171023 */ + horizontal_move = vertical_move=0; tcleval("set vertical_move 0; set horizontal_move 0" ); break; } @@ -1679,8 +1679,8 @@ int callback(int event, int mx, int my, KeySym key, if( !(ui_state & STARTSELECT) && !(ui_state & STARTWIRE) && !(ui_state & STARTLINE) ) { int prev_last_sel = lastselected; mx_save = mx; my_save = my; - mx_double_save=mousex_snap; /* 20070322 */ - my_double_save=mousey_snap; /* 20070322 */ + mx_double_save=mousex_snap; + my_double_save=mousey_snap; if( !(state & ShiftMask) && !(state & Mod1Mask) ) { unselect_all(); #ifndef __unix__ @@ -1693,11 +1693,11 @@ int callback(int event, int mx, int my, KeySym key, #ifndef __unix__ draw_selection(gc[SELLAYER], 0); /* 20181009 moved outside of cadlayers loop */ #endif - if(sel && state == ControlMask) { /* 20170416 */ + if(sel && state == ControlMask) { launcher(); } if( !(state & ShiftMask) ) { - Box boundbox; + xRect boundbox; if(auto_hilight && hilight_nets && sel == 0 ) { /* 20160413 20160503 */ if(!prev_last_sel) { calc_drawing_bbox(&boundbox, 2); @@ -1711,7 +1711,7 @@ int callback(int event, int mx, int my, KeySym key, } } } - if(auto_hilight) { /* 20160413 */ + if(auto_hilight) { hilight_net(0); if(lastselected) { redraw_hilights(); @@ -1726,13 +1726,13 @@ int callback(int event, int mx, int my, KeySym key, if(ui_state & STARTPAN2) { ui_state &=~STARTPAN2; mx_save = mx; my_save = my; - mx_double_save=mousex_snap; /* 20070322 */ - my_double_save=mousey_snap; /* 20070322 */ + mx_double_save=mousex_snap; + my_double_save=mousey_snap; break; } dbg(1, "callback(): ButtonRelease ui_state=%ld state=%d\n",ui_state,state); - if(semaphore >= 2) break; /* 20160423 */ + if(semaphore >= 2) break; if(ui_state & STARTSELECT) { if(state & ControlMask) { enable_stretch=1; @@ -1744,8 +1744,8 @@ int callback(int event, int mx, int my, KeySym key, if(!(state&(Button4Mask|Button5Mask) ) ) select_rect(END,-1); } rebuild_selected_array(); - my_snprintf(str, S(str), "mouse = %.16g %.16g - selected: %d path: %s", - mousex_snap, mousey_snap, lastselected, sch_path[currentsch] ); + my_snprintf(str, S(str), "mouse = %.16g %.16g - selected: %d path: %s", + mousex_snap, mousey_snap, lastselected, xctx.sch_path[xctx.currsch] ); statusmsg(str,1); } @@ -1767,17 +1767,17 @@ int callback(int event, int mx, int my, KeySym key, #ifndef __unix__ case MOUSE_WHEEL_UP: /* windows do not use button4 and button5 like X */ { - xorigin += -CADMOVESTEP * zoom / 2.; + xctx.xorigin += -CADMOVESTEP * xctx.zoom / 2.; draw(); } #endif break; - + default: dbg(1, "callback(): Event:%d\n",event); break; - } - + } + semaphore--; return 0; } diff --git a/src/check.c b/src/check.c index 4c56c497..751b0cf3 100644 --- a/src/check.c +++ b/src/check.c @@ -1,7 +1,7 @@ /* File: check.c - * + * * This file is part of XSCHEM, - * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit + * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit * simulation. * Copyright (C) 1998-2020 Stefan Frederik Schippers * @@ -32,47 +32,47 @@ void check_touch(int i, int j, int touch1=0,touch2=0,touch3=0,touch4=0; double delta1x,delta1y,delta2x,delta2y; double x1,y1,x2,y2; - x1=wire[i].x1; - x2=wire[i].x2; - y1=wire[i].y1; - y2=wire[i].y2; + x1=xctx.wire[i].x1; + x2=xctx.wire[i].x2; + y1=xctx.wire[i].y1; + y2=xctx.wire[i].y2; delta1x = x2-x1;delta1y = y1-y2 ; - delta2x = wire[j].x2-wire[j].x1;delta2y = wire[j].y1-wire[j].y2 ; + delta2x = xctx.wire[j].x2-xctx.wire[j].x1;delta2y = xctx.wire[j].y1-xctx.wire[j].y2 ; *included = 0; *includes = 0; *touches = 0; - *broken = 0; + *broken = 0; *breaks = 0; *parallel = (delta1x*delta2y == delta2x*delta1y ? 1:0); /* the order of the following 4 if(touch...) is not don't care !!! */ - if(touch(wire[j].x1,wire[j].y1,wire[j].x2,wire[j].y2,x1,y1) ) + if(touch(xctx.wire[j].x1,xctx.wire[j].y1,xctx.wire[j].x2,xctx.wire[j].y2,x1,y1) ) { *touches = 1;touch3 =1; *xt = x1; *yt = y1; - if((*xt > wire[j].x1 && *xt < wire[j].x2)|| - (*yt > wire[j].y1 && *yt < wire[j].y2)) *breaks = 1; + if((*xt > xctx.wire[j].x1 && *xt < xctx.wire[j].x2)|| + (*yt > xctx.wire[j].y1 && *yt < xctx.wire[j].y2)) *breaks = 1; } - if(touch(wire[j].x1,wire[j].y1,wire[j].x2,wire[j].y2,x2,y2) ) + if(touch(xctx.wire[j].x1,xctx.wire[j].y1,xctx.wire[j].x2,xctx.wire[j].y2,x2,y2) ) { *touches = 1;touch4 =1; *xt = x2; *yt = y2; - if((*xt > wire[j].x1 && *xt < wire[j].x2)|| - (*yt > wire[j].y1 && *yt < wire[j].y2)) *breaks = 1; + if((*xt > xctx.wire[j].x1 && *xt < xctx.wire[j].x2)|| + (*yt > xctx.wire[j].y1 && *yt < xctx.wire[j].y2)) *breaks = 1; } if(touch3 && touch4) *included = 1; - - if(touch(x1,y1,x2,y2,wire[j].x1,wire[j].y1) ) + + if(touch(x1,y1,x2,y2,xctx.wire[j].x1,xctx.wire[j].y1) ) { *touches = 1;touch1=1; - *xt = wire[j].x1; *yt = wire[j].y1; + *xt = xctx.wire[j].x1; *yt = xctx.wire[j].y1; if((*xt > x1 && *xt < x2)||(*yt > y1 && *yt < y2)) *broken = 1; } - if(touch(x1,y1,x2,y2,wire[j].x2,wire[j].y2) ) + if(touch(x1,y1,x2,y2,xctx.wire[j].x2,xctx.wire[j].y2) ) { *touches = 1;touch2=1; - *xt = wire[j].x2; *yt = wire[j].y2; + *xt = xctx.wire[j].x2; *yt = xctx.wire[j].y2; if((*xt > x1 && *xt < x2)||(*yt > y1 && *yt < y2)) *broken = 1; } if(touch1 && touch2) *includes = 1; @@ -86,11 +86,11 @@ void update_conn_cues(int draw_cues, int dr_win) double x0, y0; double x1, y1, x2, y2; struct wireentry *wireptr; - - hash_wires(); /* must be done also if lastwire==0 to clear wiretable */ - if(!lastwire) return; + + hash_wires(); /* must be done also if xctx.wires==0 to clear wiretable */ + if(!xctx.wires) return; if(!draw_dots) return; - if(cadhalfdotsize*mooz<0.7) return; + if(cadhalfdotsize*xctx.mooz<0.7) return; x1 = X_TO_XSCHEM(areax1); y1 = Y_TO_XSCHEM(areay1); x2 = X_TO_XSCHEM(areax2); @@ -98,18 +98,18 @@ void update_conn_cues(int draw_cues, int dr_win) for(init_wire_iterator(x1, y1, x2, y2); ( wireptr = wire_iterator_next() ) ;) { k=wireptr->n; /* optimization when editing small areas (detailed zoom) of a huge schematic */ - if(LINE_OUTSIDE(wire[k].x1, wire[k].y1, wire[k].x2, wire[k].y2, x1, y1, x2, y2)) continue; + if(LINE_OUTSIDE(xctx.wire[k].x1, xctx.wire[k].y1, xctx.wire[k].x2, xctx.wire[k].y2, x1, y1, x2, y2)) continue; for(l = 0;l < 2;l++) { if(l==0 ) { - if(wire[k].end1 !=-1) continue; /* 20181103 */ - wire[k].end1=0; - x0 = wire[k].x1; - y0 = wire[k].y1; + if(xctx.wire[k].end1 !=-1) continue; + xctx.wire[k].end1=0; + x0 = xctx.wire[k].x1; + y0 = xctx.wire[k].y1; } else { - if(wire[k].end2 !=-1) continue; /* 20181103 */ - wire[k].end2=0; - x0 = wire[k].x2; - y0 = wire[k].y2; + if(xctx.wire[k].end2 !=-1) continue; + xctx.wire[k].end2=0; + x0 = xctx.wire[k].x2; + y0 = xctx.wire[k].y2; } get_square(x0, y0, &sqx, &sqy); for(wptr = wiretable[sqx][sqy] ; wptr ; wptr = wptr->next) { @@ -117,14 +117,14 @@ void update_conn_cues(int draw_cues, int dr_win) if(i == k) { continue; /* no check wire against itself */ } - if( touch(wire[i].x1, wire[i].y1, wire[i].x2, wire[i].y2, x0,y0) ) { - if( (x0 != wire[i].x1 && x0 != wire[i].x2) || - (y0 != wire[i].y1 && y0 != wire[i].y2) ) { - if(l == 0) wire[k].end1 += 2; - else wire[k].end2 += 2; + if( touch(xctx.wire[i].x1, xctx.wire[i].y1, xctx.wire[i].x2, xctx.wire[i].y2, x0,y0) ) { + if( (x0 != xctx.wire[i].x1 && x0 != xctx.wire[i].x2) || + (y0 != xctx.wire[i].y1 && y0 != xctx.wire[i].y2) ) { + if(l == 0) xctx.wire[k].end1 += 2; + else xctx.wire[k].end2 += 2; } else { - if(l == 0) wire[k].end1 += 1; - else wire[k].end2 += 1; + if(l == 0) xctx.wire[k].end1 += 1; + else xctx.wire[k].end2 += 1; } } } @@ -136,12 +136,12 @@ void update_conn_cues(int draw_cues, int dr_win) for(init_wire_iterator(x1, y1, x2, y2); ( wireptr = wire_iterator_next() ) ;) { i = wireptr->n; /* optimization when editing small areas (detailed zoom) of a huge schematic */ - if(LINE_OUTSIDE(wire[i].x1, wire[i].y1, wire[i].x2, wire[i].y2, x1, y1, x2, y2)) continue; - if( wire[i].end1 >1 ) { /* 20150331 draw_dots */ - filledarc(WIRELAYER, ADD, wire[i].x1, wire[i].y1, cadhalfdotsize, 0, 360); + if(LINE_OUTSIDE(xctx.wire[i].x1, xctx.wire[i].y1, xctx.wire[i].x2, xctx.wire[i].y2, x1, y1, x2, y2)) continue; + if( xctx.wire[i].end1 >1 ) { /* 20150331 draw_dots */ + filledarc(WIRELAYER, ADD, xctx.wire[i].x1, xctx.wire[i].y1, cadhalfdotsize, 0, 360); } - if( wire[i].end2 >1 ) { /* 20150331 draw_dots */ - filledarc(WIRELAYER, ADD, wire[i].x2, wire[i].y2, cadhalfdotsize, 0, 360); + if( xctx.wire[i].end2 >1 ) { /* 20150331 draw_dots */ + filledarc(WIRELAYER, ADD, xctx.wire[i].x2, xctx.wire[i].y2, cadhalfdotsize, 0, 360); } } filledarc(WIRELAYER, END, 0.0, 0.0, 0.0, 0.0, 0.0); @@ -157,16 +157,16 @@ void trim_wires(void) double xt=0,yt=0; int loops=0; - do { + do { loops++; - for(i=0;irects[PINLAYER]) > 0 ) + if( (rects = (xctx.inst[k].ptr+ xctx.sym)->rects[PINLAYER]) > 0 ) { for(r=0;rboxptr[PINLAYER]; - x0=(rect[r].x1+rect[r].x2)/2; - y0=(rect[r].y1+rect[r].y2)/2; - rot=inst_ptr[k].rot; - flip=inst_ptr[k].flip; + rct=(xctx.inst[k].ptr+ xctx.sym)->rect[PINLAYER]; + x0=(rct[r].x1+rct[r].x2)/2; + y0=(rct[r].y1+rct[r].y2)/2; + rot=xctx.inst[k].rot; + flip=xctx.inst[k].flip; ROTATION(0.0,0.0,x0,y0,rx1,ry1); - x0=inst_ptr[k].x0+rx1; - y0=inst_ptr[k].y0+ry1; + x0=xctx.inst[k].x0+rx1; + y0=xctx.inst[k].y0+ry1; get_square(x0, y0, &sqx, &sqy); for(wptr=wiretable[sqx][sqy]; wptr; wptr=wptr->next) { i = wptr->n; - if( touch(wire[i].x1, wire[i].y1, - wire[i].x2, wire[i].y2, x0,y0) ) + if( touch(xctx.wire[i].x1, xctx.wire[i].y1, + xctx.wire[i].x2, xctx.wire[i].y2, x0,y0) ) { - if( (x0!=wire[i].x1 && x0!=wire[i].x2) || - (y0!=wire[i].y1 && y0!=wire[i].y2) ) { + if( (x0!=xctx.wire[i].x1 && x0!=xctx.wire[i].x2) || + (y0!=xctx.wire[i].y1 && y0!=xctx.wire[i].y2) ) { if(!changed) { push_undo(); changed=1;} check_wire_storage(); - wire[lastwire].x1=wire[i].x1; - wire[lastwire].y1=wire[i].y1; - wire[lastwire].x2=x0; - wire[lastwire].y2=y0; - wire[lastwire].sel=SELECTED; - wire[lastwire].prop_ptr=NULL; - my_strdup(31, &wire[lastwire].prop_ptr, wire[i].prop_ptr); - if(!strcmp(get_tok_value(wire[lastwire].prop_ptr,"bus",0), "true")) /* 20171201 */ - wire[lastwire].bus=1; + xctx.wire[xctx.wires].x1=xctx.wire[i].x1; + xctx.wire[xctx.wires].y1=xctx.wire[i].y1; + xctx.wire[xctx.wires].x2=x0; + xctx.wire[xctx.wires].y2=y0; + xctx.wire[xctx.wires].sel=SELECTED; + xctx.wire[xctx.wires].prop_ptr=NULL; + my_strdup(31, &xctx.wire[xctx.wires].prop_ptr, xctx.wire[i].prop_ptr); + if(!strcmp(get_tok_value(xctx.wire[xctx.wires].prop_ptr,"bus",0), "true")) + xctx.wire[xctx.wires].bus=1; else - wire[lastwire].bus=0; - wire[lastwire].node=NULL; - hash_wire(XINSERT, lastwire); - my_strdup(32, &wire[lastwire].node, wire[i].node); + xctx.wire[xctx.wires].bus=0; + xctx.wire[xctx.wires].node=NULL; + hash_wire(XINSERT, xctx.wires); + my_strdup(32, &xctx.wire[xctx.wires].node, xctx.wire[i].node); need_rebuild_selected_array=1; - lastwire++; - wire[i].x1 = x0; - wire[i].y1 = y0; + xctx.wires++; + xctx.wire[i].x1 = x0; + xctx.wire[i].y1 = y0; } } } @@ -357,17 +357,17 @@ void break_wires_at_pins(void) /* hash_wires(); */ rebuild_selected_array(); for(j=0;j1600) return; /* too big */ + /*fprintf(errfp, "size=%.16g\n", size*xctx.mooz); */ + if(size*xctx.mooz<3.0) return; /* too small */ + if(size*xctx.mooz>1600) return; /* too big */ text_bbox(s, xscale, yscale, rot, flip, hcenter, vcenter, x,y, &textx1,&texty1,&textx2,&texty2); if(!textclip(areax1,areay1,areax2,areay2,textx1,texty1,textx2,texty2)) { @@ -359,8 +359,8 @@ void draw_string(int layer, int what, const char *s, int rot, int flip, int hcen (double)xcolor_array[layer].green/65535.0, (double)xcolor_array[layer].blue/65535.0); - cairo_set_font_size (cairo_ctx, size*mooz); - cairo_set_font_size (cairo_save_ctx, size*mooz); + cairo_set_font_size (cairo_ctx, size*xctx.mooz); + cairo_set_font_size (cairo_save_ctx, size*xctx.mooz); cairo_font_extents(cairo_ctx, &fext); llength=0; my_strdup2(73, &sss, s); @@ -370,9 +370,9 @@ void draw_string(int layer, int what, const char *s, int rot, int flip, int hcen 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, size, rot, flip, + if(draw_window) cairo_draw_string_line(cairo_ctx, tt, x, y, size, rot, flip, lineno, fext.height, fext.ascent, fext.descent, llength); - if(draw_pixmap) cairo_draw_string_line(cairo_save_ctx, tt, x, y, size, rot, flip, + if(draw_pixmap) cairo_draw_string_line(cairo_save_ctx, tt, x, y, size, rot, flip, lineno, fext.height, fext.ascent, fext.descent, llength); lineno++; if(c==0) break; @@ -390,8 +390,8 @@ void draw_string(int layer, int what, const char *s, int rot, int flip, int hcen #else /* !HAS_CAIRO */ /* no CAIRO version */ -void draw_string(int layer, int what, const char *str, int rot, int flip, int hcenter, int vcenter, - double x1,double y1, double xscale, double yscale) +void draw_string(int layer, int what, const char *str, int rot, int flip, int hcenter, int vcenter, + double x1,double y1, double xscale, double yscale) { double a=0.0,yy; register double rx1=0,rx2=0,ry1=0,ry2=0; @@ -400,12 +400,12 @@ void draw_string(int layer, int what, const char *str, int rot, int flip, int hc register int pos=0,pos2=0; register unsigned int cc; register double *char_ptr_x1,*char_ptr_y1,*char_ptr_x2,*char_ptr_y2; - register int i,lines; + register int i,lines; if(str==NULL || !has_x ) return; dbg(2, "draw_string(): string=%s\n",str); - if(xscale*FONTWIDTH*mooz<1) { - dbg(1, "draw_string(): xscale=%.16g zoom=%.16g \n",xscale,zoom); + if(xscale*FONTWIDTH*xctx.mooz<1) { + dbg(1, "draw_string(): xscale=%.16g xctx.zoom=%.16g \n",xscale,xctx.zoom); return; } else { @@ -426,7 +426,7 @@ void draw_string(int layer, int what, const char *str, int rot, int flip, int hc pos=0; a=0.0; continue; - } + } lines=character[cc][0]*4; char_ptr_x1=character[cc]+1; char_ptr_y1=character[cc]+2; @@ -452,7 +452,7 @@ void draw_string(int layer, int what, const char *str, int rot, int flip, int hc #endif /* HAS_CAIRO */ void draw_temp_string(GC gctext, int what, const char *str, int rot, int flip, int hcenter, int vcenter, - double x1,double y1, double xscale, double yscale) + double x1,double y1, double xscale, double yscale) { if(!has_x) return; dbg(2, "draw_string(): string=%s\n",str); @@ -460,81 +460,81 @@ void draw_temp_string(GC gctext, int what, const char *str, int rot, int flip, i drawtemprect(gctext,what, textx1,texty1,textx2,texty2); } -void draw_symbol(int what,int c, int n,int layer,int tmp_flip, int rot, - double xoffset, double yoffset) +void draw_symbol(int what,int c, int n,int layer,int tmp_flip, int rot, + double xoffset, double yoffset) /* draws current layer only, should be called within */ { /* a "for(i=0;iprop_ptr && - !strcmp(get_tok_value( (inst_ptr[n].ptr+instdef)->prop_ptr, "type",0 ), "subcircuit") ) || + (hide_symbols==1 && (xctx.inst[n].ptr+ xctx.sym)->prop_ptr && + !strcmp(get_tok_value( (xctx.inst[n].ptr+ xctx.sym)->prop_ptr, "type",0 ), "subcircuit") ) || (hide_symbols == 2) ) { hide = 1; } else { hide = 0; } if(hide && layer == 0) { - drawrect(4, what, inst_ptr[n].xx1, inst_ptr[n].yy1, inst_ptr[n].xx2, inst_ptr[n].yy2, 2); + drawrect(4, what, xctx.inst[n].xx1, xctx.inst[n].yy1, xctx.inst[n].xx2, xctx.inst[n].yy2, 2); } if(layer==0) { - x1=X_TO_SCREEN(inst_ptr[n].x1+xoffset); /* 20150729 added xoffset, yoffset */ - x2=X_TO_SCREEN(inst_ptr[n].x2+xoffset); - y1=Y_TO_SCREEN(inst_ptr[n].y1+yoffset); - y2=Y_TO_SCREEN(inst_ptr[n].y2+yoffset); + x1=X_TO_SCREEN(xctx.inst[n].x1+xoffset); /* 20150729 added xoffset, yoffset */ + x2=X_TO_SCREEN(xctx.inst[n].x2+xoffset); + y1=Y_TO_SCREEN(xctx.inst[n].y1+yoffset); + y2=Y_TO_SCREEN(xctx.inst[n].y2+yoffset); if(!only_probes && (x2-x1)< 0.3 && (y2-y1)< 0.3) { - inst_ptr[n].flags|=1; - return; /* 20171210 */ + xctx.inst[n].flags|=1; + return; } - else if(OUTSIDE(x1,y1,x2,y2,areax1,areay1,areax2,areay2)) + else if(OUTSIDE(x1,y1,x2,y2,areax1,areay1,areax2,areay2)) { - inst_ptr[n].flags|=1; + xctx.inst[n].flags|=1; return; } - else inst_ptr[n].flags&=~1; - - } else if(inst_ptr[n].flags&1) { + else xctx.inst[n].flags&=~1; + + } else if(xctx.inst[n].flags&1) { dbg(2, "draw_symbol(): skipping inst %d\n", n); return; } - flip = inst_ptr[n].flip; + flip = xctx.inst[n].flip; if(tmp_flip) flip = !flip; - rot = (inst_ptr[n].rot + rot ) & 0x3; - - x0=inst_ptr[n].x0 + xoffset; - y0=inst_ptr[n].y0 + yoffset; - symptr = (inst_ptr[n].ptr+instdef); + rot = (xctx.inst[n].rot + rot ) & 0x3; + + x0=xctx.inst[n].x0 + xoffset; + y0=xctx.inst[n].y0 + yoffset; + symptr = (xctx.inst[n].ptr+ xctx.sym); if(!hide) { for(j=0;j< symptr->lines[layer];j++) { - line = (symptr->lineptr[layer])[j]; + line = (symptr->line[layer])[j]; ROTATION(0.0,0.0,line.x1,line.y1,x1,y1); ROTATION(0.0,0.0,line.x2,line.y2,x2,y2); ORDER(x1,y1,x2,y2); - if(line.bus) + if(line.bus) drawline(c,THICK, x0+x1, y0+y1, x0+x2, y0+y2, line.dash); else drawline(c,what, x0+x1, y0+y1, x0+x2, y0+y2, line.dash); } - for(j=0;j< symptr->polygons[layer];j++) /* 20171115 */ - { - polygon = (symptr->polygonptr[layer])[j]; + for(j=0;j< symptr->polygons[layer];j++) + { + polygon = (symptr->poly[layer])[j]; { /* scope block so we declare some auxiliary arrays for coord transforms. 20171115 */ int k; double *x = my_malloc(34, sizeof(double) * polygon.points); @@ -550,9 +550,9 @@ void draw_symbol(int what,int c, int n,int layer,int tmp_flip, int rot, } } for(j=0;j< symptr->arcs[layer];j++) - { - - arc = (symptr->arcptr[layer])[j]; + { + + arc = (symptr->arc[layer])[j]; if(flip) { angle = 270.*rot+180.-arc.b-arc.a; } else { @@ -565,45 +565,45 @@ void draw_symbol(int what,int c, int n,int layer,int tmp_flip, int rot, } } /* if(!hide) */ - if( (!hide && (layer != PINLAYER || enable_layer[layer])) || + if( (!hide && (layer != PINLAYER || enable_layer[layer])) || (hide && layer == PINLAYER && enable_layer[layer]) ) { for(j=0;j< symptr->rects[layer];j++) { - box = (symptr->boxptr[layer])[j]; + box = (symptr->rect[layer])[j]; ROTATION(0.0,0.0,box.x1,box.y1,x1,y1); ROTATION(0.0,0.0,box.x2,box.y2,x2,y2); - RECTORDER(x1,y1,x2,y2); + RECTORDER(x1,y1,x2,y2); drawrect(c,what, x0+x1, y0+y1, x0+x2, y0+y2, box.dash); filledrect(c,what, x0+x1, y0+y1, x0+x2, y0+y2); } } - if( (layer==TEXTWIRELAYER && !(inst_ptr[n].flags&2) ) || - (sym_txt && (layer==TEXTLAYER) && (inst_ptr[n].flags&2) ) ) { + if( (layer==TEXTWIRELAYER && !(xctx.inst[n].flags&2) ) || + (sym_txt && (layer==TEXTLAYER) && (xctx.inst[n].flags&2) ) ) { const char *txtptr; for(j=0;j< symptr->texts;j++) { - text = symptr->txtptr[j]; - if(text.xscale*FONTWIDTH*mooz<1) continue; + text = symptr->text[j]; + if(text.xscale*FONTWIDTH*xctx.mooz<1) continue; if( hide && text.txt_ptr && strcmp(text.txt_ptr, "@symname") && strcmp(text.txt_ptr, "@name") ) continue; txtptr= translate(n, text.txt_ptr); ROTATION(0.0,0.0,text.x0,text.y0,x1,y1); textlayer = c; - if( !(c == PINLAYER && (inst_ptr[n].flags & 4))) { - textlayer = symptr->txtptr[j].layer; + if( !(c == PINLAYER && (xctx.inst[n].flags & 4))) { + textlayer = symptr->text[j].layer; if(textlayer < 0 || textlayer >= cadlayers) textlayer = c; } - if((c == PINLAYER && inst_ptr[n].flags & 4) || enable_layer[textlayer]) { + if((c == PINLAYER && xctx.inst[n].flags & 4) || enable_layer[textlayer]) { #ifdef HAS_CAIRO - textfont = symptr->txtptr[j].font; - if((textfont && textfont[0]) || symptr->txtptr[j].flags) { + textfont = symptr->text[j].font; + if((textfont && textfont[0]) || symptr->text[j].flags) { cairo_font_slant_t slant; cairo_font_weight_t weight; - textfont = (symptr->txtptr[j].font && symptr->txtptr[j].font[0]) ? symptr->txtptr[j].font : cairo_font_name; - weight = ( symptr->txtptr[j].flags & TEXT_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL; + textfont = (symptr->text[j].font && symptr->text[j].font[0]) ? symptr->text[j].font : cairo_font_name; + weight = ( symptr->text[j].flags & TEXT_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL; slant = CAIRO_FONT_SLANT_NORMAL; - if(symptr->txtptr[j].flags & TEXT_ITALIC) slant = CAIRO_FONT_SLANT_ITALIC; - if(symptr->txtptr[j].flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE; + 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(cairo_save_ctx); @@ -614,14 +614,14 @@ void draw_symbol(int what,int c, int n,int layer,int tmp_flip, int rot, dbg(1, "drawing string: str=%s prop=%s\n", txtptr, text.prop_ptr); draw_string(textlayer, what, txtptr, (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); + flip^text.flip, text.hcenter, text.vcenter, + x0+x1, y0+y1, text.xscale, text.yscale); #ifndef HAS_CAIRO drawrect(textlayer, END, 0.0, 0.0, 0.0, 0.0, 0); drawline(textlayer, END, 0.0, 0.0, 0.0, 0.0, 0); #endif #ifdef HAS_CAIRO - if( (textfont && textfont[0]) || symptr->txtptr[j].flags) { + if( (textfont && textfont[0]) || symptr->text[j].flags) { cairo_restore(cairo_ctx); cairo_restore(cairo_save_ctx); } @@ -638,50 +638,50 @@ void draw_temp_symbol(int what, GC gc, int n,int layer,int tmp_flip, int rot, int j; double x0,y0,x1,y1,x2,y2; int flip; - Line line; - xPolygon polygon; - Box box; + xLine line; + xPoly polygon; + xRect box; xArc arc; - Text text; - register Instdef *symptr; /*20150408 */ + xText text; + register xSymbol *symptr; double angle; #ifdef HAS_CAIRO int customfont; #endif - if(inst_ptr[n].ptr == -1) return; + if(xctx.inst[n].ptr == -1) return; if(!has_x) return; - flip = inst_ptr[n].flip; + flip = xctx.inst[n].flip; if(tmp_flip) flip = !flip; - rot = (inst_ptr[n].rot + rot ) & 0x3; + rot = (xctx.inst[n].rot + rot ) & 0x3; - if(layer==0) { /* 20150424 */ - x1=X_TO_SCREEN(inst_ptr[n].x1+xoffset); /* 20150729 added xoffset, yoffset */ - x2=X_TO_SCREEN(inst_ptr[n].x2+xoffset); - y1=Y_TO_SCREEN(inst_ptr[n].y1+yoffset); - y2=Y_TO_SCREEN (inst_ptr[n].y2+yoffset); + if(layer==0) { + x1=X_TO_SCREEN(xctx.inst[n].x1+xoffset); /* 20150729 added xoffset, yoffset */ + x2=X_TO_SCREEN(xctx.inst[n].x2+xoffset); + y1=Y_TO_SCREEN(xctx.inst[n].y1+yoffset); + y2=Y_TO_SCREEN (xctx.inst[n].y2+yoffset); if(OUTSIDE(x1,y1,x2,y2,areax1,areay1,areax2,areay2)) { - inst_ptr[n].flags|=1; + xctx.inst[n].flags|=1; return; } - else inst_ptr[n].flags&=~1; + else xctx.inst[n].flags&=~1; /* following code handles different text color for labels/pins 06112002 */ - } else if(inst_ptr[n].flags&1) { + } else if(xctx.inst[n].flags&1) { dbg(2, "draw_symbol(): skipping inst %d\n", n); return; } /* /20150424 */ - x0=inst_ptr[n].x0 + xoffset; - y0=inst_ptr[n].y0 + yoffset; - symptr = (inst_ptr[n].ptr+instdef); + x0=xctx.inst[n].x0 + xoffset; + y0=xctx.inst[n].y0 + yoffset; + symptr = (xctx.inst[n].ptr+ xctx.sym); for(j=0;j< symptr->lines[layer];j++) { - line = (symptr->lineptr[layer])[j]; + line = (symptr->line[layer])[j]; ROTATION(0.0,0.0,line.x1,line.y1,x1,y1); ROTATION(0.0,0.0,line.x2,line.y2,x2,y2); ORDER(x1,y1,x2,y2); @@ -690,10 +690,10 @@ void draw_temp_symbol(int what, GC gc, int n,int layer,int tmp_flip, int rot, else drawtempline(gc,what, x0+x1, y0+y1, x0+x2, y0+y2); } - for(j=0;j< symptr->polygons[layer];j++) /* 20171115 */ + for(j=0;j< symptr->polygons[layer];j++) { /*fprintf(errfp, "draw_temp_symbol: polygon\n"); */ - polygon = (symptr->polygonptr[layer])[j]; + polygon = (symptr->poly[layer])[j]; { /* scope block so we declare some auxiliary arrays for coord transforms. 20171115 */ int k; @@ -709,10 +709,10 @@ void draw_temp_symbol(int what, GC gc, int n,int layer,int tmp_flip, int rot, my_free(721, &y); } } - + for(j=0;j< symptr->rects[layer];j++) { - box = (symptr->boxptr[layer])[j]; + box = (symptr->rect[layer])[j]; ROTATION(0.0,0.0,box.x1,box.y1,x1,y1); ROTATION(0.0,0.0,box.x2,box.y2,x2,y2); RECTORDER(x1,y1,x2,y2); @@ -720,7 +720,7 @@ void draw_temp_symbol(int what, GC gc, int n,int layer,int tmp_flip, int rot, } for(j=0;j< symptr->arcs[layer];j++) { - arc = (symptr->arcptr[layer])[j]; + arc = (symptr->arc[layer])[j]; if(flip) { angle = 270.*rot+180.-arc.b-arc.a; } else { @@ -737,8 +737,8 @@ void draw_temp_symbol(int what, GC gc, int n,int layer,int tmp_flip, int rot, const char *txtptr; for(j=0;j< symptr->texts;j++) { - text = symptr->txtptr[j]; - if(text.xscale*FONTWIDTH*mooz<1) continue; + text = symptr->text[j]; + if(text.xscale*FONTWIDTH*xctx.mooz<1) continue; txtptr= translate(n, text.txt_ptr); ROTATION(0.0,0.0,text.x0,text.y0,x1,y1); #ifdef HAS_CAIRO @@ -746,7 +746,7 @@ void draw_temp_symbol(int what, GC gc, int n,int layer,int tmp_flip, int rot, #endif if(txtptr[0]) draw_temp_string(gc, what, txtptr, (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); + flip^text.flip, text.hcenter, text.vcenter, x0+x1, y0+y1, text.xscale, text.yscale); #ifdef HAS_CAIRO if(customfont) cairo_restore(cairo_ctx); #endif @@ -761,9 +761,9 @@ void drawgrid() double delta,tmp; int i=0; if( !draw_grid || !has_x) return; - delta=cadgrid*mooz; + delta=cadgrid*xctx.mooz; while(deltaareay1 && y=CADDRAWBUFFERSIZE) { - XDrawArcs(display, window, gc, arc,i); + XDrawArcs(display, window, gc, xarc,i); i=0; } xx1=X_TO_SCREEN(x-r); @@ -1011,12 +1011,12 @@ void drawtemparc(GC gc, int what, double x, double y, double r, double a, double y2=Y_TO_SCREEN(y2); if( rectclip(areax1,areay1,areax2,areay2,&x1,&y1,&x2,&y2) ) { - arc[i].x=(short)xx1; - arc[i].y=(short)yy1; - arc[i].width= (unsigned short)(xx2 - xx1); - arc[i].height=(unsigned short)(yy2 - yy1); - arc[i].angle1 = a*64; - arc[i].angle2 = b*64; + xarc[i].x=(short)xx1; + xarc[i].y=(short)yy1; + xarc[i].width= (unsigned short)(xx2 - xx1); + xarc[i].height=(unsigned short)(yy2 - yy1); + xarc[i].angle1 = a*64; + xarc[i].angle2 = b*64; i++; } } @@ -1039,7 +1039,7 @@ void drawtemparc(GC gc, int what, double x, double y, double r, double a, double else if(what & BEGIN) i=0; else if((what & END) && i) { - XDrawArcs(display, window, gc, arc,i); + XDrawArcs(display, window, gc, xarc,i); i=0; } } @@ -1047,10 +1047,10 @@ void drawtemparc(GC gc, int what, double x, double y, double r, double a, double /* x1,y1: start; x2,y2: end; x3,y3: way point */ void arc_3_points(double x1, double y1, double x2, double y2, double x3, double y3, double *x, double *y, double *r, double *a, double *b) -{ +{ double A, B, C; double c, s; - + /* s = signed_area, if > 0 : clockwise in xorg coordinate space */ s = x3*y2-x2*y3 + x2*y1 -x1*y2 + x1*y3-x3*y1; A = x1*(y2-y3) - y1*(x2-x3) + x2*y3 - x3*y2; @@ -1059,7 +1059,7 @@ void arc_3_points(double x1, double y1, double x2, double y2, double x3, double /* printf("s=%g\n", s); */ *x = -B/2./A; *y = -C/2./A; - *r = sqrt( (*x-x1)*(*x-x1) + (*y-y1)*(*y-y1) ); + *r = sqrt( (*x-x1)*(*x-x1) + (*y-y1)*(*y-y1) ); *a = fmod(atan2(*y-y1 ,x1-*x )*180./XSCH_PI, 360.); if(*a<0.) *a+=360.; *b = fmod(atan2(*y-y2 ,x2-*x )*180./XSCH_PI, 360.); @@ -1082,7 +1082,7 @@ void arc_3_points(double x1, double y1, double x2, double y2, double x3, double void filledarc(int c, int what, double x, double y, double r, double a, double b) { static int i=0; - static XArc arc[CADDRAWBUFFERSIZE]; + static XArc xarc[CADDRAWBUFFERSIZE]; double x1, y1, x2, y2; /* arc bbox */ double xx1, yy1, xx2, yy2; /* complete circle bbox in screen coords */ @@ -1091,8 +1091,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], arc,i); - if(draw_pixmap) XFillArcs(display, save_pixmap, gc[c], arc,i); + if(draw_window) XFillArcs(display, window, gc[c], xarc,i); + if(draw_pixmap) XFillArcs(display, save_pixmap, gc[c], xarc,i); i=0; } xx1=X_TO_SCREEN(x-r); @@ -1106,12 +1106,12 @@ void filledarc(int c, int what, double x, double y, double r, double a, double b y2=Y_TO_SCREEN(y2); if( rectclip(areax1,areay1,areax2,areay2,&x1,&y1,&x2,&y2) ) { - arc[i].x=(short)xx1; - arc[i].y=(short)yy1; - arc[i].width =(unsigned short)(xx2 - xx1); - arc[i].height=(unsigned short)(yy2 - yy1); - arc[i].angle1 = a*64; - arc[i].angle2 = b*64; + xarc[i].x=(short)xx1; + xarc[i].y=(short)yy1; + xarc[i].width =(unsigned short)(xx2 - xx1); + xarc[i].height=(unsigned short)(yy2 - yy1); + xarc[i].angle1 = a*64; + xarc[i].angle2 = b*64; i++; } } @@ -1135,8 +1135,8 @@ void filledarc(int c, int what, double x, double y, double r, double a, double b else if(what & BEGIN) i=0; else if((what & END) && i) { - if(draw_window) XFillArcs(display, window, gc[c], arc,i); - if(draw_pixmap) XFillArcs(display, save_pixmap, gc[c], arc,i); + if(draw_window) XFillArcs(display, window, gc[c], xarc,i); + if(draw_pixmap) XFillArcs(display, save_pixmap, gc[c], xarc,i); i=0; } } @@ -1145,7 +1145,7 @@ void filledarc(int c, int what, double x, double y, double r, double a, double b void drawarc(int c, int what, double x, double y, double r, double a, double b, int arc_fill, int dash) { static int i=0; - static XArc arc[CADDRAWBUFFERSIZE]; + static XArc xarc[CADDRAWBUFFERSIZE]; double x1, y1, x2, y2; /* arc bbox */ double xx1, yy1, xx2, yy2; /* complete circle bbox in screen coords */ @@ -1156,8 +1156,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], arc,i); - if(draw_pixmap) XDrawArcs(display, save_pixmap, gc[c], arc,i); + if(draw_window) XDrawArcs(display, window, gc[c], xarc,i); + if(draw_pixmap) XDrawArcs(display, save_pixmap, gc[c], xarc,i); i=0; } xx1=X_TO_SCREEN(x-r); @@ -1171,12 +1171,12 @@ void drawarc(int c, int what, double x, double y, double r, double a, double b, y2=Y_TO_SCREEN(y2); if( rectclip(areax1,areay1,areax2,areay2,&x1,&y1,&x2,&y2) ) { - arc[i].x=(short)xx1; - arc[i].y=(short)yy1; - arc[i].width =(unsigned short)(xx2 - xx1); - arc[i].height=(unsigned short)(yy2 - yy1); - arc[i].angle1 = a*64; - arc[i].angle2 = b*64; + xarc[i].x=(short)xx1; + xarc[i].y=(short)yy1; + xarc[i].width =(unsigned short)(xx2 - xx1); + xarc[i].height=(unsigned short)(yy2 - yy1); + xarc[i].angle1 = a*64; + xarc[i].angle2 = b*64; i++; } } @@ -1212,7 +1212,7 @@ void drawarc(int c, int what, double x, double y, double r, double a, double b, if(fill && fill_type[c]){ if(arc_fill) { - if(draw_window) + if(draw_window) XFillArc(display, 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); @@ -1226,8 +1226,8 @@ void drawarc(int c, int what, double x, double y, double r, double a, double b, else if(what & BEGIN) i=0; else if((what & END) && i) { - if(draw_window) XDrawArcs(display, window, gc[c], arc,i); - if(draw_pixmap) XDrawArcs(display, save_pixmap, gc[c], arc,i); + if(draw_window) XDrawArcs(display, window, gc[c], xarc,i); + if(draw_pixmap) XDrawArcs(display, save_pixmap, gc[c], xarc,i); i=0; } } @@ -1247,14 +1247,14 @@ void filledrect(int c, int what, double rectx1,double recty1,double rectx2,doubl y1=Y_TO_SCREEN(recty1); x2=X_TO_SCREEN(rectx2); y2=Y_TO_SCREEN(recty2); - if(!only_probes && (x2-x1)< 2 && (y2-y1)< 2) return; /* 20171206 */ + if(!only_probes && (x2-x1)< 2 && (y2-y1)< 2) return; if( rectclip(areax1,areay1,areax2,areay2,&x1,&y1,&x2,&y2) ) { - if(draw_window) XFillRectangle(display, window, gcstipple[c], (int)x1, (int)y1, + if(draw_window) XFillRectangle(display, 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, save_pixmap,gcstipple[c], (int)x1, (int)y1, (unsigned int)x2 - (unsigned int)x1, (unsigned int)y2 - (unsigned int)y1); } @@ -1273,10 +1273,10 @@ void filledrect(int c, int what, double rectx1,double recty1,double rectx2,doubl y1=Y_TO_SCREEN(recty1); x2=X_TO_SCREEN(rectx2); y2=Y_TO_SCREEN(recty2); - if(!only_probes && (x2-x1)< 2 && (y2-y1)< 2) return; /* 20171206 */ + if(!only_probes && (x2-x1)< 2 && (y2-y1)< 2) return; if( rectclip(areax1,areay1,areax2,areay2,&x1,&y1,&x2,&y2) ) { - r[i].x=(short)x1; + r[i].x=(short)x1; r[i].y=(short)y1; r[i].width=(unsigned short)x2-r[i].x; r[i].height=(unsigned short)y2-r[i].y; @@ -1303,7 +1303,7 @@ void polygon_bbox(double *x, double *y, int points, double *bx1, double *by1, do } -void arc_bbox(double x, double y, double r, double a, double b, +void arc_bbox(double x, double y, double r, double a, double b, double *bx1, double *by1, double *bx2, double *by2) { double x2, y2, x3, y3; @@ -1321,7 +1321,7 @@ void arc_bbox(double x, double y, double r, double a, double b, aa = (int)(ceil(a/90.))*90; bb = (int)(floor((a+b)/90.))*90; - + /* printf("arc_bbox(): aa=%d bb=%d\n", aa, bb); */ x2 = x + r * cos(a * XSCH_PI/180.); y2 = y - r * sin(a * XSCH_PI/180.); @@ -1376,7 +1376,7 @@ void drawpolygon(int c, int what, double *x, double *y, int points, int poly_fil if( !rectclip(areax1,areay1,areax2,areay2,&x1,&y1,&x2,&y2) ) { return; } - if( !only_probes && (x2-x1)<0.3 && (y2-y1)<0.3) return; /* 20171206 */ + if( !only_probes && (x2-x1)<0.3 && (y2-y1)<0.3) return; p = my_malloc(38, sizeof(XPoint) * points); for(i=0;i 2000 || lastinst > 2000 ) && (x2 - x1 < ITERATOR_THRESHOLD); - + use_hash = (xctx.wires> 2000 || xctx.instances > 2000 ) && (x2 - x1 < ITERATOR_THRESHOLD); + if(use_hash) { hash_instances(); hash_wires(); } - if(!only_probes) { /* 20110112 */ + if(!only_probes) { dbg(3, "draw(): check4\n"); for(c=0;cbus) drawline(c, THICK, l->x1, l->y1, l->x2, l->y2, l->dash); else drawline(c, ADD, l->x1, l->y1, l->x2, l->y2, l->dash); } - if(enable_layer[c]) for(i=0;ix1, r->y1, r->x2, r->y2, r->dash); filledrect(c, ADD, r->x1, r->y1, r->x2, r->y2); } - if(enable_layer[c]) for(i=0;ix, a->y, a->r, a->a, a->b, a->fill, a->dash); } - if(enable_layer[c]) for(i=0;ix, p->y, p->points, p->fill, p->dash); } if(use_hash) { - + /* --------------------------------- inst_ptr iterator 20171224 */ /*loop thru all squares that intersect drawing area */ for(init_inst_iterator(x1, y1, x2, y2); ( instanceptr = inst_iterator_next() ) ;) { int ptr; i = instanceptr->n; - ptr = inst_ptr[i].ptr; - if( ptr !=-1) { /* 20180921 */ - symptr = ptr+instdef; + ptr = xctx.inst[i].ptr; + if( ptr !=-1) { + symptr = ptr+xctx.sym; if( c==0 || /*20150408 draw_symbol call is needed on layer 0 to avoid redundant work (outside check) */ - symptr->lines[c] || /* 20150408 */ + symptr->lines[c] || symptr->arcs[c] || - symptr->rects[c] || /* 20150408 */ - symptr->polygons[c] || /* 20150408 */ - ((c==TEXTWIRELAYER || c==TEXTLAYER) && symptr->texts)) { /* 20150408 */ - + symptr->rects[c] || + symptr->polygons[c] || + ((c==TEXTWIRELAYER || c==TEXTLAYER) && symptr->texts)) { + type = symptr->type; if(!( hilight_nets && type && ( ( - IS_LABEL_SH_OR_PIN(type) && inst_ptr[i].node && inst_ptr[i].node[0] && - bus_hilight_lookup(inst_ptr[i].node[0], 0, XLOOKUP ) + IS_LABEL_SH_OR_PIN(type) && xctx.inst[i].node && xctx.inst[i].node[0] && + bus_hilight_lookup(xctx.inst[i].node[0], 0, XLOOKUP ) ) || ( - !IS_LABEL_SH_OR_PIN(type) && (inst_ptr[i].flags & 4) + !IS_LABEL_SH_OR_PIN(type) && (xctx.inst[i].flags & 4) ) ) ) ) { draw_symbol(ADD, c, instanceptr->n,c,0,0,0.0,0.0); } - } /* 20150408 */ + } } /*if( ptr !=-1) */ } /* --------------------------------- /20171224 */ } else { - for(i=0;ilines[c] || /* 20150408 */ + symptr->lines[c] || symptr->arcs[c] || - symptr->rects[c] || /* 20150408 */ - symptr->polygons[c] || /* 20150408 */ - ((c==TEXTWIRELAYER || c==TEXTLAYER) && symptr->texts)) { /* 20150408 */ - - - type = (inst_ptr[i].ptr+instdef)->type; + symptr->rects[c] || + symptr->polygons[c] || + ((c==TEXTWIRELAYER || c==TEXTLAYER) && symptr->texts)) { + + + type = (xctx.inst[i].ptr+ xctx.sym)->type; if(!( hilight_nets && type && ( ( - IS_LABEL_SH_OR_PIN(type) && inst_ptr[i].node && inst_ptr[i].node[0] && - bus_hilight_lookup(inst_ptr[i].node[0], 0, XLOOKUP ) + IS_LABEL_SH_OR_PIN(type) && xctx.inst[i].node && xctx.inst[i].node[0] && + bus_hilight_lookup(xctx.inst[i].node[0], 0, XLOOKUP ) ) || ( - !IS_LABEL_SH_OR_PIN(type) && (inst_ptr[i].flags & 4) + !IS_LABEL_SH_OR_PIN(type) && (xctx.inst[i].flags & 4) ) ) ) ) { draw_symbol(ADD, c, i,c,0,0,0.0,0.0); } - } /* 20150408 */ + } } } - + filledrect(c, END, 0.0, 0.0, 0.0, 0.0); drawarc(c, END, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0); drawrect(c, END, 0.0, 0.0, 0.0, 0.0, 0); drawline(c, END, 0.0, 0.0, 0.0, 0.0, 0); } - if(draw_single_layer==-1 || draw_single_layer==WIRELAYER){ /* 20151117 */ + if(draw_single_layer==-1 || draw_single_layer==WIRELAYER){ if(use_hash) { dbg(3, "using spatial hash table iterator\n"); /*loop thru all squares that intersect drawing area */ - + for(init_wire_iterator(x1, y1, x2, y2); ( wireptr = wire_iterator_next() ) ;) { ii=wireptr->n; - if(wire[ii].bus) { - drawline(WIRELAYER, THICK, wire[ii].x1,wire[ii].y1,wire[ii].x2,wire[ii].y2, 0); + if(xctx.wire[ii].bus) { + drawline(WIRELAYER, THICK, xctx.wire[ii].x1,xctx.wire[ii].y1,xctx.wire[ii].x2,xctx.wire[ii].y2, 0); } else - drawline(WIRELAYER, ADD, wire[ii].x1,wire[ii].y1,wire[ii].x2,wire[ii].y2, 0); + drawline(WIRELAYER, ADD, xctx.wire[ii].x1,xctx.wire[ii].y1,xctx.wire[ii].x2,xctx.wire[ii].y2, 0); } } else { - for(i=0;i= cadlayers) textlayer = TEXTLAYER; - dbg(1, "draw(): drawing string %d = %s\n",i, textelement[i].txt_ptr); + dbg(1, "draw(): drawing string %d = %s\n",i, xctx.text[i].txt_ptr); #ifdef HAS_CAIRO if(!enable_layer[textlayer]) continue; - textfont = textelement[i].font; /* 20171206 */ - if( (textfont && textfont[0]) || textelement[i].flags) { + textfont = xctx.text[i].font; + if( (textfont && textfont[0]) || xctx.text[i].flags) { cairo_font_slant_t slant; cairo_font_weight_t weight; - textfont = (textelement[i].font && textelement[i].font[0]) ? textelement[i].font : cairo_font_name; - weight = ( textelement[i].flags & TEXT_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL; + textfont = (xctx.text[i].font && xctx.text[i].font[0]) ? xctx.text[i].font : cairo_font_name; + weight = ( xctx.text[i].flags & TEXT_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL; slant = CAIRO_FONT_SLANT_NORMAL; - if(textelement[i].flags & TEXT_ITALIC) slant = CAIRO_FONT_SLANT_ITALIC; - if(textelement[i].flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE; + 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(cairo_save_ctx); @@ -1740,12 +1740,12 @@ void draw(void) } #endif - draw_string(textlayer, ADD, textelement[i].txt_ptr, - textelement[i].rot, textelement[i].flip, textelement[i].hcenter, textelement[i].vcenter, - textelement[i].x0,textelement[i].y0, - textelement[i].xscale, textelement[i].yscale); + draw_string(textlayer, 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((textfont && textfont[0]) || textelement[i].flags ) { + if((textfont && textfont[0]) || xctx.text[i].flags ) { cairo_restore(cairo_ctx); cairo_restore(cairo_save_ctx); } @@ -1759,8 +1759,8 @@ 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, - xrect[0].width, xrect[0].height, xrect[0].x, xrect[0].y); /* 20181009 */ + XCopyArea(display, save_pixmap, 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 */ diff --git a/src/editprop.c b/src/editprop.c index 570a4740..ee820feb 100644 --- a/src/editprop.c +++ b/src/editprop.c @@ -1,7 +1,7 @@ /* File: editprop.c - * + * * This file is part of XSCHEM, - * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit + * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit * simulation. * Copyright (C) 1998-2020 Stefan Frederik Schippers * @@ -23,7 +23,7 @@ #include #include "xschem.h" -static int rot = 0, flip = 0; +static int rot = 0, flip = 0; char *my_strtok_r(char *str, const char *delim, char **saveptr) { @@ -60,7 +60,7 @@ size_t my_strdup(int id, char **dest, const char *src) /* empty source string -- my_free(1146, dest); dbg(3,"my_strdup(%d,): freed destination ptr\n", id); } - + return 0; } @@ -99,7 +99,7 @@ void dbg(int level, char *fmt, ...) } #ifdef HAS_SNPRINTF -int my_snprintf(char *str, int size, const char *fmt, ...) /* 20161124 */ +int my_snprintf(char *str, int size, const char *fmt, ...) { int size_of_print; char s[200]; @@ -216,7 +216,7 @@ int my_snprintf(char *string, int size, const char *format, ...) } else { dbg(1, "my_snprintf(): overflow, target size=%d, format=%s\n", size, format); } - + va_end(args); /* fprintf(errfp, "my_snprintf(): returning: |%s|\n", string); */ return n; @@ -249,14 +249,14 @@ size_t my_strcat(int id, char **str, const char *append_str) if(append_str == NULL || append_str[0]=='\0') return s; a = strlen(append_str) + 1; my_realloc(id, str, s + a ); - memcpy(*str + s, append_str, a); /* 20180923 */ + memcpy(*str + s, append_str, a); dbg(3,"my_strcat(%d,): reallocated string %s\n", id, *str); return s + a - 1; } else { if(append_str == NULL || append_str[0] == '\0') return 0; a = strlen(append_str) + 1; *str = my_malloc(id, a); - memcpy(*str, append_str, a); /* 20180923 */ + memcpy(*str, append_str, a); dbg(3,"my_strcat(%d,): allocated string %s\n", id, *str); return a - 1; } @@ -273,7 +273,7 @@ size_t my_strncat(int id, char **str, size_t n, const char *append_str) s = strlen(*str); if(append_str == NULL || append_str[0]=='\0') return s; my_realloc(id, str, s + a ); - memcpy(*str+s, append_str, a); /* 20180923 */ + memcpy(*str+s, append_str, a); *(*str+s+a) = '\0'; dbg(3,"my_strncat(%d,): reallocated string %s\n", id, *str); return s + a -1; @@ -282,7 +282,7 @@ size_t my_strncat(int id, char **str, size_t n, const char *append_str) { if(append_str == NULL || append_str[0]=='\0') return 0; *str = my_malloc(id, a ); - memcpy(*str, append_str, a); /* 20180923 */ + memcpy(*str, append_str, a); *(*str+a) = '\0'; dbg(3,"my_strncat(%d,): allocated string %s\n", id, *str); return a -1; @@ -303,7 +303,7 @@ void *my_calloc(int id, size_t nmemb, size_t size) return ptr; } -void *my_malloc(int id, size_t size) +void *my_malloc(int id, size_t size) { void *ptr; if(size>0) { @@ -331,7 +331,7 @@ void my_realloc(int id, void *ptr,size_t size) id, a, *(void **)ptr,(unsigned long) size); } -} +} void my_free(int id, void *ptr) { @@ -355,10 +355,10 @@ int my_strncpy(char *d, const char *s, int n) dbg(3, "my_strncpy(): copying %s to %lu\n", s, (unsigned long)d); while( (d[i] = s[i]) ) { - if(i == n) { + if(i == n) { if(s[i] != '\0') dbg(1, "my_strncpy(): overflow, n=%d, s=%s\n", n+1, s); d[i] = '\0'; - return i; + return i; } i++; } @@ -382,29 +382,29 @@ void set_inst_prop(int i) char *ptr; char *tmp = NULL; - ptr = (inst_ptr[i].ptr+instdef)->templ; /*20150409 */ - dbg(1, "set_inst_prop(): i=%d, name=%s, prop_ptr = %s, template=%s\n", - i, inst_ptr[i].name, inst_ptr[i].prop_ptr, ptr); - my_strdup(69, &inst_ptr[i].prop_ptr, ptr); - my_strdup2(70, &inst_ptr[i].instname, get_tok_value(ptr, "name",0)); /* 20150409 */ - if(inst_ptr[i].instname[0]) { - my_strdup(101, &tmp, inst_ptr[i].prop_ptr); + ptr = (xctx.inst[i].ptr+ xctx.sym)->templ; + dbg(1, "set_inst_prop(): i=%d, name=%s, prop_ptr = %s, template=%s\n", + i, xctx.inst[i].name, xctx.inst[i].prop_ptr, ptr); + my_strdup(69, &xctx.inst[i].prop_ptr, ptr); + my_strdup2(70, &xctx.inst[i].instname, get_tok_value(ptr, "name",0)); + if(xctx.inst[i].instname[0]) { + my_strdup(101, &tmp, xctx.inst[i].prop_ptr); new_prop_string(i, tmp, 0, dis_uniq_names); my_free(724, &tmp); } } -void edit_rect_property(void) +void edit_rect_property(void) { int i, c, n, old_dash; int drw = 0; const char *dash; int preserve; char *oldprop=NULL; - if(rect[selectedgroup[0].col][selectedgroup[0].n].prop_ptr!=NULL) { - my_strdup(67, &oldprop, rect[selectedgroup[0].col][selectedgroup[0].n].prop_ptr); + if(xctx.rect[selectedgroup[0].col][selectedgroup[0].n].prop_ptr!=NULL) { + my_strdup(67, &oldprop, xctx.rect[selectedgroup[0].col][selectedgroup[0].n].prop_ptr); tclsetvar("retval",oldprop); - } else { /* 20161208 */ + } else { tclsetvar("retval",""); } @@ -419,28 +419,28 @@ void edit_rect_property(void) c = selectedgroup[i].col; n = selectedgroup[i].n; if(preserve == 1) { - set_different_token(&rect[c][n].prop_ptr, + set_different_token(&xctx.rect[c][n].prop_ptr, (char *) tclgetvar("retval"), oldprop, 0, 0); } else { - my_strdup(99, &rect[c][n].prop_ptr, + my_strdup(99, &xctx.rect[c][n].prop_ptr, (char *) tclgetvar("retval")); } - old_dash = rect[c][n].dash; - dash = get_tok_value(rect[c][n].prop_ptr,"dash",0); + old_dash = xctx.rect[c][n].dash; + dash = get_tok_value(xctx.rect[c][n].prop_ptr,"dash",0); if( strcmp(dash, "") ) { int d = atoi(dash); - rect[c][n].dash = d >= 0? d : 0; + xctx.rect[c][n].dash = d >= 0? d : 0; } else - rect[c][n].dash = 0; - if(old_dash != rect[c][n].dash) { + xctx.rect[c][n].dash = 0; + if(old_dash != xctx.rect[c][n].dash) { if(!drw) { bbox(BEGIN,0.0,0.0,0.0,0.0); drw = 1; } - bbox(ADD, rect[c][n].x1, rect[c][n].y1, rect[c][n].x2, rect[c][n].y2); + bbox(ADD, xctx.rect[c][n].x1, xctx.rect[c][n].y1, xctx.rect[c][n].x2, xctx.rect[c][n].y2); } } - if(drw) { + if(drw) { bbox(SET , 0.0 , 0.0 , 0.0 , 0.0); draw(); bbox(END , 0.0 , 0.0 , 0.0 , 0.0); @@ -456,10 +456,10 @@ void edit_line_property(void) const char *dash; int preserve; char *oldprop=NULL; - if(line[selectedgroup[0].col][selectedgroup[0].n].prop_ptr!=NULL) { - my_strdup(46, &oldprop, line[selectedgroup[0].col][selectedgroup[0].n].prop_ptr); + if(xctx.line[selectedgroup[0].col][selectedgroup[0].n].prop_ptr!=NULL) { + my_strdup(46, &oldprop, xctx.line[selectedgroup[0].col][selectedgroup[0].n].prop_ptr); tclsetvar("retval", oldprop); - } else { /* 20161208 */ + } else { tclsetvar("retval",""); } tcleval("text_line {Input property:} 0 normal"); @@ -475,22 +475,25 @@ void edit_line_property(void) c = selectedgroup[i].col; n = selectedgroup[i].n; if(preserve == 1) { - set_different_token(&line[c][n].prop_ptr, + set_different_token(&xctx.line[c][n].prop_ptr, (char *) tclgetvar("retval"), oldprop, 0, 0); } else { - my_strdup(102, &line[c][n].prop_ptr, + my_strdup(102, &xctx.line[c][n].prop_ptr, (char *) tclgetvar("retval")); } - line[c][n].bus = !strcmp(get_tok_value(line[c][n].prop_ptr,"bus",0), "true"); - dash = get_tok_value(line[c][n].prop_ptr,"dash",0); + xctx.line[c][n].bus = !strcmp(get_tok_value(xctx.line[c][n].prop_ptr,"bus",0), "true"); + dash = get_tok_value(xctx.line[c][n].prop_ptr,"dash",0); if( strcmp(dash, "") ) { int d = atoi(dash); - line[c][n].dash = d >= 0? d : 0; + xctx.line[c][n].dash = d >= 0? d : 0; } else - line[c][n].dash = 0; - if(line[c][n].y1 < line[c][n].y2) { y1 = line[c][n].y1-bus_width; y2 = line[c][n].y2+bus_width; } - else { y1 = line[c][n].y1+bus_width; y2 = line[c][n].y2-bus_width; } - bbox(ADD, line[c][n].x1-bus_width, y1 , line[c][n].x2+bus_width , y2 ); + xctx.line[c][n].dash = 0; + if(xctx.line[c][n].y1 < xctx.line[c][n].y2) { + y1 = xctx.line[c][n].y1-bus_width; y2 = xctx.line[c][n].y2+bus_width; + } else { + y1 = xctx.line[c][n].y1+bus_width; y2 = xctx.line[c][n].y2-bus_width; + } + bbox(ADD, xctx.line[c][n].x1-bus_width, y1 , xctx.line[c][n].x2+bus_width , y2 ); } bbox(SET , 0.0 , 0.0 , 0.0 , 0.0); draw(); @@ -507,50 +510,50 @@ void edit_wire_property(void) char *oldprop=NULL; const char *bus_ptr; - if(wire[selectedgroup[0].n].prop_ptr!=NULL) { - my_strdup(47, &oldprop, wire[selectedgroup[0].n].prop_ptr); + if(xctx.wire[selectedgroup[0].n].prop_ptr!=NULL) { + my_strdup(47, &oldprop, xctx.wire[selectedgroup[0].n].prop_ptr); tclsetvar("retval", oldprop); - } else { /* 20161208 */ + } else { tclsetvar("retval",""); } tcleval("text_line {Input property:} 0 normal"); preserve = atoi(tclgetvar("preserve_unchanged_attrs")); if(strcmp(tclgetvar("rcode"),"") ) { - push_undo(); /* 20150327 */ - set_modify(1); + push_undo(); + set_modify(1); bbox(BEGIN, 0.0 , 0.0 , 0.0 , 0.0); for(i=0; i cadhalfdotsize ? bus_width : CADHALFDOTSIZE; - if(wire[k].y1 < wire[k].y2) { y1 = wire[k].y1-ov; y2 = wire[k].y2+ov; } - else { y1 = wire[k].y1+ov; y2 = wire[k].y2-ov; } - bbox(ADD, wire[k].x1-ov, y1 , wire[k].x2+ov , y2 ); - wire[k].bus=1; + if(xctx.wire[k].y1 < xctx.wire[k].y2) { y1 = xctx.wire[k].y1-ov; y2 = xctx.wire[k].y2+ov; } + else { y1 = xctx.wire[k].y1+ov; y2 = xctx.wire[k].y2-ov; } + bbox(ADD, xctx.wire[k].x1-ov, y1 , xctx.wire[k].x2+ov , y2 ); + xctx.wire[k].bus=1; } else { - if(oldbus){ /* 20171201 */ + if(oldbus){ int ov, y1, y2; ov = bus_width> cadhalfdotsize ? bus_width : CADHALFDOTSIZE; - if(wire[k].y1 < wire[k].y2) { y1 = wire[k].y1-ov; y2 = wire[k].y2+ov; } - else { y1 = wire[k].y1+ov; y2 = wire[k].y2-ov; } - bbox(ADD, wire[k].x1-ov, y1 , wire[k].x2+ov , y2 ); - wire[k].bus=0; + if(xctx.wire[k].y1 < xctx.wire[k].y2) { y1 = xctx.wire[k].y1-ov; y2 = xctx.wire[k].y2+ov; } + else { y1 = xctx.wire[k].y1+ov; y2 = xctx.wire[k].y2-ov; } + bbox(ADD, xctx.wire[k].x1-ov, y1 , xctx.wire[k].x2+ov , y2 ); + xctx.wire[k].bus=0; } } } @@ -563,17 +566,17 @@ void edit_wire_property(void) void edit_arc_property(void) { - int old_fill; /* 20180914 */ + int old_fill; double x1, y1, x2, y2; int c, i, ii, old_dash, drw = 0; char *oldprop = NULL; const char *dash; int preserve; - if(arc[selectedgroup[0].col][selectedgroup[0].n].prop_ptr!=NULL) { - my_strdup(98, &oldprop, arc[selectedgroup[0].col][selectedgroup[0].n].prop_ptr); + if(xctx.arc[selectedgroup[0].col][selectedgroup[0].n].prop_ptr!=NULL) { + my_strdup(98, &oldprop, xctx.arc[selectedgroup[0].col][selectedgroup[0].n].prop_ptr); tclsetvar("retval", oldprop); - } else { /* 20161208 */ + } else { tclsetvar("retval",""); } tcleval("text_line {Input property:} 0 normal"); @@ -581,39 +584,39 @@ void edit_arc_property(void) if(strcmp(tclgetvar("rcode"),"") ) { - set_modify(1); push_undo(); /* 20150327 */ + set_modify(1); push_undo(); for(ii=0; ii= 0 ? d : 0; + xctx.arc[c][i].dash = d >= 0 ? d : 0; } else - arc[c][i].dash = 0; - + xctx.arc[c][i].dash = 0; - if(old_fill != arc[c][i].fill || old_dash != arc[c][i].dash) { + + if(old_fill != xctx.arc[c][i].fill || old_dash != xctx.arc[c][i].dash) { if(!drw) { bbox(BEGIN,0.0,0.0,0.0,0.0); drw = 1; } - arc_bbox(arc[c][i].x, arc[c][i].y, arc[c][i].r, 0, 360, &x1,&y1,&x2,&y2); + arc_bbox(xctx.arc[c][i].x, xctx.arc[c][i].y, xctx.arc[c][i].r, 0, 360, &x1,&y1,&x2,&y2); bbox(ADD, x1, y1, x2, y2); } } @@ -627,7 +630,7 @@ void edit_arc_property(void) void edit_polygon_property(void) { - int old_fill; /* 20180914 */ + int old_fill; int k; double x1=0., y1=0., x2=0., y2=0.; int c, i, ii, old_dash; @@ -637,10 +640,10 @@ void edit_polygon_property(void) int preserve; dbg(1, "edit_property(): input property:\n"); - if(polygon[selectedgroup[0].col][selectedgroup[0].n].prop_ptr!=NULL) { - my_strdup(112, &oldprop, polygon[selectedgroup[0].col][selectedgroup[0].n].prop_ptr); + if(xctx.poly[selectedgroup[0].col][selectedgroup[0].n].prop_ptr!=NULL) { + my_strdup(112, &oldprop, xctx.poly[selectedgroup[0].col][selectedgroup[0].n].prop_ptr); tclsetvar("retval", oldprop); - } else { /* 20161208 */ + } else { tclsetvar("retval",""); } tcleval("text_line {Input property:} 0 normal"); @@ -648,41 +651,41 @@ void edit_polygon_property(void) if(strcmp(tclgetvar("rcode"),"") ) { - set_modify(1); push_undo(); /* 20150327 */ + set_modify(1); push_undo(); for(ii=0; ii= 0 ? d : 0; - } else - polygon[c][i].dash = 0; - if(old_fill != polygon[c][i].fill || old_dash != polygon[c][i].dash) { + xctx.poly[c][i].dash = d >= 0 ? d : 0; + } else + xctx.poly[c][i].dash = 0; + if(old_fill != xctx.poly[c][i].fill || old_dash != xctx.poly[c][i].dash) { if(!drw) { bbox(BEGIN,0.0,0.0,0.0,0.0); drw = 1; } - for(k=0; k x2) x2 = polygon[c][i].x[k]; - if(k==0 || polygon[c][i].y[k] > y2) y2 = polygon[c][i].y[k]; + for(k=0; k x2) x2 = xctx.poly[c][i].x[k]; + if(k==0 || xctx.poly[c][i].y[k] > y2) y2 = xctx.poly[c][i].y[k]; } bbox(ADD, x1, y1, x2, y2); } @@ -702,7 +705,7 @@ void edit_text_property(int x) #ifdef HAS_CAIRO int customfont; #endif - int sel, k, text_changed; + int sel, k, text_changed; int c,l, preserve; double xx1,yy1,xx2,yy2; double pcx,pcy; /* pin center 20070317 */ @@ -712,28 +715,28 @@ void edit_text_property(int x) dbg(1, "edit_text_property(): entering\n"); sel = selectedgroup[0].n; - my_strdup(656, &oldprop, textelement[sel].prop_ptr); - if(textelement[sel].prop_ptr !=NULL) - tclsetvar("props",textelement[sel].prop_ptr); + my_strdup(656, &oldprop, xctx.text[sel].prop_ptr); + if(xctx.text[sel].prop_ptr !=NULL) + tclsetvar("props",xctx.text[sel].prop_ptr); else - tclsetvar("props",""); /* 20171112 */ + tclsetvar("props",""); - tclsetvar("retval",textelement[sel].txt_ptr); - my_snprintf(property, S(property), "%.16g",textelement[sel].yscale); + tclsetvar("retval",xctx.text[sel].txt_ptr); + my_snprintf(property, S(property), "%.16g",xctx.text[sel].yscale); tclsetvar("vsize",property); - my_snprintf(property, S(property), "%.16g",textelement[sel].xscale); + my_snprintf(property, S(property), "%.16g",xctx.text[sel].xscale); tclsetvar("hsize",property); if(x==0) tcleval("enter_text {text:} normal"); else if(x==2) tcleval("viewdata $::retval"); - else if(x==1) tcleval("edit_vi_prop {Text:}"); + else if(x==1) tcleval("edit_vi_prop {xText:}"); else { fprintf(errfp, "edit_text_property() : unknown parameter x=%d\n",x); exit(EXIT_FAILURE); } preserve = atoi(tclgetvar("preserve_unchanged_attrs")); - + text_changed=0; if(x == 0 || x == 1) { - if( strcmp(textelement[sel].txt_ptr, tclgetvar("retval") ) ) { + if( strcmp(xctx.text[sel].txt_ptr, tclgetvar("retval") ) ) { dbg(1, "edit_text_property(): x=%d, text_changed=1\n", x); text_changed=1; } else { @@ -744,113 +747,113 @@ void edit_text_property(int x) if(strcmp(tclgetvar("rcode"),"") ) { dbg(1, "edit_text_property(): rcode !=\"\"\n"); - set_modify(1); push_undo(); /* 20150327 */ + set_modify(1); push_undo(); bbox(BEGIN,0.0,0.0,0.0,0.0); for(k=0;ktype!=NULL) - netlist_commands = !strcmp( (inst_ptr[i].ptr+instdef)->type, "netlist_commands"); + if ((xctx.inst[i].ptr + xctx.sym)->type!=NULL) + netlist_commands = !strcmp( (xctx.inst[i].ptr+ xctx.sym)->type, "netlist_commands"); - if(inst_ptr[i].prop_ptr!=NULL) { + if(xctx.inst[i].prop_ptr!=NULL) { if(netlist_commands && x==1) { - tclsetvar("retval",get_tok_value( inst_ptr[i].prop_ptr,"value",0)); + tclsetvar("retval",get_tok_value( xctx.inst[i].prop_ptr,"value",0)); } else { - tclsetvar("retval",inst_ptr[i].prop_ptr); + tclsetvar("retval",xctx.inst[i].prop_ptr); } } else { tclsetvar("retval",""); } - my_strdup(91, &old_prop, inst_ptr[i].prop_ptr); - tclsetvar("symbol",inst_ptr[i].name); + my_strdup(91, &old_prop, xctx.inst[i].prop_ptr); + tclsetvar("symbol",xctx.inst[i].name); if(x==0) { tcleval("edit_prop {Input property:}"); @@ -903,7 +906,7 @@ void edit_symbol_property(int x) update_symbol(result, x); my_free(728, &result); dbg(1, "edit_symbol_property(): done update_symbol, modified=%d\n", modified); - i=-1; /* 20160423 */ + i=-1; } /* x=0 use text widget x=1 use vim editor */ @@ -912,17 +915,17 @@ void update_symbol(const char *result, int x) int k, sym_number; int no_change_props=0; int only_different=0; - int copy_cell=0; /* 20150911 */ + int copy_cell=0; int prefix=0; char *name = NULL, *ptr = NULL, *new_prop = NULL; char symbol[PATH_MAX]; char *type; const char *new_name; int cond, allow_change_name; - int pushed=0; /* 20150327 */ + int pushed=0; dbg(1, "update_symbol(): entering\n"); - i=selectedgroup[0].n; /* 20110413 */ + i=selectedgroup[0].n; if(!result) { dbg(1, "update_symbol(): edit symbol prop aborted\n"); return; @@ -945,20 +948,20 @@ void update_symbol(const char *result, int x) dbg(1, "update_symbol(): symbol=%s\n", symbol); no_change_props=atoi(tclgetvar("no_change_attrs") ); only_different=atoi(tclgetvar("preserve_unchanged_attrs") ); - copy_cell=atoi(tclgetvar("user_wants_copy_cell") ); /* 20150911 */ + copy_cell=atoi(tclgetvar("user_wants_copy_cell") ); bbox(BEGIN,0.0,0.0,0.0,0.0); if(show_pin_net_names) { prepare_netlist_structs(0); - for(k = 0; k < (inst_ptr[i].ptr + instdef)->rects[PINLAYER]; k++) { - if( inst_ptr[i].node && inst_ptr[i].node[k]) { - find_inst_to_be_redrawn(inst_ptr[i].node[k]); + for(k = 0; k < (xctx.inst[i].ptr + xctx.sym)->rects[PINLAYER]; k++) { + if( xctx.inst[i].node && xctx.inst[i].node[k]) { + find_inst_to_be_redrawn(xctx.inst[i].node[k]); } } find_inst_hash_clear(); } - /* 20191227 necessary? --> Yes since a symbol copy has already been done + /* 20191227 necessary? --> Yes since a symbol copy has already been done in edit_symbol_property() -> tcl edit_prop, this ensures new symbol is loaded from disk. if for some reason a symbol with matching name is loaded in xschem this may be out of sync wrt disk version */ @@ -966,26 +969,26 @@ void update_symbol(const char *result, int x) remove_symbols(); link_symbols_to_instances(); } - + /* symbol reference changed? --> sym_number >=0, set prefix to 1st char to use for inst name (from symbol template) */ prefix=0; sym_number = -1; - if(strcmp(symbol, inst_ptr[i].name)) { + if(strcmp(symbol, xctx.inst[i].name)) { set_modify(1); prepared_hash_instances=0; prepared_netlist_structs=0; prepared_hilight_structs=0; sym_number=match_symbol(symbol); /* check if exist */ if(sym_number>=0) { - prefix=(get_tok_value((instdef+sym_number)->templ, "name",0))[0]; /* get new symbol prefix */ + prefix=(get_tok_value((xctx.sym+sym_number)->templ, "name",0))[0]; /* get new symbol prefix */ } } /* instance name prefix (1st char) changed? --> allow_change_name=1 */ allow_change_name = 0; if(new_prop) { - my_strdup(88, &name, get_tok_value(inst_ptr[i].prop_ptr, "name", 0)); + my_strdup(88, &name, get_tok_value(xctx.inst[i].prop_ptr, "name", 0)); new_name = get_tok_value(new_prop, "name", 0); if(!name || new_name[0] != name[0]) allow_change_name = 1; } @@ -993,99 +996,99 @@ void update_symbol(const char *result, int x) dbg(1, "update_symbol(): for k loop: k=%d\n", k); if(selectedgroup[k].type!=ELEMENT) continue; i=selectedgroup[k].n; - + /* 20171220 calculate bbox before changes to correctly redraw areas */ /* must be recalculated as cairo text extents vary with zoom factor. */ - symbol_bbox(i, &inst_ptr[i].x1, &inst_ptr[i].y1, &inst_ptr[i].x2, &inst_ptr[i].y2); - + symbol_bbox(i, &xctx.inst[i].x1, &xctx.inst[i].y1, &xctx.inst[i].x2, &xctx.inst[i].y2); + if(sym_number>=0) /* changing symbol ! */ { if(!pushed) { push_undo(); pushed=1;} delete_inst_node(i); /* 20180208 fix crashing bug: delete node info if changing symbol */ /* if number of pins is different we must delete these data *before* */ /* changing ysmbol, otherwise i might end up deleting non allocated data. */ - my_strdup(82, &inst_ptr[i].name, rel_sym_path(symbol)); + my_strdup(82, &xctx.inst[i].name, rel_sym_path(symbol)); if(event_reporting) { char n1[PATH_MAX]; char n2[PATH_MAX]; printf("xschem replace_symbol instance %s %s\n", - escape_chars(n1, inst_ptr[i].instname, PATH_MAX), + escape_chars(n1, xctx.inst[i].instname, PATH_MAX), escape_chars(n2, symbol, PATH_MAX) ); fflush(stdout); } - inst_ptr[i].ptr=sym_number; /* update instance to point to new symbol */ + xctx.inst[i].ptr=sym_number; /* update instance to point to new symbol */ } - bbox(ADD, inst_ptr[i].x1, inst_ptr[i].y1, inst_ptr[i].x2, inst_ptr[i].y2); - + bbox(ADD, xctx.inst[i].x1, xctx.inst[i].y1, xctx.inst[i].x2, xctx.inst[i].y2); + /* update property string from tcl dialog */ if(!no_change_props) { dbg(1, "update_symbol(): no_change_props=%d\n", no_change_props); if(only_different) { char * ss=NULL; - my_strdup(119, &ss, inst_ptr[i].prop_ptr); + my_strdup(119, &ss, xctx.inst[i].prop_ptr); if( set_different_token(&ss, new_prop, old_prop, 0, 0) ) { if(!pushed) { push_undo(); pushed=1;} - my_strdup(111, &inst_ptr[i].prop_ptr, ss); + my_strdup(111, &xctx.inst[i].prop_ptr, ss); set_modify(1); - prepared_hash_instances=0; /* 20171224 */ + prepared_hash_instances=0; prepared_netlist_structs=0; prepared_hilight_structs=0; } my_free(729, &ss); } else { - if(new_prop) { /* 20111205 */ - if(!inst_ptr[i].prop_ptr || strcmp(inst_ptr[i].prop_ptr, new_prop)) { - dbg(1, "update_symbol(): changing prop: |%s| -> |%s|\n", inst_ptr[i].prop_ptr, new_prop); + if(new_prop) { + if(!xctx.inst[i].prop_ptr || strcmp(xctx.inst[i].prop_ptr, new_prop)) { + dbg(1, "update_symbol(): changing prop: |%s| -> |%s|\n", xctx.inst[i].prop_ptr, new_prop); if(!pushed) { push_undo(); pushed=1;} - my_strdup(84, &inst_ptr[i].prop_ptr, new_prop); + my_strdup(84, &xctx.inst[i].prop_ptr, new_prop); set_modify(1); - prepared_hash_instances=0; /* 20171224 */ + prepared_hash_instances=0; prepared_netlist_structs=0; prepared_hilight_structs=0; } - } else { /* 20111205 */ + } else { if(!pushed) { push_undo(); pushed=1;} - my_strdup(86, &inst_ptr[i].prop_ptr, ""); + my_strdup(86, &xctx.inst[i].prop_ptr, ""); set_modify(1); - prepared_hash_instances=0; /* 20171224 */ + prepared_hash_instances=0; prepared_netlist_structs=0; prepared_hilight_structs=0; } } } - + /* if symbol changed ensure instance name (with new prefix char) is unique */ - my_strdup(152, &name, get_tok_value(inst_ptr[i].prop_ptr, "name", 0)); - if(name && name[0] ) { + my_strdup(152, &name, get_tok_value(xctx.inst[i].prop_ptr, "name", 0)); + if(name && name[0] ) { dbg(1, "update_symbol(): prefix!='\\0', name=%s\n", name); - new_name = get_tok_value(inst_ptr[i].prop_ptr, "name", 0); + new_name = get_tok_value(xctx.inst[i].prop_ptr, "name", 0); if(allow_change_name || (lastselected == 1) ) my_strdup(153, &name, new_name); /* 20110325 only modify prefix if prefix not NUL */ if(prefix) name[0]=prefix; /* change prefix if changing symbol type; */ - dbg(1, "update_symbol(): name=%s, inst_ptr[i].prop_ptr=%s\n", name, inst_ptr[i].prop_ptr); - my_strdup(89, &ptr,subst_token(inst_ptr[i].prop_ptr, "name", name) ); + dbg(1, "update_symbol(): name=%s, xctx.inst[i].prop_ptr=%s\n", name, xctx.inst[i].prop_ptr); + my_strdup(89, &ptr,subst_token(xctx.inst[i].prop_ptr, "name", name) ); /* set name of current inst */ - + if(!pushed) { push_undo(); pushed=1;} if(!k) hash_all_names(i); new_prop_string(i, ptr, k, dis_uniq_names); /* set new prop_ptr */ - - type=instdef[inst_ptr[i].ptr].type; /* 20150409 */ + + type=xctx.sym[xctx.inst[i].ptr].type; cond= !type || !IS_LABEL_SH_OR_PIN(type); - if(cond) inst_ptr[i].flags|=2; /* bit 1: flag for different textlayer for pin/labels */ - else inst_ptr[i].flags &=~2; + if(cond) xctx.inst[i].flags|=2; /* bit 1: flag for different textlayer for pin/labels */ + else xctx.inst[i].flags &=~2; } - + if(event_reporting) { char *ss=NULL; - my_strdup(120, &ss, inst_ptr[i].prop_ptr); + my_strdup(120, &ss, xctx.inst[i].prop_ptr); set_different_token(&ss, new_prop, old_prop, ELEMENT, i); my_free(730, &ss); } - my_strdup2(90, &inst_ptr[i].instname, get_tok_value(inst_ptr[i].prop_ptr, "name",0)); + my_strdup2(90, &xctx.inst[i].instname, get_tok_value(xctx.inst[i].prop_ptr, "name",0)); } /* end for(k=0;krects[PINLAYER]; k++) { - if( inst_ptr[i].node && inst_ptr[i].node[k]) { - find_inst_to_be_redrawn(inst_ptr[i].node[k]); + for(k = 0; k < (xctx.inst[i].ptr + xctx.sym)->rects[PINLAYER]; k++) { + if( xctx.inst[i].node && xctx.inst[i].node[k]) { + find_inst_to_be_redrawn(xctx.inst[i].node[k]); } } find_inst_hash_clear(); @@ -1129,9 +1132,9 @@ void update_symbol(const char *result, int x) void change_elem_order(void) { - Instance tmpinst; - Box tmpbox; - Wire tmpwire; + xInstance tmpinst; + xRect tmpbox; + xWire tmpwire; char tmp_txt[50]; /* overflow safe */ int c, new_n; @@ -1143,9 +1146,9 @@ void change_elem_order(void) tcleval("text_line {Object Sequence number} 0"); if(strcmp(tclgetvar("rcode"),"") ) { - push_undo(); /* 20150327 */ + push_undo(); set_modify(1); - prepared_hash_instances=0; /* 20171224 */ + prepared_hash_instances=0; prepared_netlist_structs=0; prepared_hilight_structs=0; } @@ -1153,27 +1156,27 @@ void change_elem_order(void) if(selectedgroup[0].type==ELEMENT) { - if(new_n>=lastinst) new_n=lastinst-1; - tmpinst=inst_ptr[new_n]; - inst_ptr[new_n]=inst_ptr[selectedgroup[0].n]; - inst_ptr[selectedgroup[0].n]=tmpinst; + if(new_n>=xctx.instances) new_n=xctx.instances-1; + tmpinst=xctx.inst[new_n]; + xctx.inst[new_n]=xctx.inst[selectedgroup[0].n]; + xctx.inst[selectedgroup[0].n]=tmpinst; dbg(1, "change_elem_order(): selected element %d\n", selectedgroup[0].n); } else if(selectedgroup[0].type==xRECT) { c=selectedgroup[0].col; - if(new_n>=lastrect[c]) new_n=lastrect[c]-1; - tmpbox=rect[c][new_n]; - rect[c][new_n]=rect[c][selectedgroup[0].n]; - rect[c][selectedgroup[0].n]=tmpbox; + if(new_n>=xctx.rects[c]) new_n=xctx.rects[c]-1; + tmpbox=xctx.rect[c][new_n]; + xctx.rect[c][new_n]=xctx.rect[c][selectedgroup[0].n]; + xctx.rect[c][selectedgroup[0].n]=tmpbox; dbg(1, "change_elem_order(): selected element %d\n", selectedgroup[0].n); } else if(selectedgroup[0].type==WIRE) { - if(new_n>=lastwire) new_n=lastwire-1; - tmpwire=wire[new_n]; - wire[new_n]=wire[selectedgroup[0].n]; - wire[selectedgroup[0].n]=tmpwire; + if(new_n>=xctx.wires) new_n=xctx.wires-1; + tmpwire=xctx.wire[new_n]; + xctx.wire[new_n]=xctx.wire[selectedgroup[0].n]; + xctx.wire[selectedgroup[0].n]=tmpwire; dbg(1, "change_elem_order(): selected element %d\n", selectedgroup[0].n); } @@ -1193,38 +1196,38 @@ void edit_property(int x) char *new_prop = NULL; if(netlist_type==CAD_SYMBOL_ATTRS) { - if(schsymbolprop!=NULL) /*09112003 */ - tclsetvar("retval",schsymbolprop); + if(xctx.schsymbolprop!=NULL) + tclsetvar("retval",xctx.schsymbolprop); else tclsetvar("retval",""); } else if(netlist_type==CAD_VHDL_NETLIST) { - if(schvhdlprop!=NULL) /*09112003 */ - tclsetvar("retval",schvhdlprop); + if(xctx.schvhdlprop!=NULL) + tclsetvar("retval",xctx.schvhdlprop); else tclsetvar("retval",""); } else if(netlist_type==CAD_VERILOG_NETLIST) { - if(schverilogprop!=NULL) /*09112003 */ - tclsetvar("retval",schverilogprop); + if(xctx.schverilogprop!=NULL) + tclsetvar("retval",xctx.schverilogprop); else tclsetvar("retval",""); } - else if(netlist_type==CAD_SPICE_NETLIST) { /* 20100217 */ - if(schprop!=NULL) - tclsetvar("retval",schprop); + else if(netlist_type==CAD_SPICE_NETLIST) { + if(xctx.schprop!=NULL) + tclsetvar("retval",xctx.schprop); else tclsetvar("retval",""); } - else if(netlist_type==CAD_TEDAX_NETLIST) { /* 20100217 */ - if(schtedaxprop!=NULL) - tclsetvar("retval",schtedaxprop); + else if(netlist_type==CAD_TEDAX_NETLIST) { + if(xctx.schtedaxprop!=NULL) + tclsetvar("retval",xctx.schtedaxprop); else tclsetvar("retval",""); } my_strdup(660, &old_prop, tclgetvar("retval")); - if(x==0) tcleval("text_line {Global schematic property:} 0"); + if(x==0) tcleval("text_line {Global schematic property:} 0"); else if(x==1) { dbg(1, "edit_property(): executing edit_vi_prop\n"); tcleval("edit_vi_prop {Global schematic property:}"); @@ -1241,45 +1244,45 @@ void edit_property(int x) if(strcmp(tclgetvar("rcode"),"") ) { - if(netlist_type==CAD_SYMBOL_ATTRS && /* 20120228 check if schprop NULL */ - (!schsymbolprop || strcmp(schsymbolprop, tclgetvar("retval") ) ) ) { /* 20120209 */ - set_modify(1); push_undo(); /* 20150327 */ - my_strdup(422, &schsymbolprop, (char *) tclgetvar("retval")); /*09112003 */ + if(netlist_type==CAD_SYMBOL_ATTRS && /* 20120228 check if xctx.schprop NULL */ + (!xctx.schsymbolprop || strcmp(xctx.schsymbolprop, tclgetvar("retval") ) ) ) { + set_modify(1); push_undo(); + my_strdup(422, &xctx.schsymbolprop, (char *) tclgetvar("retval")); - } else if(netlist_type==CAD_VERILOG_NETLIST && /* 20120228 check if schverilogprop NULL */ - (!schverilogprop || strcmp(schverilogprop, tclgetvar("retval") ) ) ) { /* 20120209 */ - set_modify(1); push_undo(); /* 20150327 */ - my_strdup(94, &schverilogprop, (char *) tclgetvar("retval")); /*09112003 */ - - } else if(netlist_type==CAD_SPICE_NETLIST && /* 20120228 check if schprop NULL */ - (!schprop || strcmp(schprop, tclgetvar("retval") ) ) ) { /* 20120209 */ - set_modify(1); push_undo(); /* 20150327 */ - my_strdup(95, &schprop, (char *) tclgetvar("retval")); /*09112003 */ + } else if(netlist_type==CAD_VERILOG_NETLIST && /* 20120228 check if xctx.schverilogprop NULL */ + (!xctx.schverilogprop || strcmp(xctx.schverilogprop, tclgetvar("retval") ) ) ) { + set_modify(1); push_undo(); + my_strdup(94, &xctx.schverilogprop, (char *) tclgetvar("retval")); - } else if(netlist_type==CAD_TEDAX_NETLIST && /* 20120228 check if schprop NULL */ - (!schtedaxprop || strcmp(schtedaxprop, tclgetvar("retval") ) ) ) { /* 20120209 */ - set_modify(1); push_undo(); /* 20150327 */ - my_strdup(96, &schtedaxprop, (char *) tclgetvar("retval")); /*09112003 */ + } else if(netlist_type==CAD_SPICE_NETLIST && /* 20120228 check if xctx.schprop NULL */ + (!xctx.schprop || strcmp(xctx.schprop, tclgetvar("retval") ) ) ) { + set_modify(1); push_undo(); + my_strdup(95, &xctx.schprop, (char *) tclgetvar("retval")); - } else if(netlist_type==CAD_VHDL_NETLIST && /* 20120228 check if schvhdlprop NULL */ - (!schvhdlprop || strcmp(schvhdlprop, tclgetvar("retval") ) ) ) { /* netlist_type==CAD_VHDL_NETLIST */ - set_modify(1); push_undo(); /* 20150327 */ - my_strdup(97, &schvhdlprop, (char *) tclgetvar("retval")); + } else if(netlist_type==CAD_TEDAX_NETLIST && /* 20120228 check if xctx.schprop NULL */ + (!xctx.schtedaxprop || strcmp(xctx.schtedaxprop, tclgetvar("retval") ) ) ) { + set_modify(1); push_undo(); + my_strdup(96, &xctx.schtedaxprop, (char *) tclgetvar("retval")); + + } else if(netlist_type==CAD_VHDL_NETLIST && /* 20120228 check if xctx.schvhdlprop NULL */ + (!xctx.schvhdlprop || strcmp(xctx.schvhdlprop, tclgetvar("retval") ) ) ) { /* netlist_type==CAD_VHDL_NETLIST */ + set_modify(1); push_undo(); + my_strdup(97, &xctx.schvhdlprop, (char *) tclgetvar("retval")); } } /* update the bounding box of vhdl "architecture" instances that embed */ - /* the schvhdlprop string. 04102001 */ - for(j=0;jtype && - !strcmp( (inst_ptr[j].ptr+instdef)->type, "architecture") ) /* 20150409 */ + if( xctx.inst[j].ptr !=-1 && + (xctx.inst[j].ptr+ xctx.sym)->type && + !strcmp( (xctx.inst[j].ptr+ xctx.sym)->type, "architecture") ) { dbg(1, "edit_property(): updating vhdl architecture\n"); - symbol_bbox(j, &inst_ptr[j].x1, &inst_ptr[j].y1, - &inst_ptr[j].x2, &inst_ptr[j].y2); - } + symbol_bbox(j, &xctx.inst[j].x1, &xctx.inst[j].y1, + &xctx.inst[j].x2, &xctx.inst[j].y2); + } } /* end for(j */ return; } @@ -1309,7 +1312,7 @@ void edit_property(int x) case WIRE: edit_wire_property(); break; - case POLYGON: /* 20171115 */ + case POLYGON: edit_polygon_property(); break; case LINE: @@ -1317,7 +1320,7 @@ void edit_property(int x) break; case xTEXT: edit_text_property(x); - break; + break; } } diff --git a/src/findnet.c b/src/findnet.c index 562dd243..1ac9ce0c 100644 --- a/src/findnet.c +++ b/src/findnet.c @@ -1,7 +1,7 @@ /* File: findnet.c - * + * * This file is part of XSCHEM, - * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit + * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit * simulation. * Copyright (C) 1998-2020 Stefan Frederik Schippers * @@ -33,9 +33,9 @@ void find_closest_net(double mx,double my) int i,w=-1; double threshold = CADWIREMINDIST * CADWIREMINDIST * cadgrid * cadgrid / 400; - for(i=0;itype); + for(i=0;itype); if(!type) continue; - no_of_pin_rects = (inst_ptr[i].ptr+instdef)->rects[PINLAYER]; + no_of_pin_rects = (xctx.inst[i].ptr+ xctx.sym)->rects[PINLAYER]; if(IS_LABEL_OR_PIN(type)) no_of_pin_rects=1; for(j=0; jboxptr[PINLAYER])[j]; + box = ((xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER])[j]; ROTATION(0.0,0.0,box.x1,box.y1,x1,y1); ROTATION(0.0,0.0,box.x2,box.y2,x2,y2); x1 += x0; @@ -137,23 +137,23 @@ void find_closest_net_or_symbol_pin(double mx,double my, double *x, double *y) yy = (y1+y2)/2; dist = (mx - xx) * (mx - xx) + (my - yy) * (my - yy); if(dist < distance) { - distance = dist; + distance = dist; min_dist_x = xx; min_dist_y = yy; } } } - for(i=0;i= angle1 || angle<= angle2) { match=1; @@ -198,17 +198,17 @@ void find_closest_arc(double mx,double my) } } dbg(1, "find_closest_arc(): dist = %g, angle = %g\n", dist, angle); - dbg(1, "find_closest_arc(): center=%g,%g: mouse: %g:%g\n", - arc[c][i].x, arc[c][i].y, mx, my); + dbg(1, "find_closest_arc(): center=%g,%g: mouse: %g:%g\n", + xctx.arc[c][i].x, xctx.arc[c][i].y, mx, my); if(match ) { dbg(1, "find_closest_arc(): i = %d\n", i); - r = i; + r = i; distance = dist; col = c; } } /* end for i */ } /* end for c */ - if( r!=-1 && distance <= thres ) /* * pow(arc[col][r].r,2)) */ + if( r!=-1 && distance <= thres ) /* * pow(xctx.arc[col][r].r,2)) */ { sel.n = r; sel.type = ARC; sel.col = col; } @@ -221,12 +221,12 @@ void find_closest_box(double mx,double my) int i,c,r=-1, col = 0; for(c=0;c */ -XColor xcolor_array[256];/* 20171109 */ -Visual *visual; /*20171111 */ -int dark_colorscheme=1; /* 20171113 */ -double color_dim=0.0; /* 20171123 */ -int no_undo=0; /* 20171204 */ +XColor xcolor_array[256]; +Visual *visual; +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 */ struct instpinentry *instpintable[NBOXES][NBOXES]; struct wireentry *wiretable[NBOXES][NBOXES]; @@ -237,7 +231,7 @@ cairo_t *cairo_ctx, *cairo_save_ctx; XRenderPictFormat *format; #if HAS_XCB==1 -xcb_connection_t *xcbconn; /* 20171125 */ +xcb_connection_t *xcbconn; xcb_render_pictforminfo_t format_rgb, format_rgba; xcb_screen_t *screen_xcb; xcb_visualtype_t *visual_xcb; @@ -260,44 +254,6 @@ double cairo_vert_correct=0.0; double nocairo_vert_correct=0.0; int show_erc=1; int hilight_nets=0; - -/* following data is relative to the current schematic */ -int max_texts; -int max_wires; -int max_instances; -int max_symbols; -int *max_rects; -int *max_polygons; -int *max_arcs; -int *max_lines; -Wire *wire; -int lastwire = 0; -Instance *inst_ptr; /* Pointer to element INSTANCE */ -int lastinst = 0; -Instdef *instdef; /* Pointer to element definition */ -int lastinstdef = 0; -Box **rect; -int *lastrect; -xPolygon **polygon; -int *lastpolygon; -xArc **arc; -int *lastarc; -Line **line; -int *lastline; -Text *textelement; -int lasttext=0; -char schematic[CADMAXHIER][PATH_MAX]; -int currentsch = 0; -char current_name[PATH_MAX]; -char *schprop=NULL; /* spice */ -char *schtedaxprop=NULL; /* tEDAx */ -char *schvhdlprop=NULL; /* vhdl property string */ -char *schsymbolprop=NULL; /* symbol property string */ -char *schverilogprop=NULL;/* verilog */ -char *xschem_version_string=NULL; -char file_version[100]; -char *sch_path[CADMAXHIER]; -int sch_inst_number[CADMAXHIER]; -int previous_instance[CADMAXHIER]; /* to remember the instance we came from when going up the hier. */ -Zoom zoom_array[CADMAXHIER]; +/* following data is relative to the current schematic */ +Xschem_ctx xctx; diff --git a/src/hash_iterator.c b/src/hash_iterator.c index 516354b8..05936667 100644 --- a/src/hash_iterator.c +++ b/src/hash_iterator.c @@ -1,7 +1,7 @@ /* File: hash_iterator.c - * + * * This file is part of XSCHEM, - * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit + * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit * simulation. * Copyright (C) 1998-2020 Stefan Frederik Schippers * @@ -33,9 +33,9 @@ static unsigned short *wireflag=NULL; void init_inst_iterator(double x1, double y1, double x2, double y2) { - dbg(3, "init_inst_iterator(): lastinst=%d\n", lastinst); - my_realloc(135, &instflag, lastinst*sizeof(unsigned short)); - memset(instflag, 0, lastinst*sizeof(unsigned short)); + dbg(3, "init_inst_iterator(): xctx.instances=%d\n", xctx.instances); + my_realloc(135, &instflag, xctx.instances*sizeof(unsigned short)); + memset(instflag, 0, xctx.instances*sizeof(unsigned short)); /* calculate square 4 1st corner of drawing area */ x1a=floor(x1/BOXSIZE) ; y1a=floor(y1/BOXSIZE) ; @@ -58,7 +58,7 @@ void init_inst_iterator(double x1, double y1, double x2, double y2) struct instentry *inst_iterator_next() { struct instentry *ptr; - dbg(3, "inst_iterator_next(): lastinst=%d\n", lastinst); + dbg(3, "inst_iterator_next(): xctx.instances=%d\n", xctx.instances); while(1) { while(instanceptr) { ptr = instanceptr; @@ -91,9 +91,9 @@ struct instentry *inst_iterator_next() void init_wire_iterator(double x1, double y1, double x2, double y2) { - dbg(3, "init_wire_iterator(): lastwire=%d\n", lastwire); - my_realloc(136, &wireflag, lastwire*sizeof(unsigned short)); - memset(wireflag, 0, lastwire*sizeof(unsigned short)); + dbg(3, "init_wire_iterator(): xctx.wires=%d\n", xctx.wires); + my_realloc(136, &wireflag, xctx.wires*sizeof(unsigned short)); + memset(wireflag, 0, xctx.wires*sizeof(unsigned short)); /* calculate square 4 1st corner of drawing area */ x1a=floor(x1/BOXSIZE) ; y1a=floor(y1/BOXSIZE) ; @@ -116,13 +116,13 @@ void init_wire_iterator(double x1, double y1, double x2, double y2) struct wireentry *wire_iterator_next() { struct wireentry *ptr; - dbg(3, "wire_iterator_next(): lastwire=%d\n", lastwire); + dbg(3, "wire_iterator_next(): xctx.wires=%d\n", xctx.wires); while(1) { while(wireptr) { ptr = wireptr; wireptr = wireptr -> next; if(!wireflag[ptr->n]) { - wireflag[ptr->n]=1; + wireflag[ptr->n]=1; return ptr; } } diff --git a/src/hilight.c b/src/hilight.c index ccb921b6..90c6f1b3 100644 --- a/src/hilight.c +++ b/src/hilight.c @@ -1,7 +1,7 @@ /* File: hilight.c - * + * * This file is part of XSCHEM, - * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit + * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit * simulation. * Copyright (C) 1998-2020 Stefan Frederik Schippers * @@ -23,7 +23,7 @@ #include "xschem.h" static struct hilight_hashentry *hilight_table[HASHSIZE]; -static int nelements=0; /* 20161221 */ +static int nelements=0; static int *inst_color=NULL; static unsigned int hash(const char *tok) @@ -32,7 +32,7 @@ static unsigned int hash(const char *tok) char *str; int c; - str=sch_path[currentsch]; + str=xctx.sch_path[xctx.currsch]; while ( (c = *tok++) ) hash = c + (hash << 6) + (hash << 16) - hash; while ( (c = *str++) ) @@ -80,11 +80,11 @@ void free_hilight_hash(void) /* remove the whole hash table */ hilight_table[i] = free_hilight_entry( hilight_table[i] ); } dbg(2, "free_hilight_hash(): : nelements=%d\n", nelements); - nelements=0; /* 20161221 */ + nelements=0; } -int get_color(int value) +int get_color(int value) { int x; @@ -122,7 +122,7 @@ void create_plot_cmd(int viewer) tok = entry->token; node_entry = bus_hash_lookup(tok, "", XLOOKUP, 0, "", "", "", ""); if(tok[0] == '#') tok++; - if(node_entry && !strcmp(sch_path[currentsch], entry->path) && + if(node_entry && !strcmp(xctx.sch_path[xctx.currsch], entry->path) && (node_entry->d.port == 0 || !strcmp(entry->path, ".") )) { c = get_color(entry->value); sprintf(color_str, "%02x%02x%02x", xcolor_array[c].red>>8, xcolor_array[c].green>>8, xcolor_array[c].blue>>8); @@ -149,7 +149,7 @@ void create_plot_cmd(int viewer) char *t=NULL, *p=NULL; my_strdup(241, &t, tok); my_strdup2(245, &p, (entry->path)+1); - Tcl_VarEval(interp, "puts $gaw_fd {copyvar v(", strtolower(p), strtolower(t), + Tcl_VarEval(interp, "puts $gaw_fd {copyvar v(", strtolower(p), strtolower(t), ") p0 #", color_str, "}\nvwait gaw_fd\n", NULL); my_free(759, &p); my_free(760, &t); @@ -183,14 +183,14 @@ struct hilight_hashentry *hilight_lookup(const char *token, int value, int remov struct hilight_hashentry *entry, *saveptr, **preventry; char *ptr; int s ; - int depth=0; /* 20161221 */ + int depth=0; if(token==NULL) return NULL; hashcode=hash(token); index=hashcode % HASHSIZE; entry=hilight_table[index]; preventry=&hilight_table[index]; - depth=0; /* 20161221 */ + depth=0; while(1) { if( !entry ) /* empty slot */ @@ -198,23 +198,23 @@ struct hilight_hashentry *hilight_lookup(const char *token, int value, int remov if( remove==XINSERT ) /* insert data */ { s=sizeof( struct hilight_hashentry ); - ptr= my_malloc(137, s ); + ptr= my_malloc(137, s ); entry=(struct hilight_hashentry *)ptr; entry->next = NULL; entry->token = NULL; my_strdup(138, &(entry->token),token); entry->path = NULL; - my_strdup(139, &(entry->path),sch_path[currentsch]); + my_strdup(139, &(entry->path),xctx.sch_path[xctx.currsch]); entry->value=value; entry->hash=hashcode; *preventry=entry; hilight_nets=1; /* some nets should be hilighted .... 07122002 */ - nelements++; /* 20161221 */ + nelements++; } return NULL; /* whether inserted or not return NULL since it was not in */ } if( entry -> hash==hashcode && !strcmp(token,entry->token) && - !strcmp(sch_path[currentsch], entry->path) ) /* found matching tok */ + !strcmp(xctx.sch_path[xctx.currsch], entry->path) ) /* found matching tok */ { if(remove==XDELETE) /* remove token from the hash table ... */ { @@ -232,10 +232,10 @@ struct hilight_hashentry *hilight_lookup(const char *token, int value, int remov } preventry=&entry->next; /* descend into the list. */ entry = entry->next; - depth++; /* 20161221 */ - if(debug_var>=2) - if(depth>200) - fprintf(errfp, "hilight_lookup(): deep into the list: %d, index=%d, token=%s, hashcode=%d\n", + depth++; + if(debug_var>=2) + if(depth>200) + fprintf(errfp, "hilight_lookup(): deep into the list: %d, index=%d, token=%s, hashcode=%d\n", depth, index, token, hashcode); } } @@ -294,8 +294,8 @@ void delete_hilight_net(void) } hilight_nets=0; - for(i=0;irects[PINLAYER]; + rects = (xctx.inst[i].ptr+ xctx.sym)->rects[PINLAYER]; for(j=0;jboxptr[PINLAYER][j].prop_ptr,"name",0); + pin_name = get_tok_value((xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER][j].prop_ptr,"name",0); if(!pin_name[0]) continue; my_strdup(450, &pin_node, expandlabel(pin_name, &mult)); dbg(1, "hilight_parent_pins(): pin_node=%s\n", pin_node); for(k = 1; k<=mult; k++) { - currentsch++; + xctx.currsch++; entry = bus_hilight_lookup(find_nth(pin_node, ',', k), 0, XLOOKUP); - currentsch--; + xctx.currsch--; if(entry) { - bus_hilight_lookup(find_nth(net_node, ',', + bus_hilight_lookup(find_nth(net_node, ',', ((inst_number - 1) * mult + k - 1) % net_mult + 1), entry->value, XINSERT); } else { - bus_hilight_lookup(find_nth(net_node, ',', + bus_hilight_lookup(find_nth(net_node, ',', ((inst_number - 1) * mult + k - 1) % net_mult + 1), 0, XDELETE); } } @@ -359,36 +359,36 @@ void hilight_child_pins(void) struct hilight_hashentry *entry; int mult, net_mult, i, inst_number; - i = previous_instance[currentsch-1]; + i = xctx.previous_instance[xctx.currsch-1]; if(!hilight_nets) return; prepare_netlist_structs(0); - rects = (inst_ptr[i].ptr+instdef)->rects[PINLAYER]; - inst_number = sch_inst_number[currentsch]; + rects = (xctx.inst[i].ptr+ xctx.sym)->rects[PINLAYER]; + inst_number = xctx.sch_inst_number[xctx.currsch]; for(j=0;jboxptr[PINLAYER][j].prop_ptr,"name",0); + pin_name = get_tok_value((xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER][j].prop_ptr,"name",0); if(!pin_name[0]) continue; my_strdup(521, &pin_node, expandlabel(pin_name, &mult)); dbg(1, "hilight_child_pins(): pin_node=%s\n", pin_node); for(k = 1; k<=mult; k++) { - dbg(1, "hilight_child_pins():looking nth net:%d, k=%d, inst_number=%d, mult=%d\n", + dbg(1, "hilight_child_pins():looking nth net:%d, k=%d, inst_number=%d, mult=%d\n", (inst_number-1)*mult+k, k, inst_number, mult); - dbg(1, "hilight_child_pins():looking net:%s\n", find_nth(net_node, ',', + dbg(1, "hilight_child_pins():looking net:%s\n", find_nth(net_node, ',', ((inst_number - 1) * mult + k - 1) % net_mult + 1)); - currentsch--; + xctx.currsch--; entry = bus_hilight_lookup(find_nth(net_node, ',', ((inst_number - 1) * mult + k - 1) % net_mult + 1), 0, XLOOKUP); - currentsch++; + xctx.currsch++; if(entry) { - bus_hilight_lookup(find_nth(pin_node, ',', k), entry->value, XINSERT); + bus_hilight_lookup(find_nth(pin_node, ',', k), entry->value, XINSERT); dbg(1, "hilight_child_pins(): inserting: %s\n", find_nth(pin_node, ',', k)); } else { - bus_hilight_lookup(find_nth(pin_node, ',', k), 0, XDELETE); + bus_hilight_lookup(find_nth(pin_node, ',', k), 0, XDELETE); dbg(1, "hilight_child_pins(): deleting: %s\n", find_nth(pin_node, ',', k)); } } /* for(k..) */ @@ -398,8 +398,8 @@ void hilight_child_pins(void) } -int bus_search(const char*s) -{ +int bus_search(const char*s) +{ int c, bus=0; while( (c=*s++) ) { if(c=='[') bus=1; @@ -413,7 +413,7 @@ int search(const char *tok, const char *val, int sub, int sel, int what) int save_draw, hilight_layer = 7; int i,c, col = 7,tmp,bus=0; const char *str; - char *type; + char *type; int has_token; const char empty_string[] = ""; char *tmpname=NULL; @@ -433,8 +433,8 @@ int search(const char *tok, const char *val, int sub, int sel, int what) #endif dbg(1, "search():val=%s\n", val); if(what==ADD || what==NOW) { - - if(!sel) { /* 20190525 */ + + if(!sel) { col=hilight_color; hilight_layer = get_color(col); if(incr_hilight) hilight_color++; @@ -442,27 +442,27 @@ int search(const char *tok, const char *val, int sub, int sel, int what) has_token = 0; prepare_netlist_structs(0); bus=bus_search(val); - for(i=0;iprop_ptr,tok+6,0)); + my_strdup(142, &tmpname,get_tok_value((xctx.inst[i].ptr+ xctx.sym)->prop_ptr,tok+6,0)); has_token = get_tok_size; if(tmpname) { str = tmpname; } else { str = empty_string; } - } else if(!strcmp(tok,"propstring")) { /* 20170408 */ - has_token = (inst_ptr[i].prop_ptr != NULL) && inst_ptr[i].prop_ptr[0]; - str = inst_ptr[i].prop_ptr; + } else if(!strcmp(tok,"propstring")) { + has_token = (xctx.inst[i].prop_ptr != NULL) && xctx.inst[i].prop_ptr[0]; + str = xctx.inst[i].prop_ptr; } else { - str = get_tok_value(inst_ptr[i].prop_ptr, tok,0); + str = get_tok_value(xctx.inst[i].prop_ptr, tok,0); has_token = get_tok_size; } dbg(1, "search(): inst=%d, tok=%s, val=%s \n", i,tok, str); - + if(bus && sub) { dbg(1, "search(): doing substr search on bus sig:%s inst=%d tok=%s val=%s\n", str,i,tok,val); str=expandlabel(str,&tmp); @@ -470,41 +470,41 @@ int search(const char *tok, const char *val, int sub, int sel, int what) if(str && has_token) { #ifdef __unix__ if( (!regexec(&re, str,0 , NULL, 0) && !sub) || /* 20071120 regex instead of strcmp */ - (!strcmp(str, val) && sub && !bus) || (strstr(str,val) && sub && bus)) + (!strcmp(str, val) && sub && !bus) || (strstr(str,val) && sub && bus)) #else if ((!strcmp(str, val) && sub && !bus) || (strstr(str,val) && sub && bus)) #endif { - if(!sel) { /*20190525 */ - type = (inst_ptr[i].ptr+instdef)->type; + if(!sel) { + type = (xctx.inst[i].ptr+ xctx.sym)->type; if( type && IS_LABEL_SH_OR_PIN(type) ) { - if(!bus_hilight_lookup(inst_ptr[i].node[0], col, XINSERT)) hilight_nets = 1; + if(!bus_hilight_lookup(xctx.inst[i].node[0], col, XINSERT)) hilight_nets = 1; if(what==NOW) for(c=0;c=0.7) { - if( wire[i].end1 >1 ) { - filledarc(hilight_layer, NOW, wire[i].x1, wire[i].y1, cadhalfdotsize, 0, 360); + xctx.wire[i].x1, xctx.wire[i].y1, xctx.wire[i].x2, xctx.wire[i].y2, 0); + if(cadhalfdotsize*xctx.mooz>=0.7) { + if( xctx.wire[i].end1 >1 ) { + filledarc(hilight_layer, NOW, xctx.wire[i].x1, xctx.wire[i].y1, cadhalfdotsize, 0, 360); } - if( wire[i].end2 >1 ) { - filledarc(hilight_layer, NOW, wire[i].x2, wire[i].y2, cadhalfdotsize, 0, 360); + if( xctx.wire[i].end2 >1 ) { + filledarc(hilight_layer, NOW, xctx.wire[i].x2, xctx.wire[i].y2, cadhalfdotsize, 0, 360); } } } @@ -547,8 +547,8 @@ int search(const char *tok, const char *val, int sub, int sel, int what) } } } - if(sel) for(c = 0; c < cadlayers; c++) for(i=0;irects[PINLAYER]; - rect=symbol->boxptr[PINLAYER]; + rct=symbol->rect[PINLAYER]; for(j=0; jvalue, XINSERT); /* add net to highlight list */ if(!propag_entry) { - /* fprintf(errfp, "inst %s: j=%d count=%d propagate=%d --> net %s, propagate to --> %s color %d\n", */ - /* inst_ptr[i].instname, j, count, propagate, netname, net_name(i, propagate, &mult, 1), entry->value); */ found=1; /* keep looping until no more nets are found. */ } - + } } /* for(j...) */ } /* for(i...) */ @@ -691,14 +689,14 @@ static void send_net_to_gaw(int simtype, const char *node) int c, k, tok_mult; struct node_hashentry *node_entry; const char *expanded_tok; - const char *tok; + const char *tok; char color_str[8]; - + if(!node || !node[0]) return; tok = node; node_entry = bus_hash_lookup(tok, "", XLOOKUP, 0, "", "", "", ""); if(tok[0] == '#') tok++; - if(node_entry && (node_entry->d.port == 0 || !strcmp(sch_path[currentsch], ".") )) { + if(node_entry && (node_entry->d.port == 0 || !strcmp(xctx.sch_path[xctx.currsch], ".") )) { char *t=NULL, *p=NULL; c = get_color(hilight_color); sprintf(color_str, "%02x%02x%02x", xcolor_array[c].red>>8, xcolor_array[c].green>>8, xcolor_array[c].blue>>8); @@ -706,9 +704,9 @@ static void send_net_to_gaw(int simtype, const char *node) tcleval("if { ![info exists gaw_fd] } { gaw_setup_tcp }\n"); for(k=1; k<=tok_mult; k++) { my_strdup(246, &t, find_nth(expanded_tok, ',', k)); - my_strdup2(254, &p, sch_path[currentsch]+1); + my_strdup2(254, &p, xctx.sch_path[xctx.currsch]+1); if(simtype == 0 ) { /* spice */ - Tcl_VarEval(interp, "puts $gaw_fd {copyvar v(", strtolower(p), strtolower(t), + Tcl_VarEval(interp, "puts $gaw_fd {copyvar v(", strtolower(p), strtolower(t), ") p0 #", color_str, "}\nvwait gaw_fd\n", NULL); } else { /* Xyce */ char *c=p; @@ -716,7 +714,7 @@ static void send_net_to_gaw(int simtype, const char *node) if(*c == '.') *c = ':'; /* Xyce uses : as path separator */ c++; } - Tcl_VarEval(interp, "puts $gaw_fd {copyvar ", strtoupper(p), strtoupper(t), + Tcl_VarEval(interp, "puts $gaw_fd {copyvar ", strtoupper(p), strtoupper(t), " p0 #", color_str, "}\nvwait gaw_fd\n", NULL); } } @@ -729,7 +727,7 @@ static void send_current_to_gaw(int simtype, const char *node) { int c, k, tok_mult; const char *expanded_tok; - const char *tok; + const char *tok; char color_str[8]; char *t=NULL, *p=NULL; @@ -742,9 +740,9 @@ static void send_current_to_gaw(int simtype, const char *node) tcleval("if { ![info exists gaw_fd] } { gaw_setup_tcp }\n"); for(k=1; k<=tok_mult; k++) { my_strdup(1179, &t, find_nth(expanded_tok, ',', k)); - my_strdup2(1180, &p, sch_path[currentsch]+1); + my_strdup2(1180, &p, xctx.sch_path[xctx.currsch]+1); if(!simtype) { /* spice */ - Tcl_VarEval(interp, "puts $gaw_fd {copyvar i(", currentsch>0 ? "v." : "", + Tcl_VarEval(interp, "puts $gaw_fd {copyvar i(", xctx.currsch>0 ? "v." : "", strtolower(p), strtolower(t), ") p0 #", color_str, "}\nvwait gaw_fd\n", NULL); } else { /* Xyce */ @@ -753,15 +751,15 @@ static void send_current_to_gaw(int simtype, const char *node) if(*c == '.') *c = ':'; /* Xyce uses : as path separator */ c++; } - Tcl_VarEval(interp, "puts $gaw_fd {copyvar ", currentsch>0 ? "V:" : "", - strtoupper(p), strtoupper( currentsch>0 ? t+1 : t ), "#branch", + Tcl_VarEval(interp, "puts $gaw_fd {copyvar ", xctx.currsch>0 ? "V:" : "", + strtoupper(p), strtoupper( xctx.currsch>0 ? t+1 : t ), "#branch", " p0 #", color_str, "}\nvwait gaw_fd\n", NULL); } } my_free(1181, &p); my_free(1182, &t); - + } @@ -781,43 +779,43 @@ void hilight_net(int to_waveform) n = selectedgroup[i].n; switch(selectedgroup[i].type) { - case WIRE: + case WIRE: if(event_reporting) { char s[PATH_MAX]; - printf("xschem search exact %d lab %s\n", 0, escape_chars(s, wire[n].node, PATH_MAX)); + printf("xschem search exact %d lab %s\n", 0, escape_chars(s, xctx.wire[n].node, PATH_MAX)); fflush(stdout); } hilight_nets=1; - if(!bus_hilight_lookup(wire[n].node, hilight_color, XINSERT)) { - if(to_waveform == GAW) send_net_to_gaw(sim_is_xyce, wire[n].node); + if(!bus_hilight_lookup(xctx.wire[n].node, hilight_color, XINSERT)) { + if(to_waveform == GAW) send_net_to_gaw(sim_is_xyce, xctx.wire[n].node); if(incr_hilight) hilight_color++; } break; case ELEMENT: - type = (inst_ptr[n].ptr+instdef)->type; - if( type && inst_ptr[n].node && IS_LABEL_SH_OR_PIN(type) ) { /* instance must have a pin! */ + 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(event_reporting) { char s[PATH_MAX]; - printf("xschem search exact %d lab %s\n", 0, escape_chars(s, inst_ptr[n].node[0], PATH_MAX)); + printf("xschem search exact %d lab %s\n", 0, escape_chars(s, xctx.inst[n].node[0], PATH_MAX)); fflush(stdout); } - if(!bus_hilight_lookup(inst_ptr[n].node[0], hilight_color, XINSERT)) { - if(to_waveform == GAW) send_net_to_gaw(sim_is_xyce, inst_ptr[n].node[0]); + if(!bus_hilight_lookup(xctx.inst[n].node[0], 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++; } } else { if(event_reporting) { char s[PATH_MAX]; - printf("xschem search exact %d name %s\n", 0, escape_chars(s, inst_ptr[n].instname, PATH_MAX)); + printf("xschem search exact %d name %s\n", 0, escape_chars(s, xctx.inst[n].instname, PATH_MAX)); fflush(stdout); } dbg(1, "hilight_net(): setting hilight flag on inst %d\n",n); hilight_nets=1; - inst_ptr[n].flags |= 4; + xctx.inst[n].flags |= 4; } if(type && (!strcmp(type, "current_probe") || !strcmp(type, "vsource")) ) { - if(to_waveform == GAW) send_current_to_gaw(sim_is_xyce, inst_ptr[n].instname); + if(to_waveform == GAW) send_current_to_gaw(sim_is_xyce, xctx.inst[n].instname); } break; default: @@ -845,33 +843,33 @@ void unhilight_net(void) n = selectedgroup[i].n; switch(selectedgroup[i].type) { - case WIRE: + case WIRE: if(event_reporting) { char s[PATH_MAX]; - printf("xschem search exact %d lab %s\n", 1, escape_chars(s, wire[n].node, PATH_MAX)); + printf("xschem search exact %d lab %s\n", 1, escape_chars(s, xctx.wire[n].node, PATH_MAX)); printf("xschem unhilight\n"); fflush(stdout); } - bus_hilight_lookup(wire[n].node, hilight_color, XDELETE); + bus_hilight_lookup(xctx.wire[n].node, hilight_color, XDELETE); break; case ELEMENT: - type = (inst_ptr[n].ptr+instdef)->type; + type = (xctx.inst[n].ptr+ xctx.sym)->type; if( type && - inst_ptr[n].node && IS_LABEL_SH_OR_PIN(type) ) { /* instance must have a pin! */ + xctx.inst[n].node && IS_LABEL_SH_OR_PIN(type) ) { /* instance must have a pin! */ if(event_reporting) { printf("xschem unhilight\n"); fflush(stdout); } - bus_hilight_lookup(inst_ptr[n].node[0], hilight_color, XDELETE); + bus_hilight_lookup(xctx.inst[n].node[0], hilight_color, XDELETE); } else { if(event_reporting) { char s[PATH_MAX]; - printf("xschem search exact %d name %s\n", 1, escape_chars(s, inst_ptr[n].instname, PATH_MAX)); + printf("xschem search exact %d name %s\n", 1, escape_chars(s, xctx.inst[n].instname, PATH_MAX)); printf("xschem unhilight\n"); fflush(stdout); } } - inst_ptr[n].flags &= ~4; + xctx.inst[n].flags &= ~4; break; default: break; @@ -882,7 +880,7 @@ void unhilight_net(void) void redraw_hilights(void) { - Box boundbox; + xRect boundbox; if(!has_x) return; calc_drawing_bbox(&boundbox, 2); bbox(BEGIN, 0.0 , 0.0 , 0.0 , 0.0); @@ -898,89 +896,89 @@ void draw_hilight_net(int on_window) char *type=NULL; int i,c; struct hilight_hashentry *entry; - register double x1,y1,x2,y2; /* 20150409 */ - Instdef *symptr; /* 20160414 */ + register double x1,y1,x2,y2; + xSymbol *symptr; int use_hash; struct wireentry *wireptr; int hilight_connected_inst; if(!hilight_nets) return; prepare_netlist_structs(0); - save_draw = draw_window; /* 20181009 */ + save_draw = draw_window; draw_window = on_window; x1 = X_TO_XSCHEM(areax1); y1 = Y_TO_XSCHEM(areay1); x2 = X_TO_XSCHEM(areax2); y2 = Y_TO_XSCHEM(areay2); - use_hash = (lastwire> 2000 || lastinst > 2000 ) && (x2 - x1 < ITERATOR_THRESHOLD); + use_hash = (xctx.wires> 2000 || xctx.instances > 2000 ) && (x2 - x1 < ITERATOR_THRESHOLD); if(use_hash) { hash_wires(); } - if(!use_hash) for(i=0;ivalue), THICK, - wire[i].x1, wire[i].y1, wire[i].x2, wire[i].y2, 0); + xctx.wire[i].x1, xctx.wire[i].y1, xctx.wire[i].x2, xctx.wire[i].y2, 0); else drawline(get_color(entry->value), NOW, - wire[i].x1, wire[i].y1, wire[i].x2, wire[i].y2, 0); - if(cadhalfdotsize*mooz>=0.7) { - if( wire[i].end1 >1 ) { /* 20150331 draw_dots */ - filledarc(get_color(entry->value), NOW, wire[i].x1, wire[i].y1, cadhalfdotsize, 0, 360); + xctx.wire[i].x1, xctx.wire[i].y1, xctx.wire[i].x2, xctx.wire[i].y2, 0); + if(cadhalfdotsize*xctx.mooz>=0.7) { + if( xctx.wire[i].end1 >1 ) { /* 20150331 draw_dots */ + filledarc(get_color(entry->value), NOW, xctx.wire[i].x1, xctx.wire[i].y1, cadhalfdotsize, 0, 360); } - if( wire[i].end2 >1 ) { /* 20150331 draw_dots */ - filledarc(get_color(entry->value), NOW, wire[i].x2, wire[i].y2, cadhalfdotsize, 0, 360); + if( xctx.wire[i].end2 >1 ) { /* 20150331 draw_dots */ + filledarc(get_color(entry->value), NOW, xctx.wire[i].x2, xctx.wire[i].y2, cadhalfdotsize, 0, 360); } } } } else for(init_wire_iterator(x1, y1, x2, y2); ( wireptr = wire_iterator_next() ) ;) { i = wireptr->n; - if( (entry = bus_hilight_lookup(wire[i].node, 0, XLOOKUP)) ) { - if(wire[i].bus) /* 20171201 */ + if( (entry = bus_hilight_lookup(xctx.wire[i].node, 0, XLOOKUP)) ) { + if(xctx.wire[i].bus) drawline(get_color(entry->value), THICK, - wire[i].x1, wire[i].y1, wire[i].x2, wire[i].y2, 0); + xctx.wire[i].x1, xctx.wire[i].y1, xctx.wire[i].x2, xctx.wire[i].y2, 0); else drawline(get_color(entry->value), NOW, - wire[i].x1, wire[i].y1, wire[i].x2, wire[i].y2, 0); - if(cadhalfdotsize*mooz>=0.7) { - if( wire[i].end1 >1 ) { /* 20150331 draw_dots */ - filledarc(get_color(entry->value), NOW, wire[i].x1, wire[i].y1, cadhalfdotsize, 0, 360); + xctx.wire[i].x1, xctx.wire[i].y1, xctx.wire[i].x2, xctx.wire[i].y2, 0); + if(cadhalfdotsize*xctx.mooz>=0.7) { + if( xctx.wire[i].end1 >1 ) { /* 20150331 draw_dots */ + filledarc(get_color(entry->value), NOW, xctx.wire[i].x1, xctx.wire[i].y1, cadhalfdotsize, 0, 360); } - if( wire[i].end2 >1 ) { /* 20150331 draw_dots */ - filledarc(get_color(entry->value), NOW, wire[i].x2, wire[i].y2, cadhalfdotsize, 0, 360); + if( xctx.wire[i].end2 >1 ) { /* 20150331 draw_dots */ + filledarc(get_color(entry->value), NOW, xctx.wire[i].x2, xctx.wire[i].y2, cadhalfdotsize, 0, 360); } } } } - dbg(1, "draw_hilight_net() : allocating inst_color %d bytes \n", lastinst*sizeof(int)); - my_realloc(145, &inst_color,lastinst*sizeof(int)); - for(i=0;itype; /* 20150409 */ + type = (xctx.inst[i].ptr+ xctx.sym)->type; - hilight_connected_inst = !strcmp(get_tok_value((inst_ptr[i].ptr+instdef)->prop_ptr, "highlight", 0), "true") || - !strcmp(get_tok_value(inst_ptr[i].prop_ptr, "highlight", 0), "true"); - if( inst_ptr[i].flags & 4) { + hilight_connected_inst = !strcmp(get_tok_value((xctx.inst[i].ptr+ xctx.sym)->prop_ptr, "highlight", 0), "true") || + !strcmp(get_tok_value(xctx.inst[i].prop_ptr, "highlight", 0), "true"); + if( xctx.inst[i].flags & 4) { dbg(1, "draw_hilight_net(): instance %d flags &4 true\n", i); inst_color[i]=PINLAYER; } else if(hilight_connected_inst) { int rects, j; - dbg(2, "draw_hilight_net(): hilight_connected_inst inst=%d, node=%s\n", i, inst_ptr[i].node[0]); - if( (rects = (inst_ptr[i].ptr+instdef)->rects[PINLAYER]) > 0 ) { + dbg(2, "draw_hilight_net(): hilight_connected_inst inst=%d, node=%s\n", i, xctx.inst[i].node[0]); + if( (rects = (xctx.inst[i].ptr+ xctx.sym)->rects[PINLAYER]) > 0 ) { for(j=0;jvalue); break; @@ -989,28 +987,28 @@ void draw_hilight_net(int on_window) } } } else if( type && IS_LABEL_SH_OR_PIN(type) ) { - entry=bus_hilight_lookup( get_tok_value(inst_ptr[i].prop_ptr,"lab",0) , 0, XLOOKUP); + entry=bus_hilight_lookup( get_tok_value(xctx.inst[i].prop_ptr,"lab",0) , 0, XLOOKUP); if(entry) inst_color[i]=get_color(entry->value); } } for(c=0;clines[c] || symptr->rects[c] || @@ -1052,7 +1050,7 @@ void print_hilight_net(int show) prepare_netlist_structs(1); /* use full prepare_netlist_structs(1) to recognize pin direction */ /* when creating pins from hilight nets 20171221 */ - /* 20180924 */ + if(!(fd = open_tmpfile("hilight_", &filename_ptr)) ) { fprintf(errfp, "print_hilight_net(): can not create tmpfile %s\n", filename_ptr); return; @@ -1060,7 +1058,7 @@ void print_hilight_net(int show) my_strdup(147, &filetmp2, filename_ptr); fclose(fd); if(!(fd = open_tmpfile("hilight_", &filename_ptr))) { - fprintf(errfp, "print_hilight_net(): can not create tmpfile %s\n", filename_ptr); + fprintf(errfp, "print_hilight_net(): can not create tmpfile %s\n", filename_ptr); my_free(776, &filetmp2); return; } @@ -1079,7 +1077,7 @@ void print_hilight_net(int show) my_free(778, &filetmp2); return; } - if(fd==NULL){ + if(fd==NULL){ dbg(1, "print_hilight_net(): problems opening netlist file\n"); my_free(779, &filetmp1); my_free(780, &filetmp2); @@ -1091,18 +1089,18 @@ void print_hilight_net(int show) for(i=0;itoken, "", XLOOKUP, 0, "", "", "", ""); /* 20170926 test for not null node_entry, this may happen if a hilighted net name has been changed */ /* before invoking this function, in this case --> skip */ - if(node_entry && !strcmp(sch_path[currentsch], entry->path)) { + if(node_entry && !strcmp(xctx.sch_path[xctx.currsch], entry->path)) { if(show==3) { - - fprintf(fd, "%s%s\n", !strcmp(entry->path, ".") ? "" : entry->path, entry->token); /* 20111106 */ - } else if(show==1) { /* 20120926 */ - fprintf(fd, "%s\n", entry->token); /* 20120926 */ + fprintf(fd, "%s%s\n", !strcmp(entry->path, ".") ? "" : entry->path, entry->token); + + } else if(show==1) { + fprintf(fd, "%s\n", entry->token); } else { if(node_entry->d.out==0 && node_entry->d.inout==0 ) fprintf(fd, "%s %s\n", entry->token, "ipin"); diff --git a/src/hspice_backannotate.tcl b/src/hspice_backannotate.tcl index fc38186b..24dcbf56 100644 --- a/src/hspice_backannotate.tcl +++ b/src/hspice_backannotate.tcl @@ -102,7 +102,7 @@ proc annotate {} { xschem set no_draw 1 read_hspice_log [xschem get netlist_dir]/hspice.out - set lastinst [xschem get lastinst] + set lastinst [xschem get instances] for { set i 0 } { $i < $lastinst } {incr i } { set name [xschem getprop instance $i name] set type [xschem getprop instance $i cell::type] diff --git a/src/icon.c b/src/icon.c index 1b6eeaba..b3023bf8 100644 --- a/src/icon.c +++ b/src/icon.c @@ -1,7 +1,7 @@ /* File: icon.c - * + * * This file is part of XSCHEM, - * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit + * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit * simulation. * Copyright (C) 1998-2020 Stefan Frederik Schippers * diff --git a/src/in_memory_undo.c b/src/in_memory_undo.c index 2744145d..35b01414 100644 --- a/src/in_memory_undo.c +++ b/src/in_memory_undo.c @@ -1,7 +1,7 @@ /* File: in_memory_undo.c - * + * * This file is part of XSCHEM, - * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit + * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit * simulation. * Copyright (C) 1998-2020 Stefan Frederik Schippers * @@ -31,19 +31,19 @@ typedef struct char *kptr; char *eptr; int *lines; - int *boxes; + int *rects; int *polygons; int *arcs; int wires; int texts; int instances; - Line **lptr; - Box **bptr; - xPolygon **pptr; + xLine **lptr; + xRect **bptr; + xPoly **pptr; xArc **aptr; - Wire *wptr; - Text *tptr; - Instance *iptr; + xWire *wptr; + xText *tptr; + xInstance *iptr; } Undo_slot; static Undo_slot uslot[MAX_UNDO]; @@ -52,23 +52,23 @@ static int initialized=0; void init_undo() { int slot; - + for(slot=0;slot conflicts with tcl exec */ - errfp=stderr; + errfp=stderr; /* 20181013 check for empty or non existing DISPLAY *before* calling Tk_Main or Tcl_Main */ #ifdef __unix__ if(!getenv("DISPLAY") || !getenv("DISPLAY")[0]) has_x=0; #endif process_options(argc, argv); - if(debug_var>=1 && !has_x) + if(debug_var>=1 && !has_x) fprintf(errfp, "main(): no DISPLAY set, assuming no X available\n"); /* detach from console (fork a child and close std file descriptors) */ diff --git a/src/move.c b/src/move.c index 49c9a349..0f402d1b 100644 --- a/src/move.c +++ b/src/move.c @@ -1,7 +1,7 @@ /* File: move.c - * + * * This file is part of XSCHEM, - * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit + * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit * simulation. * Copyright (C) 1998-2020 Stefan Frederik Schippers * @@ -27,7 +27,7 @@ static int flip = 0; static double x1=0.0, y_1=0.0, x2=0.0, y_2=0.0, deltax = 0.0, deltay = 0.0; /* static int i,c,n,k; */ static int lastsel; -static int rotatelocal=0; /* 20171208 */ +static int rotatelocal=0; void rebuild_selected_array() /* can be used only if new selected set is lower */ @@ -38,24 +38,24 @@ void rebuild_selected_array() /* can be used only if new selected set is lower * dbg(1, "rebuild selected array\n"); if(!need_rebuild_selected_array) return; lastselected=0; - for(i=0;irects[PINLAYER]; for(p = 0; p < rects; p++) { - if(node && inst_ptr[i].node[p] && !strcmp(inst_ptr[i].node[p], node )) { - symbol_bbox(i, &inst_ptr[i].x1, &inst_ptr[i].y1, &inst_ptr[i].x2, &inst_ptr[i].y2 ); - bbox(ADD, inst_ptr[i].x1, inst_ptr[i].y1, inst_ptr[i].x2, inst_ptr[i].y2 ); + if(node && xctx.inst[i].node[p] && !strcmp(xctx.inst[i].node[p], node )) { + symbol_bbox(i, &xctx.inst[i].x1, &xctx.inst[i].y1, &xctx.inst[i].x2, &xctx.inst[i].y2 ); + bbox(ADD, xctx.inst[i].x1, xctx.inst[i].y1, xctx.inst[i].x2, xctx.inst[i].y2 ); } } } - for(i=0;i < lastwire; i++) { - if(node && wire[i].node && !strcmp(wire[i].node, node )) { - if(wire[i].bus){ + for(i=0;i < xctx.wires; i++) { + if(node && xctx.wire[i].node && !strcmp(xctx.wire[i].node, node )) { + if(xctx.wire[i].bus){ int ov, y1, y2; ov = bus_width> cadhalfdotsize ? bus_width : CADHALFDOTSIZE; - if(wire[i].y1 < wire[i].y2) { y1 = wire[i].y1-ov; y2 = wire[i].y2+ov; } - else { y1 = wire[i].y1+ov; y2 = wire[i].y2-ov; } - bbox(ADD, wire[i].x1-ov, y1 , wire[i].x2+ov , y2 ); + if(xctx.wire[i].y1 < xctx.wire[i].y2) { y1 = xctx.wire[i].y1-ov; y2 = xctx.wire[i].y2+ov; } + else { y1 = xctx.wire[i].y1+ov; y2 = xctx.wire[i].y2-ov; } + bbox(ADD, xctx.wire[i].x1-ov, y1 , xctx.wire[i].x2+ov , y2 ); } else { int ov, y1, y2; ov = cadhalfdotsize; - if(wire[i].y1 < wire[i].y2) { y1 = wire[i].y1-ov; y2 = wire[i].y2+ov; } - else { y1 = wire[i].y1+ov; y2 = wire[i].y2-ov; } - bbox(ADD, wire[i].x1-ov, y1 , wire[i].x2+ov , y2 ); + if(xctx.wire[i].y1 < xctx.wire[i].y2) { y1 = xctx.wire[i].y1-ov; y2 = xctx.wire[i].y2+ov; } + else { y1 = xctx.wire[i].y1+ov; y2 = xctx.wire[i].y2-ov; } + bbox(ADD, xctx.wire[i].x1-ov, y1 , xctx.wire[i].x2+ov , y2 ); } } } @@ -492,14 +493,14 @@ void find_inst_to_be_redrawn(const char *node) void copy_objects(int what) { int c, i, n, k; - /* Box tmp; */ + /* xRect tmp; */ double angle; int newpropcnt; double tmpx, tmpy; int textlayer; const char *str; - /* 20171112 */ + #ifdef HAS_CAIRO char *textfont; /* int customfont; */ @@ -507,7 +508,7 @@ void copy_objects(int what) if(what & BEGIN) { - rotatelocal=0; /*20171208 */ + rotatelocal=0; dbg(1, "copy_objects(): BEGIN copy\n"); rebuild_selected_array(); save_selection(1); @@ -536,14 +537,14 @@ void copy_objects(int what) deltax = x2-x1; deltay = y_2 - y_1; draw_selection(gc[SELLAYER],1); } - if(what & ROTATELOCAL ) { /*20171208 */ + if(what & ROTATELOCAL ) { rotatelocal=1; - } + } if(what & ROTATE) { draw_selection(gctiled,0); rot= (rot+1) & 0x3; update_symbol_bboxes(); - } + } if(what & FLIP) { draw_selection(gctiled,0); @@ -553,11 +554,11 @@ void copy_objects(int what) if(what & END) /* copy selected objects */ { int firstw, firsti; - int save_draw; /* 20181009 */ + int save_draw; save_draw = draw_window; draw_window=1; /* temporarily re-enable draw to window together with pixmap */ draw_selection(gctiled,0); - bbox(BEGIN, 0.0 , 0.0 , 0.0 , 0.0); /* 20181009 */ + bbox(BEGIN, 0.0 , 0.0 , 0.0 , 0.0); newpropcnt=0; set_modify(1); push_undo(); /* 20150327 push_undo */ firstw = firsti = 1; @@ -571,34 +572,34 @@ void copy_objects(int what) firstw = 0; } check_wire_storage(); - /* - if(wire[n].bus){ + /* + if(xctx.wire[n].bus){ int ov, y1, y2; ov = bus_width> cadhalfdotsize ? bus_width : CADHALFDOTSIZE; - if(wire[n].y1 < wire[n].y2) { y1 = wire[n].y1-ov; y2 = wire[n].y2+ov; } - else { y1 = wire[n].y1+ov; y2 = wire[n].y2-ov; } - bbox(ADD, wire[n].x1-ov, y1 , wire[n].x2+ov , y2 ); + if(xctx.wire[n].y1 < xctx.wire[n].y2) { y1 = xctx.wire[n].y1-ov; y2 = xctx.wire[n].y2+ov; } + else { y1 = xctx.wire[n].y1+ov; y2 = xctx.wire[n].y2-ov; } + bbox(ADD, xctx.wire[n].x1-ov, y1 , xctx.wire[n].x2+ov , y2 ); } else { int ov, y1, y2; ov = cadhalfdotsize; - if(wire[n].y1 < wire[n].y2) { y1 = wire[n].y1-ov; y2 = wire[n].y2+ov; } - else { y1 = wire[n].y1+ov; y2 = wire[n].y2-ov; } - bbox(ADD, wire[n].x1-ov, y1 , wire[n].x2+ov , y2 ); + if(xctx.wire[n].y1 < xctx.wire[n].y2) { y1 = xctx.wire[n].y1-ov; y2 = xctx.wire[n].y2+ov; } + else { y1 = xctx.wire[n].y1+ov; y2 = xctx.wire[n].y2-ov; } + bbox(ADD, xctx.wire[n].x1-ov, y1 , xctx.wire[n].x2+ov , y2 ); } */ if(rotatelocal) { - ROTATION(wire[n].x1, wire[n].y1, wire[n].x1, wire[n].y1, rx1,ry1); - ROTATION(wire[n].x1, wire[n].y1, wire[n].x2, wire[n].y2, rx2,ry2); + ROTATION(xctx.wire[n].x1, xctx.wire[n].y1, xctx.wire[n].x1, xctx.wire[n].y1, rx1,ry1); + ROTATION(xctx.wire[n].x1, xctx.wire[n].y1, xctx.wire[n].x2, xctx.wire[n].y2, rx2,ry2); } else { - ROTATION(x1, y_1, wire[n].x1, wire[n].y1, rx1,ry1); - ROTATION(x1, y_1, wire[n].x2, wire[n].y2, rx2,ry2); + ROTATION(x1, y_1, xctx.wire[n].x1, xctx.wire[n].y1, rx1,ry1); + ROTATION(x1, y_1, xctx.wire[n].x2, xctx.wire[n].y2, rx2,ry2); } - if( wire[n].sel & (SELECTED|SELECTED1) ) + if( xctx.wire[n].sel & (SELECTED|SELECTED1) ) { rx1+=deltax; ry1+=deltay; } - if( wire[n].sel & (SELECTED|SELECTED2) ) + if( xctx.wire[n].sel & (SELECTED|SELECTED2) ) { rx2+=deltax; ry2+=deltay; @@ -608,13 +609,13 @@ void copy_objects(int what) ORDER(rx1,ry1,rx2,ry2); if( tmpx == rx2 && tmpy == ry2) { - if(wire[n].sel == SELECTED1) wire[n].sel = SELECTED2; - else if(wire[n].sel == SELECTED2) wire[n].sel = SELECTED1; + if(xctx.wire[n].sel == SELECTED1) xctx.wire[n].sel = SELECTED2; + else if(xctx.wire[n].sel == SELECTED2) xctx.wire[n].sel = SELECTED1; } - selectedgroup[i].n=lastwire; - storeobject(-1, rx1,ry1,rx2,ry2,WIRE,0,wire[n].sel,wire[n].prop_ptr); - wire[n].sel=0; - if(wire[n].bus) /* 20171201 */ + selectedgroup[i].n=xctx.wires; + storeobject(-1, rx1,ry1,rx2,ry2,WIRE,0,xctx.wire[n].sel,xctx.wire[n].prop_ptr); + xctx.wire[n].sel=0; + if(xctx.wire[n].bus) drawline(WIRELAYER, THICK, rx1,ry1,rx2,ry2, 0); else drawline(WIRELAYER, ADD, rx1,ry1,rx2,ry2, 0); @@ -631,21 +632,21 @@ void copy_objects(int what) switch(selectedgroup[i].type) { case LINE: - if(c!=k) break; - /* bbox(ADD, line[c][n].x1, line[c][n].y1, line[c][n].x2, line[c][n].y2) */ + if(c!=k) break; + /* bbox(ADD, xctx.line[c][n].x1, xctx.line[c][n].y1, xctx.line[c][n].x2, xctx.line[c][n].y2) */ if(rotatelocal) { - ROTATION(line[c][n].x1, line[c][n].y1, line[c][n].x1, line[c][n].y1, rx1,ry1); - ROTATION(line[c][n].x1, line[c][n].y1, line[c][n].x2, line[c][n].y2, rx2,ry2); + ROTATION(xctx.line[c][n].x1, xctx.line[c][n].y1, xctx.line[c][n].x1, xctx.line[c][n].y1, rx1,ry1); + ROTATION(xctx.line[c][n].x1, xctx.line[c][n].y1, xctx.line[c][n].x2, xctx.line[c][n].y2, rx2,ry2); } else { - ROTATION(x1, y_1, line[c][n].x1, line[c][n].y1, rx1,ry1); - ROTATION(x1, y_1, line[c][n].x2, line[c][n].y2, rx2,ry2); + ROTATION(x1, y_1, xctx.line[c][n].x1, xctx.line[c][n].y1, rx1,ry1); + ROTATION(x1, y_1, xctx.line[c][n].x2, xctx.line[c][n].y2, rx2,ry2); } - if( line[c][n].sel & (SELECTED|SELECTED1) ) + if( xctx.line[c][n].sel & (SELECTED|SELECTED1) ) { rx1+=deltax; ry1+=deltay; } - if( line[c][n].sel & (SELECTED|SELECTED2) ) + if( xctx.line[c][n].sel & (SELECTED|SELECTED2) ) { rx2+=deltax; ry2+=deltay; @@ -655,22 +656,22 @@ void copy_objects(int what) ORDER(rx1,ry1,rx2,ry2); if( tmpx == rx2 && tmpy == ry2) { - if(line[c][n].sel == SELECTED1) line[c][n].sel = SELECTED2; - else if(line[c][n].sel == SELECTED2) line[c][n].sel = SELECTED1; + if(xctx.line[c][n].sel == SELECTED1) xctx.line[c][n].sel = SELECTED2; + else if(xctx.line[c][n].sel == SELECTED2) xctx.line[c][n].sel = SELECTED1; } - if(line[c][n].bus) - drawline(k, THICK, rx1,ry1,rx2,ry2, line[c][n].dash); + if(xctx.line[c][n].bus) + drawline(k, THICK, rx1,ry1,rx2,ry2, xctx.line[c][n].dash); else - drawline(k, ADD, rx1,ry1,rx2,ry2, line[c][n].dash); - selectedgroup[i].n=lastline[c]; - storeobject(-1, rx1, ry1, rx2, ry2, LINE, c, line[c][n].sel, line[c][n].prop_ptr); - line[c][n].sel=0; + drawline(k, ADD, rx1,ry1,rx2,ry2, xctx.line[c][n].dash); + selectedgroup[i].n=xctx.lines[c]; + storeobject(-1, rx1, ry1, rx2, ry2, LINE, c, xctx.line[c][n].sel, xctx.line[c][n].prop_ptr); + xctx.line[c][n].sel=0; break; - case POLYGON: /* 20171115 */ + case POLYGON: if(c!=k) break; { - xPolygon *p = &polygon[c][n]; + xPoly *p = &xctx.poly[c][n]; /* double bx1, by1, bx2, by2; */ double *x = my_malloc(227, sizeof(double) *p->points); double *y = my_malloc(228, sizeof(double) *p->points); @@ -697,8 +698,8 @@ void copy_objects(int what) } /* bbox(ADD, bx1, by1, bx2, by2); */ drawpolygon(k, NOW, x, y, p->points, p->fill, p->dash); /* 20180914 added fill */ - selectedgroup[i].n=lastpolygon[c]; - store_polygon(-1, x, y, p->points, c, p->sel, p->prop_ptr); + selectedgroup[i].n=xctx.polygons[c]; + store_poly(-1, x, y, p->points, c, p->sel, p->prop_ptr); p->sel=0; my_free(819, &x); my_free(820, &y); @@ -707,52 +708,53 @@ void copy_objects(int what) case ARC: if(c!=k) break; /* - arc_bbox(arc[c][n].x, arc[c][n].y, arc[c][n].r, arc[c][n].a, arc[c][n].b, + arc_bbox(xctx.arc[c][n].x, xctx.arc[c][n].y, xctx.arc[c][n].r, xctx.arc[c][n].a, xctx.arc[c][n].b, &tmp.x1, &tmp.y1, &tmp.x2, &tmp.y2); bbox(ADD, tmp.x1, tmp.y1, tmp.x2, tmp.y2); */ if(rotatelocal) { /* rotate center wrt itself: do nothing */ - rx1 = arc[c][n].x; - ry1 = arc[c][n].y; + rx1 = xctx.arc[c][n].x; + ry1 = xctx.arc[c][n].y; } else { - ROTATION(x1, y_1, arc[c][n].x, arc[c][n].y, rx1,ry1); + ROTATION(x1, y_1, xctx.arc[c][n].x, xctx.arc[c][n].y, rx1,ry1); } - angle = arc[c][n].a; + angle = xctx.arc[c][n].a; if(flip) { - angle = 270.*rot+180.-arc[c][n].b-arc[c][n].a; + angle = 270.*rot+180.-xctx.arc[c][n].b-xctx.arc[c][n].a; } else { - angle = arc[c][n].a+rot*270.; + angle = xctx.arc[c][n].a+rot*270.; } angle = fmod(angle, 360.); if(angle<0.) angle+=360.; - arc[c][n].sel=0; - drawarc(k, ADD, rx1+deltax, ry1+deltay, arc[c][n].r, angle, arc[c][n].b, arc[c][n].fill, arc[c][n].dash); - selectedgroup[i].n=lastarc[c]; + xctx.arc[c][n].sel=0; + drawarc(k, ADD, rx1+deltax, ry1+deltay, + xctx.arc[c][n].r, angle, xctx.arc[c][n].b, xctx.arc[c][n].fill, xctx.arc[c][n].dash); + selectedgroup[i].n=xctx.arcs[c]; store_arc(-1, rx1+deltax, ry1+deltay, - arc[c][n].r, angle, arc[c][n].b, c, SELECTED, arc[c][n].prop_ptr); + xctx.arc[c][n].r, angle, xctx.arc[c][n].b, c, SELECTED, xctx.arc[c][n].prop_ptr); break; case xRECT: if(c!=k) break; - /* bbox(ADD, rect[c][n].x1, rect[c][n].y1, rect[c][n].x2, rect[c][n].y2); */ + /* bbox(ADD, xctx.rect[c][n].x1, xctx.rect[c][n].y1, xctx.rect[c][n].x2, xctx.rect[c][n].y2); */ if(rotatelocal) { - ROTATION(rect[c][n].x1, rect[c][n].y1, rect[c][n].x1, rect[c][n].y1, rx1,ry1); - ROTATION(rect[c][n].x1, rect[c][n].y1, rect[c][n].x2, rect[c][n].y2, rx2,ry2); + ROTATION(xctx.rect[c][n].x1, xctx.rect[c][n].y1, xctx.rect[c][n].x1, xctx.rect[c][n].y1, rx1,ry1); + ROTATION(xctx.rect[c][n].x1, xctx.rect[c][n].y1, xctx.rect[c][n].x2, xctx.rect[c][n].y2, rx2,ry2); } else { - ROTATION(x1, y_1, rect[c][n].x1, rect[c][n].y1, rx1,ry1); - ROTATION(x1, y_1, rect[c][n].x2, rect[c][n].y2, rx2,ry2); + ROTATION(x1, y_1, xctx.rect[c][n].x1, xctx.rect[c][n].y1, rx1,ry1); + ROTATION(x1, y_1, xctx.rect[c][n].x2, xctx.rect[c][n].y2, rx2,ry2); } RECTORDER(rx1,ry1,rx2,ry2); - rect[c][n].sel=0; - drawrect(k, ADD, rx1+deltax, ry1+deltay, rx2+deltax, ry2+deltay, rect[c][n].dash); + xctx.rect[c][n].sel=0; + drawrect(k, ADD, rx1+deltax, ry1+deltay, rx2+deltax, ry2+deltay, xctx.rect[c][n].dash); filledrect(k, ADD, rx1+deltax, ry1+deltay, rx2+deltax, ry2+deltay); - selectedgroup[i].n=lastrect[c]; - storeobject(-1, rx1+deltax, ry1+deltay, - rx2+deltax, ry2+deltay,xRECT, c, SELECTED, rect[c][n].prop_ptr); + selectedgroup[i].n=xctx.rects[c]; + storeobject(-1, rx1+deltax, ry1+deltay, + rx2+deltax, ry2+deltay,xRECT, c, SELECTED, xctx.rect[c][n].prop_ptr); break; case xTEXT: @@ -760,11 +762,11 @@ void copy_objects(int what) check_text_storage(); /* #ifdef HAS_CAIRO - customfont = set_text_custom_font(&textelement[n]); + customfont = set_text_custom_font(&xctx.text[n]); #endif - text_bbox(textelement[n].txt_ptr, textelement[n].xscale, - textelement[n].yscale, textelement[n].rot,textelement[n].flip, textelement[n].hcenter, textelement[n].vcenter, - textelement[n].x0, textelement[n].y0, + text_bbox(xctx.text[n].txt_ptr, xctx.text[n].xscale, + 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); @@ -772,53 +774,53 @@ void copy_objects(int what) bbox(ADD, rx1, ry1, rx2, ry2 ); */ if(rotatelocal) { - ROTATION(textelement[n].x0, textelement[n].y0, textelement[n].x0, textelement[n].y0, rx1,ry1); + ROTATION(xctx.text[n].x0, xctx.text[n].y0, xctx.text[n].x0, xctx.text[n].y0, rx1,ry1); } else { - ROTATION(x1, y_1, textelement[n].x0, textelement[n].y0, rx1,ry1); + ROTATION(x1, y_1, xctx.text[n].x0, xctx.text[n].y0, rx1,ry1); } - textelement[lasttext].txt_ptr=NULL; - my_strdup(229, &textelement[lasttext].txt_ptr,textelement[n].txt_ptr); - textelement[n].sel=0; + xctx.text[xctx.texts].txt_ptr=NULL; + my_strdup(229, &xctx.text[xctx.texts].txt_ptr,xctx.text[n].txt_ptr); + xctx.text[n].sel=0; dbg(2, "copy_objects(): current str=%s\n", - textelement[lasttext].txt_ptr); - textelement[lasttext].x0=rx1+deltax; - textelement[lasttext].y0=ry1+deltay; - textelement[lasttext].rot=(textelement[n].rot + - ( (flip && (textelement[n].rot & 1) ) ? rot+2 : rot) ) & 0x3; - textelement[lasttext].flip=flip^textelement[n].flip; - textelement[lasttext].sel=SELECTED; - textelement[lasttext].prop_ptr=NULL; - textelement[lasttext].font=NULL; - my_strdup(230, &textelement[lasttext].prop_ptr, textelement[n].prop_ptr); - my_strdup(231, &textelement[lasttext].font, get_tok_value(textelement[lasttext].prop_ptr, "font", 0)); + xctx.text[xctx.texts].txt_ptr); + xctx.text[xctx.texts].x0=rx1+deltax; + xctx.text[xctx.texts].y0=ry1+deltay; + xctx.text[xctx.texts].rot=(xctx.text[n].rot + + ( (flip && (xctx.text[n].rot & 1) ) ? rot+2 : rot) ) & 0x3; + xctx.text[xctx.texts].flip=flip^xctx.text[n].flip; + xctx.text[xctx.texts].sel=SELECTED; + xctx.text[xctx.texts].prop_ptr=NULL; + xctx.text[xctx.texts].font=NULL; + my_strdup(230, &xctx.text[xctx.texts].prop_ptr, xctx.text[n].prop_ptr); + my_strdup(231, &xctx.text[xctx.texts].font, get_tok_value(xctx.text[xctx.texts].prop_ptr, "font", 0)); - str = get_tok_value(textelement[lasttext].prop_ptr, "hcenter", 0); - textelement[lasttext].hcenter = strcmp(str, "true") ? 0 : 1; - str = get_tok_value(textelement[lasttext].prop_ptr, "vcenter", 0); - textelement[lasttext].vcenter = strcmp(str, "true") ? 0 : 1; + str = get_tok_value(xctx.text[xctx.texts].prop_ptr, "hcenter", 0); + xctx.text[xctx.texts].hcenter = strcmp(str, "true") ? 0 : 1; + str = get_tok_value(xctx.text[xctx.texts].prop_ptr, "vcenter", 0); + xctx.text[xctx.texts].vcenter = strcmp(str, "true") ? 0 : 1; - str = get_tok_value(textelement[lasttext].prop_ptr, "layer", 0); /*20171206 */ - if(str[0]) textelement[lasttext].layer = atoi(str); - else textelement[lasttext].layer = -1; + str = get_tok_value(xctx.text[xctx.texts].prop_ptr, "layer", 0); + if(str[0]) xctx.text[xctx.texts].layer = atoi(str); + else xctx.text[xctx.texts].layer = -1; - textelement[lasttext].flags = 0; - str = get_tok_value(textelement[lasttext].prop_ptr, "slant", 0); - textelement[lasttext].flags |= strcmp(str, "oblique") ? 0 : TEXT_OBLIQUE; - textelement[lasttext].flags |= strcmp(str, "italic") ? 0 : TEXT_ITALIC; - str = get_tok_value(textelement[lasttext].prop_ptr, "weight", 0); - textelement[lasttext].flags |= strcmp(str, "bold") ? 0 : TEXT_BOLD; + xctx.text[xctx.texts].flags = 0; + str = get_tok_value(xctx.text[xctx.texts].prop_ptr, "slant", 0); + xctx.text[xctx.texts].flags |= strcmp(str, "oblique") ? 0 : TEXT_OBLIQUE; + xctx.text[xctx.texts].flags |= strcmp(str, "italic") ? 0 : TEXT_ITALIC; + str = get_tok_value(xctx.text[xctx.texts].prop_ptr, "weight", 0); + xctx.text[xctx.texts].flags |= strcmp(str, "bold") ? 0 : TEXT_BOLD; - textelement[lasttext].xscale=textelement[n].xscale; - textelement[lasttext].yscale=textelement[n].yscale; + xctx.text[xctx.texts].xscale=xctx.text[n].xscale; + xctx.text[xctx.texts].yscale=xctx.text[n].yscale; - textlayer = textelement[lasttext].layer; /* 20171206 */ + textlayer = xctx.text[xctx.texts].layer; if(textlayer < 0 || textlayer >= cadlayers) textlayer = TEXTLAYER; #ifdef HAS_CAIRO - textfont = textelement[lasttext].font; /* 20171206 */ - if((textfont && textfont[0]) || textelement[lasttext].flags) { - char *font = textelement[lasttext].font; - int flags = textelement[lasttext].flags; + textfont = xctx.text[xctx.texts].font; + if((textfont && textfont[0]) || xctx.text[xctx.texts].flags) { + char *font = xctx.text[xctx.texts].font; + int flags = xctx.text[xctx.texts].flags; cairo_font_slant_t slant; cairo_font_weight_t weight; textfont = (font && font[0]) ? font : cairo_font_name; @@ -832,23 +834,23 @@ void copy_objects(int what) cairo_select_font_face (cairo_save_ctx, textfont, slant, weight); } #endif - draw_string(textlayer, ADD, textelement[lasttext].txt_ptr, /* draw moved txt */ - textelement[lasttext].rot, textelement[lasttext].flip, - textelement[lasttext].hcenter, textelement[lasttext].vcenter, + draw_string(textlayer, ADD, xctx.text[xctx.texts].txt_ptr, /* draw moved txt */ + xctx.text[xctx.texts].rot, xctx.text[xctx.texts].flip, + xctx.text[xctx.texts].hcenter, xctx.text[xctx.texts].vcenter, rx1+deltax,ry1+deltay, - textelement[lasttext].xscale, textelement[lasttext].yscale); + xctx.text[xctx.texts].xscale, xctx.text[xctx.texts].yscale); #ifndef HAS_CAIRO drawrect(textlayer, END, 0.0, 0.0, 0.0, 0.0, 0); drawline(textlayer, END, 0.0, 0.0, 0.0, 0.0, 0); #endif #ifdef HAS_CAIRO - if( (textfont && textfont[0]) || textelement[lasttext].flags) { + if( (textfont && textfont[0]) || xctx.text[xctx.texts].flags) { cairo_restore(cairo_ctx); cairo_restore(cairo_save_ctx); } #endif - selectedgroup[i].n=lasttext; - lasttext++; + selectedgroup[i].n=xctx.texts; + xctx.texts++; dbg(2, "copy_objects(): done copy string\n"); break; case ELEMENT: @@ -860,35 +862,35 @@ void copy_objects(int what) check_inst_storage(); if(rotatelocal) { - ROTATION(inst_ptr[n].x0, inst_ptr[n].y0, inst_ptr[n].x0, inst_ptr[n].y0, rx1,ry1); + ROTATION(xctx.inst[n].x0, xctx.inst[n].y0, xctx.inst[n].x0, xctx.inst[n].y0, rx1,ry1); } else { - ROTATION(x1, y_1, inst_ptr[n].x0, inst_ptr[n].y0, rx1,ry1); + ROTATION(x1, y_1, xctx.inst[n].x0, xctx.inst[n].y0, rx1,ry1); } - inst_ptr[lastinst] = inst_ptr[n]; - inst_ptr[lastinst].prop_ptr=NULL; - inst_ptr[lastinst].instname=NULL; /* 20150409 */ - inst_ptr[lastinst].node=NULL; - inst_ptr[lastinst].name=NULL; - my_strdup(232, &inst_ptr[lastinst].name, inst_ptr[n].name); - my_strdup(233, &inst_ptr[lastinst].prop_ptr, inst_ptr[n].prop_ptr); - my_strdup2(234, &inst_ptr[lastinst].instname, get_tok_value(inst_ptr[n].prop_ptr, "name",0)); /* 20150409 */ - inst_ptr[n].sel=0; - inst_ptr[lastinst].flags = inst_ptr[n].flags; - inst_ptr[lastinst].flags &= ~4; /* do not propagate hilight */ - inst_ptr[lastinst].x0 = rx1+deltax; - inst_ptr[lastinst].y0 = ry1+deltay; - inst_ptr[lastinst].sel = SELECTED; - inst_ptr[lastinst].rot = (inst_ptr[lastinst].rot + - ( (flip && (inst_ptr[lastinst].rot & 1) ) ? rot+2 : rot) ) & 0x3; - inst_ptr[lastinst].flip = (flip? !inst_ptr[n].flip:inst_ptr[n].flip); + xctx.inst[xctx.instances] = xctx.inst[n]; + xctx.inst[xctx.instances].prop_ptr=NULL; + xctx.inst[xctx.instances].instname=NULL; + xctx.inst[xctx.instances].node=NULL; + xctx.inst[xctx.instances].name=NULL; + my_strdup(232, &xctx.inst[xctx.instances].name, xctx.inst[n].name); + my_strdup(233, &xctx.inst[xctx.instances].prop_ptr, xctx.inst[n].prop_ptr); + my_strdup2(234, &xctx.inst[xctx.instances].instname, get_tok_value(xctx.inst[n].prop_ptr, "name",0)); + xctx.inst[n].sel=0; + xctx.inst[xctx.instances].flags = xctx.inst[n].flags; + xctx.inst[xctx.instances].flags &= ~4; /* do not propagate hilight */ + xctx.inst[xctx.instances].x0 = rx1+deltax; + xctx.inst[xctx.instances].y0 = ry1+deltay; + xctx.inst[xctx.instances].sel = SELECTED; + xctx.inst[xctx.instances].rot = (xctx.inst[xctx.instances].rot + + ( (flip && (xctx.inst[xctx.instances].rot & 1) ) ? rot+2 : rot) ) & 0x3; + xctx.inst[xctx.instances].flip = (flip? !xctx.inst[n].flip:xctx.inst[n].flip); /* the newpropcnt argument is zero for the 1st call and used in */ /* new_prop_string() for cleaning some internal caches. */ - if(!newpropcnt) hash_all_names(lastinst); - new_prop_string(lastinst, inst_ptr[n].prop_ptr,newpropcnt++, dis_uniq_names); - my_strdup2(235, &inst_ptr[lastinst].instname, get_tok_value(inst_ptr[lastinst].prop_ptr, "name", 0)); - n=selectedgroup[i].n=lastinst; + if(!newpropcnt) hash_all_names(xctx.instances); + new_prop_string(xctx.instances, xctx.inst[n].prop_ptr,newpropcnt++, dis_uniq_names); + my_strdup2(235, &xctx.inst[xctx.instances].instname, get_tok_value(xctx.inst[xctx.instances].prop_ptr, "name", 0)); + n=selectedgroup[i].n=xctx.instances; - lastinst++; /* must be updated before calling symbol_bbox which triggers prepare_netlist_structs(0)*/ + xctx.instances++; /* must be updated before calling symbol_bbox which triggers prepare_netlist_structs(0)*/ } break; } /* end switch(selectedgroup[i].type) */ @@ -909,22 +911,22 @@ void copy_objects(int what) prepare_netlist_structs(0); } } - + for(i = 0; i < lastselected; i++) { n = selectedgroup[i].n; if(k == 0) { if(selectedgroup[i].type == ELEMENT) { int p; - symbol_bbox(n, &inst_ptr[n].x1, &inst_ptr[n].y1, &inst_ptr[n].x2, &inst_ptr[n].y2 ); /* 20171201 */ - bbox(ADD, inst_ptr[n].x1, inst_ptr[n].y1, inst_ptr[n].x2, inst_ptr[n].y2 ); - if(show_pin_net_names) for(p = 0; p < (inst_ptr[n].ptr + instdef)->rects[PINLAYER]; p++) { - if( inst_ptr[n].node && inst_ptr[n].node[p]) { - find_inst_to_be_redrawn(inst_ptr[n].node[p]); + symbol_bbox(n, &xctx.inst[n].x1, &xctx.inst[n].y1, &xctx.inst[n].x2, &xctx.inst[n].y2 ); + bbox(ADD, xctx.inst[n].x1, xctx.inst[n].y1, xctx.inst[n].x2, xctx.inst[n].y2 ); + if(show_pin_net_names) for(p = 0; p < (xctx.inst[n].ptr + xctx.sym)->rects[PINLAYER]; p++) { + if( xctx.inst[n].node && xctx.inst[n].node[p]) { + find_inst_to_be_redrawn(xctx.inst[n].node[p]); } } } if(show_pin_net_names && selectedgroup[i].type == WIRE) { - find_inst_to_be_redrawn(wire[n].node); + find_inst_to_be_redrawn(xctx.wire[n].node); } } } @@ -936,7 +938,7 @@ void copy_objects(int what) drawline(k, END, 0.0, 0.0, 0.0, 0.0, 0); } /* end for(k=0;krects[PINLAYER]; p++) { - if( inst_ptr[n].node && inst_ptr[n].node[p]) { - find_inst_to_be_redrawn(inst_ptr[n].node[p]); + symbol_bbox(n, &xctx.inst[n].x1, &xctx.inst[n].y1, &xctx.inst[n].x2, &xctx.inst[n].y2 ); + bbox(ADD, xctx.inst[n].x1, xctx.inst[n].y1, xctx.inst[n].x2, xctx.inst[n].y2 ); + if(show_pin_net_names) for(p = 0; p < (xctx.inst[n].ptr + xctx.sym)->rects[PINLAYER]; p++) { + if( xctx.inst[n].node && xctx.inst[n].node[p]) { + find_inst_to_be_redrawn(xctx.inst[n].node[p]); } } } if(show_pin_net_names && selectedgroup[i].type == WIRE) { - find_inst_to_be_redrawn(wire[n].node); + find_inst_to_be_redrawn(xctx.wire[n].node); } } if(show_pin_net_names) find_inst_hash_clear(); @@ -1065,99 +1067,101 @@ void move_objects(int what, int merge, double dx, double dy) firstw = 0; } if(k == 0) { - if(wire[n].bus){ /* 20171201 */ + if(xctx.wire[n].bus){ int ov, y1, y2; ov = bus_width> cadhalfdotsize ? bus_width : CADHALFDOTSIZE; - if(wire[n].y1 < wire[n].y2) { y1 = wire[n].y1-ov; y2 = wire[n].y2+ov; } - else { y1 = wire[n].y1+ov; y2 = wire[n].y2-ov; } - bbox(ADD, wire[n].x1-ov, y1 , wire[n].x2+ov , y2 ); + if(xctx.wire[n].y1 < xctx.wire[n].y2) { y1 = xctx.wire[n].y1-ov; y2 = xctx.wire[n].y2+ov; } + else { y1 = xctx.wire[n].y1+ov; y2 = xctx.wire[n].y2-ov; } + bbox(ADD, xctx.wire[n].x1-ov, y1 , xctx.wire[n].x2+ov , y2 ); } else { int ov, y1, y2; ov = cadhalfdotsize; - if(wire[n].y1 < wire[n].y2) { y1 = wire[n].y1-ov; y2 = wire[n].y2+ov; } - else { y1 = wire[n].y1+ov; y2 = wire[n].y2-ov; } - bbox(ADD, wire[n].x1-ov, y1 , wire[n].x2+ov , y2 ); + if(xctx.wire[n].y1 < xctx.wire[n].y2) { y1 = xctx.wire[n].y1-ov; y2 = xctx.wire[n].y2+ov; } + else { y1 = xctx.wire[n].y1+ov; y2 = xctx.wire[n].y2-ov; } + bbox(ADD, xctx.wire[n].x1-ov, y1 , xctx.wire[n].x2+ov , y2 ); } if(rotatelocal) { - ROTATION(wire[n].x1, wire[n].y1, wire[n].x1, wire[n].y1, rx1,ry1); - ROTATION(wire[n].x1, wire[n].y1, wire[n].x2, wire[n].y2, rx2,ry2); + ROTATION(xctx.wire[n].x1, xctx.wire[n].y1, xctx.wire[n].x1, xctx.wire[n].y1, rx1,ry1); + ROTATION(xctx.wire[n].x1, xctx.wire[n].y1, xctx.wire[n].x2, xctx.wire[n].y2, rx2,ry2); } else { - ROTATION(x1, y_1, wire[n].x1, wire[n].y1, rx1,ry1); - ROTATION(x1, y_1, wire[n].x2, wire[n].y2, rx2,ry2); + ROTATION(x1, y_1, xctx.wire[n].x1, xctx.wire[n].y1, rx1,ry1); + ROTATION(x1, y_1, xctx.wire[n].x2, xctx.wire[n].y2, rx2,ry2); } - - if( wire[n].sel & (SELECTED|SELECTED1) ) + + if( xctx.wire[n].sel & (SELECTED|SELECTED1) ) { rx1+=deltax; ry1+=deltay; } - if( wire[n].sel & (SELECTED|SELECTED2) ) + if( xctx.wire[n].sel & (SELECTED|SELECTED2) ) { rx2+=deltax; ry2+=deltay; } - wire[n].x1=rx1; - wire[n].y1=ry1; + xctx.wire[n].x1=rx1; + xctx.wire[n].y1=ry1; ORDER(rx1,ry1,rx2,ry2); - if( wire[n].x1 == rx2 && wire[n].y1 == ry2) + if( xctx.wire[n].x1 == rx2 && xctx.wire[n].y1 == ry2) { - if(wire[n].sel == SELECTED1) wire[n].sel = SELECTED2; - else if(wire[n].sel == SELECTED2) wire[n].sel = SELECTED1; + if(xctx.wire[n].sel == SELECTED1) xctx.wire[n].sel = SELECTED2; + else if(xctx.wire[n].sel == SELECTED2) xctx.wire[n].sel = SELECTED1; } - wire[n].x1=rx1; - wire[n].y1=ry1; - wire[n].x2=rx2; - wire[n].y2=ry2; + xctx.wire[n].x1=rx1; + xctx.wire[n].y1=ry1; + xctx.wire[n].x2=rx2; + xctx.wire[n].y2=ry2; } else if(k == WIRELAYER) { - if(wire[n].bus) - drawline(WIRELAYER, THICK, wire[n].x1, wire[n].y1, wire[n].x2, wire[n].y2, 0); + if(xctx.wire[n].bus) + drawline(WIRELAYER, THICK, xctx.wire[n].x1, xctx.wire[n].y1, xctx.wire[n].x2, xctx.wire[n].y2, 0); else - drawline(WIRELAYER, ADD, wire[n].x1, wire[n].y1, wire[n].x2, wire[n].y2, 0); + drawline(WIRELAYER, ADD, xctx.wire[n].x1, xctx.wire[n].y1, xctx.wire[n].x2, xctx.wire[n].y2, 0); } break; case LINE: - if(c!=k) break; - bbox(ADD, line[c][n].x1, line[c][n].y1, line[c][n].x2, line[c][n].y2); + if(c!=k) break; + bbox(ADD, xctx.line[c][n].x1, xctx.line[c][n].y1, xctx.line[c][n].x2, xctx.line[c][n].y2); if(rotatelocal) { - ROTATION(line[c][n].x1, line[c][n].y1, line[c][n].x1, line[c][n].y1, rx1,ry1); - ROTATION(line[c][n].x1, line[c][n].y1, line[c][n].x2, line[c][n].y2, rx2,ry2); + ROTATION(xctx.line[c][n].x1, xctx.line[c][n].y1, xctx.line[c][n].x1, xctx.line[c][n].y1, rx1,ry1); + ROTATION(xctx.line[c][n].x1, xctx.line[c][n].y1, xctx.line[c][n].x2, xctx.line[c][n].y2, rx2,ry2); } else { - ROTATION(x1, y_1, line[c][n].x1, line[c][n].y1, rx1,ry1); - ROTATION(x1, y_1, line[c][n].x2, line[c][n].y2, rx2,ry2); + ROTATION(x1, y_1, xctx.line[c][n].x1, xctx.line[c][n].y1, rx1,ry1); + ROTATION(x1, y_1, xctx.line[c][n].x2, xctx.line[c][n].y2, rx2,ry2); } - if( line[c][n].sel & (SELECTED|SELECTED1) ) + if( xctx.line[c][n].sel & (SELECTED|SELECTED1) ) { rx1+=deltax; ry1+=deltay; } - if( line[c][n].sel & (SELECTED|SELECTED2) ) + if( xctx.line[c][n].sel & (SELECTED|SELECTED2) ) { rx2+=deltax; ry2+=deltay; } - line[c][n].x1=rx1; - line[c][n].y1=ry1; + xctx.line[c][n].x1=rx1; + xctx.line[c][n].y1=ry1; ORDER(rx1,ry1,rx2,ry2); - if( line[c][n].x1 == rx2 && line[c][n].y1 == ry2) + if( xctx.line[c][n].x1 == rx2 && xctx.line[c][n].y1 == ry2) { - if(line[c][n].sel == SELECTED1) line[c][n].sel = SELECTED2; - else if(line[c][n].sel == SELECTED2) line[c][n].sel = SELECTED1; + if(xctx.line[c][n].sel == SELECTED1) xctx.line[c][n].sel = SELECTED2; + else if(xctx.line[c][n].sel == SELECTED2) xctx.line[c][n].sel = SELECTED1; } - line[c][n].x1=rx1; - line[c][n].y1=ry1; - line[c][n].x2=rx2; - line[c][n].y2=ry2; - if(line[c][n].bus) - drawline(k, THICK, line[c][n].x1, line[c][n].y1, line[c][n].x2, line[c][n].y2, line[c][n].dash); + xctx.line[c][n].x1=rx1; + xctx.line[c][n].y1=ry1; + xctx.line[c][n].x2=rx2; + xctx.line[c][n].y2=ry2; + if(xctx.line[c][n].bus) + drawline(k, THICK, xctx.line[c][n].x1, xctx.line[c][n].y1, + xctx.line[c][n].x2, xctx.line[c][n].y2, xctx.line[c][n].dash); else - drawline(k, ADD, line[c][n].x1, line[c][n].y1, line[c][n].x2, line[c][n].y2, line[c][n].dash); + drawline(k, ADD, xctx.line[c][n].x1, xctx.line[c][n].y1, + xctx.line[c][n].x2, xctx.line[c][n].y2, xctx.line[c][n].dash); break; - case POLYGON: /* 20171115 */ + case POLYGON: if(c!=k) break; { - xPolygon *p = &polygon[c][n]; + xPoly *p = &xctx.poly[c][n]; double bx1=0., by1=0., bx2=0., by2=0.; int j; double savex0, savey0; @@ -1179,7 +1183,7 @@ void move_objects(int what, int merge, double dx, double dy) p->x[j] = rx1+deltax; p->y[j] = ry1+deltay; } - + } bbox(ADD, bx1, by1, bx2, by2); drawpolygon(k, NOW, p->x, p->y, p->points, p->fill, p->dash); @@ -1188,103 +1192,104 @@ void move_objects(int what, int merge, double dx, double dy) case ARC: if(c!=k) break; - if(arc[c][n].fill) - arc_bbox(arc[c][n].x, arc[c][n].y, arc[c][n].r, 0, 360, - &tmp.x1, &tmp.y1, &tmp.x2, &tmp.y2); + if(xctx.arc[c][n].fill) + arc_bbox(xctx.arc[c][n].x, xctx.arc[c][n].y, xctx.arc[c][n].r, 0, 360, + &tmp.x1, &tmp.y1, &tmp.x2, &tmp.y2); else - arc_bbox(arc[c][n].x, arc[c][n].y, arc[c][n].r, arc[c][n].a, arc[c][n].b, - &tmp.x1, &tmp.y1, &tmp.x2, &tmp.y2); + arc_bbox(xctx.arc[c][n].x, xctx.arc[c][n].y, xctx.arc[c][n].r, xctx.arc[c][n].a, xctx.arc[c][n].b, + &tmp.x1, &tmp.y1, &tmp.x2, &tmp.y2); dbg(1, "move_objects(): arc_bbox: %g %g %g %g\n", tmp.x1, tmp.y1, tmp.x2, tmp.y2); bbox(ADD, tmp.x1, tmp.y1, tmp.x2, tmp.y2); if(rotatelocal) { /* rotate center wrt itself: do nothing */ - rx1 = arc[c][n].x; - ry1 = arc[c][n].y; + rx1 = xctx.arc[c][n].x; + ry1 = xctx.arc[c][n].y; } else { - ROTATION(x1, y_1, arc[c][n].x, arc[c][n].y, rx1,ry1); + ROTATION(x1, y_1, xctx.arc[c][n].x, xctx.arc[c][n].y, rx1,ry1); } - angle = arc[c][n].a; + angle = xctx.arc[c][n].a; if(flip) { - angle = 270.*rot+180.-arc[c][n].b-arc[c][n].a; + angle = 270.*rot+180.-xctx.arc[c][n].b-xctx.arc[c][n].a; } else { - angle = arc[c][n].a+rot*270.; + angle = xctx.arc[c][n].a+rot*270.; } angle = fmod(angle, 360.); if(angle<0.) angle+=360.; - if(arc[c][n].sel == SELECTED) { - arc[c][n].x = rx1+deltax; - arc[c][n].y = ry1+deltay; - arc[c][n].a = angle; - } else if(arc[c][n].sel == SELECTED1) { - arc[c][n].x = rx1; - arc[c][n].y = ry1; - if(arc[c][n].r+deltax) arc[c][n].r = fabs(arc[c][n].r+deltax); - arc[c][n].a = angle; - } else if(arc[c][n].sel == SELECTED2) { + if(xctx.arc[c][n].sel == SELECTED) { + xctx.arc[c][n].x = rx1+deltax; + xctx.arc[c][n].y = ry1+deltay; + xctx.arc[c][n].a = angle; + } else if(xctx.arc[c][n].sel == SELECTED1) { + xctx.arc[c][n].x = rx1; + xctx.arc[c][n].y = ry1; + if(xctx.arc[c][n].r+deltax) xctx.arc[c][n].r = fabs(xctx.arc[c][n].r+deltax); + xctx.arc[c][n].a = angle; + } else if(xctx.arc[c][n].sel == SELECTED2) { angle = ROUND(fmod(atan2(-deltay, deltax)*180./XSCH_PI+angle, 360.)); if(angle<0.) angle +=360.; - arc[c][n].x = rx1; - arc[c][n].y = ry1; - arc[c][n].a = angle; - } else if(arc[c][n].sel==SELECTED3) { - angle = ROUND(fmod(atan2(-deltay, deltax)*180./XSCH_PI+arc[c][n].b, 360.)); + xctx.arc[c][n].x = rx1; + xctx.arc[c][n].y = ry1; + xctx.arc[c][n].a = angle; + } else if(xctx.arc[c][n].sel==SELECTED3) { + angle = ROUND(fmod(atan2(-deltay, deltax)*180./XSCH_PI+xctx.arc[c][n].b, 360.)); if(angle<0.) angle +=360.; if(angle==0) angle=360.; - arc[c][n].x = rx1; - arc[c][n].y = ry1; - arc[c][n].b = angle; + xctx.arc[c][n].x = rx1; + xctx.arc[c][n].y = ry1; + xctx.arc[c][n].b = angle; } - drawarc(k, ADD, arc[c][n].x, arc[c][n].y, arc[c][n].r, arc[c][n].a, arc[c][n].b, arc[c][n].fill, arc[c][n].dash); + drawarc(k, ADD, xctx.arc[c][n].x, xctx.arc[c][n].y, xctx.arc[c][n].r, + xctx.arc[c][n].a, xctx.arc[c][n].b, xctx.arc[c][n].fill, xctx.arc[c][n].dash); break; case xRECT: if(c!=k) break; - bbox(ADD, rect[c][n].x1, rect[c][n].y1, rect[c][n].x2, rect[c][n].y2); + bbox(ADD, xctx.rect[c][n].x1, xctx.rect[c][n].y1, xctx.rect[c][n].x2, xctx.rect[c][n].y2); if(rotatelocal) { - ROTATION(rect[c][n].x1, rect[c][n].y1, rect[c][n].x1, rect[c][n].y1, rx1,ry1); - ROTATION(rect[c][n].x1, rect[c][n].y1, rect[c][n].x2, rect[c][n].y2, rx2,ry2); + ROTATION(xctx.rect[c][n].x1, xctx.rect[c][n].y1, xctx.rect[c][n].x1, xctx.rect[c][n].y1, rx1,ry1); + ROTATION(xctx.rect[c][n].x1, xctx.rect[c][n].y1, xctx.rect[c][n].x2, xctx.rect[c][n].y2, rx2,ry2); } else { - ROTATION(x1, y_1, rect[c][n].x1, rect[c][n].y1, rx1,ry1); - ROTATION(x1, y_1, rect[c][n].x2, rect[c][n].y2, rx2,ry2); + ROTATION(x1, y_1, xctx.rect[c][n].x1, xctx.rect[c][n].y1, rx1,ry1); + ROTATION(x1, y_1, xctx.rect[c][n].x2, xctx.rect[c][n].y2, rx2,ry2); } - if( rect[c][n].sel == SELECTED) { + if( xctx.rect[c][n].sel == SELECTED) { rx1+=deltax; ry1+=deltay; rx2+=deltax; ry2+=deltay; } - else if( rect[c][n].sel == SELECTED1) { /* 20070302 stretching on rectangles */ + else if( xctx.rect[c][n].sel == SELECTED1) { /* 20070302 stretching on rectangles */ rx1+=deltax; ry1+=deltay; } - else if( rect[c][n].sel == SELECTED2) { + else if( xctx.rect[c][n].sel == SELECTED2) { rx2+=deltax; ry1+=deltay; } - else if( rect[c][n].sel == SELECTED3) { + else if( xctx.rect[c][n].sel == SELECTED3) { rx1+=deltax; ry2+=deltay; } - else if( rect[c][n].sel == SELECTED4) { + else if( xctx.rect[c][n].sel == SELECTED4) { rx2+=deltax; ry2+=deltay; } - else if(rect[c][n].sel==(SELECTED1|SELECTED2)) + else if(xctx.rect[c][n].sel==(SELECTED1|SELECTED2)) { ry1+=deltay; } - else if(rect[c][n].sel==(SELECTED3|SELECTED4)) + else if(xctx.rect[c][n].sel==(SELECTED3|SELECTED4)) { ry2+=deltay; } - else if(rect[c][n].sel==(SELECTED1|SELECTED3)) + else if(xctx.rect[c][n].sel==(SELECTED1|SELECTED3)) { rx1+=deltax; - } - else if(rect[c][n].sel==(SELECTED2|SELECTED4)) + } + else if(xctx.rect[c][n].sel==(SELECTED2|SELECTED4)) { rx2+=deltax; } @@ -1292,89 +1297,90 @@ void move_objects(int what, int merge, double dx, double dy) tx1 = rx1; ty1 = ry1; RECTORDER(rx1,ry1,rx2,ry2); - - if( rx2 == tx1) { /*20070302 */ - if(rect[c][n].sel==SELECTED1) rect[c][n].sel = SELECTED2; - else if(rect[c][n].sel==SELECTED2) rect[c][n].sel = SELECTED1; - else if(rect[c][n].sel==SELECTED3) rect[c][n].sel = SELECTED4; - else if(rect[c][n].sel==SELECTED4) rect[c][n].sel = SELECTED3; + + if( rx2 == tx1) { + if(xctx.rect[c][n].sel==SELECTED1) xctx.rect[c][n].sel = SELECTED2; + else if(xctx.rect[c][n].sel==SELECTED2) xctx.rect[c][n].sel = SELECTED1; + else if(xctx.rect[c][n].sel==SELECTED3) xctx.rect[c][n].sel = SELECTED4; + else if(xctx.rect[c][n].sel==SELECTED4) xctx.rect[c][n].sel = SELECTED3; } if( ry2 == ty1) { - if(rect[c][n].sel==SELECTED1) rect[c][n].sel = SELECTED3; - else if(rect[c][n].sel==SELECTED3) rect[c][n].sel = SELECTED1; - else if(rect[c][n].sel==SELECTED2) rect[c][n].sel = SELECTED4; - else if(rect[c][n].sel==SELECTED4) rect[c][n].sel = SELECTED2; + if(xctx.rect[c][n].sel==SELECTED1) xctx.rect[c][n].sel = SELECTED3; + else if(xctx.rect[c][n].sel==SELECTED3) xctx.rect[c][n].sel = SELECTED1; + else if(xctx.rect[c][n].sel==SELECTED2) xctx.rect[c][n].sel = SELECTED4; + else if(xctx.rect[c][n].sel==SELECTED4) xctx.rect[c][n].sel = SELECTED2; } - - rect[c][n].x1 = rx1; - rect[c][n].y1 = ry1; - rect[c][n].x2 = rx2; - rect[c][n].y2 = ry2; - drawrect(k, ADD, rect[c][n].x1, rect[c][n].y1, rect[c][n].x2, rect[c][n].y2, rect[c][n].dash); - filledrect(c, ADD, rect[c][n].x1, rect[c][n].y1, - rect[c][n].x2, rect[c][n].y2); - + + xctx.rect[c][n].x1 = rx1; + xctx.rect[c][n].y1 = ry1; + xctx.rect[c][n].x2 = rx2; + xctx.rect[c][n].y2 = ry2; + drawrect(k, ADD, xctx.rect[c][n].x1, xctx.rect[c][n].y1, + xctx.rect[c][n].x2, xctx.rect[c][n].y2, xctx.rect[c][n].dash); + filledrect(c, ADD, xctx.rect[c][n].x1, xctx.rect[c][n].y1, + xctx.rect[c][n].x2, xctx.rect[c][n].y2); + break; case xTEXT: if(k!=TEXTLAYER) break; #ifdef HAS_CAIRO - customfont = set_text_custom_font(&textelement[n]); + customfont = set_text_custom_font(&xctx.text[n]); #endif - text_bbox(textelement[n].txt_ptr, textelement[n].xscale, - textelement[n].yscale, textelement[n].rot,textelement[n].flip, textelement[n].hcenter, - textelement[n].vcenter, textelement[n].x0, textelement[n].y0, &rx1,&ry1, &rx2,&ry2); + text_bbox(xctx.text[n].txt_ptr, xctx.text[n].xscale, + 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); #endif bbox(ADD, rx1, ry1, rx2, ry2 ); - + if(rotatelocal) { - ROTATION(textelement[n].x0, textelement[n].y0, textelement[n].x0, textelement[n].y0, rx1,ry1); + ROTATION(xctx.text[n].x0, xctx.text[n].y0, xctx.text[n].x0, xctx.text[n].y0, rx1,ry1); } else { - ROTATION(x1, y_1, textelement[n].x0, textelement[n].y0, rx1,ry1); + ROTATION(x1, y_1, xctx.text[n].x0, xctx.text[n].y0, rx1,ry1); } - - textelement[n].x0=rx1+deltax; - textelement[n].y0=ry1+deltay; - textelement[n].rot=(textelement[n].rot + - ( (flip && (textelement[n].rot & 1) ) ? rot+2 : rot) ) & 0x3; - textelement[n].flip=flip^textelement[n].flip; - - textlayer = textelement[n].layer; /* 20171206 */ + + xctx.text[n].x0=rx1+deltax; + xctx.text[n].y0=ry1+deltay; + xctx.text[n].rot=(xctx.text[n].rot + + ( (flip && (xctx.text[n].rot & 1) ) ? rot+2 : rot) ) & 0x3; + xctx.text[n].flip=flip^xctx.text[n].flip; + + textlayer = xctx.text[n].layer; if(textlayer < 0 || textlayer >= cadlayers) textlayer = TEXTLAYER; #ifdef HAS_CAIRO - textfont = textelement[n].font; /* 20171206 */ - if((textfont && textfont[0]) || textelement[n].flags) { + textfont = xctx.text[n].font; + if((textfont && textfont[0]) || xctx.text[n].flags) { cairo_font_slant_t slant; cairo_font_weight_t weight; - textfont = (textelement[n].font && textelement[n].font[0]) ? textelement[n].font : cairo_font_name; - weight = ( textelement[n].flags & TEXT_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL; + textfont = (xctx.text[n].font && xctx.text[n].font[0]) ? xctx.text[n].font : cairo_font_name; + weight = ( xctx.text[n].flags & TEXT_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL; slant = CAIRO_FONT_SLANT_NORMAL; - if(textelement[n].flags & TEXT_ITALIC) slant = CAIRO_FONT_SLANT_ITALIC; - if(textelement[n].flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE; + 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(cairo_save_ctx); cairo_select_font_face (cairo_ctx, textfont, slant, weight); cairo_select_font_face (cairo_save_ctx, textfont, slant, weight); } #endif - draw_string(textlayer, ADD, textelement[n].txt_ptr, /* draw moved txt */ - textelement[n].rot, textelement[n].flip, textelement[n].hcenter, textelement[n].vcenter, - textelement[n].x0, textelement[n].y0, - textelement[n].xscale, textelement[n].yscale); + draw_string(textlayer, ADD, xctx.text[n].txt_ptr, /* draw moved txt */ + xctx.text[n].rot, xctx.text[n].flip, xctx.text[n].hcenter, xctx.text[n].vcenter, + xctx.text[n].x0, xctx.text[n].y0, + xctx.text[n].xscale, xctx.text[n].yscale); #ifndef HAS_CAIRO drawrect(textlayer, END, 0.0, 0.0, 0.0, 0.0, 0); drawline(textlayer, END, 0.0, 0.0, 0.0, 0.0, 0); #endif #ifdef HAS_CAIRO - if( (textfont && textfont[0]) || textelement[n].flags) { + if( (textfont && textfont[0]) || xctx.text[n].flags) { cairo_restore(cairo_ctx); cairo_restore(cairo_save_ctx); } #endif break; - + case ELEMENT: if(k==0) { if(firsti) { @@ -1382,15 +1388,15 @@ void move_objects(int what, int merge, double dx, double dy) firsti = 0; } if(rotatelocal) { - ROTATION(inst_ptr[n].x0, inst_ptr[n].y0, inst_ptr[n].x0, inst_ptr[n].y0, rx1,ry1); + ROTATION(xctx.inst[n].x0, xctx.inst[n].y0, xctx.inst[n].x0, xctx.inst[n].y0, rx1,ry1); } else { - ROTATION(x1, y_1, inst_ptr[n].x0, inst_ptr[n].y0, rx1,ry1); + ROTATION(x1, y_1, xctx.inst[n].x0, xctx.inst[n].y0, rx1,ry1); } - inst_ptr[n].x0 = rx1+deltax; - inst_ptr[n].y0 = ry1+deltay; - inst_ptr[n].rot = (inst_ptr[n].rot + - ( (flip && (inst_ptr[n].rot & 1) ) ? rot+2 : rot) ) & 0x3; - inst_ptr[n].flip = flip ^ inst_ptr[n].flip; + xctx.inst[n].x0 = rx1+deltax; + xctx.inst[n].y0 = ry1+deltay; + xctx.inst[n].rot = (xctx.inst[n].rot + + ( (flip && (xctx.inst[n].rot & 1) ) ? rot+2 : rot) ) & 0x3; + xctx.inst[n].flip = flip ^ xctx.inst[n].flip; } break; @@ -1413,33 +1419,33 @@ void move_objects(int what, int merge, double dx, double dy) if(k == 0) { if(selectedgroup[i].type == ELEMENT) { int p; - symbol_bbox(n, &inst_ptr[n].x1, &inst_ptr[n].y1, &inst_ptr[n].x2, &inst_ptr[n].y2 ); /* 20171201 */ - bbox(ADD, inst_ptr[n].x1, inst_ptr[n].y1, inst_ptr[n].x2, inst_ptr[n].y2 ); - if(show_pin_net_names) for(p = 0; p < (inst_ptr[n].ptr + instdef)->rects[PINLAYER]; p++) { - if( inst_ptr[n].node && inst_ptr[n].node[p]) { - find_inst_to_be_redrawn(inst_ptr[n].node[p]); + symbol_bbox(n, &xctx.inst[n].x1, &xctx.inst[n].y1, &xctx.inst[n].x2, &xctx.inst[n].y2 ); + bbox(ADD, xctx.inst[n].x1, xctx.inst[n].y1, xctx.inst[n].x2, xctx.inst[n].y2 ); + if(show_pin_net_names) for(p = 0; p < (xctx.inst[n].ptr + xctx.sym)->rects[PINLAYER]; p++) { + if( xctx.inst[n].node && xctx.inst[n].node[p]) { + find_inst_to_be_redrawn(xctx.inst[n].node[p]); } } } if(show_pin_net_names && selectedgroup[i].type == WIRE) { - find_inst_to_be_redrawn(wire[n].node); + find_inst_to_be_redrawn(xctx.wire[n].node); } } /* draw_symbol(ADD,k, n,k, 0, 0, 0.0, 0.0); */ } if(show_pin_net_names) find_inst_hash_clear(); - filledrect(k, END, 0.0, 0.0, 0.0, 0.0); + filledrect(k, END, 0.0, 0.0, 0.0, 0.0); drawarc(k, END, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0); drawrect(k, END, 0.0, 0.0, 0.0, 0.0, 0); drawline(k, END, 0.0, 0.0, 0.0, 0.0, 0); } /*end for(k=0;krects[PINLAYER] ; + + rects=(xctx.inst[i].ptr+ xctx.sym)->rects[PINLAYER] ; if(j>=rects) /* generic pins */ { - rect=(inst_ptr[i].ptr+instdef)->boxptr[GENERICLAYER]; - x0=(rect[j-rects].x1+rect[j-rects].x2)/2; - y0=(rect[j-rects].y1+rect[j-rects].y2)/2; - prop_ptr = rect[j-rects].prop_ptr; + rct=(xctx.inst[i].ptr+ xctx.sym)->rect[GENERICLAYER]; + x0=(rct[j-rects].x1+rct[j-rects].x2)/2; + y0=(rct[j-rects].y1+rct[j-rects].y2)/2; + prop_ptr = rct[j-rects].prop_ptr; } else { - rect=(inst_ptr[i].ptr+instdef)->boxptr[PINLAYER]; - x0=(rect[j].x1+rect[j].x2)/2; - y0=(rect[j].y1+rect[j].y2)/2; - prop_ptr = rect[j].prop_ptr; + rct=(xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER]; + x0=(rct[j].x1+rct[j].x2)/2; + y0=(rct[j].y1+rct[j].y2)/2; + prop_ptr = rct[j].prop_ptr; } if(jnext) { - wire[wptr->n].end1 = wire[wptr->n].end2 = -1; + xctx.wire[wptr->n].end1 = xctx.wire[wptr->n].end2 = -1; } } } @@ -365,18 +365,18 @@ void hash_wires(void) { int n; - if(prepared_hash_wires) return; + if(prepared_hash_wires) return; del_wire_table(); - for(n=0; nn].node) {ptr2=ptr2->next; continue;} /* 20171207 net already checked. Move on */ + if(xctx.wire[ptr2->n].node) {ptr2=ptr2->next; continue;} /* 20171207 net already checked. Move on */ if(ptr2->n != k) { /* 20171204 avoid checking wire against itself */ - touches = touch(wire[k].x1,wire[k].y1,wire[k].x2,wire[k].y2, - wire[ptr2->n].x1,wire[ptr2->n].y1) || - touch(wire[k].x1,wire[k].y1,wire[k].x2,wire[k].y2, - wire[ptr2->n].x2,wire[ptr2->n].y2) || - touch(wire[ptr2->n].x1,wire[ptr2->n].y1,wire[ptr2->n].x2, - wire[ptr2->n].y2, wire[k].x1,wire[k].y1) || - touch(wire[ptr2->n].x1,wire[ptr2->n].y1,wire[ptr2->n].x2, - wire[ptr2->n].y2, wire[k].x2,wire[k].y2); + touches = touch(xctx.wire[k].x1,xctx.wire[k].y1,xctx.wire[k].x2,xctx.wire[k].y2, + xctx.wire[ptr2->n].x1,xctx.wire[ptr2->n].y1) || + touch(xctx.wire[k].x1,xctx.wire[k].y1,xctx.wire[k].x2,xctx.wire[k].y2, + xctx.wire[ptr2->n].x2,xctx.wire[ptr2->n].y2) || + touch(xctx.wire[ptr2->n].x1,xctx.wire[ptr2->n].y1,xctx.wire[ptr2->n].x2, + xctx.wire[ptr2->n].y2, xctx.wire[k].x1,xctx.wire[k].y1) || + touch(xctx.wire[ptr2->n].x1,xctx.wire[ptr2->n].y1,xctx.wire[ptr2->n].x2, + xctx.wire[ptr2->n].y2, xctx.wire[k].x2,xctx.wire[k].y2); if( touches ) { - my_strdup(239, &wire[ptr2->n].node, wire[k].node); - my_strdup(240, &wire[ptr2->n].prop_ptr, - subst_token(wire[ptr2->n].prop_ptr, "lab", wire[ptr2->n].node)); + my_strdup(239, &xctx.wire[ptr2->n].node, xctx.wire[k].node); + my_strdup(240, &xctx.wire[ptr2->n].prop_ptr, + subst_token(xctx.wire[ptr2->n].prop_ptr, "lab", xctx.wire[ptr2->n].node)); wirecheck(ptr2->n); /* recursive check */ } } @@ -541,7 +541,7 @@ int get_unnamed_node(int what, int mult,int node) if (what==0) /* initialize unnamed node data structures */ { new_node=0; - my_free(828, &node_mult); + my_free(828, &node_mult); node_mult_size=0; return 0; } @@ -553,7 +553,7 @@ int get_unnamed_node(int what, int mult,int node) node_mult_size += CADCHUNKALLOC; my_realloc(242, &node_mult, sizeof(int) * node_mult_size ); for (i=node_mult_size-CADCHUNKALLOC;i0 && prepared_netlist_structs) return; /* 20160413 */ - else if (!for_netlist && prepared_hilight_structs) return; /* 20171210 */ - else delete_netlist_structs(); - if(netlist_count == 0 ) startlevel = currentsch; - print_erc = netlist_count == 0 || startlevel < currentsch; + if (for_netlist>0 && prepared_netlist_structs) return; + else if (!for_netlist && prepared_hilight_structs) return; + else delete_netlist_structs(); + if(netlist_count == 0 ) startlevel = xctx.currsch; + print_erc = netlist_count == 0 || startlevel < xctx.currsch; if (for_netlist>0) { - my_snprintf(nn, S(nn), "-----------%s", schematic[currentsch]); + my_snprintf(nn, S(nn), "-----------%s", xctx.sch[xctx.currsch]); statusmsg(nn,2); } /* reset wire & inst node labels */ dbg(1, "prepare_netlist_structs(): resetting node hash tables\n"); hash_wires(); - for (i=0;irects[PINLAYER] + - (inst_ptr[i].ptr+instdef)->rects[GENERICLAYER]; + rects=(xctx.inst[i].ptr+ xctx.sym)->rects[PINLAYER] + + (xctx.inst[i].ptr+ xctx.sym)->rects[GENERICLAYER]; if (rects > 0) { - inst_ptr[i].node = my_malloc(247, sizeof(char *) * rects); + xctx.inst[i].node = my_malloc(247, sizeof(char *) * rects); for (j=0;jtype); /* 20150409 */ - if(print_erc && (!inst_ptr[i].instname || !inst_ptr[i].instname[0]) ) { + my_strdup(248, &type,(xctx.inst[i].ptr+ xctx.sym)->type); + if(print_erc && (!xctx.inst[i].instname || !xctx.inst[i].instname[0]) ) { char str[2048]; - my_snprintf(str, S(str), "instance: %d (%s): no name attribute set", i, inst_ptr[i].name); + my_snprintf(str, S(str), "instance: %d (%s): no name attribute set", i, xctx.inst[i].name); statusmsg(str,2); - inst_ptr[i].flags |=4; + xctx.inst[i].flags |=4; hilight_nets=1; } if(print_erc && (!type || !type[0]) ) { char str[2048]; - my_snprintf(str, S(str), "Symbol: %s: no type attribute set", inst_ptr[i].name); + my_snprintf(str, S(str), "xSymbol: %s: no type attribute set", xctx.inst[i].name); statusmsg(str,2); - inst_ptr[i].flags |=4; + xctx.inst[i].flags |=4; hilight_nets=1; } - if(type && inst_ptr[i].node && IS_LABEL_OR_PIN(type) ) { /* instance must have a pin! */ + if(type && xctx.inst[i].node && IS_LABEL_OR_PIN(type) ) { /* instance must have a pin! */ if (for_netlist>0) { /* 20150918 skip labels / pins if ignore property specified on instance */ - if( netlist_type == CAD_VERILOG_NETLIST && - strcmp(get_tok_value(inst_ptr[i].prop_ptr,"verilog_ignore",0),"true")==0 ) continue; - if( netlist_type == CAD_SPICE_NETLIST && - strcmp(get_tok_value(inst_ptr[i].prop_ptr,"spice_ignore",0),"true")==0 ) continue; - if( netlist_type == CAD_VHDL_NETLIST && - strcmp(get_tok_value(inst_ptr[i].prop_ptr,"vhdl_ignore",0),"true")==0 ) continue; - if( netlist_type == CAD_TEDAX_NETLIST && - strcmp(get_tok_value(inst_ptr[i].prop_ptr,"tedax_ignore",0),"true")==0 ) continue; + if( netlist_type == CAD_VERILOG_NETLIST && + strcmp(get_tok_value(xctx.inst[i].prop_ptr,"verilog_ignore",0),"true")==0 ) continue; + if( netlist_type == CAD_SPICE_NETLIST && + strcmp(get_tok_value(xctx.inst[i].prop_ptr,"spice_ignore",0),"true")==0 ) continue; + if( netlist_type == CAD_VHDL_NETLIST && + strcmp(get_tok_value(xctx.inst[i].prop_ptr,"vhdl_ignore",0),"true")==0 ) continue; + if( netlist_type == CAD_TEDAX_NETLIST && + strcmp(get_tok_value(xctx.inst[i].prop_ptr,"tedax_ignore",0),"true")==0 ) continue; } port=0; if (strcmp(type,"label")) { /* instance is a port (not a label) */ - port=1; + port=1; /* 20071204 only define a dir property if instance is not a label */ if (!for_netlist) my_strdup(249, &dir, ""); else - my_strdup(250, &dir, get_tok_value( (inst_ptr[i].ptr+instdef)->boxptr[PINLAYER][0].prop_ptr, "dir",0)); + my_strdup(250, &dir, get_tok_value( (xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER][0].prop_ptr, "dir",0)); } else { /* handle global nodes (global=1 set as symbol property) 28032003 */ - my_strdup(251, &global_node,get_tok_value((inst_ptr[i].ptr+instdef)->prop_ptr,"global",0)); + my_strdup(251, &global_node,get_tok_value((xctx.inst[i].ptr+ xctx.sym)->prop_ptr,"global",0)); /*20071204 if instance is a label dont define a dir property for more precise erc checking */ my_strdup(252, &dir,"none"); } @@ -724,69 +724,69 @@ void prepare_netlist_structs(int for_netlist) my_free(833, &value); my_free(834, &class); } else { - my_strdup(258, &sig_type,get_tok_value(inst_ptr[i].prop_ptr,"sig_type",0)); - my_strdup(259, &verilog_type,get_tok_value(inst_ptr[i].prop_ptr,"verilog_type",0)); /*09112003 */ - my_strdup(260, &value,get_tok_value(inst_ptr[i].prop_ptr,"value",2)); - my_strdup(261, &class,get_tok_value(inst_ptr[i].prop_ptr,"class",0)); + my_strdup(258, &sig_type,get_tok_value(xctx.inst[i].prop_ptr,"sig_type",0)); + my_strdup(259, &verilog_type,get_tok_value(xctx.inst[i].prop_ptr,"verilog_type",0)); + my_strdup(260, &value,get_tok_value(xctx.inst[i].prop_ptr,"value",2)); + my_strdup(261, &class,get_tok_value(xctx.inst[i].prop_ptr,"class",0)); } - my_strdup(262, &inst_ptr[i].node[0], get_tok_value(inst_ptr[i].prop_ptr,"lab",1)); + my_strdup(262, &xctx.inst[i].node[0], get_tok_value(xctx.inst[i].prop_ptr,"lab",1)); - if (!(inst_ptr[i].node[0])) { - my_strdup(65, &inst_ptr[i].node[0], get_tok_value((inst_ptr[i].ptr+instdef)->templ, "lab",1)); - dbg(1, "no lab attr on instance, pick from symbol: %s\n", inst_ptr[i].node[0]); + if (!(xctx.inst[i].node[0])) { + my_strdup(65, &xctx.inst[i].node[0], get_tok_value((xctx.inst[i].ptr+ xctx.sym)->templ, "lab",1)); + dbg(1, "no lab attr on instance, pick from symbol: %s\n", xctx.inst[i].node[0]); } /* handle global nodes (global=1 set as symbol property) 28032003 */ if (!strcmp(type,"label") && global_node && !strcmp(global_node, "true")) { - dbg(1, "prepare_netlist_structs(): global node: %s\n",inst_ptr[i].node[0]); - record_global_node(1,NULL, inst_ptr[i].node[0]); + dbg(1, "prepare_netlist_structs(): global node: %s\n",xctx.inst[i].node[0]); + record_global_node(1,NULL, xctx.inst[i].node[0]); } - + /* do not count multiple labels/pins with same name */ - bus_hash_lookup(inst_ptr[i].node[0], /* insert node in hash table */ + bus_hash_lookup(xctx.inst[i].node[0], /* insert node in hash table */ dir, XINSERT, port, sig_type, verilog_type, value, class); dbg(2, "prepare_netlist_structs(): name=%s\n", - get_tok_value( inst_ptr[i].prop_ptr, "lab",0)); + get_tok_value( xctx.inst[i].prop_ptr, "lab",0)); dbg(2, "prepare_netlist_structs(): pin=%s\n", - get_tok_value( (inst_ptr[i].ptr+instdef)->boxptr[PINLAYER][0].prop_ptr, "name",0)); + get_tok_value( (xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER][0].prop_ptr, "name",0)); dbg(2, "prepare_netlist_structs(): dir=%s\n", - get_tok_value( (inst_ptr[i].ptr+instdef)->boxptr[PINLAYER][0].prop_ptr, "dir",0)); + get_tok_value( (xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER][0].prop_ptr, "dir",0)); /* name nets that touch ioin opin alias instances */ - rect=(inst_ptr[i].ptr+instdef)->boxptr[PINLAYER]; - x0=(rect[0].x1+rect[0].x2)/2; - y0=(rect[0].y1+rect[0].y2)/2; - rot=inst_ptr[i].rot; - flip=inst_ptr[i].flip; + rct=(xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER]; + x0=(rct[0].x1+rct[0].x2)/2; + y0=(rct[0].y1+rct[0].y2)/2; + rot=xctx.inst[i].rot; + flip=xctx.inst[i].flip; ROTATION(0.0,0.0,x0,y0,rx1,ry1); - x0=inst_ptr[i].x0+rx1; - y0=inst_ptr[i].y0+ry1; + x0=xctx.inst[i].x0+rx1; + y0=xctx.inst[i].y0+ry1; get_square(x0, y0, &sqx, &sqy); wptr=wiretable[sqx][sqy]; - if (inst_ptr[i].node[0]) while(wptr) + if (xctx.inst[i].node[0]) while(wptr) { - if (touch(wire[wptr->n].x1, wire[wptr->n].y1, - wire[wptr->n].x2, wire[wptr->n].y2, x0,y0)) + if (touch(xctx.wire[wptr->n].x1, xctx.wire[wptr->n].y1, + xctx.wire[wptr->n].x2, xctx.wire[wptr->n].y2, x0,y0)) { /* short circuit check */ - if (for_netlist>0) signal_short(wire[wptr->n].node, inst_ptr[i].node[0]); - my_strdup(263, &wire[wptr->n].node, inst_ptr[i].node[0]); - my_strdup(264, &wire[wptr->n].prop_ptr, - subst_token(wire[wptr->n].prop_ptr, "lab", wire[wptr->n].node)); + if (for_netlist>0) signal_short(xctx.wire[wptr->n].node, xctx.inst[i].node[0]); + my_strdup(263, &xctx.wire[wptr->n].node, xctx.inst[i].node[0]); + my_strdup(264, &xctx.wire[wptr->n].prop_ptr, + subst_token(xctx.wire[wptr->n].prop_ptr, "lab", xctx.wire[wptr->n].node)); wirecheck(wptr->n); } wptr=wptr->next; } } /* if(type && ... */ - } /* for(i=0;itype); /* 20150409 */ + if(for_netlist) for (i=0;itype); if (type && !IS_LABEL_OR_PIN(type) ) { - if ((generic_rects = (inst_ptr[i].ptr+instdef)->rects[GENERICLAYER]) > 0) + if ((generic_rects = (xctx.inst[i].ptr+ xctx.sym)->rects[GENERICLAYER]) > 0) { - rects = (inst_ptr[i].ptr+instdef)->rects[PINLAYER]; + rects = (xctx.inst[i].ptr+ xctx.sym)->rects[PINLAYER]; for (j=rects;jboxptr[GENERICLAYER]; - x0=(rect[j-rects].x1+rect[j-rects].x2)/2; - y0=(rect[j-rects].y1+rect[j-rects].y2)/2; - rot=inst_ptr[i].rot; - flip=inst_ptr[i].flip; + if (xctx.inst[i].node[j]) continue; /* already named node */ + rct=(xctx.inst[i].ptr+ xctx.sym)->rect[GENERICLAYER]; + x0=(rct[j-rects].x1+rct[j-rects].x2)/2; + y0=(rct[j-rects].y1+rct[j-rects].y2)/2; + rot=xctx.inst[i].rot; + flip=xctx.inst[i].flip; ROTATION(0.0,0.0,x0,y0,rx1,ry1); - x0=inst_ptr[i].x0+rx1; - y0=inst_ptr[i].y0+ry1; + x0=xctx.inst[i].x0+rx1; + y0=xctx.inst[i].y0+ry1; get_square(x0, y0, &sqx, &sqy); iptr=instpintable[sqx][sqy]; @@ -837,33 +837,33 @@ void prepare_netlist_structs(int for_netlist) } if ((iptr->x0==x0) && (iptr->y0==y0)) { - if ((inst_ptr[iptr->n].ptr+instdef)->type && inst_ptr[iptr->n].node[iptr->pin] != NULL && - !strcmp((inst_ptr[iptr->n].ptr+instdef)->type, "label")) /* 20150409 */ + if ((xctx.inst[iptr->n].ptr+ xctx.sym)->type && xctx.inst[iptr->n].node[iptr->pin] != NULL && + !strcmp((xctx.inst[iptr->n].ptr+ xctx.sym)->type, "label")) { - dbg(2, "prepare_netlist_structs(): naming generic %s\n", - inst_ptr[iptr->n].node[iptr->pin]); + dbg(2, "prepare_netlist_structs(): naming generic %s\n", + xctx.inst[iptr->n].node[iptr->pin]); - my_strdup(268, &inst_ptr[i].node[j], - get_tok_value(inst_ptr[iptr->n].prop_ptr,"value",2) ); - - /*my_strdup(269, &inst_ptr[i].node[j], inst_ptr[iptr->n].node[iptr->pin] ); */ + my_strdup(268, &xctx.inst[i].node[j], + get_tok_value(xctx.inst[iptr->n].prop_ptr,"value",2) ); + + /*my_strdup(269, &xctx.inst[i].node[j], xctx.inst[iptr->n].node[iptr->pin] ); */ if (!for_netlist) { my_strdup(270, &sig_type,""); - bus_hash_lookup(inst_ptr[iptr->n].node[iptr->pin],"none", + bus_hash_lookup(xctx.inst[iptr->n].node[iptr->pin],"none", XINSERT, 1, sig_type,"", "",""); } else { my_strdup(271, &sig_type,get_tok_value( - (inst_ptr[i].ptr+instdef)->boxptr[GENERICLAYER][j-rects].prop_ptr, "sig_type",0)); + (xctx.inst[i].ptr+ xctx.sym)->rect[GENERICLAYER][j-rects].prop_ptr, "sig_type",0)); /* insert generic label in hash table as a port so it will not */ /* be declared as a signal in the vhdl netlist. this is a workaround */ /* that should be fixed 25092001 */ - bus_hash_lookup(inst_ptr[iptr->n].node[iptr->pin], - get_tok_value((inst_ptr[i].ptr+instdef)->boxptr[GENERICLAYER][j-rects].prop_ptr, "dir",0), + bus_hash_lookup(xctx.inst[iptr->n].node[iptr->pin], + get_tok_value((xctx.inst[i].ptr+ xctx.sym)->rect[GENERICLAYER][j-rects].prop_ptr, "dir",0), XINSERT, 1, sig_type,"", "",""); - } - } /* end if(inst_ptr[iptr->n].node[iptr->pin] != NULL) */ + } + } /* end if(xctx.inst[iptr->n].node[iptr->pin] != NULL) */ } /* end if( (iptr->x0==x0) && (iptr->y0==y0) ) */ iptr=iptr->next; } @@ -876,61 +876,61 @@ void prepare_netlist_structs(int for_netlist) /* name instance pins of non (label,pin) instances */ dbg(2, "prepare_netlist_structs(): assigning node names on instance pins\n"); - for (i=0;itype); /* 20150409 */ + if(xctx.inst[i].ptr<0) continue; + expandlabel(xctx.inst[i].instname, &inst_mult); + my_strdup(272, &type,(xctx.inst[i].ptr+ xctx.sym)->type); if (type && !IS_LABEL_OR_PIN(type) ) { - if ((rects = (inst_ptr[i].ptr+instdef)->rects[PINLAYER]) > 0) - { + if ((rects = (xctx.inst[i].ptr+ xctx.sym)->rects[PINLAYER]) > 0) + { for (j=0;jboxptr[PINLAYER]; - x0=(rect[j].x1+rect[j].x2)/2; - y0=(rect[j].y1+rect[j].y2)/2; - rot=inst_ptr[i].rot; - flip=inst_ptr[i].flip; + if (xctx.inst[i].node[j]) continue; /* already named node */ + rct=(xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER]; + x0=(rct[j].x1+rct[j].x2)/2; + y0=(rct[j].y1+rct[j].y2)/2; + rot=xctx.inst[i].rot; + flip=xctx.inst[i].flip; ROTATION(0.0,0.0,x0,y0,rx1,ry1); - x0=inst_ptr[i].x0+rx1; - y0=inst_ptr[i].y0+ry1; + x0=xctx.inst[i].x0+rx1; + y0=xctx.inst[i].y0+ry1; get_square(x0, y0, &sqx, &sqy); /* name instance nodes that touch named nets */ wptr=wiretable[sqx][sqy]; dbg(2, "prepare_netlist_structs(): from attached nets\n"); while (wptr) { - if (touch(wire[wptr->n].x1, wire[wptr->n].y1, - wire[wptr->n].x2, wire[wptr->n].y2, x0,y0)) + if (touch(xctx.wire[wptr->n].x1, xctx.wire[wptr->n].y1, + xctx.wire[wptr->n].x2, xctx.wire[wptr->n].y2, x0,y0)) { - + /* short circuit check */ if (touches) { - if (for_netlist>0) signal_short(inst_ptr[i].node[j], wire[wptr->n].node); + if (for_netlist>0) signal_short(xctx.inst[i].node[j], xctx.wire[wptr->n].node); } if (!touches) { - my_strdup(273, &inst_ptr[i].node[j], wire[wptr->n].node ); - bus_hash_lookup(inst_ptr[i].node[j], - get_tok_value( (inst_ptr[i].ptr+instdef)->boxptr[PINLAYER][j].prop_ptr, "dir",0), + my_strdup(273, &xctx.inst[i].node[j], xctx.wire[wptr->n].node ); + bus_hash_lookup(xctx.inst[i].node[j], + get_tok_value( (xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER][j].prop_ptr, "dir",0), XINSERT, 0,"","","",""); - - if (wire[wptr->n].node[0]=='#') /* unnamed node, update its multiplicity */ + + if (xctx.wire[wptr->n].node[0]=='#') /* unnamed node, update its multiplicity */ { expandlabel(get_tok_value( - (inst_ptr[i].ptr+instdef)->boxptr[PINLAYER][j].prop_ptr,"name",0),&pin_mult); + (xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER][j].prop_ptr,"name",0),&pin_mult); - get_unnamed_node(2, pin_mult * inst_mult, atoi((inst_ptr[i].node[j])+4) ); + get_unnamed_node(2, pin_mult * inst_mult, atoi((xctx.inst[i].node[j])+4) ); } } /* end if(!touches) */ touches=1; } wptr=wptr->next; - } - + } + dbg(2, "prepare_netlist_structs(): from other instances\n"); touches_unnamed=0; iptr=instpintable[sqx][sqy]; @@ -943,42 +943,42 @@ void prepare_netlist_structs(int for_netlist) } if ((iptr->x0==x0) && (iptr->y0==y0)) { - if (inst_ptr[iptr->n].node[iptr->pin] != NULL) + if (xctx.inst[iptr->n].node[iptr->pin] != NULL) { /* short circuit check */ if (touches) { - if (for_netlist>0) signal_short(inst_ptr[i].node[j], inst_ptr[iptr->n].node[iptr->pin]); + if (for_netlist>0) signal_short(xctx.inst[i].node[j], xctx.inst[iptr->n].node[iptr->pin]); } if (!touches) { - my_strdup(274, &inst_ptr[i].node[j], inst_ptr[iptr->n].node[iptr->pin] ); + my_strdup(274, &xctx.inst[i].node[j], xctx.inst[iptr->n].node[iptr->pin] ); if (!for_netlist) { - bus_hash_lookup(inst_ptr[i].node[j],"none", XINSERT, 0,"","","",""); + bus_hash_lookup(xctx.inst[i].node[j],"none", XINSERT, 0,"","","",""); } else { - bus_hash_lookup(inst_ptr[i].node[j], - get_tok_value( (inst_ptr[i].ptr+instdef)->boxptr[PINLAYER][j].prop_ptr, "dir",0), + bus_hash_lookup(xctx.inst[i].node[j], + get_tok_value( (xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER][j].prop_ptr, "dir",0), XINSERT, 0,"","","",""); } - if ((inst_ptr[i].node[j])[0] == '#') + if ((xctx.inst[i].node[j])[0] == '#') { expandlabel(get_tok_value( - (inst_ptr[i].ptr+instdef)->boxptr[PINLAYER][j].prop_ptr,"name",0),&pin_mult ); + (xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER][j].prop_ptr,"name",0),&pin_mult ); /* done at beginning of for(i) loop 20171210 */ /* expandlabel(get_tok_value( */ - /* inst_ptr[i].prop_ptr,"name",0), &inst_mult); */ - get_unnamed_node(2, pin_mult * inst_mult, atoi((inst_ptr[i].node[j])+4)); + /* xctx.inst[i].prop_ptr,"name",0), &inst_mult); */ + get_unnamed_node(2, pin_mult * inst_mult, atoi((xctx.inst[i].node[j])+4)); } } touches=1; - } /* end if(inst_ptr[iptr->n].node[iptr->pin] != NULL) */ + } /* end if(xctx.inst[iptr->n].node[iptr->pin] != NULL) */ else /* touches instance with unnamed pins */ { touches_unnamed=1; } } /* end if( (iptr->x0==x0) && (iptr->y0==y0) ) */ iptr=iptr->next; - } + } /* pin did not touch named pins or nets so we name it now */ dbg(2, "prepare_netlist_structs(): naming the other pins\n"); @@ -987,17 +987,17 @@ void prepare_netlist_structs(int for_netlist) if (!(CAD_VHDL_NETLIST && !touches_unnamed)) { expandlabel(get_tok_value( - (inst_ptr[i].ptr+instdef)->boxptr[PINLAYER][j].prop_ptr,"name",0), &pin_mult); + (xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER][j].prop_ptr,"name",0), &pin_mult); /* done at beginning of for(i) loop 20171210 */ /* expandlabel(get_tok_value( */ - /* inst_ptr[i].prop_ptr,"name",0), &inst_mult); */ + /* xctx.inst[i].prop_ptr,"name",0), &inst_mult); */ my_snprintf( tmp_str, S(tmp_str), "#net%d", get_unnamed_node(1, pin_mult * inst_mult, 0)); - my_strdup(275, &inst_ptr[i].node[j], tmp_str ); + my_strdup(275, &xctx.inst[i].node[j], tmp_str ); if (!for_netlist) { - bus_hash_lookup(inst_ptr[i].node[j],"none", XINSERT, 0,"","","",""); + bus_hash_lookup(xctx.inst[i].node[j],"none", XINSERT, 0,"","","",""); } else { - bus_hash_lookup(inst_ptr[i].node[j], - get_tok_value( (inst_ptr[i].ptr+instdef)->boxptr[PINLAYER][j].prop_ptr, "dir",0), + bus_hash_lookup(xctx.inst[i].node[j], + get_tok_value( (xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER][j].prop_ptr, "dir",0), XINSERT, 0,"","","",""); } } @@ -1042,27 +1042,28 @@ int sym_vs_sch_pins() int endfile; char tag[1]; char filename[PATH_MAX]; - n_syms = lastinstdef; + n_syms = xctx.symbols; for(i=0;i= lab_array_size) { lab_array_size += CADCHUNKALLOC; my_realloc(154, &lab_array, lab_array_size * sizeof(char *)); } lab_array[pin_cnt] = NULL; - my_strdup(155, &(lab_array[pin_cnt]), lab); + my_strdup(155, &(lab_array[pin_cnt]), lab); pin_cnt++; pin_match = 0; for(j=0; j < rects; j++) { - my_strdup(293, &pin_name, get_tok_value(instdef[i].boxptr[PINLAYER][j].prop_ptr, "name", 0)); - my_strdup(294, &pin_dir, get_tok_value(instdef[i].boxptr[PINLAYER][j].prop_ptr, "dir", 0)); + my_strdup(293, &pin_name, get_tok_value(xctx.sym[i].rect[PINLAYER][j].prop_ptr, "name", 0)); + my_strdup(294, &pin_dir, get_tok_value(xctx.sym[i].rect[PINLAYER][j].prop_ptr, "dir", 0)); if( pin_name && !strcmp(pin_name, lab)) { if(!( ( !strcmp(type, "ipin") && !strcmp(pin_dir, "in") ) || @@ -1154,14 +1155,14 @@ int sym_vs_sch_pins() ) ) { char str[2048]; - my_snprintf(str, S(str), "Symbol %s: Unmatched subcircuit schematic pin direction: %s", - instdef[i].name, lab); + my_snprintf(str, S(str), "xSymbol %s: Unmatched subcircuit schematic pin direction: %s", + xctx.sym[i].name, lab); statusmsg(str,2); my_snprintf(str, S(str), " %s <--> %s", type, pin_dir); statusmsg(str,2); - for(j = 0; j < lastinst; j++) { - if(!strcmp(inst_ptr[j].name, instdef[i].name)) { - inst_ptr[j].flags |=4; + 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; } } @@ -1173,11 +1174,11 @@ int sym_vs_sch_pins() if(!pin_match) { char str[2048]; /* fprintf(errfp, " unmatched sch / sym pin: %s\n", lab); */ - my_snprintf(str, S(str), "Symbol %s: schematic pin: %s not in symbol", instdef[i].name, lab); + my_snprintf(str, S(str), "xSymbol %s: schematic pin: %s not in symbol", xctx.sym[i].name, lab); statusmsg(str,2); - for(j = 0; j < lastinst; j++) { - if(!strcmp(inst_ptr[j].name, instdef[i].name)) { - inst_ptr[j].flags |=4; + 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; } } @@ -1191,48 +1192,49 @@ int sym_vs_sch_pins() read_line(fd, 0); endfile=1; break; - default: + default: if( tag[0] == '{' ) ungetc(tag[0], fd); read_record(tag[0], fd, 0); break; } read_line(fd, 0); /* discard any remaining characters till (but not including) newline */ if(check_version && !version_found) break; - if(!file_version[0]) { - my_snprintf(file_version, S(file_version), "1.0"); - dbg(1, "sym_vs_sch_pins(): no file_version, assuming file_version=%s\n", file_version); + if(!xctx.file_version[0]) { + my_snprintf(xctx.file_version, S(xctx.file_version), "1.0"); + dbg(1, "sym_vs_sch_pins(): no file_version, assuming file_version=%s\n", xctx.file_version); } } /* while(!endfile) */ fclose(fd); if(pin_cnt != rects) { char str[2048]; - my_snprintf(str, S(str), "Symbol %s has %d pins, its schematic has %d pins", instdef[i].name, rects, pin_cnt); + my_snprintf(str, S(str), "xSymbol %s has %d pins, its schematic has %d pins", + xctx.sym[i].name, rects, pin_cnt); statusmsg(str,2); - for(j = 0; j < lastinst; j++) { - if(!strcmp(inst_ptr[j].name, instdef[i].name)) { - inst_ptr[j].flags |=4; + 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; } } } for(j=0; j < rects; j++) { - my_strdup(295, &pin_name, get_tok_value(instdef[i].boxptr[PINLAYER][j].prop_ptr, "name", 0)); + my_strdup(295, &pin_name, get_tok_value(xctx.sym[i].rect[PINLAYER][j].prop_ptr, "name", 0)); pin_match = 0; for(k=0; k"); + my_snprintf(str, S(str), "xSymbol %s: symbol pin: %s not in schematic", + xctx.sym[i].name, pin_name ? pin_name : ""); statusmsg(str,2); - for(k = 0; k < lastinst; k++) { - if(!strcmp(inst_ptr[k].name, instdef[i].name)) { - inst_ptr[k].flags |=4; + 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; } } @@ -1260,21 +1262,21 @@ int sym_vs_sch_pins() my_free(848, &pin_dir); } /* for(i=0;i n_syms) remove_symbol(lastinstdef - 1); + while(xctx.symbols > n_syms) remove_symbol(xctx.symbols - 1); return 0; } void delete_inst_node(int i) { int j, rects; - if(!inst_ptr[i].node) return; - rects = (inst_ptr[i].ptr+instdef)->rects[PINLAYER] + - (inst_ptr[i].ptr+instdef)->rects[GENERICLAYER]; + if(!xctx.inst[i].node) return; + rects = (xctx.inst[i].ptr+ xctx.sym)->rects[PINLAYER] + + (xctx.inst[i].ptr+ xctx.sym)->rects[GENERICLAYER]; if( rects > 0 ) { for(j=0;j< rects ;j++) - my_free(849, &inst_ptr[i].node[j]); - my_free(850, &inst_ptr[i].node ); + my_free(849, &xctx.inst[i].node[j]); + my_free(850, &xctx.inst[i].node ); } } @@ -1283,14 +1285,14 @@ void delete_netlist_structs(void) int i; /* erase node data structures */ dbg(1, "delete_netlist_structs(): begin erasing\n"); - for(i=0;i 0 } { + if { [xschem get currsch] > 0 } { set n "i(v.$n)" } else { set n "i($n)" @@ -131,7 +131,7 @@ proc annotate {} { xschem push_undo xschem set no_undo 1 xschem set no_draw 1 - set lastinst [xschem get lastinst] + set lastinst [xschem get instances] set path [string range [xschem get sch_path] 1 end] for { set i 0 } { $i < $lastinst } {incr i } { set name [xschem getprop instance $i name] diff --git a/src/node_hash.c b/src/node_hash.c index 92cef10a..f018473a 100644 --- a/src/node_hash.c +++ b/src/node_hash.c @@ -1,7 +1,7 @@ /* File: node_hash.c - * + * * This file is part of XSCHEM, - * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit + * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit * simulation. * Copyright (C) 1998-2020 Stefan Frederik Schippers * @@ -55,7 +55,7 @@ void print_vhdl_signals(FILE *fd) { if(strstr(ptr->token, ".")) { dbg(2, "print_vhdl_signals(): record field, skipping: %s\n", ptr->token); - ptr = ptr->next; + ptr = ptr->next; continue; /* signal is a record field, no declaration */ } if(ptr->d.port == 0 ) @@ -65,7 +65,7 @@ void print_vhdl_signals(FILE *fd) { mult=get_unnamed_node(3, 0, atoi((ptr->token)+4) ); } - else + else { mult=1; } @@ -80,10 +80,10 @@ void print_vhdl_signals(FILE *fd) if(mult>1) { for(j=mult-1;j>=0;j--) - { + { fprintf(fd, "%s %s[%d] : ", class, ptr->token[0]=='#' ? ptr->token+1 : ptr->token,j); if(ptr->sig_type && ptr->sig_type[0]) - { + { fprintf(fd, "%s", ptr->sig_type); } else @@ -97,7 +97,7 @@ void print_vhdl_signals(FILE *fd) fprintf(fd, "%s %s : ", class, ptr->token[0]=='#' ? ptr->token+1 : ptr->token); if(ptr->sig_type && ptr->sig_type[0]) - { + { fprintf(fd, "%s", ptr->sig_type); } else @@ -135,7 +135,7 @@ void print_verilog_signals(FILE *fd) { mult=get_unnamed_node(3, 0, atoi((ptr->token)+4) ); } - else + else { mult=1; } @@ -145,9 +145,9 @@ void print_verilog_signals(FILE *fd) if(mult>1) { for(j=mult-1;j>=0;j--) - { - if(ptr->verilog_type && ptr->verilog_type[0]) /*09112003 */ - { + { + if(ptr->verilog_type && ptr->verilog_type[0]) + { fprintf(fd, "%s ", ptr->verilog_type); } else @@ -160,8 +160,8 @@ void print_verilog_signals(FILE *fd) else { - if(ptr->verilog_type && ptr->verilog_type[0]) /*09112003 */ - { + if(ptr->verilog_type && ptr->verilog_type[0]) + { fprintf(fd, "%s ", ptr->verilog_type); } else @@ -200,7 +200,7 @@ struct node_hashentry *bus_hash_lookup(const char *token, const char *dir, int w dbg(3, "bus_hash_lookup(): done expanding node: %s\n", token); } if(string==NULL) return NULL; - string_ptr = start = string; + string_ptr = start = string; while(1) { c=(*string_ptr); @@ -225,8 +225,8 @@ struct node_hashentry *bus_hash_lookup(const char *token, const char *dir, int w struct node_hashentry *node_hash_lookup(const char *token, const char *dir,int what,int port, char *sig_type, char *verilog_type, char *value, char *class, const char *orig_tok) -/* token dir et all what ... action ... - * -------------------------------------------------------------------------- +/* token dir et all what ... action ... + * -------------------------------------------------------------------------- * "whatever" "in"/"out" 0,XINSERT insert in hash table if not in and return NULL * if already present just return entry address * and update in/out fields sum up port field @@ -250,8 +250,8 @@ struct node_hashentry *node_hash_lookup(const char *token, const char *dir,int w else if(!strcmp(dir,"out") ) d.out=1; else if(!strcmp(dir,"inout") ) d.inout=1; d.port=port; - hashcode=hash(token); - index=hashcode % HASHSIZE; + hashcode=hash(token); + index=hashcode % HASHSIZE; entry=node_table[index]; preventry=&node_table[index]; while(1) @@ -264,14 +264,14 @@ struct node_hashentry *node_hash_lookup(const char *token, const char *dir,int w ptr= my_malloc(281, s ); entry=(struct node_hashentry *)ptr; entry->next = NULL; - entry->token = entry->sig_type = entry->verilog_type = + entry->token = entry->sig_type = entry->verilog_type = entry->value = entry->class = entry->orig_tok = NULL; my_strdup(282, &(entry->token),token); - if(sig_type &&sig_type[0]) my_strdup(283, &(entry->sig_type), sig_type); /* 24092001 */ - if(verilog_type &&verilog_type[0]) my_strdup(284, &(entry->verilog_type), verilog_type); /* 09112003 */ - if(class && class[0]) my_strdup(285, &(entry->class), class); /* 07102001 */ - if(orig_tok && orig_tok[0]) my_strdup(286, &(entry->orig_tok), orig_tok); /* 08102001 */ - if(value && value[0]) my_strdup(287, &(entry->value), value); /* 27092001 */ + if(sig_type &&sig_type[0]) my_strdup(283, &(entry->sig_type), sig_type); + if(verilog_type &&verilog_type[0]) my_strdup(284, &(entry->verilog_type), verilog_type); + if(class && class[0]) my_strdup(285, &(entry->class), class); + if(orig_tok && orig_tok[0]) my_strdup(286, &(entry->orig_tok), orig_tok); + if(value && value[0]) my_strdup(287, &(entry->value), value); entry->d.port=d.port; entry->d.in=d.in; entry->d.out=d.out; @@ -291,11 +291,11 @@ struct node_hashentry *node_hash_lookup(const char *token, const char *dir,int w { saveptr=entry->next; my_free(854, &entry->token); - my_free(855, &entry->verilog_type); /* 09112003 */ - my_free(856, &entry->sig_type); /* 24092001 */ - my_free(857, &entry->class); /* 07102001 */ - my_free(858, &entry->orig_tok); /* 07102001 */ - my_free(859, &entry->value); /* 27092001 */ + my_free(855, &entry->verilog_type); + my_free(856, &entry->sig_type); + my_free(857, &entry->class); + my_free(858, &entry->orig_tok); + my_free(859, &entry->value); my_free(860, &entry); *preventry=saveptr; return NULL; @@ -307,16 +307,16 @@ struct node_hashentry *node_hash_lookup(const char *token, const char *dir,int w entry->d.out+=d.out; entry->d.inout+=d.inout; if(sig_type && sig_type[0] !='\0') - my_strdup(288, &(entry->sig_type), sig_type); /* 24092001 */ + my_strdup(288, &(entry->sig_type), sig_type); if(verilog_type && verilog_type[0] !='\0') - my_strdup(289, &(entry->verilog_type), verilog_type); /* 09112003 */ + my_strdup(289, &(entry->verilog_type), verilog_type); if(value && value[0] !='\0') - my_strdup(290, &(entry->value), value); /* 27092001 */ + my_strdup(290, &(entry->value), value); dbg(3, "node_hash_lookup(): hashing %s : value=%s\n\n", entry->token, entry->value? entry->value:"NULL"); return entry; } - } + } preventry=&entry->next; /* descend into the list. */ entry = entry->next; } @@ -342,7 +342,7 @@ void traverse_node_hash() if(incr_hilight) hilight_color++; statusmsg(str,2); } - else if(entry->d.out ==0 && entry->d.inout == 0) + 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); @@ -356,7 +356,7 @@ void traverse_node_hash() if(incr_hilight) hilight_color++; statusmsg(str,2); } - else if(entry->d.in ==0 && entry->d.inout == 0) + 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); @@ -371,7 +371,7 @@ void traverse_node_hash() statusmsg(str,2); } } - dbg(1, "traverse_node_hash(): node: %s in=%d out=%d inout=%d port=%d\n", + dbg(1, "traverse_node_hash(): node: %s in=%d out=%d inout=%d port=%d\n", entry->token, entry->d.in, entry->d.out, entry->d.inout, entry->d.port); entry = entry->next; @@ -389,11 +389,11 @@ static struct node_hashentry *free_hash_entry(struct node_hashentry *entry) n_elements++; collisions++; tmp = entry->next; my_free(861, &entry->token); - my_free(862, &entry->verilog_type); /* 09112003 */ - my_free(863, &entry->sig_type); /* 24092001 */ - my_free(864, &entry->class); /* 07102001 */ - my_free(865, &entry->orig_tok); /* 07102001 */ - my_free(866, &entry->value); /* 27092001 */ + my_free(862, &entry->verilog_type); + my_free(863, &entry->sig_type); + my_free(864, &entry->class); + my_free(865, &entry->orig_tok); + my_free(866, &entry->value); my_free(867, &entry); entry = tmp; } @@ -403,7 +403,7 @@ static struct node_hashentry *free_hash_entry(struct node_hashentry *entry) 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;i=cadlayers) { fprintf(errfp,"Rectangle layer > defined cadlayers, increase cadlayers\n"); c=cadlayers-1; - } /* 20150408 */ + } check_box_storage(c); - i=lastrect[c]; - ptr=rect[c]; - fscanf(fd, "%lf %lf %lf %lf ",&ptr[i].x1, &ptr[i].y1, + i=xctx.rects[c]; + ptr=xctx.rect[c]; + fscanf(fd, "%lf %lf %lf %lf ",&ptr[i].x1, &ptr[i].y1, &ptr[i].x2, &ptr[i].y2); ptr[i].prop_ptr=NULL; - RECTORDER(ptr[i].x1, ptr[i].y1, ptr[i].x2, ptr[i].y2); /* 20180108 */ + RECTORDER(ptr[i].x1, ptr[i].y1, ptr[i].x2, ptr[i].y2); ptr[i].sel=0; load_ascii_string( &ptr[i].prop_ptr, fd); select_box(c,i, SELECTED, 1); - lastrect[c]++; + xctx.rects[c]++; set_modify(1); } @@ -112,21 +112,21 @@ void merge_arc(FILE *fd) if(c>=cadlayers) { fprintf(errfp,"arc layer > defined cadlayers, increase cadlayers\n"); c=cadlayers-1; - } /* 20150408 */ + } check_arc_storage(c); - i=lastarc[c]; - ptr=arc[c]; + i=xctx.arcs[c]; + ptr=xctx.arc[c]; fscanf(fd, "%lf %lf %lf %lf %lf ",&ptr[i].x, &ptr[i].y, &ptr[i].r, &ptr[i].a, &ptr[i].b); ptr[i].prop_ptr=NULL; ptr[i].sel=0; load_ascii_string(&ptr[i].prop_ptr, fd); - if( !strcmp(get_tok_value(ptr[i].prop_ptr,"fill",0),"true") ) /* 20181011 */ + if( !strcmp(get_tok_value(ptr[i].prop_ptr,"fill",0),"true") ) ptr[i].fill =1; else ptr[i].fill =0; select_arc(c,i, SELECTED, 1); - lastarc[c]++; + xctx.arcs[c]++; set_modify(1); } @@ -134,16 +134,16 @@ void merge_arc(FILE *fd) void merge_polygon(FILE *fd) { int i,c, j, points; - xPolygon *ptr; + xPoly *ptr; fscanf(fd, "%d %d",&c, &points); if(c>=cadlayers) { fprintf(errfp,"Rectangle layer > defined cadlayers, increase cadlayers\n"); c=cadlayers-1; - } /* 20150408 */ + } check_polygon_storage(c); - i=lastpolygon[c]; - ptr=polygon[c]; + i=xctx.polygons[c]; + ptr=xctx.poly[c]; ptr[i].x=NULL; ptr[i].y=NULL; ptr[i].selected_point=NULL; @@ -157,37 +157,37 @@ void merge_polygon(FILE *fd) fscanf(fd, "%lf %lf ",&(ptr[i].x[j]), &(ptr[i].y[j])); } load_ascii_string( &ptr[i].prop_ptr, fd); - if( !strcmp(get_tok_value(ptr[i].prop_ptr,"fill",0),"true") ) /* 20181011 */ + if( !strcmp(get_tok_value(ptr[i].prop_ptr,"fill",0),"true") ) ptr[i].fill =1; else ptr[i].fill =0; select_polygon(c,i, SELECTED, 1); - lastpolygon[c]++; + xctx.polygons[c]++; set_modify(1); } void merge_line(FILE *fd) { int i,c; - Line *ptr; + xLine *ptr; fscanf(fd, "%d",&c); if(c>=cadlayers) { fprintf(errfp,"Rectangle layer > defined cadlayers, increase cadlayers\n"); c=cadlayers-1; - } /* 20150408 */ + } check_line_storage(c); - i=lastline[c]; - ptr=line[c]; - fscanf(fd, "%lf %lf %lf %lf ",&ptr[i].x1, &ptr[i].y1, + i=xctx.lines[c]; + ptr=xctx.line[c]; + fscanf(fd, "%lf %lf %lf %lf ",&ptr[i].x1, &ptr[i].y1, &ptr[i].x2, &ptr[i].y2); - ORDER(ptr[i].x1, ptr[i].y1, ptr[i].x2, ptr[i].y2); /* 20180108 */ + ORDER(ptr[i].x1, ptr[i].y1, ptr[i].x2, ptr[i].y2); ptr[i].prop_ptr=NULL; ptr[i].sel=0; load_ascii_string( &ptr[i].prop_ptr, fd); select_line(c,i, SELECTED, 1); - lastline[c]++; + xctx.lines[c]++; set_modify(1); } @@ -200,10 +200,10 @@ void merge_inst(int k,FILE *fd) int i; char *prop_ptr=NULL; - Instance *ptr; - i=lastinst; + xInstance *ptr; + i=xctx.instances; check_inst_storage(); - ptr=inst_ptr; + ptr=xctx.inst; ptr[i].name=NULL; load_ascii_string(&ptr[i].name,fd); if(fscanf(fd, "%lf %lf %d %d",&ptr[i].x0, &ptr[i].y0,&ptr[i].rot, &ptr[i].flip) < 4) { @@ -213,18 +213,18 @@ void merge_inst(int k,FILE *fd) } ptr[i].sel=0; ptr[i].flags=0; - ptr[i].ptr=-1; + ptr[i].ptr=-1; ptr[i].prop_ptr=NULL; - ptr[i].instname=NULL; /* 20150411 */ + ptr[i].instname=NULL; ptr[i].node=NULL; load_ascii_string(&prop_ptr,fd); if(!k) hash_all_names(i); new_prop_string(i, prop_ptr, k, dis_uniq_names); /* the final tmp argument is zero for the 1st call and used in */ /* new_prop_string() for cleaning some internal caches. */ - my_strdup2(306, &inst_ptr[i].instname, get_tok_value(inst_ptr[i].prop_ptr, "name", 0)); /* 20150409 */ + my_strdup2(306, &xctx.inst[i].instname, get_tok_value(xctx.inst[i].prop_ptr, "name", 0)); my_free(871, &prop_ptr); - lastinst++; + xctx.instances++; set_modify(1); } @@ -238,42 +238,42 @@ void match_merged_inst(int old) int cond; char *type; missing = 0; - for(i=old;iareay1 && ylines[layer];j++) + rot = (xctx.inst[n].rot + rot ) & 0x3; + + x0=xctx.inst[n].x0 + xoffset; + y0=xctx.inst[n].y0 + yoffset; + for(j=0;j< (xctx.inst[n].ptr+ xctx.sym)->lines[layer];j++) { - line = ((inst_ptr[n].ptr+instdef)->lineptr[layer])[j]; + line = ((xctx.inst[n].ptr+ xctx.sym)->line[layer])[j]; ROTATION(0.0,0.0,line.x1,line.y1,x1,y1); ROTATION(0.0,0.0,line.x2,line.y2,x2,y2); ORDER(x1,y1,x2,y2); ps_drawline(layer, x0+x1, y0+y1, x0+x2, y0+y2, line.dash); } - for(j=0;j< (inst_ptr[n].ptr+instdef)->polygons[layer];j++) /* 20171115 */ + for(j=0;j< (xctx.inst[n].ptr+ xctx.sym)->polygons[layer];j++) { - polygon = ((inst_ptr[n].ptr+instdef)->polygonptr[layer])[j]; + polygon = ((xctx.inst[n].ptr+ xctx.sym)->poly[layer])[j]; { /* scope block so we declare some auxiliary arrays for coord transforms. 20171115 */ int k; double *x = my_malloc(309, sizeof(double) * polygon.points); @@ -349,12 +349,12 @@ static void ps_draw_symbol(int n,int layer,int tmp_flip, int rot, my_free(876, &x); my_free(877, &y); } - + } - for(j=0;j< (inst_ptr[n].ptr+instdef)->arcs[layer];j++) + for(j=0;j< (xctx.inst[n].ptr+ xctx.sym)->arcs[layer];j++) { double angle; - arc = ((inst_ptr[n].ptr+instdef)->arcptr[layer])[j]; + arc = ((xctx.inst[n].ptr+ xctx.sym)->arc[layer])[j]; if(flip) { angle = 270.*rot+180.-arc.b-arc.a; } else { @@ -365,39 +365,39 @@ static void ps_draw_symbol(int n,int layer,int tmp_flip, int rot, ROTATION(0.0,0.0,arc.x,arc.y,x1,y1); ps_drawarc(layer, arc.fill, x0+x1, y0+y1, arc.r, angle, arc.b, arc.dash); } - if( (layer != PINLAYER || enable_layer[layer]) ) for(j=0;j< (inst_ptr[n].ptr+instdef)->rects[layer];j++) + if( (layer != PINLAYER || enable_layer[layer]) ) for(j=0;j< (xctx.inst[n].ptr+ xctx.sym)->rects[layer];j++) { - box = ((inst_ptr[n].ptr+instdef)->boxptr[layer])[j]; + box = ((xctx.inst[n].ptr+ xctx.sym)->rect[layer])[j]; ROTATION(0.0,0.0,box.x1,box.y1,x1,y1); ROTATION(0.0,0.0,box.x2,box.y2,x2,y2); - RECTORDER(x1,y1,x2,y2); + RECTORDER(x1,y1,x2,y2); ps_filledrect(layer, x0+x1, y0+y1, x0+x2, y0+y2, box.dash); } - if( (layer==TEXTWIRELAYER && !(inst_ptr[n].flags&2) ) || - (sym_txt && (layer==TEXTLAYER) && (inst_ptr[n].flags&2) ) ) + if( (layer==TEXTWIRELAYER && !(xctx.inst[n].flags&2) ) || + (sym_txt && (layer==TEXTLAYER) && (xctx.inst[n].flags&2) ) ) { const char *txtptr; - for(j=0;j< (inst_ptr[n].ptr+instdef)->texts;j++) + for(j=0;j< (xctx.inst[n].ptr+ xctx.sym)->texts;j++) { - text = (inst_ptr[n].ptr+instdef)->txtptr[j]; - /* if(text.xscale*FONTWIDTH* mooz<1) continue; */ + text = (xctx.inst[n].ptr+ xctx.sym)->text[j]; + /* if(text.xscale*FONTWIDTH* xctx.mooz<1) continue; */ txtptr= translate(n, text.txt_ptr); ROTATION(0.0,0.0,text.x0,text.y0,x1,y1); textlayer = layer; - if( !(layer == PINLAYER && (inst_ptr[n].flags & 4))) { - textlayer = (inst_ptr[n].ptr+instdef)->txtptr[j].layer; + if( !(layer == PINLAYER && (xctx.inst[n].flags & 4))) { + textlayer = (xctx.inst[n].ptr+ xctx.sym)->text[j].layer; if(textlayer < 0 || textlayer >= cadlayers) textlayer = layer; } - if((layer == PINLAYER && inst_ptr[n].flags & 4) || enable_layer[textlayer]) { + if((layer == PINLAYER && xctx.inst[n].flags & 4) || enable_layer[textlayer]) { ps_draw_string(textlayer, txtptr, (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); + x0+x1, y0+y1, text.xscale, text.yscale); } } restore_lw(); } - Tcl_SetResult(interp,"",TCL_STATIC); /* 26102003 */ + Tcl_SetResult(interp,"",TCL_STATIC); } @@ -407,7 +407,7 @@ static void fill_ps_colors() char s[200]; /* overflow safe 20161122 */ unsigned int i,c; if(debug_var>=1) { - tcleval( "puts $ps_colors"); + tcleval( "puts $ps_colors"); } for(i=0;i> 8; ps_colors[i].blue = (c & 0x0000ff); } - + } void ps_draw(void) { double dx, dy, delta,scale; - int c,i, textlayer; - char *tmp=NULL; /* 20161121 */ + int c,i, textlayer; + char *tmp=NULL; int old_grid; int modified_save; const char *r; @@ -441,13 +441,13 @@ void ps_draw(void) } } modified_save=modified; - push_undo(); /* 20161121 */ + push_undo(); trim_wires(); /* 20161121 add connection boxes on wires but undo at end */ ps_colors=my_calloc(311, cadlayers, sizeof(Ps_color)); if(ps_colors==NULL){ fprintf(errfp, "ps_draw(): calloc error\n");tcleval( "exit"); - } - + } + fill_ps_colors(); old_grid=draw_grid; draw_grid=0; @@ -455,7 +455,7 @@ void ps_draw(void) dx=areax2-areax1; dy=areay2-areay1; dbg(1, "ps_draw(): dx=%.16g dy=%.16g\n", dx, dy); - + fd=fopen("plot.ps", "w"); fprintf(fd, "%%!\n"); @@ -513,44 +513,47 @@ void ps_draw(void) restore_lw(); ps_drawgrid(); - for(i=0;i= cadlayers) textlayer = TEXTLAYER; - ps_draw_string(textlayer, textelement[i].txt_ptr, - textelement[i].rot, textelement[i].flip, textelement[i].hcenter, textelement[i].vcenter, - textelement[i].x0,textelement[i].y0, - textelement[i].xscale, textelement[i].yscale); + ps_draw_string(textlayer, 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); } restore_lw(); for(c=0;cn; - if( wire[i].end1 >1 ) { /* 20150331 draw_dots */ - ps_drawarc(WIRELAYER, 1, wire[i].x1, wire[i].y1, cadhalfdotsize, 0, 360, 0); + if( xctx.wire[i].end1 >1 ) { /* 20150331 draw_dots */ + ps_drawarc(WIRELAYER, 1, xctx.wire[i].x1, xctx.wire[i].y1, cadhalfdotsize, 0, 360, 0); } - if( wire[i].end2 >1 ) { /* 20150331 draw_dots */ - ps_drawarc(WIRELAYER, 1, wire[i].x2, wire[i].y2, cadhalfdotsize, 0, 360, 0); + if( xctx.wire[i].end2 >1 ) { /* 20150331 draw_dots */ + ps_drawarc(WIRELAYER, 1, xctx.wire[i].x2, xctx.wire[i].y2, cadhalfdotsize, 0, 360, 0); } } } - + @@ -586,15 +589,15 @@ void ps_draw(void) draw_grid=old_grid; my_free(879, &ps_colors); if(plotfile[0]) { - my_strdup(53, &tmp, "convert_to_pdf plot.ps "); /* 20161121 */ + my_strdup(53, &tmp, "convert_to_pdf plot.ps "); my_strcat(54, &tmp, plotfile); } else { - my_strdup(312, &tmp, "convert_to_pdf plot.ps plot.pdf"); /* 20161121 */ + my_strdup(312, &tmp, "convert_to_pdf plot.ps plot.pdf"); } my_strncpy(plotfile,"", S(plotfile)); tcleval( tmp); my_free(880, &tmp); - pop_undo(0); /* 20161121 */ - modified=modified_save; /* 20161121 */ + pop_undo(0); + modified=modified_save; } diff --git a/src/rawtovcd.c b/src/rawtovcd.c index dc7ecef9..f27888b1 100644 --- a/src/rawtovcd.c +++ b/src/rawtovcd.c @@ -1,7 +1,7 @@ /* File: rawtovcd.c - * + * * This file is part of XSCHEM, - * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit + * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit * simulation. * Copyright (C) 1998-2020 Stefan Frederik Schippers * @@ -52,7 +52,7 @@ void replace_bracket(char *s) /* get a short unique ascii identifier to identify node */ const char *get_vcd_id(int idx) { - static const char syms[] = + static const char syms[] = "0123456789abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ=+-_)(*&^%$#@!~`:;',\"<.>/?|"; static const int n = sizeof(syms)-1; @@ -88,11 +88,11 @@ void read_binary_block() if(debug) fprintf(stderr, "done reading binary block\n"); } -/* parse ascii raw header section: +/* parse ascii raw header section: * returns: 1 if dataset and variables were read. * 0 if transient sim dataset not found * -1 on EOF - * Typical ascii header of raw file looks like: + * Typical ascii header of raw file looks like: * * Title: **.subckt poweramp * Date: Thu Nov 21 18:36:25 2019 @@ -118,7 +118,7 @@ int read_dataset(void) const char *id; char *ptr; int transient = 0; - npoints = 0; + npoints = 0; nvars = 0; while((ptr = fgets(line, sizeof(line), fd)) ) { if(!strncmp(line, "Binary:", 7)) break; /* start of binary block */ @@ -178,7 +178,7 @@ void write_vcd_header() char t[20]; int v; printf("$timescale\n"); - strcpy(t, + strcpy(t, timescale == 1e12 ? "1ps" : timescale == 1e11 ? "10ps" : timescale == 1e10 ? "100ps" : @@ -232,7 +232,7 @@ void dump_vcd_waves() } else { if( (val != 0.0 && fabs((val - lastvalue[v]) / val) > rel_timestep_precision) || - (val == 0.0 && fabs(val - lastvalue[v]) > abs_timestep_precision) + (val == 0.0 && fabs(val - lastvalue[v]) > abs_timestep_precision) ) { printf("r%.3g %s\n", val, vcd_ids[v]); lastvalue[v] = val; diff --git a/src/save.c b/src/save.c index 21768669..613992bf 100644 --- a/src/save.c +++ b/src/save.c @@ -1,7 +1,7 @@ /* File: save.c - * + * * This file is part of XSCHEM, - * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit + * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit * simulation. * Copyright (C) 1998-2020 Stefan Frederik Schippers * @@ -25,8 +25,8 @@ #include /* waitpid */ #endif -/* -read an unknown xschem record usually like: +/* +read an unknown xschem record usually like: text {string} text {string}.... until a '\n' (outside the '{' '}' brackets) or EOF is found. within the brackets use load_ascii_string so escapes and string @@ -61,8 +61,8 @@ void read_record(int firstchar, FILE *fp, int dbg_level) /* return first portion of line if found or NULL if EOF */ char *read_line(FILE *fp, int dbg_level) { - char s[300]; - static char ret[300]; + char s[300]; + static char ret[300]; int first = 0, items; ret[0] = '\0'; @@ -79,7 +79,7 @@ char *read_line(FILE *fp, int dbg_level) } /* */ -/* 20180923 */ + /* return "/" */ /* example: "/xschem_undo_dj5hcG38T2" */ /* */ @@ -109,7 +109,7 @@ const char *random_string(const char *prefix) /* */ -/* 20180923 */ + /* try to create a tmp directory in $HOME */ /* ${HOME}/ */ /* after 5 unsuccessfull attemps give up */ @@ -134,7 +134,7 @@ const char *create_tmpdir(char *prefix) } /* */ -/* 20180924 */ + /* try to create a tmp file in $HOME */ /* ${HOME}/ */ /* after 5 unsuccessfull attemps give up */ @@ -160,10 +160,10 @@ FILE *open_tmpfile(char *prefix, char **filename) return NULL; /* failed to create random filename 5 times */ } -void updatebbox(int count, Box *boundbox, Box *tmp) +void updatebbox(int count, xRect *boundbox, xRect *tmp) { RECTORDER(tmp->x1, tmp->y1, tmp->x2, tmp->y2); - /* dbg(1, "updatebbox(): count=%d, tmp = %g %g %g %g\n", + /* dbg(1, "updatebbox(): count=%d, tmp = %g %g %g %g\n", count, tmp->x1, tmp->y1, tmp->x2, tmp->y2); */ if(count==1) *boundbox = *tmp; else @@ -173,7 +173,7 @@ void updatebbox(int count, Box *boundbox, Box *tmp) if(tmp->y1y1) boundbox->y1 = tmp->y1; if(tmp->y2>boundbox->y2) boundbox->y2 = tmp->y2; } -} +} void save_ascii_string(const char *ptr, FILE *fd) { @@ -188,10 +188,10 @@ void save_ascii_string(const char *ptr, FILE *fd) fputc('}',fd); } -void save_embedded_symbol(Instdef *s, FILE *fd) +void save_embedded_symbol(xSymbol *s, FILE *fd) { int c, i, j; - + fprintf(fd, "v {xschem version=%s file_version=%s}\n", XSCHEM_VERSION, XSCHEM_FILE_VERSION); fprintf(fd, "G "); save_ascii_string(s->prop_ptr,fd); @@ -201,8 +201,8 @@ void save_embedded_symbol(Instdef *s, FILE *fd) fprintf(fd, "E {}\n"); for(c=0;clineptr[c]; + xLine *ptr; + ptr=s->line[c]; for(i=0;ilines[c];i++) { fprintf(fd, "L %d %.16g %.16g %.16g %.16g ", c,ptr[i].x1, ptr[i].y1,ptr[i].x2, @@ -213,8 +213,8 @@ void save_embedded_symbol(Instdef *s, FILE *fd) } for(c=0;cboxptr[c]; + xRect *ptr; + ptr=s->rect[c]; for(i=0;irects[c];i++) { fprintf(fd, "B %d %.16g %.16g %.16g %.16g ", c,ptr[i].x1, ptr[i].y1,ptr[i].x2, @@ -226,7 +226,7 @@ void save_embedded_symbol(Instdef *s, FILE *fd) for(c=0;carcptr[c]; + ptr=s->arc[c]; for(i=0;iarcs[c];i++) { fprintf(fd, "A %d %.16g %.16g %.16g %.16g %.16g ", c,ptr[i].x, ptr[i].y,ptr[i].r, @@ -237,8 +237,8 @@ void save_embedded_symbol(Instdef *s, FILE *fd) } for(i=0;itexts;i++) { - Text *ptr; - ptr = s->txtptr; + xText *ptr; + ptr = s->text; fprintf(fd, "T "); save_ascii_string(ptr[i].txt_ptr,fd); fprintf(fd, " %.16g %.16g %d %d %.16g %.16g ", @@ -249,8 +249,8 @@ void save_embedded_symbol(Instdef *s, FILE *fd) } for(c=0;cpolygonptr[c]; + xPoly *ptr; + ptr=s->poly[c]; for(i=0;ipolygons[c];i++) { fprintf(fd, "P %d %d ", c,ptr[i].points); @@ -266,31 +266,31 @@ void save_embedded_symbol(Instdef *s, FILE *fd) void save_inst(FILE *fd) { int i; - Instance *ptr; + xInstance *ptr; char *tmp = NULL; - ptr=inst_ptr; - for(i=0;i", inst_ptr[i].prop_ptr? inst_ptr[i].prop_ptr:""); - lastinst++; + i, xctx.inst[i].name? xctx.inst[i].name:"", xctx.inst[i].prop_ptr? xctx.inst[i].prop_ptr:""); + xctx.instances++; } my_free(884, &tmp); my_free(885, &prop_ptr); @@ -558,23 +557,23 @@ static void load_inst(int k, FILE *fd) static void load_polygon(FILE *fd) { int i,c, j, points; - xPolygon *ptr; + xPoly *ptr; const char *dash; dbg(3, "load_polygon(): start\n"); if(fscanf(fd, "%d %d",&c, &points)<2) { - fprintf(errfp,"WARNING: missing fields for POLYGON object, ignoring.\n"); + fprintf(errfp,"WARNING: missing fields for POLYGON object, ignoring.\n"); read_line(fd, 0); return; } if(c<0 || c>=cadlayers) { - fprintf(errfp,"WARNING: wrong layer number for POLYGON object, ignoring.\n"); + fprintf(errfp,"WARNING: wrong layer number for POLYGON object, ignoring.\n"); read_line(fd, 0); return; } check_polygon_storage(c); - i=lastpolygon[c]; - ptr=polygon[c]; + i=xctx.polygons[c]; + ptr=xctx.poly[c]; ptr[i].x=NULL; ptr[i].y=NULL; ptr[i].selected_point=NULL; @@ -586,7 +585,7 @@ static void load_polygon(FILE *fd) ptr[i].sel=0; for(j=0;j=cadlayers) { - fprintf(errfp,"WARNING: wrong layer number for ARC object, ignoring.\n"); + fprintf(errfp,"WARNING: wrong layer number for ARC object, ignoring.\n"); read_line(fd, 0); return; } check_arc_storage(c); - i=lastarc[c]; - ptr=arc[c]; + i=xctx.arcs[c]; + ptr=xctx.arc[c]; if(fscanf(fd, "%lf %lf %lf %lf %lf ",&ptr[i].x, &ptr[i].y, &ptr[i].r, &ptr[i].a, &ptr[i].b) < 5) { fprintf(errfp,"WARNING: missing fields for ARC object, ignoring\n"); @@ -641,31 +640,31 @@ static void load_arc(FILE *fd) ptr[i].fill =0; dash = get_tok_value(ptr[i].prop_ptr,"dash",0); if(strcmp(dash, "")) { - int d = atoi(dash); + int d = atoi(dash); ptr[i].dash = d >= 0 ? d : 0; } else { ptr[i].dash = 0; } - lastarc[c]++; + xctx.arcs[c]++; } static void load_box(FILE *fd) { int i,c; - Box *ptr; + xRect *ptr; const char *dash; dbg(3, "load_box(): start\n"); fscanf(fd, "%d",&c); if(c<0 || c>=cadlayers) { - fprintf(errfp,"WARNING: wrong layer number for xRECT object, ignoring.\n"); + fprintf(errfp,"WARNING: wrong layer number for xRECT object, ignoring.\n"); read_line(fd, 0); return; } check_box_storage(c); - i=lastrect[c]; - ptr=rect[c]; - if(fscanf(fd, "%lf %lf %lf %lf ",&ptr[i].x1, &ptr[i].y1, + i=xctx.rects[c]; + ptr=xctx.rect[c]; + if(fscanf(fd, "%lf %lf %lf %lf ",&ptr[i].x1, &ptr[i].y1, &ptr[i].x2, &ptr[i].y2) < 4) { fprintf(errfp,"WARNING: missing fields for xRECT object, ignoring\n"); read_line(fd, 0); @@ -682,13 +681,13 @@ static void load_box(FILE *fd) } else { ptr[i].dash = 0; } - lastrect[c]++; + xctx.rects[c]++; } static void load_line(FILE *fd) { int i,c; - Line *ptr; + xLine *ptr; const char *dash; dbg(3, "load_line(): start\n"); @@ -697,11 +696,11 @@ static void load_line(FILE *fd) fprintf(errfp,"WARNING: Wrong layer number for LINE object, ignoring\n"); read_line(fd, 0); return; - } + } check_line_storage(c); - i=lastline[c]; - ptr=line[c]; - if(fscanf(fd, "%lf %lf %lf %lf ",&ptr[i].x1, &ptr[i].y1, + i=xctx.lines[c]; + ptr=xctx.line[c]; + if(fscanf(fd, "%lf %lf %lf %lf ",&ptr[i].x1, &ptr[i].y1, &ptr[i].x2, &ptr[i].y2) < 4) { fprintf(errfp,"WARNING: missing fields for LINE object, ignoring\n"); read_line(fd, 0); @@ -724,7 +723,7 @@ static void load_line(FILE *fd) } else { ptr[i].dash = 0; } - lastline[c]++; + xctx.lines[c]++; } void read_xschem_file(FILE *fd) @@ -738,34 +737,35 @@ void read_xschem_file(FILE *fd) dbg(2, "read_xschem_file(): start\n"); inst_cnt = endfile = 0; - file_version[0] = '\0'; + xctx.file_version[0] = '\0'; while(!endfile) { if(fscanf(fd," %c",tag)==EOF) break; switch(tag[0]) { case 'v': - load_ascii_string(&xschem_version_string, fd); - if(xschem_version_string) { - my_snprintf(file_version, S(file_version), "%s", get_tok_value(xschem_version_string, "file_version", 0)); + load_ascii_string(&xctx.version_string, fd); + if(xctx.version_string) { + my_snprintf(xctx.file_version, S(xctx.file_version), "%s", + get_tok_value(xctx.version_string, "file_version", 0)); version_found = 1; } - dbg(1, "read_xschem_file(): file_version=%s\n", file_version); + dbg(1, "read_xschem_file(): file_version=%s\n", xctx.file_version); break; case 'E': - load_ascii_string(&schtedaxprop,fd); /*20100217 */ + load_ascii_string(&xctx.schtedaxprop,fd); break; case 'S': - load_ascii_string(&schprop,fd); /*20100217 */ + load_ascii_string(&xctx.schprop,fd); break; case 'V': - load_ascii_string(&schverilogprop,fd); /*09112003 */ + load_ascii_string(&xctx.schverilogprop,fd); break; case 'K': - load_ascii_string(&schsymbolprop,fd); /*09112003 */ + load_ascii_string(&xctx.schsymbolprop,fd); break; case 'G': - load_ascii_string(&schvhdlprop,fd); + load_ascii_string(&xctx.schvhdlprop,fd); break; case 'L': load_line(fd); @@ -789,30 +789,31 @@ void read_xschem_file(FILE *fd) load_inst(inst_cnt++, fd); break; case '[': - my_strdup(324, &inst_ptr[lastinst-1].prop_ptr, subst_token(inst_ptr[lastinst-1].prop_ptr, "embed", "true")); + my_strdup(324, &xctx.inst[xctx.instances-1].prop_ptr, + subst_token(xctx.inst[xctx.instances-1].prop_ptr, "embed", "true")); - if(inst_ptr[lastinst-1].name) { + if(xctx.inst[xctx.instances-1].name) { char *str; - my_snprintf(name_embedded, S(name_embedded), "%s/.xschem_embedded_%d_%s", - tclgetvar("XSCHEM_TMP_DIR"), getpid(), get_cell_w_ext(inst_ptr[lastinst-1].name, 0)); + my_snprintf(name_embedded, S(name_embedded), "%s/.xschem_embedded_%d_%s", + tclgetvar("XSCHEM_TMP_DIR"), getpid(), get_cell_w_ext(xctx.inst[xctx.instances-1].name, 0)); found=0; - for(i=0;i"); my_snprintf(msg, S(msg), "alert_ {Unable to open file: %s}", filename ? filename: "(null)"); tcleval(msg); @@ -1000,10 +1001,10 @@ void load_schematic(int load_symbols, const char *filename, int reset_undo) /* 2 read_xschem_file(fd); fclose(fd); /* 20150326 moved before load symbols */ set_modify(0); - dbg(2, "load_schematic(): loaded file:wire=%d inst=%d\n",lastwire , lastinst); + dbg(2, "load_schematic(): loaded file:wire=%d inst=%d\n",xctx.wires , xctx.instances); if(load_symbols) link_symbols_to_instances(); if(reset_undo) { - Tcl_VarEval(interp, "is_xschem_file ", schematic[currentsch], NULL); + Tcl_VarEval(interp, "is_xschem_file ", xctx.sch[xctx.currsch], NULL); if(!strcmp(tclresult(), "SYMBOL")) { save_netlist_type = netlist_type; netlist_type = CAD_SYMBOL_ATTRS; @@ -1022,7 +1023,7 @@ void load_schematic(int load_symbols, const char *filename, int reset_undo) /* 2 } } } - dbg(1, "load_schematic(): %s, returning\n", schematic[currentsch]); + dbg(1, "load_schematic(): %s, returning\n", xctx.sch[xctx.currsch]); } else { set_modify(0); clear_drawing(); @@ -1031,11 +1032,11 @@ void load_schematic(int load_symbols, const char *filename, int reset_undo) /* 2 else my_snprintf(name, S(name), "%s-%d.sch", "untitled", i); if(stat(name, &buf)) break; } - my_snprintf(schematic[currentsch], S(schematic[currentsch]), "%s/%s", pwd_dir, name); - my_strncpy(current_name, name, S(current_name)); /* 20190519 */ + my_snprintf(xctx.sch[xctx.currsch], S(xctx.sch[xctx.currsch]), "%s/%s", pwd_dir, name); + my_strncpy(xctx.current_name, name, S(xctx.current_name)); } if(has_x) { /* 20161207 moved after if( (fd=..)) */ - if(strcmp(get_cell(schematic[currentsch],1), "systemlib/font")) { + if(strcmp(get_cell(xctx.sch[xctx.currsch],1), "systemlib/font")) { tcleval( "wm title . \"xschem - [file tail [xschem get schname]]\""); /* 20150417 set window and icon title */ tcleval( "wm iconname . \"xschem - [file tail [xschem get schname]]\""); } @@ -1057,7 +1058,7 @@ void delete_undo(void) rmdir(undo_dirname); my_free(895, &undo_dirname); } - + void clear_undo(void) { cur_undo_ptr = 0; @@ -1076,7 +1077,7 @@ void push_undo(void) char diff_name[PATH_MAX+100]; /* overflow safe 20161122 */ if(no_undo)return; - dbg(1, "push_undo(): cur_undo_ptr=%d tail_undo_ptr=%d head_undo_ptr=%d\n", + dbg(1, "push_undo(): cur_undo_ptr=%d tail_undo_ptr=%d head_undo_ptr=%d\n", cur_undo_ptr, tail_undo_ptr, head_undo_ptr); @@ -1090,7 +1091,7 @@ void push_undo(void) } #elif HAS_PIPE==1 my_snprintf(diff_name, S(diff_name), "%s/undo%d", undo_dirname, cur_undo_ptr%max_undo); - pipe(pd); + pipe(pd); if((pid = fork()) ==0) { /* child process */ static char f[PATH_MAX] = ""; close(pd[1]); /* close write side of pipe */ @@ -1101,7 +1102,7 @@ void push_undo(void) } /* the following 2 statements are a replacement for dup2() which is not c89 - * however these are not atomic, if another thread takes stdin + * however these are not atomic, if another thread takes stdin * in between we are in trouble */ close(0); /* close stdin */ dup(pd[0]); /* duplicate read side of pipe to stdin */ @@ -1147,9 +1148,9 @@ void pop_undo(int redo) #endif if(no_undo)return; - if(redo) { + if(redo) { if(cur_undo_ptr < head_undo_ptr) { - dbg(1, "pop_undo(): redo; cur_undo_ptr=%d tail_undo_ptr=%d head_undo_ptr=%d\n", + dbg(1, "pop_undo(): redo; cur_undo_ptr=%d tail_undo_ptr=%d head_undo_ptr=%d\n", cur_undo_ptr, tail_undo_ptr, head_undo_ptr); cur_undo_ptr++; } else { @@ -1157,7 +1158,7 @@ void pop_undo(int redo) } } else { /*redo=0 (undo) */ if(cur_undo_ptr == tail_undo_ptr) return; - dbg(1, "pop_undo(): undo; cur_undo_ptr=%d tail_undo_ptr=%d head_undo_ptr=%d\n", + dbg(1, "pop_undo(): undo; cur_undo_ptr=%d tail_undo_ptr=%d head_undo_ptr=%d\n", cur_undo_ptr, tail_undo_ptr, head_undo_ptr); if(head_undo_ptr == cur_undo_ptr) { push_undo(); @@ -1219,7 +1220,7 @@ void pop_undo(int redo) #else fclose(fd); #endif - dbg(2, "pop_undo(): loaded file:wire=%d inst=%d\n",lastwire , lastinst); + dbg(2, "pop_undo(): loaded file:wire=%d inst=%d\n",xctx.wires , xctx.instances); link_symbols_to_instances(); set_modify(1); prepared_hash_instances=0; @@ -1239,10 +1240,10 @@ void pop_undo(int redo) #endif /* ifndef IN_MEMORY_UNDO */ -/* given a 'symname' component instantiation in a LCC schematic instance +/* given a 'symname' component instantiation in a LCC schematic instance * get the type attribute from symbol global properties. * first look in already loaded symbols else inspect symbol file - * do not load all symname data, just get the type + * do not load all symname data, just get the type * return symbol type in type pointer or "" if no type or no symbol found * if pintable given (!=NULL) hash all symbol pins * if embed_fd is not NULL read symbol from embedded '[...]' tags using embed_fd file pointer */ @@ -1253,23 +1254,23 @@ void get_sym_type(const char *symname, char **type, struct int_hashentry **pinta FILE *fd; char tag[1]; int found = 0; - if(!strcmp(file_version,"1.0")) { + if(!strcmp(xctx.file_version,"1.0")) { my_strncpy(name, abs_sym_path(symname, ".sym"), S(name)); } else { my_strncpy(name, abs_sym_path(symname, ""), S(name)); } found=0; - /* first look in already loaded symbols in instdef[] array... */ - for(i=0;ivalue] = instdef[pos].boxptr[PINLAYER][i]; /* box[] is the pin array ordered as in symbol */ + box[entry->value] = xctx.sym[pos].rect[PINLAYER][i]; /* box[] is the pin array ordered as in symbol */ dbg(1, "align_sch_pins_with_sym(): i=%d, pin name=%s entry->value=%d\n", i, pinname, entry->value); } if(!fail) { - for(i=0; i < instdef[pos].rects[PINLAYER]; i++) { /* copy box[] ordererd array to LCC schematic instance */ - instdef[pos].boxptr[PINLAYER][i] = box[i]; + for(i=0; i < xctx.sym[pos].rects[PINLAYER]; i++) { /* copy box[] ordererd array to LCC schematic instance */ + xctx.sym[pos].rect[PINLAYER][i] = box[i]; } } free_int_hash(pintable); @@ -1377,14 +1378,14 @@ void align_sch_pins_with_sym(const char *name, int pos) } /* replace i/o/iopin instances of LCC schematics with symbol pins (boxes on PINLAYER layer) */ -void add_pinlayer_boxes(int *lastr, Box **bb, const char *symtype, char *prop_ptr, double inst_x0, double inst_y0) +void add_pinlayer_boxes(int *lastr, xRect **bb, const char *symtype, char *prop_ptr, double inst_x0, double inst_y0) { int i, save; const char *label; char *pin_label = NULL; i = lastr[PINLAYER]; - my_realloc(652, &bb[PINLAYER], (i + 1) * sizeof(Box)); + my_realloc(652, &bb[PINLAYER], (i + 1) * sizeof(xRect)); bb[PINLAYER][i].x1 = inst_x0 - 2.5; bb[PINLAYER][i].x2 = inst_x0 + 2.5; bb[PINLAYER][i].y1 = inst_y0 - 2.5; bb[PINLAYER][i].y2 = inst_y0 + 2.5; RECTORDER(bb[PINLAYER][i].x1, bb[PINLAYER][i].y1, bb[PINLAYER][i].x2, bb[PINLAYER][i].y2); @@ -1433,48 +1434,48 @@ void use_lcc_pins(int level, char *symtype, char (*filename)[PATH_MAX]) void calc_symbol_bbox(int pos) { - int c, i, count = 0; - Box boundbox, tmp; + int c, i, count = 0; + xRect boundbox, tmp; boundbox.x1 = boundbox.x2 = boundbox.y1 = boundbox.y2 = 0; for(c=0;c x2) x2 = instdef[pos].polygonptr[c][i].x[k]; - if(k==0 || instdef[pos].polygonptr[c][i].y[k] > y2) y2 = instdef[pos].polygonptr[c][i].y[k]; + if(k==0 || xctx.sym[pos].poly[c][i].x[k] < x1) x1 = xctx.sym[pos].poly[c][i].x[k]; + if(k==0 || xctx.sym[pos].poly[c][i].y[k] < y1) y1 = xctx.sym[pos].poly[c][i].y[k]; + if(k==0 || xctx.sym[pos].poly[c][i].x[k] > x2) x2 = xctx.sym[pos].poly[c][i].x[k]; + if(k==0 || xctx.sym[pos].poly[c][i].y[k] > y2) y2 = xctx.sym[pos].poly[c][i].y[k]; } tmp.x1=x1;tmp.y1=y1;tmp.x2=x2;tmp.y2=y2; updatebbox(count,&boundbox,&tmp); @@ -1485,7 +1486,7 @@ void calc_symbol_bbox(int pos) * is variable from one instance to another due to '@' variable expansions * * for(i=0;i exit */ @@ -1610,30 +1611,30 @@ int load_sym_def(const char *name, FILE *embed_fd) case 'E': load_ascii_string(&aux_ptr, lcc[level].fd); break; - case 'V': /*09112003 */ + case 'V': load_ascii_string(&aux_ptr, lcc[level].fd); break; - case 'S': /*20100217 */ + case 'S': load_ascii_string(&aux_ptr, lcc[level].fd); break; case 'K': /* 1.2 file format: symbol attributes for schematics placed as symbols */ if (level==0) { - load_ascii_string(&instdef[lastinstdef].prop_ptr, lcc[level].fd); - if(!instdef[lastinstdef].prop_ptr) break; - my_strdup2(424, &instdef[lastinstdef].templ, get_tok_value(instdef[lastinstdef].prop_ptr, "template",2)); - my_strdup2(515, &instdef[lastinstdef].type, get_tok_value(instdef[lastinstdef].prop_ptr, "type",0)); - } + load_ascii_string(&xctx.sym[xctx.symbols].prop_ptr, lcc[level].fd); + if(!xctx.sym[xctx.symbols].prop_ptr) break; + my_strdup2(424, &xctx.sym[xctx.symbols].templ, get_tok_value(xctx.sym[xctx.symbols].prop_ptr, "template",2)); + my_strdup2(515, &xctx.sym[xctx.symbols].type, get_tok_value(xctx.sym[xctx.symbols].prop_ptr, "type",0)); + } else { load_ascii_string(&aux_ptr, lcc[level].fd); } break; case 'G': /* .sym files or pre-1.2 symbol attributes for schematics placed as symbols */ - if (level==0 && !instdef[lastinstdef].prop_ptr) { - load_ascii_string(&instdef[lastinstdef].prop_ptr, lcc[level].fd); - if(!instdef[lastinstdef].prop_ptr) break; - my_strdup2(341, &instdef[lastinstdef].templ, get_tok_value(instdef[lastinstdef].prop_ptr, "template",2)); - my_strdup2(342, &instdef[lastinstdef].type, get_tok_value(instdef[lastinstdef].prop_ptr, "type",0)); - } + if (level==0 && !xctx.sym[xctx.symbols].prop_ptr) { + load_ascii_string(&xctx.sym[xctx.symbols].prop_ptr, lcc[level].fd); + if(!xctx.sym[xctx.symbols].prop_ptr) break; + my_strdup2(341, &xctx.sym[xctx.symbols].templ, get_tok_value(xctx.sym[xctx.symbols].prop_ptr, "template",2)); + my_strdup2(342, &xctx.sym[xctx.symbols].type, get_tok_value(xctx.sym[xctx.symbols].prop_ptr, "type",0)); + } else { load_ascii_string(&aux_ptr, lcc[level].fd); } @@ -1646,7 +1647,7 @@ int load_sym_def(const char *name, FILE *embed_fd) continue; } i=lastl[c]; - my_realloc(343, &ll[c],(i+1)*sizeof(Line)); + my_realloc(343, &ll[c],(i+1)*sizeof(xLine)); if(fscanf(lcc[level].fd, "%lf %lf %lf %lf ",&ll[c][i].x1, &ll[c][i].y1, &ll[c][i].x2, &ll[c][i].y2) < 4 ) { fprintf(errfp,"WARNING: missing fields for LINE object, ignoring\n"); @@ -1666,13 +1667,13 @@ int load_sym_def(const char *name, FILE *embed_fd) dbg(2, "l_d_s(): loaded line: ptr=%lx\n", (unsigned long)ll[c]); if(!strcmp(get_tok_value(ll[c][i].prop_ptr,"bus", 0), "true") ) ll[c][i].bus = 1; - else + else ll[c][i].bus = 0; dash = get_tok_value(ll[c][i].prop_ptr,"dash", 0); if( strcmp(dash, "") ) { int d = atoi(dash); ll[c][i].dash = d >= 0 ? d : 0; - } else + } else ll[c][i].dash = 0; ll[c][i].sel = 0; lastl[c]++; @@ -1689,7 +1690,7 @@ int load_sym_def(const char *name, FILE *embed_fd) continue; } i=lastp[c]; - my_realloc(344, &pp[c],(i+1)*sizeof(xPolygon)); + my_realloc(344, &pp[c],(i+1)*sizeof(xPoly)); pp[c][i].x = my_calloc(345, poly_points, sizeof(double)); pp[c][i].y = my_calloc(346, poly_points, sizeof(double)); pp[c][i].selected_point = my_calloc(347, poly_points, sizeof(unsigned short)); @@ -1715,7 +1716,7 @@ int load_sym_def(const char *name, FILE *embed_fd) if( strcmp(dash, "") ) { int d = atoi(dash); pp[c][i].dash = d >= 0 ? d : 0; - } else + } else pp[c][i].dash = 0; pp[c][i].sel = 0; @@ -1776,7 +1777,7 @@ int load_sym_def(const char *name, FILE *embed_fd) if (level>0 && c == PINLAYER) /* Don't care about pins inside SYM */ c = 7; i=lastr[c]; - my_realloc(349, &bb[c],(i+1)*sizeof(Box)); + my_realloc(349, &bb[c],(i+1)*sizeof(xRect)); fscanf(lcc[level].fd, "%lf %lf %lf %lf ",&bb[c][i].x1, &bb[c][i].y1, &bb[c][i].x2, &bb[c][i].y2); if (level>0) { @@ -1801,7 +1802,7 @@ int load_sym_def(const char *name, FILE *embed_fd) break; case 'T': i=lastt; - my_realloc(350, &tt,(i+1)*sizeof(Text)); + my_realloc(350, &tt,(i+1)*sizeof(xText)); tt[i].txt_ptr=NULL; tt[i].font=NULL; load_ascii_string(&tt[i].txt_ptr, lcc[level].fd); @@ -1813,7 +1814,7 @@ int load_sym_def(const char *name, FILE *embed_fd) if (tmp) my_strdup(651, &tt[i].txt_ptr, tmp); ROTATION(0.0, 0.0, tt[i].x0, tt[i].y0, rx1, ry1); tt[i].x0 = lcc[level].x0 + rx1; tt[i].y0 = lcc[level].y0 + ry1; - tt[i].rot = (tt[i].rot + ((lcc[level].flip && (tt[i].rot & 1)) ? lcc[level].rot + 2 : lcc[level].rot)) & 0x3; + tt[i].rot = (tt[i].rot + ((lcc[level].flip && (tt[i].rot & 1)) ? lcc[level].rot + 2 : lcc[level].rot)) & 0x3; tt[i].flip = lcc[level].flip ^ tt[i].flip; } tt[i].prop_ptr=NULL; @@ -1842,7 +1843,7 @@ int load_sym_def(const char *name, FILE *embed_fd) break; case 'N': /* store wires as lines on layer WIRELAYER. */ i = lastl[WIRELAYER]; - my_realloc(314, &ll[WIRELAYER],(i+1)*sizeof(Line)); + my_realloc(314, &ll[WIRELAYER],(i+1)*sizeof(xLine)); if(fscanf(lcc[level].fd, "%lf %lf %lf %lf ",&ll[WIRELAYER][i].x1, &ll[WIRELAYER][i].y1, &ll[WIRELAYER][i].x2, &ll[WIRELAYER][i].y2) < 4 ) { fprintf(errfp,"WARNING: missing fields for LINE object, ignoring\n"); @@ -1878,13 +1879,13 @@ int load_sym_def(const char *name, FILE *embed_fd) } load_ascii_string(&prop_ptr, lcc[level].fd); if(level + 1 >=CADMAXHIER) { - fprintf(errfp, "Symbol recursively instantiating symbol: max depth reached, skipping\n"); - if(has_x) tcleval("alert_ {Symbol recursively instantiating symbol: max depth reached, skipping} {} 1"); + fprintf(errfp, "xSymbol recursively instantiating symbol: max depth reached, skipping\n"); + if(has_x) tcleval("alert_ {xSymbol recursively instantiating symbol: max depth reached, skipping} {} 1"); endfile = 1; continue; } - { + { char c; filepos = xftell(lcc[level].fd); /* store file pointer position to inspect next line */ fd_tmp = NULL; @@ -1914,14 +1915,14 @@ int load_sym_def(const char *name, FILE *embed_fd) !strcmp(symtype, "use") || !strcmp(symtype, "launcher") || !strcmp(symtype, "verilog_preprocessor") || - !strcmp(symtype, "timescale") + !strcmp(symtype, "timescale") ) break; /* add PINLAYER boxes (symbol pins) at schematic i/o/iopin coordinates. */ if( level==0 && IS_PIN(symtype) ) { add_pinlayer_boxes(lastr, bb, symtype, prop_ptr, inst_x0, inst_y0); } /* build symbol filename to be loaded */ - if (!strcmp(file_version, "1.0")) { + if (!strcmp(xctx.file_version, "1.0")) { my_strncpy(sympath, abs_sym_path(symname, ".sym"), S(sympath)); } else { @@ -1959,7 +1960,7 @@ int load_sym_def(const char *name, FILE *embed_fd) lcc[level].y0 = inst_y0; lcc[level].rot = inst_rot; lcc[level].flip = inst_flip; - /* calculate LCC sub-schematic x0, y0, rotation and flip */ + /* calculate LCC sub-schematic x0, y0, rotation and flip */ if (level > 1) { int rot, flip; static int map[4]={0,3,2,1}; @@ -1975,7 +1976,7 @@ int load_sym_def(const char *name, FILE *embed_fd) } my_strdup(654, &lcc[level].prop_ptr, prop_ptr); my_strdup(657, &lcc[level].symname, symname); - dbg(1, "level incremented: level=%d, symname=%s, prop_ptr = %s sympath=%s\n", level, symname, prop_ptr, sympath); + dbg(1, "level incremented: level=%d, symname=%s, prop_ptr=%s sympath=%s\n", level, symname, prop_ptr, sympath); } break; case '[': @@ -2001,9 +2002,9 @@ int load_sym_def(const char *name, FILE *embed_fd) } /* if a 'C' line was encountered and level was incremented, rest of line must be read with lcc[level-1].fd file pointer */ - if(incremented_level) + if(incremented_level) read_line(lcc[level-1].fd, 0); /* discard any remaining characters till (but not including) newline */ - else + else read_line(lcc[level].fd, 0); /* discard any remaining characters till (but not including) newline */ } if(!embed_fd) { @@ -2011,29 +2012,29 @@ int load_sym_def(const char *name, FILE *embed_fd) fclose(lcc[0].fd); } if(embed_fd || strstr(name, ".xschem_embedded_")) { - instdef[lastinstdef].flags |= EMBEDDED; + xctx.sym[xctx.symbols].flags |= EMBEDDED; } else { - instdef[lastinstdef].flags &= ~EMBEDDED; + xctx.sym[xctx.symbols].flags &= ~EMBEDDED; } dbg(2, "l_d_s(): finished parsing file\n"); for(c=0;cprop_ptr, "schematic",0 ), "") + (xctx.inst[selectedgroup[0].n].ptr+ xctx.sym)->prop_ptr, "schematic",0 ), "") , S(schname)); if(!schname[0]) { - my_strncpy(schname, add_ext(abs_sym_path(inst_ptr[selectedgroup[0].n].name, ""), ".sch"), S(schname)); + my_strncpy(schname, add_ext(abs_sym_path(xctx.inst[selectedgroup[0].n].name, ""), ".sch"), S(schname)); } if( !stat(schname, &buf) ) { my_strdup(353, &savecmd, "ask_save \" create schematic file: "); @@ -2119,12 +2120,12 @@ void create_sch_from_sym(void) fputc('\n', fd); fprintf(fd, "S {}"); fputc('\n', fd); - ptr = inst_ptr[selectedgroup[0].n].ptr+instdef; + ptr = xctx.inst[selectedgroup[0].n].ptr+xctx.sym; npin = ptr->rects[GENERICLAYER]; - rect = ptr->boxptr[GENERICLAYER]; + rct = ptr->rect[GENERICLAYER]; ypos=0; for(i=0;irects[PINLAYER]; - rect = ptr->boxptr[PINLAYER]; + rct = ptr->rect[PINLAYER]; for(j=0;j<3;j++) { if(j==1) ypos=0; for(i=0;itype && - !strcmp( (inst_ptr[selectedgroup[0].n].ptr+instdef)->type,"missing")) return; + if((xctx.inst[selectedgroup[0].n].ptr+ xctx.sym)->type && + !strcmp( (xctx.inst[selectedgroup[0].n].ptr+ xctx.sym)->type,"missing")) return; } else return; /* build up current hierarchy path */ - my_strdup(363, &str, inst_ptr[selectedgroup[0].n].instname); - my_strdup(364, &sch_path[currentsch+1], sch_path[currentsch]); - my_strcat(365, &sch_path[currentsch+1], str); - my_strcat(366, &sch_path[currentsch+1], "."); - sch_inst_number[currentsch+1] = 1; + my_strdup(363, &str, xctx.inst[selectedgroup[0].n].instname); + my_strdup(364, &xctx.sch_path[xctx.currsch+1], xctx.sch_path[xctx.currsch]); + my_strcat(365, &xctx.sch_path[xctx.currsch+1], str); + my_strcat(366, &xctx.sch_path[xctx.currsch+1], "."); + xctx.sch_inst_number[xctx.currsch+1] = 1; my_free(921, &str); - previous_instance[currentsch]=selectedgroup[0].n; - zoom_array[currentsch].x=xorigin; - zoom_array[currentsch].y=yorigin; - zoom_array[currentsch].zoom=zoom; - ++currentsch; - if((inst_ptr[selectedgroup[0].n].ptr+instdef)->flags & EMBEDDED || - !strcmp(get_tok_value(inst_ptr[selectedgroup[0].n].prop_ptr,"embed", 0), "true")) { + xctx.previous_instance[xctx.currsch]=selectedgroup[0].n; + xctx.zoom_array[xctx.currsch].x=xctx.xorigin; + xctx.zoom_array[xctx.currsch].y=xctx.yorigin; + xctx.zoom_array[xctx.currsch].zoom=xctx.zoom; + ++xctx.currsch; + if((xctx.inst[selectedgroup[0].n].ptr+ xctx.sym)->flags & EMBEDDED || + !strcmp(get_tok_value(xctx.inst[selectedgroup[0].n].prop_ptr,"embed", 0), "true")) { /* save embedded symbol into a temporary file */ my_snprintf(name_embedded, S(name_embedded), "%s/.xschem_embedded_%d_%s", tclgetvar("XSCHEM_TMP_DIR"), getpid(), get_cell_w_ext(name, 0)); if(!(fd = fopen(name_embedded, "w")) ) { fprintf(errfp, "descend_symbol(): problems opening file %s \n", name_embedded); } - save_embedded_symbol(inst_ptr[selectedgroup[0].n].ptr+instdef, fd); + save_embedded_symbol(xctx.inst[selectedgroup[0].n].ptr+xctx.sym, fd); fclose(fd); unselect_all(); remove_symbols(); /* must follow save (if) embedded */ @@ -2243,63 +2244,63 @@ void round_schematic_to_grid(double cadsnap) switch(selectedgroup[i].type) { case xTEXT: - SNAP_TO_GRID(textelement[n].x0); - SNAP_TO_GRID(textelement[n].y0); + SNAP_TO_GRID(xctx.text[n].x0); + SNAP_TO_GRID(xctx.text[n].y0); break; case xRECT: if(c == PINLAYER) { double midx, midx_round, deltax; double midy, midy_round, deltay; - midx_round = midx = (rect[c][n].x1 + rect[c][n].x2) / 2; - midy_round = midy = (rect[c][n].y1 + rect[c][n].y2) / 2; + midx_round = midx = (xctx.rect[c][n].x1 + xctx.rect[c][n].x2) / 2; + midy_round = midy = (xctx.rect[c][n].y1 + xctx.rect[c][n].y2) / 2; SNAP_TO_GRID(midx_round); SNAP_TO_GRID(midy_round); deltax = midx_round - midx; deltay = midy_round - midy; - rect[c][n].x1 += deltax; - rect[c][n].x2 += deltax; - rect[c][n].y1 += deltay; - rect[c][n].y2 += deltay; + xctx.rect[c][n].x1 += deltax; + xctx.rect[c][n].x2 += deltax; + xctx.rect[c][n].y1 += deltay; + xctx.rect[c][n].y2 += deltay; } else { - SNAP_TO_GRID(rect[c][n].x1); - SNAP_TO_GRID(rect[c][n].y1); - SNAP_TO_GRID(rect[c][n].x2); - SNAP_TO_GRID(rect[c][n].y2); + SNAP_TO_GRID(xctx.rect[c][n].x1); + SNAP_TO_GRID(xctx.rect[c][n].y1); + SNAP_TO_GRID(xctx.rect[c][n].x2); + SNAP_TO_GRID(xctx.rect[c][n].y2); } break; case WIRE: - SNAP_TO_GRID(wire[n].x1); - SNAP_TO_GRID(wire[n].y1); - SNAP_TO_GRID(wire[n].x2); - SNAP_TO_GRID(wire[n].y2); + SNAP_TO_GRID(xctx.wire[n].x1); + SNAP_TO_GRID(xctx.wire[n].y1); + SNAP_TO_GRID(xctx.wire[n].x2); + SNAP_TO_GRID(xctx.wire[n].y2); break; case LINE: - SNAP_TO_GRID(line[c][n].x1); - SNAP_TO_GRID(line[c][n].y1); - SNAP_TO_GRID(line[c][n].x2); - SNAP_TO_GRID(line[c][n].y2); + SNAP_TO_GRID(xctx.line[c][n].x1); + SNAP_TO_GRID(xctx.line[c][n].y1); + SNAP_TO_GRID(xctx.line[c][n].x2); + SNAP_TO_GRID(xctx.line[c][n].y2); break; case ARC: - SNAP_TO_GRID(arc[c][n].x); - SNAP_TO_GRID(arc[c][n].y); + SNAP_TO_GRID(xctx.arc[c][n].x); + SNAP_TO_GRID(xctx.arc[c][n].y); break; - + case POLYGON: - for(p=0;p $infowindow_text = %s\n", tclgetvar("infowindow_text")); - tcleval(s); + tcleval(s); } } int get_instance(const char *s) { int i, found=0; - for(i=0;ilastinst) { + if(i<0 || i>xctx.instances) { Tcl_AppendResult(interp, "Index out of range", NULL); return -1; } @@ -67,7 +67,7 @@ int get_instance(const char *s) /* can be used to reach C functions from the Tk shell. */ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * argv[]) -{ +{ int i; char name[1024]; /* overflow safe 20161122 */ @@ -81,7 +81,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg fprintf(errfp, "xschem():"); for(i=0; izoom) zoom=yy1; - mooz=1/zoom; - xorigin=xorigin+areaw*zoom*(1-1/factor)/2; - yorigin=yorigin+areah*zoom*(1-1/factor)/2; - zoom*= factor; - mooz=1/zoom; + if(yy1>xctx.zoom) xctx.zoom=yy1; + xctx.mooz=1/xctx.zoom; + xctx.xorigin=xctx.xorigin+areaw*xctx.zoom*(1-1/factor)/2; + xctx.yorigin=xctx.yorigin+areah*xctx.zoom*(1-1/factor)/2; + xctx.zoom*= factor; + xctx.mooz=1/xctx.zoom; change_linewidth(-1.); draw(); } @@ -317,7 +317,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(!strcmp(argv[1],"place_text")) { - ui_state |= MENUSTARTTEXT; /* 20161201 */ + ui_state |= MENUSTARTTEXT; /* place_text(0,mousex_snap, mousey_snap); */ /* move_objects(BEGIN,0,0,0); */ Tcl_ResetResult(interp); @@ -349,7 +349,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(!strcmp(argv[1],"copy_objects")) { - copy_objects(BEGIN); + copy_objects(BEGIN); Tcl_ResetResult(interp); } @@ -359,7 +359,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg move_objects(BEGIN,0,0,0); move_objects( END,0,atof(argv[2]), atof(argv[3])); } - else move_objects(BEGIN,0,0,0); + else move_objects(BEGIN,0,0,0); Tcl_ResetResult(interp); } @@ -389,38 +389,42 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg Tcl_ResetResult(interp); } else if(!strcmp(argv[1],"clear")) - { + { int cancel; cancel=save(1); - if(!cancel){ /* 20161209 */ + if(!cancel){ char name[PATH_MAX]; struct stat buf; int i; - - currentsch = 0; - unselect_all(); /* 20180929 */ + + xctx.currsch = 0; + unselect_all(); remove_symbols(); clear_drawing(); - if(argc>=3 && !strcmp(argv[2],"SYMBOL")) { /* 20171025 */ + if(argc>=3 && !strcmp(argv[2],"SYMBOL")) { + netlist_type = CAD_SYMBOL_ATTRS; + tclsetvar("netlist_type","symbol"); for(i=0;;i++) { if(i == 0) my_snprintf(name, S(name), "%s.sym", "untitled"); else my_snprintf(name, S(name), "%s-%d.sym", "untitled", i); if(stat(name, &buf)) break; } - my_snprintf(schematic[currentsch], S(schematic[currentsch]), "%s/%s", pwd_dir, name); - my_strncpy(current_name, name, S(current_name)); + my_snprintf(xctx.sch[xctx.currsch], S(xctx.sch[xctx.currsch]), "%s/%s", pwd_dir, name); + my_strncpy(xctx.current_name, name, S(xctx.current_name)); } else { + netlist_type = CAD_SPICE_NETLIST; + tclsetvar("netlist_type","spice"); for(i=0;;i++) { if(i == 0) my_snprintf(name, S(name), "%s.sch", "untitled"); else my_snprintf(name, S(name), "%s-%d.sch", "untitled", i); if(stat(name, &buf)) break; } - my_snprintf(schematic[currentsch], S(schematic[currentsch]), "%s/%s", pwd_dir, name); - my_strncpy(current_name, name, S(current_name)); + my_snprintf(xctx.sch[xctx.currsch], S(xctx.sch[xctx.currsch]), "%s/%s", pwd_dir, name); + my_strncpy(xctx.current_name, name, S(xctx.current_name)); } draw(); - set_modify(0); /* 20171025 */ + set_modify(0); prepared_hash_instances=0; prepared_hash_wires=0; prepared_netlist_structs=0; @@ -441,9 +445,9 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(!strcmp(argv[1],"reload")) { - unselect_all(); /* 20180929 */ + unselect_all(); remove_symbols(); - load_schematic(1, schematic[currentsch], 1); + load_schematic(1, xctx.sch[xctx.currsch], 1); if(argc >= 3 && !strcmp(argv[2], "zoom_full") ) { zoom_full(1, 0); } else { @@ -451,7 +455,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg } Tcl_ResetResult(interp); } - + else if(!strcmp(argv[1],"debug")) { if(argc==3) { @@ -460,7 +464,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg } Tcl_ResetResult(interp); } - + else if(!strcmp(argv[1], "bbox")) { if(argc == 3) { if(!strcmp(argv[2], "end")) { @@ -468,11 +472,11 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg draw(); bbox(END , 0.0 , 0.0 , 0.0 , 0.0); } else if(!strcmp(argv[2], "begin")) { - bbox(BEGIN,0.0, 0.0, 0.0, 0.0); + bbox(BEGIN,0.0, 0.0, 0.0, 0.0); } } Tcl_ResetResult(interp); - } + } else if(!strcmp(argv[1], "setprop")) { int inst, fast=0; @@ -499,8 +503,8 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg return TCL_ERROR; } else { bbox(BEGIN,0.0,0.0,0.0,0.0); - symbol_bbox(inst, &inst_ptr[inst].x1, &inst_ptr[inst].y1, &inst_ptr[inst].x2, &inst_ptr[inst].y2); - bbox(ADD, inst_ptr[inst].x1, inst_ptr[inst].y1, inst_ptr[inst].x2, inst_ptr[inst].y2); + symbol_bbox(inst, &xctx.inst[inst].x1, &xctx.inst[inst].y1, &xctx.inst[inst].x2, &xctx.inst[inst].y2); + bbox(ADD, xctx.inst[inst].x1, xctx.inst[inst].y1, xctx.inst[inst].x2, xctx.inst[inst].y2); push_undo(); set_modify(1); if(!fast) { @@ -510,15 +514,15 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg } hash_all_names(inst); if(argc >= 5) { - new_prop_string(inst, subst_token(inst_ptr[inst].prop_ptr, argv[3], argv[4]),0, dis_uniq_names); - + new_prop_string(inst, subst_token(xctx.inst[inst].prop_ptr, argv[3], argv[4]),0, dis_uniq_names); + } else {/* assume argc == 4 */ - new_prop_string(inst, subst_token(inst_ptr[inst].prop_ptr, argv[3], NULL),0, dis_uniq_names); + new_prop_string(inst, subst_token(xctx.inst[inst].prop_ptr, argv[3], NULL),0, dis_uniq_names); } - my_strdup2(367, &inst_ptr[inst].instname, get_tok_value(inst_ptr[inst].prop_ptr, "name",0)); + my_strdup2(367, &xctx.inst[inst].instname, get_tok_value(xctx.inst[inst].prop_ptr, "name",0)); /* new symbol bbox after prop changes (may change due to text length) */ - symbol_bbox(inst, &inst_ptr[inst].x1, &inst_ptr[inst].y1, &inst_ptr[inst].x2, &inst_ptr[inst].y2); - bbox(ADD, inst_ptr[inst].x1, inst_ptr[inst].y1, inst_ptr[inst].x2, inst_ptr[inst].y2); + symbol_bbox(inst, &xctx.inst[inst].x1, &xctx.inst[inst].y1, &xctx.inst[inst].x2, &xctx.inst[inst].y2); + bbox(ADD, xctx.inst[inst].x1, xctx.inst[inst].y1, xctx.inst[inst].x2, xctx.inst[inst].y2); /* redraw symbol with new props */ bbox(SET,0.0,0.0,0.0,0.0); draw(); @@ -548,50 +552,50 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg char *type; char *name=NULL; char *ptr=NULL; - + bbox(BEGIN,0.0,0.0,0.0,0.0); my_strncpy(symbol, argv[4], S(symbol)); push_undo(); set_modify(1); if(!fast) { - prepared_hash_instances=0; /* 20171224 */ + prepared_hash_instances=0; prepared_netlist_structs=0; prepared_hilight_structs=0; } sym_number=match_symbol(symbol); if(sym_number>=0) { - prefix=(get_tok_value( (instdef+sym_number)->templ , "name",0))[0]; /* get new symbol prefix */ + prefix=(get_tok_value( (xctx.sym+sym_number)->templ , "name",0))[0]; /* get new symbol prefix */ } else prefix = 'x'; delete_inst_node(inst); /* 20180208 fix crashing bug: delete node info if changing symbol */ /* if number of pins is different we must delete these data *before* */ /* changing ysmbol, otherwise i might end up deleting non allocated data. */ - my_strdup(369, &inst_ptr[inst].name,symbol); - inst_ptr[inst].ptr=sym_number; - bbox(ADD, inst_ptr[inst].x1, inst_ptr[inst].y1, inst_ptr[inst].x2, inst_ptr[inst].y2); - - my_strdup(370, &name, inst_ptr[inst].instname); - if(name && name[0] ) /* 30102003 */ + my_strdup(369, &xctx.inst[inst].name,symbol); + xctx.inst[inst].ptr=sym_number; + bbox(ADD, xctx.inst[inst].x1, xctx.inst[inst].y1, xctx.inst[inst].x2, xctx.inst[inst].y2); + + my_strdup(370, &name, xctx.inst[inst].instname); + if(name && name[0] ) { /* 20110325 only modify prefix if prefix not NUL */ if(prefix) name[0]=prefix; /* change prefix if changing symbol type; */ - - my_strdup(371, &ptr,subst_token(inst_ptr[inst].prop_ptr, "name", name) ); + + my_strdup(371, &ptr,subst_token(xctx.inst[inst].prop_ptr, "name", name) ); hash_all_names(inst); new_prop_string(inst, ptr,0, dis_uniq_names); /* set new prop_ptr */ - my_strdup2(372, &inst_ptr[inst].instname, get_tok_value(inst_ptr[inst].prop_ptr, "name",0)); - - type=instdef[inst_ptr[inst].ptr].type; /* 20150409 */ + my_strdup2(372, &xctx.inst[inst].instname, get_tok_value(xctx.inst[inst].prop_ptr, "name",0)); + + type=xctx.sym[xctx.inst[inst].ptr].type; cond= !type || !IS_LABEL_SH_OR_PIN(type); - if(cond) inst_ptr[inst].flags|=2; - else inst_ptr[inst].flags &=~2; + if(cond) xctx.inst[inst].flags|=2; + else xctx.inst[inst].flags &=~2; my_free(922, &ptr); } my_free(923, &name); /* new symbol bbox after prop changes (may change due to text length) */ - symbol_bbox(inst, &inst_ptr[inst].x1, &inst_ptr[inst].y1, &inst_ptr[inst].x2, &inst_ptr[inst].y2); - bbox(ADD, inst_ptr[inst].x1, inst_ptr[inst].y1, inst_ptr[inst].x2, inst_ptr[inst].y2); + symbol_bbox(inst, &xctx.inst[inst].x1, &xctx.inst[inst].y1, &xctx.inst[inst].x2, &xctx.inst[inst].y2); + bbox(ADD, xctx.inst[inst].x1, xctx.inst[inst].y1, xctx.inst[inst].x2, xctx.inst[inst].y2); /* redraw symbol */ bbox(SET,0.0,0.0,0.0,0.0); draw(); @@ -599,20 +603,20 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg } } Tcl_ResetResult(interp); - } + } - else if( !strcmp(argv[1],"symbols")) { /* 20171028 */ + else if( !strcmp(argv[1],"symbols")) { int i; char n[100]; Tcl_AppendResult(interp, "\n", NULL); - for(i=0; i 2 && !strcmp(argv[2], "instance")) { int i; const char *tmp; @@ -625,16 +629,16 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg return TCL_ERROR; } if(argc == 4) { - Tcl_AppendResult(interp, inst_ptr[i].prop_ptr, NULL); + Tcl_AppendResult(interp, xctx.inst[i].prop_ptr, NULL); } else if(!strcmp(argv[4],"cell::name")) { - tmp = inst_ptr[i].name; + tmp = xctx.inst[i].name; Tcl_AppendResult(interp, tmp, NULL); } else if(strstr(argv[4], "cell::") ) { - tmp = get_tok_value( (inst_ptr[i].ptr+instdef)->prop_ptr, argv[4]+6, 0); + tmp = get_tok_value( (xctx.inst[i].ptr+ xctx.sym)->prop_ptr, argv[4]+6, 0); dbg(1, "xschem getprop: looking up instance %d prop cell::|%s| : |%s|\n", i, argv[4]+6, tmp); Tcl_AppendResult(interp, tmp, NULL); } else { - Tcl_AppendResult(interp, get_tok_value(inst_ptr[i].prop_ptr, argv[4], 0), NULL); + Tcl_AppendResult(interp, get_tok_value(xctx.inst[i].prop_ptr, argv[4], 0), NULL); } } else if(argc > 2 && !strcmp(argv[2], "instance_pin")) { /* 0 1 2 3 4 5 */ @@ -656,29 +660,31 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg n = atoi(argv[4]); } else { - for(n = 0; n < (inst_ptr[inst].ptr+instdef)->rects[PINLAYER]; n++) { - if(!strcmp(get_tok_value((inst_ptr[inst].ptr+instdef)->boxptr[PINLAYER][n].prop_ptr,"name",0), argv[4])) break; + xSymbol *ptr = xctx.inst[inst].ptr+ xctx.sym; + for(n = 0; n < ptr->rects[PINLAYER]; n++) { + char *prop = ptr->rect[PINLAYER][n].prop_ptr; + if(!strcmp(get_tok_value(prop, "name",0), argv[4])) break; } } - if(n>=0 && n < (inst_ptr[inst].ptr+instdef)->rects[PINLAYER]) { + if(n>=0 && n < (xctx.inst[inst].ptr+ xctx.sym)->rects[PINLAYER]) { if(argc == 5) { - Tcl_AppendResult(interp, (inst_ptr[inst].ptr+instdef)->boxptr[PINLAYER][n].prop_ptr, NULL); + Tcl_AppendResult(interp, (xctx.inst[inst].ptr+ xctx.sym)->rect[PINLAYER][n].prop_ptr, NULL); } else { tmp = 100 + strlen(argv[4]) + strlen(argv[5]); subtok = my_malloc(83,tmp); my_snprintf(subtok, tmp, "%s(%s)", argv[5], argv[4]); - value = get_tok_value(inst_ptr[inst].prop_ptr,subtok,0); + value = get_tok_value(xctx.inst[inst].prop_ptr,subtok,0); if(!value[0]) { my_snprintf(subtok, tmp, "%s(%d)", argv[5], n); - value = get_tok_value(inst_ptr[inst].prop_ptr,subtok,0); + value = get_tok_value(xctx.inst[inst].prop_ptr,subtok,0); } if(!value[0]) { - value = get_tok_value((inst_ptr[inst].ptr+instdef)->boxptr[PINLAYER][n].prop_ptr,argv[5],0); + value = get_tok_value((xctx.inst[inst].ptr+ xctx.sym)->rect[PINLAYER][n].prop_ptr,argv[5],0); } if(value[0] != 0) { char *ss; int slot; - if( (ss = strchr(inst_ptr[inst].instname, ':')) ) { + if( (ss = strchr(xctx.inst[inst].instname, ':')) ) { sscanf(ss + 1, "%d", &slot); if(strstr(value, ":")) value = find_nth(value, ':', slot); } @@ -687,47 +693,48 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg my_free(924, &subtok); } } - } else if( !strcmp(argv[2],"symbol")) { /* 20171028 */ + } else if( !strcmp(argv[2],"symbol")) { int i, found=0; if(argc!=5 && argc !=4) { Tcl_AppendResult(interp, "xschem getprop needs 2 or 3 additional arguments", NULL); return TCL_ERROR; } - for(i=0; irects[PINLAYER]; + no_of_pins= (xctx.inst[i].ptr+ xctx.sym)->rects[PINLAYER]; for(p=0;pboxptr[PINLAYER][p].prop_ptr, argv[3], 0), + get_tok_value((xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER][p].prop_ptr, argv[3], 0), "} } ", NULL); } else { - Tcl_AppendResult(interp, "{ {", s, "} {", (inst_ptr[i].ptr+instdef)->boxptr[PINLAYER][p].prop_ptr, "} } ", NULL); + Tcl_AppendResult(interp, "{ {", s, "} {", + (xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER][p].prop_ptr, "} } ", NULL); } - + } - } else if(!strcmp(argv[1],"instance_net")) { /* 20171029 */ + } else if(!strcmp(argv[1],"instance_net")) { int no_of_pins, i, p, mult; const char *str_ptr=NULL; @@ -740,10 +747,10 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg return TCL_ERROR; } prepare_netlist_structs(0); - no_of_pins= (inst_ptr[i].ptr+instdef)->rects[PINLAYER]; + no_of_pins= (xctx.inst[i].ptr+ xctx.sym)->rects[PINLAYER]; for(p=0;pboxptr[PINLAYER][p].prop_ptr,"name",0), argv[3])) { - /*str_ptr = inst_ptr[i].node[p] ? inst_ptr[i].node[p]: ""; */ + if(!strcmp( get_tok_value((xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER][p].prop_ptr,"name",0), argv[3])) { + /*str_ptr = xctx.inst[i].node[p] ? xctx.inst[i].node[p]: ""; */ str_ptr = net_name(i,p,&mult, 0); break; } @@ -751,7 +758,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg if(p>=no_of_pins) { Tcl_AppendResult(interp, "Pin not found", NULL); return TCL_ERROR; - } + } Tcl_AppendResult(interp, str_ptr, NULL); } else if(!strcmp(argv[1],"selected_set")) { int n, i; @@ -760,7 +767,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg for(n=0; n < lastselected; n++) { if(selectedgroup[n].type == ELEMENT) { i = selectedgroup[n].n; - my_strcat(645, &res, inst_ptr[i].instname); + my_strcat(645, &res, xctx.inst[i].instname); if(n < lastselected-1) my_strcat(646, &res, " "); } } @@ -771,22 +778,22 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg Tcl_AppendResult(interp, "xschem select: missing arguments.", NULL); return TCL_ERROR; } - + if(!strcmp(argv[2],"instance") && argc==4) { char *endptr; int i,found=0; int n; n=strtol(argv[3], &endptr, 10); - + /* 20171006 find by instance name */ - for(i=0;i= 0) { + if(!found && !(endptr == argv[3]) && n= 0) { select_element(n, SELECTED, 0, 0); found = 1; } @@ -795,15 +802,15 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg Tcl_AppendResult(interp, "xschem select instance: instance not found", NULL); return TCL_ERROR; } - + } else if(!strcmp(argv[2],"wire") && argc==4) { int n=atol(argv[3]); - if(n= 0) select_wire(atol(argv[3]), SELECTED, 0); + if(n= 0) select_wire(atol(argv[3]), SELECTED, 0); } else if(!strcmp(argv[2],"text") && argc==4) { int n=atol(argv[3]); - if(n= 0) select_text(atol(argv[3]), SELECTED, 0); + if(n= 0) select_text(atol(argv[3]), SELECTED, 0); } drawtemparc(gc[SELLAYER], END, 0.0, 0.0, 0.0, 0.0, 0.0); drawtemprect(gc[SELLAYER], END, 0.0, 0.0, 0.0, 0.0); @@ -817,13 +824,13 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg int x = !(atoi(argv[8])); place_symbol(-1, argv[2], atof(argv[3]), atof(argv[4]), atoi(argv[5]), atoi(argv[6]), argv[7], 0, x); } - } else if(!strcmp(argv[1],"arc")) { /* 20171022 */ + } else if(!strcmp(argv[1],"arc")) { ui_state |= MENUSTARTARC; - } else if(!strcmp(argv[1],"circle")) { /* 20171022 */ + } else if(!strcmp(argv[1],"circle")) { ui_state |= MENUSTARTCIRCLE; - } else if(!strcmp(argv[1],"snap_wire")) { /* 20171022 */ + } else if(!strcmp(argv[1],"snap_wire")) { ui_state |= MENUSTARTSNAPWIRE; - } else if(!strcmp(argv[1],"wire")) { + } else if(!strcmp(argv[1],"wire")) { double x1,y1,x2,y2; int pos, save; const char *prop; @@ -835,7 +842,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg ORDER(x1,y1,x2,y2); pos=-1; if(argc >= 7) pos=atol(argv[6]); - if(argc == 8) prop = argv[7]; + if(argc == 8) prop = argv[7]; else prop = NULL; push_undo(); storeobject(pos, x1,y1,x2,y2,WIRE,0,0,prop); @@ -848,7 +855,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg draw_window = save; } else ui_state |= MENUSTARTWIRE; - } else if(!strcmp(argv[1],"line")) { + } else if(!strcmp(argv[1],"line")) { double x1,y1,x2,y2; int pos, save; if(argc>=6) { @@ -863,7 +870,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg save = draw_window; draw_window = 1; drawline(rectcolor,NOW, x1,y1,x2,y2, 0); draw_window = save; - } + } else ui_state |= MENUSTARTLINE; } else if(!strcmp(argv[1],"rect")) { double x1,y1,x2,y2; @@ -880,7 +887,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg save = draw_window; draw_window = 1; drawrect(rectcolor,NOW, x1,y1,x2,y2, 0); draw_window = save; - } + } else ui_state |= MENUSTARTRECT; } else if(!strcmp(argv[1],"polygon")) { ui_state |= MENUSTARTPOLYGON; @@ -910,7 +917,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg } else if(!strcmp(argv[1],"save")) { dbg(1, "xschem(): saving: current schematic\n"); - if(!strcmp(schematic[currentsch],"")) { /* 20170622 check if unnamed schematic, use saveas in this case... */ + if(!strcmp(xctx.sch[xctx.currsch],"")) { /* 20170622 check if unnamed schematic, use saveas in this case... */ saveas(NULL, SCHEMATIC); } else { save(0); @@ -921,34 +928,34 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg printf("*******global variables:*******\n"); printf("netlist_dir=%s\n", netlist_dir? netlist_dir: ""); printf("lw=%d\n", lw); - printf("lastwire=%d\n", lastwire); - printf("lastinst=%d\n", lastinst); - printf("lastinstdef=%d\n", lastinstdef); + printf("wires=%d\n", xctx.wires); + printf("instances=%d\n", xctx.instances); + printf("symbols=%d\n", xctx.symbols); printf("lastselected=%d\n", lastselected); - printf("lasttext=%d\n", lasttext); - printf("max_texts=%d\n", max_texts); - printf("max_wires=%d\n", max_wires); - printf("max_instances=%d\n", max_instances); + printf("texts=%d\n", xctx.texts); + printf("maxt=%d\n", xctx.maxt); + printf("maxw=%d\n", xctx.maxw); + printf("maxi=%d\n", xctx.maxi); printf("max_selected=%d\n", max_selected); - printf("zoom=%.16g\n", zoom); - printf("xorigin=%.16g\n", xorigin); - printf("yorigin=%.16g\n", yorigin); + printf("zoom=%.16g\n", xctx.zoom); + printf("xorigin=%.16g\n", xctx.xorigin); + printf("yorigin=%.16g\n", xctx.yorigin); for(i=0;i<8;i++) { - printf("lastrect[%d]=%d\n", i, lastrect[i]); - printf("lastline[%d]=%d\n", i, lastline[i]); - printf("max_rects[%d]=%d\n", i, max_rects[i]); - printf("max_lines[%d]=%d\n", i, max_lines[i]); + printf("rects[%d]=%d\n", i, xctx.rects[i]); + printf("lines[%d]=%d\n", i, xctx.lines[i]); + printf("maxr[%d]=%d\n", i, xctx.maxr[i]); + printf("maxl[%d]=%d\n", i, xctx.maxl[i]); } for(i=0;i"); - printf("schematic[%d]=%s\n",i,schematic[i]); + printf("previous_instance[%d]=%d\n",i,xctx.previous_instance[i]); + printf("sch_path[%d]=%s\n",i,xctx.sch_path[i]? xctx.sch_path[i]:""); + printf("sch[%d]=%s\n",i,xctx.sch[i]); } printf("modified=%d\n", modified); printf("color_ps=%d\n", color_ps); @@ -976,7 +983,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg printf(" xschem globals\n"); printf(" print information about global variables\n"); printf(" xschem inst_ptr n\n"); - printf(" return inst_ptr of inst_ptr[n]\n"); + printf(" return inst_ptr of inst[n]\n"); printf(" xschem netlist\n"); printf(" perform a global netlist on current schematic\n"); printf(" xschem netlist_type type\n"); @@ -1094,7 +1101,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg global_verilog_netlist(1); else if(netlist_type == CAD_TEDAX_NETLIST) global_tedax_netlist(1); - else + else if(has_x) tcleval("tk_messageBox -type ok -message {Please Set netlisting mode (Options menu)}"); } } @@ -1108,7 +1115,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(!strcmp(argv[1],"create_plot_cmd") ) { if(argc>2) { if(!strcmp(argv[2], "gaw")) { - create_plot_cmd(GAW); + create_plot_cmd(GAW); } else { create_plot_cmd(NGSPICE); } @@ -1128,7 +1135,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg Tcl_AppendResult(interp, str, NULL); my_free(1161, &str); } - + else if(!strcmp(argv[1],"clear_netlist_dir") ) { my_strdup(373, &netlist_dir, ""); } @@ -1136,14 +1143,14 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(!strcmp(argv[1],"edit_file") ) { rebuild_selected_array(); if(lastselected==0 ) { - save_schematic(schematic[currentsch]); /* sync data with disk file before editing file */ - my_snprintf(name, S(name), "edit_file {%s}", - abs_sym_path(schematic[currentsch], "")); + save_schematic(xctx.sch[xctx.currsch]); /* sync data with disk file before editing file */ + my_snprintf(name, S(name), "edit_file {%s}", + abs_sym_path(xctx.sch[xctx.currsch], "")); tcleval(name); } else if(selectedgroup[0].type==ELEMENT) { - my_snprintf(name, S(name), "edit_file {%s}", - abs_sym_path(inst_ptr[selectedgroup[0].n].name, "")); + my_snprintf(name, S(name), "edit_file {%s}", + abs_sym_path(xctx.inst[selectedgroup[0].n].name, "")); tcleval(name); } @@ -1193,7 +1200,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg set_different_token(&s, argv[3], argv[4], 0, 0); Tcl_AppendResult(interp, s, NULL); my_free(1156, &s); - } + } else if(!strcmp(argv[1],"get_tok") ) { char *s=NULL; @@ -1211,13 +1218,13 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg if(argc==3) { dbg(1, "xschem(): load: filename=%s\n", argv[2]); delete_hilight_net(); - currentsch = 0; - unselect_all(); /* 20180929 */ + xctx.currsch = 0; + unselect_all(); remove_symbols(); /* load_symbol(argv[2]); */ load_schematic(0, argv[2], 1); - my_strdup(374, &sch_path[currentsch],"."); - sch_inst_number[currentsch] = 1; + my_strdup(374, &xctx.sch_path[xctx.currsch],"."); + xctx.sch_inst_number[xctx.currsch] = 1; zoom_full(1, 0); } } @@ -1228,17 +1235,17 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg if(!has_x || !modified || !save(1) ) { /* save(1)==1 --> user cancel */ dbg(1, "xschem(): load: filename=%s\n", argv[2]); delete_hilight_net(); - currentsch = 0; - unselect_all(); /* 20180929 */ + xctx.currsch = 0; + unselect_all(); remove_symbols(); load_schematic(1, abs_sym_path(argv[2], ""), 1); Tcl_VarEval(interp, "update_recent_file {", abs_sym_path(argv[2], ""), "}", NULL); - my_strdup(375, &sch_path[currentsch],"."); - sch_inst_number[currentsch] = 1; + my_strdup(375, &xctx.sch_path[xctx.currsch],"."); + xctx.sch_inst_number[xctx.currsch] = 1; zoom_full(1, 0); } } - else if(argc==2) { + else if(argc==2) { ask_new_file(); } } @@ -1371,7 +1378,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg Tcl_ResetResult(interp); } - else if(!strcmp(argv[1],"trim_wires")) /* 20171022 */ + else if(!strcmp(argv[1],"trim_wires")) { push_undo(); trim_wires(); @@ -1387,7 +1394,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(!strcmp(argv[1],"enable_layers")) { - enable_layers(); + enable_layers(); Tcl_ResetResult(interp); } else if(argc == 4 && !strcmp(argv[1], "list_tokens")) { @@ -1401,7 +1408,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg } else if(!strcmp(argv[1],"unhilight")) { - Box boundbox; + xRect boundbox; enable_drill=0; calc_drawing_bbox(&boundbox, 2); delete_hilight_net(); @@ -1455,7 +1462,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg Tcl_ResetResult(interp); } - else if(!strcmp(argv[1],"search") || !strcmp(argv[1],"searchmenu")) + else if(!strcmp(argv[1],"search") || !strcmp(argv[1],"searchmenu")) { /* 0 1 2 3 4 5 6(opt) */ /* select */ @@ -1491,19 +1498,19 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(!strcmp(argv[1],"instance_bbox")) { int i; char s[200]; - for(i=0;iminx, - (inst_ptr[i].ptr+instdef)->miny, - (inst_ptr[i].ptr+instdef)->maxx, - (inst_ptr[i].ptr+instdef)->maxy + my_snprintf(s, S(s), "\nSymbol: %g %g %g %g", + (xctx.inst[i].ptr+ xctx.sym)->minx, + (xctx.inst[i].ptr+ xctx.sym)->miny, + (xctx.inst[i].ptr+ xctx.sym)->maxx, + (xctx.inst[i].ptr+ xctx.sym)->maxy ); Tcl_AppendResult(interp, s, NULL); } @@ -1512,12 +1519,12 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(!strcmp(argv[1],"instance_pos")) { int i; char s[30]; - for(i=0;irects[PINLAYER]; + no_of_pins= (xctx.inst[i].ptr+ xctx.sym)->rects[PINLAYER]; for(p=0;pboxptr[PINLAYER][p].prop_ptr,"name",0); + pin = get_tok_value((xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER][p].prop_ptr,"name",0); if(!pin[0]) pin = "--ERROR--"; my_strcat(376, &pins, pin); if(p< no_of_pins-1) my_strcat(377, &pins, " "); @@ -1550,24 +1557,24 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(argc >= 3 && !strcmp(argv[1],"get") && !strcmp(argv[2],"schname") ) { int x; if(argc == 4) x = atoi(argv[3]); - else x = currentsch; - if(x<0 && currentsch+x>=0) { - Tcl_AppendResult(interp, schematic[currentsch+x], NULL); - } else if(x<=currentsch) { - Tcl_AppendResult(interp, schematic[x], NULL); + else x = xctx.currsch; + if(x<0 && xctx.currsch+x>=0) { + Tcl_AppendResult(interp, xctx.sch[xctx.currsch+x], NULL); + } else if(x<=xctx.currsch) { + Tcl_AppendResult(interp, xctx.sch[x], NULL); } } - else if(argc >=3 && !strcmp(argv[1],"get") && !strcmp(argv[2],"sch_path")) { /* 20121121 */ + else if(argc >=3 && !strcmp(argv[1],"get") && !strcmp(argv[2],"sch_path")) { int x; if(argc == 4) x = atoi(argv[3]); - else x = currentsch; - if(x<0 && currentsch+x>=0) { - Tcl_AppendResult(interp, sch_path[currentsch+x], NULL); - } else if(x<=currentsch) { - Tcl_AppendResult(interp, sch_path[x], NULL); + else x = xctx.currsch; + if(x<0 && xctx.currsch+x>=0) { + Tcl_AppendResult(interp, xctx.sch_path[xctx.currsch+x], NULL); + } else if(x<=xctx.currsch) { + Tcl_AppendResult(interp, xctx.sch_path[x], NULL); } } - else if(argc == 4 && !strcmp(argv[1],"get") && !strcmp(argv[2],"expandlabel")) { /* 20121121 */ + else if(argc == 4 && !strcmp(argv[1],"get") && !strcmp(argv[2],"expandlabel")) { int tmp, llen; char *result=NULL; const char *l; @@ -1587,7 +1594,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else Tcl_AppendResult(interp, "0",NULL); } - else if(!strcmp(argv[2],"auto_hilight")) { /* 20160413 */ + else if(!strcmp(argv[2],"auto_hilight")) { if( auto_hilight != 0 ) Tcl_AppendResult(interp, "1",NULL); else @@ -1618,14 +1625,14 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg Tcl_AppendResult(interp, "0",NULL); } else if(!strcmp(argv[2],"bbox_selected")) { - Box boundbox; + xRect boundbox; char res[2048]; calc_drawing_bbox(&boundbox, 1); my_snprintf(res, S(res), "%g %g %g %g", boundbox.x1, boundbox.y1, boundbox.x2, boundbox.y2); Tcl_AppendResult(interp, res, NULL); } else if(!strcmp(argv[2],"bbox_hilighted")) { - Box boundbox; + xRect boundbox; char res[2048]; calc_drawing_bbox(&boundbox, 2); my_snprintf(res, S(res), "%g %g %g %g", boundbox.x1, boundbox.y1, boundbox.x2, boundbox.y2); @@ -1637,7 +1644,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else Tcl_AppendResult(interp, "0",NULL); } - else if(!strcmp(argv[2],"help")) { /* 20140406 */ + else if(!strcmp(argv[2],"help")) { if( help != 0 ) Tcl_AppendResult(interp, "1",NULL); else @@ -1649,7 +1656,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else Tcl_AppendResult(interp, "0",NULL); } - else if(!strcmp(argv[2],"only_probes")) { /* 20110112 */ + else if(!strcmp(argv[2],"only_probes")) { if( only_probes != 0 ) Tcl_AppendResult(interp, "1",NULL); else @@ -1700,9 +1707,9 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg my_snprintf(s, S(s), "%d",debug_var); Tcl_AppendResult(interp, s,NULL); } - else if(!strcmp(argv[2],"currentsch")) { + else if(!strcmp(argv[2],"currsch")) { char s[30]; /* overflow safe 20161122 */ - my_snprintf(s, S(s), "%d",currentsch); + my_snprintf(s, S(s), "%d",xctx.currsch); Tcl_AppendResult(interp, s,NULL); } else if(!strcmp(argv[2],"semaphore")) { @@ -1728,47 +1735,47 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(!strcmp(argv[2],"netlist_dir")) { Tcl_AppendResult(interp, netlist_dir,NULL); } - else if(!strcmp(argv[2],"dim")) { /* 20121121 */ + else if(!strcmp(argv[2],"dim")) { char s[40]; my_snprintf(s, S(s), "%.2g", color_dim); Tcl_AppendResult(interp, s, NULL); } - else if(!strcmp(argv[2],"lastinst")) { /* 20121121 */ + else if(!strcmp(argv[2],"instances")) { char s[30]; /* overflow safe 20161122 */ - my_snprintf(s, S(s), "%d",lastinst); + my_snprintf(s, S(s), "%d",xctx.instances); Tcl_AppendResult(interp, s,NULL); } - else if(!strcmp(argv[2],"pinlayer")) { /* 20121121 */ + else if(!strcmp(argv[2],"pinlayer")) { char s[30]; /* overflow safe 20161122 */ my_snprintf(s, S(s), "%d",PINLAYER); Tcl_AppendResult(interp, s,NULL); } - else if(!strcmp(argv[2],"wirelayer")) { /* 20121121 */ + else if(!strcmp(argv[2],"wirelayer")) { char s[30]; /* overflow safe 20161122 */ my_snprintf(s, S(s), "%d",WIRELAYER); Tcl_AppendResult(interp, s,NULL); } - else if(!strcmp(argv[2],"textlayer")) { /* 20121121 */ + else if(!strcmp(argv[2],"textlayer")) { char s[30]; /* overflow safe 20161122 */ my_snprintf(s, S(s), "%d",TEXTLAYER); Tcl_AppendResult(interp, s,NULL); } - else if(!strcmp(argv[2],"sellayer")) { /* 20121121 */ + else if(!strcmp(argv[2],"sellayer")) { char s[30]; /* overflow safe 20161122 */ my_snprintf(s, S(s), "%d",SELLAYER); Tcl_AppendResult(interp, s,NULL); } - else if(!strcmp(argv[2],"gridlayer")) { /* 20121121 */ + else if(!strcmp(argv[2],"gridlayer")) { char s[30]; /* overflow safe 20161122 */ my_snprintf(s, S(s), "%d",GRIDLAYER); Tcl_AppendResult(interp, s,NULL); } - else if(!strcmp(argv[2],"backlayer")) { /* 20121121 */ + else if(!strcmp(argv[2],"backlayer")) { char s[30]; /* overflow safe 20161122 */ my_snprintf(s, S(s), "%d",BACKLAYER); Tcl_AppendResult(interp, s,NULL); } - else if(!strcmp(argv[2],"version")) { /* 20121121 */ + else if(!strcmp(argv[2],"version")) { char s[30]; /* overflow safe 20161122 */ my_snprintf(s, S(s), "XSCHEM V%s",XSCHEM_VERSION); Tcl_AppendResult(interp, s,NULL); @@ -1810,19 +1817,19 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg } } - /* + /* * ********** xschem set subcommands */ - else if(!strcmp(argv[1],"set") && argc==3) { /* 20171023 */ - if(!strcmp(argv[2],"horizontal_move")) { /* 20171023 */ + else if(!strcmp(argv[1],"set") && argc==3) { + if(!strcmp(argv[2],"horizontal_move")) { horizontal_move = atoi(tclgetvar("horizontal_move")); if(horizontal_move) { vertical_move=0; tcleval("set vertical_move 0" ); } } - else if(!strcmp(argv[2],"vertical_move")) { /* 20171023 */ + else if(!strcmp(argv[2],"vertical_move")) { vertical_move = atoi(tclgetvar("vertical_move")); if(vertical_move) { horizontal_move=0; @@ -1845,23 +1852,23 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg } } else #endif - if(!strcmp(argv[2],"no_undo")) { /* 20171204 */ + if(!strcmp(argv[2],"no_undo")) { int s = atoi(argv[3]); no_undo=s; } - else if(!strcmp(argv[2],"no_draw")) { /* 20171204 */ + else if(!strcmp(argv[2],"no_draw")) { int s = atoi(argv[3]); no_draw=s; } - else if(!strcmp(argv[2],"hide_symbols")) { /* 20171204 */ + else if(!strcmp(argv[2],"hide_symbols")) { int s = atoi(argv[3]); hide_symbols=s; } - else if(!strcmp(argv[2],"show_pin_net_names")) { /* 20171204 */ + else if(!strcmp(argv[2],"show_pin_net_names")) { int s = atoi(argv[3]); show_pin_net_names=s; } - else if(!strcmp(argv[2],"user_top_netl_name")) { /* 20171204 */ + else if(!strcmp(argv[2],"user_top_netl_name")) { my_strncpy(user_top_netl_name, argv[3], S(user_top_netl_name)); } else if(!strcmp(argv[2],"dim")) { @@ -1895,14 +1902,14 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg double s = atof(argv[3]); if(s>-20. && s<20.) nocairo_vert_correct = s; } - else if(!strcmp(argv[2],"persistent_command")) { /* 20171025 */ + else if(!strcmp(argv[2],"persistent_command")) { if(!strcmp(argv[3],"1")) { persistent_command=1; } else { persistent_command=0; } } - else if(!strcmp(argv[2],"disable_unique_names")) { /* 20171025 */ + else if(!strcmp(argv[2],"disable_unique_names")) { if(!strcmp(argv[3],"1")) { dis_uniq_names=1; } else { @@ -1912,7 +1919,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(!strcmp(argv[2],"incr_hilight")) { incr_hilight=atoi(argv[3]); } - else if(!strcmp(argv[2],"auto_hilight")) { /* 20160413 */ + else if(!strcmp(argv[2],"auto_hilight")) { auto_hilight=atoi(argv[3]); } else if(!strcmp(argv[2],"netlist_show")) { @@ -1922,13 +1929,13 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(!strcmp(argv[2],"semaphore")) { semaphore=atoi(argv[3]); } - else if(!strcmp(argv[2],"cadsnap")) { /* 20161212 */ + else if(!strcmp(argv[2],"cadsnap")) { set_snap( atof(argv[3]) ); } - else if(!strcmp(argv[2],"spiceprefix")) { /* 20161212 */ + else if(!strcmp(argv[2],"spiceprefix")) { spiceprefix=atoi(argv[3]); } - else if(!strcmp(argv[2],"cadgrid")) { /* 20161212 */ + else if(!strcmp(argv[2],"cadgrid")) { set_grid( atof(argv[3]) ); } else if(!strcmp(argv[2],"flat_netlist")) { @@ -1946,10 +1953,10 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(!strcmp(argv[2],"color_ps")) { color_ps=atoi(argv[3]); } - else if(!strcmp(argv[2],"only_probes")) { /* 20110112 */ + else if(!strcmp(argv[2],"only_probes")) { only_probes=atoi(argv[3]); } - else if(!strcmp(argv[2],"event_reporting")) { /* 20110112 */ + else if(!strcmp(argv[2],"event_reporting")) { event_reporting=atoi(argv[3]); } else if(!strcmp(argv[2],"draw_grid")) { @@ -2002,7 +2009,7 @@ void tcleval(const char str[]) fprintf(errfp, "tcleval(): evaluation of script: %s failed\n", str); } } -const char *tclresult(void) +const char *tclresult(void) { return Tcl_GetStringResult(interp); } diff --git a/src/select.c b/src/select.c index 4631f624..62eefba8 100644 --- a/src/select.c +++ b/src/select.c @@ -1,7 +1,7 @@ /* File: select.c - * + * * This file is part of XSCHEM, - * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit + * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit * simulation. * Copyright (C) 1998-2020 Stefan Frederik Schippers * @@ -31,7 +31,7 @@ static double xx1,yy1,xx2,yy2; void symbol_bbox(int i, double *x1,double *y1, double *x2, double *y2) { int j; - Text text; + xText text; const char *tmp_txt; int rot,flip; double x0, y0 ; @@ -44,30 +44,30 @@ void symbol_bbox(int i, double *x1,double *y1, double *x2, double *y2) int customfont; #endif /* symbol bbox */ - flip = inst_ptr[i].flip; - rot = inst_ptr[i].rot; - x0=inst_ptr[i].x0; - y0=inst_ptr[i].y0; - ROTATION(0.0,0.0,(inst_ptr[i].ptr+instdef)->minx, - (inst_ptr[i].ptr+instdef)->miny,*x1,*y1); - ROTATION(0.0,0.0,(inst_ptr[i].ptr+instdef)->maxx, - (inst_ptr[i].ptr+instdef)->maxy,*x2,*y2); + flip = xctx.inst[i].flip; + rot = xctx.inst[i].rot; + x0=xctx.inst[i].x0; + y0=xctx.inst[i].y0; + ROTATION(0.0,0.0,(xctx.inst[i].ptr+ xctx.sym)->minx, + (xctx.inst[i].ptr+ xctx.sym)->miny,*x1,*y1); + ROTATION(0.0,0.0,(xctx.inst[i].ptr+ xctx.sym)->maxx, + (xctx.inst[i].ptr+ xctx.sym)->maxy,*x2,*y2); RECTORDER(*x1,*y1,*x2,*y2); *x1+=x0;*y1+=y0; *x2+=x0;*y2+=y0; - inst_ptr[i].xx1 = *x1; /* 20070314 added bbox without text */ - inst_ptr[i].yy1 = *y1; /* for easier select */ - inst_ptr[i].xx2 = *x2; - inst_ptr[i].yy2 = *y2; + xctx.inst[i].xx1 = *x1; /* 20070314 added bbox without text */ + xctx.inst[i].yy1 = *y1; /* for easier select */ + xctx.inst[i].xx2 = *x2; + xctx.inst[i].yy2 = *y2; dbg(2, "symbol_bbox(): instance=%d %.16g %.16g %.16g %.16g\n",i,*x1, *y1, *x2, *y2); - + /* strings bbox */ - for(j=0;j< (inst_ptr[i].ptr+instdef)->texts;j++) + for(j=0;j< (xctx.inst[i].ptr+ xctx.sym)->texts;j++) { sym_flip = flip; sym_rot = rot; - text = (inst_ptr[i].ptr+instdef)->txtptr[j]; - dbg(2, "symbol_bbox(): instance %d text n: %d text str=%s\n", + text = (xctx.inst[i].ptr+ xctx.sym)->text[j]; + dbg(2, "symbol_bbox(): instance %d text n: %d text str=%s\n", i,j, text.txt_ptr? text.txt_ptr:"NULL"); tmp_txt = translate(i, text.txt_ptr); @@ -77,7 +77,7 @@ void symbol_bbox(int i, double *x1,double *y1, double *x2, double *y2) #ifdef HAS_CAIRO customfont=set_text_custom_font(&text); #endif - text_bbox(tmp_txt, text.xscale, text.yscale, + text_bbox(tmp_txt, text.xscale, text.yscale, (text.rot + ( (sym_flip && (text.rot & 1) ) ? sym_rot+2 : sym_rot)) &0x3, sym_flip ^ text.flip, text.hcenter, text.vcenter, x0+text_x0,y0+text_y0, &xx1,&yy1,&xx2,&yy2); @@ -96,110 +96,110 @@ void symbol_bbox(int i, double *x1,double *y1, double *x2, double *y2) static void del_rect_line_arc_poly(void) { - Box tmp; + xRect tmp; int c, j, i; for(c=0;c x2) x2 = polygon[c][i].x[k]; - if(k==0 || polygon[c][i].y[k] > y2) y2 = polygon[c][i].y[k]; + for(k=0; k x2) x2 = xctx.poly[c][i].x[k]; + if(k==0 || xctx.poly[c][i].y[k] > y2) y2 = xctx.poly[c][i].y[k]; } j++; bbox(ADD, x1, y1, x2, y2); - my_free(931, &polygon[c][i].prop_ptr); - my_free(932, &polygon[c][i].x); - my_free(933, &polygon[c][i].y); - my_free(934, &polygon[c][i].selected_point); + my_free(931, &xctx.poly[c][i].prop_ptr); + my_free(932, &xctx.poly[c][i].x); + my_free(933, &xctx.poly[c][i].y); + my_free(934, &xctx.poly[c][i].selected_point); /*fprintf(errfp, "bbox: %.16g %.16g %.16g %.16g\n", x1, y1, x2, y2); */ set_modify(1); continue; } if(j) { - polygon[c][i-j] = polygon[c][i]; + xctx.poly[c][i-j] = xctx.poly[c][i]; } } - lastpolygon[c] -= j; + xctx.polygons[c] -= j; } } @@ -215,17 +215,17 @@ void delete(void) j = 0; bbox(BEGIN, 0.0 , 0.0 , 0.0 , 0.0); rebuild_selected_array(); - if(lastselected) push_undo(); /* 20150327 */ + if(lastselected) push_undo(); /* first calculate bbox, because symbol_bbox() needs translate (@#0:net_name) which needs prepare_netlist_structs - * which needs a consistent inst_ptr[] data structure */ - + * which needs a consistent xctx.inst[] data structure */ + /* does not seem to be needed prepared_netlist_structs=0; prepared_hilight_structs=0; - */ + */ if(show_pin_net_names) { prepare_netlist_structs(0); } @@ -234,16 +234,16 @@ void delete(void) /* should be done only for ipin, opin, iopin, label <<<<< */ if(selectedgroup[i].type == ELEMENT) { int p; - symbol_bbox(n, &inst_ptr[n].x1, &inst_ptr[n].y1, &inst_ptr[n].x2, &inst_ptr[n].y2 ); /* 20171201 */ - bbox(ADD, inst_ptr[n].x1, inst_ptr[n].y1, inst_ptr[n].x2, inst_ptr[n].y2 ); - if(show_pin_net_names) for(p = 0; p < (inst_ptr[n].ptr + instdef)->rects[PINLAYER]; p++) { - if( inst_ptr[n].node && inst_ptr[n].node[p]) { - find_inst_to_be_redrawn(inst_ptr[n].node[p]); + symbol_bbox(n, &xctx.inst[n].x1, &xctx.inst[n].y1, &xctx.inst[n].x2, &xctx.inst[n].y2 ); + bbox(ADD, xctx.inst[n].x1, xctx.inst[n].y1, xctx.inst[n].x2, xctx.inst[n].y2 ); + if(show_pin_net_names) for(p = 0; p < (xctx.inst[n].ptr + xctx.sym)->rects[PINLAYER]; p++) { + if( xctx.inst[n].node && xctx.inst[n].node[p]) { + find_inst_to_be_redrawn(xctx.inst[n].node[p]); } } } - if(show_pin_net_names && selectedgroup[i].type == WIRE && wire[n].node) { - find_inst_to_be_redrawn(wire[n].node); + if(show_pin_net_names && selectedgroup[i].type == WIRE && xctx.wire[n].node) { + find_inst_to_be_redrawn(xctx.wire[n].node); } } if(show_pin_net_names) { @@ -252,37 +252,37 @@ void delete(void) - /* already done above - for(i=0;i cadhalfdotsize ? bus_width : CADHALFDOTSIZE; - if(wire[i].y1 < wire[i].y2) { y1 = wire[i].y1-ov; y2 = wire[i].y2+ov; } - else { y1 = wire[i].y1+ov; y2 = wire[i].y2-ov; } - bbox(ADD, wire[i].x1-ov, y1 , wire[i].x2+ov , y2 ); + if(xctx.wire[i].y1 < xctx.wire[i].y2) { y1 = xctx.wire[i].y1-ov; y2 = xctx.wire[i].y2+ov; } + else { y1 = xctx.wire[i].y1+ov; y2 = xctx.wire[i].y2-ov; } + bbox(ADD, xctx.wire[i].x1-ov, y1 , xctx.wire[i].x2+ov , y2 ); } else { int ov, y1, y2; ov = cadhalfdotsize; - if(wire[i].y1 < wire[i].y2) { y1 = wire[i].y1-ov; y2 = wire[i].y2+ov; } - else { y1 = wire[i].y1+ov; y2 = wire[i].y2-ov; } - bbox(ADD, wire[i].x1-ov, y1 , wire[i].x2+ov , y2 ); + if(xctx.wire[i].y1 < xctx.wire[i].y2) { y1 = xctx.wire[i].y1-ov; y2 = xctx.wire[i].y2+ov; } + else { y1 = xctx.wire[i].y1+ov; y2 = xctx.wire[i].y2-ov; } + bbox(ADD, xctx.wire[i].x1-ov, y1 , xctx.wire[i].x2+ov , y2 ); } - - my_free(941, &wire[i].prop_ptr); - my_free(942, &wire[i].node); - + + my_free(941, &xctx.wire[i].prop_ptr); + my_free(942, &xctx.wire[i].node); + set_modify(1); continue; } if(j) { - wire[i-j] = wire[i]; + xctx.wire[i-j] = xctx.wire[i]; } } - lastwire -= j; + xctx.wires -= j; if(j) { prepared_hash_wires=0; prepared_netlist_structs=0; @@ -389,7 +389,7 @@ void delete_only_rect_line_arc_poly(void) void bbox(int what,double x1,double y1, double x2, double y2) { int i; - static int bbx1, bbx2, bby1, bby2; + static int bbx1, bbx2, bby1, bby2; static int savew, saveh, savex1, savex2, savey1, savey2; static int sem=0; @@ -398,12 +398,12 @@ void bbox(int what,double x1,double y1, double x2, double y2) { case BEGIN: if(sem==1) { - fprintf(errfp, "ERROR: rentrant bbox() call\n"); - tcleval("alert_ {ERROR: reentrant bbox() call} {}");/*20171215 */ + fprintf(errfp, "ERROR: rentrant bbox() call\n"); + tcleval("alert_ {ERROR: reentrant bbox() call} {}"); } bbx1 = 300000000; bbx2 = 0; - bby1 = 300000000; + bby1 = 300000000; bby2 = 0; savex1 = areax1; savex2 = areax2; @@ -415,8 +415,8 @@ void bbox(int what,double x1,double y1, double x2, double y2) break; case ADD: if(sem==0) { - fprintf(errfp, "ERROR: bbox(ADD) call before bbox(BEGIN)\n"); - tcleval("alert_ {ERROR: bbox(ADD) call before bbox(BEGIN)} {}");/*20171215 */ + fprintf(errfp, "ERROR: bbox(ADD) call before bbox(BEGIN)\n"); + tcleval("alert_ {ERROR: bbox(ADD) call before bbox(BEGIN)} {}"); } x1=X_TO_SCREEN(x1); y1=Y_TO_SCREEN(y1); @@ -447,7 +447,7 @@ void bbox(int what,double x1,double y1, double x2, double y2) XSetClipMask(display, gctiled, None); /* 20171110 optimization, clipping already done in software */ - for(i=0;i",256); */ + /*my_strncpy(s,xctx.wire[i].prop_ptr!=NULL?xctx.wire[i].prop_ptr:"",256); */ if( !fast ) { my_snprintf(str, S(str), "selected wire: n=%d end1=%d end2=%d\nnode=%s",i, - wire[i].end1, wire[i].end2, - wire[i].prop_ptr? wire[i].prop_ptr: "(null)"); + xctx.wire[i].end1, xctx.wire[i].end2, + xctx.wire[i].prop_ptr? xctx.wire[i].prop_ptr: "(null)"); statusmsg(str,2); - /* 20070323 */ - my_snprintf(str, S(str), "n=%4d x = %.16g y = %.16g w = %.16g h = %.16g",i, wire[i].x1, wire[i].y1, - wire[i].x2-wire[i].x1, wire[i].y2-wire[i].y1 + + my_snprintf(str, S(str), "n=%4d x = %.16g y = %.16g w = %.16g h = %.16g",i, xctx.wire[i].x1, xctx.wire[i].y1, + xctx.wire[i].x2-xctx.wire[i].x1, xctx.wire[i].y2-xctx.wire[i].y1 ); statusmsg(str,1); } - if( ((wire[i].sel|select_mode) == (SELECTED1|SELECTED2)) || - ((wire[i].sel == SELECTED) && select_mode) ) - wire[i].sel = SELECTED; - else - wire[i].sel = select_mode; + if( ((xctx.wire[i].sel|select_mode) == (SELECTED1|SELECTED2)) || + ((xctx.wire[i].sel == SELECTED) && select_mode) ) + xctx.wire[i].sel = SELECTED; + else + xctx.wire[i].sel = select_mode; if(select_mode) { - dbg(1, "select(): wire[%d].end1=%d, ,end2=%d\n", i, wire[i].end1, wire[i].end2); - if(wire[i].bus) /* 20171201 */ - drawtempline(gc[SELLAYER], THICK, wire[i].x1, wire[i].y1, wire[i].x2, wire[i].y2); + dbg(1, "select(): xctx.wire[%d].end1=%d, ,end2=%d\n", i, xctx.wire[i].end1, xctx.wire[i].end2); + if(xctx.wire[i].bus) + drawtempline(gc[SELLAYER], THICK, xctx.wire[i].x1, xctx.wire[i].y1, xctx.wire[i].x2, xctx.wire[i].y2); else - drawtempline(gc[SELLAYER], ADD, wire[i].x1, wire[i].y1, wire[i].x2, wire[i].y2); + drawtempline(gc[SELLAYER], ADD, xctx.wire[i].x1, xctx.wire[i].y1, xctx.wire[i].x2, xctx.wire[i].y2); } else { - if(wire[i].bus) /* 20171201 */ - drawtempline(gctiled, THICK, wire[i].x1, wire[i].y1, wire[i].x2, wire[i].y2); + if(xctx.wire[i].bus) + drawtempline(gctiled, THICK, xctx.wire[i].x1, xctx.wire[i].y1, xctx.wire[i].x2, xctx.wire[i].y2); else - drawtempline(gctiled, NOW, wire[i].x1, wire[i].y1, wire[i].x2, wire[i].y2); + drawtempline(gctiled, NOW, xctx.wire[i].x1, xctx.wire[i].y1, xctx.wire[i].x2, xctx.wire[i].y2); } need_rebuild_selected_array=1; } @@ -644,41 +648,41 @@ void select_element(int i,unsigned short select_mode, int fast, int override_loc char str[1024]; /* overflow safe */ char s[256]; /* overflow safe */ - if(!strcmp(get_tok_value(inst_ptr[i].prop_ptr, "lock", 0), "true") && + if(!strcmp(get_tok_value(xctx.inst[i].prop_ptr, "lock", 0), "true") && select_mode == SELECTED && !override_lock) return; - my_strncpy(s,inst_ptr[i].prop_ptr!=NULL?inst_ptr[i].prop_ptr:"",S(s)); - if(event_reporting) { + my_strncpy(s,xctx.inst[i].prop_ptr!=NULL?xctx.inst[i].prop_ptr:"",S(s)); + if(event_reporting) { char n[PATH_MAX]; - printf("xschem search exact %d name %s\n", select_mode? 1:-1, escape_chars(n, inst_ptr[i].instname, PATH_MAX)); + printf("xschem search exact %d name %s\n", select_mode? 1:-1, escape_chars(n, xctx.inst[i].instname, PATH_MAX)); fflush(stdout); } if( !fast ) { - my_snprintf(str, S(str), "selected element %d: %s properties: %s", i, inst_ptr[i].name,s); + my_snprintf(str, S(str), "selected element %d: %s properties: %s", i, xctx.inst[i].name,s); statusmsg(str,2); - my_snprintf(str, S(str), "symbol name=%s", inst_ptr[i].name==NULL?"(null)":inst_ptr[i].name); + my_snprintf(str, S(str), "symbol name=%s", xctx.inst[i].name==NULL?"(null)":xctx.inst[i].name); statusmsg(str,2); /* 20190526 */ /*Why this? 20191125 only on small schematics. slow down on big schematics */ - if(lastinst < 150) { + if(xctx.instances < 150) { prepare_netlist_structs(0); - for(j=0;j< (inst_ptr[i].ptr+instdef)->rects[PINLAYER] ;j++) + for(j=0;j< (xctx.inst[i].ptr+ xctx.sym)->rects[PINLAYER] ;j++) { - if(inst_ptr[i].node && (inst_ptr[i].ptr+instdef)->boxptr[PINLAYER][j].prop_ptr) + if(xctx.inst[i].node && (xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER][j].prop_ptr) { - my_snprintf(str, S(str), "pin:%s -> %s", + my_snprintf(str, S(str), "pin:%s -> %s", get_tok_value( - (inst_ptr[i].ptr+instdef)->boxptr[PINLAYER][j].prop_ptr,"name",0) , - inst_ptr[i].node[j] ? inst_ptr[i].node[j] : ""); + (xctx.inst[i].ptr+ xctx.sym)->rect[PINLAYER][j].prop_ptr,"name",0) , + xctx.inst[i].node[j] ? xctx.inst[i].node[j] : ""); statusmsg(str,2); } } } - my_snprintf(str, S(str), "n=%4d x = %.16g y = %.16g w = %.16g h = %.16g",i, inst_ptr[i].xx1, inst_ptr[i].yy1, - inst_ptr[i].xx2-inst_ptr[i].xx1, inst_ptr[i].yy2-inst_ptr[i].yy1 + my_snprintf(str, S(str), "n=%4d x = %.16g y = %.16g w = %.16g h = %.16g",i, xctx.inst[i].xx1, xctx.inst[i].yy1, + xctx.inst[i].xx2-xctx.inst[i].xx1, xctx.inst[i].yy2-xctx.inst[i].yy1 ); statusmsg(str,1); } - inst_ptr[i].sel = select_mode; + xctx.inst[i].sel = select_mode; if(select_mode) { for(c=0;c",S(s)); + my_strncpy(s,xctx.text[i].prop_ptr!=NULL?xctx.text[i].prop_ptr:"",S(s)); my_snprintf(str, S(str), "selected text %d: properties: %s", i,s); statusmsg(str,2); - my_snprintf(str, S(str), "n=%4d x = %.16g y = %.16g", i, textelement[i].x0, textelement[i].y0); + my_snprintf(str, S(str), "n=%4d x = %.16g y = %.16g", i, xctx.text[i].x0, xctx.text[i].y0); statusmsg(str,1); } - textelement[i].sel = select_mode; + xctx.text[i].sel = select_mode; #ifdef HAS_CAIRO - customfont = set_text_custom_font(&textelement[i]); + customfont = set_text_custom_font(&xctx.text[i]); #endif if(select_mode) - draw_temp_string(gc[SELLAYER],ADD, textelement[i].txt_ptr, - textelement[i].rot, textelement[i].flip, textelement[i].hcenter, textelement[i].vcenter, - textelement[i].x0, textelement[i].y0, - textelement[i].xscale, textelement[i].yscale); + draw_temp_string(gc[SELLAYER],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); else - draw_temp_string(gctiled,NOW, textelement[i].txt_ptr, - textelement[i].rot, textelement[i].flip, textelement[i].hcenter, textelement[i].vcenter, - textelement[i].x0, textelement[i].y0, - textelement[i].xscale, textelement[i].yscale); + draw_temp_string(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); #endif @@ -733,31 +737,33 @@ void select_box(int c, int i, unsigned short select_mode, int fast) char s[256]; /* overflow safe */ if(!fast) { - my_strncpy(s,rect[c][i].prop_ptr!=NULL?rect[c][i].prop_ptr:"",S(s)); + my_strncpy(s,xctx.rect[c][i].prop_ptr!=NULL?xctx.rect[c][i].prop_ptr:"",S(s)); my_snprintf(str, S(str), "selected box : layer=%d, n=%d properties: %s",c-4,i,s); statusmsg(str,2); - /* 20070323 */ - my_snprintf(str, S(str), "n=%4d x = %.16g y = %.16g w = %.16g h = %.16g", i, rect[c][i].x1, rect[c][i].y1, - rect[c][i].x2-rect[c][i].x1, rect[c][i].y2-rect[c][i].y1 + + my_snprintf(str, S(str), "n=%4d x = %.16g y = %.16g w = %.16g h = %.16g", + i, xctx.rect[c][i].x1, xctx.rect[c][i].y1, + xctx.rect[c][i].x2-xctx.rect[c][i].x1, xctx.rect[c][i].y2-xctx.rect[c][i].y1 ); statusmsg(str,1); } if(select_mode) { if(select_mode==SELECTED) { - rect[c][i].sel = select_mode; /*20070202 */ + xctx.rect[c][i].sel = select_mode; } else { - rect[c][i].sel |= select_mode; /*20070202 */ + xctx.rect[c][i].sel |= select_mode; } - drawtemprect(gc[SELLAYER], ADD, rect[c][i].x1, rect[c][i].y1, rect[c][i].x2, rect[c][i].y2); + drawtemprect(gc[SELLAYER], ADD, xctx.rect[c][i].x1, xctx.rect[c][i].y1, + xctx.rect[c][i].x2, xctx.rect[c][i].y2); } else { - rect[c][i].sel = 0; /*20070202 */ - drawtemprect(gctiled, NOW, rect[c][i].x1, rect[c][i].y1, rect[c][i].x2, rect[c][i].y2); + xctx.rect[c][i].sel = 0; + drawtemprect(gctiled, NOW, xctx.rect[c][i].x1, xctx.rect[c][i].y1, + xctx.rect[c][i].x2, xctx.rect[c][i].y2); } - if( rect[c][i].sel == (SELECTED1|SELECTED2|SELECTED3|SELECTED4)) rect[c][i].sel = SELECTED; + if( xctx.rect[c][i].sel == (SELECTED1|SELECTED2|SELECTED3|SELECTED4)) xctx.rect[c][i].sel = SELECTED; need_rebuild_selected_array=1; - /* fprintf(errfp, "select_box(): select_mode=%d, box#=%d, rect[].sel=%d\n", select_mode, i, rect[c][i].sel); */ } @@ -768,23 +774,25 @@ void select_arc(int c, int i, unsigned short select_mode, int fast) char s[256]; /* overflow safe */ if(!fast) { - my_strncpy(s,rect[c][i].prop_ptr!=NULL?rect[c][i].prop_ptr:"",S(s)); + my_strncpy(s,xctx.rect[c][i].prop_ptr!=NULL?xctx.rect[c][i].prop_ptr:"",S(s)); my_snprintf(str, S(str), "selected arc : layer=%d, n=%d properties: %s",c-4,i,s); statusmsg(str,2); - /* 20070323 */ + my_snprintf(str, S(str), "n=%4d x = %.16g y = %.16g r = %.16g a = %.16g b = %.16g", - i, arc[c][i].x, arc[c][i].y, arc[c][i].r, arc[c][i].a, arc[c][i].b); + i, 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); statusmsg(str,1); } if(select_mode) { - arc[c][i].sel = select_mode; - drawtemparc(gc[SELLAYER], ADD, arc[c][i].x, arc[c][i].y, arc[c][i].r, arc[c][i].a, arc[c][i].b); + xctx.arc[c][i].sel = select_mode; + drawtemparc(gc[SELLAYER], 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); } else { - arc[c][i].sel = 0; /*20070202 */ - drawtemparc(gctiled, NOW, arc[c][i].x, arc[c][i].y, arc[c][i].r, arc[c][i].a, arc[c][i].b); + xctx.arc[c][i].sel = 0; + drawtemparc(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); } - /*if( arc[c][i].sel == (SELECTED1|SELECTED2|SELECTED3|SELECTED4)) arc[c][i].sel = SELECTED; */ + /*if( xctx.arc[c][i].sel == (SELECTED1|SELECTED2|SELECTED3|SELECTED4)) xctx.arc[c][i].sel = SELECTED; */ need_rebuild_selected_array=1; } @@ -801,16 +809,16 @@ void select_connected_nets(void) switch(selectedgroup[i].type) { case WIRE: - if(wire[n].sel==SELECTED) { - my_strdup(62, &str ,get_tok_value(wire[n].prop_ptr, "lab",0)); + if(xctx.wire[n].sel==SELECTED) { + my_strdup(62, &str ,get_tok_value(xctx.wire[n].prop_ptr, "lab",0)); if(str && str[0]) { search("lab", str,1, 1, NOW); } } break; case ELEMENT: - if(inst_ptr[n].sel==SELECTED) { - my_strdup(63, &str, get_tok_value(inst_ptr[n].prop_ptr, "lab",0)); + if(xctx.inst[n].sel==SELECTED) { + my_strdup(63, &str, get_tok_value(xctx.inst[n].prop_ptr, "lab",0)); if(str && str[0]) { search("lab", str,1, 1, NOW); } @@ -829,19 +837,19 @@ void select_polygon(int c, int i, unsigned short select_mode, int fast ) char s[256]; /* overflow safe */ if(!fast) { - my_strncpy(s,polygon[c][i].prop_ptr!=NULL?polygon[c][i].prop_ptr:"",S(s)); + my_strncpy(s,xctx.poly[c][i].prop_ptr!=NULL?xctx.poly[c][i].prop_ptr:"",S(s)); my_snprintf(str, S(str), "selected polygon: layer=%d, n=%d properties: %s",c-4,i,s); statusmsg(str,2); - /* 20070323 */ - my_snprintf(str, S(str), "n=%4d x0 = %.16g y0 = %.16g ...", i, polygon[c][i].x[0], polygon[c][i].y[0]); + + my_snprintf(str, S(str), "n=%4d x0 = %.16g y0 = %.16g ...", i, xctx.poly[c][i].x[0], xctx.poly[c][i].y[0]); statusmsg(str,1); } - polygon[c][i].sel = select_mode; + xctx.poly[c][i].sel = select_mode; if(select_mode) { - drawtemppolygon(gc[SELLAYER], NOW, polygon[c][i].x, polygon[c][i].y, polygon[c][i].points); + drawtemppolygon(gc[SELLAYER], NOW, xctx.poly[c][i].x, xctx.poly[c][i].y, xctx.poly[c][i].points); } else - drawtemppolygon(gctiled, NOW, polygon[c][i].x, polygon[c][i].y, polygon[c][i].points); + drawtemppolygon(gctiled, NOW, xctx.poly[c][i].x, xctx.poly[c][i].y, xctx.poly[c][i].points); need_rebuild_selected_array=1; } @@ -851,31 +859,36 @@ void select_line(int c, int i, unsigned short select_mode, int fast ) char s[256]; /* overflow safe */ if(!fast) { - my_strncpy(s,line[c][i].prop_ptr!=NULL?line[c][i].prop_ptr:"",S(s)); + my_strncpy(s,xctx.line[c][i].prop_ptr!=NULL?xctx.line[c][i].prop_ptr:"",S(s)); my_snprintf(str, S(str), "selected line: layer=%d, n=%d properties: %s",c-4,i,s); statusmsg(str,2); - /* 20070323 */ - my_snprintf(str, S(str), "n=%4d x = %.16g y = %.16g w = %.16g h = %.16g",i, line[c][i].x1, line[c][i].y1, - line[c][i].x2-line[c][i].x1, line[c][i].y2-line[c][i].y1 + + my_snprintf(str, S(str), "n=%4d x = %.16g y = %.16g w = %.16g h = %.16g", + i, xctx.line[c][i].x1, xctx.line[c][i].y1, + xctx.line[c][i].x2-xctx.line[c][i].x1, xctx.line[c][i].y2-xctx.line[c][i].y1 ); statusmsg(str,1); } - if( ((line[c][i].sel|select_mode) == (SELECTED1|SELECTED2)) || - ((line[c][i].sel == SELECTED) && select_mode) ) - line[c][i].sel = SELECTED; - else - line[c][i].sel = select_mode; + if( ((xctx.line[c][i].sel|select_mode) == (SELECTED1|SELECTED2)) || + ((xctx.line[c][i].sel == SELECTED) && select_mode) ) + xctx.line[c][i].sel = SELECTED; + else + xctx.line[c][i].sel = select_mode; if(select_mode) { - if(line[c][i].bus) - drawtempline(gc[SELLAYER], THICK, line[c][i].x1, line[c][i].y1, line[c][i].x2, line[c][i].y2); + if(xctx.line[c][i].bus) + drawtempline(gc[SELLAYER], THICK, xctx.line[c][i].x1, xctx.line[c][i].y1, + xctx.line[c][i].x2, xctx.line[c][i].y2); else - drawtempline(gc[SELLAYER], ADD, line[c][i].x1, line[c][i].y1, line[c][i].x2, line[c][i].y2); + drawtempline(gc[SELLAYER], ADD, xctx.line[c][i].x1, xctx.line[c][i].y1, + xctx.line[c][i].x2, xctx.line[c][i].y2); } else - if(line[c][i].bus) - drawtempline(gctiled, THICK, line[c][i].x1, line[c][i].y1, line[c][i].x2, line[c][i].y2); + if(xctx.line[c][i].bus) + drawtempline(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, line[c][i].x1, line[c][i].y1, line[c][i].x2, line[c][i].y2); + drawtempline(gctiled, NOW, xctx.line[c][i].x1, xctx.line[c][i].y1, + xctx.line[c][i].x2, xctx.line[c][i].y2); need_rebuild_selected_array=1; } @@ -915,7 +928,7 @@ unsigned short select_object(double mousex,double mousey, unsigned short select_ } /*end switch */ drawtemparc(gc[SELLAYER], END, 0.0, 0.0, 0.0, 0.0, 0.0); - drawtemprect(gc[SELLAYER], END, 0.0, 0.0, 0.0, 0.0); + drawtemprect(gc[SELLAYER], END, 0.0, 0.0, 0.0, 0.0); drawtempline(gc[SELLAYER], END, 0.0, 0.0, 0.0, 0.0); if(sel.type) ui_state |= SELECTION; @@ -926,39 +939,39 @@ void select_inside(double x1,double y1, double x2, double y2, int sel) /* 201509 { int c,i; double x, y, r, a, b, xa, ya, xb, yb; /* arc */ - Box tmp; + xRect tmp; #ifdef HAS_CAIRO int customfont; #endif - for(i=0;itype) continue; - if( !strcmp((inst_ptr[i].ptr+instdef)->type,"netlist_options") ) { + for(i=0;itype) continue; + if( !strcmp((xctx.inst[i].ptr+ xctx.sym)->type,"netlist_options") ) { netlist_options(i); } } @@ -83,24 +83,24 @@ void global_spice_netlist(int global) /* netlister driver */ if(!strcmp(tclgetvar("spiceprefix"), "0")) spiceprefix = 0; if(!top_subckt) fprintf(fd,"**"); - fprintf(fd,".subckt %s", skip_dir( schematic[currentsch]) ); + fprintf(fd,".subckt %s", skip_dir( xctx.sch[xctx.currsch]) ); /* print top subckt ipin/opins */ - for(i=0;iprop_ptr, "spice_ignore",0 ), "true") ) { + for(i=0;iprop_ptr, "spice_ignore",0 ), "true") ) { continue; } - my_strdup(380, &type,(inst_ptr[i].ptr+instdef)->type); /* 20150409 */ + my_strdup(380, &type,(xctx.inst[i].ptr+ xctx.sym)->type); dbg(1, "global_spice_netlist(): |%s|\n", type); if( type && !strcmp(type,"netlist_options") ) { continue; } if( type && IS_PIN(type)) { - str_tmp = expandlabel ( get_tok_value(inst_ptr[i].prop_ptr,"lab",0) ,&mult); - dbg(1, "global_spice_netlist(): |%s|\n", - get_tok_value(inst_ptr[i].prop_ptr,"lab",0)); + str_tmp = expandlabel ( get_tok_value(xctx.inst[i].prop_ptr,"lab",0) ,&mult); + dbg(1, "global_spice_netlist(): |%s|\n", + get_tok_value(xctx.inst[i].prop_ptr,"lab",0)); /*must handle invalid node names */ fprintf(fd, " %s", str_tmp ? str_tmp : "(NULL)" ); } @@ -108,21 +108,21 @@ void global_spice_netlist(int global) /* netlister driver */ fprintf(fd,"\n"); spice_netlist(fd, 0); - + first = 0; - for(i=0;iprop_ptr, "spice_ignore",0 ), "true") ) { + if( strcmp(get_tok_value(xctx.inst[i].prop_ptr,"spice_ignore",0),"true")==0 ) continue; + if(xctx.inst[i].ptr<0) continue; + if(!strcmp(get_tok_value( (xctx.inst[i].ptr+ xctx.sym)->prop_ptr, "spice_ignore",0 ), "true") ) { continue; } - my_strdup(381, &type,(inst_ptr[i].ptr+instdef)->type); /* 20150409 */ - my_strdup(382, &place,get_tok_value((inst_ptr[i].ptr+instdef)->prop_ptr,"place",0)); /* 20121223 */ + my_strdup(381, &type,(xctx.inst[i].ptr+ xctx.sym)->type); + my_strdup(382, &place,get_tok_value((xctx.inst[i].ptr+ xctx.sym)->prop_ptr,"place",0)); if( type && !strcmp(type,"netlist_commands") ) { - if(!place || strcmp(place, "end" )) { /* 20121223 */ - my_strdup(383, &place,get_tok_value(inst_ptr[i].prop_ptr,"place",0)); /*20160920 */ - if(!place || strcmp(place, "end" )) { /*20160920 */ + if(!place || strcmp(place, "end" )) { + my_strdup(383, &place,get_tok_value(xctx.inst[i].prop_ptr,"place",0)); + if(!place || strcmp(place, "end" )) { if(first == 0) fprintf(fd,"**** begin user architecture code\n"); first++; print_spice_element(fd, i) ; /* this is the element line */ @@ -133,10 +133,10 @@ void global_spice_netlist(int global) /* netlister driver */ netlist_count++; - if(schprop && schprop[0]) { + if(xctx.schprop && xctx.schprop[0]) { if(first == 0) fprintf(fd,"**** begin user architecture code\n"); first++; - fprintf(fd, "%s\n", schprop); + fprintf(fd, "%s\n", xctx.schprop); } if(first) fprintf(fd,"**** end user architecture code\n"); /* /20100217 */ @@ -145,7 +145,7 @@ void global_spice_netlist(int global) /* netlister driver */ fprintf(fd, ".ends\n"); - if(split_files) { /* 20081205 */ + if(split_files) { fclose(fd); my_snprintf(tcl_cmd_netlist, S(tcl_cmd_netlist), "netlist {%s} noshow {%s}", netl_filename, cellname); tcleval(tcl_cmd_netlist); @@ -153,52 +153,52 @@ void global_spice_netlist(int global) /* netlister driver */ } /* preserve current level instance flags before descending hierarchy for netlisting, restore later */ - stored_flags = my_calloc(146, lastinst, sizeof(unsigned int)); - for(i=0;iprop_ptr, "spice_ignore",0 ), "true") ) { + if( strcmp(get_tok_value(xctx.inst[i].prop_ptr,"spice_ignore",0),"true")==0 ) continue; + if(xctx.inst[i].ptr<0) continue; + if(!strcmp(get_tok_value( (xctx.inst[i].ptr+ xctx.sym)->prop_ptr, "spice_ignore",0 ), "true") ) { continue; } - my_strdup(384, &type,(inst_ptr[i].ptr+instdef)->type); /* 20150409 */ - my_strdup(385, &place,get_tok_value((inst_ptr[i].ptr+instdef)->prop_ptr,"place",0)); /* 20121223 */ + my_strdup(384, &type,(xctx.inst[i].ptr+ xctx.sym)->type); + my_strdup(385, &place,get_tok_value((xctx.inst[i].ptr+ xctx.sym)->prop_ptr,"place",0)); if( type && !strcmp(type,"netlist_commands") ) { - if(place && !strcmp(place, "end" )) { /* 20121223 */ + if(place && !strcmp(place, "end" )) { if(first == 0) fprintf(fd,"**** begin user architecture code\n"); first++; - print_spice_element(fd, i) ; /* 20160920 */ - } else { /* 20160920 */ - my_strdup(386, &place,get_tok_value(inst_ptr[i].prop_ptr,"place",0)); /*20160920 */ - if(place && !strcmp(place, "end" )) { /* 20160920 */ + print_spice_element(fd, i) ; + } else { + my_strdup(386, &place,get_tok_value(xctx.inst[i].prop_ptr,"place",0)); + if(place && !strcmp(place, "end" )) { if(first == 0) fprintf(fd,"**** begin user architecture code\n"); first++; - print_spice_element(fd, i) ; /* 20160920 */ + print_spice_element(fd, i) ; } } } /* netlist_commands */ @@ -250,7 +250,7 @@ void global_spice_netlist(int global) /* netlister driver */ /* 20150922 added split_files check */ - if(!split_files) fprintf(fd, ".end\n"); /* 20081202 */ + if(!split_files) fprintf(fd, ".end\n"); dbg(1, "global_spice_netlist(): starting awk on netlist!\n"); @@ -290,63 +290,63 @@ static char *model_name(const char *m) return model_name_result; } -void spice_block_netlist(FILE *fd, int i) /*20081223 */ +void spice_block_netlist(FILE *fd, int i) { - int spice_stop=0; /* 20111113 */ + int spice_stop=0; char netl_filename[PATH_MAX]; - char tcl_cmd_netlist[PATH_MAX + 100]; /* 20081202 */ - char cellname[PATH_MAX]; /* 20081202 */ + char tcl_cmd_netlist[PATH_MAX + 100]; + char cellname[PATH_MAX]; char filename[PATH_MAX]; const char *str_tmp; /* int j; */ /* int mult; */ char *extra=NULL; - - if(!strcmp( get_tok_value(instdef[i].prop_ptr,"spice_stop",0),"true") ) + + if(!strcmp( get_tok_value(xctx.sym[i].prop_ptr,"spice_stop",0),"true") ) spice_stop=1; else spice_stop=0; if(split_files) { - my_snprintf(netl_filename, S(netl_filename), "%s/.%s_%d", netlist_dir, skip_dir(instdef[i].name), getpid()); + my_snprintf(netl_filename, S(netl_filename), "%s/.%s_%d", netlist_dir, skip_dir(xctx.sym[i].name), getpid()); dbg(1, "spice_block_netlist(): split_files: netl_filename=%s\n", netl_filename); fd=fopen(netl_filename, "w"); - my_snprintf(cellname, S(cellname), "%s.spice", skip_dir(instdef[i].name)); + my_snprintf(cellname, S(cellname), "%s.spice", skip_dir(xctx.sym[i].name)); } - fprintf(fd, "\n* expanding symbol: %s # of pins=%d\n\n", - instdef[i].name,instdef[i].rects[PINLAYER] ); - - fprintf(fd, ".subckt %s ",skip_dir(instdef[i].name)); + fprintf(fd, "\n* expanding symbol: %s # of pins=%d\n\n", + xctx.sym[i].name,xctx.sym[i].rects[PINLAYER] ); + + fprintf(fd, ".subckt %s ",skip_dir(xctx.sym[i].name)); print_spice_subckt(fd, i); - my_strdup(387, &extra, get_tok_value(instdef[i].prop_ptr,"extra",0) ); /* 20081206 */ + my_strdup(387, &extra, get_tok_value(xctx.sym[i].prop_ptr,"extra",0) ); fprintf(fd, "%s ", extra ? extra : "" ); - + /* 20081206 new get_sym_template does not return token=value pairs where token listed in extra */ - fprintf(fd, "%s", get_sym_template(instdef[i].templ, extra)); /* 20150409 */ + fprintf(fd, "%s", get_sym_template(xctx.sym[i].templ, extra)); my_free(950, &extra); fprintf(fd, "\n"); - - if((str_tmp = get_tok_value(instdef[i].prop_ptr, "schematic",0 ))[0]) { + + if((str_tmp = get_tok_value(xctx.sym[i].prop_ptr, "schematic",0 ))[0]) { my_strncpy(filename, abs_sym_path(str_tmp, ""), S(filename)); load_schematic(1,filename, 0); } else { - load_schematic(1, add_ext(abs_sym_path(instdef[i].name, ""), ".sch") ,0); /* 20190518 */ + load_schematic(1, add_ext(abs_sym_path(xctx.sym[i].name, ""), ".sch") ,0); } spice_netlist(fd, spice_stop); /* 20111113 added spice_stop */ netlist_count++; - /* 20100217 */ - if(schprop && schprop[0]) { + + if(xctx.schprop && xctx.schprop[0]) { fprintf(fd,"**** begin user architecture code\n"); - fprintf(fd, "%s\n", schprop); + fprintf(fd, "%s\n", xctx.schprop); fprintf(fd,"**** end user architecture code\n"); } /* /20100217 */ fprintf(fd, ".ends\n\n"); - if(split_files) { /* 20081204 */ + if(split_files) { fclose(fd); my_snprintf(tcl_cmd_netlist, S(tcl_cmd_netlist), "netlist {%s} noshow {%s}", netl_filename, cellname); tcleval(tcl_cmd_netlist); @@ -363,33 +363,33 @@ void spice_netlist(FILE *fd, int spice_stop ) prepare_netlist_structs(1); /* set_modify(1); */ /* 20160302 prepare_netlist_structs could change schematic (wire node naming for example) */ traverse_node_hash(); /* print all warnings about unconnected floatings etc */ - if(!spice_stop) { /* 20111113 */ - for(i=0;iprop_ptr, "spice_ignore",0 ), "true") ) { + if( strcmp(get_tok_value(xctx.inst[i].prop_ptr,"spice_ignore",0),"true")==0 ) continue; + if(xctx.inst[i].ptr<0) continue; + if(!strcmp(get_tok_value( (xctx.inst[i].ptr+ xctx.sym)->prop_ptr, "spice_ignore",0 ), "true") ) { continue; } - my_strdup(388, &type,(inst_ptr[i].ptr+instdef)->type); /* 20150409 */ + my_strdup(388, &type,(xctx.inst[i].ptr+ xctx.sym)->type); if( type && IS_PIN(type) ) { print_spice_element(fd, i) ; /* this is the element line */ } } - - for(i=0;iprop_ptr, "spice_ignore",0 ), "true") ) {/*20070726 */ - continue; /*20070726 */ - } /*20070726 */ - - my_strdup(390, &type,(inst_ptr[i].ptr+instdef)->type); /* 20150409 */ + if( strcmp(get_tok_value(xctx.inst[i].prop_ptr,"spice_ignore",0),"true")==0 ) continue; + if(xctx.inst[i].ptr<0) continue; + if(!strcmp(get_tok_value( (xctx.inst[i].ptr+ xctx.sym)->prop_ptr, "spice_ignore",0 ), "true") ) { + continue; + } + + my_strdup(390, &type,(xctx.inst[i].ptr+ xctx.sym)->type); if( type && !IS_LABEL_OR_PIN(type) ) { if(!strcmp(type,"netlist_commands") && netlist_count==0) continue; /* already done in global_spice_netlist */ - if(netlist_count && - !strcmp(get_tok_value(inst_ptr[i].prop_ptr, "only_toplevel", 0), "true")) continue; /* 20160418 */ + if(netlist_count && + !strcmp(get_tok_value(xctx.inst[i].prop_ptr, "only_toplevel", 0), "true")) continue; if(!strcmp(type,"netlist_commands")) { fprintf(fd,"**** begin user architecture code\n"); print_spice_element(fd, i) ; /* this is the element line */ @@ -398,10 +398,10 @@ void spice_netlist(FILE *fd, int spice_stop ) const char *m; print_spice_element(fd, i) ; /* this is the element line */ /* hash device_model attribute if any */ - m = get_tok_value(inst_ptr[i].prop_ptr, "device_model", 2); + m = get_tok_value(xctx.inst[i].prop_ptr, "device_model", 2); if(m[0]) hash_lookup(model_table, model_name(m), m, XINSERT); else { - m = get_tok_value( (inst_ptr[i].ptr+instdef)->prop_ptr, "device_model", 2); + m = get_tok_value( (xctx.inst[i].ptr+ xctx.sym)->prop_ptr, "device_model", 2); if(m[0]) hash_lookup(model_table, model_name(m), m, XINSERT); } my_free(951, &model_name_result); @@ -431,7 +431,7 @@ static unsigned int hash(const char *tok) /* token value what ... what ... * -------------------------------------------------------------------------- * "whatever" "whatever" XINSERT insert in hash table if not in. - * if already present update value if not NULL, + * if already present update value if not NULL, * return entry address. * "whatever" "whatever" XINSERT_NOREPLACE same as XINSERT but do not replace existing value * return NULL if not found. @@ -444,7 +444,7 @@ struct hashentry *hash_lookup(struct hashentry **table, const char *token, const unsigned int hashcode, index; struct hashentry *entry, *saveptr, **preventry; int s ; - + if(token==NULL) return NULL; hashcode=hash(token); index=hashcode % HASHSIZE; @@ -518,7 +518,7 @@ void free_hash(struct hashentry **table) /* token value what ... what ... * -------------------------------------------------------------------------- * "whatever" "whatever" XINSERT insert in hash table if not in. - * if already present update value if not NULL, + * if already present update value if not NULL, * return entry address. * "whatever" "whatever" XINSERT_NOREPLACE same as XINSERT but do not replace existing value * return NULL if not found. @@ -531,7 +531,7 @@ struct int_hashentry *int_hash_lookup(struct int_hashentry **table, const char * unsigned int hashcode, index; struct int_hashentry *entry, *saveptr, **preventry; int s ; - + if(token==NULL) return NULL; hashcode=hash(token); index=hashcode % HASHSIZE; diff --git a/src/store.c b/src/store.c index 5275961f..6f50678d 100644 --- a/src/store.c +++ b/src/store.c @@ -1,7 +1,7 @@ /* File: store.c - * + * * This file is part of XSCHEM, - * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit + * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit * simulation. * Copyright (C) 1998-2020 Stefan Frederik Schippers * @@ -25,10 +25,10 @@ void check_wire_storage(void) { - if(lastwire >= max_wires) + if(xctx.wires >= xctx.maxw) { - max_wires=(1+lastwire / CADMAXWIRES)*CADMAXWIRES; - my_realloc(392, &wire, sizeof(Wire)*max_wires); + xctx.maxw=(1+xctx.wires / CADMAXWIRES)*CADMAXWIRES; + my_realloc(392, &xctx.wire, sizeof(xWire)*xctx.maxw); } } @@ -43,58 +43,58 @@ void check_selected_storage(void) void check_text_storage(void) { - if(lasttext >= max_texts) + if(xctx.texts >= xctx.maxt) { - max_texts=(1 + lasttext / CADMAXTEXT) * CADMAXTEXT; - my_realloc(394, &textelement, sizeof(Text)*max_texts); + xctx.maxt=(1 + xctx.texts / CADMAXTEXT) * CADMAXTEXT; + my_realloc(394, &xctx.text, sizeof(xText)*xctx.maxt); } } void check_symbol_storage(void) { int i; - if(lastinstdef >= max_symbols) + if(xctx.symbols >= xctx.maxs) { - dbg(1, "check_symbol_storage(): more than max_symbols, %s\n", - schematic[currentsch] ); - max_symbols=(1 + lastinstdef / ELEMDEF) * ELEMDEF; - my_realloc(395, &instdef, sizeof(Instdef)*max_symbols); - for(i=lastinstdef;i= max_instances) + if(xctx.instances >= xctx.maxi) { - max_instances=(1 + lastinst / ELEMINST) * ELEMINST; - my_realloc(402, &inst_ptr, sizeof(Instance)*max_instances); + xctx.maxi=(1 + xctx.instances / ELEMINST) * ELEMINST; + my_realloc(402, &xctx.inst, sizeof(xInstance)*xctx.maxi); } } void check_arc_storage(int c) { - if(lastarc[c] >= max_arcs[c]) + if(xctx.arcs[c] >= xctx.maxa[c]) { - max_arcs[c]=(1 + lastarc[c] / CADMAXOBJECTS) * CADMAXOBJECTS; - my_realloc(403, &arc[c], sizeof(xArc)*max_arcs[c]); + xctx.maxa[c]=(1 + xctx.arcs[c] / CADMAXOBJECTS) * CADMAXOBJECTS; + my_realloc(403, &xctx.arc[c], sizeof(xArc)*xctx.maxa[c]); } } void check_box_storage(int c) { - if(lastrect[c] >= max_rects[c]) + if(xctx.rects[c] >= xctx.maxr[c]) { - max_rects[c]=(1 + lastrect[c] / CADMAXOBJECTS) * CADMAXOBJECTS; - my_realloc(404, &rect[c], sizeof(Box)*max_rects[c]); + xctx.maxr[c]=(1 + xctx.rects[c] / CADMAXOBJECTS) * CADMAXOBJECTS; + my_realloc(404, &xctx.rect[c], sizeof(xRect)*xctx.maxr[c]); } } void check_line_storage(int c) { - if(lastline[c] >= max_lines[c]) + if(xctx.lines[c] >= xctx.maxl[c]) { - max_lines[c]=(1 + lastline[c] / CADMAXOBJECTS) * CADMAXOBJECTS; - my_realloc(405, &line[c], sizeof(Line)*max_lines[c]); + xctx.maxl[c]=(1 + xctx.lines[c] / CADMAXOBJECTS) * CADMAXOBJECTS; + my_realloc(405, &xctx.line[c], sizeof(xLine)*xctx.maxl[c]); } } -void check_polygon_storage(int c) /*20171115 */ +void check_polygon_storage(int c) { - if(lastpolygon[c] >= max_polygons[c]) + if(xctx.polygons[c] >= xctx.maxp[c]) { - max_polygons[c]=(1 + lastpolygon[c] / CADMAXOBJECTS) * CADMAXOBJECTS; - my_realloc(406, &polygon[c], sizeof(xPolygon)*max_polygons[c]); + xctx.maxp[c]=(1 + xctx.polygons[c] / CADMAXOBJECTS) * CADMAXOBJECTS; + my_realloc(406, &xctx.poly[c], sizeof(xPoly)*xctx.maxp[c]); } } -void store_arc(int pos, double x, double y, double r, double a, double b, +void store_arc(int pos, double x, double y, double r, double a, double b, unsigned int rectcolor, unsigned short sel, char *prop_ptr) { int n, j; const char *dash; check_arc_storage(rectcolor); - if(pos==-1) n=lastarc[rectcolor]; + if(pos==-1) n=xctx.arcs[rectcolor]; else { - for(j=lastarc[rectcolor];j>pos;j--) + for(j=xctx.arcs[rectcolor];j>pos;j--) { - arc[rectcolor][j]=arc[rectcolor][j-1]; + xctx.arc[rectcolor][j]=xctx.arc[rectcolor][j-1]; } n=pos; } - arc[rectcolor][n].x = x; - arc[rectcolor][n].y = y; - arc[rectcolor][n].r = r; - arc[rectcolor][n].a = a; - arc[rectcolor][n].b = b; - arc[rectcolor][n].prop_ptr = NULL; - my_strdup(407, &arc[rectcolor][n].prop_ptr, prop_ptr); - arc[rectcolor][n].sel = sel; - if( !strcmp(get_tok_value(arc[rectcolor][n].prop_ptr,"fill",0),"true") ) - arc[rectcolor][n].fill =1; + xctx.arc[rectcolor][n].x = x; + xctx.arc[rectcolor][n].y = y; + xctx.arc[rectcolor][n].r = r; + xctx.arc[rectcolor][n].a = a; + xctx.arc[rectcolor][n].b = b; + xctx.arc[rectcolor][n].prop_ptr = NULL; + my_strdup(407, &xctx.arc[rectcolor][n].prop_ptr, prop_ptr); + xctx.arc[rectcolor][n].sel = sel; + if( !strcmp(get_tok_value(xctx.arc[rectcolor][n].prop_ptr,"fill",0),"true") ) + xctx.arc[rectcolor][n].fill =1; else - arc[rectcolor][n].fill =0; - dash = get_tok_value(arc[rectcolor][n].prop_ptr,"dash",0); + xctx.arc[rectcolor][n].fill =0; + dash = get_tok_value(xctx.arc[rectcolor][n].prop_ptr,"dash",0); if( strcmp(dash, "") ) { int d = atoi(dash); - arc[rectcolor][n].dash = d >= 0 ? d : 0; + xctx.arc[rectcolor][n].dash = d >= 0 ? d : 0; } else - arc[rectcolor][n].dash = 0; + xctx.arc[rectcolor][n].dash = 0; - lastarc[rectcolor]++; + xctx.arcs[rectcolor]++; set_modify(1); } -void store_polygon(int pos, double *x, double *y, int points, unsigned int rectcolor, unsigned short sel, char *prop_ptr) +void store_poly(int pos, double *x, double *y, int points, unsigned int rectcolor, unsigned short sel, char *prop_ptr) { int n, j; const char *dash; check_polygon_storage(rectcolor); - if(pos==-1) n=lastpolygon[rectcolor]; + if(pos==-1) n=xctx.polygons[rectcolor]; else { - for(j=lastpolygon[rectcolor];j>pos;j--) + for(j=xctx.polygons[rectcolor];j>pos;j--) { - polygon[rectcolor][j]=polygon[rectcolor][j-1]; + xctx.poly[rectcolor][j]=xctx.poly[rectcolor][j-1]; } n=pos; } - dbg(2, "store_polygon(): storing POLYGON %d\n",n); - - polygon[rectcolor][n].x=NULL; - polygon[rectcolor][n].y=NULL; - polygon[rectcolor][n].selected_point=NULL; - polygon[rectcolor][n].prop_ptr=NULL; - polygon[rectcolor][n].x= my_calloc(408, points, sizeof(double)); - polygon[rectcolor][n].y= my_calloc(409, points, sizeof(double)); - polygon[rectcolor][n].selected_point= my_calloc(410, points, sizeof(unsigned short)); - my_strdup(411, &polygon[rectcolor][n].prop_ptr, prop_ptr); - for(j=0;j= 0 ? d : 0; + xctx.poly[rectcolor][n].dash = d >= 0 ? d : 0; } else - polygon[rectcolor][n].dash = 0; + xctx.poly[rectcolor][n].dash = 0; - lastpolygon[rectcolor]++; + xctx.polygons[rectcolor]++; set_modify(1); } @@ -243,92 +243,92 @@ void storeobject(int pos, double x1,double y1,double x2,double y2, { check_line_storage(rectcolor); - if(pos==-1) n=lastline[rectcolor]; + if(pos==-1) n=xctx.lines[rectcolor]; else { - for(j=lastline[rectcolor];j>pos;j--) + for(j=xctx.lines[rectcolor];j>pos;j--) { - line[rectcolor][j]=line[rectcolor][j-1]; + xctx.line[rectcolor][j]=xctx.line[rectcolor][j-1]; } n=pos; } dbg(2, "storeobject(): storing LINE %d\n",n); - line[rectcolor][n].x1=x1; - line[rectcolor][n].x2=x2; - line[rectcolor][n].y1=y1; - line[rectcolor][n].y2=y2; - line[rectcolor][n].prop_ptr=NULL; - my_strdup(412, &line[rectcolor][n].prop_ptr, prop_ptr); - line[rectcolor][n].sel=sel; - if( !strcmp(get_tok_value(line[rectcolor][n].prop_ptr, "bus", 0), "true") ) - line[rectcolor][n].bus = 1; + xctx.line[rectcolor][n].x1=x1; + xctx.line[rectcolor][n].x2=x2; + xctx.line[rectcolor][n].y1=y1; + xctx.line[rectcolor][n].y2=y2; + xctx.line[rectcolor][n].prop_ptr=NULL; + my_strdup(412, &xctx.line[rectcolor][n].prop_ptr, prop_ptr); + xctx.line[rectcolor][n].sel=sel; + if( !strcmp(get_tok_value(xctx.line[rectcolor][n].prop_ptr, "bus", 0), "true") ) + xctx.line[rectcolor][n].bus = 1; else - line[rectcolor][n].bus = 0; - dash = get_tok_value(line[rectcolor][n].prop_ptr,"dash",0); + xctx.line[rectcolor][n].bus = 0; + dash = get_tok_value(xctx.line[rectcolor][n].prop_ptr,"dash",0); if( strcmp(dash, "") ) { int d = atoi(dash); - line[rectcolor][n].dash = d >= 0 ? d : 0; + xctx.line[rectcolor][n].dash = d >= 0 ? d : 0; } else - line[rectcolor][n].dash = 0; - lastline[rectcolor]++; + xctx.line[rectcolor][n].dash = 0; + xctx.lines[rectcolor]++; set_modify(1); } if(type == xRECT) { check_box_storage(rectcolor); - if(pos==-1) n=lastrect[rectcolor]; + if(pos==-1) n=xctx.rects[rectcolor]; else { - for(j=lastrect[rectcolor];j>pos;j--) + for(j=xctx.rects[rectcolor];j>pos;j--) { - rect[rectcolor][j]=rect[rectcolor][j-1]; + xctx.rect[rectcolor][j]=xctx.rect[rectcolor][j-1]; } n=pos; } dbg(2, "storeobject(): storing RECT %d\n",n); - rect[rectcolor][n].x1=x1; - rect[rectcolor][n].x2=x2; - rect[rectcolor][n].y1=y1; - rect[rectcolor][n].y2=y2; - rect[rectcolor][n].prop_ptr=NULL; - my_strdup(413, &rect[rectcolor][n].prop_ptr, prop_ptr); - rect[rectcolor][n].sel=sel; - dash = get_tok_value(rect[rectcolor][n].prop_ptr,"dash",0); + xctx.rect[rectcolor][n].x1=x1; + xctx.rect[rectcolor][n].x2=x2; + xctx.rect[rectcolor][n].y1=y1; + xctx.rect[rectcolor][n].y2=y2; + xctx.rect[rectcolor][n].prop_ptr=NULL; + my_strdup(413, &xctx.rect[rectcolor][n].prop_ptr, prop_ptr); + xctx.rect[rectcolor][n].sel=sel; + dash = get_tok_value(xctx.rect[rectcolor][n].prop_ptr,"dash",0); if( strcmp(dash, "") ) { int d = atoi(dash); - rect[rectcolor][n].dash = d >= 0 ? d : 0; + xctx.rect[rectcolor][n].dash = d >= 0 ? d : 0; } else - rect[rectcolor][n].dash = 0; - lastrect[rectcolor]++; + xctx.rect[rectcolor][n].dash = 0; + xctx.rects[rectcolor]++; set_modify(1); } if(type == WIRE) { check_wire_storage(); - if(pos==-1) n=lastwire; + if(pos==-1) n=xctx.wires; else { - for(j=lastwire;j>pos;j--) + for(j=xctx.wires;j>pos;j--) { - wire[j]=wire[j-1]; + xctx.wire[j]=xctx.wire[j-1]; } n=pos; } dbg(2, "storeobject(): storing WIRE %d\n",n); - wire[n].x1=x1; - wire[n].y1=y1; - wire[n].x2=x2; - wire[n].y2=y2; - wire[n].prop_ptr=NULL; - wire[n].node=NULL; - wire[n].end1=0; - wire[n].end2=0; - my_strdup(414, &wire[n].prop_ptr, prop_ptr); - if(!strcmp(get_tok_value(wire[n].prop_ptr,"bus",0), "true")) wire[n].bus=1; /* 20171201 */ - else wire[n].bus=0; + xctx.wire[n].x1=x1; + xctx.wire[n].y1=y1; + xctx.wire[n].x2=x2; + xctx.wire[n].y2=y2; + xctx.wire[n].prop_ptr=NULL; + xctx.wire[n].node=NULL; + xctx.wire[n].end1=0; + xctx.wire[n].end2=0; + my_strdup(414, &xctx.wire[n].prop_ptr, prop_ptr); + if(!strcmp(get_tok_value(xctx.wire[n].prop_ptr,"bus",0), "true")) xctx.wire[n].bus=1; + else xctx.wire[n].bus=0; - wire[n].sel=sel; - lastwire++; + xctx.wire[n].sel=sel; + xctx.wires++; set_modify(1); } } @@ -336,14 +336,14 @@ void storeobject(int pos, double x1,double y1,double x2,double y2, void freenet_nocheck(int i) { int j; - my_free(959, &wire[i].prop_ptr); - my_free(960, &wire[i].node); - for(j=i+1;j\n", x1, y1, x2, y2); } @@ -79,7 +79,7 @@ static void svg_xdrawpoint(int layer, double x1, double y1) static void svg_xfillrectangle(int layer, double x1, double y1, double x2, double y2, int dash) { fprintf(fd,"\n", x1, y1, x2, y1, x2, y2, x1, y2, x1, y1); } @@ -97,7 +97,7 @@ static void svg_drawpolygon(int c, int what, double *x, double *y, int points, i return; } fprintf(fd, "\n", - xx, yy, rr, svg_stroke.red, svg_stroke.green, svg_stroke.blue, + xx, yy, rr, svg_stroke.red, svg_stroke.green, svg_stroke.blue, svg_stroke.red, svg_stroke.green, svg_stroke.blue, svg_linew/4); } } @@ -159,7 +159,7 @@ static void svg_drawarc(int gc, int fillarc, double x,double y,double r,double a xx=X_TO_SVG(x); yy=Y_TO_SVG(y); - rr=r*mooz; + rr=r*xctx.mooz; arc_bbox(x, y, r, a, b, &x1,&y1,&x2,&y2); x1=X_TO_SVG(x1); y1=Y_TO_SVG(y1); @@ -170,11 +170,11 @@ static void svg_drawarc(int gc, int fillarc, double x,double y,double r,double a { if(b == 360.) { fprintf(fd, "\n", - svg_stroke.red, svg_stroke.green, svg_stroke.blue, + svg_stroke.red, svg_stroke.green, svg_stroke.blue, svg_stroke.red, svg_stroke.green, svg_stroke.blue, svg_linew); else fprintf(fd, "stroke=\"rgb(%d,%d,%d)\" fill=\"none\" stroke-width=\"%g\"/>\n", @@ -186,10 +186,10 @@ static void svg_drawarc(int gc, int fillarc, double x,double y,double r,double a yy2 = -rr * sin((a + b) * XSCH_PI / 180.) + yy; fa = b > 180 ? 1 : 0; fs = b > 0 ? 0 : 1; - + fprintf(fd,"areay1 && ylines[layer];j++) + rot = (xctx.inst[n].rot + rot ) & 0x3; + + x0=xctx.inst[n].x0 + xoffset; + y0=xctx.inst[n].y0 + yoffset; + for(j=0;j< (xctx.inst[n].ptr+ xctx.sym)->lines[layer];j++) { - line = ((inst_ptr[n].ptr+instdef)->lineptr[layer])[j]; + line = ((xctx.inst[n].ptr+ xctx.sym)->line[layer])[j]; ROTATION(0.0,0.0,line.x1,line.y1,x1,y1); ROTATION(0.0,0.0,line.x2,line.y2,x2,y2); ORDER(x1,y1,x2,y2); svg_drawline(layer, x0+x1, y0+y1, x0+x2, y0+y2, line.dash); } - for(j=0;j< (inst_ptr[n].ptr+instdef)->polygons[layer];j++) /* 20171115 */ + for(j=0;j< (xctx.inst[n].ptr+ xctx.sym)->polygons[layer];j++) { - polygon = ((inst_ptr[n].ptr+instdef)->polygonptr[layer])[j]; + polygon = ((xctx.inst[n].ptr+ xctx.sym)->poly[layer])[j]; { /* scope block so we declare some auxiliary arrays for coord transforms. 20171115 */ int k; double *x = my_malloc(417, sizeof(double) * polygon.points); @@ -362,10 +362,10 @@ static void svg_draw_symbol(int n,int layer,int tmp_flip, int rot, my_free(962, &y); } } - for(j=0;j< (inst_ptr[n].ptr+instdef)->arcs[layer];j++) + for(j=0;j< (xctx.inst[n].ptr+ xctx.sym)->arcs[layer];j++) { double angle; - arc = ((inst_ptr[n].ptr+instdef)->arcptr[layer])[j]; + arc = ((xctx.inst[n].ptr+ xctx.sym)->arc[layer])[j]; if(flip) { angle = 270.*rot+180.-arc.b-arc.a; } else { @@ -377,38 +377,38 @@ static void svg_draw_symbol(int n,int layer,int tmp_flip, int rot, svg_drawarc(layer, arc.fill, x0+x1, y0+y1, arc.r, angle, arc.b, arc.dash); } - if( (layer != PINLAYER || enable_layer[layer]) ) for(j=0;j< (inst_ptr[n].ptr+instdef)->rects[layer];j++) + if( (layer != PINLAYER || enable_layer[layer]) ) for(j=0;j< (xctx.inst[n].ptr+ xctx.sym)->rects[layer];j++) { - box = ((inst_ptr[n].ptr+instdef)->boxptr[layer])[j]; + box = ((xctx.inst[n].ptr+ xctx.sym)->rect[layer])[j]; ROTATION(0.0,0.0,box.x1,box.y1,x1,y1); ROTATION(0.0,0.0,box.x2,box.y2,x2,y2); - RECTORDER(x1,y1,x2,y2); + RECTORDER(x1,y1,x2,y2); svg_filledrect(layer, x0+x1, y0+y1, x0+x2, y0+y2, box.dash); } - if( (layer==TEXTWIRELAYER && !(inst_ptr[n].flags&2) ) || - (sym_txt && (layer==TEXTLAYER) && (inst_ptr[n].flags&2) ) ) + if( (layer==TEXTWIRELAYER && !(xctx.inst[n].flags&2) ) || + (sym_txt && (layer==TEXTLAYER) && (xctx.inst[n].flags&2) ) ) { const char *txtptr; - for(j=0;j< (inst_ptr[n].ptr+instdef)->texts;j++) + for(j=0;j< (xctx.inst[n].ptr+ xctx.sym)->texts;j++) { - text = (inst_ptr[n].ptr+instdef)->txtptr[j]; - /* if(text.xscale*FONTWIDTH* mooz<1) continue; */ + text = (xctx.inst[n].ptr+ xctx.sym)->text[j]; + /* if(text.xscale*FONTWIDTH* xctx.mooz<1) continue; */ txtptr= translate(n, text.txt_ptr); ROTATION(0.0,0.0,text.x0,text.y0,x1,y1); textlayer = layer; - if( !(layer == PINLAYER && (inst_ptr[n].flags & 4))) { - textlayer = (inst_ptr[n].ptr+instdef)->txtptr[j].layer; + if( !(layer == PINLAYER && (xctx.inst[n].flags & 4))) { + textlayer = (xctx.inst[n].ptr+ xctx.sym)->text[j].layer; if(textlayer < 0 || textlayer >= cadlayers) textlayer = layer; } - if((layer == PINLAYER && inst_ptr[n].flags & 4) || enable_layer[textlayer]) { + if((layer == PINLAYER && xctx.inst[n].flags & 4) || enable_layer[textlayer]) { svg_draw_string(textlayer, txtptr, (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); + flip^text.flip, text.hcenter, text.vcenter, + x0+x1, y0+y1, text.xscale, text.yscale); } } } - Tcl_SetResult(interp,"",TCL_STATIC); /*26102003 */ + Tcl_SetResult(interp,"",TCL_STATIC); } @@ -418,7 +418,7 @@ static void fill_svg_colors() char s[200]; /* overflow safe 20161122 */ unsigned int i,c; if(debug_var>=1) { - tcleval( "puts $svg_colors"); + tcleval( "puts $svg_colors"); } for(i=0;i=1) { - fprintf(errfp, "svg_colors: %d %d %d\n", svg_colors[i].red, svg_colors[i].green, svg_colors[i].blue); + fprintf(errfp, "svg_colors: %d %d %d\n", svg_colors[i].red, svg_colors[i].green, svg_colors[i].blue); } } - + } void svg_draw(void) { double dx, dy; - int c,i, textlayer; + int c,i, textlayer; int filledrect; int old_grid; - int modified_save; /* 20161121 */ + int modified_save; char *tmpstring=NULL; const char *r; @@ -470,8 +470,8 @@ void svg_draw(void) svg_colors=my_calloc(419, cadlayers, sizeof(Svg_color)); if(svg_colors==NULL){ fprintf(errfp, "svg_draw(): calloc error\n");tcleval( "exit"); - } - + } + fill_svg_colors(); old_grid=draw_grid; @@ -483,10 +483,10 @@ void svg_draw(void) modified_save=modified; - push_undo(); /* 20161121 */ + push_undo(); trim_wires(); /* 20161121 add connection boxes on wires but undo at end */ - - + + if(plotfile[0]) fd=fopen(plotfile, "w"); else fd=fopen("plot.svg", "w"); my_strncpy(plotfile,"", S(plotfile)); @@ -496,7 +496,7 @@ void svg_draw(void) fprintf(fd, "