def export_schematic(): schematic_file = os.path.join(electronics_root, 'splitflap.sch') output_dir = os.path.join(electronics_root, 'build') file_util.mkdir_p(output_dir) screencast_output_file = os.path.join(output_dir, 'export_schematic_screencast.ogv') schematic_output_pdf_file = os.path.join(output_dir, 'splitflap.pdf') schematic_output_png_file = os.path.join(output_dir, 'schematic.png') with versioned_schematic(schematic_file): with recorded_xvfb(screencast_output_file, width=800, height=600, colordepth=24): with PopenContext(['eeschema', schematic_file], close_fds=True) as eeschema_proc: eeschema_plot_schematic(output_dir) eeschema_proc.terminate() logger.info('Rasterize') subprocess.check_call([ 'convert', '-density', '96', schematic_output_pdf_file, '-background', 'white', '-alpha', 'remove', schematic_output_png_file, ])
def export_schematic(schematic_file, kicad_4): # Use absolute path - eeschema handles libraries differently with full path vs filename schematic_file = os.path.abspath(schematic_file) filename, _ = os.path.splitext(os.path.basename(schematic_file)) output_dir = os.path.join(electronics_root, 'build') file_util.mkdir_p(output_dir) screencast_output_file = os.path.join(output_dir, 'export_schematic_screencast.ogv') schematic_output_pdf_file = os.path.join(output_dir, filename + '.pdf') schematic_output_png_file = os.path.join(output_dir, filename + '.png') settings = { 'PlotFormat': '4', # PDF } with patch_config(os.path.expanduser('~/.config/kicad/eeschema'), settings): with versioned_file(schematic_file): with recorded_xvfb(screencast_output_file, width=WIDTH, height=HEIGHT, colordepth=24): with PopenContext(['eeschema', schematic_file], close_fds=True) as eeschema_proc: eeschema_plot_schematic(output_dir, kicad_4) eeschema_proc.terminate() logger.info('Rasterize') subprocess.check_call([ 'convert', '-density', '96', schematic_output_pdf_file, '-background', 'white', '-alpha', 'remove', schematic_output_png_file, ])
def export_3d(filename): pcb_file = os.path.abspath(filename) output_dir = os.path.join(electronics_root, 'build') file_util.mkdir_p(output_dir) screencast_output_file = os.path.join(output_dir, 'export_3d_screencast.ogv') name, _ = os.path.splitext(os.path.basename(pcb_file)) output_file = os.path.join(output_dir, f'{name}-3d.png') settings = { 'canvas_type': '1', 'SMaskColor_Red': '0.1', 'SMaskColor_Green': '0.1', 'SMaskColor_Blue': '0.1', 'RenderEngine': '1', 'Render_RAY_ProceduralTextures': '0', } with patch_config(os.path.expanduser('~/.config/kicad/pcbnew'), settings): with versioned_file(pcb_file): with recorded_xvfb(screencast_output_file, width=WIDTH, height=HEIGHT, colordepth=24): with PopenContext(['pcbnew', pcb_file], close_fds=True) as pcbnew_proc: _pcbnew_export_3d(output_file) pcbnew_proc.terminate()
def export_schematic(prjfile, wait_init): """Print schematics to file in PDF format Keyword arguments: prjfile -- The project file name including relative path from project_root WITHOUT extension. """ sch_file_path = os.path.dirname(prjfile) sch_file_name = os.path.basename(prjfile) schematic_file = os.path.join(project_root, prjfile + '.sch') output_dir = os.path.join(project_root, 'CI-BUILD/' + sch_file_name + '/SCH') file_util.mkdir_p(output_dir) #TODO: Remove when stable or add debug flag screencast_output_file = os.path.join(output_dir, 'export_schematic_screencast.ogv') schematic_output_pdf_file = os.path.join(output_dir, sch_file_name + '.pdf') with recorded_xvfb(screencast_output_file, width=800, height=600, colordepth=24): with PopenContext(['eeschema', schematic_file], close_fds=True) as eeschema_proc: eeschema_plot_schematic(schematic_output_pdf_file, wait_init) eeschema_proc.terminate()
def export_bom(): schematic_file = os.path.join(electronics_root, 'splitflap.sch') output_dir = os.path.join(electronics_root, 'build') file_util.mkdir_p(output_dir) screencast_output_file = os.path.join(output_dir, 'export_bom_screencast.ogv') with recorded_xvfb(screencast_output_file, width=800, height=600, colordepth=24): with PopenContext(['eeschema', schematic_file], close_fds=True) as eeschema_proc: eeschema_export_bom(output_dir) eeschema_proc.terminate() logger.info('Convert component XML to useful BOM CSV file...') subprocess.check_call([ 'python', '-u', os.path.join(electronics_root, 'bom', 'generate_bom_csv.py'), os.path.join(electronics_root, 'splitflap.xml'), os.path.join(output_dir, 'bom.csv'), ])
def export_jlcpcb(pcb, schematic): pcb_file = os.path.abspath(pcb) output_dir = os.path.join( electronics_root, 'build', os.path.splitext(os.path.basename(pcb_file))[0] + '-jlc') file_util.mkdir_p(output_dir) with versioned_file(pcb_file): command = [ 'kikit', 'fab', 'jlcpcb', ] if schematic is not None: schematic_file = os.path.abspath(schematic) command += [ '--assembly', '--schematic', schematic_file, ] command += [ pcb_file, output_dir, ] subprocess.check_call(command)
def cleanup(args): board_file_path = os.path.dirname(args.brd) board_file_name = os.path.basename(args.brd) board_file = os.path.join(project_root, args.brd + '_' + args.variant + '.kicad_pcb') board = pcbnew.LoadBoard(board_file) output_dir = os.path.join( project_root, 'CI-BUILD/' + board_file_name + '_' + args.variant + '/DLF') file_util.mkdir_p(output_dir) #TODO: Remove when stable or add debug flag screencast_output_file = os.path.join(output_dir, 'dlf' + args.variant + '.ogv') with recorded_xvfb(screencast_output_file, width=800, height=600, colordepth=24): with PopenContext(['pcbnew', board_file], close_fds=True) as pcbnew_proc: pcbnew_cleanup(args.footprints, args.wait_init) pcbnew_proc.terminate()
def main(argv): parser = argparse.ArgumentParser(description='Plot Gerber Files') parser.add_argument('--brd', nargs='?', dest='brd', required=True) parser.add_argument('--dir', nargs='?', dest='dir', default='./') parser.add_argument('--all', action='store_true', dest='all', default=False) parser.add_argument('--protel', action='store_true', dest='protel', default=False) parser.add_argument('--fcu', action='store_true', dest='fcu', default=False) parser.add_argument('--bcu', action='store_true', dest='bcu', default=False) parser.add_argument('--fmask', action='store_true', dest='fmask', default=False) parser.add_argument('--bmask', action='store_true', dest='bmask', default=False) parser.add_argument('--fsilks', action='store_true', dest='fsilks', default=False) parser.add_argument('--bsilks', action='store_true', dest='bsilks', default=False) parser.add_argument('--edgecuts', action='store_true', dest='edgecuts', default=False) parser.add_argument('--drl', action='store_true', dest='drl', default=False) parser.add_argument('--splitth', action='store_true', dest='splitth', default=False) args = parser.parse_args(argv) args.dir = os.path.abspath(os.path.join(os.getcwd(), args.dir)) args.brd = os.path.join(os.getcwd(), args.brd) file_util.mkdir_p(args.dir) os.chdir(args.dir) plot(args)
def run_drc(pcb_file, output_dir, record=True): file_util.mkdir_p(output_dir) recording_file = os.path.join(output_dir, 'run_drc_screencast.ogv') drc_output_file = os.path.join(os.path.abspath(output_dir), 'drc_result.rpt') xvfb_kwargs = { 'width': 800, 'height': 600, 'colordepth': 24, } with recorded_xvfb(recording_file, **xvfb_kwargs) if record else Xvfb(**xvfb_kwargs): with PopenContext(['pcbnew', pcb_file], close_fds=True) as pcbnew_proc: clipboard_store(drc_output_file) window = wait_for_window('pcbnew', 'Pcbnew', 10, False) logger.info('Focus main pcbnew window') wait_for_window('pcbnew', 'Pcbnew') # Needed to rebuild the menu, making sure it is actually built xdotool(['windowsize', '--sync', window, '750', '600']) wait_for_window('pcbnew', 'Pcbnew') logger.info('Open Inspect->DRC') xdotool(['key', 'alt+i', 'd']) logger.info('Focus DRC modal window') wait_for_window('DRC modal window', 'DRC Control') xdotool(['key', 'Tab', 'Tab', 'Tab', # Refill zones on DRC gets saved in /root/.config/kicad/pcbnew as RefillZonesBeforeDrc 'key', 'Tab', 'space', # Enable reporting all errors for tracks 'Tab', 'Tab', 'Tab', 'space', 'Tab' ]) logger.info('Pasting output dir') xdotool(['key', 'ctrl+v']) xdotool(['key', 'Return']) wait_for_window('Report completed dialog', 'Disk File Report Completed') xdotool(['key', 'Return']) pcbnew_proc.terminate() return drc_output_file
def run_interactive_bom(pcb_file, output_dir, record=True): file_util.mkdir_p(output_dir) recording_file = os.path.join(output_dir, 'run_interactive_bom.ogv') drc_output_file = os.path.abspath(output_dir) xvfb_kwargs = { 'width': 1024, 'height': 786, 'colordepth': 24, } with recorded_xvfb(recording_file, **xvfb_kwargs) if record else Xvfb( **xvfb_kwargs): with PopenContext(['pcbnew', pcb_file], close_fds=True) as pcbnew_proc: clipboard_store(drc_output_file) dismiss_configure_global_footprint_upgrade() dismiss_enable_graphics_acceleration() #logger.info(xwininfo(['-root', '-tree'])) window = wait_for_window('pcbnew', 'Pcbnew', 10, False) logger.info('Focus main pcbnew window') wait_for_window('pcbnew', 'Pcbnew') # Needed to rebuild the menu, making sure it is actually built xdotool(['windowsize', '--sync', window, '1024', '786']) wait_for_window('pcbnew', 'Pcbnew') logger.info('Open Inspect->DRC') xdotool(['key', 'alt+t', 'Up', 'Right', 'Up', 'KP_Enter']) logger.info('Focus DRC modal window') wait_for_window('DRC modal window', 'InteractiveHtmlBom v2.3') xdotool( ['search', '--name', 'InteractiveHtmlBom v2.3', 'windowfocus']) logger.info('first..') logger.info('Pasting output dir') xdotool(['key', 'ctrl+v']) logger.info('return + sleep') xdotool(['key', 'Return']) time.sleep(10) pcbnew_proc.terminate() return drc_output_file
def export_bom(schematic_file): output_dir = os.path.join(electronics_root, 'build') file_util.mkdir_p(output_dir) screencast_output_file = os.path.join(output_dir, 'export_bom_screencast.ogv') with versioned_schematic(schematic_file): with recorded_xvfb(screencast_output_file, width=800, height=600, colordepth=24): with PopenContext(['eeschema', schematic_file], close_fds=True) as eeschema_proc: eeschema_export_bom() eeschema_proc.terminate()
def export_jlcpcb(schematic, pcb): schematic_file = os.path.abspath(schematic) pcb_file = os.path.abspath(pcb) output_dir = os.path.join(electronics_root, 'build', 'jlc') file_util.mkdir_p(output_dir) with versioned_file(pcb_file): subprocess.check_call([ 'kikit', 'fab', 'jlcpcb', '--assembly', '--schematic', schematic_file, pcb_file, output_dir, ])
def main(argv): parser = argparse.ArgumentParser( description='Delete footprints and cleanup PCB') parser.add_argument('--dir', nargs='?', dest='dir', default='./') parser.add_argument('--brd', nargs='?', dest='brd', required=True) parser.add_argument('--variant', nargs='?', dest='variant', default='') parser.add_argument('--footprints', nargs='?', dest='footprints', required=True) parser.add_argument('--wait_init', nargs='?', dest='wait_init', default=10) args = parser.parse_args(argv) args.dir = os.path.abspath(os.path.join(os.getcwd(), args.dir)) args.brd = os.path.join(os.getcwd(), args.brd) args.footprints = args.footprints.split(',') file_util.mkdir_p(args.dir) os.chdir(args.dir) delete_footprints(args) cleanup(args)
def export_bom(): schematic_file = os.path.join(electronics_root, 'splitflap.sch') output_dir = os.path.join(electronics_root, 'build') file_util.mkdir_p(output_dir) screencast_output_file = os.path.join(output_dir, 'export_bom_screencast.ogv') with versioned_schematic(schematic_file): with recorded_xvfb(screencast_output_file, width=800, height=600, colordepth=24): with PopenContext(['eeschema', schematic_file], close_fds=True) as eeschema_proc: eeschema_export_bom(output_dir) eeschema_proc.terminate() logger.info('Convert component XML to useful BOM CSV file...') subprocess.check_call([ 'python', '-u', os.path.join(electronics_root, 'bom', 'generate_bom_csv.py'), os.path.join(electronics_root, 'splitflap.xml'), os.path.join(output_dir, 'bom.csv'), ])
def export_bom(prjfile, wait_init): """Creates the BOM in xml Keyword arguments: prjfile -- The project file name including relative path from project_root WITHOUT extension. """ sch_file_path = os.path.dirname(prjfile) sch_file_name = os.path.basename(prjfile) schematic_file = os.path.join(project_root, prjfile + '.sch') output_dir = os.path.join(project_root, 'CI-BUILD/' + sch_file_name + '/BOM') file_util.mkdir_p(output_dir) screencast_output_file = os.path.join(output_dir, 'export_bom_screencast.ogv') with recorded_xvfb(screencast_output_file, width=800, height=600, colordepth=24): with PopenContext(['eeschema', schematic_file], close_fds=True) as eeschema_proc: eeschema_export_bom(output_dir, wait_init) eeschema_proc.terminate() # Copy xml BOM to CI Folder subprocess.check_call([ 'mv', prjfile + '.xml', output_dir, ]) # Copy csv BOM to CI Folder subprocess.check_call([ 'mv', prjfile, output_dir + '/' + sch_file_name + '.csv', ])
def export_bom(): schematic_file = os.path.join(electronics_root, "splitflap.sch") output_dir = os.path.join(electronics_root, "build") file_util.mkdir_p(output_dir) screencast_output_file = os.path.join(output_dir, "export_bom_screencast.ogv") with versioned_schematic(schematic_file): with recorded_xvfb(screencast_output_file, width=800, height=600, colordepth=24): with PopenContext(["eeschema", schematic_file], close_fds=True) as eeschema_proc: eeschema_export_bom(output_dir) eeschema_proc.terminate() logger.info("Convert component XML to useful BOM CSV file...") subprocess.check_call( [ "python", "-u", os.path.join(electronics_root, "bom", "generate_bom_csv.py"), os.path.join(electronics_root, "splitflap.xml"), os.path.join(output_dir, "bom.csv"), ] )
help='Treat warnings as errors', action='store_true') erc_parser.add_argument('--junit_xml', '-x', help='Generate junit XML report', action='store_true') args = parser.parse_args() schematic = os.path.abspath(args.schematic) if not os.path.isfile(schematic): logging.error(args.schematic + ' does not exist') exit(-1) output_dir = os.path.abspath(args.output_dir) + '/' file_util.mkdir_p(output_dir) if args.command == 'export': eeschema_export_schematic(schematic, output_dir, args.file_format, args.all_pages) exit(0) if args.command == 'run_erc': errors = eeschema_run_erc(schematic, output_dir, args.warnings_as_errors, args.junit_xml) if errors > 0: logging.error('{} ERC errors detected'.format(errors)) exit(errors) exit(0) else: usage() if sys.argv[1] == 'help':
def run_export_step(pcb_file, output_dir, record=True): file_util.mkdir_p(output_dir) recording_file = os.path.join(output_dir, 'run_export_step.ogv') board = ''.join(map(str, pcb_file.split('.')[0:-1])) step_file = os.path.join(os.path.abspath(output_dir), board + ".step") xvfb_kwargs = { 'width': 800, 'height': 600, 'colordepth': 24, } with recorded_xvfb(recording_file, **xvfb_kwargs) if record else Xvfb( **xvfb_kwargs): with PopenContext(['pcbnew', pcb_file], close_fds=True) as pcbnew_proc: print(step_file) clipboard_store(step_file.encode()) window = wait_for_window('pcbnew', 'Pcbnew', 10, False) logger.info('Focus main pcbnew window') wait_for_window('pcbnew', 'Pcbnew') # Needed to rebuild the menu, making sure it is actually built xdotool(['windowsize', '--sync', window, '750', '600']) wait_for_window('pcbnew', 'Pcbnew') logger.info('Open File->Export->Step') xdotool([ 'key', 'alt+f', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Down', 'Down', 'Down', 'Down', 'Return' ]) logger.info('Focus Export STEP modal window') wait_for_window('Export STEP modal window', 'Export STEP') logger.info('Pasting output file') logger.info(step_file) xdotool(['key', 'ctrl+v']) xdotool([ 'key', 'Tab', 'Tab', 'Down', 'Down', 'Down', 'Down', # Board center origin 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Return' ]) try: wait_for_window('STEP Export override dialog', 'STEP Export') xdotool(['key', 'Return']) except: print("Timeout") logger.info('Close Export STEP modal window') xdotool(['key', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Return']) pcbnew_proc.terminate() return step_file
def run_drc(pcb_file, output_dir, record=True): file_util.mkdir_p(output_dir) recording_file = os.path.join(output_dir, 'run_drc_screencast.ogv') drc_output_file = os.path.join(os.path.abspath(output_dir), 'drc_result.rpt') xvfb_kwargs = { 'width': 1024, 'height': 786, 'colordepth': 24, } with recorded_xvfb(recording_file, **xvfb_kwargs) if record else Xvfb( **xvfb_kwargs): with PopenContext(['pcbnew', pcb_file], close_fds=True) as pcbnew_proc: clipboard_store(drc_output_file) dismiss_configure_global_footprint_upgrade() dismiss_enable_graphics_acceleration() #logger.info(xwininfo(['-root', '-tree'])) window = wait_for_window('pcbnew', 'Pcbnew', 10, False) logger.info('Focus main pcbnew window') wait_for_window('pcbnew', 'Pcbnew') # Needed to rebuild the menu, making sure it is actually built xdotool(['windowsize', '--sync', window, '1024', '786']) wait_for_window('pcbnew', 'Pcbnew') logger.info('Open Inspect->DRC') xdotool(['key', 'alt+i', 'Up', 'KP_Enter']) logger.info('Focus DRC modal window') wait_for_window('DRC modal window', 'DRC Control') xdotool(['search', '--name', 'DRC Control', 'windowfocus']) logger.info('first..') xdotool([ 'key', 'Tab', 'Tab', 'Tab', 'Tab', 'space', 'Tab', 'space', 'Tab', 'space', 'Tab', 'space', ]) logger.info('Pasting output dir') xdotool(['key', 'ctrl+v']) logger.info('return + sleep') xdotool(['key', 'Return']) #time.sleep(1) wait_for_window('Zone fills are out-of-date. Refill?', 'Confirmation', 10, True, False) xdotool(['key', 'Down', 'KP_Enter']) wait_for_window('Report completed dialog', 'Disk File Report Completed', 10, True, False) xdotool(['key', 'Return']) pcbnew_proc.terminate() return drc_output_file