Skip to content

Commit 13acfe8

Browse files
committed
[PCB Print][Fixed] Worksheet page 1 vs other pages look
- When using the internal mechanism Fixes #903
1 parent 51a41a8 commit 13acfe8

4 files changed

Lines changed: 34 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3434
- Panelize:
3535
- Problems when using angles (#898)
3636
- Confusing error when the output wasn't generated
37+
- PCB Print: worksheet page 1 vs other pages look when using the internal
38+
mechanism (#903)
3739

3840
### Changed
3941
- `--fail-on-warnings` now ignores filtered warning (as the help suggested)

docs/source/Changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ Fixed
6161
- Problems when using angles (#898)
6262
- Confusing error when the output wasn’t generated
6363

64+
- PCB Print: worksheet page 1 vs other pages look when using the
65+
internal mechanism (#903)
66+
6467
Changed
6568
~~~~~~~
6669

kibot/kicad/worksheet.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (c) 2022-2024 Salvador E. Tropea
3-
# Copyright (c) 2022-2024 Instituto Nacional de Tecnología Industrial
2+
# Copyright (c) 2022-2026 Salvador E. Tropea
3+
# Copyright (c) 2022-2026 Instituto Nacional de Tecnología Industrial
44
# License: AGPL-3.0
55
# Project: KiBot (formerly KiPlot)
66
# KiCad bugs:
77
# - Text bold doesn't work
88
# - Shape Line and Rect swapped
99
"""
10-
KiCad v5/6/7/8 Worksheet format.
10+
KiCad v5/6/7/8/9 Worksheet format.
1111
A basic implementation of the .kicad_wks file format.
1212
Documentation: https://dev-docs.kicad.org/en/file-formats/sexpr-worksheet/
1313
"""
1414
from base64 import b64decode
15+
from copy import deepcopy
1516
import io
1617
from pcbnew import wxPoint, wxSize, FromMM, wxPointMM
1718
from ..gs import GS
@@ -30,7 +31,7 @@
3031
from .pcb import get_embedded_file
3132
from .pcb_draw_helpers import (GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_HJUSTIFY_CENTER,
3233
GR_TEXT_VJUSTIFY_TOP, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_BOTTOM)
33-
from .sexpdata import load, dumps, SExpData
34+
from .sexpdata import load, dumps, SExpData, Symbol
3435
from .sexp_helpers import (_check_is_symbol_list, _check_float, _check_integer, _check_symbol_value, _check_str, _check_symbol,
3536
_check_relaxed, _get_points, _check_symbol_str, Color)
3637
from ..svgutils.transform import ImageElement, GroupElement
@@ -48,6 +49,7 @@
4849
'C3': 'COMMENT4', 'C4': 'COMMENT5', 'C5': 'COMMENT6', 'C6': 'COMMENT7', 'C7': 'COMMENT8',
4950
'C8': 'COMMENT9', 'Y': 'COMPANY', 'F': 'FILENAME', 'D': 'ISSUE_DATE', 'Z': 'PAPER', 'R': 'REVISION',
5051
'P': 'SHEETNAME', 'T': 'TITLE'}
52+
REVERSE_OPTION = {'page1only': 'notonpage1', 'notonpage1': 'page1only'}
5153

5254

5355
class WksError(Exception):
@@ -589,8 +591,27 @@ def expand(self, vars, remove_images=False):
589591
new_sexp.append(e)
590592
self.sexp = new_sexp
591593

592-
def save(self, fname):
593-
""" Save the sexp to a file """
594+
def save(self, fname, page=None):
595+
""" Save the sexp to a file.
596+
Can also adapt the `option` to match the page when using a tool for only one page """
597+
sexp = self.sexp
598+
if page is not None and page != 1:
599+
# A page number is provided
600+
# Here we change things so KiCad can print it as page 1, but the page looks correct
601+
logger.debugl(2, f" - Changing things for page {page}")
602+
sexp = deepcopy(self.sexp)
603+
for e in sexp[1:]:
604+
e_type = _check_is_symbol_list(e)
605+
for o in e[1:]:
606+
if isinstance(o, list):
607+
smb = _check_is_symbol_list(o)
608+
if smb == 'option':
609+
# page1only -> notonpage1
610+
# notonpage1 -> page1only
611+
old = o[1]
612+
o[1] = Symbol(REVERSE_OPTION[_check_symbol(o, 1, smb)])
613+
logger.debugl(3, f" - Changing {e_type}: {old} -> {o[1]}")
614+
594615
with open(fname, 'wt') as f:
595-
f.write(dumps(self.sexp))
616+
f.write(dumps(sexp))
596617
f.write('\n')

kibot/out_pcb_print.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ def plot_frame_ki8_external(self, dir_name, p, page, pages, color):
736736
# Expand the variables in the copied worksheet
737737
tb_vars = self.fill_kicad_vars(page, pages, p)
738738
ws.expand(tb_vars, remove_images=True)
739-
ws.save(wks)
739+
ws.save(wks, page)
740740
# Plot the frame using a helper script
741741
# kicad-cli fails: https://gitlab.com/kicad/code/kicad/-/issues/18928
742742
script = os.path.join(GS.get_resource_path('tools'), 'frame_plotter')

0 commit comments

Comments
 (0)