Ejemplo n.º 1
0
def airwires(board, showgui=0):
    'search for airwires in eagle board'
    board = Path(board).expand().abspath()

    file_out = tempfile.NamedTemporaryFile(suffix='.txt', delete=0)
    file_out.close()

    ulp = ulp_templ.replace('FILE_NAME', file_out.name)

    file_ulp = tempfile.NamedTemporaryFile(suffix='.ulp', delete=0)
    file_ulp.write(ulp.encode('utf-8'))
    file_ulp.close()

    commands = [
        'run ' + file_ulp.name,
        'quit',
    ]
    command_eagle(board, commands=commands, showgui=showgui)

    n = int(Path(file_out.name).text())

    Path(file_out.name).remove()
    Path(file_ulp.name).remove()

    return n
Ejemplo n.º 2
0
def export_partlist_to_file(input, output, timeout=20, showgui=False):
    """
    call eagle and export sch or brd to partlist text file

    :param input: .sch or .brd file name
    :param output: text file name
    :param timeout: int
    :param showgui: Bool, True -> do not hide eagle GUI
    :rtype: None
    """
    input = norm_path(input)
    output = norm_path(output)

    commands = export_command(output=output, output_type="partlist")
    command_eagle(input=input, timeout=timeout, commands=commands, showgui=showgui)
Ejemplo n.º 3
0
def export_partlist_to_file(input, output, timeout=20, showgui=False):
    '''
    call eagle and export sch or brd to partlist text file

    :param input: .sch or .brd file name
    :param output: text file name
    :param timeout: int
    :param showgui: Bool, True -> do not hide eagle GUI
    :rtype: None
    '''
    input = norm_path(input)
    output = norm_path(output)

    commands = export_command(output=output, output_type='partlist')
    command_eagle(
        input=input, timeout=timeout, commands=commands, showgui=showgui)
Ejemplo n.º 4
0
def airwires(board, showgui=0):
    "search for airwires in eagle board"
    with tempfile.TemporaryDirectory() as temp_dir:
        board = norm_path(board)

        file_out = join(temp_dir, "out.txt")

        ulp = ulp_templ.replace("FILE_NAME", file_out)

        file_ulp = join(temp_dir, "out.ulp")
        write_text(file_ulp, ulp)

        commands = [
            "run " + file_ulp,
            "quit",
        ]
        command_eagle(board, commands=commands, showgui=showgui)

        n = int(read_text(file_out))

        return n
Ejemplo n.º 5
0
def export_image3d(input, output, size=(800, 600), pcb_rotate=(0, 0, 0), timeout=20, showgui=False):
    '''
    Exporting eagle .brd file into 3D image file
    using Eagle3D and povray.
    GUI is not displayed if ``pyvirtualdisplay`` is installed.
    If export is blocked somehow (e.g. popup window is displayed) then after timeout operation is canceled with exception.
    Problem can be investigated by setting 'showgui' flag.

    :param input: eagle .brd file name
    :param output: image file name (.png)
    :param timeout: operation is canceled after this timeout (sec)
    :param showgui: eagle GUI is displayed
    :param size: tuple(width, size), image size
    :rtype: None
    '''
    input = norm_path(input)
    output = norm_path(output)

    ext = os.path.splitext(input)[1]
    if ext not in ['.brd']:
        raise ValueError('Input extension is not ".brd", brd=' + str(input))

    commands = []
    eagle3d = Path(__file__).dirname() / 'eagle3d'
    ulp = (eagle3d / '3d50.ulp').abspath()

    commands += ['RUN ' + ulp]
    commands += ['QUIT']

    def render(dir, f):
        # povray has strange file access policy,
        # better to generate under tmp

        # cli doc:
        # http://library.thinkquest.org/3285/language/cmdln.html

        templ = '#local pcb_rotate_%s = %s'
        pov = Path(f.replace('.brd', '.pov'))
        if pcb_rotate != (0, 0, 0):
            s = pov.text()
            s = s.replace(templ % ('x', 0), templ % ('x', pcb_rotate[0]))
            s = s.replace(templ % ('y', 0), templ % ('y', pcb_rotate[1]))
            s = s.replace(templ % ('z', 0), templ % ('z', pcb_rotate[2]))
            pov.write_text(s)
        fpng = Path(f.replace('.brd', '.png'))
        cmd = []
        cmd += ["povray"]
        cmd += ["-d"]  # no display
        cmd += ["-a"]  # anti-aliasing
        cmd += ['+W' + str(size[0])]  # width
        cmd += ['+H' + str(size[1])]  # height
        cmd += ['-o' + fpng]
        cmd += ['-L' + eagle3d]
        cmd += [pov]
        p = Proc(cmd).call()
        if not fpng.exists():
            raise EagleError('povray error, proc=%s' % p)
        fpng.copy(output)

    command_eagle(input=input, timeout=timeout, commands=commands,
                  showgui=showgui, callback=render)
