Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: plot board layers for kicad 8 (and later?) #174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions pcbdraw/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from pcbdraw.unit import read_resistance
import svgpathtools # type: ignore
from lxml import etree, objectify # type: ignore
from pcbnewTransition import KICAD_VERSION, isV6, isV7, isV8, pcbnew # type: ignore
from pcbnewTransition import KICAD_VERSION, isV6, isV7, pcbnew # type: ignore

T = TypeVar("T")
Numeric = Union[int, float]
Expand All @@ -41,7 +41,8 @@

etree.register_namespace("xlink", "http://www.w3.org/1999/xlink")

LEGACY_KICAD = not isV6() and not isV7() and not isV8()
LEGACY_KICAD5 = KICAD_VERSION[0] < 6 and not isV6() # 5.99 counts as "6" in kicad versioning
LEGACY_KICAD6 = KICAD_VERSION[0] < 7 and not isV7() # 6.99 counts as "7" in kicad versioning

default_style = {
"copper": "#417e5a",
Expand Down Expand Up @@ -112,9 +113,9 @@ def is_same(p1: Point, p2: Point) -> bool:
dx = p1[0] - p2[0]
dy = p1[1] - p2[1]
pseudo_distance = dx*dx + dy*dy
if isV7():
return pseudo_distance < 0.01 ** 2
return pseudo_distance < 100 ** 2
if LEGACY_KICAD6:
return pseudo_distance < 100 ** 2
return pseudo_distance < 0.01 ** 2

def format(self, first: bool) -> str:
ret = ""
Expand Down Expand Up @@ -590,7 +591,7 @@ def collect_holes(board: pcbnew.BOARD) -> List[Hole]:
orientation=pad.GetOrientation(),
drillsize=(drs.x, drs.y)
))
via_type = pcbnew.VIA if LEGACY_KICAD else pcbnew.PCB_VIA
via_type = pcbnew.VIA if LEGACY_KICAD5 else pcbnew.PCB_VIA
for track in board.GetTracks():
if not isinstance(track, via_type):
continue
Expand Down Expand Up @@ -1030,15 +1031,15 @@ def __init__(self, board: Union[str, pcbnew.BOARD]):

self.yield_warning: Callable[[str, str], None] = lambda tag, msg: None # Handle warnings

if isV7():
self.ki2svg = self._ki2svg_v7
self.svg2ki = self._svg2ki_v7
elif isV6():
if LEGACY_KICAD5:
self.ki2svg = self._ki2svg_v5
self.svg2ki = self._svg2ki_v5
elif LEGACY_KICAD6:
self.ki2svg = self._ki2svg_v6
self.svg2ki = self._svg2ki_v6
else:
self.ki2svg = self._ki2svg_v5
self.svg2ki = self._svg2ki_v5
self.ki2svg = self._ki2svg_v7
self.svg2ki = self._svg2ki_v7

@property
def svg_precision(self) -> int:
Expand Down Expand Up @@ -1216,9 +1217,11 @@ def execute_plot_plan(self, to_plot: List[PlotAction]) -> None:
# Method does not exist in older versions of KiCad
pass
popt.SetTextMode(pcbnew.PLOT_TEXT_MODE_STROKE)
if isV6():
if LEGACY_KICAD5:
pass
elif LEGACY_KICAD6:
popt.SetSvgPrecision(self.svg_precision, False)
if isV7():
else:
popt.SetSvgPrecision(self.svg_precision)
for action in to_plot:
if len(action.layers) == 0:
Expand Down