[PCB Print][Fixed] Problems with images in the WKS (KiCad 5/6)

- Added regression test
This commit is contained in:
Salvador E. Tropea 2023-04-01 18:07:51 -03:00
parent 7849fc0bde
commit 3221a7fe00
9 changed files with 40 additions and 20 deletions

View File

@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- PCB Print:
- Interference between the visible layers in the PRL file and the results
when scaling. (#407)
- Problems with images in the WKS (KiCad 5/6)
- Diff:
- Problems when using an output and no variant specified.
- PCB/SCH parity test:

View File

@ -80,7 +80,7 @@ test_docker_local_1:
# Run in the same directory to make the __pycache__ valid
# Also change the owner of the files to the current user (we run as root like in GitHub)
#docker run --rm -it -v $(CWD):$(CWD) --workdir="$(CWD)" setsoft/kicad_auto_test:latest '/bin/bash'
docker run --rm -v $(CWD):$(CWD) --workdir="$(CWD)" setsoft/kicad_auto_test:latest \
docker run --rm -v $(CWD):$(CWD) --workdir="$(CWD)" ghcr.io/inti-cmnb/kicad_auto_test:ki5 \
/bin/bash -c "flake8 . --count --statistics ; python3-coverage run -a src/kibot --help-outputs > /dev/null; pytest-3 --log-cli-level debug -k '$(SINGLE_TEST)' --test_dir=output ; $(PY_COV) html; chown -R $(USER_ID):$(GROUP_ID) output/ tests/board_samples/ tests/.config/kiplot/plugins/__pycache__/ tests/test_plot/fake_pcbnew/__pycache__/ tests/.config/kibot/plugins/__pycache__/ .coverage.* htmlcov/"
#$(PY_COV) report
#x-www-browser htmlcov/index.html
@ -106,6 +106,8 @@ test_docker_local_1_ki7:
docker run --rm -v $(CWD):$(CWD) --workdir="$(CWD)" ghcr.io/inti-cmnb/kicad_auto_test:ki7 \
/bin/bash -c "python3-coverage run src/kibot --help-outputs > /dev/null; pytest-3 --log-cli-level debug -k '$(SINGLE_TEST)' --test_dir=output ; $(PY_COV) html; chown -R $(USER_ID):$(GROUP_ID) output/ tests/board_samples/ tests/.config/kiplot/plugins/__pycache__/ tests/test_plot/fake_pcbnew/__pycache__/ tests/.config/kibot/plugins/__pycache__/ .coverage htmlcov/"
t1k7: test_docker_local_1_ki7
test_docker_local:
rm -rf output
rm -f tests/.local

View File

@ -527,16 +527,21 @@ class GS(object):
@staticmethod
def iu_to_svg(values, svg_precision):
""" Converts 1 or more values from KiCad internal IUs to the units used for SVGs """
if not isinstance(values, tuple):
values = [values]
""" Converts 1 or more values from KiCad internal IUs to the units used for SVGs.
For tuples we assume the result is SVG coordinates, for 1 value a scale """
if GS.ki5:
return tuple(map(lambda x: int(round(x*KICAD5_SVG_SCALE)), values))
if isinstance(values, tuple):
return tuple(map(lambda x: int(round(x*KICAD5_SVG_SCALE)), values))
return values*KICAD5_SVG_SCALE
if GS.ki7:
return tuple(map(GS.to_mm, values))
if isinstance(values, tuple):
return tuple(map(GS.to_mm, values))
return GS.to_mm(values)
# KiCad 6
mult = 10.0 ** (svg_precision - 6)
return tuple(map(lambda x: int(round(x*mult)), values))
if isinstance(values, tuple):
return tuple(map(lambda x: int(round(x*mult)), values))
return values*mult
@staticmethod
def svg_round(val):

View File

@ -417,6 +417,7 @@ class WksBitmap(WksDrawing):
p.images.append(e)
def add_to_svg(e, svg, p, svg_precision):
# Note: we compute all in KiCad IUs, and then apply a scale for the SVG
s = e.data
w, h = unpack('>LL', s[16:24])
# For KiCad 300 dpi is 1:1 scale
@ -429,7 +430,7 @@ class WksBitmap(WksDrawing):
# KiCad 6 can adjust the precision
# The default is 6 and makes 1 KiCad unit == 1 SVG unit
# But this isn't supported by browsers (Chrome and Firefox)
scale = GS.iu_to_svg(1.0, svg_precision)[0]
scale = GS.iu_to_svg(1.0, svg_precision)
for _ in range(e.repeat):
img = ImageElement(io.BytesIO(s), w, h)
x = pos.x-round(w/2)

View File

@ -1,7 +1,8 @@
(kicad_wks (version 20210606) (generator pl_editor)
(setup (textsize 1.5 1.5)(linewidth 0.15)(textlinewidth 0.15)
(left_margin 10)(right_margin 10)(top_margin 10)(bottom_margin 10))
(rect (name "") (start 110 34) (end 2 2) (comment "rect around the title block") (option page1only))
(rect (name "") (start 110 34) (end 2 2) (option page1only) (comment "rect around the title block")
)
(rect (name "") (start 0 0 ltcorner) (end 0 0) (repeat 2) (incrx 2) (incry 2))
(line (name "") (start 50 2 ltcorner) (end 50 0 ltcorner) (repeat 30) (incrx 50))
(tbtext "1" (name "") (pos 25 1 ltcorner) (font (size 1.3 1.3)) (repeat 100) (incrx 50))
@ -13,25 +14,34 @@
(tbtext "A" (name "") (pos 1 25 rtcorner) (font (size 1.3 1.3)) (justify center) (repeat 100) (incry 50))
(tbtext "Date: ${ISSUE_DATE}" (name "") (pos 87 6.9))
(line (name "") (start 110 5.5) (end 2 5.5))
(tbtext "${KICAD_VERSION}" (name "") (pos 109 4.1) (comment "Kicad version"))
(tbtext "No KiCad version to make it reproducible\n" (name "") (pos 109 4.1) (comment "Kicad version")
)
(line (name "") (start 110 8.5) (end 2 8.5))
(tbtext "Rev: ${REVISION}" (name "") (pos 24 6.9) (font bold))
(tbtext "Size: ${PAPER}" (name "") (pos 109 6.9) (comment "Paper format name"))
(tbtext "Id: ${#}/${##}" (name "") (pos 24 4.1) (comment "Sheet id"))
(tbtext "Size: ${PAPER}" (name "") (pos 109 6.9) (comment "Paper format name")
)
(tbtext "Id: ${#}/${##}" (name "") (pos 24 4.1) (comment "Sheet id")
)
(line (name "") (start 110 12.5) (end 2 12.5))
(tbtext "Title: ${TITLE}" (name "") (pos 109 10.7) (font (size 2 2) bold))
(tbtext "File: ${FILENAME}" (name "") (pos 109 14.3))
(line (name "") (start 110 18.5) (end 2 18.5))
(tbtext "Sheet: ${SHEETNAME}" (name "") (pos 109 17))
(tbtext "${COMPANY}" (name "") (pos 109 20) (font bold) (comment "Company name") (option page1only))
(tbtext "${COMMENT1}" (name "") (pos 109 23) (comment "Comment 0") (option page1only))
(tbtext "${COMMENT2}" (name "") (pos 109 26) (comment "Comment 1") (option page1only))
(tbtext "${COMMENT3}" (name "") (pos 109 29) (comment "Comment 2") (option page1only))
(tbtext "${COMMENT4}" (name "") (pos 109 32) (comment "Comment 3") (option page1only))
(tbtext "${COMPANY}" (name "") (pos 109 20) (option page1only) (font bold) (comment "Company name")
)
(tbtext "${COMMENT1}" (name "") (pos 109 23) (option page1only) (comment "Comment 0")
)
(tbtext "${COMMENT2}" (name "") (pos 109 26) (option page1only) (comment "Comment 1")
)
(tbtext "${COMMENT3}" (name "") (pos 109 29) (option page1only) (comment "Comment 2")
)
(tbtext "${COMMENT4}" (name "") (pos 109 32) (option page1only) (comment "Comment 3")
)
(line (name "") (start 90 8.5) (end 90 5.5))
(line (name "") (start 26 8.5) (end 26 2))
(rect (name "") (start 157 34) (end 110 2) (comment "rect around the logo") (option page1only))
(polygon (name "") (pos 133.5002 11.5002) (linewidth 0.00254) (option page1only)
(rect (name "") (start 157 34) (end 110 2) (option page1only) (comment "rect around the logo")
)
(polygon (name "") (pos 133.5002 11.5002) (option page1only) (linewidth 0.00254)
(pts (xy 20.574 8.382) (xy 19.9009 8.382) (xy 19.9009 6.26364) (xy 19.7485 5.98932) (xy 19.71802 5.92328)
(xy 19.69262 5.83946) (xy 19.66976 5.72262) (xy 19.65198 5.56006) (xy 19.63674 5.33908) (xy 19.6215 5.04952) (xy 19.61134 4.67614)
(xy 19.60372 4.20624) (xy 19.5961 3.62712) (xy 19.58848 2.92862) (xy 19.5834 2.09296) (xy 19.57832 1.11252) (xy 19.57578 0.27432)
@ -138,7 +148,7 @@
(xy 15.66418 0.127) (xy 16.06042 0.08382) (xy 16.48714 0.17018) (xy 16.68018 0.254) (xy 17.018 0.42672) (xy 17.018 2.23774)
(xy 17.018 4.04876) (xy 17.018 4.04876))
)
(bitmap (name "") (pos 131.5022 27.0072) (scale 0.75) (option page1only)
(bitmap (name "") (pos 131.5022 27.0072) (option page1only) (scale 0.75)
(pngdata
(data "89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52 00 00 01 72 00 00 00 C8 08 06 00 00 00 F5 02 6A ")
(data "AE 00 00 00 04 73 42 49 54 08 08 08 08 7C 08 64 88 00 00 00 09 70 48 59 73 00 00 2B 5C 00 00 2B ")

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 KiB

View File

@ -128,6 +128,7 @@ def test_pcb_print_simple_1(test_dir):
ctx.run()
ctx.expect_out_file(prj+'-F_Cu_mono.png')
ctx.expect_out_file(prj+'-F_Cu_color.png')
ctx.compare_image(prj+'-F_Cu_color.png', height='100%')
ctx.expect_out_file(prj+'-assembly_page_01.eps')
ctx.expect_out_file(prj+'-assembly_page_01.svg')
ctx.expect_out_file(prj+'-assembly.ps')