code cleanup in new_schematic(), error checks to make new window creation safe and simpler (proc new_window what path filename)
This commit is contained in:
parent
afa8a2d2d7
commit
6dbd952910
133
src/xinit.c
133
src/xinit.c
|
|
@ -820,62 +820,125 @@ void preview_window(const char *what, const char *tk_win_path, const char *filen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MAX_NEW_WINDOWS 20
|
||||||
void new_schematic(const char *what, const char *tk_win_path, const char *filename)
|
void new_schematic(const char *what, const char *tk_win_path, const char *filename)
|
||||||
{
|
{
|
||||||
static int n = 0, cnt = 0;
|
static int initialized = 0;
|
||||||
static Xschem_ctx *save_xctx[20]; /* save pointer to current schematic context structure */
|
static int cnt = 0;
|
||||||
static Window new_window;
|
static Xschem_ctx *save_xctx[MAX_NEW_WINDOWS]; /* save pointer to current schematic context structure */
|
||||||
static Tk_Window tknew_window[20];
|
static Tk_Window tknew_window[MAX_NEW_WINDOWS];
|
||||||
|
int i, n;
|
||||||
|
Window new_window;
|
||||||
|
Tk_Window tkwin;
|
||||||
|
|
||||||
dbg(1, "------\n");
|
|
||||||
if(!strcmp(what, "create")) {
|
if(!strcmp(what, "create")) {
|
||||||
dbg(1, "new_schematic() create, save ctx\n");
|
dbg(1, "new_schematic() create, save ctx\n");
|
||||||
if(cnt == 0) save_xctx[0] = xctx; /* save current schematic */
|
if(cnt == 0) {
|
||||||
|
for(i = 0; i < MAX_NEW_WINDOWS; i++) {
|
||||||
|
save_xctx[i] = NULL;
|
||||||
|
tknew_window[i] = NULL;
|
||||||
|
}
|
||||||
|
save_xctx[0] = xctx; /* save current schematic */
|
||||||
|
tknew_window[0] = Tk_NameToWindow(interp, ".drw", mainwindow);
|
||||||
|
if(!initialized) {
|
||||||
|
tcleval("bind .drw <Enter> {+ new_window switch .drw}");
|
||||||
|
initialized = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(cnt + 1 >= MAX_NEW_WINDOWS) return; /* no more free slots */
|
||||||
cnt++;
|
cnt++;
|
||||||
n = cnt;
|
for(i = 1; i < MAX_NEW_WINDOWS; i++) { /* search 1st free slot */
|
||||||
tknew_window[cnt] = Tk_NameToWindow(interp, tk_win_path, mainwindow);
|
if(save_xctx[i] == NULL) {
|
||||||
Tk_MakeWindowExist(tknew_window[cnt]);
|
n = i;
|
||||||
new_window = Tk_WindowId(tknew_window[cnt]);
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tknew_window[n] = Tk_NameToWindow(interp, tk_win_path, mainwindow);
|
||||||
|
Tk_MakeWindowExist(tknew_window[n]);
|
||||||
|
new_window = Tk_WindowId(tknew_window[n]);
|
||||||
dbg(1, "new_schematic() draw\n");
|
dbg(1, "new_schematic() draw\n");
|
||||||
xctx = NULL; /* reset for preview */
|
xctx = NULL; /* reset for preview */
|
||||||
alloc_xschem_data(); /* alloc data into xctx */
|
alloc_xschem_data(); /* alloc data into xctx */
|
||||||
save_xctx[cnt] = xctx;
|
save_xctx[n] = xctx;
|
||||||
dbg(1, "new_schematic() draw, load schematic\n");
|
dbg(1, "new_schematic() draw, load schematic\n");
|
||||||
xctx->window = new_window;
|
xctx->window = new_window;
|
||||||
resetwin(1, 0, 1, 0, 0); /* create preview pixmap. resetwin(create_pixmap, clear_pixmap, force) */
|
resetwin(1, 0, 1, 0, 0); /* create preview pixmap. resetwin(create_pixmap, clear_pixmap, force, w, h) */
|
||||||
load_schematic(1,filename, 0);
|
load_schematic(1,filename, 0);
|
||||||
zoom_full(1, 0, 1, 0.97); /* draw */
|
zoom_full(1, 0, 1, 0.97); /* draw */
|
||||||
} else if(!strcmp(what, "redraw")) {
|
} else if(!strcmp(what, "redraw")) {
|
||||||
Xschem_ctx *save;
|
Xschem_ctx *save;
|
||||||
save = xctx;
|
if(cnt) {
|
||||||
n = atoi(tk_win_path);
|
save = xctx;
|
||||||
if(n <0) n = 0;
|
tkwin = Tk_NameToWindow(interp, tk_win_path, mainwindow);
|
||||||
if(n > cnt) n = cnt;
|
for(i = 0; i < MAX_NEW_WINDOWS; i++) {
|
||||||
xctx = save_xctx[n];
|
if(tkwin == tknew_window[i]) {
|
||||||
draw();
|
n = i;
|
||||||
xctx = save;
|
break;
|
||||||
set_modify(xctx->modified);
|
}
|
||||||
|
}
|
||||||
|
if(n >= 0 && n < MAX_NEW_WINDOWS) {
|
||||||
|
xctx = save_xctx[n];
|
||||||
|
draw();
|
||||||
|
xctx = save;
|
||||||
|
set_modify(xctx->modified); /* restore modified status */
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if(!strcmp(what, "destroy")) {
|
} else if(!strcmp(what, "destroy")) {
|
||||||
if(cnt > 0) {
|
if(cnt) {
|
||||||
dbg(1, "new_schematic() destroy\n");
|
dbg(1, "new_schematic() destroy\n");
|
||||||
xctx = save_xctx[cnt];
|
tkwin = Tk_NameToWindow(interp, tk_win_path, mainwindow);
|
||||||
delete_schematic_data();
|
for(i = 1; i < MAX_NEW_WINDOWS; i++) {
|
||||||
save_xctx[cnt] = NULL;
|
if(tkwin == tknew_window[i]) {
|
||||||
Tk_DestroyWindow(tknew_window[cnt]);
|
n = i;
|
||||||
cnt--;
|
break;
|
||||||
n = 0;
|
}
|
||||||
|
}
|
||||||
|
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];
|
||||||
|
delete_schematic_data();
|
||||||
|
save_xctx[i] = NULL;
|
||||||
|
Tk_DestroyWindow(tknew_window[i]);
|
||||||
|
tknew_window[i] = NULL;
|
||||||
|
cnt--;
|
||||||
|
}
|
||||||
|
}
|
||||||
xctx = save_xctx[0]; /* restore schematic */
|
xctx = save_xctx[0]; /* restore schematic */
|
||||||
set_modify(xctx->modified);
|
set_modify(xctx->modified);
|
||||||
}
|
}
|
||||||
} else if(!strcmp(what, "switch")) {
|
} else if(!strcmp(what, "switch")) {
|
||||||
n = atoi(tk_win_path);
|
if(cnt) {
|
||||||
if(n <0) n = 0;
|
dbg(1, "new_schematic() switch\n");
|
||||||
if(n > cnt) n = cnt;
|
tkwin = Tk_NameToWindow(interp, tk_win_path, mainwindow);
|
||||||
xctx = save_xctx[n];
|
for(i = 0; i < MAX_NEW_WINDOWS; i++) {
|
||||||
change_linewidth(xctx->lw); /* restore correct linewidth since it was changed in preview
|
if(tkwin == tknew_window[i]) {
|
||||||
* need to do the XSetLineAttributes */
|
n = i;
|
||||||
set_modify(xctx->modified);
|
break;
|
||||||
/* draw();*/
|
}
|
||||||
|
}
|
||||||
|
if(n >= 0 && n < MAX_NEW_WINDOWS) {
|
||||||
|
xctx = save_xctx[n];
|
||||||
|
change_linewidth(xctx->lw); /* restore correct linewidth since it was changed in preview
|
||||||
|
* need to do the XSetLineAttributes */
|
||||||
|
set_modify(xctx->modified);
|
||||||
|
/* draw();*/
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3315,6 +3315,11 @@ proc new_window {what {path {}} {filename {}}} {
|
||||||
update
|
update
|
||||||
xschem new_schematic create $path $filename
|
xschem new_schematic create $path $filename
|
||||||
set_bindings $path
|
set_bindings $path
|
||||||
|
bind $path <Expose> "new_window redraw $path"
|
||||||
|
wm protocol $path WM_DELETE_WINDOW "new_window destroy $path"
|
||||||
|
bind $path <Enter> "new_window switch $path"
|
||||||
|
} elseif { $what eq {destroy_all}} {
|
||||||
|
xschem new_schematic destroy_all {} {}
|
||||||
} elseif { $what eq {destroy}} {
|
} elseif { $what eq {destroy}} {
|
||||||
xschem new_schematic destroy $path {}
|
xschem new_schematic destroy $path {}
|
||||||
} elseif { $what eq {switch}} {
|
} elseif { $what eq {switch}} {
|
||||||
|
|
@ -3329,17 +3334,12 @@ proc test1 {} {
|
||||||
xschem load [abs_sym_path rom8k.sch]
|
xschem load [abs_sym_path rom8k.sch]
|
||||||
new_window create .xx [abs_sym_path mos_power_ampli.sch]
|
new_window create .xx [abs_sym_path mos_power_ampli.sch]
|
||||||
new_window create .yy [abs_sym_path solar_panel.sch]
|
new_window create .yy [abs_sym_path solar_panel.sch]
|
||||||
bind .xx <Expose> { new_window redraw 1 }
|
|
||||||
bind .yy <Expose> { new_window redraw 2 }
|
|
||||||
bind .xx <Enter> { new_window switch 1 }
|
|
||||||
bind .yy <Enter> { new_window switch 2 }
|
|
||||||
bind .drw <Enter> {+ new_window switch 0}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#### TEST MODE #####
|
#### TEST MODE #####
|
||||||
proc test1_end {} {
|
proc test1_end {} {
|
||||||
new_window destroy
|
new_window destroy .xx
|
||||||
new_window destroy
|
new_window destroy .yy
|
||||||
}
|
}
|
||||||
|
|
||||||
proc set_bindings {window_path} {
|
proc set_bindings {window_path} {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue