From b23988ccdf5dffd0b64db256290928e1ff87b505 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Fri, 2 Dec 2022 16:43:01 +0100 Subject: [PATCH] added commented lines for antialiasing; JL:cairo_set_line_width should only be called with has_x as xctx->cairo_ctx and xctx->cairo_save_ctx is NULL when run with -x; JL:XCopyArea must be called to draw correctly with Cairo on Windows --- src/draw.c | 7 +-- src/xinit.c | 8 +++- xschem_library/ngspice/pv_ngspice.sch | 66 +++++++++++++------------- xschem_library/ngspice/pv_ngspice.sym | 9 ++-- xschem_library/ngspice/solar_panel.sch | 2 +- 5 files changed, 49 insertions(+), 43 deletions(-) diff --git a/src/draw.c b/src/draw.c index 36445ef3..c5b04810 100644 --- a/src/draw.c +++ b/src/draw.c @@ -3540,9 +3540,11 @@ int XSetTile(Display* display, GC gc, Pixmap s_pixmap) void MyXCopyArea(Display* display, Drawable src, Drawable dest, GC gc, int src_x, int src_y, unsigned int width, unsigned int height, int dest_x, int dest_y) { - - #if !defined(__unix__) && defined(HAS_CAIRO) + #if !defined(__unix__) + XCopyArea(display, src, dest, gc, src_x, src_y, width, height, dest_x, dest_y); + #if defined(HAS_CAIRO) my_cairo_fill(xctx->cairo_save_sfc, dest_x, dest_y, width, height); + #endif #elif (defined(__unix__) && defined(HAS_CAIRO)) || DRAW_ALL_CAIRO==1 cairo_set_source_surface(xctx->cairo_ctx, xctx->cairo_save_sfc, 0, 0); cairo_paint(xctx->cairo_ctx); @@ -3550,4 +3552,3 @@ void MyXCopyArea(Display* display, Drawable src, Drawable dest, GC gc, int src_x XCopyArea(display, src, dest, gc, src_x, src_y, width, height, dest_x, dest_y); #endif } - diff --git a/src/xinit.c b/src/xinit.c index ee309ebb..e150117c 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -1734,8 +1734,10 @@ void change_linewidth(double w) xctx->areah = xctx->areay2 - xctx->areay1; } #if HAS_CAIRO==1 - cairo_set_line_width(xctx->cairo_ctx, INT_WIDTH(xctx->lw)); - cairo_set_line_width(xctx->cairo_save_ctx, INT_WIDTH(xctx->lw)); + if(has_x) { + cairo_set_line_width(xctx->cairo_ctx, INT_WIDTH(xctx->lw)); + cairo_set_line_width(xctx->cairo_save_ctx, INT_WIDTH(xctx->lw)); + } #endif } @@ -1772,6 +1774,7 @@ static void resetcairo(int create, int clear, int force_or_resize) } xctx->cairo_save_ctx = cairo_create(xctx->cairo_save_sfc); + /* cairo_set_antialias (xctx->cairo_save_ctx, CAIRO_ANTIALIAS_NONE); */ cairo_select_font_face(xctx->cairo_save_ctx, tclgetvar("cairo_font_name"), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size(xctx->cairo_save_ctx, 20); @@ -1792,6 +1795,7 @@ static void resetcairo(int create, int clear, int force_or_resize) fprintf(errfp, "ERROR: invalid cairo surface\n"); } xctx->cairo_ctx = cairo_create(xctx->cairo_sfc); + /* cairo_set_antialias (xctx->cairo_ctx, CAIRO_ANTIALIAS_NONE); */ cairo_select_font_face(xctx->cairo_ctx, tclgetvar("cairo_font_name"), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size(xctx->cairo_ctx, 20); diff --git a/xschem_library/ngspice/pv_ngspice.sch b/xschem_library/ngspice/pv_ngspice.sch index 8cb0f5cb..256f59f2 100644 --- a/xschem_library/ngspice/pv_ngspice.sch +++ b/xschem_library/ngspice/pv_ngspice.sch @@ -7,23 +7,23 @@ S {} E {} B 2 860 -550 1360 -160 {flags=graph y1 = 0 -y2 = 6.6 +y2 = 6 divy = 4 subdivy=1 -x1=0 -x2=24 +x1=-0.0573452 +x2=22.5919 divx=8 unitx=1 color=15 node=i(vload) dataset=-1} B 2 860 -790 1360 -550 {flags=graph -y1 = 0 -y2 = 112 +y1 = 7.29412e-05 +y2 = 99.9997 divy = 4 subdivy=1 -x1=0 -x2=24 +x1=-0.0573452 +x2=22.5919 divx=8 unitx=1 color=8 @@ -32,47 +32,43 @@ plus i(vload) *\\"" dataset=-1} -T {Voc = 22 -Wp = 100W -Vmp = 17.5} 320 -550 0 0 0.4 0.4 {} T {position the mouse close to one of the curves and press 't' to display only that curve. This allows you to annotate the active -waveform in the schematic.} 480 -470 0 0 0.3 0.3 {} -N 230 -440 230 -380 { +waveform in the schematic.} 480 -370 0 0 0.3 0.3 {} +N 430 -480 430 -420 { lab=minus} -N 230 -530 230 -500 { +N 430 -570 430 -540 { lab=mn} -N 90 -420 110 -420 { +N 290 -460 310 -460 { lab=fade} -N 230 -660 230 -590 { +N 430 -700 430 -630 { lab=pn} -N 230 -760 230 -720 { +N 430 -800 430 -760 { lab=plus} -C {iopin.sym} 230 -760 2 1 {name=p1 lab=plus} -C {iopin.sym} 230 -380 2 1 {name=p2 lab=minus} +C {iopin.sym} 430 -800 2 1 {name=p1 lab=plus} +C {iopin.sym} 430 -420 2 1 {name=p2 lab=minus} C {title.sym} 160 -40 0 0 {name=l1 author="Stefan Schippers" net_name=true} -C {ammeter.sym} 230 -470 2 1 {name=Vm} -C {lab_pin.sym} 230 -610 2 0 {name=l2 sig_type=std_logic lab=pn} -C {lab_pin.sym} 230 -510 2 0 {name=l3 sig_type=std_logic lab=mn} -C {isource_arith.sym} 230 -560 2 0 {name=G1 -CUR="v(f) * 5.5 * (1 - exp( (v(pn,mn) -+ -21 - v(f)*2.5 ) * 0.6) - -+ 0.002 * (v(pn,mn) - 21 - v(f)*2.5))" +C {ammeter.sym} 430 -510 2 1 {name=Vm} +C {lab_pin.sym} 430 -650 2 0 {name=l2 sig_type=std_logic lab=pn} +C {lab_pin.sym} 430 -550 2 0 {name=l3 sig_type=std_logic lab=mn} +C {isource_arith.sym} 430 -600 2 0 {name=G1 +CUR="v(f) * power * 2.16 / n * (1 - (3.5e-7 * exp( v(pn,mn) / n / 0.041)))" } -C {ipin.sym} 90 -420 2 1 {name=p2 lab=fade} -C {ammeter.sym} 140 -420 3 0 {name=Vf} -C {lab_pin.sym} 170 -420 2 0 {name=l3 sig_type=std_logic lab=f} -C {ammeter.sym} 230 -690 2 1 {name=Vp} +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 only_toplevel=true -value=" +value=".param power=100 +.param n=36 vload plus minus 0 vsun fade 0 0 vref minus 0 0 .control save plus i(vload) i(vm) n(pn) v(mn) -dc vload 0 24 0.5 vsun 0.2 1.0 0.2 +dc vload 0 48 0.2 vsun 0.2 1.0 0.2 write pv_ngspice.raw quit .endc @@ -262,7 +258,13 @@ AAAAAAAAAAA2QAAAAAAAADZAAAAAAAAAAADARn38MD4KQMBGffwwPgpAwEZ9/DA+CkAAAAAAAIA2QAAA A0CQxRO3tvADQJDFE7e28ANAAAAAAAAAN0AAAAAAAAAAAAAAAAAAADdAAAAAAAAAN0AAAAAAAAAAAEB3KAhg5fY/QHcoCGDl9j9AdygIYOX2PwAAAAAAgDdAAAAAAAAA AAAAAAAAAIA3QAAAAAAAgDdAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4QAAAAAAAAAAAAAAAAAAAOEAAAAAAAAA4QAAAAAAAAAAAgJ4EsCXg /r+AngSwJeD+v4CeBLAl4P6/"} -C {ngspice_get_expr.sym} 280 -560 0 0 {name=r24 +C {ngspice_get_expr.sym} 480 -600 0 0 {name=r24 node="[format %.4g [expr ([ngspice::get_voltage pn] - [ngspice::get_voltage mn]) * [ngspice::get_current Vm]]] W" descr = power } +C {launcher.sym} 1300 -90 0 0 {name=h2 +descr="Reload waves" +tclcommand=" +xschem raw_read $netlist_dir/[file tail [file rootname [xschem get current_name]]].raw +" +} diff --git a/xschem_library/ngspice/pv_ngspice.sym b/xschem_library/ngspice/pv_ngspice.sym index 82cbd21d..c6fa9d18 100644 --- a/xschem_library/ngspice/pv_ngspice.sym +++ b/xschem_library/ngspice/pv_ngspice.sym @@ -2,11 +2,11 @@ v {xschem version=3.1.0 file_version=1.2 } G {} K {type=subcircuit -format="@name @pinlist @symname m=@m" +format="@name @pinlist @symname power=@power n=@n m=@m" -template="name=X1 m=1"} +template="name=X1 power=100 n=36 m=1"} V {} S {} E {} @@ -22,7 +22,6 @@ B 5 -42.5 -2.5 -37.5 2.5 {name=fade dir=in} P 4 7 -35 -30 -25 -20 -20 -25 -15 -10 -30 -15 -25 -20 -35 -30 {} P 4 7 -35 -5 -25 5 -20 0 -15 15 -30 10 -25 5 -35 -5 {} T {@name} 15 -28.75 0 0 0.2 0.2 {} -T {Voc = 22 -Wp = 100W -Vmp = 17.5} 30 -10 0 0 0.2 0.2 {} +T {Wp = @power +n = @n} 30 -10 0 0 0.2 0.2 {} T {m=@m} -5 16.25 0 1 0.2 0.2 {} diff --git a/xschem_library/ngspice/solar_panel.sch b/xschem_library/ngspice/solar_panel.sch index 6cec0e59..58d7bc40 100644 --- a/xschem_library/ngspice/solar_panel.sch +++ b/xschem_library/ngspice/solar_panel.sch @@ -275,7 +275,7 @@ tclcommand=" xschem raw_read $netlist_dir/[file tail [file rootname [xschem get current_name]]].raw tran " } -C {pv_ngspice.sym} 370 -360 0 0 {name=X1 m=1} +C {pv_ngspice.sym} 370 -360 0 0 {name=X1 m=1 power=100 n=36} C {lab_pin.sym} 370 -280 0 0 {name=l12 lab=0 } C {capa.sym} 510 -410 0 0 {name=C11 m=1