Skip to content

Commit 8433082

Browse files
committed
Handle modified layer names
1 parent e274cc1 commit 8433082

File tree

5 files changed

+71
-43
lines changed

5 files changed

+71
-43
lines changed

SparkFunKiCadCAMmer/cammer/cammer.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,11 @@ def startCAMmer(self, args, board=None, logger=None):
102102
layertable = {}
103103
numlayers = PCB_LAYER_ID_COUNT
104104
for i in range(numlayers):
105-
layertable[board.GetLayerName(i)] = i
105+
layertable[i] = {'standardName': board.GetStandardLayerName(i), 'actualName': board.GetLayerName(i)}
106106

107107
# Protel file extensions
108108
file_ext = {
109109
"F.Cu": "GTL",
110-
"In1.Cu": "GL1",
111-
"In2.Cu": "GL2",
112-
"In3.Cu": "GL3",
113-
"In4.Cu": "GL4",
114110
"B.Cu": "GBL",
115111
"F.Mask": "GTS",
116112
"B.Mask": "GBS",
@@ -120,6 +116,8 @@ def startCAMmer(self, args, board=None, logger=None):
120116
"B.Silkscreen": "GBO",
121117
"Edge.Cuts": "GKO"
122118
}
119+
for i in range(1,31): # Add 30 internal copper layers
120+
file_ext["In{}.Cu".format(i)] = "GL{}".format(i)
123121

124122
# Start plotting: https://gitlab.com/kicad/code/kicad/-/blob/master/demos/python_scripts_examples/plot_board.py
125123

@@ -155,7 +153,12 @@ def startCAMmer(self, args, board=None, logger=None):
155153
sysExit= 2
156154
else:
157155
layername = layer.replace(".", "_")
158-
pctl.SetLayer(layertable[layer])
156+
layerNumber = None
157+
for id, names in layertable.items():
158+
if layer in names['standardName']:
159+
layerNumber = id
160+
break
161+
pctl.SetLayer(layerNumber)
159162
pctl.OpenPlotfile(layername, PLOT_FORMAT_GERBER)
160163
pctl.PlotLayer()
161164
pctl.ClosePlot() # Release the file - or we can't rename it
@@ -188,8 +191,10 @@ def startCAMmer(self, args, board=None, logger=None):
188191
if e in file_ext.keys():
189192
edge_ext = file_ext[e]
190193
layername = e.replace(".", "_")
191-
if e in layertable.keys():
192-
allEdges.push_back(layertable[e])
194+
for id, names in layertable.items():
195+
if e in names['standardName']:
196+
allEdges.push_back(id)
197+
break
193198

194199
if edge_ext == "":
195200
report += "Unknown edge(s): " + str(edges) + "\n"

SparkFunKiCadCAMmer/dialog/dialog.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,12 @@ def __init__(self, parent, config, layertable, cammer, func):
101101
for key in self.config.keys():
102102
deleteThese = []
103103
for layer in self.config[key].keys():
104-
if layer not in layertable.keys():
104+
found = False
105+
for id, names in self.layertable.items():
106+
if layer in names['standardName']:
107+
found = True
108+
break
109+
if not found:
105110
deleteThese.append(layer) # Avoids "dictionary changed size during iteration"
106111
for d in deleteThese:
107112
self.config[key].pop(d, None)
@@ -119,7 +124,12 @@ def __init__(self, parent, config, layertable, cammer, func):
119124
hasKey = layer in self.config[key].keys()
120125
except:
121126
pass
122-
if (layer not in layertable.keys()) or hasKey:
127+
found = False
128+
for id, names in self.layertable.items():
129+
if layer in names['standardName']:
130+
found = True
131+
break
132+
if (not found) or hasKey:
123133
deleteThese.append(layer)
124134
for d in deleteThese:
125135
defaults[key].pop(d, None)
@@ -129,9 +139,9 @@ def __init__(self, parent, config, layertable, cammer, func):
129139
# Add any extra layers which are present in layertable - default these to disabled
130140
for key in self.config.keys():
131141
addThese = []
132-
for layer in layertable.keys():
133-
if layer not in self.config[key].keys():
134-
addThese.append(layer)
142+
for id, names in self.layertable.items():
143+
if names['standardName'] not in self.config[key].keys():
144+
addThese.append(names['standardName'])
135145
for a in addThese:
136146
d = {a: 'false'} # JSON style
137147
self.config[key].update(d)
@@ -176,7 +186,12 @@ def LoadSettings(self):
176186
e = "1" if enabled == 'true' else "0" # JSON style
177187
self.LayersGrid.SetCellValue(row, 0, e)
178188
self.LayersGrid.SetCellRenderer(row, 0, wx.grid.GridCellBoolRenderer())
179-
self.LayersGrid.SetCellValue(row, 1, layer)
189+
layerName = layer
190+
for id, names in self.layertable.items():
191+
if layer in names['standardName']:
192+
if names['actualName'] != names['standardName']:
193+
layerName += " (" + names['actualName'] + ")"
194+
self.LayersGrid.SetCellValue(row, 1, layerName)
180195
self.LayersGrid.SetReadOnly(row, 1)
181196
row += 1
182197

