Even more working

This commit is contained in:
John Beard 2018-06-02 12:28:46 +01:00
parent 5298dc2c72
commit fb7e579a64
4 changed files with 134 additions and 12 deletions

View File

@ -18,6 +18,13 @@ outputs:
exclude_edge_layer: false
exclude_pads_from_silkscreen: false
use_aux_axis_as_origin: false
plot_sheet_reference: true
plot_footprint_refs: true
plot_footprint_values: true
force_plot_invisible_refs_vals: false
tent_vias: true
check_zone_fills: true
layers:
- layer: F.Cu
suffix: F_Cu
@ -33,4 +40,10 @@ outputs:
options:
metric_units: true
pth_and_npth_single_file: true
use_aux_axis_as_origin: false
use_aux_axis_as_origin: false
minimal_header: false
mirror_y_axis: false
report:
filename: 'drill_report.rpt'
map:
type: 'pdf'

View File

@ -50,6 +50,36 @@ class CfgYamlReader(CfgReader):
return val
def _parse_drill_map(self, map_opts):
mo = PC.DrillMapOptions()
TYPES = {
'hpgl': pcbnew.PLOT_FORMAT_HPGL,
'ps': pcbnew.PLOT_FORMAT_POST,
'gerber': pcbnew.PLOT_FORMAT_GERBER,
'dxf': pcbnew.PLOT_FORMAT_DXF,
'svg': pcbnew.PLOT_FORMAT_SVG,
'pdf': pcbnew.PLOT_FORMAT_PDF
}
type_s = self._get_required(map_opts, 'type')
try:
mo.type = TYPES[type_s]
except KeyError:
raise self.YamlError("Unknown drill map type: {}".format(type_s))
return mo
def _parse_drill_report(self, report_opts):
opts = PC.DrillReportOptions()
opts.filename = self._get_required(report_opts, 'filename')
return opts
def _parse_out_opts(self, otype, options):
po = PC.OutputOptions(otype)
@ -73,6 +103,15 @@ class CfgYamlReader(CfgReader):
to.use_aux_axis_as_origin = self._get_required(
options, 'use_aux_axis_as_origin')
to.generate_map = 'map' in options
to.generate_report = 'report' in options
if to.generate_map:
to.map_options = self._parse_drill_map(options['map'])
if to.generate_map:
to.report_options = self._parse_drill_report(options['report'])
# set type-specific options
if otype == 'gerber':
to.subtract_mask_from_silk = self._get_required(
@ -83,6 +122,10 @@ class CfgYamlReader(CfgReader):
if otype == 'excellon':
to.metric_units = self._get_required(
options, 'metric_units')
to.mirror_y_axis = self._get_required(
options, 'mirror_y_axis')
to.minimal_header = self._get_required(
options, 'minimal_header')
to.pth_and_npth_single_file = self._get_required(
options, 'pth_and_npth_single_file')

View File

@ -37,6 +37,8 @@ class Plotter(object):
# fresh plot controller
pc = pcbnew.PLOT_CONTROLLER(board)
self._configure_output_dir(pc, op)
if self._output_is_layer(op):
self._do_layer_plot(board, pc, op)
elif self._output_is_drill(op):
@ -55,7 +57,7 @@ class Plotter(object):
return output.options.type in [PCfg.OutputOptions.EXCELLON]
def _get_plot_format(self, output):
def _get_layer_plot_format(self, output):
"""
Gets the Pcbnew plot format for a given KiPlot output type
"""
@ -91,7 +93,7 @@ class Plotter(object):
plot_ctrl.SetLayer(layer.layer)
# Plot single layer to file
plot_format = self._get_plot_format(output)
plot_format = self._get_layer_plot_format(output)
plot_ctrl.OpenPlotfile(suffix, plot_format, desc)
logging.debug("Plotting layer {} to {}".format(
layer.layer, plot_ctrl.GetPlotFileName()))
@ -99,7 +101,49 @@ class Plotter(object):
def _do_drill_plot(self, board, plot_ctrl, output):
pass
to = output.options.type_options
outdir = plot_ctrl.GetPlotOptions().GetOutputDirectory()
drlwriter = pcbnew.EXCELLON_WRITER(board)
mirror_y = to.mirror_y_axis
minimal_header = to.minimal_header
# dialog_gendrill.cpp:357
if to.use_aux_axis_as_origin:
offset = board.GetAuxOrigin()
else:
offset = pcbnew.wxPoint(0, 0)
merge_npth = to.pth_and_npth_single_file
zeros_format = pcbnew.EXCELLON_WRITER.DECIMAL_FORMAT
drlwriter.SetOptions(mirror_y, minimal_header, offset, merge_npth)
drlwriter.SetFormat(to.metric_units, zeros_format)
gen_drill = True
gen_map = to.generate_map
gen_report = to.generate_report
if gen_drill:
logging.debug("Generating drill files in {}"
.format(outdir))
if gen_map:
drlwriter.SetMapFileFormat(to.map_options.type)
logging.debug("Generating drill map type {} in {}"
.format(to.map_options.type, outdir))
drlwriter.CreateDrillandMapFilesSet(outdir, gen_drill, gen_map)
if gen_report:
drill_report_file = os.path.join(outdir,
to.report_options.filename)
logging.debug("Generating drill report: {}"
.format(drill_report_file))
drlwriter.GenDrillReportFile(drill_report_file)
def _configure_gerber_opts(self, po, output):
@ -112,6 +156,17 @@ class Plotter(object):
po.SetSubtractMaskFromSilk(gerb_opts.subtract_mask_from_silk)
po.SetUseGerberProtelExtensions(gerb_opts.use_protel_extensions)
def _configure_output_dir(self, plot_ctrl, output):
po = plot_ctrl.GetPlotOptions()
# outdir is a combination of the config and output
outdir = os.path.join(self.cfg.outdir, output.outdir)
logging.debug("Output destination: {}".format(outdir))
po.SetOutputDirectory(outdir)
def _configure_plot_ctrl(self, plot_ctrl, output):
logging.debug("Configuring plot controller for output")
@ -144,10 +199,3 @@ class Plotter(object):
# and shape
# usually sel to True for copper layers
po.SetSkipPlotNPTH_Pads(False)
# outdir is a combination of the config and output
outdir = os.path.join(self.cfg.outdir, output.outdir)
logging.debug("Output destination: {}".format(outdir))
po.SetOutputDirectory(outdir)

View File

@ -36,7 +36,11 @@ class GerberOptions(LayerOptions):
class DrillOptions(object):
def __init__(self):
pass
self.generate_map = False
self.generate_report = False
self.map_options = None
self.report_options = None
class ExcellonOptions(DrillOptions):
@ -46,6 +50,20 @@ class ExcellonOptions(DrillOptions):
super(ExcellonOptions, self).__init__()
self.metric_units = True
self.minimal_header = False
self.mirror_y_axis = False
class DrillReportOptions(object):
def __init__(self):
self.filename = None
class DrillMapOptions(object):
def __init__(self):
self.type = None
class OutputOptions(object):