def plot_to_directory(pcb_file, output_directory, temp_dir): board_name = os.path.splitext(os.path.basename(pcb_file))[0] with pcb_util.get_plotter(pcb_file, temp_dir) as plotter: plotter.plot_options.SetDrillMarksType(pcbnew.PCB_PLOT_PARAMS.NO_DRILL_SHAPE) plotter.plot_options.SetExcludeEdgeLayer(False) LayerDef = namedtuple('LayerDef', ['layer', 'mirror']) layers = [ LayerDef(pcbnew.F_Cu, False), LayerDef(pcbnew.B_Cu, True), LayerDef(pcbnew.F_SilkS, False), LayerDef(pcbnew.B_SilkS, True), ] pdfs = [] for layer in layers: plotter.plot_options.SetMirror(layer.mirror) output_filename = plotter.plot(layer.layer, pcbnew.PLOT_FORMAT_PDF) pdfs.append(output_filename) _, map_file = plotter.plot_drill() pdfs.append(map_file) output_pdf_filename = os.path.join(output_directory, '%s_packet.pdf' % (board_name,)) command = ['pdfunite'] + pdfs + [output_pdf_filename] subprocess.check_call(command)
def plot_to_directory(output_directory, temp_dir): board_name = os.path.splitext(os.path.basename(PCB_FILENAME))[0] with pcb_util.get_plotter(PCB_FILENAME, temp_dir) as plotter: plotter.plot_options.SetDrillMarksType(pcbnew.PCB_PLOT_PARAMS.NO_DRILL_SHAPE) plotter.plot_options.SetExcludeEdgeLayer(False) LayerDef = namedtuple('LayerDef', ['layer', 'mirror']) layers = [ LayerDef(pcbnew.F_Cu, False), LayerDef(pcbnew.B_Cu, True), LayerDef(pcbnew.F_SilkS, False), LayerDef(pcbnew.B_SilkS, True), ] pdfs = [] for layer in layers: plotter.plot_options.SetMirror(layer.mirror) output_filename = plotter.plot(layer.layer, pcbnew.PLOT_FORMAT_PDF) pdfs.append(output_filename) _, map_file = plotter.plot_drill() pdfs.append(map_file) output_pdf_filename = os.path.join(output_directory, '%s_packet.pdf' % (board_name,)) command = ['pdfunite'] + pdfs + [output_pdf_filename] subprocess.check_call(command)
def plot_to_directory(pcb_file, output_directory, temp_dir): layers = [ { 'layer': pcbnew.B_SilkS, 'color': '#CC00CC', 'alpha': 0.8, }, { 'layer': pcbnew.B_Cu, 'color': '#33EE33', 'alpha': 0.5, }, { 'layer': pcbnew.F_Cu, 'color': '#CC0000', 'alpha': 0.5, }, { 'layer': pcbnew.F_SilkS, 'color': '#00CCCC', 'alpha': 0.8, }, ] with pcb_util.get_plotter(pcb_file, temp_dir) as plotter: processed_svg_files = [] for i, layer in enumerate(layers): output_filename = plotter.plot(layer['layer'], pcbnew.PLOT_FORMAT_SVG) logger.info('Post-processing %s...', output_filename) processor = SvgProcessor(output_filename) def colorize(original): if original.lower() == '#000000': return layer['color'] return original processor.apply_color_transform(colorize) processor.wrap_with_group({ 'opacity': str(layer['alpha']), }) output_filename2 = os.path.join( temp_dir, 'processed-' + os.path.basename(output_filename)) processor.write(output_filename2) processed_svg_files.append((output_filename2, processor)) logger.info('Merging layers...') final_svg = os.path.join(output_directory, 'merged.svg') shutil.copyfile(processed_svg_files[0][0], final_svg) output_processor = SvgProcessor(final_svg) for _, processor in processed_svg_files: output_processor.import_groups(processor) output_processor.write(final_svg)
def plot_job(job, output_directory, temp_dir): logger.info("processing job " + job["filename"]) with pcb_util.get_plotter(PCB_FILENAME, temp_dir) as plotter: plotter.plot_options.SetMirror(job["mirror"]) plotter.plot_options.SetExcludeEdgeLayer(False) processed_svg_files = [] for i, layer in enumerate(job["layers"]): output_filename = plotter.plot(layer['layer'], pcbnew.PLOT_FORMAT_SVG) logger.info('Post-processing %s...', output_filename) processor = SvgProcessor(output_filename) def colorize(original): if original.lower() == '#000000': return layer['color'] return original processor.apply_color_transform(colorize) processor.wrap_with_group({ 'opacity': str(layer['alpha']), }) output_filename2 = os.path.join( temp_dir, 'processed-' + os.path.basename(output_filename)) processor.write(output_filename2) processed_svg_files.append((output_filename2, processor)) logger.info('merging layers...') final_svg = os.path.join(output_directory, job["filename"] + '.svg') shutil.copyfile(processed_svg_files[0][0], final_svg) output_processor = SvgProcessor(final_svg) for _, processor in processed_svg_files: output_processor.import_groups(processor) output_processor.write(final_svg) logger.info('rasterizing...') final_png = os.path.join(output_directory, job["filename"] + '.png') subprocess.check_call([ 'inkscape', '--export-area-drawing', '--export-dpi=600', '--export-png', final_png, '--export-background', '#FFFFFF', final_svg, ])
def plot_to_directory(output_directory, temp_dir): board_name = os.path.splitext(os.path.basename(PCB_FILENAME))[0] LayerDef = namedtuple('LayerDef', ['layer', 'extension']) output_files = [] with pcb_util.get_plotter(PCB_FILENAME, temp_dir) as plotter: plotter.plot_options.SetDrillMarksType( pcbnew.PCB_PLOT_PARAMS.NO_DRILL_SHAPE) layers = [ LayerDef(pcbnew.F_Cu, 'Top.gbr'), # медное покрытие верхнего слоя LayerDef(pcbnew.F_Mask, 'MaskTop.gbr'), # маска верхнего слоя LayerDef(pcbnew.F_SilkS, 'SilkTop.gbr'), # тексты на верхней стороне платы LayerDef(pcbnew.B_Cu, 'Bottom.gbr'), # медное покрытие нижнего слоя LayerDef(pcbnew.B_Mask, 'MaskBot.gbr'), # маска нижнего слоя LayerDef(pcbnew.B_SilkS, 'SilkBot.gbr'), # тексты на нижней стороне платы LayerDef(pcbnew.Edge_Cuts, 'Border.gbr'), # контур платы # 'drl' # сверловка ] for layer in layers: output_filename = plotter.plot(layer.layer, pcbnew.PLOT_FORMAT_GERBER) desired_name = '%s.%s' % ( board_name, layer.extension, ) desired_output_filename = os.path.join(output_directory, desired_name) os.rename(output_filename, desired_output_filename) output_files.append(desired_output_filename) drill_file, _ = plotter.plot_drill() desired_drill_file = os.path.join(output_directory, '%s.drl' % (board_name, )) os.rename(drill_file, desired_drill_file) output_files.append(desired_drill_file) version_info = pcb_util.get_version_info() zip_file_name = os.path.join(output_directory, '%s_gerber.zip' % (board_name, )) with zipfile.ZipFile(zip_file_name, 'w') as z: for f in output_files: z.write(f, os.path.relpath(f, output_directory))
def plot_to_directory(output_directory, temp_dir): board_name = os.path.splitext(os.path.basename(PCB_FILENAME))[0] LayerDef = namedtuple('LayerDef', ['layer', 'extension']) output_files = [] with pcb_util.get_plotter(PCB_FILENAME, temp_dir) as plotter: plotter.plot_options.SetDrillMarksType( pcbnew.PCB_PLOT_PARAMS.NO_DRILL_SHAPE) layers = [ LayerDef(pcbnew.F_Cu, 'GTL'), LayerDef(pcbnew.F_Mask, 'GTS'), LayerDef(pcbnew.F_SilkS, 'GTO'), LayerDef(pcbnew.B_Cu, 'GBL'), LayerDef(pcbnew.B_Mask, 'GBS'), LayerDef(pcbnew.B_SilkS, 'GBO'), LayerDef(pcbnew.Edge_Cuts, 'GML'), ] for layer in layers: output_filename = plotter.plot(layer.layer, pcbnew.PLOT_FORMAT_GERBER) desired_name = '%s.%s' % ( board_name, layer.extension, ) desired_output_filename = os.path.join(output_directory, desired_name) os.rename(output_filename, desired_output_filename) output_files.append(desired_output_filename) drill_file, _ = plotter.plot_drill() desired_drill_file = os.path.join(output_directory, '%s.txt' % (board_name, )) os.rename(drill_file, desired_drill_file) output_files.append(desired_drill_file) version_info = pcb_util.get_version_info() zip_file_name = os.path.join(output_directory, '%s_gerber.zip' % (board_name, )) with zipfile.ZipFile(zip_file_name, 'w') as z: for f in output_files: z.write(f, os.path.relpath(f, output_directory))
def plot_to_directory(output_directory, temp_dir): board_name = os.path.splitext(os.path.basename(PCB_FILENAME))[0] LayerDef = namedtuple('LayerDef', ['layer', 'extension']) output_files = [] with pcb_util.get_plotter(PCB_FILENAME, temp_dir) as plotter: plotter.plot_options.SetDrillMarksType(pcbnew.PCB_PLOT_PARAMS.NO_DRILL_SHAPE) layers = [ LayerDef(pcbnew.F_Cu, 'GTL'), LayerDef(pcbnew.F_Mask, 'GTS'), LayerDef(pcbnew.F_SilkS, 'GTO'), LayerDef(pcbnew.B_Cu, 'GBL'), LayerDef(pcbnew.B_Mask, 'GBS'), LayerDef(pcbnew.B_SilkS, 'GBO'), LayerDef(pcbnew.Edge_Cuts, 'GML'), ] for layer in layers: output_filename = plotter.plot(layer.layer, pcbnew.PLOT_FORMAT_GERBER) desired_name = '%s.%s' % ( board_name, layer.extension, ) desired_output_filename = os.path.join(output_directory, desired_name) os.rename(output_filename, desired_output_filename) output_files.append(desired_output_filename) drill_file, _ = plotter.plot_drill() desired_drill_file = os.path.join(output_directory, '%s.txt' % (board_name,)) os.rename(drill_file, desired_drill_file) output_files.append(desired_drill_file) version_info = pcb_util.get_version_info() zip_file_name = os.path.join(output_directory, '%s_gerber.zip' % (board_name, )) with zipfile.ZipFile(zip_file_name, 'w') as z: for f in output_files: z.write(f, os.path.relpath(f, output_directory))
def plot_to_directory(pcb_file, output_directory, temp_dir): board_name = os.path.splitext(os.path.basename(pcb_file))[0] layers = [ { 'layer': pcbnew.B_SilkS, 'color': '#CC00CC', 'alpha': 0.8, }, { 'layer': pcbnew.B_Cu, 'color': '#33EE33', 'alpha': 0.5, }, { 'layer': pcbnew.F_Cu, 'color': '#CC0000', 'alpha': 0.5, }, { 'layer': pcbnew.F_SilkS, 'color': '#00CCCC', 'alpha': 0.8, }, { 'layer': pcbnew.Cmts_User, 'color': '#333333', 'alpha': 0.8, }, { 'layer': pcbnew.Edge_Cuts, 'color': '#3333CC', 'alpha': 0.8, }, ] with pcb_util.get_plotter(pcb_file, temp_dir) as plotter: plotter.plot_options.SetExcludeEdgeLayer(True) processed_svg_files = [] for i, layer in enumerate(layers): output_filename = plotter.plot(layer['layer'], pcbnew.PLOT_FORMAT_SVG) logger.info('Post-processing %s...', output_filename) processor = SvgProcessor(output_filename) def colorize(original): if original.lower() == '#000000': return layer['color'] return original processor.apply_color_transform(colorize) processor.wrap_with_group({ 'opacity': str(layer['alpha']), }) output_filename2 = os.path.join( temp_dir, 'processed-' + os.path.basename(output_filename)) processor.write(output_filename2) processed_svg_files.append((output_filename2, processor)) # Plot the paste layer to its own SVG logger.info('Plotting paste SVG') output_filename = plotter.plot(pcbnew.F_Paste, pcbnew.PLOT_FORMAT_SVG) processor = SvgProcessor(output_filename) def colorize(original): if original.lower() == '#000000': return '#FF0000' return original processor.apply_group_style_transforms({ 'fill-opacity': lambda _: '0', 'stroke': lambda _: '#FF0000', 'stroke-opacity': lambda _: '1', 'stroke-width': lambda _: '20', }) paste_filename = os.path.join(output_directory, '%s_paste.svg' % board_name) processor.write(paste_filename) logger.info('Merging layers...') final_svg = os.path.join(output_directory, '%s_merged.svg' % board_name) shutil.copyfile(processed_svg_files[0][0], final_svg) output_processor = SvgProcessor(final_svg) for _, processor in processed_svg_files: output_processor.import_groups(processor) output_processor.write(final_svg) logger.info('Rasterizing...') raster_width = 1280 final_png = os.path.join(output_directory, '%s_merged.png' % board_name) subprocess.check_call([ 'inkscape', '--export-area-drawing', '--export-width', str(raster_width), '--export-png', final_png, '--export-background', '#FFFFFF', final_svg, ])
def plot_to_directory(output_directory, temp_dir): layers = [ { 'layer': pcbnew.B_SilkS, 'color': '#CC00CC', 'alpha': 0.8, }, { 'layer': pcbnew.B_Cu, 'color': '#33EE33', 'alpha': 0.5, }, { 'layer': pcbnew.F_Cu, 'color': '#CC0000', 'alpha': 0.5, }, { 'layer': pcbnew.F_SilkS, 'color': '#00CCCC', 'alpha': 0.8, }, ] with pcb_util.get_plotter(PCB_FILENAME, temp_dir) as plotter: plotter.plot_options.SetExcludeEdgeLayer(False) processed_svg_files = [] for i, layer in enumerate(layers): output_filename = plotter.plot(layer['layer'], pcbnew.PLOT_FORMAT_SVG) logger.info('Post-processing %s...', output_filename) processor = SvgProcessor(output_filename) def colorize(original): if original.lower() == '#000000': return layer['color'] return original processor.apply_color_transform(colorize) processor.wrap_with_group({ 'opacity': str(layer['alpha']), }) output_filename2 = os.path.join(temp_dir, 'processed-' + os.path.basename(output_filename)) processor.write(output_filename2) processed_svg_files.append((output_filename2, processor)) logger.info('Merging layers...') final_svg = os.path.join(output_directory, 'merged.svg') shutil.copyfile(processed_svg_files[0][0], final_svg) output_processor = SvgProcessor(final_svg) for _, processor in processed_svg_files: output_processor.import_groups(processor) output_processor.write(final_svg) logger.info('Rasterizing...') final_png = os.path.join(output_directory, 'merged.png') subprocess.check_call([ 'inkscape', '--export-area-drawing', '--export-width=320', '--export-png', final_png, '--export-background', '#FFFFFF', final_svg, ])
def plot_to_directory(pcb_filename, svg_filename_top, svg_filename_bot, temp_dir): sides = [ { 'svg_filename': svg_filename_bot, 'layers':[ { 'layer': pcbnew.B_SilkS, 'color': '#CC00CC', 'alpha': 0.8, }, { 'layer': pcbnew.B_Cu, 'color': '#33EE33', 'alpha': 0.5, }, ] }, { 'svg_filename': svg_filename_top, 'layers':[ { 'layer': pcbnew.F_Cu, 'color': '#CC0000', 'alpha': 0.5, }, { 'layer': pcbnew.F_SilkS, 'color': '#00CCCC', 'alpha': 0.8, }, ] } ] with pcb_util.get_plotter(pcb_filename, temp_dir) as plotter: plotter.plot_options.SetExcludeEdgeLayer(False) #plotter.plot_options.SetAutoScale(False) for i, side in enumerate(sides): processed_svg_files = [] for i, layer in enumerate(side['layers']): output_filename = plotter.plot(layer['layer'], pcbnew.PLOT_FORMAT_SVG) #logger.info('Post-processing %s...', output_filename) processor = SvgProcessor(output_filename) def colorize(original): if original.lower() == '#000000': return layer['color'] return original processor.apply_color_transform(colorize) processor.wrap_with_group({ 'opacity': str(layer['alpha']), }) output_filename2 = os.path.join(temp_dir, 'processed-' + os.path.basename(output_filename)) processor.write(output_filename2) processed_svg_files.append((output_filename2, processor)) shutil.copyfile(processed_svg_files[0][0], side['svg_filename']) output_processor = SvgProcessor(side['svg_filename']) for _, processor in processed_svg_files: output_processor.import_groups(processor) output_processor.write(side['svg_filename'])
def plot_to_directory(output_directory, temp_dir): layers = [ { 'layer': pcbnew.B_SilkS, 'color': '#CC00CC', 'alpha': 0.8, }, { 'layer': pcbnew.B_Cu, 'color': '#33EE33', 'alpha': 0.5, }, { 'layer': pcbnew.F_Cu, 'color': '#CC0000', 'alpha': 0.5, }, { 'layer': pcbnew.F_SilkS, 'color': '#00CCCC', 'alpha': 0.8, }, ] with pcb_util.get_plotter(PCB_FILENAME, temp_dir) as plotter: plotter.plot_options.SetExcludeEdgeLayer(False) processed_svg_files = [] for i, layer in enumerate(layers): output_filename = plotter.plot(layer['layer'], pcbnew.PLOT_FORMAT_SVG) logger.info('Post-processing %s...', output_filename) processor = SvgProcessor(output_filename) def colorize(original): if original.lower() == '#000000': return layer['color'] return original processor.apply_color_transform(colorize) processor.wrap_with_group({ 'opacity': str(layer['alpha']), }) output_filename2 = os.path.join( temp_dir, 'processed-' + os.path.basename(output_filename)) processor.write(output_filename2) processed_svg_files.append((output_filename2, processor)) logger.info('Merging layers...') final_svg = os.path.join(output_directory, 'merged.svg') shutil.copyfile(processed_svg_files[0][0], final_svg) output_processor = SvgProcessor(final_svg) for _, processor in processed_svg_files: output_processor.import_groups(processor) output_processor.write(final_svg) logger.info('Rasterizing...') final_png = os.path.join(output_directory, 'merged.png') subprocess.check_call([ 'inkscape', '--export-area-drawing', '--export-width=320', '--export-png', final_png, '--export-background', '#FFFFFF', final_svg, ])