@@ -191,7 +206,12 @@ def LoadSettings(self):
191206
e = "1" if enabled == 'true' else "0" # JSON style
192207
self.EdgesGrid.SetCellValue(row, 0, e)
193208
self.EdgesGrid.SetCellRenderer(row, 0, wx.grid.GridCellBoolRenderer())
194-
self.EdgesGrid.SetCellValue(row, 1, layer)
209+
layerName = layer
210+
for id, names in self.layertable.items():
211+
if layer in names['standardName']:
212+
if names['actualName'] != names['standardName']:
213+
layerName += " (" + names['actualName'] + ")"
214+
self.EdgesGrid.SetCellValue(row, 1, layerName)
195215
self.EdgesGrid.SetReadOnly(row, 1)
196216
row += 1
197217

@@ -200,14 +220,18 @@ def CurrentSettings(self):
200220

201221
for row in range(self.LayersGrid.GetNumberRows()):
202222
enabled = 'true' if (self.LayersGrid.GetCellValue(row, 0) == "1") else 'false' # JSON style
203-
layer = self.LayersGrid.GetCellValue(row, 1)
204-
d = {layer: enabled}
223+
layername = self.LayersGrid.GetCellValue(row, 1)
224+
if " (" in layername:
225+
layername = layername[:layername.find(" (")] # Trim the actual name - if present
226+
d = {layername: enabled}
205227
params['Layers'].update(d)
206228

207229
for row in range(self.EdgesGrid.GetNumberRows()):
208230
enabled = 'true' if (self.EdgesGrid.GetCellValue(row, 0) == "1") else 'false' # JSON style
209-
layer = self.EdgesGrid.GetCellValue(row, 1)
210-
d = {layer: enabled}
231+
layername = self.EdgesGrid.GetCellValue(row, 1)
232+
if " (" in layername:
233+
layername = layername[:layername.find(" (")] # Trim the actual name - if present
234+
d = {layername: enabled}
211235
params['Edges'].update(d)
212236

213237
return params

SparkFunKiCadCAMmer/plugin.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,19 @@ def Run(self):
6969
layertable = {}
7070
numlayers = pcbnew.PCB_LAYER_ID_COUNT
7171
for i in range(numlayers):
72-
layertable[board.GetLayerName(i)] = i
72+
layertable[i] = {'standardName': board.GetStandardLayerName(i), 'actualName': board.GetLayerName(i)}
7373

7474
# Check the number of copper layers. Delete unwanted layers from the table.
7575
wantedCopper = []
76-
if board.GetCopperLayerCount() >= 2:
77-
wantedCopper.extend(['F.Cu','B.Cu'])
78-
if board.GetCopperLayerCount() >= 4:
79-
wantedCopper.extend(['In1.Cu','In2.Cu'])
80-
if board.GetCopperLayerCount() >= 6:
81-
wantedCopper.extend(['In3.Cu','In4.Cu'])
76+
wantedCopper.append("F.Cu")
77+
wantedCopper.append("B.Cu")
78+
if (board.GetCopperLayerCount() > 2):
79+
for i in range(1, board.GetCopperLayerCount() - 1):
80+
wantedCopper.append("In{}.Cu".format(i))
8281
deleteLayers = []
83-
for layer in layertable.keys():
84-
if layer[-3:] == ".Cu":
85-
if layer not in wantedCopper:
82+
for layer, names in layertable.items():
83+
if names['standardName'][-3:] == ".Cu":
84+
if names['standardName'] not in wantedCopper:
8685
deleteLayers.append(layer)
8786
for layer in deleteLayers:
8887
layertable.pop(layer, None)
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"

SparkFunKiCadCAMmer/test_dialog.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ def OnInit(self):
1212
config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'cammer_config.json')
1313

1414
layertable = {
15-
'F.Cu': 0,
16-
'In1.Cu': 1,
17-
'In2.Cu': 2,
18-
'B.Cu': 5,
19-
'F.Paste': 6,
20-
'B.Paste': 7,
21-
'F.Silkscreen': 8,
22-
'B.Silkscreen': 9,
23-
'F.Mask': 10,
24-
'B.Mask': 11,
25-
'Edge.Cuts': 12,
26-
'User.Comments': 13,
27-
'Fake.Fake': 20
15+
0: { 'standardName': 'F.Cu', 'actualName': 'F-Cu-Renamed' },
16+
1: { 'standardName': 'In1.Cu', 'actualName': 'In1-Cu-Renamed' },
17+
2: { 'standardName': 'In2.Cu', 'actualName': 'In2.Cu' },
18+
5: { 'standardName': 'B.Cu', 'actualName': 'B.Cu' },
19+
6: { 'standardName': 'F.Paste', 'actualName': 'F.Paste' },
20+
7: { 'standardName': 'B.Paste', 'actualName': 'B.Paste' },
21+
8: { 'standardName': 'F.Silkscreen', 'actualName': 'F.Silkscreen' },
22+
9: { 'standardName': 'B.Silkscreen', 'actualName': 'B.Silkscreen' },
23+
10: { 'standardName': 'F.Mask', 'actualName': 'F.Mask' },
24+
11: { 'standardName': 'B.Mask', 'actualName': 'B.Mask' },
25+
12: { 'standardName': 'Edge.Cuts', 'actualName': 'Edge.Cuts' },
26+
13: { 'standardName': 'User.Comments', 'actualName': 'User.Comments' },
27+
20: { 'standardName': 'Fake.Fake', 'actualName': 'Fake.Fake' }
2828
}
2929

3030
self.frame = frame = Dialog(None, config_file, layertable, CAMmer(), self.run)

0 commit comments

Comments
 (0)