Ejemplo n.º 6
0
def export_image3d(
    input, output, size=(800, 600), pcb_rotate=(0, 0, 0), timeout=20, showgui=False
):
    """
    Exporting eagle .brd file into 3D image file
    using Eagle3D and povray.
    If export is blocked somehow (e.g. popup window is displayed) then after timeout operation is canceled with exception.
    Problem can be investigated by setting 'showgui' flag.

    :param input: eagle .brd file name
    :param output: image file name (.png)
    :param timeout: operation is canceled after this timeout (sec)
    :param showgui: eagle GUI is displayed
    :param size: tuple(width, size), image size
    :rtype: None
    """
    input = norm_path(input)
    output = norm_path(output)
    if not output.endswith(".png"):
        raise ValueError("use .png extension!")

    ext = os.path.splitext(input)[1]
    if ext not in [".brd"]:
        raise ValueError('Input extension is not ".brd", brd=' + str(input))

    commands = []
    eagle3d = join(dirname(__file__), "eagle3d")
    ulp = norm_path(join(eagle3d, "3d50.ulp"))
    if not exists(ulp):
        raise EagleError("missing file:%s" % ulp)

    commands += ["RUN " + ulp]
    commands += ["QUIT"]

    def render(dir, f):
        # povray has strange file access policy,
        # better to generate under tmp

        # cli doc:
        # http://library.thinkquest.org/3285/language/cmdln.html

        templ = "#local pcb_rotate_%s = %s"
        pov = f.replace(".brd", ".pov")
        if not exists(pov):
            raise EagleError("missing pov file: %s" % pov)
        # log.debug("pov file %s content: %s", pov, pov.read_text())
        if pcb_rotate != (0, 0, 0):
            s = read_text(pov)
            s = s.replace(templ % ("x", 0), templ % ("x", pcb_rotate[0]))
            s = s.replace(templ % ("y", 0), templ % ("y", pcb_rotate[1]))
            s = s.replace(templ % ("z", 0), templ % ("z", pcb_rotate[2]))
            write_text(pov, s)
        fpng = f.replace(".brd", ".png")
        cmd = []
        cmd += ["povray"]
        cmd += ["-d"]  # no display
        cmd += ["-a"]  # anti-aliasing
        cmd += ["+W" + str(size[0])]  # width
        cmd += ["+H" + str(size[1])]  # height
        cmd += ["-o" + fpng]
        cmd += ["-L" + eagle3d]
        cmd += [pov]
        p = EasyProcess(cmd).call()
        if not exists(fpng):
            raise EagleError("povray error, proc=%s" % p)
        copy(fpng, output)

    command_eagle(
        input=input,
        timeout=timeout,
        commands=commands,
        showgui=showgui,
        callback=render,
    )
