fix regression (tcl context was not saved/restored correctly)

This commit is contained in:
Stefan Frederik 2022-02-02 00:11:46 +01:00
parent 200f4210d0
commit a8e1a6c047
8 changed files with 451 additions and 286 deletions

View File

@ -270,6 +270,51 @@
<Component Id="cmp9C61E6C73B92F631D2F4921DBC7E27AA" Guid="{7EFC602D-8DD1-4269-8307-DB293A17C3FE}">
<File Id="fil8D7933E7D123C25695CC78C1148017A9" KeyPath="yes" Source="$(var.docSrcDir)\xschem_man\global_property.png" />
</Component>
<Component Id="cmp740874B224A56CFE2CCF34DF58E60FD0" Guid="{306D7CE9-B69C-49A8-9AE9-658A1A2EFF06}">
<File Id="filFABFA28AE6A48C24358CBBA3588306CB" KeyPath="yes" Source="$(var.docSrcDir)\xschem_man\graphs.html" />
</Component>
<Component Id="cmpC813583375804396B97AED14720B5626" Guid="{913470B7-9D06-4401-8EE8-F41790CB6EA5}">
<File Id="filD674B9C36FC8FC7540A8F39A53224E43" KeyPath="yes" Source="$(var.docSrcDir)\xschem_man\graphs01.png" />
</Component>
<Component Id="cmp230FF209E9F582A4F1E7648DE73456CB" Guid="{9EF81220-D963-4DEE-A1AE-C7BDE61BCE47}">
<File Id="fil7773B42F33BFE9332820D40733863C14" KeyPath="yes" Source="$(var.docSrcDir)\xschem_man\graphs02.png" />
</Component>
<Component Id="cmp5A9CD2054A04C919AE72DE3D1F353CFE" Guid="{8B52AA1A-B751-4982-9CDA-A21B6E2FE61F}">
<File Id="filB457E827354F127DA98F8DCD47733AA2" KeyPath="yes" Source="$(var.docSrcDir)\xschem_man\graphs03.png" />
</Component>
<Component Id="cmpB7FFDE35B0ABD817CB7911FF1EA95EBF" Guid="{100C8AC8-A6BF-4F96-B7AE-7D6E12456E31}">
<File Id="filD9D670302F61B3C48E80E43A46E114B0" KeyPath="yes" Source="$(var.docSrcDir)\xschem_man\graphs04.png" />
</Component>
<Component Id="cmp5BD82B4625C5DDDFD12CA154246CEEBD" Guid="{E70CF0E5-CBDE-425C-90B0-CBEF0843A2AB}">
<File Id="fil5A95EA74DE26FD2DBCEEB19E406EBF8B" KeyPath="yes" Source="$(var.docSrcDir)\xschem_man\graphs05.png" />
</Component>
<Component Id="cmpE93F45A345CBCE6CE0BFB45A0B8A1CFE" Guid="{0FC564A2-3C92-45A7-A2C6-47F7C3241CB7}">
<File Id="filF9EACF3BBD6AFC5E2B516EDE4CFD19CD" KeyPath="yes" Source="$(var.docSrcDir)\xschem_man\graphs06.png" />
</Component>
<Component Id="cmp51DB9959998196E893263640FEB98E34" Guid="{8296CC84-051B-4AF4-8FED-6E988343CA67}">
<File Id="fil8DBF11E3DB65C1FBB2C28F8467D9A91D" KeyPath="yes" Source="$(var.docSrcDir)\xschem_man\graphs07.png" />
</Component>
<Component Id="cmpDF1717CE9FBAD9506F3230EBCF486304" Guid="{5BDC9631-7443-4E50-AC19-2EEE58A8955E}">
<File Id="fil70A651707CB61D244A0E2AEBF8BB18B3" KeyPath="yes" Source="$(var.docSrcDir)\xschem_man\graphs08.png" />
</Component>
<Component Id="cmp85DFC1BFDBD576871E2F52C6F43B78E6" Guid="{EEE32424-3832-487A-973A-96508B125EF1}">
<File Id="fil1C6DD758E0BE985AF7F2C3CD7FCFA125" KeyPath="yes" Source="$(var.docSrcDir)\xschem_man\graphs09.png" />
</Component>
<Component Id="cmp14AEDEF10B42CBCD0FCDB294E7D40813" Guid="{77C6AA29-772A-4235-881A-07E58A1E4832}">
<File Id="filA8DD27097EEA145C9FD6912B91142EC8" KeyPath="yes" Source="$(var.docSrcDir)\xschem_man\graphs10.png" />
</Component>
<Component Id="cmpD3F50248B5661D0762D1937C118E395E" Guid="{18D80823-6693-4881-808A-B947057B27B8}">
<File Id="fil3C2EE361B66A1E6337E4223BE26200DB" KeyPath="yes" Source="$(var.docSrcDir)\xschem_man\graphs11.png" />
</Component>
<Component Id="cmpE98EB455E6D39076B1A40C1CAB3D835E" Guid="{317CD41E-AAE2-40B6-A408-050AC585C2A5}">
<File Id="fil23F611BD2A702D7E3820AD7C74811351" KeyPath="yes" Source="$(var.docSrcDir)\xschem_man\graphs12.png" />
</Component>
<Component Id="cmp5D66F2AD13E998B64847AB8B0624EE21" Guid="{9E78E24A-858A-43AF-B143-03CDD602124F}">
<File Id="fil94720C4E20330274DB4C89C8EBE7B2FC" KeyPath="yes" Source="$(var.docSrcDir)\xschem_man\graphs13.png" />
</Component>
<Component Id="cmp99C532DCC5EF9E1CD1D26BED58B2934E" Guid="{25622185-DA1B-43B3-89E5-646B7AE4E02C}">
<File Id="fil04166376BFA25115160171891B16FB23" KeyPath="yes" Source="$(var.docSrcDir)\xschem_man\graphs14.png" />
</Component>
<Component Id="cmp7D84114D6FDF0E09CB66A982B3C581C3" Guid="{06F4736F-88F7-459A-BF81-9F04C78C45B7}">
<File Id="fil00E7CE2F76CC18FC1618A1670E025C42" KeyPath="yes" Source="$(var.docSrcDir)\xschem_man\gschemtoxschem.png" />
</Component>
@ -901,6 +946,21 @@
<ComponentRef Id="cmpFDD3D37AEDD41E4A735CC0D0B06FF0E7" />
<ComponentRef Id="cmpE04977F0950425CA6A35D7443890FEDA" />
<ComponentRef Id="cmp9C61E6C73B92F631D2F4921DBC7E27AA" />
<ComponentRef Id="cmp740874B224A56CFE2CCF34DF58E60FD0" />
<ComponentRef Id="cmpC813583375804396B97AED14720B5626" />
<ComponentRef Id="cmp230FF209E9F582A4F1E7648DE73456CB" />
<ComponentRef Id="cmp5A9CD2054A04C919AE72DE3D1F353CFE" />
<ComponentRef Id="cmpB7FFDE35B0ABD817CB7911FF1EA95EBF" />
<ComponentRef Id="cmp5BD82B4625C5DDDFD12CA154246CEEBD" />
<ComponentRef Id="cmpE93F45A345CBCE6CE0BFB45A0B8A1CFE" />
<ComponentRef Id="cmp51DB9959998196E893263640FEB98E34" />
<ComponentRef Id="cmpDF1717CE9FBAD9506F3230EBCF486304" />
<ComponentRef Id="cmp85DFC1BFDBD576871E2F52C6F43B78E6" />
<ComponentRef Id="cmp14AEDEF10B42CBCD0FCDB294E7D40813" />
<ComponentRef Id="cmpD3F50248B5661D0762D1937C118E395E" />
<ComponentRef Id="cmpE98EB455E6D39076B1A40C1CAB3D835E" />
<ComponentRef Id="cmp5D66F2AD13E998B64847AB8B0624EE21" />
<ComponentRef Id="cmp99C532DCC5EF9E1CD1D26BED58B2934E" />
<ComponentRef Id="cmp7D84114D6FDF0E09CB66A982B3C581C3" />
<ComponentRef Id="cmpDB80566B13B66B2A92E91DA0585404A9" />
<ComponentRef Id="cmp8C7AB373FA963AF5F88C8B394FB28B19" />

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,8 @@
/*************************************************************/
/* Define to 1 if cairo is available and is to be used */
/*#undef HAS_CAIRO */
/* #define HAS_CAIRO 1
#define CAIRO_WIN32_STATIC_BUILD 1 */
/* Define to 1 if Xlib's xcb is available */
/*#undef HAS_XCB */

