2020-08-08 15:47:34 +02:00
|
|
|
/* File: xinit.c
|
2020-10-12 13:13:31 +02:00
|
|
|
*
|
2020-08-08 15:47:34 +02:00
|
|
|
* This file is part of XSCHEM,
|
2020-10-12 13:13:31 +02:00
|
|
|
* a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit
|
2020-08-08 15:47:34 +02:00
|
|
|
* simulation.
|
2021-07-27 16:42:54 +02:00
|
|
|
* Copyright (C) 1998-2021 Stefan Frederik Schippers
|
2020-08-08 15:47:34 +02:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "xschem.h"
|
|
|
|
|
#ifdef __unix__
|
|
|
|
|
#include <pwd.h> /* getpwuid */
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static int init_done=0; /* 20150409 to avoid double call by Xwindows close and TclExitHandler */
|
|
|
|
|
static XSetWindowAttributes winattr;
|
2020-12-03 23:17:13 +01:00
|
|
|
static Tk_Window tkwindow, mainwindow;
|
2020-08-08 15:47:34 +02:00
|
|
|
static XWMHints *hints_ptr;
|
|
|
|
|
static Window topwindow;
|
|
|
|
|
static XColor xcolor_exact,xcolor;
|
|
|
|
|
typedef int myproc(
|
|
|
|
|
ClientData clientData,
|
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
|
int argc,
|
|
|
|
|
const char *argv[]);
|
|
|
|
|
|
2022-01-10 18:54:07 +01:00
|
|
|
/* variables for handling multiple windows/tabs */
|
|
|
|
|
static Xschem_ctx *save_xctx[MAX_NEW_WINDOWS]; /* save pointer to current schematic context structure */
|
|
|
|
|
static char window_path[MAX_NEW_WINDOWS][WINDOW_PATH_SIZE];
|
|
|
|
|
static int window_count = 0;
|
|
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
|
/* EWMH message handling routines 20071027... borrowed from wmctrl code */
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
|
#define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
|
|
|
|
|
#define _NET_WM_STATE_ADD 1 /* add/set property */
|
|
|
|
|
#define _NET_WM_STATE_TOGGLE 2 /* toggle property */
|
|
|
|
|
|
|
|
|
|
static int client_msg(Display *disp, Window win, char *msg, /* {{{ */
|
|
|
|
|
unsigned long data0, unsigned long data1,
|
|
|
|
|
unsigned long data2, unsigned long data3,
|
|
|
|
|
unsigned long data4) {
|
|
|
|
|
XEvent event;
|
|
|
|
|
long mask = SubstructureRedirectMask | SubstructureNotifyMask;
|
|
|
|
|
|
|
|
|
|
event.xclient.type = ClientMessage;
|
|
|
|
|
event.xclient.serial = 0;
|
|
|
|
|
event.xclient.send_event = True;
|
|
|
|
|
event.xclient.message_type = XInternAtom(disp, msg, False);
|
|
|
|
|
event.xclient.window = win;
|
|
|
|
|
event.xclient.format = 32;
|
|
|
|
|
event.xclient.data.l[0] = data0;
|
|
|
|
|
event.xclient.data.l[1] = data1;
|
|
|
|
|
event.xclient.data.l[2] = data2;
|
|
|
|
|
event.xclient.data.l[3] = data3;
|
|
|
|
|
event.xclient.data.l[4] = data4;
|
|
|
|
|
|
|
|
|
|
if (XSendEvent(disp, DefaultRootWindow(disp), False, mask, &event)) {
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fprintf(errfp, "Cannot send %s event.\n", msg);
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
}/*}}}*/
|
|
|
|
|
|
|
|
|
|
|
2022-02-19 14:31:55 +01:00
|
|
|
static int window_state (Display *disp, Window win, char *arg) {/*{{{*/
|
2021-12-02 13:28:40 +01:00
|
|
|
char arg_copy[256]; /* overflow safe */
|
2020-08-08 15:47:34 +02:00
|
|
|
unsigned long action;
|
|
|
|
|
int i;
|
|
|
|
|
Atom prop1 = 0;
|
|
|
|
|
Atom prop2 = 0;
|
|
|
|
|
char *p1, *p2;
|
2020-11-22 00:51:24 +01:00
|
|
|
const char *argerr = "expects a list of comma separated parameters: "
|
|
|
|
|
"\"(remove|add|toggle),<PROP1>[,<PROP2>]\"\n";
|
2020-08-08 15:47:34 +02:00
|
|
|
|
2021-12-02 13:28:40 +01:00
|
|
|
char tmp_prop1[256], tmp1[256]; /* overflow safe */
|
|
|
|
|
char tmp_prop2[256], tmp2[256]; /* overflow safe */
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
|
2021-12-02 13:28:40 +01:00
|
|
|
if (!arg || strlen(arg) == 0) {
|
2020-08-08 15:47:34 +02:00
|
|
|
fputs(argerr, errfp);
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
}
|
2021-12-02 13:28:40 +01:00
|
|
|
dbg(1,"window_state() , win=0x%x arg=%s\n", (int)win, arg);
|
|
|
|
|
my_strncpy(arg_copy, arg, S(arg_copy));
|
2020-08-08 15:47:34 +02:00
|
|
|
if ((p1 = strchr(arg_copy, ','))) {
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
*p1 = '\0';
|
|
|
|
|
|
|
|
|
|
/* action */
|
|
|
|
|
if (strcmp(arg_copy, "remove") == 0) {
|
|
|
|
|
action = _NET_WM_STATE_REMOVE;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp(arg_copy, "add") == 0) {
|
|
|
|
|
action = _NET_WM_STATE_ADD;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp(arg_copy, "toggle") == 0) {
|
|
|
|
|
action = _NET_WM_STATE_TOGGLE;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fputs("Invalid action. Use either remove, add or toggle.\n", errfp);
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
p1++;
|
|
|
|
|
|
|
|
|
|
/* the second property */
|
|
|
|
|
if ((p2 = strchr(p1, ','))) {
|
|
|
|
|
*p2 = '\0';
|
|
|
|
|
p2++;
|
|
|
|
|
if (strlen(p2) == 0) {
|
|
|
|
|
fputs("Invalid zero length property.\n", errfp);
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
for( i = 0; p2[i]; i++) tmp2[i] = toupper( p2[i] );
|
2021-12-02 13:28:40 +01:00
|
|
|
tmp2[i] = '\0';
|
2020-08-08 15:47:34 +02:00
|
|
|
my_snprintf(tmp_prop2, S(tmp_prop2), "_NET_WM_STATE_%s", tmp2);
|
|
|
|
|
prop2 = XInternAtom(disp, tmp_prop2, False);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* the first property */
|
|
|
|
|
if (strlen(p1) == 0) {
|
|
|
|
|
fputs("Invalid zero length property.\n", errfp);
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
for( i = 0; p1[i]; i++) tmp1[i] = toupper( p1[i] );
|
2021-12-02 13:28:40 +01:00
|
|
|
tmp1[i] = '\0';
|
2020-08-08 15:47:34 +02:00
|
|
|
my_snprintf(tmp_prop1, S(tmp_prop1), "_NET_WM_STATE_%s", tmp1);
|
|
|
|
|
prop1 = XInternAtom(disp, tmp_prop1, False);
|
|
|
|
|
|
2020-10-12 13:13:31 +02:00
|
|
|
|
|
|
|
|
return client_msg(disp, win, "_NET_WM_STATE",
|
2020-08-08 15:47:34 +02:00
|
|
|
action, (unsigned long)prop1, (unsigned long)prop2, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fputs(argerr, errfp);
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
}/*}}}*/
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
|
|
2021-11-17 22:15:36 +01:00
|
|
|
/* used to set icon */
|
|
|
|
|
void windowid(const char *winpath)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
Display *display;
|
|
|
|
|
Tk_Window mainwindow;
|
|
|
|
|
|
|
|
|
|
unsigned int ww;
|
2021-11-10 14:11:27 +01:00
|
|
|
Window framewin, rootwindow, parent_of_topwindow;
|
2020-08-08 15:47:34 +02:00
|
|
|
Window *framewin_child_ptr;
|
|
|
|
|
unsigned int framewindow_nchildren;
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2021-11-18 03:01:28 +01:00
|
|
|
dbg(1, "windowid(): winpath=%s\n", winpath);
|
2020-08-08 15:47:34 +02:00
|
|
|
framewindow_nchildren =0;
|
2020-10-16 19:16:03 +02:00
|
|
|
mainwindow=Tk_MainWindow(interp);
|
|
|
|
|
display = Tk_Display(mainwindow);
|
2021-12-05 12:39:05 +01:00
|
|
|
tclvareval("winfo id ", winpath, NULL);
|
2020-10-16 19:16:03 +02:00
|
|
|
sscanf(tclresult(), "0x%x", (unsigned int *) &ww);
|
|
|
|
|
framewin = ww;
|
|
|
|
|
XQueryTree(display, framewin, &rootwindow, &parent_of_topwindow, &framewin_child_ptr, &framewindow_nchildren);
|
|
|
|
|
dbg(1,"framewinID=%x\n", (unsigned int) framewin);
|
|
|
|
|
dbg(1,"framewin nchilds=%d\n", (unsigned int)framewindow_nchildren);
|
|
|
|
|
dbg(1,"framewin parentID=%x\n", (unsigned int) parent_of_topwindow);
|
|
|
|
|
if (debug_var>=1) {
|
|
|
|
|
if (framewindow_nchildren==0) fprintf(errfp, "no framewin child\n");
|
|
|
|
|
else fprintf(errfp, "framewin child 0=%x\n", (unsigned int)framewin_child_ptr[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* here I create the icon pixmap,to be used when iconified, */
|
2020-08-08 15:47:34 +02:00
|
|
|
#ifdef __unix__
|
2020-10-16 19:16:03 +02:00
|
|
|
if(!cad_icon_pixmap) {
|
2020-11-10 13:17:25 +01:00
|
|
|
i=XpmCreatePixmapFromData(display,framewin, cad_icon,&cad_icon_pixmap, &cad_icon_mask, NULL);
|
2020-12-06 20:52:35 +01:00
|
|
|
dbg(1, "windowid(): creating icon pixmap returned: %d\n",i);
|
2020-10-16 19:16:03 +02:00
|
|
|
}
|
2021-11-17 22:15:36 +01:00
|
|
|
hints_ptr = XAllocWMHints();
|
|
|
|
|
hints_ptr->icon_pixmap = cad_icon_pixmap ;
|
|
|
|
|
hints_ptr->icon_mask = cad_icon_mask ;
|
|
|
|
|
hints_ptr->flags = IconPixmapHint | IconMaskHint;
|
|
|
|
|
XSetWMHints(display, parent_of_topwindow, hints_ptr);
|
|
|
|
|
XFree(hints_ptr);
|
2020-08-08 15:47:34 +02:00
|
|
|
#endif
|
2020-10-16 19:16:03 +02:00
|
|
|
Tcl_SetResult(interp,"",TCL_STATIC);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-19 14:31:55 +01:00
|
|
|
static int err(Display *display, XErrorEvent *xev)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
char s[1024]; /* overflow safe 20161122 */
|
|
|
|
|
int l=250;
|
|
|
|
|
#ifdef __unix__
|
|
|
|
|
XGetErrorText(display, xev->error_code, s,l);
|
|
|
|
|
dbg(1, "err(): Err %d :%s maj=%d min=%d\n", xev->error_code, s, xev->request_code,
|
|
|
|
|
xev->minor_code);
|
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-19 14:31:55 +01:00
|
|
|
static unsigned int find_best_color(char colorname[])
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
double distance=10000000000.0, dist, r, g, b, red, green, blue;
|
|
|
|
|
double deltar,deltag,deltab;
|
2020-12-05 03:16:01 +01:00
|
|
|
unsigned int idx;
|
2021-11-16 22:28:10 +01:00
|
|
|
|
2021-12-07 19:43:57 +01:00
|
|
|
/* dbg(1, "find_best_color() start: %g\n", timer(1)); */
|
2020-08-08 15:47:34 +02:00
|
|
|
#ifdef __unix__
|
|
|
|
|
if( XAllocNamedColor(display, colormap, colorname, &xcolor_exact, &xcolor) ==0 )
|
|
|
|
|
{
|
|
|
|
|
for(i=0;i<=255;i++) {
|
2021-11-16 22:28:10 +01:00
|
|
|
xctx->xcolor_array[i].pixel=i;
|
|
|
|
|
XQueryColor(display, colormap, xctx->xcolor_array+i);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
/* debug ... */
|
2021-11-16 22:28:10 +01:00
|
|
|
dbg(2, "find_best_color(): Server failed to allocate requested color, finding substitute\n");
|
2020-08-08 15:47:34 +02:00
|
|
|
XLookupColor(display, colormap, colorname, &xcolor_exact, &xcolor);
|
|
|
|
|
red = xcolor.red; green = xcolor.green; blue = xcolor.blue;
|
2020-12-05 03:16:01 +01:00
|
|
|
idx=0;
|
2020-08-08 15:47:34 +02:00
|
|
|
for(i = 0;i<=255; i++)
|
|
|
|
|
{
|
2021-11-16 22:28:10 +01:00
|
|
|
r = xctx->xcolor_array[i].red ; g = xctx->xcolor_array[i].green ; b = xctx->xcolor_array[i].blue;
|
2020-08-08 15:47:34 +02:00
|
|
|
deltar = (r - red);deltag = (g - green);deltab = (b - blue);
|
|
|
|
|
dist = deltar*deltar + deltag*deltag + deltab*deltab;
|
|
|
|
|
if( dist <= distance )
|
|
|
|
|
{
|
2020-12-05 03:16:01 +01:00
|
|
|
idx = i;
|
2020-08-08 15:47:34 +02:00
|
|
|
distance = dist;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/*XLookupColor(display, colormap, colorname, &xcolor_exact, &xcolor); */
|
2020-12-05 03:16:01 +01:00
|
|
|
idx = xcolor.pixel;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2021-12-07 19:43:57 +01:00
|
|
|
/* dbg(1, "find_best_color() return: %g\n", timer(1)); */
|
2020-12-05 03:16:01 +01:00
|
|
|
return idx;
|
2022-02-18 15:11:44 +01:00
|
|
|
#else
|
|
|
|
|
Tk_Window mainwindow = Tk_MainWindow(interp);
|
|
|
|
|
XColor *xc = Tk_GetColor(interp, mainwindow, colorname);
|
|
|
|
|
/* if (XAllocColor(display, colormap, xc)) return(xc->pixel); */
|
|
|
|
|
return xc->pixel;
|
|
|
|
|
#endif
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-11-16 22:28:10 +01:00
|
|
|
static void init_color_array(double dim, double dim_bg)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
char s[256]; /* overflow safe 20161122 */
|
|
|
|
|
int i;
|
2020-10-12 13:13:31 +02:00
|
|
|
unsigned int r, g, b;
|
2021-11-16 22:28:10 +01:00
|
|
|
double tmp_dim;
|
2020-10-17 03:47:32 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
for(i=0;i<cadlayers;i++) {
|
|
|
|
|
my_snprintf(s, S(s), "lindex $colors %d",i);
|
|
|
|
|
tcleval(s);
|
2020-08-16 03:34:45 +02:00
|
|
|
dbg(2, "init_color_array(): color:%s\n",tclresult());
|
2020-08-08 15:47:34 +02:00
|
|
|
|
2020-10-12 13:13:31 +02:00
|
|
|
sscanf(tclresult(), "#%02x%02x%02x", &r, &g, &b);
|
2021-11-16 22:28:10 +01:00
|
|
|
if(i == BACKLAYER) tmp_dim = dim_bg;
|
|
|
|
|
else tmp_dim = dim;
|
|
|
|
|
if(tmp_dim>=0.) {
|
|
|
|
|
r +=(51.-r/5.)*tmp_dim;
|
|
|
|
|
g +=(51.-g/5.)*tmp_dim;
|
|
|
|
|
b +=(51.-b/5.)*tmp_dim;
|
|
|
|
|
} else {
|
|
|
|
|
r +=(r/5.)*tmp_dim;
|
|
|
|
|
g +=(g/5.)*tmp_dim;
|
|
|
|
|
b +=(b/5.)*tmp_dim;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2021-11-16 22:28:10 +01:00
|
|
|
/* fprintf(errfp, "init_color_array: colors: %.16g %.16g %.16g dim=%.16g c=%d\n", r, g, b, dim, i); */
|
|
|
|
|
if(r>0xff) r=0xff;
|
|
|
|
|
if(g>0xff) g=0xff;
|
|
|
|
|
if(b>0xff) b=0xff;
|
2020-08-08 15:47:34 +02:00
|
|
|
my_snprintf(s, S(s), "#%02x%02x%02x", r, g, b);
|
2021-11-16 22:28:10 +01:00
|
|
|
my_strdup(643, &xctx->color_array[i], s);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-19 14:31:55 +01:00
|
|
|
static void init_pixdata()/* populate xctx->fill_type array that is used in create_gc() to set fill styles */
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
int i,j, full, empty;
|
|
|
|
|
for(i=0;i<cadlayers;i++) {
|
|
|
|
|
full=1; empty=1;
|
|
|
|
|
for(j=0;j<32;j++) {
|
2020-10-12 13:13:31 +02:00
|
|
|
if(i<sizeof(pixdata_init)/sizeof(pixdata_init[0]))
|
2020-08-08 15:47:34 +02:00
|
|
|
pixdata[i][j] = pixdata_init[i][j];
|
2020-10-12 13:13:31 +02:00
|
|
|
else
|
2020-08-08 15:47:34 +02:00
|
|
|
pixdata[i][j] = 0x00;
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
if(pixdata[i][j]!=0xff) full=0;
|
|
|
|
|
if(pixdata[i][j]!=0x00) empty=0;
|
|
|
|
|
}
|
2021-11-16 22:28:10 +01:00
|
|
|
if(full) xctx->fill_type[i] = 1;
|
|
|
|
|
else if(empty) xctx->fill_type[i] = 0;
|
|
|
|
|
else xctx->fill_type[i]=2;
|
|
|
|
|
if(rainbow_colors && i>5) xctx->fill_type[i]=1; /* 20171212 solid fill style */
|
|
|
|
|
/*fprintf(errfp, "fill_type[%d]= %d\n", i, xctx->fill_type[i]); */
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 05:14:25 +01:00
|
|
|
static void free_xschem_data()
|
2020-10-04 19:53:09 +02:00
|
|
|
{
|
|
|
|
|
int i;
|
2021-11-29 11:52:32 +01:00
|
|
|
xctx->delete_undo();
|
2020-12-31 03:08:24 +01:00
|
|
|
free_simdata();
|
2021-12-22 04:39:23 +01:00
|
|
|
|
|
|
|
|
my_free(970, &xctx->node_table);
|
|
|
|
|
my_free(1385, &xctx->inst_table);
|
|
|
|
|
my_free(1386, &xctx->node_redraw_table);
|
|
|
|
|
my_free(1387, &xctx->hilight_table);
|
|
|
|
|
my_free(1388, &xctx->raw_table);
|
|
|
|
|
|
2020-10-15 17:39:21 +02:00
|
|
|
my_free(1098, &xctx->wire);
|
|
|
|
|
my_free(1100, &xctx->text);
|
|
|
|
|
my_free(1107, &xctx->inst);
|
2020-10-04 19:53:09 +02:00
|
|
|
for(i=0;i<cadlayers;i++) {
|
2020-12-06 22:07:33 +01:00
|
|
|
my_free(1103, &xctx->rect[i]);
|
|
|
|
|
my_free(1104, &xctx->line[i]);
|
|
|
|
|
my_free(1105, &xctx->poly[i]);
|
|
|
|
|
my_free(1106, &xctx->arc[i]);
|
2020-10-04 19:53:09 +02:00
|
|
|
}
|
2020-10-15 17:39:21 +02:00
|
|
|
for(i=0;i<xctx->maxs;i++) {
|
2020-12-06 22:07:33 +01:00
|
|
|
my_free(1109, &xctx->sym[i].line);
|
|
|
|
|
my_free(1110, &xctx->sym[i].rect);
|
|
|
|
|
my_free(1111, &xctx->sym[i].arc);
|
|
|
|
|
my_free(1112, &xctx->sym[i].poly);
|
|
|
|
|
my_free(1113, &xctx->sym[i].lines);
|
|
|
|
|
my_free(1114, &xctx->sym[i].polygons);
|
|
|
|
|
my_free(1115, &xctx->sym[i].arcs);
|
|
|
|
|
my_free(1116, &xctx->sym[i].rects);
|
2020-10-04 19:53:09 +02:00
|
|
|
}
|
2020-10-15 17:39:21 +02:00
|
|
|
my_free(1117, &xctx->sym);
|
|
|
|
|
my_free(1118, &xctx->rect);
|
|
|
|
|
my_free(1119, &xctx->line);
|
|
|
|
|
my_free(1125, &xctx->poly);
|
|
|
|
|
my_free(1126, &xctx->arc);
|
|
|
|
|
my_free(1124, &xctx->rects);
|
|
|
|
|
my_free(1127, &xctx->polygons);
|
|
|
|
|
my_free(1128, &xctx->arcs);
|
|
|
|
|
my_free(1129, &xctx->lines);
|
|
|
|
|
my_free(1130, &xctx->maxr);
|
|
|
|
|
my_free(1131, &xctx->maxp);
|
|
|
|
|
my_free(1132, &xctx->maxa);
|
|
|
|
|
my_free(1133, &xctx->maxl);
|
2020-12-03 04:20:05 +01:00
|
|
|
my_free(1108, &xctx->sel_array);
|
2020-10-15 17:39:21 +02:00
|
|
|
for(i=0;i<CADMAXHIER;i++) my_free(1139, &xctx->sch_path[i]);
|
2020-12-12 13:36:39 +01:00
|
|
|
my_free(1099, &xctx->gridpoint);
|
2020-12-12 20:50:06 +01:00
|
|
|
my_free(1214, &xctx->biggridpoint);
|
2021-11-16 22:28:10 +01:00
|
|
|
my_free(1135, &xctx->gc);
|
|
|
|
|
my_free(1136, &xctx->gcstipple);
|
|
|
|
|
for(i=0;i<cadlayers;i++) my_free(1101, &xctx->color_array[i]);
|
|
|
|
|
my_free(605, &xctx->color_array);
|
|
|
|
|
my_free(1123, &xctx->enable_layer);
|
|
|
|
|
my_free(1121, &xctx->active_layer);
|
|
|
|
|
my_free(1295, &xctx->top_path);
|
2022-01-10 18:54:07 +01:00
|
|
|
my_free(1463, &xctx->current_win_path);
|
2021-11-16 22:28:10 +01:00
|
|
|
my_free(1120, &xctx->fill_type);
|
2021-12-04 01:45:26 +01:00
|
|
|
if(xctx->inst_redraw_table) my_free(604, &xctx->inst_redraw_table);
|
2020-10-15 17:39:21 +02:00
|
|
|
my_free(269, &xctx);
|
2020-10-04 19:53:09 +02:00
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
|
2022-02-19 14:31:55 +01:00
|
|
|
static void create_gc(void)
|
2021-11-16 22:28:10 +01:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for(i=0;i<cadlayers;i++)
|
|
|
|
|
{
|
|
|
|
|
pixmap[i] = XCreateBitmapFromData(display, xctx->window, (char*)(pixdata[i]),16,16);
|
|
|
|
|
xctx->gc[i] = XCreateGC(display,xctx->window,0L,NULL);
|
|
|
|
|
xctx->gcstipple[i] = XCreateGC(display,xctx->window,0L,NULL);
|
|
|
|
|
XSetStipple(display,xctx->gcstipple[i],pixmap[i]);
|
|
|
|
|
if(xctx->fill_type[i]==1) XSetFillStyle(display,xctx->gcstipple[i],FillSolid);
|
|
|
|
|
else XSetFillStyle(display,xctx->gcstipple[i],FillStippled);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-19 14:31:55 +01:00
|
|
|
static void free_gc()
|
2021-11-16 22:28:10 +01:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for(i=0;i<cadlayers;i++) {
|
|
|
|
|
XFreeGC(display,xctx->gc[i]);
|
|
|
|
|
XFreeGC(display,xctx->gcstipple[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 05:14:25 +01:00
|
|
|
static void alloc_xschem_data(const char *top_path, const char *win_path)
|
2020-10-04 12:51:34 +02:00
|
|
|
{
|
2020-12-06 02:10:53 +01:00
|
|
|
int i, j;
|
2020-12-04 00:30:13 +01:00
|
|
|
|
2020-10-17 22:39:52 +02:00
|
|
|
xctx = my_calloc(153, 1, sizeof(Xschem_ctx));
|
2020-12-04 00:30:13 +01:00
|
|
|
xctx->cur_undo_ptr = 0;
|
|
|
|
|
xctx->head_undo_ptr = 0;
|
|
|
|
|
xctx->tail_undo_ptr = 0;
|
|
|
|
|
xctx->undo_dirname = NULL;
|
2021-11-28 14:35:55 +01:00
|
|
|
|
2022-01-10 18:54:07 +01:00
|
|
|
if(!strcmp(tclgetvar("undo_type"), "disk")) {
|
|
|
|
|
xctx->undo_type = 0;
|
|
|
|
|
xctx->push_undo = push_undo;
|
|
|
|
|
xctx->pop_undo = pop_undo;
|
|
|
|
|
xctx->delete_undo = delete_undo;
|
|
|
|
|
xctx->clear_undo = clear_undo;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
xctx->undo_type = 1; /* "memory" */
|
|
|
|
|
xctx->push_undo = mem_push_undo;
|
|
|
|
|
xctx->pop_undo = mem_pop_undo;
|
|
|
|
|
xctx->delete_undo = mem_delete_undo;
|
|
|
|
|
xctx->clear_undo = mem_clear_undo;
|
|
|
|
|
}
|
2021-11-29 02:47:37 +01:00
|
|
|
xctx->undo_initialized = 0;
|
2020-10-15 17:39:21 +02:00
|
|
|
xctx->zoom=CADINITIALZOOM;
|
|
|
|
|
xctx->mooz=1/CADINITIALZOOM;
|
|
|
|
|
xctx->xorigin=CADINITIALX;
|
|
|
|
|
xctx->yorigin=CADINITIALY;
|
2021-12-29 05:11:39 +01:00
|
|
|
xctx->graph_names = NULL;
|
|
|
|
|
xctx->graph_values = NULL;
|
|
|
|
|
xctx->graph_nvars = 0;
|
|
|
|
|
xctx->graph_npoints = NULL;
|
2022-02-05 00:28:06 +01:00
|
|
|
xctx->graph_allpoints = 0;
|
2021-12-29 05:11:39 +01:00
|
|
|
xctx->graph_datasets = 0;
|
2021-12-27 05:22:19 +01:00
|
|
|
xctx->graph_master = 0;
|
2021-12-30 15:45:38 +01:00
|
|
|
xctx->graph_cursor1_x = 0;
|
|
|
|
|
xctx->graph_unlock_x = 0;
|
2021-12-29 05:11:39 +01:00
|
|
|
xctx->graph_flags = 0;
|
2022-01-28 04:44:07 +01:00
|
|
|
xctx->graph_top = 0;
|
2021-12-27 05:22:19 +01:00
|
|
|
xctx->graph_bottom = 0;
|
|
|
|
|
xctx->graph_left = 0;
|
2022-01-29 12:27:54 +01:00
|
|
|
xctx->graph_lastsel = -1;
|
2022-02-02 18:33:16 +01:00
|
|
|
xctx->graph_sim_type = 0; /* type of sim, 1: Tran, 2: Dc, 3: Ac */
|
2022-01-28 04:44:07 +01:00
|
|
|
xctx->graph_struct.hilight_wave[0] = -1; /* graph index of hilight wave */
|
|
|
|
|
xctx->graph_struct.hilight_wave[1] = -1; /* index of wave */
|
2021-12-22 04:39:23 +01:00
|
|
|
xctx->raw_schname = NULL;
|
2020-10-15 17:39:21 +02:00
|
|
|
xctx->wires = 0;
|
|
|
|
|
xctx->instances = 0;
|
|
|
|
|
xctx->symbols = 0;
|
2021-11-16 22:28:10 +01:00
|
|
|
xctx->sym_txt = 1;
|
2020-10-15 17:39:21 +02:00
|
|
|
xctx->texts = 0;
|
|
|
|
|
xctx->schprop = NULL; /* SPICE */
|
|
|
|
|
xctx->schtedaxprop=NULL; /* tEDAx */
|
|
|
|
|
xctx->schvhdlprop=NULL; /* vhdl property string */
|
|
|
|
|
xctx->schsymbolprop=NULL; /* symbol property string */
|
|
|
|
|
xctx->schverilogprop=NULL;/* verilog */
|
|
|
|
|
xctx->version_string = NULL;
|
2021-11-09 19:05:56 +01:00
|
|
|
xctx->rectcolor= 4; /* this is the current layer when xschem started. */
|
2020-10-15 17:39:21 +02:00
|
|
|
xctx->currsch = 0;
|
2020-12-02 15:10:47 +01:00
|
|
|
xctx->ui_state = 0;
|
|
|
|
|
xctx->need_reb_sel_arr = 1;
|
|
|
|
|
xctx->lastsel = 0;
|
|
|
|
|
xctx->maxsel = 0;
|
|
|
|
|
xctx->prep_net_structs = 0;
|
|
|
|
|
xctx->prep_hi_structs = 0;
|
2021-10-28 10:36:23 +02:00
|
|
|
xctx->simdata = NULL;
|
|
|
|
|
xctx->simdata_ninst = 0;
|
2020-12-02 15:10:47 +01:00
|
|
|
xctx->prep_hash_inst = 0;
|
|
|
|
|
xctx->prep_hash_wires = 0;
|
|
|
|
|
xctx->modified = 0;
|
2020-12-03 04:20:05 +01:00
|
|
|
xctx->semaphore = 0;
|
2022-02-04 17:35:07 +01:00
|
|
|
xctx->tok_size = 0;
|
2020-12-02 15:10:47 +01:00
|
|
|
xctx->netlist_name[0] = '\0';
|
2021-11-17 23:12:17 +01:00
|
|
|
xctx->flat_netlist = 0;
|
2021-07-14 01:43:29 +02:00
|
|
|
xctx->plotfile[0] = '\0';
|
2021-01-14 18:12:02 +01:00
|
|
|
xctx->netlist_unconn_cnt = 0; /* unique count of unconnected pins while netlisting */
|
2020-12-06 02:10:53 +01:00
|
|
|
xctx->current_dirname[0] = '\0';
|
|
|
|
|
for(i = 0; i < NBOXES; i++) {
|
|
|
|
|
for(j = 0; j < NBOXES; j++) {
|
2021-11-23 15:03:51 +01:00
|
|
|
xctx->instpin_spatial_table[i][j] = NULL;
|
|
|
|
|
xctx->wire_spatial_table[i][j] = NULL;
|
|
|
|
|
xctx->inst_spatial_table[i][j] = NULL;
|
2020-12-06 02:10:53 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-28 01:33:01 +01:00
|
|
|
xctx->node_table = my_calloc(517, HASHSIZE, sizeof(Node_hashentry *));
|
|
|
|
|
xctx->node_redraw_table = my_calloc(973, HASHSIZE, sizeof(Int_hashentry *));
|
|
|
|
|
xctx->inst_table = my_calloc(1382, HASHSIZE, sizeof(Inst_hashentry *));
|
|
|
|
|
xctx->hilight_table = my_calloc(1383, HASHSIZE, sizeof(Hilight_hashentry *));
|
|
|
|
|
xctx->raw_table = my_calloc(1384, HASHSIZE, sizeof(Int_hashentry *));
|
2021-12-22 04:39:23 +01:00
|
|
|
|
2021-12-04 01:45:26 +01:00
|
|
|
xctx->inst_redraw_table = NULL;
|
|
|
|
|
xctx->inst_redraw_table_size = 0;
|
2020-12-06 02:10:53 +01:00
|
|
|
xctx->window = xctx->save_pixmap = 0;
|
2020-12-03 11:42:06 +01:00
|
|
|
xctx->xrect[0].width = xctx->xrect[0].height = xctx->xrect[0].x = xctx->xrect[0].y = 0;
|
2020-12-07 20:04:57 +01:00
|
|
|
#if HAS_CAIRO==1
|
2020-12-06 02:10:53 +01:00
|
|
|
xctx->cairo_ctx = xctx->cairo_save_ctx = NULL;
|
|
|
|
|
xctx->cairo_sfc = xctx->cairo_save_sfc = NULL;
|
2020-12-07 18:51:15 +01:00
|
|
|
#endif
|
2020-12-06 02:10:53 +01:00
|
|
|
xctx->gctiled = 0;
|
|
|
|
|
/* get_unnamed_node() */
|
|
|
|
|
xctx->new_node = 0;
|
|
|
|
|
xctx->node_mult = NULL;
|
|
|
|
|
xctx->node_mult_size = 0;
|
2020-12-06 16:10:22 +01:00
|
|
|
/* move.c */
|
|
|
|
|
xctx->rx1 = xctx->rx2 = xctx->ry1 = xctx->ry2 = 0.0;
|
|
|
|
|
xctx->move_rot = 0;
|
|
|
|
|
xctx->move_flip = 0;
|
2021-10-25 17:05:43 +02:00
|
|
|
xctx->manhattan_lines = 0;
|
2020-12-06 16:10:22 +01:00
|
|
|
xctx->x1 = xctx->y_1 = xctx->x2 = xctx->y_2 = xctx->deltax = xctx->deltay = 0.0;
|
|
|
|
|
xctx->movelastsel = 0;
|
|
|
|
|
xctx->rotatelocal=0;
|
|
|
|
|
/* new_wire */
|
|
|
|
|
xctx->nl_x1 = xctx->nl_y1 = xctx->nl_x2 = xctx->nl_y2 = 0.0;
|
|
|
|
|
xctx->nl_xx1 = xctx->nl_yy1 = xctx->nl_xx2 = xctx->nl_yy2 = 0.0;
|
|
|
|
|
/* new_arc */
|
|
|
|
|
xctx->nl_x = xctx->nl_y = xctx->nl_r = xctx->nl_a = xctx->nl_b = xctx->nl_x3 = xctx->nl_y3 = 0.0;
|
|
|
|
|
xctx->nl_state = 0;
|
|
|
|
|
xctx->nl_sweep_angle = 0.0;
|
|
|
|
|
/* new_polygon */
|
|
|
|
|
xctx->nl_polyx = xctx->nl_polyy = NULL;
|
|
|
|
|
xctx->nl_points = xctx->nl_maxpoints = 0;
|
|
|
|
|
/* select_rect */
|
|
|
|
|
xctx->nl_xr = xctx->nl_yr = xctx->nl_xr2 = xctx->nl_yr2 = 0.0;
|
|
|
|
|
xctx->nl_sel = xctx->nl_sem = 0;
|
|
|
|
|
|
2020-12-27 19:20:24 +01:00
|
|
|
xctx->hilight_time = 0; /* timestamp for sims */
|
2020-12-06 02:10:53 +01:00
|
|
|
xctx->hilight_nets = 0;
|
|
|
|
|
xctx->hilight_color = 0;
|
2021-01-02 01:55:01 +01:00
|
|
|
for(i=0;i<CADMAXHIER;i++) {
|
|
|
|
|
xctx->sch_path[i]=NULL;
|
|
|
|
|
xctx->sch_path_hash[i]=0;
|
|
|
|
|
}
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strdup(1187, &xctx->sch_path[0],".");
|
|
|
|
|
xctx->sch_inst_number[0] = 1;
|
|
|
|
|
xctx->maxt=CADMAXTEXT;
|
|
|
|
|
xctx->maxw=CADMAXWIRES;
|
|
|
|
|
xctx->maxi=ELEMINST;
|
|
|
|
|
xctx->maxs=ELEMDEF;
|
|
|
|
|
xctx->text=my_calloc(606, xctx->maxt,sizeof(xText));
|
|
|
|
|
xctx->wire=my_calloc(607, xctx->maxw,sizeof(xWire));
|
|
|
|
|
xctx->inst=my_calloc(609, xctx->maxi , sizeof(xInstance) );
|
|
|
|
|
xctx->sym=my_calloc(610, xctx->maxs , sizeof(xSymbol) );
|
|
|
|
|
for(i=0;i<xctx->maxs;i++) {
|
|
|
|
|
xctx->sym[i].line=my_calloc(611, cadlayers, sizeof(xLine *));
|
|
|
|
|
xctx->sym[i].poly=my_calloc(612, cadlayers, sizeof(xPoly *));
|
|
|
|
|
xctx->sym[i].arc=my_calloc(613, cadlayers, sizeof(xArc *));
|
|
|
|
|
xctx->sym[i].rect=my_calloc(614, cadlayers, sizeof(xRect *));
|
|
|
|
|
xctx->sym[i].lines=my_calloc(615, cadlayers, sizeof(int));
|
|
|
|
|
xctx->sym[i].rects=my_calloc(616, cadlayers, sizeof(int));
|
|
|
|
|
xctx->sym[i].arcs=my_calloc(617, cadlayers, sizeof(int));
|
|
|
|
|
xctx->sym[i].polygons=my_calloc(618, cadlayers, sizeof(int));
|
2020-10-04 12:51:34 +02:00
|
|
|
}
|
2020-10-15 17:39:21 +02:00
|
|
|
xctx->maxr=my_calloc(620, cadlayers, sizeof(int));
|
|
|
|
|
xctx->maxa=my_calloc(621, cadlayers, sizeof(int));
|
|
|
|
|
xctx->maxp=my_calloc(622, cadlayers, sizeof(int));
|
|
|
|
|
xctx->maxl=my_calloc(623, cadlayers, sizeof(int));
|
2020-10-04 12:51:34 +02:00
|
|
|
for(i=0;i<cadlayers;i++)
|
|
|
|
|
{
|
2020-12-06 22:07:33 +01:00
|
|
|
xctx->maxr[i]=CADMAXOBJECTS;
|
|
|
|
|
xctx->maxp[i]=CADMAXOBJECTS;
|
|
|
|
|
xctx->maxl[i]=CADMAXOBJECTS;
|
|
|
|
|
xctx->maxa[i]=CADMAXOBJECTS;
|
2020-10-04 12:51:34 +02:00
|
|
|
}
|
2020-10-15 17:39:21 +02:00
|
|
|
xctx->rect=my_calloc(624, cadlayers, sizeof(xRect *));
|
|
|
|
|
xctx->line=my_calloc(625, cadlayers, sizeof(xLine *));
|
|
|
|
|
xctx->poly=my_calloc(626, cadlayers, sizeof(xPoly *));
|
|
|
|
|
xctx->arc=my_calloc(627, cadlayers, sizeof(xArc *));
|
2020-10-04 12:51:34 +02:00
|
|
|
for(i=0;i<cadlayers;i++)
|
|
|
|
|
{
|
2020-12-06 22:07:33 +01:00
|
|
|
xctx->rect[i]=my_calloc(628, xctx->maxr[i],sizeof(xRect));
|
|
|
|
|
xctx->arc[i]=my_calloc(629, xctx->maxa[i],sizeof(xArc));
|
|
|
|
|
xctx->poly[i]=my_calloc(630, xctx->maxp[i],sizeof(xPoly));
|
|
|
|
|
xctx->line[i]=my_calloc(631, xctx->maxl[i],sizeof(xLine));
|
2020-10-04 12:51:34 +02:00
|
|
|
}
|
2020-10-15 17:39:21 +02:00
|
|
|
xctx->rects=my_calloc(632, cadlayers, sizeof(int));
|
|
|
|
|
xctx->polygons=my_calloc(633, cadlayers, sizeof(int));
|
|
|
|
|
xctx->arcs=my_calloc(634, cadlayers, sizeof(int));
|
|
|
|
|
xctx->lines=my_calloc(635, cadlayers, sizeof(int));
|
2020-12-03 04:20:05 +01:00
|
|
|
xctx->maxsel=MAXGROUP;
|
|
|
|
|
xctx->sel_array=my_calloc(619, xctx->maxsel, sizeof(Selected));
|
2020-12-12 20:50:06 +01:00
|
|
|
xctx->biggridpoint=(XSegment*)my_calloc(1213, CADMAXGRIDPOINTS,sizeof(XSegment));
|
2020-12-12 13:36:39 +01:00
|
|
|
xctx->gridpoint=(XPoint*)my_calloc(608, CADMAXGRIDPOINTS,sizeof(XPoint));
|
2021-10-25 17:05:43 +02:00
|
|
|
xctx->enable_drill = 0;
|
2021-11-18 01:55:01 +01:00
|
|
|
xctx->prev_set_modify = -1;
|
2021-10-25 17:05:43 +02:00
|
|
|
xctx->pending_fullzoom = 0;
|
|
|
|
|
my_strncpy(xctx->hiersep, ".", S(xctx->hiersep));
|
|
|
|
|
xctx->no_undo = 0;
|
2021-10-26 00:04:13 +02:00
|
|
|
xctx->draw_single_layer = -1;
|
|
|
|
|
xctx->draw_dots = 1;
|
2021-11-17 23:12:17 +01:00
|
|
|
xctx->only_probes = 0;
|
2021-11-18 01:55:01 +01:00
|
|
|
xctx->menu_removed = 0; /* fullscreen pervious setting */
|
|
|
|
|
xctx->save_lw = 0.0; /* used to save linewidth when selecting 'only_probes' view */
|
|
|
|
|
xctx->onetime = 0; /* callback() static var */
|
|
|
|
|
xctx->save_netlist_type = 0;
|
|
|
|
|
xctx->loaded_symbol = 0;
|
2021-10-26 00:04:13 +02:00
|
|
|
xctx->no_draw = 0;
|
2021-11-18 01:55:01 +01:00
|
|
|
xctx->sem = 0; /* bbox */
|
|
|
|
|
xctx->old_prop = NULL;
|
|
|
|
|
xctx->edit_sym_i = -1;
|
|
|
|
|
xctx->netlist_commands = 0;
|
2021-10-26 00:04:13 +02:00
|
|
|
xctx->draw_pixmap = 1;
|
2021-11-16 22:28:10 +01:00
|
|
|
xctx->gc=my_calloc(638, cadlayers, sizeof(GC));
|
|
|
|
|
xctx->gcstipple=my_calloc(639, cadlayers, sizeof(GC));
|
|
|
|
|
xctx->color_array=my_calloc(637, cadlayers, sizeof(char*));
|
|
|
|
|
xctx->enable_layer=my_calloc(87, cadlayers, sizeof(int));
|
|
|
|
|
xctx->n_active_layers = 0;
|
|
|
|
|
xctx->active_layer=my_calloc(563, cadlayers, sizeof(int));
|
|
|
|
|
xctx->hide_symbols = 0;
|
2021-11-17 01:12:55 +01:00
|
|
|
xctx->netlist_type = CAD_SPICE_NETLIST;
|
2021-11-16 22:28:10 +01:00
|
|
|
xctx->top_path = NULL;
|
2022-01-09 05:14:25 +01:00
|
|
|
xctx->current_win_path = NULL;
|
2021-11-16 22:28:10 +01:00
|
|
|
my_strdup2(1296, &xctx->top_path, top_path);
|
2022-01-09 05:14:25 +01:00
|
|
|
my_strdup2(1462, &xctx->current_win_path, win_path);
|
2021-11-16 22:28:10 +01:00
|
|
|
xctx->fill_type=my_calloc(640, cadlayers, sizeof(int));
|
2022-01-26 15:20:00 +01:00
|
|
|
xctx->case_insensitive = 0;
|
2022-02-01 18:31:23 +01:00
|
|
|
xctx->x_strcmp = strcmp;
|
2021-11-16 22:28:10 +01:00
|
|
|
xctx->fill_pattern = 1;
|
|
|
|
|
xctx->draw_window = 0;
|
2021-11-20 13:33:40 +01:00
|
|
|
xctx->time_last_modify = 0;
|
2020-10-04 19:53:09 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-19 14:31:55 +01:00
|
|
|
static void delete_schematic_data(void)
|
2020-10-04 12:51:34 +02:00
|
|
|
{
|
2021-11-16 22:28:10 +01:00
|
|
|
dbg(1, "delete_schematic_data()\n");
|
|
|
|
|
unselect_all();
|
2021-11-28 13:16:01 +01:00
|
|
|
/* clear static data in get_tok_value() must be done after unselect_all()
|
|
|
|
|
* as this functions re-uses get_tok_value() */
|
|
|
|
|
get_tok_value(NULL, NULL, 0); /* clear static data in function */
|
2021-12-01 00:35:52 +01:00
|
|
|
/* delete inst and wire node fields, delete inst_pin spatial hash, and node hash table */
|
|
|
|
|
delete_netlist_structs();
|
2021-11-16 22:28:10 +01:00
|
|
|
clear_all_hilights(); /* data structs for hilighting nets/instances */
|
|
|
|
|
get_unnamed_node(0, 0, 0); /* net### enumerator used for netlisting */
|
2022-01-20 01:57:53 +01:00
|
|
|
clear_drawing();
|
2021-11-16 22:28:10 +01:00
|
|
|
if(has_x) {
|
|
|
|
|
resetwin(0, 1, 1, 0, 0); /* delete preview pixmap, delete cairo surfaces */
|
|
|
|
|
free_gc();
|
|
|
|
|
}
|
2021-12-01 00:35:52 +01:00
|
|
|
/* delete instances, wires, lines, rects, arcs, polys, texts, hash_inst, hash_wire,
|
|
|
|
|
* inst & wire .node fields, instance name hash */
|
2021-11-16 22:28:10 +01:00
|
|
|
remove_symbols();
|
2021-12-29 05:11:39 +01:00
|
|
|
free_rawfile(0);
|
2021-11-16 22:28:10 +01:00
|
|
|
free_xschem_data(); /* delete the xctx struct */
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-19 14:31:55 +01:00
|
|
|
static void xwin_exit(void)
|
2020-10-04 19:53:09 +02:00
|
|
|
{
|
|
|
|
|
int i;
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-10-04 19:53:09 +02:00
|
|
|
if(!init_done) {
|
2020-12-06 02:10:53 +01:00
|
|
|
dbg(0, "xwin_exit() double call, doing nothing...\n");
|
2020-10-12 13:13:31 +02:00
|
|
|
return;
|
2020-10-04 19:53:09 +02:00
|
|
|
}
|
2021-12-01 00:35:52 +01:00
|
|
|
tcleval("catch { ngspice::resetdata }"); /* remove ngspice annotation data if any */
|
2021-11-16 22:28:10 +01:00
|
|
|
delete_schematic_data();
|
2020-10-04 19:53:09 +02:00
|
|
|
if(has_x) {
|
2021-11-16 22:28:10 +01:00
|
|
|
Tk_DestroyWindow(mainwindow);
|
|
|
|
|
#ifdef __unix__
|
|
|
|
|
if(cad_icon_pixmap) {
|
|
|
|
|
XFreePixmap(display, cad_icon_pixmap);
|
|
|
|
|
XFreePixmap(display, cad_icon_mask);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
if (cad_icon_pixmap) Tk_FreePixmap(display, cad_icon_pixmap);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef __unix__
|
|
|
|
|
for(i = 0; i < cadlayers; i++) XFreePixmap(display,pixmap[i]);
|
|
|
|
|
#else
|
|
|
|
|
for(i = 0; i < cadlayers; i++) Tk_FreePixmap(display, pixmap[i]);
|
|
|
|
|
#endif
|
|
|
|
|
my_free(1134, &pixmap);
|
2020-10-04 19:53:09 +02:00
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
dbg(1, "xwin_exit(): clearing drawing data structures\n");
|
2020-10-04 19:53:09 +02:00
|
|
|
|
|
|
|
|
/* global context - graphic preferences/settings */
|
|
|
|
|
for(i=0;i<cadlayers;i++) {
|
|
|
|
|
my_free(1102, &pixdata[i]);
|
|
|
|
|
}
|
|
|
|
|
my_free(1122, &pixdata);
|
2022-01-16 01:12:43 +01:00
|
|
|
my_free(1138, &cli_opt_tcl_command);
|
2020-10-04 19:53:09 +02:00
|
|
|
clear_expandlabel_data();
|
|
|
|
|
get_sym_template(NULL, NULL); /* clear static data in function */
|
|
|
|
|
list_tokens(NULL, 0); /* clear static data in function */
|
|
|
|
|
translate(0, NULL); /* clear static data in function */
|
|
|
|
|
translate2(NULL, 0, NULL); /* clear static data in function */
|
|
|
|
|
subst_token(NULL, NULL, NULL); /* clear static data in function */
|
2022-02-13 11:24:38 +01:00
|
|
|
find_nth(NULL, "", 0); /* clear static data in function */
|
2021-10-26 01:18:16 +02:00
|
|
|
tcl_hook2(NULL); /* clear static data in function */
|
2021-01-06 03:01:14 +01:00
|
|
|
save_ascii_string(NULL, NULL, 0); /* clear static data in function */
|
2020-10-04 19:53:09 +02:00
|
|
|
dbg(1, "xwin_exit(): removing font\n");
|
|
|
|
|
for(i=0;i<127;i++) my_free(1140, &character[i]);
|
|
|
|
|
dbg(1, "xwin_exit(): closed display\n");
|
2022-01-10 18:54:07 +01:00
|
|
|
my_strncpy(cli_opt_filename, "", S(cli_opt_filename));
|
2020-10-04 19:53:09 +02:00
|
|
|
my_free(1143, &xschem_executable);
|
|
|
|
|
record_global_node(2, NULL, NULL); /* delete global node array */
|
|
|
|
|
dbg(1, "xwin_exit(): deleted undo buffer\n");
|
2022-01-15 13:19:06 +01:00
|
|
|
/* delete cmdline stuff */
|
|
|
|
|
for(i = 0 ; i < cli_opt_argc; i++) {
|
|
|
|
|
my_free(1141, &cli_opt_argv[i]);
|
|
|
|
|
}
|
|
|
|
|
my_free(1464, &cli_opt_argv);
|
2022-01-15 23:35:37 +01:00
|
|
|
if(errfp!=stderr) fclose(errfp);
|
|
|
|
|
errfp=stderr;
|
2021-12-07 02:18:23 +01:00
|
|
|
if(!detach) printf("\n");
|
2020-10-04 19:53:09 +02:00
|
|
|
init_done=0; /* 20150409 to avoid multiple calls */
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
|
2020-11-19 15:08:40 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* color structures in xschem:
|
2021-11-16 22:28:10 +01:00
|
|
|
* - char *xctx->color_array[]:
|
2020-11-19 15:08:40 +01:00
|
|
|
* array of color character names ("#xxxxxx" hex) indexed by xschem layer number.
|
|
|
|
|
* these are set from tcl 'color' list variable in init_color_array()
|
2021-11-16 22:28:10 +01:00
|
|
|
* - unsigned int xctx->color_index[]:
|
2020-11-19 15:08:40 +01:00
|
|
|
* array of integers, pixel values, color lookup table, indexed by xschem layer num.
|
|
|
|
|
* this array is initialized in build_colors() by calling find_best_color()
|
|
|
|
|
* indexes are returned from XAllocNamedColor()
|
|
|
|
|
* these are used in XSetForeground and XSetBackground calls:
|
2021-11-16 22:28:10 +01:00
|
|
|
* XSetForeground(display, gc, xctx->color_index[i])
|
|
|
|
|
* - XColor xctx->xcolor_array[]:
|
2020-11-19 15:08:40 +01:00
|
|
|
* array of 256 XColor structures:
|
|
|
|
|
* typedef struct {
|
|
|
|
|
* unsigned long pixel; // pixel value
|
|
|
|
|
* unsigned short red, green, blue; // rgb values
|
|
|
|
|
* char flags; // DoRed, DoGreen, DoBlue
|
|
|
|
|
* char pad;
|
|
|
|
|
* } XColor;
|
|
|
|
|
* This array is used temporarily in find_best_color() to store all
|
|
|
|
|
* allocated colors in case of pseudocolor visuals to find best substitute when
|
|
|
|
|
* XAllocNamedColor fails to find the requested "color_array[i]".
|
2021-11-16 22:28:10 +01:00
|
|
|
* When all xctx->color_index[] are populated with pixel values xctx->xcolor_array[]
|
2020-11-19 15:08:40 +01:00
|
|
|
* is reset with the xschem layer colors in build_colors() using XLookupColor():
|
|
|
|
|
* for(i=0;i<cadlayers;i++) {
|
2021-11-16 22:28:10 +01:00
|
|
|
* XLookupColor(display, colormap, xctx->color_array[i], &xcolor_exact, &xcolor);
|
|
|
|
|
* xctx->xcolor_array[i] = xcolor;
|
2020-11-19 15:08:40 +01:00
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
2021-11-16 22:28:10 +01:00
|
|
|
int build_colors(double dim, double dim_bg)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
int i;
|
2021-11-16 22:28:10 +01:00
|
|
|
dbg(1, "build_colors(): dim=%g, dim_bg=%g\n", dim, dim_bg);
|
2021-11-10 13:43:08 +01:00
|
|
|
if(tclgetboolvar("dark_colorscheme")) {
|
2020-08-08 15:47:34 +02:00
|
|
|
tcleval("llength $dark_colors");
|
2020-08-16 03:34:45 +02:00
|
|
|
if(atoi(tclresult())>=cadlayers){
|
2020-08-08 15:47:34 +02:00
|
|
|
tcleval("set colors $dark_colors");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
tcleval("llength $light_colors");
|
2020-08-16 03:34:45 +02:00
|
|
|
if(atoi(tclresult()) >=cadlayers){
|
2020-08-08 15:47:34 +02:00
|
|
|
tcleval("set colors $light_colors");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
tcleval("llength $colors");
|
2020-08-16 03:34:45 +02:00
|
|
|
if(atoi(tclresult())<cadlayers){
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(errfp,"Tcl var colors not set correctly\n");
|
|
|
|
|
return -1; /* fail */
|
2020-08-31 23:11:20 +02:00
|
|
|
} else {
|
|
|
|
|
tcleval("regsub -all {\"} $colors {} svg_colors");
|
|
|
|
|
tcleval("regsub -all {#} $svg_colors {0x} svg_colors");
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2021-11-16 22:28:10 +01:00
|
|
|
init_color_array(dim, dim_bg);
|
2020-08-08 15:47:34 +02:00
|
|
|
for(i=0;i<cadlayers;i++)
|
|
|
|
|
{
|
2021-11-16 22:28:10 +01:00
|
|
|
xctx->color_index[i] = find_best_color(xctx->color_array[i]);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
for(i=0;i<cadlayers;i++)
|
|
|
|
|
{
|
2021-11-16 22:28:10 +01:00
|
|
|
XSetBackground(display, xctx->gc[i], xctx->color_index[0]); /* for dashed lines 'off' color */
|
|
|
|
|
XSetForeground(display, xctx->gc[i], xctx->color_index[i]);
|
|
|
|
|
XSetForeground(display, xctx->gcstipple[i], xctx->color_index[i]);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
for(i=0;i<cadlayers;i++) {
|
2022-02-18 15:11:44 +01:00
|
|
|
#ifdef __unix__
|
2021-11-16 22:28:10 +01:00
|
|
|
XLookupColor(display, colormap, xctx->color_array[i], &xcolor_exact, &xcolor);
|
|
|
|
|
xctx->xcolor_array[i] = xcolor;
|
2022-02-18 15:11:44 +01:00
|
|
|
#else
|
|
|
|
|
Tk_Window mainwindow = Tk_MainWindow(interp);
|
|
|
|
|
XColor *xc = Tk_GetColor(interp, mainwindow, xctx->color_array[i]);
|
|
|
|
|
xctx->xcolor_array[i] = *xc;
|
|
|
|
|
#endif
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
tcleval("reconfigure_layers_menu");
|
|
|
|
|
return 0; /* success */
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-24 01:07:33 +01:00
|
|
|
void set_clip_mask(int what)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
if(what == SET) {
|
|
|
|
|
for(i=0;i<cadlayers;i++)
|
|
|
|
|
{
|
|
|
|
|
XSetClipRectangles(display, xctx->gc[i], 0,0, xctx->xrect, 1, Unsorted);
|
|
|
|
|
XSetClipRectangles(display, xctx->gcstipple[i], 0,0, xctx->xrect, 1, Unsorted);
|
|
|
|
|
}
|
|
|
|
|
XSetClipRectangles(display, xctx->gctiled, 0,0, xctx->xrect, 1, Unsorted);
|
|
|
|
|
#if HAS_CAIRO==1
|
|
|
|
|
cairo_rectangle(xctx->cairo_ctx, xctx->xrect[0].x, xctx->xrect[0].y,
|
|
|
|
|
xctx->xrect[0].width, xctx->xrect[0].height);
|
|
|
|
|
cairo_clip(xctx->cairo_ctx);
|
|
|
|
|
cairo_rectangle(xctx->cairo_save_ctx, xctx->xrect[0].x, xctx->xrect[0].y,
|
|
|
|
|
xctx->xrect[0].width, xctx->xrect[0].height);
|
|
|
|
|
cairo_clip(xctx->cairo_save_ctx);
|
|
|
|
|
#endif
|
|
|
|
|
} else if(what == END) {
|
|
|
|
|
for(i=0;i<cadlayers;i++)
|
|
|
|
|
{
|
|
|
|
|
XSetClipMask(display, xctx->gc[i], None);
|
|
|
|
|
XSetClipMask(display, xctx->gcstipple[i], None);
|
|
|
|
|
}
|
|
|
|
|
XSetClipMask(display, xctx->gctiled, None);
|
|
|
|
|
#if HAS_CAIRO==1
|
|
|
|
|
cairo_reset_clip(xctx->cairo_ctx);
|
|
|
|
|
cairo_reset_clip(xctx->cairo_save_ctx);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-26 13:16:52 +01:00
|
|
|
#ifdef __unix__
|
2021-11-24 01:07:33 +01:00
|
|
|
/* moved here to avoid Xorg-specific calls in move.c */
|
|
|
|
|
int pending_events(void)
|
|
|
|
|
{
|
|
|
|
|
return XPending(display);
|
|
|
|
|
}
|
2021-11-26 13:16:52 +01:00
|
|
|
#endif
|
2021-11-24 01:07:33 +01:00
|
|
|
|
|
|
|
|
void toggle_fullscreen(const char *topwin)
|
|
|
|
|
{
|
|
|
|
|
char fullscr[]="add,fullscreen";
|
|
|
|
|
char normal[]="remove,fullscreen";
|
|
|
|
|
unsigned int topwin_id;
|
|
|
|
|
Window rootwindow, parent_id;
|
|
|
|
|
Window *framewin_child_ptr;
|
|
|
|
|
unsigned int framewindow_nchildren;
|
|
|
|
|
int fs;
|
|
|
|
|
|
|
|
|
|
if(!strcmp(topwin, ".drw")) {
|
|
|
|
|
tcleval( "winfo id .");
|
|
|
|
|
sscanf(tclresult(), "0x%x", (unsigned int *) &topwin_id);
|
|
|
|
|
} else {
|
2021-12-05 12:39:05 +01:00
|
|
|
tclvareval("winfo id ", xctx->top_path, NULL);
|
2021-11-24 01:07:33 +01:00
|
|
|
sscanf(tclresult(), "0x%x", (unsigned int *) &topwin_id);
|
|
|
|
|
}
|
|
|
|
|
XQueryTree(display, topwin_id, &rootwindow, &parent_id, &framewin_child_ptr, &framewindow_nchildren);
|
|
|
|
|
fs = tclgetintvar("fullscreen");
|
2022-01-31 02:42:52 +01:00
|
|
|
fs = (fs+1)%3;
|
2021-11-24 01:07:33 +01:00
|
|
|
if(fs==1) tclsetvar("fullscreen","1");
|
|
|
|
|
else if(fs==2) tclsetvar("fullscreen","2");
|
|
|
|
|
else tclsetvar("fullscreen","0");
|
|
|
|
|
|
|
|
|
|
dbg(1, "toggle_fullscreen(): fullscreen=%d\n", fs);
|
|
|
|
|
if(fs==2) {
|
2022-01-31 02:42:52 +01:00
|
|
|
if(tclgetboolvar("toolbar_visible")) {
|
|
|
|
|
xctx->menu_removed |= 2;
|
|
|
|
|
tclvareval("toolbar_hide ", xctx->top_path, NULL);
|
|
|
|
|
}
|
|
|
|
|
tclvareval("pack forget ", xctx->top_path, ".tabs", NULL);
|
|
|
|
|
tclvareval("pack forget ", xctx->top_path, ".menubar ",
|
|
|
|
|
xctx->top_path, ".statusbar; update", NULL);
|
|
|
|
|
xctx->menu_removed |= 1;
|
2021-11-24 01:07:33 +01:00
|
|
|
}
|
2022-01-31 02:42:52 +01:00
|
|
|
if(fs !=2 && xctx->menu_removed ) {
|
|
|
|
|
if(tclgetboolvar("tabbed_interface")) {
|
|
|
|
|
tclvareval("pack ", xctx->top_path,
|
|
|
|
|
".tabs -fill x -side top -expand false -side top -before ",
|
|
|
|
|
xctx->top_path, ".drw", NULL);
|
|
|
|
|
tclvareval("pack ", xctx->top_path,
|
|
|
|
|
".menubar -anchor n -side top -fill x -before ", xctx->top_path, ".tabs; pack ",
|
|
|
|
|
xctx->top_path, ".statusbar -after ", xctx->top_path,
|
|
|
|
|
".drw -anchor sw -fill x; update", NULL);
|
|
|
|
|
} else {
|
|
|
|
|
tclvareval("pack ", xctx->top_path,
|
|
|
|
|
".menubar -anchor n -side top -fill x -before ", xctx->top_path, ".drw; pack ",
|
|
|
|
|
xctx->top_path, ".statusbar -after ", xctx->top_path,
|
|
|
|
|
".drw -anchor sw -fill x; update", NULL);
|
|
|
|
|
}
|
|
|
|
|
if(xctx->menu_removed & 2) tclvareval("toolbar_show ", xctx->top_path, NULL);
|
2021-11-24 01:07:33 +01:00
|
|
|
xctx->menu_removed=0;
|
|
|
|
|
}
|
|
|
|
|
if(fs == 1) {
|
|
|
|
|
window_state(display , parent_id,fullscr);
|
|
|
|
|
} else if(fs == 2) {
|
|
|
|
|
window_state(display , parent_id,normal);
|
|
|
|
|
window_state(display , parent_id,fullscr);
|
|
|
|
|
} else {
|
|
|
|
|
window_state(display , parent_id,normal);
|
|
|
|
|
}
|
|
|
|
|
xctx->pending_fullzoom=1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
|
2022-02-19 14:31:55 +01:00
|
|
|
static void tclexit(ClientData s)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
dbg(1, "tclexit() INVOKED\n");
|
|
|
|
|
if(init_done) xwin_exit();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-19 14:31:55 +01:00
|
|
|
static int source_tcl_file(char *s)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
char tmp[1024];
|
2020-10-12 13:13:31 +02:00
|
|
|
if(Tcl_EvalFile(interp, s)==TCL_ERROR) {
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(errfp, "Tcl_AppInit() error: can not execute %s, please fix:\n", s);
|
2020-08-16 03:34:45 +02:00
|
|
|
fprintf(errfp, "%s", tclresult());
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(errfp, "\n");
|
|
|
|
|
my_snprintf(tmp, S(tmp), "tk_messageBox -icon error -type ok -message \
|
|
|
|
|
{Tcl_AppInit() err 1: can not execute %s, please fix:\n %s}",
|
2020-08-16 03:34:45 +02:00
|
|
|
s, tclresult());
|
2020-08-08 15:47:34 +02:00
|
|
|
if(has_x) {
|
2020-10-12 13:13:31 +02:00
|
|
|
tcleval( "wm withdraw .");
|
|
|
|
|
tcleval( tmp);
|
2020-08-08 15:47:34 +02:00
|
|
|
Tcl_Exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
return TCL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
return TCL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-10 18:54:07 +01:00
|
|
|
void preview_window(const char *what, const char *win_path, const char *fname)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-12-03 18:21:23 +01:00
|
|
|
static char *current_file = NULL;
|
|
|
|
|
static Xschem_ctx *save_xctx = NULL; /* save pointer to current schematic context structure */
|
|
|
|
|
static Xschem_ctx *preview_xctx = NULL; /* save pointer to current schematic context structure */
|
2020-12-03 23:17:13 +01:00
|
|
|
static Window pre_window;
|
|
|
|
|
static Tk_Window tkpre_window;
|
2020-12-03 18:21:23 +01:00
|
|
|
|
|
|
|
|
dbg(1, "------\n");
|
2020-08-08 15:47:34 +02:00
|
|
|
if(!strcmp(what, "create")) {
|
2022-01-09 05:14:25 +01:00
|
|
|
dbg(1, "preview_window() create, save ctx, win_path=%s\n", win_path);
|
|
|
|
|
tkpre_window = Tk_NameToWindow(interp, win_path, mainwindow);
|
2020-08-08 15:47:34 +02:00
|
|
|
Tk_MakeWindowExist(tkpre_window);
|
|
|
|
|
pre_window = Tk_WindowId(tkpre_window);
|
2020-12-03 18:21:23 +01:00
|
|
|
save_xctx = xctx; /* save current schematic */
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
else if(!strcmp(what, "draw")) {
|
2020-12-03 18:21:23 +01:00
|
|
|
dbg(1, "preview_window() draw\n");
|
|
|
|
|
xctx = preview_xctx;
|
2022-01-10 18:54:07 +01:00
|
|
|
if(!current_file || strcmp(fname, current_file) ) {
|
2020-12-03 18:21:23 +01:00
|
|
|
if(current_file) {
|
2020-12-06 02:10:53 +01:00
|
|
|
delete_schematic_data();
|
2020-12-03 18:21:23 +01:00
|
|
|
}
|
2022-01-10 18:54:07 +01:00
|
|
|
my_strdup(117, ¤t_file, fname);
|
2020-12-03 18:21:23 +01:00
|
|
|
xctx = NULL; /* reset for preview */
|
2022-01-09 05:14:25 +01:00
|
|
|
alloc_xschem_data(".dialog", ".dialog.drw"); /* alloc data into xctx */
|
2021-11-16 22:28:10 +01:00
|
|
|
init_pixdata(); /* populate xctx->fill_type array that is used in create_gc() to set fill styles */
|
2020-12-03 18:21:23 +01:00
|
|
|
preview_xctx = xctx;
|
|
|
|
|
preview_xctx->window = pre_window;
|
2021-11-16 22:28:10 +01:00
|
|
|
create_gc();
|
|
|
|
|
enable_layers();
|
|
|
|
|
build_colors(0.0, 0.0);
|
2020-12-22 00:13:25 +01:00
|
|
|
resetwin(1, 0, 1, 0, 0); /* create preview pixmap. resetwin(create_pixmap, clear_pixmap, force) */
|
2020-12-06 02:10:53 +01:00
|
|
|
dbg(1, "preview_window() draw, load schematic\n");
|
2022-01-10 18:54:07 +01:00
|
|
|
load_schematic(1,fname, 0);
|
2020-12-03 18:21:23 +01:00
|
|
|
}
|
2020-12-22 00:13:25 +01:00
|
|
|
zoom_full(1, 0, 1, 0.97); /* draw */
|
2020-12-03 18:21:23 +01:00
|
|
|
xctx = save_xctx;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
else if(!strcmp(what, "destroy")) {
|
2020-12-03 18:21:23 +01:00
|
|
|
dbg(1, "preview_window() destroy\n");
|
|
|
|
|
xctx = preview_xctx;
|
|
|
|
|
if(current_file) {
|
2020-12-06 02:10:53 +01:00
|
|
|
delete_schematic_data();
|
2020-12-03 18:21:23 +01:00
|
|
|
preview_xctx = NULL;
|
|
|
|
|
}
|
2020-12-06 02:10:53 +01:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
Tk_DestroyWindow(tkpre_window);
|
2020-12-03 18:21:23 +01:00
|
|
|
my_free(1144, ¤t_file);
|
|
|
|
|
xctx = save_xctx; /* restore schematic */
|
|
|
|
|
save_xctx = NULL;
|
2022-01-10 03:07:57 +01:00
|
|
|
set_modify(-1);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-10 18:54:07 +01:00
|
|
|
/* check if filename is already loaded into a tab or window */
|
|
|
|
|
/* caller should supply a win_path string for storing matching window path */
|
|
|
|
|
int check_loaded(const char *f, char *win_path)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
Xschem_ctx *ctx;
|
|
|
|
|
int found = 0;
|
|
|
|
|
for(i = 0; i < MAX_NEW_WINDOWS; i++) {
|
|
|
|
|
ctx = save_xctx[i];
|
2022-01-29 02:36:54 +01:00
|
|
|
dbg(1, "window_count=%d i=%d\n", window_count, i);
|
2022-01-11 01:09:56 +01:00
|
|
|
/* if only one schematic it is not yet saved in save_xctx */
|
|
|
|
|
if(window_count == 0 && i == 0) ctx = xctx;
|
2022-01-10 18:54:07 +01:00
|
|
|
if(ctx) {
|
2022-01-29 02:36:54 +01:00
|
|
|
dbg(1, "%s <--> %s\n", ctx->sch[ctx->currsch], f);
|
2022-01-10 18:54:07 +01:00
|
|
|
if(!strcmp(ctx->sch[ctx->currsch], f)) {
|
2022-01-11 01:09:56 +01:00
|
|
|
dbg(1, "check_loaded(): f=%s, sch=%s\n", f, ctx->sch[ctx->currsch]);
|
2022-01-10 18:54:07 +01:00
|
|
|
found = 1;
|
|
|
|
|
my_strncpy(win_path, window_path[i], S(window_path[i]));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-29 02:36:54 +01:00
|
|
|
dbg(1, "check_loaded: return %d\n", found);
|
2022-01-10 18:54:07 +01:00
|
|
|
return found;
|
|
|
|
|
}
|
2021-11-16 22:28:10 +01:00
|
|
|
|
2022-01-11 01:09:56 +01:00
|
|
|
/* caller (via new_schematic() ) should take care of switching tcl context
|
|
|
|
|
* before calling this function, see callback()
|
|
|
|
|
*
|
|
|
|
|
* tclvareval("save_ctx ", old_winpath, NULL);
|
|
|
|
|
* tclvareval("restore_ctx ", winpath, NULL);
|
|
|
|
|
* tclvareval("housekeeping_ctx", NULL);
|
|
|
|
|
*/
|
2022-01-10 18:54:07 +01:00
|
|
|
static void switch_window(int *window_count, const char *win_path)
|
2020-12-03 23:17:13 +01:00
|
|
|
{
|
2021-11-02 02:23:45 +01:00
|
|
|
int i, n;
|
|
|
|
|
Tk_Window tkwin;
|
2022-01-16 00:51:12 +01:00
|
|
|
if(!strcmp(win_path, xctx->current_win_path)) return; /* already there */
|
2022-01-10 18:54:07 +01:00
|
|
|
if(*window_count) {
|
2022-01-11 01:09:56 +01:00
|
|
|
dbg(1, "new_schematic(\"switch_win\"...): %s\n", win_path);
|
2022-01-10 18:54:07 +01:00
|
|
|
tkwin = Tk_NameToWindow(interp, win_path, mainwindow); /* NULL if win_path not existing */
|
2022-01-11 01:09:56 +01:00
|
|
|
if(!tkwin) dbg(0, "new_schematic(\"switch_win\",...): Warning: %s has been destroyed\n", win_path);
|
2022-01-10 18:54:07 +01:00
|
|
|
n = -1;
|
|
|
|
|
if(tkwin) for(i = 0; i < MAX_NEW_WINDOWS; i++) {
|
|
|
|
|
if(!strcmp(win_path, window_path[i])) {
|
|
|
|
|
n = i;
|
|
|
|
|
break;
|
2021-11-02 02:23:45 +01:00
|
|
|
}
|
2022-01-10 18:54:07 +01:00
|
|
|
}
|
|
|
|
|
if(n == -1) {
|
2022-01-11 01:09:56 +01:00
|
|
|
dbg(0, "new_schematic(\"switch_win\"...): no window to switch to found: %s\n", win_path);
|
2022-01-10 18:54:07 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* if window was closed then tkwin == 0 --> do nothing */
|
|
|
|
|
if(tkwin && n >= 0 && n < MAX_NEW_WINDOWS) {
|
|
|
|
|
xctx = save_xctx[n];
|
|
|
|
|
set_modify(-1); /* sets window title */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void switch_tab(int *window_count, const char *win_path)
|
|
|
|
|
{
|
|
|
|
|
int i, n;
|
2022-01-16 00:51:12 +01:00
|
|
|
|
|
|
|
|
if(!strcmp(win_path, xctx->current_win_path)) return; /* already there */
|
2022-01-10 18:54:07 +01:00
|
|
|
if(*window_count) {
|
|
|
|
|
dbg(1, "new_schematic() switch_tab: %s\n", win_path);
|
|
|
|
|
n = -1;
|
|
|
|
|
for(i = 0; i < MAX_NEW_WINDOWS; i++) {
|
|
|
|
|
if(!strcmp(win_path, window_path[i])) {
|
|
|
|
|
n = i;
|
|
|
|
|
break;
|
2021-11-02 02:23:45 +01:00
|
|
|
}
|
2022-01-10 18:54:07 +01:00
|
|
|
}
|
|
|
|
|
if(n == -1) {
|
|
|
|
|
dbg(0, "new_schematic(\"switch_tab\"...): no tab to switch to found: %s\n", win_path);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-01-13 00:58:00 +01:00
|
|
|
/* if no matching tab found --> do nothing */
|
2022-01-10 18:54:07 +01:00
|
|
|
if(n >= 0 && n < MAX_NEW_WINDOWS) {
|
|
|
|
|
tclvareval("save_ctx ", xctx->current_win_path, NULL);
|
|
|
|
|
xctx = save_xctx[n];
|
|
|
|
|
tclvareval("restore_ctx ", win_path, NULL);
|
|
|
|
|
tclvareval("housekeeping_ctx", NULL);
|
|
|
|
|
tclvareval("reconfigure_layers_button {}", NULL);
|
|
|
|
|
xctx->window = save_xctx[0]->window;
|
|
|
|
|
resetwin(1, 1, 1, 0, 0);
|
|
|
|
|
set_modify(-1); /* sets window title */
|
|
|
|
|
draw();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void create_new_window(int *window_count, const char *fname)
|
|
|
|
|
{
|
|
|
|
|
Window win_id;
|
|
|
|
|
char toppath[WINDOW_PATH_SIZE];
|
|
|
|
|
int i, n;
|
|
|
|
|
|
2022-01-29 02:36:54 +01:00
|
|
|
dbg(1, "new_schematic() create: fname=%s *window_count = %d\n", fname, *window_count);
|
|
|
|
|
|
|
|
|
|
if(/* *window_count && */ fname && fname[0] && check_loaded(fname, toppath)) {
|
2022-01-10 18:54:07 +01:00
|
|
|
char msg[PATH_MAX+100];
|
2022-01-29 02:36:54 +01:00
|
|
|
my_snprintf(msg, S(msg),
|
|
|
|
|
"tk_messageBox -type okcancel -icon warning -parent [xschem get topwindow] "
|
|
|
|
|
"-message {Warning: %s already open.}", fname);
|
|
|
|
|
if(has_x) {
|
2022-01-10 18:54:07 +01:00
|
|
|
tcleval(msg);
|
2022-01-29 02:36:54 +01:00
|
|
|
if(strcmp(tclresult(), "ok")) return;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-01-10 18:54:07 +01:00
|
|
|
dbg(0, "create_new_window: %s already open: %s\n", fname, toppath);
|
2022-01-29 02:36:54 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2022-01-10 18:54:07 +01:00
|
|
|
}
|
|
|
|
|
if(*window_count == 0) {
|
|
|
|
|
for(i = 0; i < MAX_NEW_WINDOWS; i++) {
|
|
|
|
|
save_xctx[i] = NULL;
|
|
|
|
|
my_strncpy(window_path[i], "", S(window_path[i]));
|
|
|
|
|
}
|
|
|
|
|
tclvareval("save_ctx ", xctx->current_win_path, NULL);
|
|
|
|
|
save_xctx[0] = xctx; /* save current schematic */
|
|
|
|
|
/* window_path[0] = Tk_NameToWindow(interp, ".drw", mainwindow); */
|
|
|
|
|
my_strncpy(window_path[0], xctx->current_win_path, S(window_path[0]));
|
|
|
|
|
}
|
|
|
|
|
if(*window_count + 1 >= MAX_NEW_WINDOWS) {
|
|
|
|
|
dbg(0, "new_schematic(\"create\"...): no more free slots\n");
|
|
|
|
|
return; /* no more free slots */
|
|
|
|
|
}
|
|
|
|
|
(*window_count)++;
|
|
|
|
|
tcleval(".menubar.view.menu entryconfigure 21 -state disabled");
|
|
|
|
|
n = -1;
|
|
|
|
|
for(i = 1; i < MAX_NEW_WINDOWS; i++) { /* search 1st free slot */
|
|
|
|
|
if(save_xctx[i] == NULL) {
|
|
|
|
|
n = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(n == -1) {
|
|
|
|
|
dbg(0, "new_schematic(\"create\"...): no more free slots\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
my_snprintf(window_path[n], S(window_path[n]), ".x%d.drw", n);
|
|
|
|
|
my_snprintf(toppath, S(toppath), ".x%d", n);
|
|
|
|
|
tclvareval("toplevel ", toppath, " -bg {} -width 400 -height 400", NULL);
|
|
|
|
|
tclvareval("build_widgets ", toppath, NULL);
|
|
|
|
|
tclvareval("pack_widgets ", toppath, " ; update", NULL);
|
|
|
|
|
Tk_MakeWindowExist(Tk_NameToWindow(interp, window_path[n], mainwindow));
|
|
|
|
|
win_id = Tk_WindowId(Tk_NameToWindow(interp, window_path[n], mainwindow));
|
|
|
|
|
Tk_ChangeWindowAttributes(Tk_NameToWindow(interp, window_path[n], mainwindow), CWBackingStore, &winattr);
|
|
|
|
|
xctx = NULL;
|
|
|
|
|
alloc_xschem_data(toppath, window_path[n]); /* alloc data into xctx */
|
|
|
|
|
xctx->netlist_type = CAD_SPICE_NETLIST; /* for new windows start with spice netlist mode */
|
|
|
|
|
tclsetvar("netlist_type","spice");
|
|
|
|
|
init_pixdata();/* populate xctx->fill_type array that is used in create_gc() to set fill styles */
|
|
|
|
|
save_xctx[n] = xctx;
|
|
|
|
|
dbg(1, "new_schematic() draw, load schematic\n");
|
|
|
|
|
xctx->window = win_id;
|
|
|
|
|
set_snap(0); /* set default value specified in xschemrc as 'snap' else CADSNAP */
|
|
|
|
|
set_grid(0); /* set default value specified in xschemrc as 'grid' else CADGRID */
|
|
|
|
|
create_gc();
|
|
|
|
|
enable_layers();
|
|
|
|
|
build_colors(0.0, 0.0);
|
|
|
|
|
resetwin(1, 0, 1, 0, 0); /* create preview pixmap. resetwin(create_pixmap, clear_pixmap, force, w, h) */
|
|
|
|
|
/* draw empty window so if following load fails due to missing file window appears correctly drawn */
|
|
|
|
|
zoom_full(1, 0, 1, 0.97);
|
|
|
|
|
load_schematic(1, fname, 1);
|
|
|
|
|
zoom_full(1, 0, 1, 0.97); /* draw */
|
|
|
|
|
tclvareval("set_bindings ", window_path[n], NULL);
|
|
|
|
|
tclvareval("save_ctx ", window_path[n], NULL);
|
|
|
|
|
windowid(toppath);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-11 01:09:56 +01:00
|
|
|
static void create_new_tab(int *window_count, const char *fname)
|
2022-01-10 18:54:07 +01:00
|
|
|
{
|
|
|
|
|
int i, n;
|
|
|
|
|
char open_path[WINDOW_PATH_SIZE];
|
2022-01-11 01:09:56 +01:00
|
|
|
char nn[WINDOW_PATH_SIZE];
|
|
|
|
|
char win_path[WINDOW_PATH_SIZE];
|
2022-01-10 18:54:07 +01:00
|
|
|
|
|
|
|
|
dbg(1, "new_schematic() new_tab, creating...\n");
|
2022-01-29 02:36:54 +01:00
|
|
|
if(/* *window_count && */ fname && fname[0] && check_loaded(fname, open_path)) {
|
2022-01-10 18:54:07 +01:00
|
|
|
char msg[PATH_MAX+100];
|
2022-01-29 02:36:54 +01:00
|
|
|
my_snprintf(msg, S(msg),
|
|
|
|
|
"tk_messageBox -type okcancel -icon warning -parent [xschem get topwindow] "
|
|
|
|
|
"-message {Warning: %s already open.}", fname);
|
|
|
|
|
if(has_x) {
|
2022-01-10 18:54:07 +01:00
|
|
|
tcleval(msg);
|
2022-01-29 02:36:54 +01:00
|
|
|
if(strcmp(tclresult(), "ok")) {
|
|
|
|
|
switch_tab(window_count, open_path);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-01-10 18:54:07 +01:00
|
|
|
dbg(0, "create_new_tab: %s already open: %s\n", fname, open_path);
|
2022-01-29 02:36:54 +01:00
|
|
|
switch_tab(window_count, open_path);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-01-10 18:54:07 +01:00
|
|
|
}
|
|
|
|
|
if(*window_count == 0) {
|
|
|
|
|
for(i = 0; i < MAX_NEW_WINDOWS; i++) {
|
|
|
|
|
save_xctx[i] = NULL;
|
|
|
|
|
my_strncpy(window_path[i], "", S(window_path[i]));
|
|
|
|
|
}
|
|
|
|
|
tclvareval("save_ctx ", xctx->current_win_path, NULL);
|
|
|
|
|
save_xctx[0] = xctx; /* save current schematic */
|
|
|
|
|
my_strncpy(window_path[0], xctx->current_win_path, S(window_path[0]));
|
|
|
|
|
}
|
|
|
|
|
if(*window_count + 1 >= MAX_NEW_WINDOWS) {
|
|
|
|
|
dbg(0, "new_schematic(\"new_tab\"...): no more free slots\n");
|
|
|
|
|
return; /* no more free slots */
|
|
|
|
|
}
|
|
|
|
|
(*window_count)++;
|
|
|
|
|
tcleval(".menubar.view.menu entryconfigure 21 -state disabled");
|
|
|
|
|
n = -1;
|
|
|
|
|
for(i = 1; i < MAX_NEW_WINDOWS; i++) { /* search 1st free slot */
|
|
|
|
|
if(save_xctx[i] == NULL) {
|
|
|
|
|
n = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(n == -1) {
|
|
|
|
|
dbg(0, "new_schematic(\"newtab\"...): no more free slots\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-01-11 01:09:56 +01:00
|
|
|
/* tcl code to create the tab button */
|
|
|
|
|
my_snprintf(nn, S(nn), "%d", n);
|
|
|
|
|
tclvareval(
|
2022-01-13 15:40:20 +01:00
|
|
|
"button ", ".tabs.x", nn, " -padx 2 -pady 0 -anchor nw -text Tab2 "
|
2022-01-11 01:09:56 +01:00
|
|
|
"-command \"xschem new_schematic switch_tab .x", nn, ".drw\"", NULL);
|
2022-01-12 23:44:52 +01:00
|
|
|
tclvareval("bind .tabs.x",nn," <ButtonPress> {swap_tabs %X %Y press}", NULL);
|
|
|
|
|
tclvareval("bind .tabs.x",nn," <ButtonRelease> {swap_tabs %X %Y release}", NULL);
|
2022-01-11 01:09:56 +01:00
|
|
|
tclvareval(
|
|
|
|
|
"if {![info exists tctx::tab_bg] } {set tctx::tab_bg [",
|
2022-01-12 23:44:52 +01:00
|
|
|
".tabs.x", nn, " cget -bg]}", NULL);
|
|
|
|
|
tclvareval("pack ", ".tabs.x", nn,
|
|
|
|
|
" -before ", ".tabs.add -side left", NULL);
|
2022-01-11 01:09:56 +01:00
|
|
|
/* */
|
|
|
|
|
|
2022-01-12 23:44:52 +01:00
|
|
|
my_snprintf(win_path, S(win_path), ".x%d.drw", n);
|
2022-01-10 18:54:07 +01:00
|
|
|
my_strncpy(window_path[n], win_path, S(window_path[n]));
|
|
|
|
|
xctx = NULL;
|
|
|
|
|
alloc_xschem_data("", win_path); /* alloc data into xctx */
|
|
|
|
|
xctx->netlist_type = CAD_SPICE_NETLIST; /* for new windows start with spice netlist mode */
|
|
|
|
|
tclsetvar("netlist_type","spice");
|
|
|
|
|
init_pixdata();/* populate xctx->fill_type array that is used in create_gc() to set fill styles */
|
|
|
|
|
save_xctx[n] = xctx;
|
|
|
|
|
dbg(1, "new_schematic() draw, load schematic\n");
|
|
|
|
|
xctx->window = save_xctx[0]->window;
|
|
|
|
|
set_snap(0); /* set default value specified in xschemrc as 'snap' else CADSNAP */
|
|
|
|
|
set_grid(0); /* set default value specified in xschemrc as 'grid' else CADGRID */
|
|
|
|
|
create_gc();
|
|
|
|
|
enable_layers();
|
|
|
|
|
build_colors(0.0, 0.0);
|
|
|
|
|
resetwin(1, 0, 1, 0, 0); /* create pixmap. resetwin(create_pixmap, clear_pixmap, force, w, h) */
|
|
|
|
|
/* draw empty window so if following load fails due to missing file window appears correctly drawn */
|
|
|
|
|
zoom_full(1, 0, 1, 0.97);
|
|
|
|
|
load_schematic(1,fname, 1);
|
|
|
|
|
zoom_full(1, 0, 1, 0.97); /* draw */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void destroy_window(int *window_count, const char *win_path)
|
|
|
|
|
{
|
|
|
|
|
int i, n;
|
|
|
|
|
Xschem_ctx *savectx;
|
|
|
|
|
Tk_Window tkwin;
|
|
|
|
|
savectx = xctx;
|
|
|
|
|
if(*window_count) {
|
|
|
|
|
int close = 0;
|
2022-01-15 13:19:06 +01:00
|
|
|
dbg(1, "new_schematic() destroy {%s}\n", win_path);
|
2022-01-10 18:54:07 +01:00
|
|
|
if(xctx->modified && has_x) {
|
|
|
|
|
tcleval("tk_messageBox -type okcancel -parent [xschem get topwindow] -message \""
|
|
|
|
|
"[get_cell [xschem get schname] 0]"
|
|
|
|
|
": UNSAVED data: want to exit?\"");
|
|
|
|
|
if(strcmp(tclresult(),"ok")==0) close = 1;
|
|
|
|
|
}
|
|
|
|
|
else close = 1;
|
|
|
|
|
Tcl_ResetResult(interp);
|
|
|
|
|
if(close) {
|
|
|
|
|
tkwin = Tk_NameToWindow(interp, win_path, mainwindow); /* NULL if win_path not existing */
|
|
|
|
|
if(!tkwin) dbg(0, "new_schematic(\"destroy\", ...): Warning: %s has been destroyed\n", win_path);
|
2022-01-09 05:14:25 +01:00
|
|
|
n = -1;
|
2022-01-10 18:54:07 +01:00
|
|
|
if(tkwin) for(i = 1; i < MAX_NEW_WINDOWS; i++) {
|
|
|
|
|
if(!strcmp(win_path, window_path[i])) {
|
2022-01-09 05:14:25 +01:00
|
|
|
n = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(n == -1) {
|
2022-01-10 18:54:07 +01:00
|
|
|
dbg(0, "new_schematic(\"destroy\"...): no window to destroy found: %s\n", win_path);
|
|
|
|
|
return;
|
2022-01-09 05:14:25 +01:00
|
|
|
}
|
2022-01-10 18:54:07 +01:00
|
|
|
if(tkwin && n >= 1 && n < MAX_NEW_WINDOWS) {
|
|
|
|
|
/* delete Tcl context of deleted schematic window */
|
|
|
|
|
tclvareval("delete_ctx ", win_path, NULL);
|
|
|
|
|
xctx = save_xctx[n];
|
|
|
|
|
/* set saved ctx to main window if current is to be destroyed */
|
|
|
|
|
if(savectx == xctx) savectx = save_xctx[0];
|
|
|
|
|
tclvareval("winfo toplevel ", win_path, NULL);
|
|
|
|
|
delete_schematic_data();
|
|
|
|
|
save_xctx[n] = NULL;
|
|
|
|
|
Tk_DestroyWindow(Tk_NameToWindow(interp, window_path[n], mainwindow));
|
|
|
|
|
tclvareval("destroy ", tclresult(), NULL);
|
|
|
|
|
my_strncpy(window_path[n], "", S(window_path[n]));
|
|
|
|
|
(*window_count)--;
|
|
|
|
|
if(*window_count == 0) tcleval(".menubar.view.menu entryconfigure 21 -state normal");
|
2022-01-09 05:14:25 +01:00
|
|
|
}
|
2022-01-10 18:54:07 +01:00
|
|
|
}
|
|
|
|
|
/* following 3 lines must be done also if window not closed */
|
|
|
|
|
xctx = savectx; /* restore previous schematic or main window if previous destroyed */
|
|
|
|
|
tclvareval("restore_ctx ", xctx->current_win_path, " ; housekeeping_ctx", NULL);
|
|
|
|
|
set_modify(-1); /* sets window title */
|
|
|
|
|
} else {
|
|
|
|
|
dbg(0, "new_schematic() destroy_tab: there are no additional tabs\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void destroy_tab(int *window_count, const char *win_path)
|
|
|
|
|
{
|
|
|
|
|
int i, n;
|
|
|
|
|
if(*window_count) {
|
|
|
|
|
int close = 0;
|
|
|
|
|
dbg(1, "new_schematic() destroy_tab\n");
|
|
|
|
|
|
|
|
|
|
if(strcmp(win_path, xctx->current_win_path)) {
|
|
|
|
|
dbg(0, "new_schematic(\"destroy_tab\", %s): must be in this tab to destroy\n", win_path);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(xctx->modified && has_x) {
|
|
|
|
|
tcleval("tk_messageBox -type okcancel -parent [xschem get topwindow] -message \""
|
|
|
|
|
"[get_cell [xschem get schname] 0]"
|
|
|
|
|
": UNSAVED data: want to exit?\"");
|
|
|
|
|
if(strcmp(tclresult(),"ok")==0) close = 1;
|
|
|
|
|
}
|
|
|
|
|
else close = 1;
|
|
|
|
|
Tcl_ResetResult(interp);
|
|
|
|
|
if(close) {
|
2022-01-09 05:14:25 +01:00
|
|
|
n = -1;
|
2022-01-10 18:54:07 +01:00
|
|
|
for(i = 1; i < MAX_NEW_WINDOWS; i++) {
|
|
|
|
|
if(!strcmp(win_path, window_path[i])) {
|
2022-01-09 05:14:25 +01:00
|
|
|
n = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(n == -1) {
|
2022-01-10 18:54:07 +01:00
|
|
|
dbg(0, "new_schematic(\"destroy_tab\"...): no tab to destroy found: %s\n", win_path);
|
|
|
|
|
return;
|
2022-01-09 05:14:25 +01:00
|
|
|
}
|
2022-01-10 18:54:07 +01:00
|
|
|
if(n >= 1 && n < MAX_NEW_WINDOWS) {
|
|
|
|
|
tclvareval("delete_ctx ", win_path, NULL);
|
|
|
|
|
tclvareval("delete_tab ", win_path, NULL);
|
|
|
|
|
xctx = save_xctx[n];
|
|
|
|
|
delete_schematic_data();
|
|
|
|
|
save_xctx[n] = NULL;
|
|
|
|
|
my_strncpy(window_path[n], "", S(window_path[n]));
|
|
|
|
|
/* delete Tcl context of deleted schematic window */
|
|
|
|
|
(*window_count)--;
|
|
|
|
|
if(*window_count == 0) tcleval(".menubar.view.menu entryconfigure 21 -state normal");
|
|
|
|
|
}
|
|
|
|
|
xctx = save_xctx[0]; /* restore main (.drw) schematic */
|
2022-01-13 00:58:00 +01:00
|
|
|
resetwin(1, 0, 0, 0, 0); /* create pixmap. resetwin(create_pixmap, clear_pixmap, force, w, h) */
|
2022-01-10 18:54:07 +01:00
|
|
|
tclvareval("restore_ctx ", xctx->current_win_path, " ; housekeeping_ctx", NULL);
|
|
|
|
|
set_modify(-1); /* sets window title */
|
|
|
|
|
draw();
|
2021-11-02 02:23:45 +01:00
|
|
|
}
|
2022-01-10 18:54:07 +01:00
|
|
|
} else {
|
|
|
|
|
dbg(0, "new_schematic() destroy_tab: there are no additional tabs\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void destroy_all_windows(int *window_count)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
Xschem_ctx *savectx;
|
|
|
|
|
Tk_Window tkwin;
|
|
|
|
|
savectx = xctx;
|
|
|
|
|
if(*window_count) {
|
|
|
|
|
int close;
|
|
|
|
|
dbg(1, "new_schematic() destroy_all\n");
|
|
|
|
|
for(i = 1; i < MAX_NEW_WINDOWS; i++) {
|
|
|
|
|
if(window_path[i][0]) {
|
|
|
|
|
tkwin = Tk_NameToWindow(interp, window_path[i], mainwindow); /* NULL if win_path not existing */
|
|
|
|
|
if(!tkwin) dbg(0, "new_schematic(\"switch\",...): Warning: %s has been destroyed\n", window_path[i]);
|
|
|
|
|
else {
|
|
|
|
|
xctx = save_xctx[i];
|
|
|
|
|
close = 0;
|
|
|
|
|
/* reset old focused window so callback() will force repaint on expose events */
|
|
|
|
|
if(xctx->modified && has_x) {
|
|
|
|
|
tcleval("tk_messageBox -type okcancel -parent [xschem get topwindow] -message \""
|
|
|
|
|
"[get_cell [xschem get schname] 0]"
|
|
|
|
|
": UNSAVED data: want to exit?\"");
|
|
|
|
|
if(strcmp(tclresult(),"ok")==0) close = 1;
|
2022-01-09 05:14:25 +01:00
|
|
|
}
|
2022-01-10 18:54:07 +01:00
|
|
|
else close = 1;
|
|
|
|
|
Tcl_ResetResult(interp);
|
|
|
|
|
if(close) {
|
|
|
|
|
tclvareval("winfo toplevel ", window_path[i], NULL);
|
2022-01-09 05:14:25 +01:00
|
|
|
delete_schematic_data();
|
2022-01-10 18:54:07 +01:00
|
|
|
/* set saved ctx to main window if previous is about to be destroyed */
|
|
|
|
|
if(savectx == save_xctx[i]) savectx = save_xctx[0];
|
|
|
|
|
save_xctx[i] = NULL;
|
|
|
|
|
Tk_DestroyWindow(Tk_NameToWindow(interp, window_path[i], mainwindow));
|
2022-01-09 05:14:25 +01:00
|
|
|
tclvareval("destroy ", tclresult(), NULL);
|
2022-01-10 18:54:07 +01:00
|
|
|
/* delete Tcl context of deleted schematic window */
|
|
|
|
|
tclvareval("delete_ctx ", window_path[i], NULL);
|
|
|
|
|
my_strncpy(window_path[i], "", S(window_path[i]));
|
|
|
|
|
(*window_count)--;
|
|
|
|
|
if(*window_count == 0) tcleval(".menubar.view.menu entryconfigure 21 -state normal");
|
2022-01-09 05:14:25 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-10 18:54:07 +01:00
|
|
|
}
|
|
|
|
|
/* following 3 lines must be done also if windows not closed */
|
|
|
|
|
xctx = savectx; /* restore previous schematic or main if old is destroyed */
|
|
|
|
|
tclvareval("restore_ctx ", xctx->current_win_path, " ; housekeeping_ctx", NULL);
|
|
|
|
|
set_modify(-1); /* sets window title */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void destroy_all_tabs(int *window_count)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
Xschem_ctx *savectx;
|
|
|
|
|
savectx = xctx;
|
|
|
|
|
if(*window_count) {
|
|
|
|
|
int close;
|
|
|
|
|
dbg(1, "new_schematic() destroy_all_tabs\n");
|
|
|
|
|
for(i = 1; i < MAX_NEW_WINDOWS; i++) {
|
|
|
|
|
if(window_path[i][0]) {
|
|
|
|
|
xctx = save_xctx[i];
|
|
|
|
|
close = 0;
|
|
|
|
|
/* reset old focused window so callback() will force repaint on expose events */
|
2022-01-09 05:14:25 +01:00
|
|
|
if(xctx->modified && has_x) {
|
|
|
|
|
tcleval("tk_messageBox -type okcancel -parent [xschem get topwindow] -message \""
|
|
|
|
|
"[get_cell [xschem get schname] 0]"
|
|
|
|
|
": UNSAVED data: want to exit?\"");
|
|
|
|
|
if(strcmp(tclresult(),"ok")==0) close = 1;
|
|
|
|
|
}
|
|
|
|
|
else close = 1;
|
|
|
|
|
Tcl_ResetResult(interp);
|
|
|
|
|
if(close) {
|
2022-01-10 18:54:07 +01:00
|
|
|
/* delete Tcl context of deleted schematic window */
|
|
|
|
|
tclvareval("delete_ctx ", window_path[i], NULL);
|
|
|
|
|
tclvareval("delete_tab ", window_path[i], NULL);
|
|
|
|
|
delete_schematic_data();
|
|
|
|
|
/* set saved ctx to main window if previous is about to be destroyed */
|
|
|
|
|
if(savectx == save_xctx[i]) savectx = save_xctx[0];
|
|
|
|
|
save_xctx[i] = NULL;
|
|
|
|
|
my_strncpy(window_path[i], "", S(window_path[i]));
|
|
|
|
|
(*window_count)--;
|
|
|
|
|
if(*window_count == 0) tcleval(".menubar.view.menu entryconfigure 21 -state normal");
|
2022-01-09 05:14:25 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-10 18:54:07 +01:00
|
|
|
/* following 3 lines must be done also if windows not closed */
|
|
|
|
|
xctx = savectx; /* restore previous schematic or main if old is destroyed */
|
|
|
|
|
tclvareval("restore_ctx ", xctx->current_win_path, " ; housekeeping_ctx", NULL);
|
|
|
|
|
set_modify(-1); /* sets window title */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* top_path is the path prefix of win_path:
|
|
|
|
|
*
|
|
|
|
|
* win_path top_path
|
|
|
|
|
* ".drw" ""
|
|
|
|
|
* ".x1.drw" ".x1"
|
|
|
|
|
*/
|
|
|
|
|
int new_schematic(const char *what, const char *win_path, const char *fname)
|
|
|
|
|
{
|
|
|
|
|
int tabbed_interface;
|
|
|
|
|
const char *tmp;
|
|
|
|
|
|
2022-01-15 23:35:37 +01:00
|
|
|
if(!has_x) return 0;
|
2022-01-10 18:54:07 +01:00
|
|
|
tabbed_interface = 0;
|
|
|
|
|
if((tmp = tclgetvar("tabbed_interface"))) {
|
|
|
|
|
if(tmp[0] == '1') tabbed_interface = 1;
|
|
|
|
|
}
|
|
|
|
|
dbg(1, "new_schematic(): current_win_path=%s, what=%s, win_path=%s\n", xctx->current_win_path, what, win_path);
|
|
|
|
|
if(!strcmp(what, "ntabs")) {
|
|
|
|
|
return window_count;
|
|
|
|
|
} else if(!strcmp(what, "create")) {
|
|
|
|
|
if(!tabbed_interface) {
|
|
|
|
|
create_new_window(&window_count, fname);
|
|
|
|
|
} else {
|
2022-01-11 01:09:56 +01:00
|
|
|
create_new_tab(&window_count, fname);
|
2022-01-10 18:54:07 +01:00
|
|
|
}
|
|
|
|
|
} else if(!strcmp(what, "destroy")) {
|
|
|
|
|
if(!tabbed_interface) {
|
|
|
|
|
destroy_window(&window_count, win_path);
|
|
|
|
|
} else {
|
|
|
|
|
destroy_tab(&window_count, win_path);
|
|
|
|
|
}
|
2022-01-09 05:14:25 +01:00
|
|
|
} else if(!strcmp(what, "destroy_all")) {
|
2022-01-09 14:58:45 +01:00
|
|
|
if(!tabbed_interface) {
|
2022-01-10 18:54:07 +01:00
|
|
|
destroy_all_windows(&window_count);
|
2022-01-09 14:58:45 +01:00
|
|
|
} else {
|
2022-01-10 18:54:07 +01:00
|
|
|
destroy_all_tabs(&window_count);
|
2022-01-09 05:14:25 +01:00
|
|
|
}
|
2022-01-11 01:09:56 +01:00
|
|
|
} else if(!strcmp(what, "switch_win")) {
|
|
|
|
|
switch_window(&window_count, win_path); /* see comments in switch_window() */
|
|
|
|
|
} else if(!strcmp(what, "switch_tab")) {
|
|
|
|
|
switch_tab(&window_count, win_path);
|
2020-12-03 23:17:13 +01:00
|
|
|
}
|
2022-01-10 18:54:07 +01:00
|
|
|
return window_count;
|
2020-12-03 23:17:13 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-06 02:10:53 +01:00
|
|
|
void change_linewidth(double w)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-12-06 02:10:53 +01:00
|
|
|
int i, changed;
|
|
|
|
|
|
|
|
|
|
changed=0;
|
|
|
|
|
/* choose line width automatically based on zoom */
|
|
|
|
|
if(w<0.) {
|
2021-11-10 13:43:08 +01:00
|
|
|
int cs;
|
|
|
|
|
cs = tclgetdoublevar("cadsnap");
|
|
|
|
|
if(tclgetboolvar("change_lw")) {
|
|
|
|
|
xctx->lw=xctx->mooz * 0.09 * cs;
|
|
|
|
|
cadhalfdotsize = CADHALFDOTSIZE + 0.04 * (cs-10);
|
2020-12-06 02:10:53 +01:00
|
|
|
changed=1;
|
|
|
|
|
}
|
|
|
|
|
/* explicitly set line width */
|
|
|
|
|
} else {
|
|
|
|
|
xctx->lw=w;
|
|
|
|
|
changed=1;
|
|
|
|
|
}
|
|
|
|
|
if(!changed) return;
|
|
|
|
|
if(has_x) {
|
|
|
|
|
for(i=0;i<cadlayers;i++) {
|
2021-11-16 22:28:10 +01:00
|
|
|
XSetLineAttributes (display, xctx->gc[i], INT_WIDTH(xctx->lw), LineSolid, CapRound , JoinRound);
|
2020-12-06 02:10:53 +01:00
|
|
|
}
|
|
|
|
|
XSetLineAttributes (display, xctx->gctiled, INT_WIDTH(xctx->lw), LineSolid, CapRound , JoinRound);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-12-06 02:10:53 +01:00
|
|
|
xctx->areax1 = -2*INT_WIDTH(xctx->lw);
|
|
|
|
|
xctx->areay1 = -2*INT_WIDTH(xctx->lw);
|
|
|
|
|
xctx->areax2 = xctx->xrect[0].width+2*INT_WIDTH(xctx->lw);
|
|
|
|
|
xctx->areay2 = xctx->xrect[0].height+2*INT_WIDTH(xctx->lw);
|
|
|
|
|
xctx->areaw = xctx->areax2-xctx->areax1;
|
|
|
|
|
xctx->areah = xctx->areay2 - xctx->areay1;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-12-06 02:10:53 +01:00
|
|
|
|
|
|
|
|
/* clears and creates cairo_sfc, cairo_ctx, cairo_save_sfc, cairo_save_ctx
|
|
|
|
|
* and sets some graphical attributes */
|
2022-02-19 14:31:55 +01:00
|
|
|
static void resetcairo(int create, int clear, int force_or_resize)
|
2020-12-06 02:10:53 +01:00
|
|
|
{
|
2020-12-07 20:04:57 +01:00
|
|
|
#if HAS_CAIRO==1
|
2020-12-06 02:10:53 +01:00
|
|
|
dbg(1, "resetcairo() %d, %d, %d\n", create, clear, force_or_resize);
|
|
|
|
|
if(clear && force_or_resize) {
|
|
|
|
|
/* xctx->cairo_save_sfc is based on pixmap and pixmaps are not resizeable, so on resize
|
|
|
|
|
* we must destroy & recreate everything. xctx->cairo_sfc can be resized using cairo_*_surface_set_size
|
|
|
|
|
* being based on window */
|
|
|
|
|
cairo_destroy(xctx->cairo_save_ctx);
|
|
|
|
|
cairo_surface_destroy(xctx->cairo_save_sfc);
|
|
|
|
|
cairo_destroy(xctx->cairo_ctx);
|
|
|
|
|
cairo_surface_destroy(xctx->cairo_sfc);
|
|
|
|
|
}
|
|
|
|
|
if(create && force_or_resize) {
|
2022-01-20 01:57:53 +01:00
|
|
|
cairo_font_options_t *options;
|
|
|
|
|
options = cairo_font_options_create();
|
|
|
|
|
cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_FAST);
|
|
|
|
|
cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_SLIGHT);
|
2020-12-06 02:10:53 +01:00
|
|
|
/***** Create Cairo save buffer drawing area *****/
|
2022-02-02 00:11:46 +01:00
|
|
|
#ifdef __unix__
|
2020-12-06 02:10:53 +01:00
|
|
|
xctx->cairo_save_sfc =
|
2021-12-22 04:39:23 +01:00
|
|
|
cairo_xlib_surface_create(display, xctx->save_pixmap, visual, xctx->xrect[0].width, xctx->xrect[0].height);
|
2022-02-02 00:11:46 +01:00
|
|
|
#else
|
|
|
|
|
HWND hwnd = Tk_GetHWND(xctx->window);
|
|
|
|
|
HDC dc = GetDC(hwnd);
|
|
|
|
|
xctx->cairo_save_sfc = cairo_win32_surface_create(dc);
|
|
|
|
|
#endif
|
2020-12-06 02:10:53 +01:00
|
|
|
if(cairo_surface_status(xctx->cairo_save_sfc)!=CAIRO_STATUS_SUCCESS) {
|
|
|
|
|
fprintf(errfp, "ERROR: invalid cairo xcb surface\n");
|
|
|
|
|
}
|
2022-01-19 00:49:46 +01:00
|
|
|
|
2020-12-06 02:10:53 +01:00
|
|
|
xctx->cairo_save_ctx = cairo_create(xctx->cairo_save_sfc);
|
2021-11-10 13:43:08 +01:00
|
|
|
cairo_select_font_face(xctx->cairo_save_ctx, tclgetvar("cairo_font_name"),
|
|
|
|
|
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
2020-12-06 02:10:53 +01:00
|
|
|
cairo_set_font_size(xctx->cairo_save_ctx, 20);
|
2022-01-19 00:49:46 +01:00
|
|
|
|
|
|
|
|
cairo_set_font_options(xctx->cairo_save_ctx, options);
|
|
|
|
|
|
2020-12-06 02:10:53 +01:00
|
|
|
cairo_set_line_width(xctx->cairo_save_ctx, 1);
|
|
|
|
|
cairo_set_line_join(xctx->cairo_save_ctx, CAIRO_LINE_JOIN_ROUND);
|
|
|
|
|
cairo_set_line_cap(xctx->cairo_save_ctx, CAIRO_LINE_CAP_ROUND);
|
|
|
|
|
/***** Create Cairo main drawing window structures *****/
|
2022-02-02 00:11:46 +01:00
|
|
|
#ifdef __unix__
|
2021-12-22 04:39:23 +01:00
|
|
|
xctx->cairo_sfc = cairo_xlib_surface_create(display, xctx->window, visual,
|
|
|
|
|
xctx->xrect[0].width, xctx->xrect[0].height);
|
2022-02-02 00:11:46 +01:00
|
|
|
#else
|
|
|
|
|
xctx->cairo_sfc = cairo_win32_surface_create(dc);
|
|
|
|
|
#endif
|
2020-12-06 02:10:53 +01:00
|
|
|
if(cairo_surface_status(xctx->cairo_sfc)!=CAIRO_STATUS_SUCCESS) {
|
|
|
|
|
fprintf(errfp, "ERROR: invalid cairo surface\n");
|
|
|
|
|
}
|
|
|
|
|
xctx->cairo_ctx = cairo_create(xctx->cairo_sfc);
|
2021-11-10 13:43:08 +01:00
|
|
|
cairo_select_font_face(xctx->cairo_ctx, tclgetvar("cairo_font_name"),
|
|
|
|
|
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
2020-12-06 02:10:53 +01:00
|
|
|
cairo_set_font_size(xctx->cairo_ctx, 20);
|
2022-01-19 00:49:46 +01:00
|
|
|
|
|
|
|
|
cairo_set_font_options(xctx->cairo_ctx, options);
|
|
|
|
|
|
2020-12-06 02:10:53 +01:00
|
|
|
cairo_set_line_width(xctx->cairo_ctx, 1);
|
|
|
|
|
cairo_set_line_join(xctx->cairo_ctx, CAIRO_LINE_JOIN_ROUND);
|
|
|
|
|
cairo_set_line_cap(xctx->cairo_ctx, CAIRO_LINE_CAP_ROUND);
|
2022-01-19 00:49:46 +01:00
|
|
|
cairo_font_options_destroy(options);
|
2020-12-06 02:10:53 +01:00
|
|
|
}
|
|
|
|
|
#endif /* HAS_CAIRO */
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-22 00:13:25 +01:00
|
|
|
/* w and h (if > 0 ) parameters force reset pixmap to w x h, regardless of window size */
|
|
|
|
|
void resetwin(int create_pixmap, int clear_pixmap, int force, int w, int h)
|
2020-12-06 02:10:53 +01:00
|
|
|
{
|
|
|
|
|
unsigned int width, height;
|
|
|
|
|
XWindowAttributes wattr;
|
2020-12-22 00:13:25 +01:00
|
|
|
int status;
|
|
|
|
|
#ifndef __unix__
|
|
|
|
|
HWND hwnd = Tk_GetHWND(xctx->window);
|
|
|
|
|
RECT rct;
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-12-06 02:10:53 +01:00
|
|
|
if(has_x) {
|
2020-12-22 00:13:25 +01:00
|
|
|
if(w && h) {
|
|
|
|
|
width = w;
|
|
|
|
|
height = h;
|
|
|
|
|
status = 1;
|
|
|
|
|
} else {
|
|
|
|
|
#ifdef __unix__
|
|
|
|
|
status = XGetWindowAttributes(display, xctx->window, &wattr);
|
|
|
|
|
if(status) {
|
|
|
|
|
width = wattr.width;
|
|
|
|
|
height = wattr.height;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
status = GetWindowRect(hwnd, &rct);
|
|
|
|
|
if(status) {
|
|
|
|
|
width = rct.right - rct.left;
|
|
|
|
|
height = rct.bottom - rct.top;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
if(status) {
|
2020-12-06 02:10:53 +01:00
|
|
|
/* if(wattr.map_state==IsUnmapped) return; */
|
2021-12-22 04:39:23 +01:00
|
|
|
xctx->areax2 = width + 2 * INT_WIDTH(xctx->lw);
|
|
|
|
|
xctx->areay2 = height + 2 * INT_WIDTH(xctx->lw);
|
|
|
|
|
xctx->areax1 = -2 * INT_WIDTH(xctx->lw);
|
|
|
|
|
xctx->areay1 = -2 * INT_WIDTH(xctx->lw);
|
|
|
|
|
xctx->areaw = xctx->areax2 - xctx->areax1;
|
|
|
|
|
xctx->areah = xctx->areay2 - xctx->areay1;
|
2020-12-06 02:10:53 +01:00
|
|
|
/* if no force avoid unnecessary work if no resize */
|
2021-12-22 04:39:23 +01:00
|
|
|
if( force || width != xctx->xrect[0].width || height != xctx->xrect[0].height) {
|
|
|
|
|
dbg(1, "resetwin(): create: %d, clear: %d, force: %d, w=%d h=%d\n",
|
|
|
|
|
create_pixmap, clear_pixmap, force, width, height);
|
2020-12-06 02:10:53 +01:00
|
|
|
dbg(1, "resetwin(): changing size\n\n");
|
|
|
|
|
xctx->xrect[0].x = 0;
|
|
|
|
|
xctx->xrect[0].y = 0;
|
2021-12-22 04:39:23 +01:00
|
|
|
xctx->xrect[0].width = width;
|
|
|
|
|
xctx->xrect[0].height = height;
|
2020-12-06 02:10:53 +01:00
|
|
|
if(clear_pixmap) {
|
|
|
|
|
resetcairo(0, 1, 1); /* create, clear, force */
|
|
|
|
|
#ifdef __unix__
|
|
|
|
|
XFreePixmap(display,xctx->save_pixmap);
|
|
|
|
|
#else
|
|
|
|
|
Tk_FreePixmap(display, xctx->save_pixmap);
|
|
|
|
|
#endif
|
|
|
|
|
XFreeGC(display,xctx->gctiled);
|
|
|
|
|
}
|
|
|
|
|
if(create_pixmap) {
|
|
|
|
|
#ifdef __unix__
|
2021-12-22 04:39:23 +01:00
|
|
|
xctx->save_pixmap = XCreatePixmap(display, xctx->window,
|
|
|
|
|
xctx->xrect[0].width, xctx->xrect[0].height, screendepth);
|
2020-12-06 02:10:53 +01:00
|
|
|
#else
|
2021-12-22 04:39:23 +01:00
|
|
|
xctx->save_pixmap = Tk_GetPixmap(display, xctx->window,
|
|
|
|
|
xctx->xrect[0].width, xctx->xrect[0].height, screendepth);
|
2020-12-06 02:10:53 +01:00
|
|
|
#endif
|
|
|
|
|
xctx->gctiled = XCreateGC(display,xctx->window,0L, NULL);
|
|
|
|
|
XSetTile(display,xctx->gctiled, xctx->save_pixmap);
|
|
|
|
|
XSetFillStyle(display,xctx->gctiled,FillTiled);
|
2020-12-26 22:29:45 +01:00
|
|
|
/* whenever a pixmap is recreated all GC attributes must be reissued */
|
|
|
|
|
change_linewidth(-1.0);
|
2020-12-06 02:10:53 +01:00
|
|
|
resetcairo(1, 0, 1); /* create, clear, force */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-25 17:05:43 +02:00
|
|
|
if(xctx->pending_fullzoom) {
|
2021-12-29 05:11:39 +01:00
|
|
|
dbg(1, "resetwin(): pending_fulzoom: doing zoom_full()\n");
|
2020-12-22 00:13:25 +01:00
|
|
|
zoom_full(0, 0, 1, 0.97);
|
2021-10-25 17:05:43 +02:00
|
|
|
xctx->pending_fullzoom=0;
|
2020-12-06 02:10:53 +01:00
|
|
|
}
|
|
|
|
|
dbg(1, "resetwin(): Window reset\n");
|
|
|
|
|
} /* end if(has_x) */
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
int Tcl_AppInit(Tcl_Interp *inter)
|
|
|
|
|
{
|
|
|
|
|
char name[PATH_MAX]; /* overflow safe 20161122 */
|
|
|
|
|
char tmp[2*PATH_MAX+100]; /* 20161122 overflow safe */
|
2022-01-13 00:58:00 +01:00
|
|
|
#ifndef __unix__
|
2022-01-12 23:55:46 +01:00
|
|
|
char install_dir[PATH_MAX] = "";
|
2022-01-13 00:58:00 +01:00
|
|
|
#endif
|
2020-08-08 15:47:34 +02:00
|
|
|
int i;
|
2020-12-14 19:11:24 +01:00
|
|
|
double l_width;
|
2020-08-08 15:47:34 +02:00
|
|
|
struct stat buf;
|
|
|
|
|
const char *home_buff;
|
|
|
|
|
int running_in_src_dir;
|
2021-11-10 13:43:08 +01:00
|
|
|
int fs;
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
/* get PWD and HOME */
|
|
|
|
|
if(!getcwd(pwd_dir, PATH_MAX)) {
|
|
|
|
|
fprintf(errfp, "Tcl_AppInit(): getcwd() failed\n");
|
|
|
|
|
}
|
|
|
|
|
#ifdef __unix__
|
|
|
|
|
if ((home_buff = getenv("HOME")) == NULL) {
|
|
|
|
|
home_buff = getpwuid(getuid())->pw_dir;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
change_to_unix_fn(pwd_dir);
|
|
|
|
|
home_buff = getenv("USERPROFILE");
|
|
|
|
|
change_to_unix_fn(home_buff);
|
|
|
|
|
#endif
|
|
|
|
|
my_strncpy(home_dir, home_buff, S(home_dir));
|
|
|
|
|
|
2021-11-16 22:28:10 +01:00
|
|
|
/* set error and exit handlers */
|
2020-08-08 15:47:34 +02:00
|
|
|
XSetErrorHandler(err);
|
2021-12-05 15:31:26 +01:00
|
|
|
if(!interp) interp=inter;
|
2020-08-08 15:47:34 +02:00
|
|
|
Tcl_Init(interp);
|
2020-12-07 15:46:20 +01:00
|
|
|
if(has_x) {
|
|
|
|
|
Tk_Init(interp);
|
|
|
|
|
tclsetvar("has_x","1");
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
Tcl_CreateExitHandler(tclexit, 0);
|
|
|
|
|
#ifdef __unix__
|
2021-01-04 15:19:08 +01:00
|
|
|
my_snprintf(tmp, S(tmp),"regsub -all {~/} {%s} {%s/}", XSCHEM_LIBRARY_PATH, home_dir);
|
2020-08-08 15:47:34 +02:00
|
|
|
tcleval(tmp);
|
2020-08-16 03:34:45 +02:00
|
|
|
tclsetvar("XSCHEM_LIBRARY_PATH", tclresult());
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2021-11-16 22:28:10 +01:00
|
|
|
|
2021-11-09 19:05:56 +01:00
|
|
|
/* 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);
|
2021-11-16 22:28:10 +01:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
/* test if running xschem in src/ dir (usually for testing) */
|
2021-11-16 22:28:10 +01:00
|
|
|
running_in_src_dir = 0;
|
2020-08-08 15:47:34 +02:00
|
|
|
if( !stat("./xschem.tcl", &buf) && !stat("./systemlib", &buf) && !stat("./xschem", &buf)) {
|
|
|
|
|
running_in_src_dir = 1;
|
|
|
|
|
tclsetvar("XSCHEM_SHAREDIR",pwd_dir); /* for testing xschem builds in src dir*/
|
2021-11-16 22:28:10 +01:00
|
|
|
|
|
|
|
|
/* set builtin library path if running in src/ */
|
2021-11-09 19:05:56 +01:00
|
|
|
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);
|
2020-10-07 16:12:33 +02:00
|
|
|
tcleval(tmp);
|
2020-10-12 13:13:31 +02:00
|
|
|
} else if( !stat(XSCHEM_SHAREDIR, &buf) ) {
|
2020-08-08 15:47:34 +02:00
|
|
|
tclsetvar("XSCHEM_SHAREDIR",XSCHEM_SHAREDIR);
|
|
|
|
|
/* ... else give up searching, may set later after loading xschemrc */
|
|
|
|
|
}
|
|
|
|
|
#else
|
2021-11-16 22:28:10 +01:00
|
|
|
char *up_hier=NULL, *win_xschem_library_path=NULL;
|
|
|
|
|
#define WIN_XSCHEM_LIBRARY_PATH_NUM 9
|
|
|
|
|
const char *WIN_XSCHEM_LIBRARY_PATH[WIN_XSCHEM_LIBRARY_PATH_NUM] = {
|
|
|
|
|
/*1*/ "xschem_library",
|
|
|
|
|
/*2*/ "xschem_library/devices",
|
|
|
|
|
/*3*/ "xschem_library/examples",
|
|
|
|
|
/*4*/ "xschem_library/ngspice",
|
|
|
|
|
/*5*/ "xschem_library/logic",
|
|
|
|
|
/*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);
|
|
|
|
|
if (dir_len>11)
|
|
|
|
|
install_dir[dir_len-11] = '\0'; /* 11 = remove /xschem.exe */
|
|
|
|
|
/* debugging in Visual Studio will not have bin */
|
|
|
|
|
my_snprintf(tmp, S(tmp), "regexp {bin$} \"%s\"", install_dir);
|
|
|
|
|
tcleval(tmp);
|
|
|
|
|
running_in_src_dir = 0;
|
|
|
|
|
if (atoi(tclresult()) == 0)
|
|
|
|
|
{
|
|
|
|
|
running_in_src_dir = 1; /* no bin, so it's running in Visual studio source directory*/
|
|
|
|
|
my_strdup(62, &up_hier, "../../..");
|
|
|
|
|
}
|
|
|
|
|
else my_strdup(63, &up_hier, "..");
|
2021-12-18 13:11:21 +01:00
|
|
|
/* my_strcat(415, &win_xschem_library_path, "."); */
|
2021-11-16 22:28:10 +01:00
|
|
|
for (i = 0; i < WIN_XSCHEM_LIBRARY_PATH_NUM; ++i) {
|
|
|
|
|
my_snprintf(tmp, S(tmp),"%s/%s/%s", install_dir, up_hier, WIN_XSCHEM_LIBRARY_PATH[i]);
|
2021-12-18 13:11:21 +01:00
|
|
|
if (i > 0) my_strcat(416, &win_xschem_library_path, "\;");
|
2021-11-16 22:28:10 +01:00
|
|
|
my_strcat(431, &win_xschem_library_path, tmp);
|
|
|
|
|
}
|
2021-12-03 23:59:46 +01:00
|
|
|
my_snprintf(tmp, S(tmp), "set tmp2 {%s}; "
|
2021-11-16 22:28:10 +01:00
|
|
|
"while {[regsub {([^/]*\\.*[^./]+[^/]*)/\\.\\./?} $tmp2 {} tmp2]} {}; ", win_xschem_library_path);
|
|
|
|
|
const char *result2 = tcleval(tmp);
|
|
|
|
|
const char *win_xschem_library_path_clean = tclgetvar("tmp2");
|
|
|
|
|
tclsetvar("XSCHEM_LIBRARY_PATH", win_xschem_library_path_clean);
|
|
|
|
|
my_free(432, &win_xschem_library_path);
|
|
|
|
|
my_free(441, &up_hier);
|
2021-11-09 19:05:56 +01:00
|
|
|
char *xschem_sharedir=NULL;
|
2020-08-08 15:47:34 +02:00
|
|
|
if ((xschem_sharedir=getenv("XSCHEM_SHAREDIR")) != NULL) {
|
|
|
|
|
if (!stat(xschem_sharedir, &buf)) {
|
|
|
|
|
tclsetvar("XSCHEM_SHAREDIR", xschem_sharedir);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-01-12 23:55:46 +01:00
|
|
|
if (running_in_src_dir==1) {
|
2020-10-14 01:38:51 +02:00
|
|
|
/* pwd_dir can be working directory specified as "Working Directory" in settings */
|
|
|
|
|
my_snprintf(tmp, S(tmp), "%s/../../../src", install_dir);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2020-10-07 16:12:33 +02:00
|
|
|
my_snprintf(tmp, S(tmp), "%s/../share", install_dir);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
tclsetvar("XSCHEM_SHAREDIR", tmp);
|
|
|
|
|
}
|
|
|
|
|
/* create user conf dir */
|
|
|
|
|
my_snprintf(user_conf_dir, S(user_conf_dir), "%s/xschem", home_dir); /* create user_conf root directory first */
|
|
|
|
|
if (stat(user_conf_dir, &buf)) {
|
|
|
|
|
if (!mkdir(user_conf_dir, 0700)) {
|
|
|
|
|
dbg(1, "Tcl_AppInit(): created root directory to setup and create for user conf dir: %s\n", user_conf_dir);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fprintf(errfp, "Tcl_AppInit(): failure creating %s\n", user_conf_dir);
|
|
|
|
|
Tcl_Exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
my_snprintf(user_conf_dir, S(user_conf_dir), "%s/xschem/%s", home_dir, USER_CONF_DIR);
|
|
|
|
|
tclsetvar("USER_CONF_DIR", user_conf_dir);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* create USER_CONF_DIR if it was not installed */
|
|
|
|
|
if(stat(user_conf_dir, &buf)) {
|
|
|
|
|
if(!mkdir(user_conf_dir, 0700)) {
|
|
|
|
|
dbg(1, "Tcl_AppInit(): created %s dir\n", user_conf_dir);
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(errfp, "Tcl_AppInit(): failure creating %s\n", user_conf_dir);
|
|
|
|
|
Tcl_Exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
/* */
|
|
|
|
|
/* SOURCE xschemrc file */
|
|
|
|
|
/* */
|
2022-01-16 01:12:43 +01:00
|
|
|
if(cli_opt_load_initfile) {
|
2020-08-08 15:47:34 +02:00
|
|
|
/* get xschemrc given om cmdline, in this case do *not* source any other xschemrc*/
|
2022-01-16 01:12:43 +01:00
|
|
|
if(cli_opt_rcfile[0]) {
|
|
|
|
|
my_snprintf(name, S(name), cli_opt_rcfile);
|
2020-08-08 15:47:34 +02:00
|
|
|
if(stat(name, &buf) ) {
|
2022-01-16 01:12:43 +01:00
|
|
|
/* cli_opt_rcfile given on cmdline is not existing */
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(errfp, "Tcl_AppInit() err 2: cannot find %s\n", name);
|
|
|
|
|
Tcl_ResetResult(interp);
|
|
|
|
|
Tcl_Exit(EXIT_FAILURE);
|
2020-10-12 13:13:31 +02:00
|
|
|
return TCL_ERROR;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
dbg(1, "Tcl_AppInit(): sourcing %s\n", name);
|
|
|
|
|
source_tcl_file(name);
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
else {
|
|
|
|
|
/* get systemwide xschemrc ... */
|
|
|
|
|
if(tclgetvar("XSCHEM_SHAREDIR")) {
|
2022-01-12 23:55:46 +01:00
|
|
|
#ifndef __unix__
|
|
|
|
|
if (running_in_src_dir == 1) {
|
|
|
|
|
my_snprintf(name, S(name), "%s/../../XSchemWix/xschemrc", install_dir);
|
|
|
|
|
if (!stat(name, &buf)) {
|
|
|
|
|
dbg(1, "Tcl_AppInit(): sourcing %s\n", name);
|
|
|
|
|
source_tcl_file(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
my_snprintf(name, S(name), "%s/xschemrc", tclgetvar("XSCHEM_SHAREDIR"));
|
|
|
|
|
if (!stat(name, &buf)) {
|
|
|
|
|
dbg(1, "Tcl_AppInit(): sourcing %s\n", name);
|
|
|
|
|
source_tcl_file(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#else
|
2020-08-08 15:47:34 +02:00
|
|
|
my_snprintf(name, S(name), "%s/xschemrc",tclgetvar("XSCHEM_SHAREDIR"));
|
|
|
|
|
if(!stat(name, &buf)) {
|
|
|
|
|
dbg(1, "Tcl_AppInit(): sourcing %s\n", name);
|
|
|
|
|
source_tcl_file(name);
|
|
|
|
|
}
|
2022-01-12 23:55:46 +01:00
|
|
|
#endif
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
/* ... then source xschemrc in present directory if existing ... */
|
|
|
|
|
if(!running_in_src_dir) {
|
|
|
|
|
my_snprintf(name, S(name), "%s/xschemrc",pwd_dir);
|
|
|
|
|
if(!stat(name, &buf)) {
|
|
|
|
|
dbg(1, "Tcl_AppInit(): sourcing %s\n", name);
|
|
|
|
|
source_tcl_file(name);
|
|
|
|
|
} else {
|
|
|
|
|
/* ... or look for (user_conf_dir)/xschemrc */
|
|
|
|
|
my_snprintf(name, S(name), "%s/xschemrc", user_conf_dir);
|
|
|
|
|
if(!stat(name, &buf)) {
|
|
|
|
|
dbg(1, "Tcl_AppInit(): sourcing %s\n", name);
|
|
|
|
|
source_tcl_file(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-16 22:28:10 +01:00
|
|
|
/* END SOURCING xschemrc */
|
2020-08-08 15:47:34 +02:00
|
|
|
|
2020-10-12 13:13:31 +02:00
|
|
|
if(rainbow_colors) tclsetvar("rainbow_colors","1");
|
|
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
/* */
|
|
|
|
|
/* START LOOKING FOR xschem.tcl */
|
|
|
|
|
/* */
|
|
|
|
|
if(!tclgetvar("XSCHEM_SHAREDIR")) {
|
|
|
|
|
fprintf(errfp, "Tcl_AppInit() err 3: cannot find xschem.tcl\n");
|
|
|
|
|
if(has_x) {
|
2020-10-12 13:13:31 +02:00
|
|
|
tcleval( "wm withdraw .");
|
2020-08-08 15:47:34 +02:00
|
|
|
tcleval(
|
|
|
|
|
"tk_messageBox -icon error -type ok -message \"Tcl_AppInit() err 3: xschem.tcl not found, "
|
|
|
|
|
"you are probably missing XSCHEM_SHAREDIR\"");
|
|
|
|
|
}
|
|
|
|
|
Tcl_ResetResult(interp);
|
|
|
|
|
Tcl_AppendResult(interp, "Tcl_AppInit() err 3: xschem.tcl not found, "
|
|
|
|
|
"you are probably missing XSCHEM_SHAREDIR",NULL);
|
|
|
|
|
Tcl_Exit(EXIT_FAILURE);
|
2020-10-12 13:13:31 +02:00
|
|
|
return TCL_ERROR;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
/* END LOOKING FOR xschem.tcl */
|
|
|
|
|
|
|
|
|
|
dbg(1, "Tcl_AppInit(): XSCHEM_SHAREDIR=%s XSCHEM_LIBRARY_PATH=%s\n",
|
2020-10-12 13:13:31 +02:00
|
|
|
tclgetvar("XSCHEM_SHAREDIR"),
|
2020-08-08 15:47:34 +02:00
|
|
|
tclgetvar("XSCHEM_LIBRARY_PATH") ? tclgetvar("XSCHEM_LIBRARY_PATH") : "NULL"
|
|
|
|
|
);
|
|
|
|
|
dbg(1, "Tcl_AppInit(): done step a of xinit()\n");
|
|
|
|
|
|
|
|
|
|
/* */
|
|
|
|
|
/* CREATE XSCHEM 'xschem' COMMAND */
|
|
|
|
|
/* */
|
|
|
|
|
Tcl_CreateCommand(interp, "xschem", (myproc *) xschem, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
dbg(1, "Tcl_AppInit(): done step a1 of xinit()\n");
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2021-11-16 22:28:10 +01:00
|
|
|
|
|
|
|
|
/* Execute tcl script given on command line with --tcl */
|
2022-01-16 01:12:43 +01:00
|
|
|
if(cli_opt_tcl_command) {
|
|
|
|
|
tcleval(cli_opt_tcl_command);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
/* set tcp port given in cmdline if any */
|
|
|
|
|
if(tcp_port > 0) {
|
|
|
|
|
if(tcp_port < 1024) fprintf(errfp, "please use port numbers >=1024 on command line\n");
|
|
|
|
|
else {
|
|
|
|
|
my_snprintf(name, S(name), "set xschem_listen_port %d", tcp_port);
|
|
|
|
|
tcleval(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* */
|
|
|
|
|
/* EXECUTE xschem.tcl */
|
|
|
|
|
/* */
|
|
|
|
|
my_snprintf(name, S(name), "%s/%s", tclgetvar("XSCHEM_SHAREDIR"), "xschem.tcl");
|
|
|
|
|
if(stat(name, &buf) ) {
|
|
|
|
|
fprintf(errfp, "Tcl_AppInit() err 4: cannot find %s\n", name);
|
|
|
|
|
if(has_x) {
|
2020-10-12 13:13:31 +02:00
|
|
|
tcleval( "wm withdraw .");
|
2020-08-08 15:47:34 +02:00
|
|
|
tcleval(
|
|
|
|
|
"tk_messageBox -icon error -type ok -message \"Tcl_AppInit() err 4: xschem.tcl not found, "
|
|
|
|
|
"installation problem or undefined XSCHEM_SHAREDIR\"");
|
|
|
|
|
}
|
|
|
|
|
Tcl_ResetResult(interp);
|
|
|
|
|
Tcl_AppendResult(interp, "Tcl_AppInit() err 4: xschem.tcl not found, "
|
|
|
|
|
"you are probably missing XSCHEM_SHAREDIR\n",NULL);
|
|
|
|
|
Tcl_Exit(EXIT_FAILURE);
|
2020-10-12 13:13:31 +02:00
|
|
|
return TCL_ERROR;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
dbg(1, "Tcl_AppInit(): sourcing %s\n", name);
|
|
|
|
|
source_tcl_file(name);
|
|
|
|
|
dbg(1, "Tcl_AppInit(): done executing xschem.tcl\n");
|
2021-11-16 22:28:10 +01:00
|
|
|
/* */
|
|
|
|
|
/* END EXECUTE xschem.tcl */
|
|
|
|
|
/* */
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
/* resolve absolute pathname of xschem (argv[0]) for future usage */
|
|
|
|
|
my_strdup(44, &xschem_executable, get_file_path(xschem_executable));
|
|
|
|
|
dbg(1, "Tcl_AppInit(): resolved xschem_executable=%s\n", xschem_executable);
|
|
|
|
|
|
|
|
|
|
|
2021-11-16 22:28:10 +01:00
|
|
|
/* get xschem globals from tcl variables set in xschemrc/xschem.tcl */
|
2021-11-10 13:43:08 +01:00
|
|
|
cairo_font_line_spacing = tclgetdoublevar("cairo_font_line_spacing");
|
2020-10-12 13:13:31 +02:00
|
|
|
if(color_ps==-1)
|
2020-08-08 15:47:34 +02:00
|
|
|
color_ps=atoi(tclgetvar("color_ps"));
|
|
|
|
|
else {
|
|
|
|
|
my_snprintf(tmp, S(tmp), "%d",color_ps);
|
|
|
|
|
tclsetvar("color_ps",tmp);
|
|
|
|
|
}
|
2020-12-14 19:11:24 +01:00
|
|
|
l_width=atoi(tclgetvar("line_width"));
|
2021-11-10 13:43:08 +01:00
|
|
|
if(tclgetboolvar("change_lw")) l_width = 0.0;
|
2020-08-08 15:47:34 +02:00
|
|
|
cadlayers=atoi(tclgetvar("cadlayers"));
|
|
|
|
|
if(debug_var==-10) debug_var=0;
|
2021-11-10 13:43:08 +01:00
|
|
|
my_snprintf(tmp, S(tmp), "%.16g",CADGRID);
|
2021-12-05 12:39:05 +01:00
|
|
|
tclvareval("set_ne cadgrid ", tmp, NULL);
|
2021-11-10 13:43:08 +01:00
|
|
|
my_snprintf(tmp, S(tmp), "%.16g",CADSNAP);
|
2021-12-05 12:39:05 +01:00
|
|
|
tclvareval("set_ne cadsnap ", tmp, NULL);
|
2021-11-10 13:43:08 +01:00
|
|
|
cairo_vert_correct = tclgetdoublevar("cairo_vert_correct");
|
|
|
|
|
nocairo_vert_correct = tclgetdoublevar("nocairo_vert_correct");
|
|
|
|
|
cairo_font_scale = tclgetdoublevar("cairo_font_scale");
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
/* */
|
|
|
|
|
/* [m]allocate dynamic memory */
|
|
|
|
|
/* */
|
2022-01-09 05:14:25 +01:00
|
|
|
alloc_xschem_data("", ".drw");
|
2021-11-29 02:47:37 +01:00
|
|
|
|
2021-11-16 22:28:10 +01:00
|
|
|
/* global context / graphic preferences/settings */
|
|
|
|
|
pixdata=my_calloc(641, cadlayers, sizeof(char*));
|
|
|
|
|
for(i=0;i<cadlayers;i++)
|
|
|
|
|
{
|
|
|
|
|
pixdata[i]=my_calloc(642, 32, sizeof(char));
|
|
|
|
|
}
|
2022-01-15 23:35:37 +01:00
|
|
|
if(has_x) pixmap=my_calloc(636, cadlayers, sizeof(Pixmap));
|
2021-11-16 22:28:10 +01:00
|
|
|
|
|
|
|
|
my_strncpy(xctx->plotfile, cli_opt_plotfile, S(xctx->plotfile));
|
2021-11-17 23:12:17 +01:00
|
|
|
xctx->draw_window = tclgetintvar("draw_window");
|
|
|
|
|
xctx->only_probes = tclgetintvar("only_probes");
|
2020-08-08 15:47:34 +02:00
|
|
|
|
2021-11-16 22:28:10 +01:00
|
|
|
/* set global variables fetching data from tcl code */
|
2021-11-17 01:12:55 +01:00
|
|
|
if(cli_opt_netlist_type) {
|
|
|
|
|
xctx->netlist_type = cli_opt_netlist_type;
|
|
|
|
|
set_tcl_netlist_type();
|
|
|
|
|
} else {
|
|
|
|
|
const char *n;
|
|
|
|
|
n = tclgetvar("netlist_type");
|
|
|
|
|
if(!strcmp(n, "spice")) xctx->netlist_type = CAD_SPICE_NETLIST;
|
|
|
|
|
else if(!strcmp(n, "vhdl")) xctx->netlist_type = CAD_VHDL_NETLIST;
|
|
|
|
|
else if(!strcmp(n, "verilog")) xctx->netlist_type = CAD_VERILOG_NETLIST;
|
|
|
|
|
else if(!strcmp(n, "tedax")) xctx->netlist_type = CAD_TEDAX_NETLIST;
|
|
|
|
|
else if(!strcmp(n, "symbol")) xctx->netlist_type = CAD_SYMBOL_ATTRS;
|
|
|
|
|
}
|
2021-11-16 22:28:10 +01:00
|
|
|
init_pixdata();/* populate xctx->fill_type array that is used in create_gc() to set fill styles */
|
|
|
|
|
init_color_array(0.0, 0.0);
|
2020-08-08 15:47:34 +02:00
|
|
|
my_snprintf(tmp, S(tmp), "%d",debug_var);
|
2021-10-25 17:05:43 +02:00
|
|
|
tclsetvar("debug_var",tmp );
|
|
|
|
|
tclsetvar("menu_debug_var",debug_var ? "1" : "0" );
|
2021-11-17 23:12:17 +01:00
|
|
|
if(cli_opt_flat_netlist) {
|
|
|
|
|
tclsetvar("flat_netlist","1");
|
|
|
|
|
xctx->flat_netlist = 1;
|
|
|
|
|
}
|
2020-12-03 04:20:05 +01:00
|
|
|
xctx->areaw = CADWIDTH+4*INT_WIDTH(xctx->lw); /* clip area extends 1 pixel beyond physical xctx->window area */
|
|
|
|
|
xctx->areah = CADHEIGHT+4*INT_WIDTH(xctx->lw); /* to avoid drawing clipped rectangle borders at xctx->window edges */
|
2020-12-02 15:10:47 +01:00
|
|
|
xctx->areax1 = -2*INT_WIDTH(xctx->lw);
|
|
|
|
|
xctx->areay1 = -2*INT_WIDTH(xctx->lw);
|
|
|
|
|
xctx->areax2 = xctx->areaw-2*INT_WIDTH(xctx->lw);
|
|
|
|
|
xctx->areay2 = xctx->areah-2*INT_WIDTH(xctx->lw);
|
2020-12-03 11:42:06 +01:00
|
|
|
xctx->xrect[0].x = 0;
|
|
|
|
|
xctx->xrect[0].y = 0;
|
|
|
|
|
xctx->xrect[0].width = CADWIDTH;
|
|
|
|
|
xctx->xrect[0].height = CADHEIGHT;
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strncpy(xctx->file_version, XSCHEM_FILE_VERSION, S(xctx->file_version));
|
2020-11-17 02:17:34 +01:00
|
|
|
/* compile_font() needs enabled layers, these are set after xschem.tcl loading completed
|
|
|
|
|
* so we temporarily enable all them here */
|
2021-11-16 22:28:10 +01:00
|
|
|
for(i = 0; i < cadlayers; i++) xctx->enable_layer[i] = 1;
|
2020-08-08 15:47:34 +02:00
|
|
|
compile_font();
|
|
|
|
|
/* restore current dir after loading font */
|
2020-12-03 04:20:05 +01:00
|
|
|
if(getenv("PWD")) {
|
2020-12-02 15:10:47 +01:00
|
|
|
/* $env(PWD) better than pwd_dir as it does not dereference symlinks */
|
2020-12-03 04:20:05 +01:00
|
|
|
my_strncpy(xctx->current_dirname, getenv("PWD"), S(xctx->current_dirname));
|
2020-10-13 16:23:48 +02:00
|
|
|
} else {
|
2020-12-03 04:20:05 +01:00
|
|
|
my_strncpy(xctx->current_dirname, pwd_dir, S(xctx->current_dirname));
|
2020-10-13 16:23:48 +02:00
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
/* */
|
|
|
|
|
/* X INITIALIZATION */
|
|
|
|
|
/* */
|
|
|
|
|
if( has_x ) {
|
|
|
|
|
mainwindow=Tk_MainWindow(interp);
|
|
|
|
|
if(!mainwindow) {
|
|
|
|
|
fprintf(errfp, "Tcl_AppInit() err 6: Tk_MainWindow returned NULL...\n");
|
|
|
|
|
return TCL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
display = Tk_Display(mainwindow);
|
|
|
|
|
tkwindow = Tk_NameToWindow(interp, ".drw", mainwindow);
|
|
|
|
|
Tk_MakeWindowExist(tkwindow);
|
2020-12-03 04:20:05 +01:00
|
|
|
xctx->window = Tk_WindowId(tkwindow);
|
2020-08-08 15:47:34 +02:00
|
|
|
topwindow = Tk_WindowId(mainwindow);
|
|
|
|
|
|
2020-12-03 04:20:05 +01:00
|
|
|
dbg(1, "Tcl_AppInit(): drawing window ID=0x%lx\n",xctx->window);
|
2020-08-08 15:47:34 +02:00
|
|
|
dbg(1, "Tcl_AppInit(): top window ID=0x%lx\n",topwindow);
|
2020-10-12 13:13:31 +02:00
|
|
|
dbg(1, "Tcl_AppInit(): done tkinit()\n");
|
2020-08-08 15:47:34 +02:00
|
|
|
|
2020-12-06 20:52:35 +01:00
|
|
|
screen_number = Tk_ScreenNumber(mainwindow);
|
|
|
|
|
colormap = Tk_Colormap(mainwindow);
|
2021-10-25 17:05:43 +02:00
|
|
|
screendepth = Tk_Depth(mainwindow);
|
|
|
|
|
dbg(1, "Tcl_AppInit(): screen depth: %d\n",screendepth);
|
2020-12-06 20:52:35 +01:00
|
|
|
visual = Tk_Visual(mainwindow);
|
2020-08-08 15:47:34 +02:00
|
|
|
|
2020-10-12 13:13:31 +02:00
|
|
|
/*
|
2020-08-08 15:47:34 +02:00
|
|
|
if (!XMatchVisualInfo(
|
|
|
|
|
display, XDefaultScreen(display), 24, TrueColor, &vinfo)
|
|
|
|
|
) return fprintf(errfp, "no 32 bit visual\n");
|
|
|
|
|
visual = vinfo.visual;
|
|
|
|
|
*/
|
|
|
|
|
dbg(1, "Tcl_AppInit(): done step b of xinit()\n");
|
2021-11-16 22:28:10 +01:00
|
|
|
|
|
|
|
|
create_gc();
|
|
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
dbg(1, "Tcl_AppInit(): done step c of xinit()\n");
|
2021-11-16 22:28:10 +01:00
|
|
|
if(build_colors(0.0, 0.0)) exit(-1);
|
2020-08-08 15:47:34 +02:00
|
|
|
dbg(1, "Tcl_AppInit(): done step e of xinit()\n");
|
2020-12-03 04:20:05 +01:00
|
|
|
/* xctx->save_pixmap must be created as resetwin() frees it before recreating with new size. */
|
2020-12-06 02:10:53 +01:00
|
|
|
|
2020-12-22 00:13:25 +01:00
|
|
|
resetwin(1, 0, 1, 0, 0);
|
2020-12-07 20:04:57 +01:00
|
|
|
#if HAS_CAIRO==1
|
2020-12-06 02:10:53 +01:00
|
|
|
/* load font from tcl 20171112 */
|
|
|
|
|
tclsetvar("has_cairo","1");
|
|
|
|
|
#endif
|
2020-08-08 15:47:34 +02:00
|
|
|
|
2020-12-14 19:11:24 +01:00
|
|
|
change_linewidth(l_width);
|
2020-08-08 15:47:34 +02:00
|
|
|
dbg(1, "Tcl_AppInit(): done xinit()\n");
|
2021-11-16 22:28:10 +01:00
|
|
|
/* Set backing store window attribute */
|
2020-08-08 15:47:34 +02:00
|
|
|
winattr.backing_store = WhenMapped;
|
2021-11-17 13:32:32 +01:00
|
|
|
/* winattr.backing_store = NotUseful; */
|
2020-08-08 15:47:34 +02:00
|
|
|
Tk_ChangeWindowAttributes(tkwindow, CWBackingStore, &winattr);
|
2020-10-12 13:13:31 +02:00
|
|
|
|
|
|
|
|
dbg(1, "Tcl_AppInit(): sizeof xInstance=%lu , sizeof xSymbol=%lu\n",
|
|
|
|
|
(unsigned long) sizeof(xInstance),(unsigned long) sizeof(xSymbol));
|
|
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
#ifdef __unix__
|
2020-10-12 13:13:31 +02:00
|
|
|
dbg(1, "Tcl_AppInit(): xserver max request size: %d\n",
|
2020-08-08 15:47:34 +02:00
|
|
|
(int)XMaxRequestSize(display));
|
|
|
|
|
#else
|
|
|
|
|
dbg(1, "Tcl_AppInit(): xserver max request size:\n");
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
set_snap(0); /* set default value specified in xschemrc as 'snap' else CADSNAP */
|
|
|
|
|
set_grid(0); /* set default value specified in xschemrc as 'grid' else CADGRID */
|
|
|
|
|
} /* if(has_x) */
|
|
|
|
|
dbg(1, "Tcl_AppInit(): done X init\n");
|
2020-09-07 09:34:41 +02:00
|
|
|
|
|
|
|
|
/* pass to tcl values of Alt, Shift, COntrol key masks so bind Alt-KeyPress events will work for windows */
|
2020-10-12 13:13:31 +02:00
|
|
|
#ifndef __unix__
|
2020-09-07 09:34:41 +02:00
|
|
|
my_snprintf(tmp, S(tmp), "%d", Mod1Mask);
|
|
|
|
|
tclsetvar("Mod1Mask", tmp);
|
|
|
|
|
my_snprintf(tmp, S(tmp), "%d", ShiftMask);
|
|
|
|
|
tclsetvar("ShiftMask", tmp);
|
|
|
|
|
my_snprintf(tmp, S(tmp), "%d", ControlMask);
|
|
|
|
|
tclsetvar("ControlMask", tmp);
|
|
|
|
|
#endif
|
2021-11-18 03:01:28 +01:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
/* END X INITIALIZATION */
|
|
|
|
|
init_done=1; /* 20171008 moved before option processing, otherwise xwin_exit will not be invoked */
|
|
|
|
|
/* leaving undo buffer and other garbage around. */
|
2020-08-31 13:54:37 +02:00
|
|
|
/* */
|
2021-11-09 19:05:56 +01:00
|
|
|
/* Completing tk windows creation (see xschem.tcl, pack_widgets) and event binding */
|
2020-10-12 13:13:31 +02:00
|
|
|
/* *AFTER* X initialization done */
|
2020-08-31 13:54:37 +02:00
|
|
|
/* */
|
2021-11-18 03:01:28 +01:00
|
|
|
if(has_x) {
|
2022-01-11 02:01:11 +01:00
|
|
|
tclsetintvar("tctx::max_new_windows", MAX_NEW_WINDOWS);
|
2021-11-18 03:01:28 +01:00
|
|
|
tcleval("pack_widgets; set_bindings .drw");
|
|
|
|
|
}
|
2020-08-31 13:54:37 +02:00
|
|
|
|
2021-11-10 13:43:08 +01:00
|
|
|
fs=tclgetintvar("fullscreen");
|
|
|
|
|
if(fs) {
|
|
|
|
|
tclsetvar("fullscreen", "0");
|
2020-09-07 15:20:22 +02:00
|
|
|
tcleval("update");
|
2021-11-09 19:05:56 +01:00
|
|
|
toggle_fullscreen(".");
|
2020-09-07 15:20:22 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-04 02:56:11 +01:00
|
|
|
if(tclgetboolvar("case_insensitive")) {
|
|
|
|
|
xctx->case_insensitive = 1;
|
|
|
|
|
xctx->x_strcmp = my_strcasecmp;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
/* */
|
|
|
|
|
/* START PROCESSING USER OPTIONS */
|
|
|
|
|
/* */
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
/* set tcl netlist_dir if netlist_dir given on cmdline */
|
2021-11-23 17:02:36 +01:00
|
|
|
if(cli_opt_netlist_dir[0]) tclsetvar("netlist_dir", cli_opt_netlist_dir);
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
if(!set_netlist_dir(0, NULL)) {
|
2021-11-23 17:02:36 +01:00
|
|
|
const char *n;
|
|
|
|
|
n = tclgetvar("netlist_dir");
|
|
|
|
|
fprintf(errfp, "problems creating netlist directory %s\n", n ? n : "<NULL>");
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2022-01-16 01:12:43 +01:00
|
|
|
if(cli_opt_initial_netlist_name[0]) my_strncpy(xctx->netlist_name, cli_opt_initial_netlist_name, S(cli_opt_initial_netlist_name));
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
enable_layers();
|
|
|
|
|
|
2020-10-13 17:51:14 +02:00
|
|
|
/* prefer using env(PWD) if existing since it does not dereference symlinks */
|
|
|
|
|
if(tcleval("info exists env(PWD)")[0] == '1') {
|
|
|
|
|
my_snprintf(pwd_dir, S(pwd_dir), "%s", tclgetvar("env(PWD)"));
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-10 18:54:07 +01:00
|
|
|
if(cli_opt_filename[0]) {
|
2020-10-13 01:07:28 +02:00
|
|
|
char f[PATH_MAX];
|
2020-10-14 01:38:51 +02:00
|
|
|
|
|
|
|
|
#ifdef __unix__
|
2022-01-10 18:54:07 +01:00
|
|
|
if(cli_opt_filename[0] == '~' && cli_opt_filename[1] == '/') {
|
|
|
|
|
my_snprintf(f, S(f), "%s%s", home_dir, cli_opt_filename + 1);
|
|
|
|
|
} else if(cli_opt_filename[0] == '.' && cli_opt_filename[1] == '/') {
|
|
|
|
|
my_snprintf(f, S(f), "%s%s", pwd_dir, cli_opt_filename + 1);
|
|
|
|
|
} else if(cli_opt_filename[0] !='/') {
|
|
|
|
|
my_snprintf(f, S(f), "%s/%s", pwd_dir, cli_opt_filename);
|
2021-10-10 00:44:01 +02:00
|
|
|
} else {
|
2022-01-10 18:54:07 +01:00
|
|
|
my_snprintf(f, S(f), "%s", cli_opt_filename);
|
2021-10-10 00:44:01 +02:00
|
|
|
}
|
2020-10-14 01:38:51 +02:00
|
|
|
#else
|
2022-01-10 18:54:07 +01:00
|
|
|
my_strncpy(f, abs_sym_path(cli_opt_filename, ""), S(f));
|
2020-10-14 01:38:51 +02:00
|
|
|
#endif
|
2022-01-10 18:54:07 +01:00
|
|
|
dbg(1, "Tcl_AppInit(): cli_opt_filename %s given, removing symbols\n", cli_opt_filename);
|
2021-10-10 00:44:01 +02:00
|
|
|
remove_symbols();
|
2022-01-16 01:12:43 +01:00
|
|
|
/* if cli_opt_do_netlist=1 call load_schematic with 'reset_undo=0' avoiding call
|
2021-11-16 22:28:10 +01:00
|
|
|
to tcl is_xschem_file that could change xctx->netlist_type to symbol */
|
2022-01-16 01:12:43 +01:00
|
|
|
load_schematic(1, f, !cli_opt_do_netlist);
|
2021-12-05 12:39:05 +01:00
|
|
|
tclvareval("update_recent_file {", f, "}", NULL);
|
2022-01-16 01:12:43 +01:00
|
|
|
} else if(!cli_opt_tcl_script[0]) {
|
2020-10-12 13:13:31 +02:00
|
|
|
char * tmp;
|
2022-01-10 18:54:07 +01:00
|
|
|
char fname[PATH_MAX];
|
2020-10-12 13:13:31 +02:00
|
|
|
tmp = (char *) tclgetvar("XSCHEM_START_WINDOW");
|
2021-12-04 01:50:05 +01:00
|
|
|
#ifndef __unix__
|
|
|
|
|
change_to_unix_fn(tmp);
|
|
|
|
|
#endif
|
2020-08-08 15:47:34 +02:00
|
|
|
dbg(1, "Tcl_AppInit(): tmp=%s\n", tmp? tmp: "NULL");
|
2022-01-10 18:54:07 +01:00
|
|
|
my_strncpy(fname, abs_sym_path(tmp, ""), S(fname));
|
2022-01-16 01:12:43 +01:00
|
|
|
/* if cli_opt_do_netlist=1 call load_schematic with 'reset_undo=0' avoiding call
|
2021-11-16 22:28:10 +01:00
|
|
|
to tcl is_xschem_file that could change xctx->netlist_type to symbol */
|
2022-01-16 01:12:43 +01:00
|
|
|
load_schematic(1, fname, !cli_opt_do_netlist);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-09-30 00:55:34 +02:00
|
|
|
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2021-11-16 22:28:10 +01:00
|
|
|
zoom_full(0, 0, 1, 0.97); /* Necessary to tell xschem the initial area to display */
|
2021-10-25 17:05:43 +02:00
|
|
|
xctx->pending_fullzoom=1;
|
2022-01-16 01:12:43 +01:00
|
|
|
if(cli_opt_do_netlist) {
|
2020-08-08 15:47:34 +02:00
|
|
|
if(debug_var>=1) {
|
2021-11-17 23:12:17 +01:00
|
|
|
if(xctx->flat_netlist)
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(errfp, "xschem: flat netlist requested\n");
|
|
|
|
|
}
|
2022-01-10 18:54:07 +01:00
|
|
|
if(!cli_opt_filename[0]) {
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(errfp, "xschem: cant do a netlist without a filename\n");
|
2021-11-16 22:28:10 +01:00
|
|
|
tcleval("exit");
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2021-11-23 17:02:36 +01:00
|
|
|
if(tclgetvar("netlist_dir")[0]) {
|
2021-11-16 22:28:10 +01:00
|
|
|
if(xctx->netlist_type == CAD_SPICE_NETLIST)
|
2020-08-08 15:47:34 +02:00
|
|
|
global_spice_netlist(1); /* 1 means global netlist */
|
2021-11-16 22:28:10 +01:00
|
|
|
else if(xctx->netlist_type == CAD_VHDL_NETLIST)
|
2020-08-08 15:47:34 +02:00
|
|
|
global_vhdl_netlist(1); /* 1 means global netlist */
|
2021-11-16 22:28:10 +01:00
|
|
|
else if(xctx->netlist_type == CAD_VERILOG_NETLIST)
|
2020-08-08 15:47:34 +02:00
|
|
|
global_verilog_netlist(1); /* 1 means global netlist */
|
2021-11-16 22:28:10 +01:00
|
|
|
else if(xctx->netlist_type == CAD_TEDAX_NETLIST)
|
2020-08-08 15:47:34 +02:00
|
|
|
global_tedax_netlist(1); /* 1 means global netlist */
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(errfp, "xschem: please set netlist_dir in xschemrc\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-16 01:12:43 +01:00
|
|
|
if(cli_opt_do_print) {
|
2022-01-10 18:54:07 +01:00
|
|
|
if(!cli_opt_filename[0]) {
|
2020-08-31 13:54:37 +02:00
|
|
|
dbg(0, "xschem: can't do a print without a filename\n");
|
2021-11-16 22:28:10 +01:00
|
|
|
tcleval("exit");
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2022-01-16 01:12:43 +01:00
|
|
|
if(cli_opt_do_print==1) {
|
2020-12-17 03:48:34 +01:00
|
|
|
|
|
|
|
|
xctx->xrect[0].x = 0;
|
|
|
|
|
xctx->xrect[0].y = 0;
|
2021-12-22 04:39:23 +01:00
|
|
|
xctx->xrect[0].width = 842;
|
|
|
|
|
xctx->xrect[0].height = 595;
|
2020-12-17 03:48:34 +01:00
|
|
|
xctx->areax2 = 842+2;
|
|
|
|
|
xctx->areay2 = 595+2;
|
|
|
|
|
xctx->areax1 = -2;
|
|
|
|
|
xctx->areay1 = -2;
|
|
|
|
|
xctx->areaw = xctx->areax2-xctx->areax1;
|
|
|
|
|
xctx->areah = xctx->areay2-xctx->areay1;
|
2020-12-22 00:13:25 +01:00
|
|
|
zoom_full(0, 0, 2, 0.97);
|
2021-06-13 23:55:17 +02:00
|
|
|
ps_draw(7);
|
2022-01-16 01:12:43 +01:00
|
|
|
} else if(cli_opt_do_print == 2) {
|
2020-08-31 13:54:37 +02:00
|
|
|
if(!has_x) {
|
|
|
|
|
dbg(0, "xschem: can not do a png export if no X11 present / Xserver running (check if DISPLAY set).\n");
|
|
|
|
|
} else {
|
|
|
|
|
tcleval("tkwait visibility .drw");
|
2020-12-22 00:13:25 +01:00
|
|
|
print_image();
|
2020-08-31 13:54:37 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-12-22 00:13:25 +01:00
|
|
|
else svg_draw();
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
|
2022-01-16 01:12:43 +01:00
|
|
|
if(cli_opt_do_simulation) {
|
2022-01-10 18:54:07 +01:00
|
|
|
if(!cli_opt_filename[0]) {
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(errfp, "xschem: can't do a simulation without a filename\n");
|
2021-11-16 22:28:10 +01:00
|
|
|
tcleval("exit");
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
tcleval( "simulate");
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-16 01:12:43 +01:00
|
|
|
if(cli_opt_do_waves) {
|
2022-01-10 18:54:07 +01:00
|
|
|
if(!cli_opt_filename[0]) {
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(errfp, "xschem: can't show simulation waves without a filename\n");
|
2021-11-16 22:28:10 +01:00
|
|
|
tcleval("exit");
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
tcleval( "waves [file tail \"[xschem get schname]\"]");
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-13 02:08:36 +01:00
|
|
|
/* */
|
|
|
|
|
/* SOURCE XSCHEMRC SUPPLIED TCL FILES */
|
|
|
|
|
/* */
|
|
|
|
|
tcleval("update; source_user_tcl_files");
|
|
|
|
|
|
2021-11-16 22:28:10 +01:00
|
|
|
/* source tcl file given on command line with --script */
|
2022-01-16 01:12:43 +01:00
|
|
|
if(cli_opt_tcl_script[0]) {
|
2021-12-08 00:38:19 +01:00
|
|
|
char str[PATH_MAX + 40];
|
|
|
|
|
/* can not use tclvareval() here because if script contains 'exit'
|
|
|
|
|
* program terminates before tclvareval() has a chance to cleanup
|
|
|
|
|
* its dynamically allocated string
|
|
|
|
|
*/
|
2022-01-16 01:12:43 +01:00
|
|
|
my_snprintf(str, S(str), "update; source {%s}", cli_opt_tcl_script);
|
2022-01-13 02:08:36 +01:00
|
|
|
tcleval(str);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(quit) {
|
2021-11-16 22:28:10 +01:00
|
|
|
tcleval("exit");
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
|
2022-01-15 13:19:06 +01:00
|
|
|
|
|
|
|
|
/* load additional files */
|
2022-01-15 23:35:37 +01:00
|
|
|
if(has_x) for(i = 2; i < cli_opt_argc; i++) {
|
2022-01-15 13:19:06 +01:00
|
|
|
tclvareval("xschem load_new_window ", cli_opt_argv[i], NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
/* */
|
|
|
|
|
/* END PROCESSING USER OPTIONS */
|
|
|
|
|
/* */
|
|
|
|
|
|
2020-08-31 13:54:37 +02:00
|
|
|
|
2022-01-16 01:12:43 +01:00
|
|
|
if(!detach && !cli_opt_no_readline) {
|
2020-08-08 15:47:34 +02:00
|
|
|
tcleval( "if {![catch {package require tclreadline}]} "
|
2021-11-16 22:28:10 +01:00
|
|
|
"{::tclreadline::readline builtincompleter 0;"
|
|
|
|
|
/* "::tclreadline::readline customcompleter completer;" */
|
|
|
|
|
"::tclreadline::Loop }"
|
|
|
|
|
);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbg(1, "Tcl_AppInit(): returning TCL_OK\n");
|
|
|
|
|
return TCL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|