Ejemplo n.º 7
0
def export_image(
    input,
    output,
    timeout=20,
    palette="white",
    resolution=150,
    layers=None,
    command=None,
    mirror=False,
    showgui=False,
):
    """
    Exporting eagle .sch or .brd file into image file.
    If export is blocked somehow (e.g. popup window is displayed) then after timeout operation is canceled with exception.
    Problem can be investigated by setting 'showgui' flag.
    Exporting generates an image file. Only PNG format is supported

    :param input: eagle .sch or .brd file name
    :param output: image file name (e.g. 'eagle.png')
    :param palette: background color [None,black,white,colored]
    :param resolution: image resolution in dpi (50..2400)
    :param timeout: operation is canceled after this timeout (sec)
    :param showgui: eagle GUI is displayed
    :param layers: list, layers to be displayed ['top','pads']
    :param command: string, direct eagle command
    :param mirror: Bool
    :rtype: None
    """
    input = norm_path(input)
    output = norm_path(output)
    if not output.endswith(".png"):
        raise ValueError("use .png extension!")

    if palette:
        palette = palette.lower()

    if palette == "none":
        palette = None

    cmds = []
    if palette is not None:
        cmds += ["SET PALETTE {palette}".format(palette=palette)]

    if layers is not None:
        cmds += ["DISPLAY NONE " + " ".join(layers)]

    if command is not None:
        cmds += [command]

    with tempfile.TemporaryDirectory() as temp_dir:
        if mirror:
            fout = join(temp_dir, "out.png")
        else:
            fout = output

        commands = export_command(output=fout,
                                  output_type="image",
                                  commands=cmds,
                                  resolution=resolution)
        command_eagle(input=input,
                      timeout=timeout,
                      commands=commands,
                      showgui=showgui)

        if mirror:
            im = Image.open(fout)
            # save dpi info
            info = im.info
            im = ImageOps.mirror(im)
            im.save(output, **info)
Ejemplo n.º 8
0
def export_image(input, output, timeout=20, palette='white', resolution=150, layers=None, command=None, mirror=False, showgui=False):
    '''
    Exporting eagle .sch or .brd file into image file.
    GUI is not displayed if ``pyvirtualdisplay`` is installed.
    If export is blocked somehow (e.g. popup window is displayed) then after timeout operation is canceled with exception.
    Problem can be investigated by setting 'showgui' flag.

    Exporting generates an image file with a format corresponding
    to the given filename extension.
    The following image formats are available:

    .bmp    Windows Bitmap Files

    .png    Portable Network Graphics Files

    .pbm    Portable Bitmap Files

    .pgm    Portable Grayscale Bitmap Files

    .ppm    Portable Pixelmap Files

    .tif    TIFF Files

    .xbm    X Bitmap Files

    .xpm    X Pixmap Files

    :param input: eagle .sch or .brd file name
    :param output: image file name, existing file will be removed first!
    :param palette: background color [None,black,white,colored]
    :param resolution: image resolution in dpi (50..2400)
    :param timeout: operation is canceled after this timeout (sec)
    :param showgui: eagle GUI is displayed
    :param layers: list, layers to be displayed ['top','pads']
    :param command: string, direct eagle command
    :param mirror: Bool
    :rtype: None
    '''
    input = norm_path(input)
    output = norm_path(output)

    if palette:
        palette = palette.lower()

    if palette == 'none':
        palette = None

    cmds = []
    if palette is not None:
        cmds += ['SET PALETTE {palette}'.format(palette=palette)]

    if layers is not None:
        cmds += ['DISPLAY NONE ' + ' '.join(layers)]

    if command is not None:
        cmds += [command]

    if mirror:
        f = tempfile.NamedTemporaryFile(suffix='.png', prefix='eagexp_')
        fout = f.name
    else:
        fout = output

    commands = export_command(output=fout, output_type='image',
                              commands=cmds, resolution=resolution)
    command_eagle(
        input=input, timeout=timeout, commands=commands, showgui=showgui)

    if mirror:
        im = Image.open(fout)
        # save dpi info
        info = im.info
        im = ImageOps.mirror(im)
        im.save(output, **info)