From 4180a9afb66631f12f969beab270bba1dc81326f Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Thu, 9 Jan 2025 09:45:21 -0300 Subject: [PATCH] [PCB Print][Fixed] Problems when using the default worksheet - And the internal frame plotter - Variables not expanded Fixes #767 --- CHANGELOG.md | 3 +++ docs/source/Changelog.rst | 5 +++++ kibot/kicad/worksheet.py | 3 ++- kibot/out_pcb_print.py | 36 +++++++++++++++--------------------- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 040d1c09..a4d26ac8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Via pairs overwritten by PTH files (#758) - Navigate Results: - Problems when using `erc: true` or `drc: true` (#742) +- PCB Print: + - Problems when using the default worksheet and the internal frame plotter + (#767) ### Changed - Default temporal layer for internal use is now "Margin", instead of "User.9" diff --git a/docs/source/Changelog.rst b/docs/source/Changelog.rst index 91c155a4..8c1ceb5d 100644 --- a/docs/source/Changelog.rst +++ b/docs/source/Changelog.rst @@ -156,6 +156,11 @@ Fixed - Problems when using ``erc: true`` or ``drc: true`` (#742) +- PCB Print: + + - Problems when using the default worksheet and the internal frame + plotter (#767) + Changed ~~~~~~~ diff --git a/kibot/kicad/worksheet.py b/kibot/kicad/worksheet.py index 64171f7c..0eb4120c 100644 --- a/kibot/kicad/worksheet.py +++ b/kibot/kicad/worksheet.py @@ -500,7 +500,8 @@ def load(file): elif e_type == 'tbtext': obj = WksText.parse(e) if not version: - obj.text = text_from_ki5(obj.text) + # Translate KiCad 5 %X markers, and also change the sexp tree + e[1] = obj.text = text_from_ki5(obj.text) elements.append(obj) elif e_type == 'polygon': elements.append(WksPolygon.parse(e)) diff --git a/kibot/out_pcb_print.py b/kibot/out_pcb_print.py index 96fc3c34..4a239165 100644 --- a/kibot/out_pcb_print.py +++ b/kibot/out_pcb_print.py @@ -703,28 +703,22 @@ def plot_frame_ki8_external(self, dir_name, p, page, pages, color): self.pcb.write(pcb_name) # Copy the project pro_name, _, _ = GS.copy_project(pcb_name) - # Make a local WKS available - if self._sheet_reference_layout: - # Worksheet override - wks = os.path.abspath(self._sheet_reference_layout) - wks = KiConf.fix_page_layout(os.path.join(pcb_dir, GS.pro_fname), force_pcb=wks, force_sch=wks) - else: - # Original worksheet - wks = KiConf.fix_page_layout(os.path.join(pcb_dir, GS.pro_fname)) + # Copy the layout, user provided or default, we need to expand vars here + # In particular KiBot internal stuff + wks = KiConf.fix_page_layout(os.path.join(pcb_dir, GS.pro_fname), force_pcb=self.layout, force_sch=self.layout) wks = wks[1] - if wks: - logger.debugl(1, ' - Worksheet: '+wks) - try: - ws = kicad_worksheet.Worksheet.load(wks) - error = None - except (kicad_worksheet.WksError, SchError) as e: - error = str(e) - if error: - raise KiPlotConfigurationError('Error reading `{}` ({})'.format(wks, error)) - # Expand the variables in the copied worksheet - tb_vars = self.fill_kicad_vars(page, pages, p) - ws.expand(tb_vars, remove_images=True) - ws.save(wks) + logger.debugl(1, ' - Worksheet: '+wks) + try: + ws = kicad_worksheet.Worksheet.load(wks) + error = None + except (kicad_worksheet.WksError, SchError) as e: + error = str(e) + if error: + raise KiPlotConfigurationError('Error reading `{}` ({})'.format(wks, error)) + # Expand the variables in the copied worksheet + tb_vars = self.fill_kicad_vars(page, pages, p) + ws.expand(tb_vars, remove_images=True) + ws.save(wks) # Plot the frame using a helper script # kicad-cli fails: https://gitlab.com/kicad/code/kicad/-/issues/18928 script = os.path.join(GS.get_resource_path('tools'), 'frame_plotter')