Skip to content
Merged
Show file tree
Hide file tree
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
63 changes: 19 additions & 44 deletions SparkFunKiCadPanelizer/panelizer/panelizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,6 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
# Any PCB_TEXT containing any of these keywords will be copied into the ordering instructions
possibleExtras = ['clean', 'Clean', 'CLEAN', 'stackup', 'Stackup', 'STACKUP']

# Permutations for Ordering Instructions
possibleOrderingInstructions = [
"Ordering_Instructions",
"ORDERING_INSTRUCTIONS",
"Ordering Instructions",
"ORDERING INSTRUCTIONS"
]

sysExit = -1 # -1 indicates sysExit has not (yet) been set. The code below will set this to 0, 1, 2.
report = "\nSTART: " + datetime.now().isoformat() + "\n"

Expand Down Expand Up @@ -368,9 +360,10 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
cutWidth = 0
drawings = board.GetDrawings()
for drawing in drawings:
if drawing.IsOnLayer(edgeLayerNumber):
if drawing.GetWidth() > cutWidth:
cutWidth = drawing.GetWidth()
if hasattr(drawing, "IsOnLayer") and hasattr(drawing, "GetWidth"):
if drawing.IsOnLayer(edgeLayerNumber):
if drawing.GetWidth() > cutWidth:
cutWidth = drawing.GetWidth()
#report += "Subtracting Edge.Cuts line width of {}mm.\n".format(cutWidth / SCALE)
boardWidth -= cutWidth
boardHeight -= cutWidth
Expand Down Expand Up @@ -443,7 +436,6 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
if PANEL_X or PANEL_Y:
report += "You can fit " + str(NUM_X) + " x " + str(NUM_Y) + " boards on the panel.\n"

orderingInstructionsSeen = False
sparkfunLogoSeen = False
sparkxLogoSeen = False
solderMask = None
Expand Down Expand Up @@ -495,9 +487,6 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
newModules = []
prodIDs = []
for sourceModule in modules:
for instruction in possibleOrderingInstructions:
if instruction in sourceModule.GetFPIDAsString():
orderingInstructionsSeen = True
if "SparkFun_Logo" in sourceModule.GetFPIDAsString():
sparkfunLogoSeen = True
if "SparkX_Logo" in sourceModule.GetFPIDAsString():
Expand Down Expand Up @@ -533,12 +522,13 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
ref = sourceModule.Reference().GetText()
prodIDs.append([sourceModule.GetPropertyNative("PROD_ID"), ref])
else: # Move source modules which are outside the bounding box
if pos.y > boardBottomEdge: # If the drawing is below the bottom edge, move it below the rail
# If the drawing is below the bottom edge and likely to clip the rail, move it below the rail
if (pos.y > boardBottomEdge) and (pos.y < (boardBottomEdge + (2 * int(HORIZONTAL_EDGE_RAIL_WIDTH * SCALE)))):
sourceModule.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
sourceModule.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
sourceModule.Move(pcbnew.VECTOR2I(0, int((-(NUM_Y - 1) * boardHeight) - (HORIZONTAL_EDGE_RAIL_WIDTH * SCALE))))
elif pos.x > boardRightEdge: # If the drawing is to the right, move it beyond the panel
sourceModule.Move(pcbnew.VECTOR2I(int(((NUM_X - 1) * boardWidth) + (VERTICAL_EDGE_RAIL_WIDTH * SCALE)), 0))
else: # elif pos.x < boardLeftEdge: # If the drawing is to the left, move it outside the rail
sourceModule.Move(pcbnew.VECTOR2I(int(-VERTICAL_EDGE_RAIL_WIDTH * SCALE), 0))

Expand Down Expand Up @@ -1190,13 +1180,6 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
sysExit = 1

# Add ordering instructions:
if not orderingInstructionsSeen:
if wx.GetApp() is not None:
resp = wx.MessageBox("Ordering Instructions not found!\nNo futher warnings will be given.",
'Warning', wx.OK | wx.ICON_WARNING)
report += "Ordering Instructions not found! No futher ordering warnings will be given.\n"
sysExit = 1

if ordering is None:
report += "\nOrdering Instructions:\n"
report += (
Expand Down Expand Up @@ -1236,6 +1219,7 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
report += orderingExtras
else:
try:
defaultsUsed = False
with open(ordering, 'w') as oi:
oi.write("Ordering Instructions:\n")
oi.write(
Expand All @@ -1248,39 +1232,27 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
if material is not None:
oi.write(material + "\n")
if solderMask is None:
if wx.GetApp() is not None and orderingInstructionsSeen:
resp = wx.MessageBox("Solder mask color not found!",
'Warning', wx.OK | wx.ICON_WARNING)
defaultsUsed = True
solderMask = "Solder Mask: Red (Default)"
oi.write(solderMask + "\n")
if silkscreen is None:
if wx.GetApp() is not None and orderingInstructionsSeen:
resp = wx.MessageBox("Silkscreen color not found!",
'Warning', wx.OK | wx.ICON_WARNING)
defaultsUsed = True
silkscreen = "Silkscreen: White (Default)"
oi.write(silkscreen + "\n")
if copperLayers is None:
if wx.GetApp() is not None and orderingInstructionsSeen:
resp = wx.MessageBox("Number of layers not found!",
'Warning', wx.OK | wx.ICON_WARNING)
defaultsUsed = True
copperLayers = "Layers: 2 (Default)"
oi.write(copperLayers + "\n")
if finish is None:
if wx.GetApp() is not None and orderingInstructionsSeen:
resp = wx.MessageBox("PCB finish not found!",
'Warning', wx.OK | wx.ICON_WARNING)
defaultsUsed = True
finish = "Finish: HASL Lead-free (Default)"
oi.write(finish + "\n")
if thickness is None:
if wx.GetApp() is not None and orderingInstructionsSeen:
resp = wx.MessageBox("PCB thickness not found!",
'Warning', wx.OK | wx.ICON_WARNING)
defaultsUsed = True
thickness = "Thickness: 1.6mm (Default)"
oi.write(thickness + "\n")
if copperWeight is None:
if wx.GetApp() is not None and orderingInstructionsSeen:
resp = wx.MessageBox("Copper weight not found!",
'Warning', wx.OK | wx.ICON_WARNING)
defaultsUsed = True
copperWeight = "Copper weight: 1oz (Default)"
oi.write(copperWeight + "\n")
if minTrackWidth < INVALID_WIDTH:
Expand All @@ -1291,6 +1263,9 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
float(minViaDrill) / SCALE, float(minViaDrill) * 1000 / (SCALE * 25.4)))
if orderingExtras is not None:
oi.write(orderingExtras)
if defaultsUsed:
report += "Warning: Ordering Instructions contains default values.\n"
sysExit = 1
except Exception as e:
# Don't throw exception if we can't save ordering instructions
pass
Expand All @@ -1310,7 +1285,7 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
refs += ref
else:
refs += "," + ref
if wx.GetApp() is not None and orderingInstructionsSeen:
if wx.GetApp() is not None:
resp = wx.MessageBox("Empty (undefined) PROD_IDs found!\n" + refs,
'Warning', wx.OK | wx.ICON_WARNING)
report += "Empty (undefined) PROD_IDs found: " + refs + "\n"
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.2.0"
__version__ = "1.3.0"