Skip to content

Commit 54a2f7d

Browse files
authored
Merge pull request #1 from sparkfun/release_candidate
v1.0.1 - better reporting; better parsing of ordering instructions
2 parents 1eb95f9 + 43bb637 commit 54a2f7d

File tree

3 files changed

+72
-54
lines changed

3 files changed

+72
-54
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ The code for this plugin is licensed under the MIT license. Please see `LICENSE`
5353

5454
`panelizer.py` is based heavily on [Simon John (@sej7278)](https://github.com/sej7278/kicad-panelizer)'s version of [Willem Hillier (@willemcvu)'s kicad-panelizer](https://github.com/willemcvu/kicad-panelizer).
5555

56-
The [wxFormBuilder](https://github.com/wxFormBuilder/wxFormBuilder/releases) `text_dialog.fbp` and associated code is based on [Greg Davill @gregdavill](https://github.com/gregdavill)'s [KiBuzzard](https://github.com/gregdavill/KiBuzzard).
56+
The [wxFormBuilder](https://github.com/wxFormBuilder/wxFormBuilder/releases) `text_dialog.fbp` and associated code is based on [Greg Davill (@gregdavill)](https://github.com/gregdavill)'s [KiBuzzard](https://github.com/gregdavill/KiBuzzard).
5757

5858
## How It Works
5959

SparkFunKiCadPanelizer/panelizer/panelizer.py

Lines changed: 70 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,20 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
118118
# Minimum spacer for exposed edge panels
119119
MINIMUM_SPACER = 6.35 # mm
120120

121+
INVALID_WIDTH = 999999999
122+
121123
# 'Extra' ordering instructions
122124
# Any PCB_TEXT containing any of these keywords will be copied into the ordering instructions
123125
possibleExtras = ['clean', 'Clean', 'CLEAN']
124126

127+
# Permutations for Ordering Instructions
128+
possibleOrderingInstructions = [
129+
"Ordering_Instructions",
130+
"ORDERING_INSTRUCTIONS",
131+
"Ordering Instructions",
132+
"ORDERING INSTRUCTIONS"
133+
]
134+
125135
sysExit = -1 # -1 indicates sysExit has not (yet) been set. The code below will set this to 0, 1, 2.
126136
report = "\nSTART: " + datetime.now().isoformat() + "\n"
127137

@@ -390,8 +400,8 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
390400
# Array of tracks
391401
# Note: Duplicate uses the same net name for the duplicated track.
392402
# This creates DRC unconnected net errors. (KiKit does this properly...)
393-
minTrackWidth = 999999999
394-
minViaDrill = 999999999
403+
minTrackWidth = INVALID_WIDTH
404+
minViaDrill = INVALID_WIDTH
395405
tracks = board.GetTracks()
396406
newTracks = []
397407
for sourceTrack in tracks: # iterate through each track to be copied
@@ -431,8 +441,9 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
431441
newModules = []
432442
prodIDs = []
433443
for sourceModule in modules:
434-
if "Ordering_Instructions" in sourceModule.GetFPIDAsString():
435-
orderingInstructionsSeen = True
444+
for instruction in possibleOrderingInstructions:
445+
if instruction in sourceModule.GetFPIDAsString():
446+
orderingInstructionsSeen = True
436447
if "SparkFun_Logo" in sourceModule.GetFPIDAsString():
437448
sparkfunLogoSeen = True
438449
if "SparkX_Logo" in sourceModule.GetFPIDAsString():
@@ -518,26 +529,28 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
518529
for sourceDrawing in drawings:
519530
if isinstance(sourceDrawing, pcbnew.PCB_TEXT):
520531
txt = sourceDrawing.GetShownText()
521-
if "mask" in txt or "Mask" in txt or "MASK" in txt:
522-
solderMask = txt
523-
if "layers" in txt or "Layers" in txt or "LAYERS" in txt:
524-
if numLayers is None: # Should we trust the instructions or the tracks?!
525-
numLayers = txt
526-
if "impedance" in txt or "Impedance" in txt or "IMPEDANCE" in txt:
527-
controlledImpedance = txt
528-
if "finish" in txt or "Finish" in txt or "FINISH" in txt:
529-
finish = txt
530-
if "thickness" in txt or "Thickness" in txt or "THICKNESS" in txt:
531-
thickness = txt
532-
if "material" in txt or "Material" in txt or "MATERIAL" in txt:
533-
material = txt
534-
if "weight" in txt or "Weight" in txt or "WEIGHT" in txt or "oz" in txt or "Oz" in txt or "OZ" in txt:
535-
copperWeight = txt
536-
for extra in possibleExtras:
537-
if extra in txt:
538-
if orderingExtras is None:
539-
orderingExtras = ""
540-
orderingExtras += txt + "\n"
532+
lines = txt.splitlines()
533+
for line in lines:
534+
if "mask" in line or "Mask" in line or "MASK" in line:
535+
solderMask = line
536+
if "layers" in line or "Layers" in line or "LAYERS" in line:
537+
if numLayers is None: # Should we trust the instructions or the tracks?!
538+
numLayers = line
539+
if "impedance" in line or "Impedance" in line or "IMPEDANCE" in line:
540+
controlledImpedance = line
541+
if "finish" in line or "Finish" in line or "FINISH" in line:
542+
finish = line
543+
if "thickness" in line or "Thickness" in line or "THICKNESS" in line:
544+
thickness = line
545+
if "material" in line or "Material" in line or "MATERIAL" in line:
546+
material = line
547+
if "weight" in line or "Weight" in line or "WEIGHT" in line or "oz" in line or "Oz" in line or "OZ" in line:
548+
copperWeight = line
549+
for extra in possibleExtras:
550+
if extra in line:
551+
if orderingExtras is None:
552+
orderingExtras = ""
553+
orderingExtras += line + "\n"
541554
pos = sourceDrawing.GetPosition() # Check if drawing is outside the bounding box
542555
if pos.x >= boardLeftEdge and pos.x <= boardRightEdge and \
543556
pos.y >= boardTopEdge and pos.y <= boardBottomEdge:
@@ -1070,27 +1083,29 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
10701083
if material is not None:
10711084
report += material + "\n"
10721085
if solderMask is None:
1073-
solderMask = "Solder Mask: Red"
1086+
solderMask = "Solder Mask: Red (Default)"
10741087
report += solderMask + "\n"
10751088
if silkscreen is None:
1076-
silkscreen = "Silkscreen: White"
1089+
silkscreen = "Silkscreen: White (Default)"
10771090
report += silkscreen + "\n"
10781091
if numLayers is None:
1079-
numLayers = "Layers: 2"
1092+
numLayers = "Layers: 2 (Default)"
10801093
report += numLayers + "\n"
10811094
if finish is None:
1082-
finish = "Finish: HASL Lead-free"
1095+
finish = "Finish: HASL Lead-free (Default)"
10831096
report += finish + "\n"
10841097
if thickness is None:
1085-
thickness = "Thickness: 1.6mm"
1098+
thickness = "Thickness: 1.6mm (Default)"
10861099
report += thickness + "\n"
10871100
if copperWeight is None:
1088-
copperWeight = "Copper weight: 1oz"
1101+
copperWeight = "Copper weight: 1oz (Default)"
10891102
report += copperWeight + "\n"
1090-
report += "Minimum track width: {:.2f}mm ({:.2f}mil)\n".format(
1091-
float(minTrackWidth) / SCALE, float(minTrackWidth) * 1000 / (SCALE * 25.4))
1092-
report += "Minimum via drill: {:.2f}mm ({:.2f}mil)\n".format(
1093-
float(minViaDrill) / SCALE, float(minViaDrill) * 1000 / (SCALE * 25.4))
1103+
if minTrackWidth < INVALID_WIDTH:
1104+
report += "Minimum track width: {:.2f}mm ({:.2f}mil)\n".format(
1105+
float(minTrackWidth) / SCALE, float(minTrackWidth) * 1000 / (SCALE * 25.4))
1106+
if minViaDrill < INVALID_WIDTH:
1107+
report += "Minimum via drill: {:.2f}mm ({:.2f}mil)\n".format(
1108+
float(minViaDrill) / SCALE, float(minViaDrill) * 1000 / (SCALE * 25.4))
10941109
if orderingExtras is not None:
10951110
report += orderingExtras
10961111
else:
@@ -1110,66 +1125,69 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
11101125
if wx.GetApp() is not None and orderingInstructionsSeen:
11111126
resp = wx.MessageBox("Solder mask color not found!",
11121127
'Warning', wx.OK | wx.ICON_WARNING)
1113-
solderMask = "Solder Mask: Red"
1128+
solderMask = "Solder Mask: Red (Default)"
11141129
oi.write(solderMask + "\n")
11151130
if silkscreen is None:
11161131
if wx.GetApp() is not None and orderingInstructionsSeen:
11171132
resp = wx.MessageBox("Silkscreen color not found!",
11181133
'Warning', wx.OK | wx.ICON_WARNING)
1119-
silkscreen = "Silkscreen: White"
1134+
silkscreen = "Silkscreen: White (Default)"
11201135
oi.write(silkscreen + "\n")
11211136
if numLayers is None:
11221137
if wx.GetApp() is not None and orderingInstructionsSeen:
11231138
resp = wx.MessageBox("Number of layers not found!",
11241139
'Warning', wx.OK | wx.ICON_WARNING)
1125-
numLayers = "Layers: 2"
1140+
numLayers = "Layers: 2 (Default)"
11261141
oi.write(numLayers + "\n")
11271142
if finish is None:
11281143
if wx.GetApp() is not None and orderingInstructionsSeen:
11291144
resp = wx.MessageBox("PCB finish not found!",
11301145
'Warning', wx.OK | wx.ICON_WARNING)
1131-
finish = "Finish: HASL Lead-free"
1146+
finish = "Finish: HASL Lead-free (Default)"
11321147
oi.write(finish + "\n")
11331148
if thickness is None:
11341149
if wx.GetApp() is not None and orderingInstructionsSeen:
11351150
resp = wx.MessageBox("PCB thickness not found!",
11361151
'Warning', wx.OK | wx.ICON_WARNING)
1137-
thickness = "Thickness: 1.6mm"
1152+
thickness = "Thickness: 1.6mm (Default)"
11381153
oi.write(thickness + "\n")
11391154
if copperWeight is None:
11401155
if wx.GetApp() is not None and orderingInstructionsSeen:
11411156
resp = wx.MessageBox("Copper weight not found!",
11421157
'Warning', wx.OK | wx.ICON_WARNING)
1143-
copperWeight = "Copper weight: 1oz"
1158+
copperWeight = "Copper weight: 1oz (Default)"
11441159
oi.write(copperWeight + "\n")
1145-
oi.write("Minimum track width: {:.2f}mm ({:.2f}mil)\n".format(
1146-
float(minTrackWidth) / SCALE, float(minTrackWidth) * 1000 / (SCALE * 25.4)))
1147-
oi.write("Minimum via drill: {:.2f}mm ({:.2f}mil)\n".format(
1148-
float(minViaDrill) / SCALE, float(minViaDrill) * 1000 / (SCALE * 25.4)))
1160+
if minTrackWidth < INVALID_WIDTH:
1161+
oi.write("Minimum track width: {:.2f}mm ({:.2f}mil)\n".format(
1162+
float(minTrackWidth) / SCALE, float(minTrackWidth) * 1000 / (SCALE * 25.4)))
1163+
if minViaDrill < INVALID_WIDTH:
1164+
oi.write("Minimum via drill: {:.2f}mm ({:.2f}mil)\n".format(
1165+
float(minViaDrill) / SCALE, float(minViaDrill) * 1000 / (SCALE * 25.4)))
11491166
if orderingExtras is not None:
11501167
oi.write(orderingExtras)
11511168
except Exception as e:
11521169
# Don't throw exception if we can't save ordering instructions
11531170
pass
11541171

1155-
if (prodIDs is not None):
1172+
if len(prodIDs) > 0:
11561173
emptyProdIDs = {}
11571174
for prodID in prodIDs:
11581175
if (prodID[0] == '') or (prodID[0] == ' '):
11591176
if prodID[1] not in emptyProdIDs:
11601177
emptyProdIDs[prodID[1]] = 1
11611178
else:
11621179
emptyProdIDs[prodID[1]] = emptyProdIDs[prodID[1]] + 1
1163-
if wx.GetApp() is not None and orderingInstructionsSeen and emptyProdIDs:
1180+
if len(emptyProdIDs) > 0:
11641181
refs = ""
1165-
for keys, value in emptyProdIDs.items():
1182+
for ref, num in emptyProdIDs.items():
11661183
if refs == "":
1167-
refs += keys
1184+
refs += ref
11681185
else:
1169-
refs += "," + keys
1170-
resp = wx.MessageBox("Empty (undefined) PROD_IDs found!\n" + refs,
1171-
'Warning', wx.OK | wx.ICON_WARNING)
1172-
report += "Empty (undefined) PROD_IDs found!" + refs + "\n"
1186+
refs += "," + ref
1187+
if wx.GetApp() is not None and orderingInstructionsSeen:
1188+
resp = wx.MessageBox("Empty (undefined) PROD_IDs found!\n" + refs,
1189+
'Warning', wx.OK | wx.ICON_WARNING)
1190+
report += "Empty (undefined) PROD_IDs found: " + refs + "\n"
11731191
sysExit = 1
11741192

11751193
if sysExit < 0:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.0"
1+
__version__ = "1.0.1"

0 commit comments

Comments
 (0)