11
11
https://github.com/sej7278/kicad-panelizer
12
12
"""
13
13
14
- __panelizer_version__ = "2.0" # SFE's first version
15
-
16
14
import os
17
15
import sys
18
16
from argparse import ArgumentParser
21
19
from datetime import datetime
22
20
import wx
23
21
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
+
24
44
class Panelizer ():
25
45
def __init__ (self ):
26
46
pass
@@ -31,7 +51,7 @@ def args_parse(self, args):
31
51
# set up command-line arguments parser
32
52
parser = ArgumentParser (description = "A script to panelize KiCad 7 files." )
33
53
parser .add_argument (
34
- "-v" , "--version" , action = "version" , version = "%(prog)s " + __panelizer_version__
54
+ "-v" , "--version" , action = "version" , version = "%(prog)s " + _APP_VERSION
35
55
)
36
56
parser .add_argument (
37
57
"-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):
117
137
FIDUCIAL_FOOTPRINT_SMALL = "Fiducial_1mm_Mask3mm"
118
138
119
139
# Text for empty edges
120
- EMPTY_EDGE_TEXT = "SparkFun "
140
+ EMPTY_EDGE_TEXT = "Panelized "
121
141
122
142
# Minimum spacer for exposed edge panels
123
143
MINIMUM_SPACER = 6.35 # mm
@@ -562,7 +582,7 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
562
582
newDrawings = []
563
583
for sourceDrawing in drawings :
564
584
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'
566
586
lines = txt .splitlines ()
567
587
for line in lines :
568
588
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):
610
630
#if txt is not None: # Copy all text outside the bounding box to the report
611
631
# report += txt + "\n"
612
632
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 )))
614
635
elif pos .x > boardRightEdge : # If the drawing is to the right, move it beyond the panel
615
636
sourceDrawing .Move (pcbnew .VECTOR2I (int (((NUM_X - 1 ) * boardWidth ) + (VERTICAL_EDGE_RAIL_WIDTH * SCALE )), 0 ))
616
637
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):
960
981
# Add fiducials
961
982
962
983
# 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
964
987
if fiducialPath is not None :
965
988
fiducialPath = os .path .join (fiducialPath ,"Fiducial.pretty" )
966
989
else :
0 commit comments