From baca559ffcc4cf5c9a53a636fbda5e349e23492b Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Wed, 1 Feb 2023 00:23:33 +0100 Subject: [PATCH] refactor some code (use set_text_flags() to avoid repetitive code), add xschem setprop text and xschem getprop text commands to set/get text attributes --- XSchemWin/README_WIN | 20 + XSchemWin/XSchemWin_cairo.vcxproj | 18 +- XSchemWin/XSchemWix/doc.wxs | 16 + XSchemWin/XSchemWix/heat_doc.wxs | 642 +++++++++++++------------- XSchemWin/config.h | 3 + src/actions.c | 49 +- src/cairo_jpg.c | 9 + src/create_alloc_ids.awk | 1 - src/editprop.c | 19 +- src/move.c | 22 +- src/paste.c | 23 +- src/save.c | 76 +-- src/scheduler.c | 77 ++- src/xschem.h | 1 + xschem_library/examples/rlc.sch | 128 ++++- xschem_library/ngspice/pv_ngspice.sch | 2 +- 16 files changed, 623 insertions(+), 483 deletions(-) diff --git a/XSchemWin/README_WIN b/XSchemWin/README_WIN index 3861c193..da7a2028 100644 --- a/XSchemWin/README_WIN +++ b/XSchemWin/README_WIN @@ -41,6 +41,8 @@ INSTRUCTIONS TO COMPILE XSCHEM IN VISUAL STUDIO 2022 Optional: - Windows Ghostscript (to print) Add directory of gswin64.exe to PATH if installer didn't do it + - Jpeg for Windows (GNU Win32) + http://www.ijg.org *** NOTE: DO 2A OR 2B, but NOT BOTH *** 2A. Steps in (2B) are already saved in XSchemWin/XSchemWin.sln. @@ -149,3 +151,21 @@ INSTRUCTIONS TO COMPILE CAIRO AND COMPILE XSCHEM WITH IT ON VISUAL STUDIO 2022 * Properties > VC++ Directories > Include: ;cairo_win\cairo\src;cairo_win\projects\cairo\src; Libraries: ;cairo_win\projects\x64\Debug;cairo_win\libs;cairo_win\freetype\objs\x64\Debug Static * Properties > Linker > Input > Additional Dependencies: Add ;cairo.lib;pixman.lib;zlibd.lib;libpngd.lib;freetype.lib; + +OPTIONAL: INSTRUCTIONS TO COMPILE WITH JPEG FOR WINDOW (To be used with CAIRO) + 1. Download jpegsr9e.zip from http://www.ijg.org/ (as of 1/30/2023) + 2. Unzip jpeg-9e into cairo_win directory (See above) + 3. Open the Developer Command Prompt for VS 2022 (Tools > Command Line > Developer Command Prompt) + 4. cd to source in (2) + 5. Type: nmake /f makefile.vs setupcopy-v17 + 6. Open the solution file jpeg.sln, build the library project. + 7. Build for Release, x64 + + Updating Xschem's properties and compile: + + Uncomment the following from config.h + a. /* #define HAS_LIBJPEG 1 */ + b. For Release and Debug, x64 + * Properties > VC++ Directories > Include: ;cairo_win\jpeg-9e + Libraries: ;cairo_win\jpeg-9e\Release\x64 + * Properties > Linker > Input > Additional Dependencies: Add ;jpeg.lib \ No newline at end of file diff --git a/XSchemWin/XSchemWin_cairo.vcxproj b/XSchemWin/XSchemWin_cairo.vcxproj index 9320989d..793d0135 100644 --- a/XSchemWin/XSchemWin_cairo.vcxproj +++ b/XSchemWin/XSchemWin_cairo.vcxproj @@ -102,8 +102,8 @@ true - $(VC_IncludePath);$(WindowsSDK_IncludePath);C:\ActiveTcl\include;cairo_win\cairo\src;cairo_win\projects\cairo\src; - $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;C:\ActiveTcl\lib;cairo_win\projects\x64\Debug;cairo_win\libs;cairo_win\freetype\objs\x64\Debug Static + $(VC_IncludePath);$(WindowsSDK_IncludePath);C:\ActiveTcl\include;cairo_win\cairo\src;cairo_win\projects\cairo\src;cairo_win\jpeg-9e + $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;C:\ActiveTcl\lib;cairo_win\projects\x64\Debug;cairo_win\libs;cairo_win\freetype\objs\x64\Debug Static;cairo_win\jpeg-9e\Release\x64 $(VC_ExecutablePath_x64);$(CommonExecutablePath);D:\GnuWin32\bin XSchem @@ -115,15 +115,15 @@ false - $(VC_IncludePath);$(WindowsSDK_IncludePath);C:\ActiveTcl\include;cairo_win\cairo\src;cairo_win\projects\cairo\src; - $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;C:\ActiveTcl\lib;cairo_win\projects\x64\Release;cairo_win\libs;cairo_win/freetype\objs\x64\Release Static + $(VC_IncludePath);$(WindowsSDK_IncludePath);C:\ActiveTcl\include;cairo_win\cairo\src;cairo_win\projects\cairo\src;cairo_win\jpeg-9e + $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;C:\ActiveTcl\lib;cairo_win\projects\x64\Release;cairo_win\libs;cairo_win/freetype\objs\x64\Release Static;cairo_win\jpeg-9e\Release\x64 $(VC_ExecutablePath_x64);$(CommonExecutablePath);D:\GnuWin32\bin XSchem false - $(VC_IncludePath);$(WindowsSDK_IncludePath);C:\myTcl86\include;cairo_win\cairo\src;cairo_win\projects\cairo\src; - $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;C:\myTcl86\lib;cairo_win\projects\x64\Release;cairo_win\libs;cairo_win/freetype\objs\x64\Release Static + $(VC_IncludePath);$(WindowsSDK_IncludePath);C:\myTcl86\include;cairo_win\cairo\src;cairo_win\projects\cairo\src;cairo_win\jpeg-9e + $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;C:\myTcl86\lib;cairo_win\projects\x64\Release;cairo_win\libs;cairo_win/freetype\objs\x64\Release Static;cairo_win\jpeg-9e\Release\x64 $(VC_ExecutablePath_x64);$(CommonExecutablePath);D:\GnuWin32\bin XSchem @@ -150,7 +150,7 @@ Console true - cairo.lib;pixman.lib;zlibd.lib;libpngd.lib;freetype.lib;tcl86t.lib;tk86t.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + jpeg.lib;cairo.lib;pixman.lib;zlibd.lib;libpngd.lib;freetype.lib;tcl86t.lib;tk86t.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -200,7 +200,7 @@ true true true - cairo.lib;pixman.lib;zlib.lib;libpng.lib;freetype.lib;tcl86t.lib;tk86t.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + jpeg.lib;cairo.lib;pixman.lib;zlib.lib;libpng.lib;freetype.lib;tcl86t.lib;tk86t.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -218,7 +218,7 @@ true true true - cairo.lib;pixman.lib;zlib.lib;libpng.lib;freetype.lib;tcl86t.lib;tk86t.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + jpeg.lib;cairo.lib;pixman.lib;zlib.lib;libpng.lib;freetype.lib;tcl86t.lib;tk86t.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) diff --git a/XSchemWin/XSchemWix/doc.wxs b/XSchemWin/XSchemWix/doc.wxs index 7c4e6c7d..e6db2dd2 100644 --- a/XSchemWin/XSchemWix/doc.wxs +++ b/XSchemWin/XSchemWix/doc.wxs @@ -492,6 +492,18 @@ + + + + + + + + + + + + @@ -1114,6 +1126,10 @@ + + + + diff --git a/XSchemWin/XSchemWix/heat_doc.wxs b/XSchemWin/XSchemWix/heat_doc.wxs index 3a93867d..2433090a 100644 --- a/XSchemWin/XSchemWix/heat_doc.wxs +++ b/XSchemWin/XSchemWix/heat_doc.wxs @@ -3,946 +3,958 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1113,6 +1125,10 @@ + + + + diff --git a/XSchemWin/config.h b/XSchemWin/config.h index 07290494..e3281bd1 100644 --- a/XSchemWin/config.h +++ b/XSchemWin/config.h @@ -3,6 +3,9 @@ /* Source: config.h.in; to regenerate run ./configure */ /*************************************************************/ +/* Define this var if libjpeg is available and is to be used */ +/* #define HAS_LIBJPEG 1 */ + /* Define to 1 if cairo is available and is to be used */ /* #define HAS_CAIRO 1 #define CAIRO_WIN32_STATIC_BUILD 1 */ diff --git a/src/actions.c b/src/actions.c index 729f04e5..a0473adc 100644 --- a/src/actions.c +++ b/src/actions.c @@ -581,6 +581,32 @@ int set_rect_flags(xRect *r) return f; } +int set_text_flags(xText *t) +{ + const char *str; + t->flags = 0; + t->hcenter = 0; + t->vcenter = 0; + t->layer = -1; + if(t->prop_ptr) { + my_strdup(_ALLOC_ID_, &t->font, get_tok_value(t->prop_ptr, "font", 0)); + str = get_tok_value(t->prop_ptr, "hcenter", 0); + t->hcenter = strcmp(str, "true") ? 0 : 1; + str = get_tok_value(t->prop_ptr, "vcenter", 0); + t->vcenter = strcmp(str, "true") ? 0 : 1; + str = get_tok_value(t->prop_ptr, "layer", 0); + if(str[0]) t->layer = atoi(str); + str = get_tok_value(t->prop_ptr, "slant", 0); + t->flags |= strcmp(str, "oblique") ? 0 : TEXT_OBLIQUE; + t->flags |= strcmp(str, "italic") ? 0 : TEXT_ITALIC; + str = get_tok_value(t->prop_ptr, "weight", 0); + t->flags |= strcmp(str, "bold") ? 0 : TEXT_BOLD; + str = get_tok_value(t->prop_ptr, "hide", 0); + t->flags |= strcmp(str, "true") ? 0 : HIDE_TEXT; + } + return 0; +} + /* what: * 1: create * 0: clear @@ -2553,7 +2579,7 @@ int place_text(int draw_text, double mx, double my) { char *txt; int textlayer; - const char *str; + /* const char *str; */ int save_draw; xText *t = &xctx->text[xctx->texts]; #if HAS_CAIRO==1 @@ -2592,26 +2618,7 @@ int place_text(int draw_text, double mx, double my) /* debug ... */ /* t->prop_ptr=NULL; */ dbg(1, "place_text(): done text input\n"); - - str = get_tok_value(t->prop_ptr, "hcenter", 0); - t->hcenter = strcmp(str, "true") ? 0 : 1; - str = get_tok_value(t->prop_ptr, "vcenter", 0); - t->vcenter = strcmp(str, "true") ? 0 : 1; - - str = get_tok_value(t->prop_ptr, "layer", 0); - if(str[0]) t->layer = atoi(str); - else t->layer = -1; - - t->flags = 0; - str = get_tok_value(t->prop_ptr, "slant", 0); - t->flags |= strcmp(str, "oblique") ? 0 : TEXT_OBLIQUE; - t->flags |= strcmp(str, "italic") ? 0 : TEXT_ITALIC; - str = get_tok_value(t->prop_ptr, "weight", 0); - t->flags |= strcmp(str, "bold") ? 0 : TEXT_BOLD; - str = get_tok_value(t->prop_ptr, "hide", 0); - t->flags |= strcmp(str, "true") ? 0 : HIDE_TEXT; - - my_strdup(_ALLOC_ID_, &t->font, get_tok_value(t->prop_ptr, "font", 0)); + set_text_flags(t); textlayer = t->layer; if(textlayer < 0 || textlayer >= cadlayers) textlayer = TEXTLAYER; #if HAS_CAIRO==1 diff --git a/src/cairo_jpg.c b/src/cairo_jpg.c index 22e00980..d14d8807 100644 --- a/src/cairo_jpg.c +++ b/src/cairo_jpg.c @@ -298,7 +298,11 @@ cairo_status_t cairo_image_surface_write_to_jpeg(cairo_surface_t *sfc, const cha int outfile; /* Open/create new file */ +#ifdef __unix__ if ((outfile = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1) +#else + if ((outfile = open(filename, O_WRONLY | O_CREAT, _S_IREAD | _S_IWRITE)) == -1) +#endif return CAIRO_STATUS_DEVICE_ERROR; /* write surface to file */ @@ -388,6 +392,11 @@ cairo_surface_t *cairo_image_surface_create_from_jpeg_mem(void *data, size_t len * intend to check errno you shall set it to 0 before calling this function * because it modifies errno only in case of an error. */ + +#ifndef __unix__ +typedef SSIZE_T ssize_t; +#endif + #ifdef USE_CAIRO_READ_FUNC_LEN_T cairo_surface_t *cairo_image_surface_create_from_jpeg_stream(cairo_read_func_len_t read_func, void *closure) #else diff --git a/src/create_alloc_ids.awk b/src/create_alloc_ids.awk index 2d0e7d31..cdf0dd11 100755 --- a/src/create_alloc_ids.awk +++ b/src/create_alloc_ids.awk @@ -2,7 +2,6 @@ # replaces _ALLOC_ID_ in all source files with unique ID for memory tracking BEGIN{ - if(ARGC <= 1) { print "Usage: " ENVIRON["_"] " create|reset" exit diff --git a/src/editprop.c b/src/editprop.c index a18fc391..c2cb4c96 100644 --- a/src/editprop.c +++ b/src/editprop.c @@ -937,7 +937,7 @@ static void edit_text_property(int x) double xx1,yy1,xx2,yy2; double pcx,pcy; /* pin center 20070317 */ char property[100];/* used for float 2 string conv (xscale and yscale) overflow safe */ - const char *str; + /* const char *str; */ char *oldprop = NULL; dbg(1, "edit_text_property(): entering\n"); @@ -1052,22 +1052,7 @@ static void edit_text_property(int x) set_different_token(&xctx->text[sel].prop_ptr, (char *) tclgetvar("props"), oldprop, 0, 0); else my_strdup(_ALLOC_ID_, &xctx->text[sel].prop_ptr,(char *) tclgetvar("props")); - my_strdup(_ALLOC_ID_, &xctx->text[sel].font, get_tok_value(xctx->text[sel].prop_ptr, "font", 0)); - str = get_tok_value(xctx->text[sel].prop_ptr, "hcenter", 0); - xctx->text[sel].hcenter = strcmp(str, "true") ? 0 : 1; - str = get_tok_value(xctx->text[sel].prop_ptr, "vcenter", 0); - xctx->text[sel].vcenter = strcmp(str, "true") ? 0 : 1; - str = get_tok_value(xctx->text[sel].prop_ptr, "layer", 0); - if(str[0]) xctx->text[sel].layer = atoi(str); - else xctx->text[sel].layer=-1; - xctx->text[sel].flags = 0; - str = get_tok_value(xctx->text[sel].prop_ptr, "slant", 0); - xctx->text[sel].flags |= strcmp(str, "oblique") ? 0 : TEXT_OBLIQUE; - xctx->text[sel].flags |= strcmp(str, "italic") ? 0 : TEXT_ITALIC; - str = get_tok_value(xctx->text[sel].prop_ptr, "weight", 0); - xctx->text[sel].flags |= strcmp(str, "bold") ? 0 : TEXT_BOLD; - str = get_tok_value(xctx->text[sel].prop_ptr, "hide", 0); - xctx->text[sel].flags |= strcmp(str, "true") ? 0 : HIDE_TEXT; + set_text_flags(&xctx->text[sel]); } if(size_changed) { xctx->text[sel].xscale=hsize; diff --git a/src/move.c b/src/move.c index 6389ada1..77e0200b 100644 --- a/src/move.c +++ b/src/move.c @@ -607,7 +607,6 @@ void copy_objects(int what) double angle, dtmp; int newpropcnt; double tmpx, tmpy; - const char *str; #if HAS_CAIRO==1 int customfont; @@ -907,26 +906,7 @@ void copy_objects(int what) xctx->text[xctx->texts].prop_ptr=NULL; xctx->text[xctx->texts].font=NULL; my_strdup(_ALLOC_ID_, &xctx->text[xctx->texts].prop_ptr, xctx->text[n].prop_ptr); - my_strdup(_ALLOC_ID_, &xctx->text[xctx->texts].font, get_tok_value(xctx->text[xctx->texts].prop_ptr, "font", 0)); - - str = get_tok_value(xctx->text[xctx->texts].prop_ptr, "hcenter", 0); - xctx->text[xctx->texts].hcenter = strcmp(str, "true") ? 0 : 1; - str = get_tok_value(xctx->text[xctx->texts].prop_ptr, "vcenter", 0); - xctx->text[xctx->texts].vcenter = strcmp(str, "true") ? 0 : 1; - - str = get_tok_value(xctx->text[xctx->texts].prop_ptr, "layer", 0); - if(str[0]) xctx->text[xctx->texts].layer = atoi(str); - else xctx->text[xctx->texts].layer = -1; - - xctx->text[xctx->texts].flags = 0; - str = get_tok_value(xctx->text[xctx->texts].prop_ptr, "slant", 0); - xctx->text[xctx->texts].flags |= strcmp(str, "oblique") ? 0 : TEXT_OBLIQUE; - xctx->text[xctx->texts].flags |= strcmp(str, "italic") ? 0 : TEXT_ITALIC; - str = get_tok_value(xctx->text[xctx->texts].prop_ptr, "weight", 0); - xctx->text[xctx->texts].flags |= strcmp(str, "bold") ? 0 : TEXT_BOLD; - str = get_tok_value(xctx->text[xctx->texts].prop_ptr, "hide", 0); - xctx->text[xctx->texts].flags |= strcmp(str, "true") ? 0 : HIDE_TEXT; - + set_text_flags(&xctx->text[xctx->texts]); xctx->text[xctx->texts].xscale=xctx->text[n].xscale; xctx->text[xctx->texts].yscale=xctx->text[n].yscale; diff --git a/src/paste.c b/src/paste.c index af2b46be..219adf4e 100644 --- a/src/paste.c +++ b/src/paste.c @@ -29,7 +29,6 @@ static void merge_text(FILE *fd) { int i; - const char *str; check_text_storage(); i=xctx->texts; xctx->text[i].txt_ptr=NULL; @@ -46,27 +45,7 @@ static void merge_text(FILE *fd) xctx->text[i].font=NULL; xctx->text[i].sel=0; load_ascii_string(&xctx->text[i].prop_ptr,fd); - my_strdup(_ALLOC_ID_, &xctx->text[i].font, get_tok_value(xctx->text[i].prop_ptr, "font", 0)); - - - str = get_tok_value(xctx->text[i].prop_ptr, "hcenter", 0); - xctx->text[i].hcenter = strcmp(str, "true") ? 0 : 1; - str = get_tok_value(xctx->text[i].prop_ptr, "vcenter", 0); - xctx->text[i].vcenter = strcmp(str, "true") ? 0 : 1; - - str = get_tok_value(xctx->text[i].prop_ptr, "layer", 0); - if(str[0]) xctx->text[i].layer = atoi(str); - else xctx->text[i].layer = -1; - - xctx->text[i].flags = 0; - str = get_tok_value(xctx->text[i].prop_ptr, "slant", 0); - xctx->text[i].flags |= strcmp(str, "oblique") ? 0 : TEXT_OBLIQUE; - xctx->text[i].flags |= strcmp(str, "italic") ? 0 : TEXT_ITALIC; - str = get_tok_value(xctx->text[i].prop_ptr, "weight", 0); - xctx->text[i].flags |= strcmp(str, "bold") ? 0 : TEXT_BOLD; - str = get_tok_value(xctx->text[i].prop_ptr, "hide", 0); - xctx->text[i].flags |= strcmp(str, "true") ? 0 : HIDE_TEXT; - + set_text_flags(&xctx->text[i]); select_text(i,SELECTED, 1); set_modify(1); xctx->texts++; diff --git a/src/save.c b/src/save.c index d7f14634..0be9c591 100644 --- a/src/save.c +++ b/src/save.c @@ -1667,45 +1667,25 @@ static void write_xschem_file(FILE *fd) static void load_text(FILE *fd) { int i; - const char *str; - dbg(3, "load_text(): start\n"); - check_text_storage(); - i=xctx->texts; - xctx->text[i].txt_ptr=NULL; - load_ascii_string(&xctx->text[i].txt_ptr,fd); - if(fscanf(fd, "%lf %lf %hd %hd %lf %lf ", - &xctx->text[i].x0, &xctx->text[i].y0, &xctx->text[i].rot, - &xctx->text[i].flip, &xctx->text[i].xscale, - &xctx->text[i].yscale)<6) { - fprintf(errfp,"WARNING: missing fields for TEXT object, ignoring\n"); - read_line(fd, 0); - return; - } - xctx->text[i].prop_ptr=NULL; - xctx->text[i].font=NULL; - xctx->text[i].sel=0; - load_ascii_string(&xctx->text[i].prop_ptr,fd); - if( xctx->text[i].prop_ptr) - my_strdup(_ALLOC_ID_, &xctx->text[i].font, get_tok_value(xctx->text[i].prop_ptr, "font", 0)); - - str = get_tok_value(xctx->text[i].prop_ptr, "hcenter", 0); - xctx->text[i].hcenter = strcmp(str, "true") ? 0 : 1; - str = get_tok_value(xctx->text[i].prop_ptr, "vcenter", 0); - xctx->text[i].vcenter = strcmp(str, "true") ? 0 : 1; - - str = get_tok_value(xctx->text[i].prop_ptr, "layer", 0); - if(str[0]) xctx->text[i].layer = atoi(str); - else xctx->text[i].layer = -1; - xctx->text[i].flags = 0; - str = get_tok_value(xctx->text[i].prop_ptr, "slant", 0); - xctx->text[i].flags |= strcmp(str, "oblique") ? 0 : TEXT_OBLIQUE; - xctx->text[i].flags |= strcmp(str, "italic") ? 0 : TEXT_ITALIC; - str = get_tok_value(xctx->text[i].prop_ptr, "weight", 0); - xctx->text[i].flags |= strcmp(str, "bold") ? 0 : TEXT_BOLD; - str = get_tok_value(xctx->text[i].prop_ptr, "hide", 0); - xctx->text[i].flags |= strcmp(str, "true") ? 0 : HIDE_TEXT; - - xctx->texts++; + dbg(3, "load_text(): start\n"); + check_text_storage(); + i=xctx->texts; + xctx->text[i].txt_ptr=NULL; + load_ascii_string(&xctx->text[i].txt_ptr,fd); + if(fscanf(fd, "%lf %lf %hd %hd %lf %lf ", + &xctx->text[i].x0, &xctx->text[i].y0, &xctx->text[i].rot, + &xctx->text[i].flip, &xctx->text[i].xscale, + &xctx->text[i].yscale)<6) { + fprintf(errfp,"WARNING: missing fields for TEXT object, ignoring\n"); + read_line(fd, 0); + return; + } + xctx->text[i].prop_ptr=NULL; + xctx->text[i].font=NULL; + xctx->text[i].sel=0; + load_ascii_string(&xctx->text[i].prop_ptr,fd); + set_text_flags(&xctx->text[i]); + xctx->texts++; } static void load_wire(FILE *fd) @@ -2998,7 +2978,6 @@ int load_sym_def(const char *name, FILE *embed_fd) int lastt; xText *tt; int endfile; - const char *str; char *skip_line; const char *dash; xSymbol * symbol; @@ -3380,22 +3359,7 @@ int load_sym_def(const char *name, FILE *embed_fd) my_strcat(1163, &tt[i].prop_ptr, lay); } dbg(1, "l_s_d(): loaded text : t=%s p=%s\n", tt[i].txt_ptr, tt[i].prop_ptr ? tt[i].prop_ptr : "NULL"); - my_strdup(_ALLOC_ID_, &tt[i].font, get_tok_value(tt[i].prop_ptr, "font", 0)); - str = get_tok_value(tt[i].prop_ptr, "hcenter", 0); - tt[i].hcenter = strcmp(str, "true") ? 0 : 1; - str = get_tok_value(tt[i].prop_ptr, "vcenter", 0); - tt[i].vcenter = strcmp(str, "true") ? 0 : 1; - str = get_tok_value(tt[i].prop_ptr, "layer", 0); - if(str[0]) tt[i].layer = atoi(str); - else tt[i].layer = -1; - tt[i].flags = 0; - str = get_tok_value(tt[i].prop_ptr, "slant", 0); - tt[i].flags |= strcmp(str, "oblique") ? 0 : TEXT_OBLIQUE; - tt[i].flags |= strcmp(str, "italic") ? 0 : TEXT_ITALIC; - str = get_tok_value(tt[i].prop_ptr, "weight", 0); - tt[i].flags |= strcmp(str, "bold") ? 0 : TEXT_BOLD; - str = get_tok_value(tt[i].prop_ptr, "hide", 0); - tt[i].flags |= strcmp(str, "true") ? 0 : HIDE_TEXT; + set_text_flags(&tt[i]); lastt++; break; case 'N': /* store wires as lines on layer WIRELAYER. */ diff --git a/src/scheduler.c b/src/scheduler.c index 73a7bac2..1e9bfbdc 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -1194,7 +1194,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(argc > 5) Tcl_SetResult(interp, (char *)get_tok_value(xctx->sym[i].prop_ptr, argv[4], atoi(argv[5])), TCL_VOLATILE); - } else if(!strcmp(argv[2], "rect")) { + } else if(!strcmp(argv[2], "rect")) { /* xschem getprop rect c n token */ if(argc < 6) { Tcl_SetResult(interp, "xschem getprop rect needs ", TCL_STATIC); return TCL_ERROR; @@ -1203,6 +1203,14 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg int n = atoi(argv[4]); Tcl_SetResult(interp, (char *)get_tok_value(xctx->rect[c][n].prop_ptr, argv[5], 2), TCL_VOLATILE); } + } else if(!strcmp(argv[2], "text")) { /* xschem getprop text n token */ + if(argc < 5) { + Tcl_SetResult(interp, "xschem getprop text needs ", TCL_STATIC); + return TCL_ERROR; + } else { + int n = atoi(argv[3]); + Tcl_SetResult(interp, (char *)get_tok_value(xctx->text[n].prop_ptr, argv[4], 2), TCL_VOLATILE); + } } } @@ -2768,6 +2776,73 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg bbox(END,0.0,0.0,0.0,0.0); } Tcl_ResetResult(interp); + + } else if(argc > 4 && !strcmp(argv[2], "text")) { + /* 0 1 2 3 4 5 6 + * xschem setprop text n token value [fast] */ + int change_done = 0; + int tmp, fast = 0; + double xx1, xx2, yy1, yy2, dtmp; + xText *t; + int n = atoi(argv[3]); + if(!(n >=0 && n < xctx->texts) ) { + Tcl_SetResult(interp, "xschem setprop text: wrong text number", TCL_STATIC); + return TCL_ERROR; + } + t = &xctx->text[n]; + if(argc > 6) { + if(!strcmp(argv[6], "fast")) { + fast = 1; + argc = 6; + } + if(!strcmp(argv[6], "fastundo")) { + fast = 3; + argc = 6; + } + } + else if(argc > 5) { + if(!strcmp(argv[5], "fast")) { + fast = 1; + argc = 5; + } + if(!strcmp(argv[5], "fastundo")) { + fast = 3; + argc = 5; + } + } + if(!fast) { + bbox(START,0.0,0.0,0.0,0.0); + } + if(argc > 5) { + /* verify if there is some difference */ + if(strcmp(argv[5], get_tok_value(t->prop_ptr, argv[4], 0))) { + change_done = 1; + if(fast == 3 || fast == 0) xctx->push_undo(); + my_strdup2(_ALLOC_ID_, &t->prop_ptr, subst_token(t->prop_ptr, argv[4], argv[5])); + } + } else { + get_tok_value(t->prop_ptr, argv[4], 0); + if(xctx->tok_size) { + change_done = 1; + if(fast == 3 || fast == 0) xctx->push_undo(); + my_strdup2(_ALLOC_ID_, &t->prop_ptr, subst_token(t->prop_ptr, argv[4], NULL)); /* delete attr */ + } + } + if(change_done) set_modify(1); + set_text_flags(t); + text_bbox(t->txt_ptr, t->xscale, + t->yscale, t->rot, t->flip, t->hcenter, + t->vcenter, t->x0, t->y0, + &xx1,&yy1,&xx2,&yy2, &tmp, &dtmp); + + if(!fast) { + bbox(ADD, xx1, yy1, xx2, yy2); + /* redraw rect with new props */ + bbox(SET,0.0,0.0,0.0,0.0); + draw(); + bbox(END,0.0,0.0,0.0,0.0); + } + Tcl_ResetResult(interp); } } else if(!strcmp(argv[1], "show_pin_net_names")) diff --git a/src/xschem.h b/src/xschem.h index 709084ad..9a599fb4 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -1084,6 +1084,7 @@ extern int read_rawfile_from_attr(const char *b64s, size_t length, const char *t extern int raw_read_from_attr(const char *type); extern char *base64_from_file(const char *f, size_t *length); extern int set_rect_flags(xRect *r); +extern int set_text_flags(xText *t); extern int set_rect_extraptr(int what, xRect *drptr); extern unsigned char *base64_decode(const char *data, const size_t input_length, size_t *output_length); extern char *base64_encode(const unsigned char *data, const size_t input_length, size_t *output_length, int brk); diff --git a/xschem_library/examples/rlc.sch b/xschem_library/examples/rlc.sch index fc54fa63..cc2ab67e 100644 --- a/xschem_library/examples/rlc.sch +++ b/xschem_library/examples/rlc.sch @@ -1,35 +1,121 @@ -v {xschem version=2.9.9 file_version=1.2 } +v {xschem version=3.1.0 file_version=1.2 +} G {} K {} V {} S {} E {} -N 280 -520 280 -420 {lab=#net1} -N 280 -240 480 -240 {lab=0} -N 280 -360 280 -300 {lab=C} -N 280 -620 480 -620 {lab=A} -N 480 -620 480 -520 {lab=A} -N 280 -620 280 -580 {lab=A} -N 480 -320 480 -240 {} -N 480 -460 480 -380 {} +L 4 120 -540 120 -480 {} +L 4 120 -480 130 -480 {} +L 4 120 -460 130 -480 {} +L 4 110 -480 120 -460 {} +L 4 110 -480 120 -480 {} +B 2 590 -550 1390 -150 {flags=graph +y1=-0.0011 +y2=0.0011 +ypos1=0 +ypos2=2 +divy=5 +subdivy=1 +unity=1 +x1=0.000675077 +x2=0.000778653 +divx=5 +subdivx=1 +node="\\"Cap. power; i(v1) a b - *\\" +\\"Avg Cap. power running average; i(v1) a b - * 40u ravg()\\"" +color="4 7" +dataset=-1 +unitx=1 +logx=0 +logy=0 +} +B 2 590 -810 1390 -550 {flags=graph +y1=-0.0007 +y2=0.0007 +ypos1=0 +ypos2=2 +divy=5 +subdivy=1 +unity=1 +x1=0.000675077 +x2=0.000778653 +divx=5 +subdivx=1 + + +dataset=-1 +unitx=1 +logx=0 +logy=0 +color=8 +node=i(v1)} +B 2 590 -1070 1390 -810 {flags=graph +y1=-0.7 +y2=3 +ypos1=0 +ypos2=2 +divy=5 +subdivy=1 +unity=1 +x1=0.000675077 +x2=0.000778653 +divx=5 +subdivx=1 + + +dataset=-1 +unitx=1 +logx=0 +logy=0 + +color="4 6 7 12" +node="a b c d" +hilight_wave=2} +T {I(V1)} 60 -520 0 0 0.4 0.4 {} +N 150 -480 150 -380 {lab=B} +N 150 -200 350 -200 {lab=0} +N 150 -320 150 -260 {lab=C} +N 150 -580 350 -580 {lab=A} +N 350 -580 350 -480 {lab=A} +N 150 -580 150 -540 {lab=A} +N 350 -280 350 -200 { +lab=0} +N 350 -420 350 -340 { +lab=D} C {title.sym} 160 -30 0 0 {name=l1 author="Stefan Schippers"} C {launcher.sym} 320 -100 0 0 {name=h1 descr="NGSPICE Manual" url="https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=2ahUKEwiVvafVvtzfAhVHExoKHaZLAIQQFjAAegQICRAC&url=http%3A%2F%2Fngspice.sourceforge.net%2Fdocs%2Fngspice-manual.pdf&usg=AOvVaw3n8fjRjAJRgWMjg1Y04Ht8"} -C {code_shown.sym} 640 -210 0 0 {name=STIMULI +C {code_shown.sym} 0 -930 0 0 {name=STIMULI only_toplevel=true tclcommand="xschem edit_vi_prop" value=" -.tran 10n 800u uic -.save all +.control + + save all + tran 10n 800u uic + let pow = i(v1) * v(a,b) + meas tran cap_avg_pow avg pow from=600u to=800u + write rlc.raw +.endc "} -C {capa.sym} 280 -550 0 0 {name=C1 m=1 value=50nF footprint=1206 device="ceramic capacitor" net_name=true} -C {lab_pin.sym} 280 -330 2 1 {name=l2 sig_type=std_logic lab=C} -C {lab_pin.sym} 480 -580 2 0 {name=l4 sig_type=std_logic lab=A} -C {lab_pin.sym} 480 -240 2 0 {name=l5 sig_type=std_logic lab=0} -C {res.sym} 480 -490 0 0 {name=R1 m=1 value=1k footprint=1206 device=resistor +C {capa.sym} 150 -510 0 0 {name=C1 m=1 value=50nF footprint=1206 device="ceramic capacitor" net_name=true} +C {lab_pin.sym} 150 -290 2 1 {name=l2 sig_type=std_logic lab=C} +C {lab_pin.sym} 150 -560 2 0 {name=l4 sig_type=std_logic lab=A} +C {lab_pin.sym} 350 -200 2 0 {name=l5 sig_type=std_logic lab=0} +C {res.sym} 350 -450 0 0 {name=R1 m=1 value=1k footprint=1206 device=resistor net_name=true} -C {ind.sym} 280 -390 0 0 {name=L1 value=10mH net_name=true} -C {vsource.sym} 280 -270 0 0 {name=V1 value="pwl 0 0 100u 0 101u 3" net_name=true} -C {lab_show.sym} 280 -450 0 0 {name=l3} -C {ammeter.sym} 480 -350 0 0 {name=Vmeas} +C {ind.sym} 150 -350 0 0 {name=L1 value=10mH net_name=true} +C {vsource.sym} 150 -230 0 0 {name=V1 +xvalue="pwl 0 0 100u 0 101u 3" +value="pulse 0 3 0 100n 100n 9.9u 20u" + +net_name=true} +C {ammeter.sym} 350 -310 0 0 {name=Vmeas} +C {lab_pin.sym} 150 -450 2 0 {name=l6 sig_type=std_logic lab=B} +C {lab_pin.sym} 350 -380 2 0 {name=l7 sig_type=std_logic lab=D} +C {launcher.sym} 760 -90 0 0 {name=h5 +descr="load waves" +tclcommand="xschem raw_read $netlist_dir/rlc.raw tran" +} diff --git a/xschem_library/ngspice/pv_ngspice.sch b/xschem_library/ngspice/pv_ngspice.sch index 256f59f2..3cd8c587 100644 --- a/xschem_library/ngspice/pv_ngspice.sch +++ b/xschem_library/ngspice/pv_ngspice.sch @@ -59,7 +59,7 @@ C {ipin.sym} 290 -460 2 1 {name=p2 lab=fade} C {ammeter.sym} 340 -460 3 0 {name=Vf} C {lab_pin.sym} 370 -460 2 0 {name=l3 sig_type=std_logic lab=f} C {ammeter.sym} 430 -730 2 1 {name=Vp} -C {code_shown.sym} 30 -280 0 0 {name=CONTROL +C {code_shown.sym} 20 -340 0 0 {name=CONTROL only_toplevel=true value=".param power=100 .param n=36