Skip to content

Commit 6dfbaea

Browse files
committed
Add gerber drills
1 parent d3b331e commit 6dfbaea

File tree

3 files changed

+62
-14
lines changed

3 files changed

+62
-14
lines changed

docs/samples/generic_plot.kiplot.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ outputs:
5252
map:
5353
type: 'pdf'
5454

55+
- name: gerber drills
56+
comment: "Gerber drill files"
57+
type: gerb_drill
58+
dir: gerberdir
59+
options:
60+
use_aux_axis_as_origin: false
61+
5562
- name: postscript
5663
comment: "Postscript files"
5764
type: ps

kiplot/kiplot.py

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,16 @@ def _output_is_layer(self, output):
6060
PCfg.OutputOptions.GERBER,
6161
PCfg.OutputOptions.POSTSCRIPT,
6262
PCfg.OutputOptions.DXF,
63+
PCfg.OutputOptions.SVG,
64+
PCfg.OutputOptions.PDF,
65+
PCfg.OutputOptions.HPGL,
6366
]
6467

6568
def _output_is_drill(self, output):
6669

6770
return output.options.type in [
6871
PCfg.OutputOptions.EXCELLON,
72+
PCfg.OutputOptions.GERB_DRILL,
6973
]
7074

7175
def _get_layer_plot_format(self, output):
@@ -129,31 +133,57 @@ def _do_layer_plot(self, board, plot_ctrl, output):
129133
plot_ctrl.OpenPlotfile(suffix, plot_format, desc)
130134

131135
logging.debug("Plotting layer {} to {}".format(
132-
layer.layer, plot_ctrl.GetPlotFileName()))
136+
layer.layer, plot_ctrl.GetPlotFileName()))
133137
plot_ctrl.PlotLayer()
134138

135-
def _do_drill_plot(self, board, plot_ctrl, output):
136-
137-
to = output.options.type_options
139+
def _configure_excellon_drill_writer(self, board, offset, options):
138140

139-
outdir = plot_ctrl.GetPlotOptions().GetOutputDirectory()
141+
drill_writer = pcbnew.EXCELLON_WRITER(board)
140142

141-
drlwriter = pcbnew.EXCELLON_WRITER(board)
143+
to = options.type_options
142144

143145
mirror_y = to.mirror_y_axis
144146
minimal_header = to.minimal_header
145147

148+
merge_npth = to.pth_and_npth_single_file
149+
zeros_format = pcbnew.EXCELLON_WRITER.DECIMAL_FORMAT
150+
151+
drill_writer.SetOptions(mirror_y, minimal_header, offset, merge_npth)
152+
drill_writer.SetFormat(to.metric_units, zeros_format)
153+
154+
return drill_writer
155+
156+
def _configure_gerber_drill_writer(self, board, offset, options):
157+
158+
drill_writer = pcbnew.GERBER_WRITER(board)
159+
160+
# hard coded in UI?
161+
drill_writer.SetFormat(5)
162+
drill_writer.SetOptions(offset)
163+
164+
return drill_writer
165+
166+
def _do_drill_plot(self, board, plot_ctrl, output):
167+
168+
to = output.options.type_options
169+
170+
outdir = plot_ctrl.GetPlotOptions().GetOutputDirectory()
171+
146172
# dialog_gendrill.cpp:357
147173
if to.use_aux_axis_as_origin:
148174
offset = board.GetAuxOrigin()
149175
else:
150176
offset = pcbnew.wxPoint(0, 0)
151177

152-
merge_npth = to.pth_and_npth_single_file
153-
zeros_format = pcbnew.EXCELLON_WRITER.DECIMAL_FORMAT
154-
155-
drlwriter.SetOptions(mirror_y, minimal_header, offset, merge_npth)
156-
drlwriter.SetFormat(to.metric_units, zeros_format)
178+
if output.options.type == PCfg.OutputOptions.EXCELLON:
179+
drill_writer = self._configure_excellon_drill_writer(
180+
board, offset, output.options)
181+
elif output.options.type == PCfg.OutputOptions.GERB_DRILL:
182+
drill_writer = self._configure_gerber_drill_writer(
183+
board, offset, output.options)
184+
else:
185+
raise error.PlotError("Can't make a writer for type {}"
186+
.format(output.options.type))
157187

158188
gen_drill = True
159189
gen_map = to.generate_map
@@ -164,19 +194,19 @@ def _do_drill_plot(self, board, plot_ctrl, output):
164194
.format(outdir))
165195

166196
if gen_map:
167-
drlwriter.SetMapFileFormat(to.map_options.type)
197+
drill_writer.SetMapFileFormat(to.map_options.type)
168198
logging.debug("Generating drill map type {} in {}"
169199
.format(to.map_options.type, outdir))
170200

171-
drlwriter.CreateDrillandMapFilesSet(outdir, gen_drill, gen_map)
201+
drill_writer.CreateDrillandMapFilesSet(outdir, gen_drill, gen_map)
172202

173203
if gen_report:
174204
drill_report_file = os.path.join(outdir,
175205
to.report_options.filename)
176206
logging.debug("Generating drill report: {}"
177207
.format(drill_report_file))
178208

179-
drlwriter.GenDrillReportFile(drill_report_file)
209+
drill_writer.GenDrillReportFile(drill_report_file)
180210

181211
def _configure_gerber_opts(self, po, output):
182212

kiplot/plot_config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ def __init__(self):
313313

314314
super(DrillOptions, self).__init__()
315315

316+
self.use_aux_axis_as_origin = False
317+
316318
self.map_options = None
317319
self.report_options = None
318320

@@ -336,6 +338,13 @@ def __init__(self):
336338
self.mirror_y_axis = False
337339

338340

341+
class GerberDrillOptions(DrillOptions):
342+
343+
def __init__(self):
344+
345+
super(GerberDrillOptions, self).__init__()
346+
347+
339348
class DrillReportOptions(object):
340349

341350
def __init__(self):
@@ -377,6 +386,8 @@ def __init__(self, otype):
377386
self.type_options = PdfOptions()
378387
elif otype == self.EXCELLON:
379388
self.type_options = ExcellonOptions()
389+
elif otype == self.GERB_DRILL:
390+
self.type_options = GerberDrillOptions()
380391
else:
381392
self.type_options = None
382393

0 commit comments

Comments
 (0)