Skip to content

Commit

Permalink
Merge pull request #11 from sparkfun/release_candidate
Browse files Browse the repository at this point in the history
v1.2.0
  • Loading branch information
PaulZC authored Mar 18, 2024
2 parents fdfaeb9 + 84953b5 commit f0d018c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SparkFun PCB Panelizer plugin for KiCad 7
# SparkFun PCB Panelizer plugin for KiCad 7 / 8

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

Expand Down
37 changes: 30 additions & 7 deletions SparkFunKiCadPanelizer/panelizer/panelizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
https://github.com/sej7278/kicad-panelizer
"""

__panelizer_version__ = "2.0" # SFE's first version

import os
import sys
from argparse import ArgumentParser
Expand All @@ -21,6 +19,28 @@
from datetime import datetime
import wx

# sub folder for our resource files
_RESOURCE_DIRECTORY = os.path.join("..", "resource")

#https://stackoverflow.com/a/50914550
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, _RESOURCE_DIRECTORY, relative_path)

def get_version(rel_path: str) -> str:
try:
with open(resource_path(rel_path), encoding='utf-8') as fp:
for line in fp.read().splitlines():
if line.startswith("__version__"):
delim = '"' if '"' in line else "'"
return line.split(delim)[1]
raise RuntimeError("Unable to find version string.")
except:
raise RuntimeError("Unable to find _version.py.")

_APP_VERSION = get_version("_version.py")

class Panelizer():
def __init__(self):
pass
Expand All @@ -31,7 +51,7 @@ def args_parse(self, args):
# set up command-line arguments parser
parser = ArgumentParser(description="A script to panelize KiCad 7 files.")
parser.add_argument(
"-v", "--version", action="version", version="%(prog)s " + __panelizer_version__
"-v", "--version", action="version", version="%(prog)s " + _APP_VERSION
)
parser.add_argument(
"-p", "--path", help="Path to the *.kicad_pcb file to be panelized"
Expand Down Expand Up @@ -117,7 +137,7 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
FIDUCIAL_FOOTPRINT_SMALL = "Fiducial_1mm_Mask3mm"

# Text for empty edges
EMPTY_EDGE_TEXT = "SparkFun"
EMPTY_EDGE_TEXT = "Panelized"

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

# Find the KiCad Fiducial footprints
fiducialPath = os.getenv('KICAD7_FOOTPRINT_DIR') # This works when running the plugin inside KiCad
kicadVersion = pcbnew.GetBuildVersion().split('.')[0]
fiducialEnv = "KICAD{}_FOOTPRINT_DIR".format(kicadVersion)
fiducialPath = os.getenv(fiducialEnv ) # This works when running the plugin inside KiCad
if fiducialPath is not None:
fiducialPath = os.path.join(fiducialPath,"Fiducial.pretty")
else:
Expand Down
15 changes: 10 additions & 5 deletions SparkFunKiCadPanelizer/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ def __init__(self):

self._pcbnew_frame = None

self.supportedVersions = ['7.','8.']

self.kicad_build_version = pcbnew.GetBuildVersion()

productionDir = "Production"

def IsVersion(self, VersionStr):
for v in VersionStr:
if v in self.kicad_build_version:
def IsSupported(self):
for v in self.supportedVersions:
if self.kicad_build_version.startswith(v):
return True
return False

def Run(self):
if self._pcbnew_frame is None:
try:
Expand Down Expand Up @@ -94,7 +96,7 @@ def Run(self):
def run_panelizer(dlg, p_panelizer):
self.logger.log(logging.INFO, "Running Panelizer")

if self.IsVersion(['7.']):
if self.IsSupported():
command = []

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

Expand Down
2 changes: 1 addition & 1 deletion SparkFunKiCadPanelizer/resource/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.1.3"
__version__ = "1.2.0"
2 changes: 1 addition & 1 deletion pcm/metadata_template.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://go.kicad.org/pcm/schemas/v1",
"name": "SparkFun KiCad Panelizer",
"description": "SparkFun's simple PCB panelizer for KiCad 7",
"description": "SparkFun's simple PCB panelizer for KiCad 7 / 8",
"description_full": "Converts a single PCB into a panel of multiple PCBs with v-scores in between",
"identifier": "com.github.sparkfun.SparkFunKiCadPanelizer",
"type": "plugin",
Expand Down

0 comments on commit f0d018c

Please sign in to comment.