Skip to content

Commit

Permalink
Adapt to unit changes in v7 RC1
Browse files Browse the repository at this point in the history
  • Loading branch information
yaqwsx committed Jan 12, 2023
1 parent b23af18 commit 6e9c0b7
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions pcbdraw/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ def __init__(self, path: str) -> None:
def is_same(p1: Point, p2: Point) -> bool:
dx = p1[0] - p2[0]
dy = p1[1] - p2[1]
return math.sqrt(dx*dx+dy*dy) < 100
pseudo_distance = dx*dx + dy*dy
if isV7():
return pseudo_distance < 0.01 ** 2
return pseudo_distance < 100 ** 2

def format(self, first: bool) -> str:
ret = ""
Expand Down Expand Up @@ -1015,8 +1018,15 @@ def __init__(self, boardFile: str):

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

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

@property
def svg_precision(self) -> int:
Expand Down Expand Up @@ -1236,6 +1246,12 @@ def _ki2svg_v5(self, x: int) -> float:
def _svg2ki_v5(self, x: float) -> int:
return dmil2ki(x)

def _svg2ki_v7(self, x: float) -> int:
return int(pcbnew.FromMM(x))

def _ki2svg_v7(self, x: int) -> float:
return float(pcbnew.ToMM(x))

def _shrink_svg(self, svg: etree.ElementTree, margin: int) -> None:
"""
Shrink the SVG canvas to the size of the drawing. Add margin in
Expand Down

0 comments on commit 6e9c0b7

Please sign in to comment.