Added schematic printing to PDF.

Partially added PCB printing to PDF.
This commit is contained in:
Salvador E. Tropea 2020-03-19 19:59:19 -03:00
parent 46e2a12385
commit d0d9c37064
4 changed files with 79 additions and 4 deletions

View File

@ -4,6 +4,7 @@ Class to read KiPlot config files
import os
import re
import sys
import pcbnew
@ -19,7 +20,6 @@ try:
except:
log.init(False,False)
logger.error('No yaml module for Python, install python3-yaml')
import sys
sys.exit(misc.NO_YAML_MODULE)
@ -371,6 +371,18 @@ class CfgYamlReader(CfgReader):
'to': 'name_format',
'required': lambda opts: False,
},
{
'key': 'output',
'types': ['pdf_sch_print'],
'to': 'output',
'required': lambda opts: False,
},
{
'key': 'output_name',
'types': ['pdf_pcb_print'],
'to': 'output_name',
'required': lambda opts: True,
},
]
po = PC.OutputOptions(otype)
@ -457,14 +469,15 @@ class CfgYamlReader(CfgReader):
if otype not in ['gerber', 'ps', 'hpgl', 'dxf', 'pdf', 'svg',
'gerb_drill', 'excellon', 'position',
'kibom', 'ibom']:
'kibom', 'ibom', 'pdf_sch_print', 'pdf_pcb_print']:
raise YamlError("Unknown output type: {}".format(otype))
try:
options = o_obj['options']
except KeyError:
if otype != 'ibom':
raise YamlError("Output need to have options specified")
if not otype in ['ibom', 'pdf_sch_print']:
logger.error('Output "'+name+'" needs options')
sys.exit(misc.EXIT_BAD_CONFIG)
options = None
logger.debug("Parsing output options for {} ({})".format(name, otype))

View File

@ -108,6 +108,10 @@ class Plotter(object):
self._do_position_plot(board, pc, op)
elif self._output_is_bom(op):
self._do_bom(board, pc, op, brd_file)
elif self._output_is_sch_print(op):
self._do_sch_print(board, pc, op, brd_file)
elif self._output_is_pcb_print(op):
self._do_pcb_print(board, pc, op, brd_file)
else:
raise PlotError("Don't know how to plot type {}"
.format(op.options.type))
@ -220,6 +224,12 @@ class Plotter(object):
def _output_is_position(self, output):
return output.options.type == PCfg.OutputOptions.POSITION
def _output_is_sch_print(self, output):
return output.options.type == PCfg.OutputOptions.PDF_SCH_PRINT
def _output_is_pcb_print(self, output):
return output.options.type == PCfg.OutputOptions.PDF_PCB_PRINT
def _output_is_bom(self, output):
return output.options.type in [
PCfg.OutputOptions.KIBOM,
@ -536,6 +546,27 @@ class Plotter(object):
else:
raise PlotError("Format is invalid: {}".format(to.format))
def _do_sch_print(self, board, plot_ctrl, output, brd_file):
sch_file = check_eeschema_do(brd_file)
outdir = plot_ctrl.GetPlotOptions().GetOutputDirectory()
cmd = [misc.CMD_EESCHEMA_DO, 'export', '--all_pages',
'--file_format', 'pdf', sch_file, outdir]
if logger.getEffectiveLevel() <= logging.DEBUG:
cmd.insert(1, '-vv')
cmd.insert(1, '-r')
logger.debug('Executing: '+str(cmd))
ret = call(cmd)
if ret:
logger.error(misc.CMD_EESCHEMA_DO+' returned %d', ret)
exit(misc.PDF_SCH_PRINT)
to = output.options.type_options
if to.output:
cur = os.path.join(outdir, os.path.splitext(brd_file)[0]) + '.pdf'
new = os.path.join(outdir, to.output)
logger.debug('Moving '+cur+' -> '+new)
os.rename(cur,new)
def _do_bom(self, board, plot_ctrl, output, brd_file):
if output.options.type == 'kibom':
self._do_kibom(board, plot_ctrl, output, brd_file)
@ -637,6 +668,14 @@ class Plotter(object):
assert(output.options.type == PCfg.OutputOptions.POSITION)
def _configure_sch_print_opts(self, po, output):
assert(output.options.type == PCfg.OutputOptions.PDF_SCH_PRINT)
def _configure_pcb_print_opts(self, po, output):
assert(output.options.type == PCfg.OutputOptions.PDF_PCB_PRINT)
def _configure_kibom_opts(self, po, output):
assert(output.options.type == PCfg.OutputOptions.KIBOM)
@ -704,6 +743,11 @@ class Plotter(object):
self._configure_kibom_opts(po, output)
elif output.options.type == PCfg.OutputOptions.IBOM:
self._configure_ibom_opts(po, output)
elif output.options.type == PCfg.OutputOptions.PDF_SCH_PRINT:
self._configure_sch_print_opts(po, output)
elif output.options.type == PCfg.OutputOptions.PDF_PCB_PRINT:
self._configure_pcb_print_opts(po, output)
po.SetDrillMarksType(opts.drill_marks)

View File

@ -13,6 +13,7 @@ NO_PCB_FILE = 8
NO_SCH_FILE = 9
ERC_ERROR = 10
BOM_ERROR = 11
PDF_SCH_PRINT = 12
CMD_EESCHEMA_DO = 'eeschema_do'
URL_EESCHEMA_DO = 'https://github.com/INTI-CMNB/kicad-automation-scripts'

View File

@ -395,6 +395,17 @@ class IBoMOptions(TypeOptions):
self.blacklist = None
self.name_format = None
class SchPrintOptions(TypeOptions):
def __init__(self):
self.output = None
class PcbPrintOptions(TypeOptions):
def __init__(self):
self.output = None
class OutputOptions(object):
@ -410,6 +421,8 @@ class OutputOptions(object):
POSITION = 'position'
KIBOM = 'kibom'
IBOM = 'ibom'
PDF_SCH_PRINT = 'pdf_sch_print'
PDF_PCB_PRINT = 'pdf_pcb_print'
def __init__(self, otype):
self.type = otype
@ -436,6 +449,10 @@ class OutputOptions(object):
self.type_options = KiBoMOptions()
elif otype == self.IBOM:
self.type_options = IBoMOptions()
elif otype == self.PDF_SCH_PRINT:
self.type_options = SchPrintOptions()
elif otype == self.PDF_PCB_PRINT:
self.type_options = PcbPrintOptions()
else:
self.type_options = None