Skip to content

Commit

Permalink
[PcbDraw][Fixed] Reverted upstream patch
Browse files Browse the repository at this point in the history
Breaks the bottom for KiCad 5/6
  • Loading branch information
set-soft committed Feb 8, 2024
1 parent b2cf6f0 commit e0ebf0d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 24 deletions.
40 changes: 40 additions & 0 deletions kibot/PcbDraw/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
22 changes: 12 additions & 10 deletions kibot/PcbDraw/pcbnew_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,18 @@ def __init__(self, *args):
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):
Expand Down
16 changes: 2 additions & 14 deletions kibot/PcbDraw/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]) \
Expand Down Expand Up @@ -1319,19 +1319,7 @@ def _shrink_svg(self, svg: etree.ElementTree, margin: tuple, compute_bbox: bool=

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
Expand Down

0 comments on commit e0ebf0d

Please sign in to comment.