(2) full widget creation for xschem new windows, code cleanup, removed old stuff

This commit is contained in:
Stefan Frederik 2021-11-09 19:05:56 +01:00
parent c6a6d1b1dc
commit c3c1b39cb5
9 changed files with 858 additions and 830 deletions

View File

@ -216,11 +216,34 @@ void toggle_only_probes()
draw();
}
void toggle_fullscreen()
void toggle_fullscreen(const char *topwin)
{
char *mytopwin = NULL;
char fullscr[]="add,fullscreen";
char normal[]="remove,fullscreen";
static int menu_removed = 0;
unsigned int topwin_id;
Window rootwindow, parent_id;
Window *framewin_child_ptr;
unsigned int framewindow_nchildren;
if(!strcmp(topwin, ".drw")) {
my_strdup2(1290, &mytopwin, "");
tcleval( "winfo id .");
sscanf(tclresult(), "0x%x", (unsigned int *) &topwin_id);
} else {
Tcl_VarEval(interp, "winfo toplevel ", topwin, NULL);
my_strdup2(1291, &mytopwin, tclresult());
Tcl_VarEval(interp, "winfo id ", mytopwin, NULL);
sscanf(tclresult(), "0x%x", (unsigned int *) &topwin_id);
}
XQueryTree(display, topwin_id, &rootwindow, &parent_id, &framewin_child_ptr, &framewindow_nchildren);
fullscreen = (fullscreen+1)%2;
if(fullscreen==1) tclsetvar("fullscreen","1");
else if(fullscreen==2) tclsetvar("fullscreen","2");
@ -228,25 +251,26 @@ void toggle_fullscreen()
dbg(1, "toggle_fullscreen(): fullscreen=%d\n", fullscreen);
if(fullscreen==2) {
tcleval("pack forget .menubar .statusbar; update");
Tcl_VarEval(interp, "pack forget ", mytopwin, ".menubar ", mytopwin, ".statusbar; update", NULL);
menu_removed = 1;
}
if(fullscreen !=2 && menu_removed) {
tcleval("pack .menubar -anchor n -side top -fill x -before .drw\n\
pack .statusbar -after .drw -anchor sw -fill x; update");
Tcl_VarEval(interp, "pack ", mytopwin, ".menubar -anchor n -side top -fill x -before ", mytopwin, ".drw\n\
pack ", mytopwin, ".statusbar -after ", mytopwin, ".drw -anchor sw -fill x; update", NULL);
menu_removed=0;
}
if(fullscreen == 1) {
window_state(display , parent_of_topwindow,fullscr);
window_state(display , parent_id,fullscr);
} else if(fullscreen == 2) {
window_state(display , parent_of_topwindow,normal);
window_state(display , parent_of_topwindow,fullscr);
window_state(display , parent_id,normal);
window_state(display , parent_id,fullscr);
} else {
window_state(display , parent_of_topwindow,normal);
window_state(display , parent_id,normal);
}
xctx->pending_fullzoom=1;
my_free(1291, &mytopwin);
}
#ifdef __unix__
@ -967,7 +991,7 @@ void schematic_in_new_window(void)
void launcher(void)
{
const char *str;
const char *url;
char program[PATH_MAX];
int n;
rebuild_selected_array();
@ -979,19 +1003,13 @@ void launcher(void)
select_object(mx,my,0, 0);
n=xctx->sel_array[0].n;
my_strncpy(program, get_tok_value(xctx->inst[n].prop_ptr,"program",0), S(program)); /* handle backslashes */
str = get_tok_value(xctx->inst[n].prop_ptr,"url",0); /* handle backslashes */
dbg(1, "launcher(): str=%s\n", str);
if(str[0] || (program[0])) {
tclsetvar("launcher_var",str);
if(program[0]) { /* 20170413 leave launcher_program empty if unspecified */
tclsetvar("launcher_program",program);
} else {
tclsetvar("launcher_program","");
}
tcleval( "launcher");
url = get_tok_value(xctx->inst[n].prop_ptr,"url",0); /* handle backslashes */
dbg(1, "launcher(): url=%s\n", url);
if(url[0] || (program[0])) { /* open url with appropriate program */
Tcl_VarEval(interp, "launcher {", url, "} {", program, "}", NULL);
} else {
my_strncpy(program, get_tok_value(xctx->inst[n].prop_ptr,"tclcommand",0), S(program));
if(program[0]) { /* 20170415 execute tcl command */
if(program[0]) { /* execute tcl command */
tcleval(program);
}
}

View File

@ -138,7 +138,7 @@ 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 callback(const char *winpath, int event, int mx, int my, KeySym key,
int button, int aux, int state)
{
char str[PATH_MAX + 100]; /* overflow safe 20161122 */
@ -648,6 +648,12 @@ int callback(int event, int mx, int my, KeySym key,
xctx->rectcolor = key - '0'+4;
my_snprintf(n, S(n), "%d", xctx->rectcolor);
Tcl_VarEval(interp, "xschem set rectcolor ", n, NULL);
if(!strcmp(winpath, ".drw")) {
Tcl_VarEval(interp, "reconfigure_layers_button {}", NULL);
} else {
Tcl_VarEval(interp, "reconfigure_layers_button [winfo parent ", winpath, "]", NULL);
}
dbg(1, "callback(): new color: %d\n",color_index[xctx->rectcolor]);
break;
}
@ -1139,8 +1145,9 @@ int callback(int event, int mx, int my, KeySym key,
}
if(key=='\\' && state==0) /* fullscreen */
{
dbg(1, "callback(): toggle fullscreen\n");
toggle_fullscreen();
dbg(1, "callback(): toggle fullscreen, winpath=%s\n", winpath);
toggle_fullscreen(winpath);
break;
}
if(key=='f' && state==Mod1Mask) /* flip objects around their anchor points 20171208 */

View File

@ -161,9 +161,9 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
if(!strcmp(argv[1],"callback") )
{
cmd_found = 1;
callback( atoi(argv[2]), atoi(argv[3]), atoi(argv[4]), (KeySym)atol(argv[5]),
atoi(argv[6]), atoi(argv[7]), atoi(argv[8]) );
dbg(2, "callback %s %s %s %s %s %s %s\n", argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
callback( argv[2], atoi(argv[3]), atoi(argv[4]), atoi(argv[5]), (KeySym)atol(argv[6]),
atoi(argv[7]), atoi(argv[8]), atoi(argv[9]) );
dbg(2, "callback %s %s %s %s %s %s %s %s\n", argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]);
Tcl_ResetResult(interp);
}
@ -458,7 +458,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
{
cmd_found = 1;
dbg(1, "scheduler(): xschem fullscreen, fullscreen=%d\n", fullscreen);
toggle_fullscreen();
toggle_fullscreen(argv[2]);
Tcl_ResetResult(interp);
}
}
@ -2323,7 +2323,6 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
}
else if(!strcmp(argv[2],"rectcolor")) {
xctx->rectcolor=atoi(argv[3]);
tcleval("reconfigure_layers_button");
rebuild_selected_array();
if(xctx->lastsel) {
change_layer();

View File

@ -267,7 +267,7 @@ void init_color_array(double dim)
double rr, gg, bb;
static int done=0;
dim_bg = tclgetvar("dim_background")[0] == '1' ? 1: 0;
dim_bg = tclgetvar("color_dim")[0] == '1' ? 1: 0;
for(i=0;i<cadlayers;i++) {
my_snprintf(s, S(s), "lindex $colors %d",i);
tcleval(s);
@ -399,6 +399,7 @@ void alloc_xschem_data()
xctx->schsymbolprop=NULL; /* symbol property string */
xctx->schverilogprop=NULL;/* verilog */
xctx->version_string = NULL;
xctx->rectcolor= 4; /* this is the current layer when xschem started. */
xctx->currsch = 0;
xctx->ui_state = 0;
xctx->need_reb_sel_arr = 1;
@ -466,7 +467,6 @@ void alloc_xschem_data()
xctx->hilight_time = 0; /* timestamp for sims */
xctx->hilight_nets = 0;
xctx->hilight_color = 0;
xctx->rectcolor = 0;
for(i=0;i<CADMAXHIER;i++) {
xctx->sch_path[i]=NULL;
xctx->sch_path_hash[i]=0;
@ -862,40 +862,35 @@ void new_schematic(const char *what, const char *tk_win_path, const char *filena
zoom_full(1, 0, 1, 0.97); /* draw */
} else if(!strcmp(what, "destroy")) {
if(cnt) {
int close = 0;
dbg(1, "new_schematic() destroy\n");
tkwin = Tk_NameToWindow(interp, tk_win_path, mainwindow);
for(i = 1; i < MAX_NEW_WINDOWS; i++) {
if(tkwin == tknew_window[i]) {
n = i;
break;
if(xctx->modified && has_x) {
tcleval("tk_messageBox -type okcancel -message {UNSAVED data: want to exit?}");
if(strcmp(tclresult(),"ok")==0) close = 1;
}
else close = 1;
Tcl_ResetResult(interp);
if(close) {
tkwin = Tk_NameToWindow(interp, tk_win_path, mainwindow);
for(i = 1; i < MAX_NEW_WINDOWS; i++) {
if(tkwin == tknew_window[i]) {
n = i;
break;
}
}
}
if(n >= 1 && n < MAX_NEW_WINDOWS) {
xctx = save_xctx[n];
delete_schematic_data();
save_xctx[n] = NULL;
Tk_DestroyWindow(tknew_window[n]);
tknew_window[n] = NULL;
xctx = save_xctx[0]; /* restore schematic */
set_modify(xctx->modified);
cnt--;
}
}
} else if(!strcmp(what, "destroy_all")) {
if(cnt) {
dbg(1, "new_schematic() destroy_all\n");
for(i = 1; i < MAX_NEW_WINDOWS; i++) {
if(tknew_window[i]) {
xctx = save_xctx[i];
if(n >= 1 && n < MAX_NEW_WINDOWS) {
xctx = save_xctx[n];
delete_schematic_data();
save_xctx[i] = NULL;
Tk_DestroyWindow(tknew_window[i]);
tknew_window[i] = NULL;
save_xctx[n] = NULL;
Tcl_VarEval(interp, "winfo parent ", tk_win_path, NULL);
Tk_DestroyWindow(tknew_window[n]);
Tcl_VarEval(interp, "destroy ", tclresult(), NULL);
tknew_window[n] = NULL;
xctx = save_xctx[0]; /* restore schematic */
set_modify(xctx->modified);
cnt--;
}
}
xctx = save_xctx[0]; /* restore schematic */
set_modify(xctx->modified);
}
} else if(!strcmp(what, "switch")) {
if(cnt) {
@ -1152,6 +1147,11 @@ int Tcl_AppInit(Tcl_Interp *inter)
tclsetvar("XSCHEM_LIBRARY_PATH", tclresult());
running_in_src_dir = 0;
/* create user conf dir , remove ~ if present */
my_snprintf(tmp, S(tmp),"regsub {^~/} {%s} {%s/}", USER_CONF_DIR, home_dir);
tcleval(tmp);
my_snprintf(user_conf_dir, S(user_conf_dir), "%s", tclresult());
tclsetvar("USER_CONF_DIR", user_conf_dir);
/* test if running xschem in src/ dir (usually for testing) */
if( !stat("./xschem.tcl", &buf) && !stat("./systemlib", &buf) && !stat("./xschem", &buf)) {
running_in_src_dir = 1;
@ -1161,18 +1161,37 @@ int Tcl_AppInit(Tcl_Interp *inter)
tcleval(tmp);
tclsetvar("XSCHEM_LIBRARY_PATH", tclresult());
*/
my_snprintf(tmp, S(tmp), "subst [file dirname \"%s\"]/xschem_library/devices", pwd_dir);
my_snprintf(tmp, S(tmp),
"set XSCHEM_LIBRARY_PATH %s/xschem_library", user_conf_dir);
tcleval(tmp);
my_snprintf(tmp, S(tmp),
"append XSCHEM_LIBRARY_PATH : [file dirname \"%s\"]/xschem_library/devices", pwd_dir);
tcleval(tmp);
my_snprintf(tmp, S(tmp),
"append XSCHEM_LIBRARY_PATH : [file dirname \"%s\"]/xschem_library/examples", pwd_dir);
tcleval(tmp);
my_snprintf(tmp, S(tmp),
"append XSCHEM_LIBRARY_PATH : [file dirname \"%s\"]/xschem_library/ngspice", pwd_dir);
tcleval(tmp);
my_snprintf(tmp, S(tmp),
"append XSCHEM_LIBRARY_PATH : [file dirname \"%s\"]/xschem_library/logic", pwd_dir);
tcleval(tmp);
my_snprintf(tmp, S(tmp),
"append XSCHEM_LIBRARY_PATH : [file dirname \"%s\"]/xschem_library/xschem_simulator", pwd_dir);
tcleval(tmp);
my_snprintf(tmp, S(tmp),
"append XSCHEM_LIBRARY_PATH : [file dirname \"%s\"]/xschem_library/binto7seg", pwd_dir);
tcleval(tmp);
my_snprintf(tmp, S(tmp),
"append XSCHEM_LIBRARY_PATH : [file dirname \"%s\"]/xschem_library/pcb", pwd_dir);
tcleval(tmp);
my_snprintf(tmp, S(tmp),
"append XSCHEM_LIBRARY_PATH : [file dirname \"%s\"]/xschem_library/rom8k", pwd_dir);
tcleval(tmp);
tclsetvar("XSCHEM_LIBRARY_PATH", tclresult());
} else if( !stat(XSCHEM_SHAREDIR, &buf) ) {
tclsetvar("XSCHEM_SHAREDIR",XSCHEM_SHAREDIR);
/* ... else give up searching, may set later after loading xschemrc */
}
/* create user conf dir , remove ~ if present */
my_snprintf(tmp, S(tmp),"regsub {^~/} {%s} {%s/}", USER_CONF_DIR, home_dir);
tcleval(tmp);
my_snprintf(user_conf_dir, S(user_conf_dir), "%s", tclresult());
tclsetvar("USER_CONF_DIR", user_conf_dir);
#else
char install_dir[MAX_PATH]="";
char *up_hier=NULL, *win_xschem_library_path=NULL;
@ -1183,10 +1202,10 @@ int Tcl_AppInit(Tcl_Interp *inter)
/*3*/ "xschem_library/examples",
/*4*/ "xschem_library/ngspice",
/*5*/ "xschem_library/logic",
/*6*/ "xschem_library/binto7seg",
/*7*/ "xschem_library/pcb",
/*8*/ "xschem_library/rom8k",
/*9*/ "xschem_library/xschem_simulator"};
/*6*/ "xschem_library/xschem_simulator"};
/*7*/ "xschem_library/binto7seg",
/*8*/ "xschem_library/pcb",
/*9*/ "xschem_library/rom8k",
GetModuleFileNameA(NULL, install_dir, MAX_PATH);
change_to_unix_fn(install_dir);
int dir_len=strlen(install_dir);
@ -1215,7 +1234,7 @@ int Tcl_AppInit(Tcl_Interp *inter)
tclsetvar("XSCHEM_LIBRARY_PATH", win_xschem_library_path_clean);
my_free(432, &win_xschem_library_path);
my_free(441, &up_hier);
char* gxschem_library=NULL, *xschem_sharedir=NULL;
char *xschem_sharedir=NULL;
if ((xschem_sharedir=getenv("XSCHEM_SHAREDIR")) != NULL) {
if (!stat(xschem_sharedir, &buf)) {
tclsetvar("XSCHEM_SHAREDIR", xschem_sharedir);
@ -1532,7 +1551,6 @@ int Tcl_AppInit(Tcl_Interp *inter)
visual = vinfo.visual;
*/
dbg(1, "Tcl_AppInit(): done step b of xinit()\n");
xctx->rectcolor= 4; /* this is the current layer when xschem started. */
for(i=0;i<cadlayers;i++)
{
pixmap[i] = XCreateBitmapFromData(display, xctx->window, (char*)(pixdata[i]),16,16);
@ -1595,16 +1613,16 @@ int Tcl_AppInit(Tcl_Interp *inter)
/* leaving undo buffer and other garbage around. */
/* */
/* Completing tk windows creation (see xschem.tcl, build_windows) and event binding */
/* Completing tk windows creation (see xschem.tcl, pack_widgets) and event binding */
/* *AFTER* X initialization done */
/* */
if(has_x) tcleval("build_windows");
if(has_x) tcleval("pack_widgets");
fullscreen=atoi(tclgetvar("fullscreen"));
if(fullscreen) {
fullscreen = 0;
tcleval("update");
toggle_fullscreen();
toggle_fullscreen(".");
}
/* */

View File

@ -752,6 +752,7 @@ extern char cairo_font_name[80];
extern double cairo_font_line_spacing; /* allows to change line spacing: default: 1.0 */
extern double cairo_vert_correct;
extern int debug_var;
extern double color_dim; /* can not be put in Xctx unless all X11 colors are reset on window change */
/*********** End of variables backed in xschem.tcl ***********/
extern int help;
extern char *cad_icon[];
@ -768,7 +769,6 @@ extern char *tcl_command;
extern char tcl_script[PATH_MAX];
extern int tcp_port;
extern char **color_array;
extern double color_dim; /* can not be put in Xctx unless all X11 colors are reset on window change */
extern unsigned int color_index[];
extern int n_active_layers; /* can not be put in Xctx, since it is bound to enable_layer[] */
extern int *active_layer; /* can not be put in Xctx, since it is bound to enable_layer[] */
@ -908,7 +908,7 @@ extern void xwin_exit(void);
extern void resetcairo(int create, int clear, int force_or_resize);
extern int Tcl_AppInit(Tcl_Interp *interp);
extern int source_tcl_file(char *s);
extern int callback(int event, int mx, int my, KeySym key,
extern int callback(const char *winpath, int event, int mx, int my, KeySym key,
int button, int aux, int state);
extern void resetwin(int create_pixmap, int clear_pixmap, int force, int w, int h);
extern void find_closest_net(double mx,double my);
@ -1170,7 +1170,7 @@ extern void windowid();
extern void preview_window(const char *what, const char *tk_win_path, const char *filename);
extern void new_schematic(const char *what, const char *tk_win_path, const char *filename);
extern int window_state (Display *disp, Window win, char *arg);
extern void toggle_fullscreen();
extern void toggle_fullscreen(const char *topwin);
extern void toggle_only_probes();
extern void update_symbol(const char *result, int x);
extern void tclexit(ClientData s);

File diff suppressed because it is too large Load Diff

View File

@ -26,9 +26,17 @@
# /home/schippes/share/doc/xschem/rom8k
#### For testing in build src directory
#### if unset following paths are set:
#### if unset following paths are set and maintained if existing:
#
# ~/.xschem/xschem_library
# ../xschem_library/devices
# ../xschem_library/examples
# ../xschem_library/ngspice
# ../xschem_library/logic
# ../xschem_library/xschem_simulator
# ../xschem_library/binto7seg
# ../xschem_library/pcb
# ../xschem_library/rom8k
#### For testing after installation: uncomment following lines
# set xschem_doc_dir [file dirname ${XSCHEM_SHAREDIR}]/doc/xschem

View File

@ -1,5 +1,6 @@
v {xschem version=2.9.5_RC8 file_version=1.1}
v {xschem version=3.0.0 file_version=1.2 }
G {}
K {}
V {}
S {}
E {}
@ -104,16 +105,16 @@ value=".option SCALE=1e-6 PARHIER=LOCAL RUNLVL=6 post MODMONTE=1
vvss vss 0 dc 0
.save all
.save tran @q5[p]
** models are generally not free: you must download
** SPICE models for active devices and put them into the below
** referenced file in simulation directory.
.include models_tesla.txt
.temp 30
.tran 1n 1m uic
.meas tran iavg AVG i(vc) from=950u to=990u
.probe tran p(q1) i(d2) i(d1) i(d3) i(l1) i(l2) i(L3)
.meas tran pavg AVG p(q1) from=950u to=990u
.meas tran iavg AVG i(vvcc) from=950u to=990u
.probe tran p(q5) i(l1) i(l2)
.meas tran pavg AVG @q5[p] from=950u to=990u
"}
C {lab_pin.sym} 140 -640 0 0 {name=p1 lab=VCC}
C {res.sym} 140 -580 0 1 {name=Rs m=1 value=1}

View File

@ -1,5 +1,6 @@
v {xschem version=2.9.5 file_version=1.1}
v {xschem version=3.0.0 file_version=1.2 }
G {}
K {}
V {}
S {}
E {}
@ -70,4 +71,3 @@ C {launcher.sym} 90 -580 0 0 {name=h1
descr="Ctrl-click to go to Delorie's
project page for info"
url="http://www.delorie.com/electronics/spice-stuff"}
C {test5.sch} 1070 -290 0 0 {}