From e0ebf0dd1d78c09f7faa99f8a6b7a6efb474cf3e Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Thu, 8 Feb 2024 10:16:24 -0300 Subject: [PATCH] [PcbDraw][Fixed] Reverted upstream patch Breaks the bottom for KiCad 5/6 --- kibot/PcbDraw/README.md | 40 ++++++++++++++++++++++++++++++ kibot/PcbDraw/pcbnew_transition.py | 22 ++++++++-------- kibot/PcbDraw/plot.py | 16 ++---------- 3 files changed, 54 insertions(+), 24 deletions(-) diff --git a/kibot/PcbDraw/README.md b/kibot/PcbDraw/README.md index 6aa3a62b..ddf32727 100644 --- a/kibot/PcbDraw/README.md +++ b/kibot/PcbDraw/README.md @@ -613,4 +613,44 @@ index c9653ac5..a72a944c 100644 return ``` +## 2024-02-08 Revert changes, because impact on v5 +- The isV8() is not strictly needed, there to allow doing diffs between old and new generated SVGs +- The upstream approach fails to compute the mirror for KiCad 5/6, but I'm not sure if also for other cases + +```diff +diff --git a/kibot/PcbDraw/plot.py b/kibot/PcbDraw/plot.py +index a72a944c..dd86b03d 100644 +--- a/kibot/PcbDraw/plot.py ++++ b/kibot/PcbDraw/plot.py +@@ -384,7 +384,7 @@ def strip_style_svg(root: etree.Element, keys: List[str], forbidden_colors: List + for key, val in styles.items(): + if key not in keys or val == 'none': + new_styles[key] = val +- else: ++ elif isV8(): + new_styles[key] = new_val + el.attrib["style"] = ";" \ + .join([f"{key}: {val}" for key, val in new_styles.items()]) \ +@@ -1319,19 +1319,7 @@ class PcbPlotter(): + + from lxml.etree import tostring as serializeXml # type: ignore + from . import svgpathtools # type: ignore +- tree = xmlParse(serializeXml(svg)) +- +- # As we cannot interpret mask cropping, we cannot simply take all paths +- # from source document (as e.g., silkscreen outside PCB) would enlarge +- # the canvas. Instead, we take bounding box of the substrate and +- # components separately +- paths = [] +- components = tree.find(".//*[@id='componentContainer']") +- if components is not None: +- paths += svgpathtools.document.flattened_paths(components) +- substrate = tree.find(".//*[@id='cut-off']") +- if substrate is not None: +- paths += svgpathtools.document.flattened_paths(substrate) ++ paths = svgpathtools.document.flattened_paths(xmlParse(serializeXml(svg))) + + if len(paths) == 0: + return +``` diff --git a/kibot/PcbDraw/pcbnew_transition.py b/kibot/PcbDraw/pcbnew_transition.py index 095032a0..fc2ea842 100644 --- a/kibot/PcbDraw/pcbnew_transition.py +++ b/kibot/PcbDraw/pcbnew_transition.py @@ -192,16 +192,18 @@ if not isV7(KICAD_VERSION) and not isV8(KICAD_VERSION): for x in dir(pcbnew): patchRotate(getattr(pcbnew, x)) - originalCalcArcAngles = pcbnew.EDA_SHAPE.CalcArcAngles - if not getattr(originalCalcArcAngles, "patched", False): - def newCalcArcAngles(self, start, end): - start.value = self.GetArcAngleStart() / 10 - if self.GetShape() == pcbnew.SHAPE_T_CIRCLE: - end.value = start.value + 360 - else: - end.value = start.value + self.GetArcAngle() / 10 - setattr(newCalcArcAngles, "patched", True) - pcbnew.EDA_SHAPE.CalcArcAngles = newCalcArcAngles + # This is for v6 only, v5 fails + if isV6(KICAD_VERSION): + originalCalcArcAngles = pcbnew.EDA_SHAPE.CalcArcAngles + if not getattr(originalCalcArcAngles, "patched", False): + def newCalcArcAngles(self, start, end): + start.value = self.GetArcAngleStart() / 10 + if self.GetShape() == pcbnew.SHAPE_T_CIRCLE: + end.value = start.value + 360 + else: + end.value = start.value + self.GetArcAngle() / 10 + setattr(newCalcArcAngles, "patched", True) + pcbnew.EDA_SHAPE.CalcArcAngles = newCalcArcAngles # GetSelectMenuText for x in dir(pcbnew): diff --git a/kibot/PcbDraw/plot.py b/kibot/PcbDraw/plot.py index a72a944c..dd86b03d 100644 --- a/kibot/PcbDraw/plot.py +++ b/kibot/PcbDraw/plot.py @@ -384,7 +384,7 @@ def strip_style_svg(root: etree.Element, keys: List[str], forbidden_colors: List for key, val in styles.items(): if key not in keys or val == 'none': new_styles[key] = val - else: + elif isV8(): new_styles[key] = new_val el.attrib["style"] = ";" \ .join([f"{key}: {val}" for key, val in new_styles.items()]) \ @@ -1319,19 +1319,7 @@ class PcbPlotter(): from lxml.etree import tostring as serializeXml # type: ignore from . import svgpathtools # type: ignore - tree = xmlParse(serializeXml(svg)) - - # As we cannot interpret mask cropping, we cannot simply take all paths - # from source document (as e.g., silkscreen outside PCB) would enlarge - # the canvas. Instead, we take bounding box of the substrate and - # components separately - paths = [] - components = tree.find(".//*[@id='componentContainer']") - if components is not None: - paths += svgpathtools.document.flattened_paths(components) - substrate = tree.find(".//*[@id='cut-off']") - if substrate is not None: - paths += svgpathtools.document.flattened_paths(substrate) + paths = svgpathtools.document.flattened_paths(xmlParse(serializeXml(svg))) if len(paths) == 0: return