View File

@ -78,34 +78,43 @@ void print_image()
tclsetvar("draw_grid", "0");
xctx->draw_pixmap=1;
draw();
#ifdef __unix__
#if HAS_CAIRO == 1 /* use cairo native support for png writing, no need to convert
* XPM and handles Xrender extensions for transparent embedded images */
{
cairo_surface_t *png_sfc;
#ifdef __unix__
png_sfc = cairo_xlib_surface_create(display, xctx->save_pixmap, visual,
xctx->xrect[0].width, xctx->xrect[0].height);
#else
HWND hwnd = Tk_GetHWND(xctx->window);
HDC dc = GetDC(hwnd);
png_sfc = cairo_win32_surface_create(dc);
#endif
if(xctx->plotfile[0])
cairo_surface_write_to_png(png_sfc, xctx->plotfile);
else
cairo_surface_write_to_png(png_sfc, "plot.png");
}
#else /* no cairo */
#ifdef __unix__
XpmWriteFileFromPixmap(display, "plot.xpm", xctx->save_pixmap,0, NULL ); /* .gz ???? */
dbg(1, "print_image(): Window image saved\n");
if(xctx->plotfile[0]) {
my_snprintf(cmd, S(cmd), "convert_to_png plot.xpm {%s}", xctx->plotfile);
tcleval(cmd);
} else tcleval( "convert_to_png plot.xpm plot.png");
#endif
#else
char *psfile=NULL;
#else
char *psfile = NULL;
create_ps(&psfile, 7);
if(xctx->plotfile[0]) {
if (xctx->plotfile[0]) {
my_snprintf(cmd, S(cmd), "convert_to_png {%s} {%s}", psfile, xctx->plotfile);
tcleval(cmd);
} else tcleval( "convert_to_png {%s} plot.png", psfile);
}
else tcleval("convert_to_png {%s} plot.png", psfile);
#endif
#endif
my_strncpy(xctx->plotfile,"", S(xctx->plotfile));
tclsetboolvar("draw_grid", save_draw_grid);
@ -113,8 +122,9 @@ void print_image()
}
#if HAS_CAIRO==1
void set_cairo_color(int layer)
void set_cairo_color(int layer)
{
#ifdef __unix__
cairo_set_source_rgb(xctx->cairo_ctx,
(double)xctx->xcolor_array[layer].red/65535.0,
(double)xctx->xcolor_array[layer].green/65535.0,
@ -123,6 +133,10 @@ void set_cairo_color(int layer)
(double)xctx->xcolor_array[layer].red/65535.0,
(double)xctx->xcolor_array[layer].green/65535.0,
(double)xctx->xcolor_array[layer].blue/65535.0);
#else /* temporary until I get find_best_color to work on Windows */
cairo_set_source_rgb(xctx->cairo_ctx, 1, 0, 0);
cairo_set_source_rgb(xctx->cairo_save_ctx, 1, 0, 0);
#endif
}
/* remember to call cairo_restore(xctx->cairo_ctx) when done !! */

