Skip to content

Commit

Permalink
[PcbDraw][Fixed] Support for 7.0.1 polygons
Browse files Browse the repository at this point in the history
- Now KiCad generates polygons in the SVG
Fixes the problem reported in upstream: yaqwsx/PcbDraw#142
  • Loading branch information
set-soft committed Mar 27, 2023
1 parent d9cca11 commit 5f41606
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- KiKit present: problems when no board was specified. (#402)
- Datasheet download:
- Avoid interruptions when too many redirections is detected (#408)
- PcbDraw:
- KiCad 7.0.1 polygons used as board edge. (yaqwsx/PcbDraw#142)


## [1.6.1] - 2023-03-16
Expand Down
32 changes: 32 additions & 0 deletions kibot/PcbDraw/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,35 @@ index 8ca660e6..9dc45ba9 100644
center = footprint.GetPosition()
orient = math.radians(footprint.GetOrientation().AsDegrees())


## 2023-03-27 Fixe for KiCad 7.0.1 polygons

diff --git a/kibot/PcbDraw/plot.py b/kibot/PcbDraw/plot.py
index 9dc45ba9..8df84469 100644
--- a/kibot/PcbDraw/plot.py
+++ b/kibot/PcbDraw/plot.py
@@ -408,7 +408,22 @@ def get_board_polygon(svg_elements: etree.Element) -> etree.Element:
for group in svg_elements:
for svg_element in group:
if svg_element.tag == "path":
- elements.append(SvgPathItem(svg_element.attrib["d"]))
+ path = svg_element.attrib["d"]
+ # Check if this is a closed polygon (KiCad 7.0.1+)
+ polygon = re.fullmatch(r"M ((\d+\.\d+),(\d+\.\d+) )+Z", path)
+ if polygon:
+ # Yes, decompose it in lines
+ polygon = re.findall(r"(\d+\.\d+),(\d+\.\d+) ", path)
+ start = polygon[0]
+ # Close it
+ polygon.append(polygon[0])
+ # Add the lines
+ for end in polygon[1:]:
+ path = 'M'+start[0]+' '+start[1]+' L'+end[0]+' '+end[1]
+ elements.append(SvgPathItem(path))
+ start = end
+ else:
+ elements.append(SvgPathItem(path))
elif svg_element.tag == "circle":
# Convert circle to path
att = svg_element.attrib

17 changes: 16 additions & 1 deletion kibot/PcbDraw/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,22 @@ def get_board_polygon(svg_elements: etree.Element) -> etree.Element:
for group in svg_elements:
for svg_element in group:
if svg_element.tag == "path":
elements.append(SvgPathItem(svg_element.attrib["d"]))
path = svg_element.attrib["d"]
# Check if this is a closed polygon (KiCad 7.0.1+)
polygon = re.fullmatch(r"M ((\d+\.\d+),(\d+\.\d+) )+Z", path)
if polygon:
# Yes, decompose it in lines
polygon = re.findall(r"(\d+\.\d+),(\d+\.\d+) ", path)
start = polygon[0]
# Close it
polygon.append(polygon[0])
# Add the lines
for end in polygon[1:]:
path = 'M'+start[0]+' '+start[1]+' L'+end[0]+' '+end[1]
elements.append(SvgPathItem(path))
start = end
else:
elements.append(SvgPathItem(path))
elif svg_element.tag == "circle":
# Convert circle to path
att = svg_element.attrib
Expand Down

0 comments on commit 5f41606

Please sign in to comment.