Skip to content

Commit f0d018c

Browse files
authored
Merge pull request #11 from sparkfun/release_candidate
v1.2.0
2 parents fdfaeb9 + 84953b5 commit f0d018c

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SparkFun PCB Panelizer plugin for KiCad 7
1+
# SparkFun PCB Panelizer plugin for KiCad 7 / 8
22

33
This plugin converts a single PCB into a panel of multiple PCBs, separated by v-score grooves.
44

SparkFunKiCadPanelizer/panelizer/panelizer.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
https://github.com/sej7278/kicad-panelizer
1212
"""
1313

14-
__panelizer_version__ = "2.0" # SFE's first version
15-
1614
import os
1715
import sys
1816
from argparse import ArgumentParser
@@ -21,6 +19,28 @@
2119
from datetime import datetime
2220
import wx
2321

22+
# sub folder for our resource files
23+
_RESOURCE_DIRECTORY = os.path.join("..", "resource")
24+
25+
#https://stackoverflow.com/a/50914550
26+
def resource_path(relative_path):
27+
""" Get absolute path to resource, works for dev and for PyInstaller """
28+
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
29+
return os.path.join(base_path, _RESOURCE_DIRECTORY, relative_path)
30+
31+
def get_version(rel_path: str) -> str:
32+
try:
33+
with open(resource_path(rel_path), encoding='utf-8') as fp:
34+
for line in fp.read().splitlines():
35+
if line.startswith("__version__"):
36+
delim = '"' if '"' in line else "'"
37+
return line.split(delim)[1]
38+
raise RuntimeError("Unable to find version string.")
39+
except:
40+
raise RuntimeError("Unable to find _version.py.")
41+
42+
_APP_VERSION = get_version("_version.py")
43+
2444
class Panelizer():
2545
def __init__(self):
2646
pass
@@ -31,7 +51,7 @@ def args_parse(self, args):
3151
# set up command-line arguments parser
3252
parser = ArgumentParser(description="A script to panelize KiCad 7 files.")
3353
parser.add_argument(
34-
"-v", "--version", action="version", version="%(prog)s " + __panelizer_version__
54+
"-v", "--version", action="version", version="%(prog)s " + _APP_VERSION
3555
)
3656
parser.add_argument(
3757
"-p", "--path", help="Path to the *.kicad_pcb file to be panelized"
@@ -117,7 +137,7 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
117137
FIDUCIAL_FOOTPRINT_SMALL = "Fiducial_1mm_Mask3mm"
118138

119139
# Text for empty edges
120-
EMPTY_EDGE_TEXT = "SparkFun"
140+
EMPTY_EDGE_TEXT = "Panelized"
121141

122142
# Minimum spacer for exposed edge panels
123143
MINIMUM_SPACER = 6.35 # mm
@@ -562,7 +582,7 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
562582
newDrawings = []
563583
for sourceDrawing in drawings:
564584
if isinstance(sourceDrawing, pcbnew.PCB_TEXT):
565-
txt = sourceDrawing.GetShownText()
585+
txt = sourceDrawing.GetShownText(aAllowExtraText=True) # 8.0 Fix: PCB_TEXT.GetShownText() missing 1 required positional argument: 'aAllowExtraText'
566586
lines = txt.splitlines()
567587
for line in lines:
568588
if "mask" in line or "Mask" in line or "MASK" in line:
@@ -610,7 +630,8 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
610630
#if txt is not None: # Copy all text outside the bounding box to the report
611631
# report += txt + "\n"
612632
if pos.y > boardBottomEdge: # If the drawing is below the bottom edge, move it below the rail
613-
sourceDrawing.Move(pcbnew.VECTOR2I(0, int(HORIZONTAL_EDGE_RAIL_WIDTH * SCALE)))
633+
if pos.y < (boardBottomEdge + (HORIZONTAL_EDGE_RAIL_WIDTH * SCALE)): # But only if in the way
634+
sourceDrawing.Move(pcbnew.VECTOR2I(0, int(HORIZONTAL_EDGE_RAIL_WIDTH * SCALE)))
614635
elif pos.x > boardRightEdge: # If the drawing is to the right, move it beyond the panel
615636
sourceDrawing.Move(pcbnew.VECTOR2I(int(((NUM_X - 1) * boardWidth) + (VERTICAL_EDGE_RAIL_WIDTH * SCALE)), 0))
616637
elif pos.y < boardTopEdge: # If the drawing is above the top edge, move it above the panel
@@ -960,7 +981,9 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
960981
# Add fiducials
961982

962983
# Find the KiCad Fiducial footprints
963-
fiducialPath = os.getenv('KICAD7_FOOTPRINT_DIR') # This works when running the plugin inside KiCad
984+
kicadVersion = pcbnew.GetBuildVersion().split('.')[0]
985+
fiducialEnv = "KICAD{}_FOOTPRINT_DIR".format(kicadVersion)
986+
fiducialPath = os.getenv(fiducialEnv ) # This works when running the plugin inside KiCad
964987
if fiducialPath is not None:
965988
fiducialPath = os.path.join(fiducialPath,"Fiducial.pretty")
966989
else:

SparkFunKiCadPanelizer/plugin.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@ def __init__(self):
2727

2828
self._pcbnew_frame = None
2929

30+
self.supportedVersions = ['7.','8.']
31+
3032
self.kicad_build_version = pcbnew.GetBuildVersion()
3133

3234
productionDir = "Production"
3335

34-
def IsVersion(self, VersionStr):
35-
for v in VersionStr:
36-
if v in self.kicad_build_version:
36+
def IsSupported(self):
37+
for v in self.supportedVersions:
38+
if self.kicad_build_version.startswith(v):
3739
return True
3840
return False
39-
41+
4042
def Run(self):
4143
if self._pcbnew_frame is None:
4244
try:
@@ -94,7 +96,7 @@ def Run(self):
9496
def run_panelizer(dlg, p_panelizer):
9597
self.logger.log(logging.INFO, "Running Panelizer")
9698

97-
if self.IsVersion(['7.']):
99+
if self.IsSupported():
98100
command = []
99101

100102
convertDimensions = 1.0
@@ -157,6 +159,9 @@ def run_panelizer(dlg, p_panelizer):
157159
if sysExit > 0:
158160
wx.MessageBox("Panelizer " + ("warning" if (sysExit == 1) else "error") + ".\nPlease check panelizer.log for details.",
159161
("Warning" if (sysExit == 1) else "Error"), wx.OK | (wx.ICON_WARNING if (sysExit == 1) else wx.ICON_ERROR))
162+
else:
163+
wx.MessageBox("Panelizer complete.\nPlease check panelizer.log for details.",
164+
"Info", wx.OK | wx.ICON_INFORMATION)
160165
else:
161166
self.logger.log(logging.ERROR, "Could not get the board")
162167

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.1.3"
1+
__version__ = "1.2.0"

pcm/metadata_template.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://go.kicad.org/pcm/schemas/v1",
33
"name": "SparkFun KiCad Panelizer",
4-
"description": "SparkFun's simple PCB panelizer for KiCad 7",
4+
"description": "SparkFun's simple PCB panelizer for KiCad 7 / 8",
55
"description_full": "Converts a single PCB into a panel of multiple PCBs with v-scores in between",
66
"identifier": "com.github.sparkfun.SparkFunKiCadPanelizer",
77
"type": "plugin",

0 commit comments

Comments
 (0)