View File

@ -222,13 +222,16 @@ unsigned char *base64_decode(const char *data, const size_t input_length, size_t
* data layout in memory arranged to maximize cache locality
* when looking up data
*/
static void read_binary_block(FILE *fd)
static void read_binary_block(FILE *fd, int sim_type)
{
int p, v;
double *tmp;
size_t size = 0;
int offset = 0;
int mult = 0;
double val;
if(sim_type == 3) mult = 1; /* AC analysis, complex numbers twice the size */
for(p = 0 ; p < xctx->graph_datasets; p++) {
size += xctx->graph_nvars * xctx->graph_npoints[p];
@ -236,19 +239,24 @@ static void read_binary_block(FILE *fd)
}
/* read buffer */
tmp = my_calloc(1405, xctx->graph_nvars, sizeof(double *));
tmp = my_calloc(1405, xctx->graph_nvars, (sizeof(double *) << mult));
/* allocate storage for binary block */
if(!xctx->graph_values) xctx->graph_values = my_calloc(118, xctx->graph_nvars, sizeof(SPICE_DATA *));
for(p = 0 ; p < xctx->graph_nvars; p++) {
my_realloc(372, &xctx->graph_values[p], (size + xctx->graph_npoints[xctx->graph_datasets]) * sizeof(double));
my_realloc(372,
&xctx->graph_values[p], (size + xctx->graph_npoints[xctx->graph_datasets]) * sizeof(SPICE_DATA));
}
/* read binary block */
for(p = 0; p < xctx->graph_npoints[xctx->graph_datasets]; p++) {
if(fread(tmp, sizeof(double), xctx->graph_nvars, fd) != xctx->graph_nvars) {
if(fread(tmp, (sizeof(double) << mult), xctx->graph_nvars, fd) != xctx->graph_nvars) {
dbg(0, "Warning: binary block is not of correct size\n");
}
/* assign to xschem struct, memory aligned per variable, for cache locality */
for(v = 0; v < xctx->graph_nvars; v++) {
if(mult) for(v = 0; v < xctx->graph_nvars; v++) { /*AC analysis: calculate magnitude */
xctx->graph_values[v][offset + p] =
sqrt( tmp[v << mult] * tmp[v << mult] + tmp[(v << mult) + 1] * tmp[(v << mult) + 1]);
}
else for(v = 0; v < xctx->graph_nvars; v++) {
xctx->graph_values[v][offset + p] = tmp[v];
}
}
@ -292,7 +300,7 @@ static int read_dataset(FILE *fd)
int npoints = xctx->graph_npoints[xctx->graph_datasets];
if(sim_type) {
done_header = 1;
read_binary_block(fd);
read_binary_block(fd, sim_type);
dbg(1, "read_dataset(): read binary block, nvars=%d npoints=%d\n", xctx->graph_nvars, npoints);
xctx->graph_datasets++;
exit_status = 1;
@ -310,6 +318,10 @@ static int read_dataset(FILE *fd)
if(sim_type && sim_type != 2) sim_type = 0;
else sim_type = 2;
}
else if(!strncmp(line, "Plotname: AC Analysis", 21)) {
if(sim_type && sim_type != 3) sim_type = 0;
else sim_type = 3;
}
else if(!strncmp(line, "Plotname:", 9)) {
sim_type = 0;
}

View File

@ -1532,8 +1532,15 @@ void resetcairo(int create, int clear, int force_or_resize)
cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_FAST);
cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_SLIGHT);
/***** Create Cairo save buffer drawing area *****/
#ifdef __unix__
xctx->cairo_save_sfc =
cairo_xlib_surface_create(display, xctx->save_pixmap, visual, xctx->xrect[0].width, xctx->xrect[0].height);
#else
HWND hwnd = Tk_GetHWND(xctx->window);
HDC dc = GetDC(hwnd);
xctx->cairo_save_sfc = cairo_win32_surface_create(dc);
cairo_surface_set_device_scale(xctx->cairo_save_sfc, 1, 1);
#endif
if(cairo_surface_status(xctx->cairo_save_sfc)!=CAIRO_STATUS_SUCCESS) {
fprintf(errfp, "ERROR: invalid cairo xcb surface\n");
}
@ -1549,8 +1556,13 @@ void resetcairo(int create, int clear, int force_or_resize)
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 *****/
#ifdef __unix__
xctx->cairo_sfc = cairo_xlib_surface_create(display, xctx->window, visual,
xctx->xrect[0].width, xctx->xrect[0].height);
#else
xctx->cairo_sfc = cairo_win32_surface_create(dc);
cairo_surface_set_device_scale(xctx->cairo_sfc, 1, 1);
#endif
if(cairo_surface_status(xctx->cairo_sfc)!=CAIRO_STATUS_SUCCESS) {
fprintf(errfp, "ERROR: invalid cairo surface\n");
}

View File

@ -103,8 +103,12 @@ extern char win_temp_dir[PATH_MAX];
#if HAS_CAIRO==1
#include <cairo.h>
#if __unix__
#include <cairo-xlib.h>
#include "cairo-xlib-xrender.h"
#else
#include <cairo-win32.h>
#endif
#endif
#include <tcl.h>

View File

@ -4529,18 +4529,19 @@ proc delete_ctx {context} {
}
proc restore_ctx {context} {
# puts "restoring tcl context $context : semaphore=[xschem get semaphore]"
global has_x
if {![info exists $has_x]} {return}
if {![info exists has_x]} {return}
# puts "restoring tcl context $context : semaphore=[xschem get semaphore]"
set tctx::tctx $context
array unset ::sim
uplevel #0 {
if { [ array exists $tctx::tctx ] } {
# puts "restore_ctx $tctx::tctx"
# Cleanup these vars to avoid side effects from previous ctx
## Cleanup these vars to avoid side effects from previous ctx
unset -nocomplain gaw_fd
foreach tctx::i $tctx::global_list {
if { [info exists [subst $tctx::tctx]($tctx::i)] } {
# puts "restoring: $tctx::i"
set $tctx::i [set [subst $tctx::tctx]($tctx::i)]
}
}
@ -4554,14 +4555,15 @@ proc restore_ctx {context} {
}
proc save_ctx {context} {
# puts "saving tcl context $context : semaphore=[xschem get semaphore]"
global has_x
if {![info exists $has_x]} {return}
if {![info exists has_x]} {return}
# puts "saving tcl context $context : semaphore=[xschem get semaphore]"
set tctx::tctx $context
uplevel #0 {
# puts "save_ctx $tctx::tctx"
foreach tctx::i $tctx::global_list {
if { [info exists $tctx::i] } {
# puts "saving: $tctx::i"
set [subst $tctx::tctx]($tctx::i) [set $tctx::i]
}
}